AutoFiller_QR_Campamento/admin/generate_qrs.php

26 lines
742 B
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__);
require_once __DIR__ . '/../config/database.php';
regenerateQrCsv(getDB());
$python = trim(shell_exec('which python3') ?: 'python3');
$script = $root . '/generate_qrs.py';
$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');