Refactor fxImportResultatsComIdForEve to use org_id instead of com_id for event sharing templates in MSIN-4482. Update SQL queries and comments for clarity. Ensure compatibility with legacy data structures. Increment version code.

This commit is contained in:
2026-07-24 15:44:25 -04:00
parent 1ca75a4ed4
commit a1b6fa8911
2 changed files with 21 additions and 11 deletions

View File

@ -142,18 +142,22 @@ function fxImportResultatsGuessField($strHeader) {
return $tabCandidates[0]['key'];
}
/**
* Clé de partage templates entre événements du même org (pas de com_id sur evenements).
* MSIN-4482 — stockée dans inscriptions_import_templates.com_id (legacy name = org_id).
*/
function fxImportResultatsComIdForEve($intEveId) {
global $objDatabase;
$intEveId = intval($intEveId);
if ($intEveId <= 0) {
return 0;
}
$sql = "SELECT com_id FROM inscriptions_evenements WHERE eve_id = " . $intEveId . " LIMIT 1";
$sql = "SELECT org_id FROM inscriptions_evenements WHERE eve_id = " . $intEveId . " LIMIT 1";
$tab = $objDatabase->fxGetResults($sql);
if (!is_array($tab) || empty($tab[1]['com_id'])) {
if (!is_array($tab) || empty($tab[1]['org_id'])) {
return 0;
}
return intval($tab[1]['com_id']);
return intval($tab[1]['org_id']);
}
function fxImportResultatsEpreuvesList($intEveId) {
@ -188,7 +192,8 @@ function fxImportResultatsEpreuvesList($intEveId) {
function fxImportResultatsQuestionsList($intEveId) {
global $objDatabase;
$intEveId = intval($intEveId);
$sql = "SELECT que_id, que_question_fr, que_rapport_label_fr, que_actif"
// que_rapport_label_fr peut manquer sur vieux schémas — fallback question seule
$sql = "SELECT que_id, que_question_fr, que_actif"
. " FROM inscriptions_questions WHERE eve_id = " . $intEveId
. " AND que_actif = 1 ORDER BY que_tri, que_id";
$tab = $objDatabase->fxGetResults($sql);
@ -197,10 +202,7 @@ function fxImportResultatsQuestionsList($intEveId) {
return $tabOut;
}
for ($i = 1; $i <= count($tab); $i++) {
$strLabel = trim((string)($tab[$i]['que_rapport_label_fr'] ?? ''));
if ($strLabel === '') {
$strLabel = trim((string)($tab[$i]['que_question_fr'] ?? ''));
}
$strLabel = trim((string)($tab[$i]['que_question_fr'] ?? ''));
$tabOut[] = array(
'que_id' => intval($tab[$i]['que_id']),
'label' => $strLabel !== '' ? $strLabel : ('Question #' . intval($tab[$i]['que_id'])),
@ -471,12 +473,20 @@ function fxImportResultatsFindTemplates($intEveId, $strSig) {
global $objDatabase;
$intEveId = intval($intEveId);
$strSig = preg_replace('/[^a-f0-9]/', '', strtolower((string)$strSig));
$intComId = fxImportResultatsComIdForEve($intEveId);
$intOrgId = fxImportResultatsComIdForEve($intEveId);
// Table absente (SQL pas encore joué) → pas d'erreur HTML dans le JSON AJAX
$sqlCheck = "SELECT 1 AS ok FROM information_schema.TABLES"
. " WHERE TABLE_SCHEMA = DATABASE()"
. " AND TABLE_NAME = 'inscriptions_import_templates' LIMIT 1";
$tabCheck = $objDatabase->fxGetResults($sqlCheck);
if (!is_array($tabCheck) || empty($tabCheck[1]['ok'])) {
return array();
}
$sql = "SELECT tpl_id, eve_id, com_id, tpl_name, tpl_header_sig, tpl_mapping_json, tpl_maj"
. " FROM inscriptions_import_templates"
. " WHERE tpl_actif = 1 AND tpl_header_sig = '" . addslashes($strSig) . "'"
. " AND (eve_id = " . $intEveId
. ($intComId > 0 ? (" OR com_id = " . $intComId) : '')
. ($intOrgId > 0 ? (" OR com_id = " . $intOrgId) : '')
. ")"
. " ORDER BY (eve_id = " . $intEveId . ") DESC, tpl_maj DESC LIMIT 20";
$tab = $objDatabase->fxGetResults($sql);

View File

@ -8,7 +8,7 @@ SET @db := DATABASE();
CREATE TABLE IF NOT EXISTS `inscriptions_import_templates` (
`tpl_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`eve_id` int(10) unsigned NOT NULL DEFAULT 0,
`com_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'MSIN-4482 — 0 = lié événement ; >0 = réutilisable côté client',
`com_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'MSIN-4482 — org_id evenement (partage templates même org) ; pas com_id compte',
`tpl_name` varchar(120) NOT NULL DEFAULT '',
`tpl_header_sig` char(40) NOT NULL DEFAULT '' COMMENT 'sha1 en-têtes normalisés',
`tpl_headers_json` mediumtext NOT NULL,