40097-vm/save_marketing_video.php
2026-05-05 03:03:33 +00:00

118 lines
4.2 KiB
PHP

<?php
include 'db/config.php';
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$db = db();
$action = $_POST['action'] ?? 'create';
if ($action == 'update') {
// Lógica para actualizar (Editora o Tú)
$id = $_POST['id'];
$estado = $_POST['estado'];
$link_video = $_POST['link_video'] ?? '';
$link_landing = $_POST['link_landing'] ?? '';
$link_flyer = $_POST['link_flyer'] ?? '';
$material = $_POST['material'] ?? '';
$fecha_entrega = !empty($_POST['fecha_entrega']) ? $_POST['fecha_entrega'] : null;
$orden = !empty($_POST['orden']) ? $_POST['orden'] : 0;
$angulo_video = $_POST['angulo_video'] ?? '';
$link_inspiracion_landing = $_POST['link_inspiracion_landing'] ?? '';
$link_inspiracion_video = $_POST['link_inspiracion_video'] ?? '';
try {
$stmt = $db->prepare("UPDATE marketing_videos SET
estado = ?,
link_video = ?,
link_landing = ?,
link_flyer = ?,
material = ?,
fecha_entrega = ?,
orden = ?,
angulo_video = ?,
link_inspiracion_landing = ?,
link_inspiracion_video = ?
WHERE id = ?");
$stmt->execute([
$estado,
$link_video,
$link_landing,
$link_flyer,
$material,
$fecha_entrega,
$orden,
$angulo_video,
$link_inspiracion_landing,
$link_inspiracion_video,
$id
]);
header('Location: marketing_produccion.php?success=updated');
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
} else {
// Lógica para crear (Tú)
$producto_id = !empty($_POST['producto_id']) ? $_POST['producto_id'] : null;
$instrucciones = $_POST['instrucciones'] ?? '';
$fecha_entrega = !empty($_POST['fecha_entrega']) ? $_POST['fecha_entrega'] : null;
$orden = !empty($_POST['orden']) ? $_POST['orden'] : 0;
$angulo_video = $_POST['angulo_video'] ?? '';
$link_inspiracion_landing = $_POST['link_inspiracion_landing'] ?? '';
$link_inspiracion_video = $_POST['link_inspiracion_video'] ?? '';
$link_flyer = $_POST['link_flyer'] ?? '';
$material = $_POST['material'] ?? '';
$foto_path = null;
if (isset($_FILES['foto_producto']) && $_FILES['foto_producto']['error'] == 0) {
$target_dir = "assets/uploads/marketing_images/";
if (!is_dir($target_dir)) {
mkdir($target_dir, 0777, true);
}
$file_extension = pathinfo($_FILES["foto_producto"]["name"], PATHINFO_EXTENSION);
$file_name = uniqid() . '.' . $file_extension;
$target_file = $target_dir . $file_name;
if (move_uploaded_file($_FILES["foto_producto"]["tmp_name"], $target_file)) {
$foto_path = $target_file;
}
}
try {
$stmt = $db->prepare("INSERT INTO marketing_videos (
producto_id,
foto_producto,
material,
instrucciones,
estado,
fecha_entrega,
orden,
angulo_video,
link_inspiracion_landing,
link_inspiracion_video,
link_flyer
) VALUES (?, ?, ?, ?, 'Pendiente', ?, ?, ?, ?, ?, ?)");
$stmt->execute([
$producto_id,
$foto_path,
$material,
$instrucciones,
$fecha_entrega,
$orden,
$angulo_video,
$link_inspiracion_landing,
$link_inspiracion_video,
$link_flyer
]);
header('Location: marketing_produccion.php?success=created');
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
}
?>