38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../includes/admin_bootstrap.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
redirect(BASE_URL . '/admin/qrs.php');
|
|
}
|
|
|
|
set_time_limit(600);
|
|
|
|
$root = dirname(__DIR__);
|
|
$python = trim(shell_exec('which python3') ?: 'python3');
|
|
$script = $root . '/generate_qrs.py';
|
|
|
|
// Actualizar qr_data.csv antes de generar
|
|
require_once __DIR__ . '/../config/database.php';
|
|
$db = getDB();
|
|
$rows = $db->query('
|
|
SELECT u.codigo, m.nombre AS modulo, u.nombre AS ubicacion
|
|
FROM ubicaciones u JOIN modulos m ON m.id = u.modulo_id
|
|
WHERE u.activo = 1 ORDER BY u.codigo
|
|
')->fetchAll();
|
|
$fh = fopen($root . '/qr_data.csv', 'w');
|
|
fputcsv($fh, ['codigo', 'modulo', 'ubicacion', 'url']);
|
|
foreach ($rows as $r) {
|
|
fputcsv($fh, [$r['codigo'], $r['modulo'], $r['ubicacion'], BASE_URL . '/formulario.php?u=' . $r['codigo']]);
|
|
}
|
|
fclose($fh);
|
|
|
|
$cmd = escapeshellarg($python) . ' ' . escapeshellarg($script) . ' 2>&1';
|
|
$output = shell_exec($cmd);
|
|
|
|
if ($output !== null && str_contains($output, 'Listo!')) {
|
|
flash('success', trim(preg_replace('/\s+/', ' ', $output)));
|
|
} else {
|
|
flash('danger', 'Error al generar QR: ' . ($output ?: 'sin salida del script'));
|
|
}
|
|
|
|
redirect(BASE_URL . '/admin/qrs.php');
|