Files
ms1inscription-v5/ajax_promoteur.php

114 lines
4.0 KiB
PHP

<?php
session_start();
// MSIN-4468 — Les libellés AJAX appartiennent toujours au contexte compte.php.
define('MS1_PROMOTEUR_AJAX', true);
$_SERVER['PHP_SELF'] = '/compte.php';
$_SERVER['SCRIPT_NAME'] = '/compte.php';
$vPage = 'compte.php';
require_once "php/inc_fonctions.php";
include_once("php/inc_fx_modifierinscriptions.php");
require_once "php/inc_fx_promoteur.php";
require_once "php/inc_fx_messages.php";
require_once "php/inc_fx_eve_acces.php";
global $vDomaine;
$strAction = $intEvenement = $intNewNoBib = $intEpreuveCommandee = $intEpreuve = $intPartipcipant = $intQuantite = $strStatutCourse = '';
$strLangue = $_SESSION['lang'] ?? 'fr';
$strQuantiteTotale = '';
if (isset($_REQUEST['a'])) {
$strAction = $_REQUEST['a'];
}
if (isset($_REQUEST['eve_id'])) {
$intEvenement = $_REQUEST['eve_id'];
}
if (isset($_REQUEST['new_no_bib'])) {
$intNewNoBib = $_REQUEST['new_no_bib'];
}
if (isset($_REQUEST['pec_id'])) {
$intEpreuveCommandee = $_REQUEST['pec_id'];
}
if (isset($_REQUEST['epr_id'])) {
$intEpreuve = $_REQUEST['epr_id'];
}
if (isset($_REQUEST['par_id'])) {
$intPartipcipant = $_REQUEST['par_id'];
}
if (isset($_REQUEST['qte'])) {
$intQuantite = $_REQUEST['qte'];
}
if (isset($_REQUEST['total'])) {
$strQuantiteTotale = trim((string)$_REQUEST['total']);
}
if (isset($_REQUEST['lang']) && in_array($_REQUEST['lang'], array('fr', 'en'), true)) {
$strLangue = $_REQUEST['lang'];
}
if (isset($_REQUEST['par_statut_course'])) {
$strStatutCourse = $_REQUEST['par_statut_course'];
}
$vtexte_page = obtenirTextepage($vPage, $strLangue, 2);
$tabRetour = array();
header('Content-Type: application/json; charset=utf-8');
switch($strAction) {
case 'qte':
$tabRetour = fxUpdateQuantites($intEpreuve, $intQuantite, $strLangue);
break;
case 'qte_total':
// MSIN-4468 — Nouvelle convention V4; l'action legacy qte demeure inchangée.
if (!fxBibRequirePromoteurSession()) {
$tabRetour = array('state' => 'error', 'message' => fxBibMsg('bib_v4_ajax_session_invalid'));
break;
}
if (!fxBibValidateCsrf($_POST['csrf_token'] ?? '')) {
$tabRetour = array('state' => 'error', 'message' => fxBibMsg('bib_v4_ajax_unauthorized'));
break;
}
$intEveId = fxBibResolveEveIdFromRequest();
$blnCanEditQte = !empty($_SESSION['usa_id'])
|| (!empty($_SESSION['com_id'])
&& $intEveId > 0
&& fxEveAccesHasPermission($_SESSION['com_id'], $intEveId, 'epreuves.edit_qte'));
if (!$blnCanEditQte) {
$tabRetour = array('state' => 'error', 'message' => fxBibMsg('bib_v4_ajax_unauthorized'));
break;
}
if ($strQuantiteTotale === ''
|| strlen($strQuantiteTotale) > 7
|| !ctype_digit($strQuantiteTotale)) {
$tabRetour = array('state' => 'error', 'message' => afficheTexte('promoteur_bad_qte_update', 0));
break;
}
$tabRetour = fxUpdateQuantiteTotale($intEpreuve, intval($strQuantiteTotale));
if (($tabRetour['state'] ?? 'error') !== 'success') {
if (($tabRetour['error_code'] ?? '') === 'total_below_registrations') {
$tabRetour['message'] = fxBibMsg(
'bib_v5_qte_total_min',
intval($tabRetour['qte_inscrits'] ?? 0)
);
} else {
$tabRetour['message'] = afficheTexte('promoteur_bad_qte_update', 0);
}
}
break;
case 'no_equipe':
case 'no_bib':
$tabRetour = fxSetBibManuel($strAction, $intEvenement, $intNewNoBib, $intEpreuveCommandee, $intEpreuve, $intPartipcipant, $strLangue);
break;
case 'par_statut_course':
$tabRetour = fxSetParStatutCourse($intPartipcipant, $strStatutCourse, $strLangue);
break;
case 'teammates':
$tabRetour = fxShowTeammates($intEvenement, $intEpreuve, $intEpreuveCommandee);
break;
}
unset($_SESSION['msg']);
echo json_encode($tabRetour);