Files
ms1inscription-v5/php/inc_v2_assets.php

172 lines
8.3 KiB
PHP

<?php
/**
* MSIN-4435 — Assets JS modules v2 (hors inc_footer_scripts.php legacy).
* Bib v4, gestion inscriptions v2 : chargés uniquement sur leurs pages.
*/
if (!function_exists('fxV2RegisterScript')) {
/** @param string $strName bib-assignments | inscr-gestion | promoteur-hub */
function fxV2RegisterScript($strName) {
global $MS1_V2_SCRIPTS;
if (!isset($MS1_V2_SCRIPTS) || !is_array($MS1_V2_SCRIPTS)) {
$MS1_V2_SCRIPTS = [];
}
if (!in_array($strName, $MS1_V2_SCRIPTS, true)) {
$MS1_V2_SCRIPTS[] = $strName;
}
}
/** Config injectée dans window.MS1_V2_PROMOTEUR_HUB avant promoteur-hub.js */
function fxV2PromoteurHubConfig($strLangue) {
global $vDomaine;
$strLangue = ($strLangue === 'en') ? 'en' : 'fr';
$strWait = afficheTexte('preloader_wait', 0, 0, 1);
if (trim((string)$strWait) === '' || $strWait === 'preloader_wait' || $strWait === '*preloader_wait*') {
$strWait = function_exists('fxPromoteurHubTexte')
? fxPromoteurHubTexte('promoteur_hub_load_dashboard', 0)
: '';
}
// MSIN-4401 — libellés Info injectés (pas de FR/EN en dur dans promoteur-hub.js).
$strAjaxError = function_exists('fxPromoteurHubTexte')
? fxPromoteurHubTexte('promoteur_hub_ajax_error', 0)
: afficheTexte('promoteur_hub_ajax_error', 0, 0, 1);
return [
'ajaxUrl' => $vDomaine . '/ajax_promoteur_hub.php',
'preloaderWait' => $strWait,
// MSIN-4399 — Ouvrir automatiquement la carte de cet événement au chargement.
'focusEveId' => function_exists('fxPromoteurHubParseFocusEveId')
? fxPromoteurHubParseFocusEveId()
: 0,
'i18n' => [
'ajaxError' => $strAjaxError,
],
];
}
/** Config injectée dans window.MS1_V2_INSCR_GESTION avant inscr-gestion.js */
function fxV2InscrGestionConfig($strLangue) {
global $vDomaine;
$strLangue = ($strLangue === 'en') ? 'en' : 'fr';
return [
'domain' => $vDomaine,
'lang' => $strLangue,
// MSIN-4401 — true = OCR dossard via serveur (Vision), pas Tesseract local.
'bibOcrCloud' => function_exists('fxInscrGestionBibOcrCloudEnabled')
? (bool)fxInscrGestionBibOcrCloudEnabled()
: false,
'preloaderWait' => afficheTexte('preloader_wait', 0, 0, 1),
'refundCancelHint' => function_exists('fxInscrGestionT')
? fxInscrGestionT('inscr_gestion_refund_cancel_hint')
: '',
'loginMessages' => [
'txt_login' => function_exists('fxInscrGestionT')
? fxInscrGestionT('inscr_gestion_login_err_user')
: '',
'txt_password' => function_exists('fxInscrGestionT')
? fxInscrGestionT('inscr_gestion_login_err_pass')
: '',
],
// MSIN-4401 — libellés Info injectés (pas de FR/EN en dur dans le JS).
'i18n' => function_exists('fxInscrGestionT') ? [
'errLoad' => fxInscrGestionT('inscr_gestion_err_load'),
'errNetwork' => fxInscrGestionT('inscr_gestion_err_network'),
'errRefund' => fxInscrGestionT('inscr_gestion_err_refund'),
'refundOk' => fxInscrGestionT('inscr_gestion_refund_ok'),
'bibOcrNotConfigured' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_bib_ocr_not_configured')
: fxInscrGestionT('inscr_gestion_bib_ocr_not_configured'),
'bibOcrVisionPrefix' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_bib_ocr_vision_prefix')
: fxInscrGestionT('inscr_gestion_bib_ocr_vision_prefix'),
'bibOcrImageInvalid' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_bib_ocr_image_invalid')
: fxInscrGestionT('inscr_gestion_bib_ocr_image_invalid'),
'bibOcrNetwork' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_bib_ocr_network')
: fxInscrGestionT('inscr_gestion_bib_ocr_network'),
'bibOcrUnreadable' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_bib_scan_invalid')
: fxInscrGestionT('inscr_gestion_bib_scan_invalid'),
'bibScanScanning' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_bib_scan_scanning')
: '',
'bibScanLoading' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_bib_scan_loading')
: '',
'bibScanReady' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_bib_scan_ready')
: '',
'bibScanFound' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_bib_scan_found')
: '',
'bibScanFoundSearch' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_bib_scan_found_search')
: '',
'bibScanInvalid' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_bib_scan_invalid')
: '',
'bibScanCamera' => function_exists('fxInscrGestionScanLabel')
? fxInscrGestionScanLabel('inscr_gestion_qr_camera_error')
: '',
// MSIN-4448 — Remis inline liste (confirmation retrait).
'remisConfirmTitle' => fxInscrGestionT('inscr_gestion_remis_confirm_title'),
'remisConfirmMsg' => fxInscrGestionT('inscr_gestion_remis_confirm_msg'),
'remisConfirmOk' => fxInscrGestionT('inscr_gestion_remis_confirm_ok'),
'remisConfirmCancel' => fxInscrGestionT('inscr_gestion_remis_confirm_cancel'),
] : [],
// MSIN-4448 — Operateur pour no_bib_remis_par (chemin superadm / usa_id).
'remisOperator' => [
'par_id' => intval($_SESSION['com_info']['com_id'] ?? ($_SESSION['com_id'] ?? 0)),
'par' => trim(
(string)($_SESSION['com_info']['com_prenom'] ?? '')
. ' '
. (string)($_SESSION['com_info']['com_nom'] ?? '')
),
],
];
}
/** À appeler dans inc_footer.php après inc_footer_scripts.php */
function fxV2RenderFooterScripts() {
global $MS1_V2_SCRIPTS, $vDomaine, $strLangue;
if (empty($MS1_V2_SCRIPTS) || !is_array($MS1_V2_SCRIPTS)) {
return;
}
$mapFiles = [
'bib-assignments' => '/js/v2/bib-assignments.js',
'inscr-gestion' => '/js/v2/inscr-gestion.js',
'promoteur-hub' => '/js/v2/promoteur-hub.js',
];
if (in_array('promoteur-hub', $MS1_V2_SCRIPTS, true)) {
$cfg = fxV2PromoteurHubConfig($strLangue ?? 'fr');
echo '<script>window.MS1_V2_PROMOTEUR_HUB='
. json_encode($cfg, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP)
. ';</script>' . "\n";
}
if (in_array('inscr-gestion', $MS1_V2_SCRIPTS, true)) {
$cfg = fxV2InscrGestionConfig($strLangue ?? 'fr');
echo '<script>window.MS1_V2_INSCR_GESTION='
. json_encode($cfg, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP)
. ';</script>' . "\n";
}
foreach ($MS1_V2_SCRIPTS as $strName) {
if (!isset($mapFiles[$strName])) {
continue;
}
$strSrc = htmlspecialchars($vDomaine . $mapFiles[$strName], ENT_QUOTES, 'UTF-8');
echo '<script src="' . $strSrc . '?v=' . htmlspecialchars(_VERSION_CODE, ENT_QUOTES, 'UTF-8') . '"></script>' . "\n";
}
}
}