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 ]); $redirect = $_POST['redirect'] ?? 'marketing_produccion.php?success=updated'; header('Location: ' . $redirect); } 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 = ''; if (isset($_POST['angulo_video'])) { $angulo_video = is_array($_POST['angulo_video']) ? implode(',', array_filter($_POST['angulo_video'])) : $_POST['angulo_video']; } $link_inspiracion_landing = ''; if (isset($_POST['link_inspiracion_landing'])) { $link_inspiracion_landing = is_array($_POST['link_inspiracion_landing']) ? implode(',', array_filter($_POST['link_inspiracion_landing'])) : $_POST['link_inspiracion_landing']; } $link_inspiracion_video = ''; if (isset($_POST['link_inspiracion_video'])) { $link_inspiracion_video = is_array($_POST['link_inspiracion_video']) ? implode(',', array_filter($_POST['link_inspiracion_video'])) : $_POST['link_inspiracion_video']; } $link_flyer = ''; if (isset($_POST['link_flyer'])) { $link_flyer = is_array($_POST['link_flyer']) ? implode(',', array_filter($_POST['link_flyer'])) : $_POST['link_flyer']; } $link_video = ''; if (isset($_POST['link_video'])) { $link_video = is_array($_POST['link_video']) ? implode(',', array_filter($_POST['link_video'])) : $_POST['link_video']; } $link_landing = ''; if (isset($_POST['link_landing'])) { $link_landing = is_array($_POST['link_landing']) ? implode(',', array_filter($_POST['link_landing'])) : $_POST['link_landing']; } $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, link_video, link_landing ) VALUES (?, ?, ?, ?, 'PENDIENTE', ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([ $producto_id, $foto_path, $material, $instrucciones, $fecha_entrega, $orden, $angulo_video, $link_inspiracion_landing, $link_inspiracion_video, $link_flyer, $link_video, $link_landing ]); $video_id = $db->lastInsertId(); // Guardar costo inicial si se proporcionó if (!empty($_POST['costo_producto'])) { $costo_producto = $_POST['costo_producto']; $stmt_costo = $db->prepare("INSERT INTO marketing_costos (video_id, costo_producto, inversion_total) VALUES (?, ?, ?)"); $stmt_costo->execute([$video_id, $costo_producto, $costo_producto]); } $redirect = $_POST['redirect'] ?? 'marketing_produccion.php?success=created'; header('Location: ' . $redirect); } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } } } ?>