40097-vm/delete_marketing_video_v3.php
2026-05-19 01:22:09 +00:00

35 lines
997 B
PHP

<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
include 'db/config.php';
if (!isset($_SESSION['user_role']) || !in_array($_SESSION['user_role'], ['Administrador', 'admin'])) {
header('Location: dashboard.php');
exit();
}
$db = db();
if (isset($_GET['id'])) {
$id = $_GET['id'];
// Obtener la ruta de la foto para borrarla
$stmt = $db->prepare("SELECT foto_producto FROM marketing_videos_v3 WHERE id = ?");
$stmt->execute([$id]);
$video = $stmt->fetch(PDO::FETCH_ASSOC);
if ($video) {
if (!empty($video['foto_producto']) && file_exists($video['foto_producto'])) {
unlink($video['foto_producto']);
}
// Borrar de ambas tablas V3
$db->prepare("DELETE FROM marketing_costos_v3 WHERE video_id = ?")->execute([$id]);
$db->prepare("DELETE FROM marketing_videos_v3 WHERE id = ?")->execute([$id]);
}
}
header("Location: calculo_costos_v3.php?success=deleted");
exit;
?>