179 lines
6.6 KiB
PHP
179 lines
6.6 KiB
PHP
<?php
|
|
/**
|
|
* MSIN-4482 / MSIN-4520 — AJAX import participants (hors transaction) — superadm.
|
|
* Buffer strict : toute sortie parasite (erreur SQL, notices Excel) casse dataType:json.
|
|
*/
|
|
ob_start();
|
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_WARNING);
|
|
ini_set('display_errors', '0');
|
|
|
|
require_once dirname(__FILE__) . '/php/inc_functions.php';
|
|
require_once dirname(__FILE__) . '/../php/inc_fx_import_resultats.php';
|
|
|
|
$intUsaId = fxSuperadmAjaxAuthOrJsonExit();
|
|
if (session_status() === PHP_SESSION_ACTIVE) {
|
|
session_write_close();
|
|
}
|
|
|
|
$strAction = trim((string)($_REQUEST['a'] ?? ''));
|
|
$intEveId = intval($_REQUEST['eve_id'] ?? 0);
|
|
$tabRetour = array('state' => 'error', 'message' => 'action_invalide');
|
|
|
|
// MSIN-4482 — toutes les actions mutantes exigent le type « Sans inscription en ligne »
|
|
$tabActionsGuard = array('upload', 'choose_sheets', 'save_template', 'validate', 'commit', 'reset_preview', 'reset', 'download_anomalies');
|
|
if (in_array($strAction, $tabActionsGuard, true)) {
|
|
$tabGuard = fxImportResultatsGuardEveSansInscription($intEveId);
|
|
if (is_array($tabGuard)) {
|
|
$tabRetour = $tabGuard;
|
|
while (ob_get_level() > 0) {
|
|
ob_end_clean();
|
|
}
|
|
if (!headers_sent()) {
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
}
|
|
echo json_encode($tabRetour, JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
switch ($strAction) {
|
|
case 'upload':
|
|
if ($intEveId <= 0) {
|
|
$tabRetour = array('state' => 'error', 'message' => 'eve_id manquant');
|
|
break;
|
|
}
|
|
if (empty($_FILES['file'])) {
|
|
$tabRetour = array('state' => 'error', 'message' => 'Fichier manquant');
|
|
break;
|
|
}
|
|
$tabRetour = fxImportResultatsSaveUpload($intEveId, $_FILES['file']);
|
|
break;
|
|
|
|
// MSIN-4520 — multi-onglets : colonne épreuve OU onglets = épreuves
|
|
case 'choose_sheets':
|
|
if ($intEveId <= 0) {
|
|
$tabRetour = array('state' => 'error', 'message' => 'eve_id manquant');
|
|
break;
|
|
}
|
|
$strToken = trim((string)($_REQUEST['token'] ?? ''));
|
|
$strMode = trim((string)($_REQUEST['sheet_mode'] ?? ''));
|
|
$strSheet = trim((string)($_REQUEST['sheet'] ?? ''));
|
|
$tabSheets = $_REQUEST['sheets'] ?? array();
|
|
if (is_string($tabSheets)) {
|
|
$arrDecodedSheets = json_decode($tabSheets, true);
|
|
$tabSheets = is_array($arrDecodedSheets)
|
|
? $arrDecodedSheets
|
|
: array_filter(array_map('trim', explode(',', $tabSheets)));
|
|
}
|
|
if (!is_array($tabSheets)) {
|
|
$tabSheets = array();
|
|
}
|
|
$tabRetour = fxImportResultatsChooseSheets($intEveId, $strToken, $strMode, $strSheet, $tabSheets);
|
|
break;
|
|
|
|
case 'save_template':
|
|
if ($intEveId <= 0) {
|
|
$tabRetour = array('state' => 'error', 'message' => 'eve_id manquant');
|
|
break;
|
|
}
|
|
$strToken = trim((string)($_REQUEST['token'] ?? ''));
|
|
$strName = trim((string)($_REQUEST['tpl_name'] ?? ''));
|
|
$arrMapping = $_REQUEST['mapping'] ?? array();
|
|
if (is_string($arrMapping)) {
|
|
$arrDecoded = json_decode($arrMapping, true);
|
|
$arrMapping = is_array($arrDecoded) ? $arrDecoded : array();
|
|
}
|
|
if (!is_array($arrMapping)) {
|
|
$arrMapping = array();
|
|
}
|
|
$tabRetour = fxImportResultatsSaveTemplate($intEveId, $strToken, $strName, $arrMapping, $intUsaId, true);
|
|
break;
|
|
|
|
case 'validate':
|
|
if ($intEveId <= 0) {
|
|
$tabRetour = array('state' => 'error', 'message' => 'eve_id manquant');
|
|
break;
|
|
}
|
|
$strToken = trim((string)($_REQUEST['token'] ?? ''));
|
|
$arrMapping = $_REQUEST['mapping'] ?? array();
|
|
if (is_string($arrMapping)) {
|
|
$arrDecoded = json_decode($arrMapping, true);
|
|
$arrMapping = is_array($arrDecoded) ? $arrDecoded : array();
|
|
}
|
|
if (!is_array($arrMapping)) {
|
|
$arrMapping = array();
|
|
}
|
|
$tabRetour = fxImportResultatsValidateMapping($intEveId, $strToken, $arrMapping);
|
|
break;
|
|
|
|
case 'commit':
|
|
if ($intEveId <= 0) {
|
|
$tabRetour = array('state' => 'error', 'message' => 'eve_id manquant');
|
|
break;
|
|
}
|
|
$strToken = trim((string)($_REQUEST['token'] ?? ''));
|
|
$arrMapping = $_REQUEST['mapping'] ?? array();
|
|
if (is_string($arrMapping)) {
|
|
$arrDecoded = json_decode($arrMapping, true);
|
|
$arrMapping = is_array($arrDecoded) ? $arrDecoded : array();
|
|
}
|
|
if (!is_array($arrMapping)) {
|
|
$arrMapping = array();
|
|
}
|
|
$tabRetour = fxImportResultatsCommit($intEveId, $strToken, $arrMapping);
|
|
break;
|
|
|
|
case 'reset_preview':
|
|
if ($intEveId <= 0) {
|
|
$tabRetour = array('state' => 'error', 'message' => 'eve_id manquant');
|
|
break;
|
|
}
|
|
$tabRetour = fxImportResultatsResetPreview($intEveId);
|
|
break;
|
|
|
|
case 'reset':
|
|
if ($intEveId <= 0) {
|
|
$tabRetour = array('state' => 'error', 'message' => 'eve_id manquant');
|
|
break;
|
|
}
|
|
$strConfirm = trim((string)($_REQUEST['confirm'] ?? ''));
|
|
$tabRetour = fxImportResultatsReset($intEveId, $strConfirm);
|
|
break;
|
|
|
|
// MSIN-4520 — CSV anomalies (importés avec problème de champ)
|
|
case 'download_anomalies':
|
|
if ($intEveId <= 0) {
|
|
$tabRetour = array('state' => 'error', 'message' => 'eve_id manquant');
|
|
break;
|
|
}
|
|
$strToken = trim((string)($_REQUEST['token'] ?? ''));
|
|
$tabDl = fxImportResultatsDownloadAnomalies($intEveId, $strToken);
|
|
if (($tabDl['state'] ?? '') !== 'ok' || empty($tabDl['path'])) {
|
|
$tabRetour = is_array($tabDl) ? $tabDl : array('state' => 'error', 'message' => 'anomalies_introuvables');
|
|
break;
|
|
}
|
|
while (ob_get_level() > 0) {
|
|
ob_end_clean();
|
|
}
|
|
$strFn = (string)($tabDl['filename'] ?? 'import_anomalies.csv');
|
|
header('Content-Type: text/csv; charset=utf-8');
|
|
header('Content-Disposition: attachment; filename="' . str_replace('"', '', $strFn) . '"');
|
|
header('Content-Length: ' . filesize($tabDl['path']));
|
|
readfile($tabDl['path']);
|
|
exit;
|
|
|
|
default:
|
|
$tabRetour = array('state' => 'error', 'message' => 'action_invalide');
|
|
break;
|
|
}
|
|
|
|
// Jeter tout HTML parasite (erreur SQL legacy, notices PHPExcel, etc.)
|
|
while (ob_get_level() > 0) {
|
|
ob_end_clean();
|
|
}
|
|
if (!headers_sent()) {
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
}
|
|
echo json_encode($tabRetour, JSON_UNESCAPED_UNICODE);
|
|
exit;
|