Files
ms1inscription-v5/ms1_kc_qr_batch.php
stephan 3e3a0f1de7 Add static sync functionality and update UI for development tools
This commit introduces the `fxAdminStaticSyncAllowed` function to control access to static database synchronization tools, ensuring only authorized users in development and pre-production environments can access them. The UI is updated to display a new section for these tools in the admin interface, enhancing the overall user experience and access management for development tasks. Additionally, the `.gitignore` file is updated to exclude the `/output/` directory from version control.
2026-06-22 14:08:16 -04:00

135 lines
4.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Génération par lot de QR codes key_chain (kc.php?param1=...).
*
* CLI:
* php ms1_kc_qr_batch.php --start=500 --count=100
*
* Web (protégé par KEYCHAIN_HTTP_EDIT_SECRET):
* /ms1_kc_qr_batch.php?k=<secret>&start=500&count=100
*/
$blnNoMaintenance = true;
function kc_qr_batch_is_cli()
{
return (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg');
}
if (kc_qr_batch_is_cli()) {
require_once __DIR__ . '/php/inc_settings.php';
} else {
require_once __DIR__ . '/php/inc_fonctions.php';
header('X-Robots-Tag: noindex, nofollow');
}
require_once __DIR__ . '/php/inc_fx_kc_qr.php';
function kc_qr_batch_params()
{
$source = kc_qr_batch_is_cli() ? kc_qr_batch_cli_args() : $_GET;
return [
'start' => isset($source['start']) ? intval($source['start']) : 500,
'count' => isset($source['count']) ? intval($source['count']) : 100,
'base_url' => isset($source['base_url']) ? trim((string) $source['base_url']) : 'https://ms1inscription.com',
'module_size' => isset($source['module_size']) ? intval($source['module_size']) : 18,
'with_logo' => !isset($source['with_logo']) || (string) $source['with_logo'] !== '0',
'output_dir' => isset($source['output_dir']) ? trim((string) $source['output_dir']) : (__DIR__ . '/output/kc_qr'),
];
}
function kc_qr_batch_cli_args()
{
global $argv;
$params = [];
if (!is_array($argv)) {
return $params;
}
foreach (array_slice($argv, 1) as $arg) {
if (strpos($arg, '--') !== 0) {
continue;
}
$pair = explode('=', substr($arg, 2), 2);
$params[$pair[0]] = $pair[1] ?? '1';
}
return $params;
}
function kc_qr_batch_web_authorized()
{
$strSecret = isset($_GET['k']) ? (string) $_GET['k'] : '';
return ($strSecret !== '' && defined('KEYCHAIN_HTTP_EDIT_SECRET') && hash_equals(KEYCHAIN_HTTP_EDIT_SECRET, $strSecret));
}
if (!kc_qr_batch_is_cli()) {
if (!kc_qr_batch_web_authorized()) {
http_response_code(403);
echo 'Accès refusé.';
exit;
}
}
$params = kc_qr_batch_params();
if ($params['count'] < 1 || $params['count'] > 500) {
$msg = 'Le paramètre count doit être entre 1 et 500.';
if (kc_qr_batch_is_cli()) {
fwrite(STDERR, $msg . PHP_EOL);
exit(1);
}
http_response_code(400);
echo $msg;
exit;
}
$result = fxKcQrGenerateBatch($params);
if (kc_qr_batch_is_cli()) {
echo 'QR codes générés: ' . $result['count'] . PHP_EOL;
echo 'Plage param1: ' . $result['start'] . ' → ' . $result['end'] . PHP_EOL;
echo 'Dossier: ' . $result['output_dir'] . PHP_EOL;
echo 'Manifeste: ' . $result['manifest'] . PHP_EOL;
exit(0);
}
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex, nofollow">
<title>QR key_chain — génération</title>
<style>
body { font-family: "Segoe UI", sans-serif; max-width: 720px; margin: 2rem auto; padding: 0 1rem; color: #1a1a2e; }
.ok { background: #e6f4ed; border: 1px solid #b8e6d0; padding: 1rem; border-radius: 12px; }
code { background: #f3f4f6; padding: 0.15rem 0.35rem; border-radius: 4px; }
ul { padding-left: 1.2rem; }
</style>
</head>
<body>
<h1>QR codes générés</h1>
<div class="ok">
<p><strong><?php echo (int) $result['count']; ?></strong> fichiers créés
(param1 <?php echo (int) $result['start']; ?> → <?php echo (int) $result['end']; ?>).</p>
<p>Dossier serveur : <code><?php echo htmlspecialchars($result['output_dir'], ENT_QUOTES, 'UTF-8'); ?></code></p>
<p>Manifeste CSV : <code><?php echo htmlspecialchars(basename($result['manifest']), ENT_QUOTES, 'UTF-8'); ?></code></p>
</div>
<h2>Exemples</h2>
<ul>
<?php
$preview = array_slice($result['files'], 0, 6);
foreach ($preview as $file) {
$name = basename($file);
echo '<li><code>' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8') . '</code></li>';
}
if (count($result['files']) > 6) {
echo '<li>… et ' . (count($result['files']) - 6) . ' autres</li>';
}
?>
</ul>
<p>Relancer avec dautres paramètres :
<code>?k=…&amp;start=<?php echo (int) $params['start']; ?>&amp;count=<?php echo (int) $params['count']; ?></code></p>
</body>
</html>