MSIN-3487 — Enhance kc.php to support QR short link entry for event results and key chains. Implement redirection based on event ID and improve database query handling. Update inc_fonctions.php to include extra event functions. Increment version code.
This commit is contained in:
65
kc.php
65
kc.php
@ -1,39 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* MSIN-3487 — Point d'entrée QR court.
|
||||
*
|
||||
* Modes :
|
||||
* 1) Résultats événement :
|
||||
* /kc.php?t=eve&id={eve_id}
|
||||
* → inscriptions_evenements_extra.eve_resultats_url
|
||||
* → sinon fallback https://ms1.ca
|
||||
*
|
||||
* 2) Key chain (porte-clés / véhicules) — inchangé :
|
||||
* /kc.php?param1={pk_key_chain}
|
||||
* → key_chain.key_chain_http
|
||||
* → sinon insert + fallback https://ms1.ca
|
||||
*/
|
||||
session_start();
|
||||
global $objDatabase, $vDomaine, $strLangue;
|
||||
require_once "php/inc_fonctions.php";
|
||||
require_once 'php/inc_fonctions.php';
|
||||
|
||||
if (!empty($_GET['param1']))
|
||||
$key_chain_id = $_GET['param1'];
|
||||
else
|
||||
$key_chain_id = 0;
|
||||
$defaut_landingpage="https://ms1.ca";
|
||||
$strType = isset($_GET['t']) ? strtolower(trim((string) $_GET['t'])) : '';
|
||||
|
||||
$sqlkey_chain = "SELECT * FROM key_chain WHERE pk_key_chain = " . $key_chain_id ;
|
||||
// --- MSIN-3487 : redirect résultats par eve_id ---
|
||||
if ($strType === 'eve') {
|
||||
$intEveId = 0;
|
||||
if (isset($_GET['id'])) {
|
||||
$intEveId = intval($_GET['id']);
|
||||
} elseif (isset($_GET['eve_id'])) {
|
||||
$intEveId = intval($_GET['eve_id']);
|
||||
}
|
||||
|
||||
header('Location: ' . fxEveExtraResolveResultatsUrl($intEveId));
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- Key chain historique ---
|
||||
$key_chain_id = !empty($_GET['param1']) ? intval($_GET['param1']) : 0;
|
||||
$defaut_landingpage = fxEveExtraResultatsFallbackUrl();
|
||||
|
||||
$sqlkey_chain = 'SELECT * FROM key_chain WHERE pk_key_chain = ' . $key_chain_id;
|
||||
$infoCompte = $objDatabase->fxGetRow($sqlkey_chain);
|
||||
if (!$infoCompte == null) {
|
||||
|
||||
$mem_count = $infoCompte['key_chain_count'] + 1;
|
||||
$update_plus="";
|
||||
$update_plus = '';
|
||||
if ($infoCompte['key_chain_com_id'] == 0 && isset($_SESSION['com_id'])) {
|
||||
$update_plus="key_chain_com_id=".$_SESSION['com_id'].",";}
|
||||
$update_plus = 'key_chain_com_id=' . intval($_SESSION['com_id']) . ',';
|
||||
}
|
||||
|
||||
$sqlUpdate = "UPDATE key_chain SET ".$update_plus."key_chain_adress_ip='". $_SERVER['REMOTE_ADDR'] ."',key_chain_count = ".$mem_count." WHERE pk_key_chain = " . $key_chain_id ;
|
||||
$sqlUpdate = 'UPDATE key_chain SET ' . $update_plus
|
||||
. "key_chain_adress_ip='" . $objDatabase->fxEscape($_SERVER['REMOTE_ADDR']) . "',"
|
||||
. 'key_chain_count = ' . intval($mem_count)
|
||||
. ' WHERE pk_key_chain = ' . $key_chain_id;
|
||||
$qryUpdate = $objDatabase->fxQuery($sqlUpdate);
|
||||
|
||||
header("Location: ".$infoCompte['key_chain_http']);
|
||||
header('Location: ' . $infoCompte['key_chain_http']);
|
||||
} else {
|
||||
if (isset($_SESSION['com_id'])) {
|
||||
$mem_com_id=$_SESSION['com_id'];
|
||||
$mem_com_id = intval($_SESSION['com_id']);
|
||||
} else {
|
||||
$mem_com_id = 0;
|
||||
}
|
||||
|
||||
|
||||
$sqlUpdate = "insert key_chain SET key_chain_com_id=".$mem_com_id.",key_chain_timestamp=now(),key_chain_http='".$defaut_landingpage."',key_chain_adress_ip='". $_SERVER['REMOTE_ADDR'] ."',key_chain_count = 1,pk_key_chain=" . $key_chain_id;
|
||||
$sqlUpdate = 'INSERT key_chain SET key_chain_com_id=' . $mem_com_id
|
||||
. ',key_chain_timestamp=now(),'
|
||||
. "key_chain_http='" . $objDatabase->fxEscape($defaut_landingpage) . "',"
|
||||
. "key_chain_adress_ip='" . $objDatabase->fxEscape($_SERVER['REMOTE_ADDR']) . "',"
|
||||
. 'key_chain_count = 1,pk_key_chain=' . $key_chain_id;
|
||||
$qryUpdate = $objDatabase->fxQuery($sqlUpdate);
|
||||
|
||||
header("Location: $defaut_landingpage" );
|
||||
header('Location: ' . $defaut_landingpage);
|
||||
}
|
||||
exit;
|
||||
|
||||
@ -12,6 +12,7 @@ include_once APPLICATION_PATH . 'php/inc_mysql.php';
|
||||
include_once APPLICATION_PATH . 'php/inc_dates.php';
|
||||
include_once APPLICATION_PATH . 'php/inc_mail.php';
|
||||
include_once APPLICATION_PATH . 'php/inc_fx_memberships.php';
|
||||
include_once APPLICATION_PATH . 'php/inc_fx_eve_extra.php'; // MSIN-3487 — extra événement (lien résultats, etc.)
|
||||
include_once APPLICATION_PATH . 'php/inc_fx_liste_attente.php';// inclure les fonctions des abonemennts
|
||||
include_once APPLICATION_PATH . 'php/recaptcha.class.php';
|
||||
|
||||
|
||||
123
php/inc_fx_eve_extra.php
Normal file
123
php/inc_fx_eve_extra.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* MSIN-3487 — Métadonnées supplémentaires d'événement
|
||||
* (table inscriptions_evenements_extra).
|
||||
*
|
||||
* Fonctions indépendantes : utilisables depuis kc.php, impression dossards,
|
||||
* hub promoteur, etc. Ne pas mélanger avec key_chain (QR physiques).
|
||||
*/
|
||||
|
||||
/**
|
||||
* URL de repli si aucun lien résultats n'est configuré pour l'événement.
|
||||
* Aligné sur le défaut historique de kc.php / key_chain.
|
||||
*/
|
||||
function fxEveExtraResultatsFallbackUrl()
|
||||
{
|
||||
return 'https://ms1.ca';
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit la ligne extra d'un événement (ou null).
|
||||
*
|
||||
* @param int $intEveId
|
||||
* @return array|null
|
||||
*/
|
||||
function fxEveExtraGetRow($intEveId)
|
||||
{
|
||||
global $objDatabase;
|
||||
|
||||
$intEveId = intval($intEveId);
|
||||
if ($intEveId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sql = 'SELECT * FROM inscriptions_evenements_extra WHERE eve_id = ' . $intEveId . ' LIMIT 1';
|
||||
$tabRow = $objDatabase->fxGetRow($sql);
|
||||
|
||||
return ($tabRow === null || $tabRow === false) ? null : $tabRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le lien résultats brut, ou null s'il est absent / vide.
|
||||
*
|
||||
* @param int $intEveId
|
||||
* @return string|null
|
||||
*/
|
||||
function fxEveExtraGetResultatsUrl($intEveId)
|
||||
{
|
||||
$tabRow = fxEveExtraGetRow($intEveId);
|
||||
if ($tabRow === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$strUrl = trim((string) ($tabRow['eve_resultats_url'] ?? ''));
|
||||
|
||||
return ($strUrl !== '') ? $strUrl : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lien résultats à utiliser pour une redirection :
|
||||
* URL configurée, sinon fallback (ms1.ca).
|
||||
*
|
||||
* @param int $intEveId
|
||||
* @return string
|
||||
*/
|
||||
function fxEveExtraResolveResultatsUrl($intEveId)
|
||||
{
|
||||
$strUrl = fxEveExtraGetResultatsUrl($intEveId);
|
||||
|
||||
return ($strUrl !== null) ? $strUrl : fxEveExtraResultatsFallbackUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée ou met à jour le lien résultats pour un événement.
|
||||
*
|
||||
* @param int $intEveId
|
||||
* @param string $strUrl Chaîne vide = effacer le lien (NULL en BD)
|
||||
* @return bool
|
||||
*/
|
||||
function fxEveExtraSetResultatsUrl($intEveId, $strUrl)
|
||||
{
|
||||
global $objDatabase;
|
||||
|
||||
$intEveId = intval($intEveId);
|
||||
if ($intEveId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$strUrl = trim((string) $strUrl);
|
||||
if ($strUrl === '') {
|
||||
$strSqlUrl = 'NULL';
|
||||
} else {
|
||||
$strSqlUrl = "'" . $objDatabase->fxEscape($strUrl) . "'";
|
||||
}
|
||||
|
||||
// MSIN-3487 — upsert : une ligne max par eve_id
|
||||
$sql = 'INSERT INTO inscriptions_evenements_extra (eve_id, eve_resultats_url, eve_extra_maj)'
|
||||
. ' VALUES (' . $intEveId . ', ' . $strSqlUrl . ', NOW())'
|
||||
. ' ON DUPLICATE KEY UPDATE'
|
||||
. ' eve_resultats_url = VALUES(eve_resultats_url),'
|
||||
. ' eve_extra_maj = NOW()';
|
||||
|
||||
return (bool) $objDatabase->fxQuery($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* URL courte à encoder dans un QR (kc.php redirige vers les résultats).
|
||||
* Exemple : https://ms1inscription.com/kc.php?t=eve&id=760
|
||||
*
|
||||
* @param int $intEveId
|
||||
* @param string|null $strBaseUrl Défaut = $vDomaine
|
||||
* @return string
|
||||
*/
|
||||
function fxKcEveResultatsQrUrl($intEveId, $strBaseUrl = null)
|
||||
{
|
||||
global $vDomaine;
|
||||
|
||||
$intEveId = intval($intEveId);
|
||||
if ($strBaseUrl === null || trim((string) $strBaseUrl) === '') {
|
||||
$strBaseUrl = !empty($vDomaine) ? $vDomaine : 'https://ms1inscription.com';
|
||||
}
|
||||
|
||||
return rtrim($strBaseUrl, '/') . '/kc.php?t=eve&id=' . $intEveId;
|
||||
}
|
||||
24
sql/MSIN-3487-inscriptions-evenements-extra.sql
Normal file
24
sql/MSIN-3487-inscriptions-evenements-extra.sql
Normal file
@ -0,0 +1,24 @@
|
||||
-- MSIN-3487 — Table supplémentaire par événement (lien résultats, etc.)
|
||||
-- Prérequis : aucun
|
||||
-- Notes prod : idempotent (CREATE IF NOT EXISTS) ; pas de FK (pattern projet)
|
||||
--
|
||||
-- IMPORTANT — sélectionner la base AVANT d'exécuter (sinon erreur 1046).
|
||||
-- Décommenter UNE ligne USE ci-dessous selon l'environnement :
|
||||
--
|
||||
-- USE devinscription_preprod;
|
||||
-- USE devinscription_prod;
|
||||
-- USE ms1inscription_preprod;
|
||||
-- USE ms1inscription_prod;
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `inscriptions_evenements_extra` (
|
||||
`eve_id` int(10) unsigned NOT NULL
|
||||
COMMENT 'MSIN-3487 — PK = inscriptions_evenements.eve_id',
|
||||
`eve_resultats_url` varchar(500) DEFAULT NULL
|
||||
COMMENT 'MSIN-3487 — URL publique des résultats de course',
|
||||
`eve_extra_maj` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
|
||||
COMMENT 'MSIN-3487 — dernière mise à jour de la ligne',
|
||||
PRIMARY KEY (`eve_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||
COMMENT='MSIN-3487 — métadonnées supplémentaires d''événement (hors table principale)';
|
||||
Reference in New Issue
Block a user