@@ -389,10 +422,79 @@ function recalculateRowVisual(row) {
}
function eliminarRow(id) {
- if (confirm('¿Eliminar este registro de la V3?')) {
- window.location.href = 'delete_marketing_video_v3.php?id=' + id;
+ if (confirm("¿Eliminar este registro de la V3?")) {
+ window.location.href = "delete_marketing_video_v3.php?id=" + id;
}
}
+
+function triggerImageUpload(id) {
+ document.getElementById(`file-input-${id}`).click();
+}
+
+function uploadImage(id) {
+ const fileInput = document.getElementById(`file-input-${id}`);
+ if (!fileInput.files || !fileInput.files[0]) return;
+
+ const formData = new FormData();
+ formData.append('id', id);
+ formData.append('foto_producto', fileInput.files[0]);
+
+ const cell = fileInput.closest('td');
+ const originalContent = cell.innerHTML;
+ cell.innerHTML = '
';
+
+ fetch('update_marketing_video_image_v3.php', {
+ method: 'POST',
+ body: formData
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (data.success) {
+ location.reload(); // Recargamos para ver la nueva imagen
+ } else {
+ alert('Error al subir imagen: ' + data.error);
+ cell.innerHTML = originalContent;
+ }
+ })
+ .catch(err => {
+ console.error(err);
+ alert('Error técnico al subir imagen');
+ cell.innerHTML = originalContent;
+ });
+}
+
+// Script de apertura forzada y diagnóstico
+document.addEventListener('DOMContentLoaded', function() {
+ const btn = document.getElementById('btnAbrirModalV3');
+ const modalEl = document.getElementById('modalNuevoV3');
+
+ if (btn && modalEl) {
+ btn.addEventListener('click', function() {
+ console.log('Intento de apertura manual del modal...');
+ try {
+ // Intento 1: Usando la API de Bootstrap 5
+ if (typeof bootstrap !== 'undefined') {
+ const modalInstance = new bootstrap.Modal(modalEl);
+ modalInstance.show();
+ console.log('Modal abierto con bootstrap.Modal');
+ } else {
+ // Intento 2: Si bootstrap no está definido, intentar vía jQuery si existe
+ if (typeof $ !== 'undefined' && typeof $.fn.modal !== 'undefined') {
+ $(modalEl).modal('show');
+ console.log('Modal abierto con jQuery');
+ } else {
+ alert('Error: No se encontró la librería de Bootstrap. Por favor, recarga la página.');
+ }
+ }
+ } catch (err) {
+ console.error('Error al abrir modal:', err);
+ alert('Hubo un problema técnico al abrir la ventana. Error: ' + err.message);
+ }
+ });
+ } else {
+ console.error('No se encontró el botón o el modal en el DOM');
+ }
+});
\ No newline at end of file
diff --git a/delete_marketing_video_v3.php b/delete_marketing_video_v3.php
index 42520451..a6f4e1df 100644
--- a/delete_marketing_video_v3.php
+++ b/delete_marketing_video_v3.php
@@ -1,9 +1,11 @@
beginTransaction();
+
$stmt = $db->prepare("INSERT INTO marketing_videos_v3 (
producto_id,
foto_producto,
@@ -45,14 +49,29 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
]);
$video_id = $db->lastInsertId();
+ if (!$video_id) {
+ throw new Exception("No se pudo obtener el ID del video insertado.");
+ }
+
// Guardar costo inicial en la tabla de costos V3
$stmt_costo = $db->prepare("INSERT INTO marketing_costos_v3 (video_id, costo_producto, inversion_total) VALUES (?, ?, ?)");
$stmt_costo->execute([$video_id, $costo_producto, $costo_producto]);
+ $db->commit();
+
$redirect = $_POST['redirect'] ?? 'calculo_costos_v3.php?success=1';
header('Location: ' . $redirect);
- } catch (PDOException $e) {
- echo "Error: " . $e->getMessage();
+ exit();
+ } catch (Exception $e) {
+ if ($db->inTransaction()) {
+ $db->rollBack();
+ }
+ error_log("Error en save_marketing_video_v3.php: " . $e->getMessage());
+ header('Location: calculo_costos_v3.php?error=' . urlencode($e->getMessage()));
+ exit();
}
+} else {
+ header('Location: calculo_costos_v3.php');
+ exit();
}
?>
\ No newline at end of file
diff --git a/update_marketing_video_image_v3.php b/update_marketing_video_image_v3.php
new file mode 100644
index 00000000..f9705b7d
--- /dev/null
+++ b/update_marketing_video_image_v3.php
@@ -0,0 +1,51 @@
+ false, 'error' => 'No autorizado']);
+ exit();
+}
+
+if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['foto_producto']) && isset($_POST['id'])) {
+ $db = db();
+ $id = $_POST['id'];
+
+ if ($_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() . '_v3.' . $file_extension;
+ $target_file = $target_dir . $file_name;
+
+ if (move_uploaded_file($_FILES["foto_producto"]["tmp_name"], $target_file)) {
+ try {
+ // Opcional: borrar imagen anterior si existe
+ $stmt_old = $db->prepare("SELECT foto_producto FROM marketing_videos_v3 WHERE id = ?");
+ $stmt_old->execute([$id]);
+ $old_photo = $stmt_old->fetchColumn();
+ if ($old_photo && file_exists($old_photo)) {
+ unlink($old_photo);
+ }
+
+ $stmt = $db->prepare("UPDATE marketing_videos_v3 SET foto_producto = ? WHERE id = ?");
+ $stmt->execute([$target_file, $id]);
+
+ echo json_encode(['success' => true, 'path' => $target_file]);
+ } catch (Exception $e) {
+ echo json_encode(['success' => false, 'error' => $e->getMessage()]);
+ }
+ } else {
+ echo json_encode(['success' => false, 'error' => 'Error al mover el archivo']);
+ }
+ } else {
+ echo json_encode(['success' => false, 'error' => 'Error en la subida: ' . $_FILES['foto_producto']['error']]);
+ }
+} else {
+ echo json_encode(['success' => false, 'error' => 'Solicitud inválida']);
+}
+?>