Autosave: 20260729-183901
This commit is contained in:
parent
543b57f55d
commit
cd63f23d4e
@ -850,12 +850,80 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
if ($view === 'todos') {
|
||||
if ($aImport !== $bImport) {
|
||||
return $bImport <=> $aImport;
|
||||
}
|
||||
|
||||
$aSourceRow = (int) ($a['source_row'] ?? 0);
|
||||
$bSourceRow = (int) ($b['source_row'] ?? 0);
|
||||
if ($aSourceRow !== $bSourceRow) {
|
||||
return $bSourceRow <=> $aSourceRow;
|
||||
}
|
||||
|
||||
$aId = (int) ($a['id'] ?? 0);
|
||||
$bId = (int) ($b['id'] ?? 0);
|
||||
if ($aId !== $bId) {
|
||||
return $bId <=> $aId;
|
||||
}
|
||||
|
||||
return strcmp((string) ($a['source_key'] ?? ''), (string) ($b['source_key'] ?? ''));
|
||||
}
|
||||
|
||||
if ($aImport !== $bImport) {
|
||||
return $bImport <=> $aImport;
|
||||
}
|
||||
|
||||
return cc_test_order_time($b) <=> cc_test_order_time($a);
|
||||
});
|
||||
|
||||
$visibleOrdersTotalCount = count($visibleOrders);
|
||||
$todosPageSize = 200;
|
||||
$todosPage = 1;
|
||||
$todosTotalPages = 1;
|
||||
$todosPageStart = 0;
|
||||
$todosPageEnd = 0;
|
||||
$todosPaginationPages = [];
|
||||
|
||||
if ($view === 'todos') {
|
||||
$requestedPage = (int) ($_GET['page'] ?? 1);
|
||||
if ($requestedPage < 1) {
|
||||
$requestedPage = 1;
|
||||
}
|
||||
|
||||
$todosTotalPages = max(1, (int) ceil($visibleOrdersTotalCount / $todosPageSize));
|
||||
if ($requestedPage > $todosTotalPages) {
|
||||
$requestedPage = $todosTotalPages;
|
||||
}
|
||||
|
||||
$todosPage = $requestedPage;
|
||||
$todosPageStart = ($todosPage - 1) * $todosPageSize;
|
||||
$visibleOrders = array_slice($visibleOrders, $todosPageStart, $todosPageSize);
|
||||
$todosPageEnd = $todosPageStart + count($visibleOrders);
|
||||
|
||||
if ($todosTotalPages <= 7) {
|
||||
$todosPaginationPages = range(1, $todosTotalPages);
|
||||
} else {
|
||||
$todosPaginationPages[] = 1;
|
||||
$windowStart = max(2, $todosPage - 1);
|
||||
$windowEnd = min($todosTotalPages - 1, $todosPage + 1);
|
||||
|
||||
if ($windowStart > 2) {
|
||||
$todosPaginationPages[] = 'ellipsis';
|
||||
}
|
||||
|
||||
for ($pageNumber = $windowStart; $pageNumber <= $windowEnd; $pageNumber++) {
|
||||
$todosPaginationPages[] = $pageNumber;
|
||||
}
|
||||
|
||||
if ($windowEnd < $todosTotalPages - 1) {
|
||||
$todosPaginationPages[] = 'ellipsis';
|
||||
}
|
||||
|
||||
$todosPaginationPages[] = $todosTotalPages;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable $exception) {
|
||||
$errorMessage = $exception->getMessage();
|
||||
}
|
||||
@ -1224,7 +1292,10 @@ require_once 'layout_header.php';
|
||||
<?php if ($selectedAssessorFilterLabel !== ''): ?>
|
||||
<span class="badge bg-primary-subtle text-primary-emphasis border border-primary-subtle">Asesora: <?php echo htmlspecialchars($selectedAssessorFilterLabel); ?></span>
|
||||
<?php endif; ?>
|
||||
<span class="badge bg-light text-dark border"><?php echo count($visibleOrders); ?> pedidos únicos en esta bandeja</span>
|
||||
<span class="badge bg-light text-dark border"><?php echo (int) $visibleOrdersTotalCount; ?> pedidos únicos en esta bandeja</span>
|
||||
<?php if ($view === 'todos'): ?>
|
||||
<span class="badge bg-primary-subtle text-primary-emphasis border">Página <?php echo (int) $todosPage; ?> de <?php echo (int) $todosTotalPages; ?> · 200 por página</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
@ -1873,6 +1944,50 @@ require_once 'layout_header.php';
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php if ($view === 'todos'): ?>
|
||||
<div class="border-top bg-light-subtle px-3 py-3 d-flex flex-column flex-lg-row justify-content-between align-items-lg-center gap-2">
|
||||
<div class="small text-muted">
|
||||
<?php if ($visibleOrdersTotalCount > 0): ?>
|
||||
Mostrando <?php echo (int) $todosPageStart + 1; ?>-<?php echo (int) min($todosPageEnd, $visibleOrdersTotalCount); ?> de <?php echo (int) $visibleOrdersTotalCount; ?> pedidos · 200 por página
|
||||
<?php else: ?>
|
||||
No hay pedidos para mostrar en esta vista.
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if ($todosTotalPages > 1): ?>
|
||||
<nav aria-label="Paginación de pedidos">
|
||||
<ul class="pagination pagination-sm mb-0 flex-wrap">
|
||||
<li class="page-item<?php echo $todosPage <= 1 ? ' disabled' : ''; ?>">
|
||||
<?php if ($todosPage <= 1): ?>
|
||||
<span class="page-link">«</span>
|
||||
<?php else: ?>
|
||||
<a class="page-link" href="<?php echo htmlspecialchars(cc_test_build_url('call_center_pro.php', array_merge($callCenterParams, ['page' => $todosPage - 1]))); ?>" aria-label="Anterior">«</a>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php foreach ($todosPaginationPages as $pageEntry): ?>
|
||||
<?php if ($pageEntry === 'ellipsis'): ?>
|
||||
<li class="page-item disabled"><span class="page-link">…</span></li>
|
||||
<?php else: ?>
|
||||
<li class="page-item<?php echo (int) $pageEntry === $todosPage ? ' active' : ''; ?>">
|
||||
<?php if ((int) $pageEntry === $todosPage): ?>
|
||||
<span class="page-link" aria-current="page"><?php echo (int) $pageEntry; ?></span>
|
||||
<?php else: ?>
|
||||
<a class="page-link" href="<?php echo htmlspecialchars(cc_test_build_url('call_center_pro.php', array_merge($callCenterParams, ['page' => (int) $pageEntry]))); ?>"><?php echo (int) $pageEntry; ?></a>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<li class="page-item<?php echo $todosPage >= $todosTotalPages ? ' disabled' : ''; ?>">
|
||||
<?php if ($todosPage >= $todosTotalPages): ?>
|
||||
<span class="page-link">»</span>
|
||||
<?php else: ?>
|
||||
<a class="page-link" href="<?php echo htmlspecialchars(cc_test_build_url('call_center_pro.php', array_merge($callCenterParams, ['page' => $todosPage + 1]))); ?>" aria-label="Siguiente">»</a>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@ -328,7 +328,10 @@ $uploadErrorMessage = null;
|
||||
$assessors = [];
|
||||
$orders = [];
|
||||
$visibleOrders = [];
|
||||
$modalsHtml = [];
|
||||
$modalsHtml = fopen('php://temp', 'w+');
|
||||
if ($modalsHtml === false) {
|
||||
$modalsHtml = null;
|
||||
}
|
||||
$totalRows = 0;
|
||||
$agregadosCount = 0;
|
||||
$lastProcessedRow = null;
|
||||
@ -1131,12 +1134,80 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
if ($view === 'todos') {
|
||||
if ($aImport !== $bImport) {
|
||||
return $bImport <=> $aImport;
|
||||
}
|
||||
|
||||
$aSourceRow = (int) ($a['source_row'] ?? 0);
|
||||
$bSourceRow = (int) ($b['source_row'] ?? 0);
|
||||
if ($aSourceRow !== $bSourceRow) {
|
||||
return $bSourceRow <=> $aSourceRow;
|
||||
}
|
||||
|
||||
$aId = (int) ($a['id'] ?? 0);
|
||||
$bId = (int) ($b['id'] ?? 0);
|
||||
if ($aId !== $bId) {
|
||||
return $bId <=> $aId;
|
||||
}
|
||||
|
||||
return strcmp((string) ($a['source_key'] ?? ''), (string) ($b['source_key'] ?? ''));
|
||||
}
|
||||
|
||||
if ($aImport !== $bImport) {
|
||||
return $bImport <=> $aImport;
|
||||
}
|
||||
|
||||
return cc_test_order_time($b) <=> cc_test_order_time($a);
|
||||
});
|
||||
|
||||
$visibleOrdersTotalCount = count($visibleOrders);
|
||||
$todosPageSize = 200;
|
||||
$todosPage = 1;
|
||||
$todosTotalPages = 1;
|
||||
$todosPageStart = 0;
|
||||
$todosPageEnd = 0;
|
||||
$todosPaginationPages = [];
|
||||
|
||||
if ($view === 'todos') {
|
||||
$requestedPage = (int) ($_GET['page'] ?? 1);
|
||||
if ($requestedPage < 1) {
|
||||
$requestedPage = 1;
|
||||
}
|
||||
|
||||
$todosTotalPages = max(1, (int) ceil($visibleOrdersTotalCount / $todosPageSize));
|
||||
if ($requestedPage > $todosTotalPages) {
|
||||
$requestedPage = $todosTotalPages;
|
||||
}
|
||||
|
||||
$todosPage = $requestedPage;
|
||||
$todosPageStart = ($todosPage - 1) * $todosPageSize;
|
||||
$visibleOrders = array_slice($visibleOrders, $todosPageStart, $todosPageSize);
|
||||
$todosPageEnd = $todosPageStart + count($visibleOrders);
|
||||
|
||||
if ($todosTotalPages <= 7) {
|
||||
$todosPaginationPages = range(1, $todosTotalPages);
|
||||
} else {
|
||||
$todosPaginationPages[] = 1;
|
||||
$windowStart = max(2, $todosPage - 1);
|
||||
$windowEnd = min($todosTotalPages - 1, $todosPage + 1);
|
||||
|
||||
if ($windowStart > 2) {
|
||||
$todosPaginationPages[] = 'ellipsis';
|
||||
}
|
||||
|
||||
for ($pageNumber = $windowStart; $pageNumber <= $windowEnd; $pageNumber++) {
|
||||
$todosPaginationPages[] = $pageNumber;
|
||||
}
|
||||
|
||||
if ($windowEnd < $todosTotalPages - 1) {
|
||||
$todosPaginationPages[] = 'ellipsis';
|
||||
}
|
||||
|
||||
$todosPaginationPages[] = $todosTotalPages;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable $exception) {
|
||||
$errorMessage = $exception->getMessage();
|
||||
}
|
||||
@ -1784,7 +1855,10 @@ require_once 'layout_header.php';
|
||||
<h2 class="h5 fw-bold mb-1"><?php echo htmlspecialchars($allowedViews[$view]); ?></h2>
|
||||
<p class="text-muted small mb-1"><?php echo $viewStatesNote; ?></p>
|
||||
</div>
|
||||
<span class="badge bg-light text-dark border"><?php echo count($visibleOrders); ?> pedidos únicos en esta bandeja</span>
|
||||
<span class="badge bg-light text-dark border"><?php echo (int) $visibleOrdersTotalCount; ?> pedidos únicos en esta bandeja</span>
|
||||
<?php if ($view === 'todos'): ?>
|
||||
<span class="badge bg-primary-subtle text-primary-emphasis border">Página <?php echo (int) $todosPage; ?> de <?php echo (int) $todosTotalPages; ?> · 200 por página</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<div class="border-bottom bg-light-subtle px-3 py-3">
|
||||
@ -1950,7 +2024,7 @@ require_once 'layout_header.php';
|
||||
|
||||
<div class="cc-callcenter-assign-row">
|
||||
<input type="hidden" name="target_assessor" class="js-assessor-hidden" value="<?php echo htmlspecialchars((string) $selectedAssessorKeyForSelect); ?>">
|
||||
<select class="form-select form-select-sm js-assessor-select" data-server-assessor="<?php echo htmlspecialchars((string) $selectedAssessorKeyForSelect); ?>" autocomplete="off" data-lpignore="true" data-1p-ignore="true" data-bwignore="true">
|
||||
<select name="target_assessor" class="form-select form-select-sm js-assessor-select" data-server-assessor="<?php echo htmlspecialchars((string) $selectedAssessorKeyForSelect); ?>" autocomplete="off" data-lpignore="true" data-1p-ignore="true" data-bwignore="true">
|
||||
<option value=""<?php echo ($selectedAssessorKeyForSelect === '') ? ' selected' : ''; ?>>Sin asignar</option>
|
||||
|
||||
<?php foreach ($assessors as $assessorKey => $assessor): ?>
|
||||
@ -2473,18 +2547,66 @@ require_once 'layout_header.php';
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php $modalsHtml[] = ob_get_clean(); ?>
|
||||
<?php
|
||||
$modalHtml = ob_get_clean();
|
||||
if (is_resource($modalsHtml)) {
|
||||
fwrite($modalsHtml, $modalHtml . PHP_EOL);
|
||||
}
|
||||
?>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php if ($view === 'todos'): ?>
|
||||
<div class="border-top bg-light-subtle px-3 py-3 d-flex flex-column flex-lg-row justify-content-between align-items-lg-center gap-2">
|
||||
<div class="small text-muted">
|
||||
<?php if ($visibleOrdersTotalCount > 0): ?>
|
||||
Mostrando <?php echo (int) $todosPageStart + 1; ?>-<?php echo (int) min($todosPageEnd, $visibleOrdersTotalCount); ?> de <?php echo (int) $visibleOrdersTotalCount; ?> pedidos · 200 por página
|
||||
<?php else: ?>
|
||||
No hay pedidos para mostrar en esta vista.
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if ($todosTotalPages > 1): ?>
|
||||
<nav aria-label="Paginación de pedidos">
|
||||
<ul class="pagination pagination-sm mb-0 flex-wrap">
|
||||
<li class="page-item<?php echo $todosPage <= 1 ? ' disabled' : ''; ?>">
|
||||
<?php if ($todosPage <= 1): ?>
|
||||
<span class="page-link">«</span>
|
||||
<?php else: ?>
|
||||
<a class="page-link" href="<?php echo htmlspecialchars(cc_test_build_url('gestiones_callcenter.php', array_merge(['view' => 'todos', 'store' => $storeKey, 'page' => $todosPage - 1], $persistedAssessorParams))); ?>" aria-label="Anterior">«</a>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php foreach ($todosPaginationPages as $pageEntry): ?>
|
||||
<?php if ($pageEntry === 'ellipsis'): ?>
|
||||
<li class="page-item disabled"><span class="page-link">…</span></li>
|
||||
<?php else: ?>
|
||||
<li class="page-item<?php echo (int) $pageEntry === $todosPage ? ' active' : ''; ?>">
|
||||
<?php if ((int) $pageEntry === $todosPage): ?>
|
||||
<span class="page-link" aria-current="page"><?php echo (int) $pageEntry; ?></span>
|
||||
<?php else: ?>
|
||||
<a class="page-link" href="<?php echo htmlspecialchars(cc_test_build_url('gestiones_callcenter.php', array_merge(['view' => 'todos', 'store' => $storeKey, 'page' => (int) $pageEntry], $persistedAssessorParams))); ?>"><?php echo (int) $pageEntry; ?></a>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<li class="page-item<?php echo $todosPage >= $todosTotalPages ? ' disabled' : ''; ?>">
|
||||
<?php if ($todosPage >= $todosTotalPages): ?>
|
||||
<span class="page-link">»</span>
|
||||
<?php else: ?>
|
||||
<a class="page-link" href="<?php echo htmlspecialchars(cc_test_build_url('gestiones_callcenter.php', array_merge(['view' => 'todos', 'store' => $storeKey, 'page' => $todosPage + 1], $persistedAssessorParams))); ?>" aria-label="Siguiente">»</a>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php if (!empty($modalsHtml)): ?>
|
||||
<?php echo implode("
|
||||
", $modalsHtml); ?>
|
||||
<?php if (is_resource($modalsHtml)): ?>
|
||||
<?php rewind($modalsHtml); fpassthru($modalsHtml); fclose($modalsHtml); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="modal fade" id="ccAssessorColorModal" tabindex="-1" aria-labelledby="ccAssessorColorModalLabel" aria-hidden="true">
|
||||
|
||||
@ -868,7 +868,7 @@ foreach ($videos as $v) {
|
||||
<div class="modal fade" id="gestionarVideoModal" tabindex="-1" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<form action="save_marketing_video.php" method="POST">
|
||||
<form action="save_marketing_video.php" method="POST" enctype="multipart/form-data">
|
||||
<input type="hidden" name="action" value="update">
|
||||
<input type="hidden" name="id" id="edit_id">
|
||||
<div class="modal-header">
|
||||
@ -896,6 +896,21 @@ foreach ($videos as $v) {
|
||||
<label class="form-label">Fecha Entrega</label>
|
||||
<input type="date" name="fecha_entrega" id="edit_fecha_entrega" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<label class="form-label">Foto del producto</label>
|
||||
<div class="row g-3 align-items-center">
|
||||
<div class="col-md-4">
|
||||
<div class="border rounded-3 bg-light p-2 text-center">
|
||||
<img id="edit_foto_producto_preview" src="" alt="Foto actual del producto" class="img-fluid rounded d-none" style="max-height: 180px; object-fit: cover;">
|
||||
<div id="edit_foto_producto_placeholder" class="text-muted small py-5">Sin foto actual</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<input type="file" name="foto_producto" id="edit_foto_producto" class="form-control" accept="image/*">
|
||||
<div class="form-text">Sube una nueva foto para reemplazar la actual. Si no eliges una, se conserva la imagen existente.</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Material</label>
|
||||
<input type="text" name="material" id="edit_material" class="form-control">
|
||||
@ -1087,6 +1102,37 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const savedView = localStorage.getItem('video_production_view') || 'table';
|
||||
switchView(savedView);
|
||||
|
||||
const editFotoInput = document.getElementById('edit_foto_producto');
|
||||
const editFotoPreview = document.getElementById('edit_foto_producto_preview');
|
||||
const editFotoPlaceholder = document.getElementById('edit_foto_producto_placeholder');
|
||||
|
||||
if (editFotoInput && editFotoPreview && editFotoPlaceholder) {
|
||||
editFotoInput.addEventListener('change', function() {
|
||||
const file = this.files && this.files[0];
|
||||
if (file) {
|
||||
const objectUrl = URL.createObjectURL(file);
|
||||
editFotoPreview.src = objectUrl;
|
||||
editFotoPreview.classList.remove('d-none');
|
||||
editFotoPlaceholder.classList.add('d-none');
|
||||
editFotoPreview.onload = function() {
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
const currentSrc = editFotoPreview.dataset.currentSrc || '';
|
||||
if (currentSrc) {
|
||||
editFotoPreview.src = currentSrc;
|
||||
editFotoPreview.classList.remove('d-none');
|
||||
editFotoPlaceholder.classList.add('d-none');
|
||||
} else {
|
||||
editFotoPreview.removeAttribute('src');
|
||||
editFotoPreview.classList.add('d-none');
|
||||
editFotoPlaceholder.classList.remove('d-none');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const observationInputs = document.querySelectorAll('.observation-input');
|
||||
observationInputs.forEach(input => {
|
||||
let lastSavedValue = input.value;
|
||||
@ -1263,6 +1309,26 @@ function gestionarVideo(video) {
|
||||
document.getElementById('edit_orden').value = video.orden || 0;
|
||||
document.getElementById('edit_fecha_entrega').value = video.fecha_entrega || '';
|
||||
document.getElementById('edit_material').value = video.material || '';
|
||||
|
||||
const editFotoInput = document.getElementById('edit_foto_producto');
|
||||
const editFotoPreview = document.getElementById('edit_foto_producto_preview');
|
||||
const editFotoPlaceholder = document.getElementById('edit_foto_producto_placeholder');
|
||||
if (editFotoInput) {
|
||||
editFotoInput.value = '';
|
||||
}
|
||||
if (editFotoPreview && editFotoPlaceholder) {
|
||||
const currentPhoto = video.foto_producto || '';
|
||||
editFotoPreview.dataset.currentSrc = currentPhoto;
|
||||
if (currentPhoto) {
|
||||
editFotoPreview.src = currentPhoto;
|
||||
editFotoPreview.classList.remove('d-none');
|
||||
editFotoPlaceholder.classList.add('d-none');
|
||||
} else {
|
||||
editFotoPreview.removeAttribute('src');
|
||||
editFotoPreview.classList.add('d-none');
|
||||
editFotoPlaceholder.classList.remove('d-none');
|
||||
}
|
||||
}
|
||||
|
||||
// Llenar links dinámicos
|
||||
const fillLinks = (containerId, inputName, data) => {
|
||||
|
||||
@ -7,6 +7,52 @@ if (!isset($_SESSION['user_id'])) {
|
||||
exit();
|
||||
}
|
||||
|
||||
function marketing_store_video_photo(?array $file, ?string $currentPath = null): ?string
|
||||
{
|
||||
if ($file === null || !isset($file['error']) || $file['error'] === UPLOAD_ERR_NO_FILE) {
|
||||
return $currentPath;
|
||||
}
|
||||
|
||||
if ($file['error'] !== UPLOAD_ERR_OK) {
|
||||
return $currentPath;
|
||||
}
|
||||
|
||||
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
|
||||
$mimeType = $file['type'] ?? '';
|
||||
if (!in_array($mimeType, $allowedTypes, true)) {
|
||||
return $currentPath;
|
||||
}
|
||||
|
||||
$target_dir = 'assets/uploads/marketing_images/';
|
||||
if (!is_dir($target_dir)) {
|
||||
mkdir($target_dir, 0777, true);
|
||||
}
|
||||
|
||||
$file_extension = strtolower(pathinfo($file['name'] ?? '', PATHINFO_EXTENSION));
|
||||
if ($file_extension === '') {
|
||||
$mimeExtensions = [
|
||||
'image/jpeg' => 'jpg',
|
||||
'image/png' => 'png',
|
||||
'image/gif' => 'gif',
|
||||
'image/webp' => 'webp',
|
||||
];
|
||||
$file_extension = $mimeExtensions[$mimeType] ?? 'jpg';
|
||||
}
|
||||
|
||||
$file_name = uniqid('video_', true) . '.' . $file_extension;
|
||||
$target_file = $target_dir . $file_name;
|
||||
|
||||
if (!move_uploaded_file($file['tmp_name'], $target_file)) {
|
||||
return $currentPath;
|
||||
}
|
||||
|
||||
if (!empty($currentPath) && $currentPath !== $target_file && file_exists($currentPath)) {
|
||||
@unlink($currentPath);
|
||||
}
|
||||
|
||||
return $target_file;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$db = db();
|
||||
$action = $_POST['action'] ?? 'create';
|
||||
@ -15,7 +61,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
// Lógica para actualizar (Editora o Tú)
|
||||
$id = $_POST['id'];
|
||||
$estado = $_POST['estado'];
|
||||
|
||||
|
||||
$link_video = '';
|
||||
if (isset($_POST['link_video'])) {
|
||||
$link_video = is_array($_POST['link_video']) ? implode(',', array_filter($_POST['link_video'])) : $_POST['link_video'];
|
||||
@ -34,25 +80,31 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$material = $_POST['material'] ?? '';
|
||||
$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'];
|
||||
}
|
||||
|
||||
$stmt_current = $db->prepare("SELECT foto_producto FROM marketing_videos WHERE id = ?");
|
||||
$stmt_current->execute([$id]);
|
||||
$current_photo = $stmt_current->fetchColumn();
|
||||
$foto_path = marketing_store_video_photo($_FILES['foto_producto'] ?? null, is_string($current_photo) && $current_photo !== '' ? $current_photo : null);
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("UPDATE marketing_videos SET
|
||||
estado = ?,
|
||||
foto_producto = ?,
|
||||
link_video = ?,
|
||||
link_landing = ?,
|
||||
link_flyer = ?,
|
||||
@ -64,16 +116,17 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
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,
|
||||
$estado,
|
||||
$foto_path,
|
||||
$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';
|
||||
@ -87,17 +140,17 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$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'];
|
||||
@ -119,22 +172,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
$foto_path = marketing_store_video_photo($_FILES['foto_producto'] ?? null, null);
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("INSERT INTO marketing_videos (
|
||||
@ -153,14 +191,14 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
link_landing
|
||||
) VALUES (?, ?, ?, ?, 'PENDIENTE', ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([
|
||||
$producto_id,
|
||||
$foto_path,
|
||||
$material,
|
||||
$instrucciones,
|
||||
$fecha_entrega,
|
||||
$orden,
|
||||
$angulo_video,
|
||||
$link_inspiracion_landing,
|
||||
$producto_id,
|
||||
$foto_path,
|
||||
$material,
|
||||
$instrucciones,
|
||||
$fecha_entrega,
|
||||
$orden,
|
||||
$angulo_video,
|
||||
$link_inspiracion_landing,
|
||||
$link_inspiracion_video,
|
||||
$link_flyer,
|
||||
$link_video,
|
||||
@ -182,4 +220,4 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user