Files
ms1inscription-v5/inc_list_logs_course.php
2026-05-13 09:43:32 -04:00

545 lines
22 KiB
PHP

<?php
include_once 'php/thermometer.class.php';
global $objDatabase, $tabEvenement, $strLangue, $vDomaine, $strCode;
function fxShowColumn($arrChamps, $arrListeParticipants, $x, $strLangue, $intEquipe = 0) {
$strResults = '';
foreach ($arrChamps as $arrCol) {
if (($arrCol['field'] == 'pec_nom_equipe' && intval($intEquipe) != 1) || ($arrCol['field'] == 'epr_type,epr_nom' && intval($intEquipe) == 2) || ($arrCol['field'] == 'par_prenom,par_nom' && intval($intEquipe) == 1)) {
$mem_affiche = '';
} else {
$arrData = array();
$mem_field = explode(',', $arrCol['field']);
foreach ($mem_field as $strField) {
$arrData[] = $arrListeParticipants[$x][fxchecklangue($strField, $arrCol['multilingue'], $strLangue)];
}
$mem_affiche = implode(' ', $arrData);
}
switch ($arrCol['format']) {
case 'float':
$mem_affiche = number_format($mem_affiche, 2, ',', ' ');
break;
case 'time':
$mem_affiche = fxSecondsToTime($mem_affiche);
break;
}
$strResults .= '<td style="text-align: ' . $arrCol['align'] . ';" class="">' . $mem_affiche . '</td>';
}
return $strResults;
}
function fxchecklangue($strField, $intMultilingue, $langues) {
if (intval($intMultilingue) == 1)
return $strField . "_" . $langues;
else
return $strField;
}
function fxGetchamps($eve_id, $intEpreuveRecherche, $intNbEquipes) {
global $objDatabase;
$arrColonnes = array();
$arrColonnes[20] = array(
'field' => 'epr_type,epr_nom',
'align' => 'left',
'label_fr' => 'Épreuve',
'label_en' => 'Race',
'multilingue' => 1,
'format' => 'string'
);
$arrColonnes[30] = array(
'field' => 'par_prenom,par_nom',
'align' => 'left',
'label_fr' => 'Nom',
'label_en' => 'Name',
'multilingue' => 0,
'format' => 'string'
);
$sqlLogFields = "SELECT DISTINCT c.* FROM logs_questions_epreuves e, logs_questions_champs c WHERE c.lqc_id = e.lqc_id AND e.lqe_actif = 1 AND e.eve_id = " . intval($eve_id) . " ORDER BY e.lqe_tri";
$arrLogFields = $objDatabase->fxGetResults($sqlLogFields);
if ($arrLogFields != null) {
for ($intCtr = 1; $intCtr <= count($arrLogFields); $intCtr++) {
switch ($arrLogFields[$intCtr]['lqc_nom']) {
case 'rlq_distance':
$arrColonnes[$arrLogFields[$intCtr]['lqc_tri'] . 0] = array(
'field' => 'tot_objectif_distance',
'align' => 'right',
'label_fr' => 'Objectif',
'label_en' => 'Goal',
'multilingue' => 0,
'format' => 'float'
);
$arrColonnes[$arrLogFields[$intCtr]['lqc_tri'] . 1] = array(
'field' => 'tot_distance',
'align' => 'right',
'label_fr' => 'Distance total',
'label_en' => 'Total distance',
'multilingue' => 0,
'format' => 'float'
);
break;
case 'rlq_temps':
/*$arrColonnes[$arrLogFields[$intCtr]['lqc_tri'] . 0] = array(
'field' => 'tot_objectif_temps',
'align' => 'left',
'label_fr' => 'Objectif',
'label_en' => 'Goal',
'multilingue' => 0,
'format' => 'time'
);*/
$arrColonnes[$arrLogFields[$intCtr]['lqc_tri'] . 1] = array(
'field' => 'tot_temps',
'align' => 'left',
'label_fr' => 'Temps total',
'label_en' => 'Total time',
'multilingue' => 0,
'format' => 'time'
);
break;
}
}
}
if (intval($intNbEquipes) > 0) {
$arrColonnes[10] = array(
'field' => 'pec_nom_equipe',
'align' => 'left',
'label_fr' => 'Équipe',
'label_en' => 'Team',
'multilingue' => 0,
'format' => 'string'
);
}
return $arrColonnes;
}
function fxGetListeParticipants($eve_id, $strWhere, $strOrder, $pec_id = 0) {
global $objDatabase;
if (intval($pec_id) != 0) { // trouver les participants d'une équipe précise
$sql = "
(SELECT
rec.pec_equipe, rec.pec_nom_equipe, rp.*, rp.epr_objectif_distance AS tot_objectif_distance,
(
SELECT
COALESCE(SUM(rlq.rlq_distance), 0) AS tot_distance
FROM
resultats_logs_questions rlq
WHERE
rlq.pec_id = rec.pec_id_original AND rlq.par_id = rp.par_id_original
) AS tot_distance,
(
SELECT
COALESCE(SUM(TIME_TO_SEC(rlq.rlq_temps)), 0) AS tot_temps
FROM
resultats_logs_questions rlq
WHERE
rlq.pec_id = rec.pec_id_original AND rlq.par_id = rp.par_id_original
) AS tot_temps,
pe.epr_categorie_fr, pe.epr_categorie_en, pe.epr_type_fr, pe.epr_type_en, pe.epr_nom_fr, pe.epr_nom_en, rec.pec_id_original
FROM
resultats_epreuves_commandees rec, resultats_participants rp, inscriptions_panier_epreuves pe
WHERE
rp.pec_id = rec.pec_id_original AND rp.is_cancelled = 0 AND pe.epr_id = rec.epr_id AND rec.eve_id = " . intval($eve_id) . " AND rec.pec_equipe = 1 AND rec.pec_id_original = " . intval($pec_id) . ")
" . $strOrder . "
";
} else { // trouver TOUS les participants et équipes d'un événement
$sql = "
(SELECT
rec.pec_equipe, rec.pec_nom_equipe, rp.*, rp.epr_objectif_distance AS tot_objectif_distance,
(
SELECT
COALESCE(SUM(rlq.rlq_distance), 0) AS tot_distance
FROM
resultats_logs_questions rlq
WHERE
rlq.pec_id = rec.pec_id_original AND rlq.par_id = rp.par_id_original
) AS tot_distance,
(
SELECT
COALESCE(SUM(TIME_TO_SEC(rlq.rlq_temps)), 0) AS tot_temps
FROM
resultats_logs_questions rlq
WHERE
rlq.pec_id = rec.pec_id_original AND rlq.par_id = rp.par_id_original
) AS tot_temps,
pe.epr_categorie_fr, pe.epr_categorie_en, pe.epr_type_fr, pe.epr_type_en, pe.epr_nom_fr, pe.epr_nom_en, rec.pec_id_original
FROM
resultats_epreuves_commandees rec, resultats_participants rp, inscriptions_panier_epreuves pe
WHERE
rp.pec_id = rec.pec_id_original AND rp.is_cancelled = 0 AND pe.epr_id = rec.epr_id AND rec.eve_id = " . intval($eve_id) . " AND rec.pec_equipe = 0
" . $strWhere . ")
UNION
(SELECT
rec.pec_equipe, rec.pec_nom_equipe, rp.*,
(
SELECT
COALESCE(SUM(rp.epr_objectif_distance), 0) AS tot_objectif_distance_equipe
FROM
resultats_participants rp
WHERE
rp.pec_id = rec.pec_id_original
) AS tot_objectif_distance,
(
SELECT
COALESCE(SUM(rlq.rlq_distance), 0) AS tot_distance
FROM
resultats_logs_questions rlq
WHERE
rlq.pec_id = rec.pec_id_original
) AS tot_distance,
(
SELECT
COALESCE(SUM(TIME_TO_SEC(rlq.rlq_temps)), 0) AS tot_temps
FROM
resultats_logs_questions rlq
WHERE
rlq.pec_id = rec.pec_id_original
) AS tot_temps,
pe.epr_categorie_fr, pe.epr_categorie_en, pe.epr_type_fr, pe.epr_type_en, pe.epr_nom_fr, pe.epr_nom_en, rec.pec_id_original
FROM
resultats_epreuves_commandees rec, resultats_participants rp, inscriptions_panier_epreuves pe
WHERE
rp.pec_id = rec.pec_id_original AND rp.is_cancelled = 0 AND pe.epr_id = rec.epr_id AND rec.eve_id = " . intval($eve_id) . " AND rec.pec_equipe = 1
" . $strWhere . "
GROUP BY rec.pec_id_original)
" . $strOrder . "
";
}
$rec = $objDatabase->fxGetResults($sql);
return $rec;
}
function fxGetObjectifEpreuve($intEpreuve) {
global $objDatabase;
$sqlObjectif = "
SELECT
COALESCE(SUM(rp.epr_objectif_distance), 0) AS tot_objectif_distance, ie.epr_objectif_distance_global, ie.epr_montant_distance_offline, COALESCE(SUM(TIME_TO_SEC(rp.epr_objectif_temps)), 0) AS tot_objectif_temps, COALESCE(TIME_TO_SEC(ie.epr_objectif_temps_global), 0) AS epr_objectif_temps_global, COALESCE(TIME_TO_SEC(ie.epr_montant_temps_offline), 0) AS epr_montant_temps_offline
FROM
resultats_epreuves_commandees rec, resultats_participants rp, inscriptions_epreuves ie
WHERE
rec.epr_id = ie.epr_id AND rp.is_cancelled = 0 AND rec.tep_id = 3 AND rp.pec_id = rec.pec_id_original AND rec.epr_id = " . intval($intEpreuve) . "
";
$arrObjectif = $objDatabase->fxGetRow($sqlObjectif);
return $arrObjectif;
}
function fxGetTotalEpreuve($intEpreuve) {
global $objDatabase;
$sqlTotal = "
SELECT
COALESCE(SUM(rlq.rlq_distance), 0) AS tot_distance, COALESCE(SUM(TIME_TO_SEC(rlq.rlq_temps)), 0) AS tot_temps
FROM
resultats_epreuves_commandees rec, resultats_logs_questions rlq, resultats_participants rp
WHERE
rlq.pec_id = rec.pec_id_original AND rlq.par_id = rp.par_id_original AND rp.is_cancelled = 0 AND rec.pec_id_original = rp.pec_id AND rec.epr_id = " . intval($intEpreuve) . "
";
$arrTotal = $objDatabase->fxGetRow($sqlTotal);
return $arrTotal;
}
function fxListEpreuves($evenement, $strLangue, $intEpreuveRecherche) {
global $objDatabase;
$arrRetour = array();
$strWhere = '';
if (trim($intEpreuveRecherche) != '') {
$strWhere = " AND ipe.epr_id = " . intval($intEpreuveRecherche);
}
$sqlEpreuves = "
SELECT
ipe.epr_id, ipe.epr_type_$strLangue, ipe.epr_nom_$strLangue, ipe.epr_categorie_$strLangue, ipe.epr_equipe
FROM
inscriptions_panier_epreuves_commandees rec, inscriptions_panier_epreuves ipe
WHERE
ipe.epr_id = rec.epr_id AND rec.eve_id = " . intval($evenement) . " AND ipe.tep_id = 3 $strWhere
GROUP BY
ipe.epr_id
ORDER BY
epr_type_" . $strLangue
;
$arrEpreuves = $objDatabase->fxGetResults($sqlEpreuves);
if ($arrEpreuves != null) {
$arrRetour['epreuves'] = $arrEpreuves;
$intNbEpreuves = 0;
foreach ($arrEpreuves as $item) {
$intNbEpreuves += $item['epr_equipe'];
}
$arrRetour['equipe'] = $intNbEpreuves;
}
return $arrRetour;
}
$strEpreuve = afficheTexte('toutlesepreuves',0);
$strWhere = $intEpreuveRecherche = $strNomRecherche = $strOrderGet = '';
$strOrderBy = " ORDER BY epr_categorie_" . $strLangue . ", epr_type_" . $strLangue . ", epr_nom_" . $strLangue . ", tot_temps DESC, tot_distance DESC, tot_objectif_distance DESC, par_nom, par_prenom";
// v?rifier les form POST
if (isset($_GET['order'])) {
$strOrderGet = $objDatabase->fxEscape($_GET['order']);
$strOrderBy = " ORDER BY " . $strOrderGet;
}
if (isset($_GET['rech_epreuve'])) {
if ($_GET['rech_epreuve'] != '') {
$intEpreuveRecherche = intval($_GET['rech_epreuve']);
$strWhere .= ' AND rec.epr_id = ' . $_GET['rech_epreuve'];
$intEpreuveRecherche = $_GET['rech_epreuve'];
$intEpreuve = $_GET['rech_epreuve'];
// trouver le nom de l'?preuve
foreach ($tabEvenement['epreuves'] as $tabEpreuves) {
if ($tabEpreuves['epr_id'] == $intEpreuve) {
$strEpreuve = fxUnescape($tabEpreuves['epr_type_' . $strLangue]);
if (trim($tabEpreuves['epr_nom_' . $strLangue]) != '')
$strEpreuve .= ' - ' . fxUnescape($tabEpreuves['epr_nom_' . $strLangue]);
}
}
}
}
$arrEpreuves = fxListEpreuves($tabEvenement['general']['eve_id'], $strLangue, $intEpreuveRecherche);
$arrEpreuvesSelect = fxListEpreuves($tabEvenement['general']['eve_id'], $strLangue, '');
$intNbEquipes = $arrEpreuvesSelect['equipe'];
if (!empty($_GET['rech_nom'])) {
if (trim($_GET['rech_nom']) != '') {
if ($intNbEquipes == 0){
$strWhere .= " AND CONCAT(par_prenom,' ',par_nom) LIKE '%" . $_GET['rech_nom'] . "%'" ;
$strNomRecherche = $_GET['rech_nom'];
} else {
$strWhere .= " AND (CONCAT(par_prenom,' ',par_nom) LIKE '%" . $_GET['rech_nom'] . "%' OR pec_nom_equipe LIKE '%" . $_GET['rech_nom'] . "%')" ;
$strNomRecherche = $_GET['rech_nom'];
}
}
}
?>
<h1><?php afficheTexte('titrelisteparticipantscoursevirtuelle'); ?></h1>
<?php
$fltDistanceParcourueTotal = $fltObjectifDistanceTotal = $intTempsParcourueTotal = $intObjectifTempsTotal = 0;
foreach ($arrEpreuves['epreuves'] as $key => $value){
$arrTotalEpreuve = fxGetTotalEpreuve($value['epr_id']); // amassé total
$arrObjectifEpreuve = fxGetObjectifEpreuve($value['epr_id']); // objectif total
$fltDistanceParcourue = $arrTotalEpreuve['tot_distance'];
$intTempsParcourue = $arrTotalEpreuve['tot_temps'];
$fltObjectifDistance = $arrObjectifEpreuve['tot_objectif_distance'];
$fltObjectifDistanceGlobal = $arrObjectifEpreuve['epr_objectif_distance_global'];
$intObjectifTemps = $intObjectifTempsGlobal = $arrObjectifEpreuve['epr_objectif_temps_global'];
$fltDistanceOffline = $arrObjectifEpreuve['epr_montant_distance_offline'];
$intTempsOffline = $arrObjectifEpreuve['epr_montant_temps_offline'];
if (floatval($fltObjectifDistanceGlobal) > 0) {
$fltObjectifDistance = $fltObjectifDistanceGlobal;
}
if (floatval($fltDistanceOffline) > 0) {
$fltDistanceParcourue += $fltDistanceOffline;
}
if (intval($intTempsOffline) > 0) {
$intTempsParcourue += $intTempsOffline;
}
// comptabiliser les totaux
$fltDistanceParcourueTotal += floatval($fltDistanceParcourue);
$fltObjectifDistanceTotal += floatval($fltObjectifDistance);
$intTempsParcourueTotal += intval($intTempsParcourue);
$intObjectifTempsTotal += intval($intObjectifTemps);
}
if (floatval($fltObjectifDistanceTotal) > 0) {
if ($strLangue == 'fr') {
$strAmountLabel = ' Distance parcourue';
$strGoalLabel = 'Objectif';
} else {
$strAmountLabel = ' Distance traveled';
$strGoalLabel = 'Goal';
}
$objThermometer = new \clsThermometer\clsThermometer($fltObjectifDistanceTotal, $fltDistanceParcourueTotal);
echo $objThermometer->fxShow('h', 2, 'distance', ' km', $strAmountLabel, $strGoalLabel, $strLangue);
}
if (intval($intObjectifTempsTotal) > 0) {
if ($strLangue == 'fr') {
$strAmountLabel = ' Temps parcourue';
$strGoalLabel = 'Objectif';
} else {
$strAmountLabel = ' Time traveled';
$strGoalLabel = 'Goal';
}
$objThermometer = new \clsThermometer\clsThermometer($intObjectifTempsTotal, $intTempsParcourueTotal);
echo $objThermometer->fxShow('h', 0, 'time', '', $strAmountLabel, $strGoalLabel, $strLangue);
}
?>
<div class="card box_participant rounded-0">
<div class="card-header">
<h2><?php if ($strLangue == 'fr') { ?>Recherche :<?php } else { ?>Search :<?php } ?></h2>
</div>
<div class="card-body">
<form action="<?php echo $vDomaine; ?>/<?php echo $strCode; ?>/<?php if ($strLangue == 'fr') { ?>suivez-resultats<?php } else { ?>track-results<?php } ?>" id="frm_search" name="frm_search" method="get">
<input type="hidden" name="adm" value="<?php echo($stradm);?>">
<div class="form-group row">
<label for="rech_nom" class="control-label col-12 col-lg-4 text-lg-right"><?php afficheTexte('rech_nom'); if ($intNbEquipes == 1) { afficheTexte('rech_equipe'); } ?> :</label>
<div class="col-12 col-lg-7">
<input class="form-control rounded-0" type="text" id="rech_nom" name="rech_nom" value="<?php echo $strNomRecherche; ?>">
</div>
</div>
<div class="form-group row">
<label for="rech_evenement" class="control-label col-12 col-lg-4 text-lg-right"><?php afficheTexte('rech_evenement'); ?> :</label>
<div class="col-12 col-lg-7">
<select name="rech_epreuve" id="rech_evenement" class="form-control rounded-0">
<option value=""><?php echo afficheTexte('tousinscription', 0); ?></option>
<?php
for ($x = 1; $x <= count($arrEpreuvesSelect['epreuves']); $x++) {
?>
<option value="<?php echo $arrEpreuvesSelect['epreuves'][$x]['epr_id']; ?>"<?php echo (intval($arrEpreuvesSelect['epreuves'][$x]['epr_id']) == $intEpreuveRecherche) ? ' selected' : ''; ?>>
<?php
if (trim($arrEpreuvesSelect['epreuves'][$x]['epr_categorie_' . $strLangue]) != '') {
echo $arrEpreuvesSelect['epreuves'][$x]['epr_categorie_' . $strLangue] . " - ";
}
echo $arrEpreuvesSelect['epreuves'][$x]['epr_type_' . $strLangue];
if (trim($arrEpreuvesSelect['epreuves'][$x]['epr_nom_' . $strLangue]) != '') {
echo " - " . $arrEpreuvesSelect['epreuves'][$x]['epr_nom_' . $strLangue];
}
?>
</option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group row">
<div class="col-12 col-lg-7 offset-lg-4">
<button class="btn btn-primary rounded-0" type="submit" id="btn_recherche" name="btn_recherche"><?php if ($strLangue == 'fr') { ?>Recherche<?php } else { ?>Search<?php } ?></button>
</div>
</div>
</form>
</div>
</div>
<?php
//liste des participants
$arrListeParticipants = fxGetListeParticipants($tabEvenement['general']['eve_id'], $strWhere, $strOrderBy);
$arrChamps = fxGetchamps($tabEvenement['general']['eve_id'], $intEpreuveRecherche, $intNbEquipes);
ksort($arrChamps);
echo '<br><h2>' . $strEpreuve . '</h2>';
if ($stradm!="")
echo '<h2>' . afficheTexte('nombreinscription', 0) . ' ' . count($arrListeParticipants) . '</h2><br>';
if ($arrListeParticipants != null) {
$strResults = '
<table class="table">
<thead>
<tr>
';
//entete pour le tableau
foreach ($arrChamps as $arrCol) {
$strResults .= '
<th class="text-' . $arrCol['align'] . '">
' . $arrCol['label_' . $strLangue] . '
</th>
';
}
$strResults .= '
</tr>
</thead>
<tbody>
';
// contenue le tableau
$strCategorie = $strNom = $strType = $strCategoriePrec = $strNomPrec = $strTypePrec = '';
for ($intCtrParticipant = 1; $intCtrParticipant <= count($arrListeParticipants); $intCtrParticipant++) {
$strClass = ($intCtrParticipant & 1) ? '' : 'table-secondary';
$strCategorie = $arrListeParticipants[$intCtrParticipant]['epr_categorie_' . $strLangue];
if ($strCategorie != $strCategoriePrec) { // afficher la catégorie
$strResults .= '
<tr class="bg-primary" style="font-weight: bold;">
<td class="text-left" colspan="' . count($arrChamps) . '">
<h3 class="text-white">' . fxUnescape($strCategorie) . '</h3>
</td>
</tr>
';
}
if (intval($arrListeParticipants[$intCtrParticipant]['pec_equipe']) == 1) { // afficher les équipes
$strResults .= '
<tr class="' . $strClass . '" style="font-weight: bold;">
';
$strResults .= fxShowColumn($arrChamps, $arrListeParticipants, $intCtrParticipant, $strLangue, 1);
$strResults .= '
</tr>
';
// afficher les participants de cette équipe
$arrListeParticipantsEquipe = fxGetListeParticipants($tabEvenement['general']['eve_id'], $strWhere, $strOrderBy, $arrListeParticipants[$intCtrParticipant]['pec_id_original']);
if ($arrListeParticipantsEquipe != null) {
for ($x2 = 1; $x2 <= count($arrListeParticipantsEquipe); $x2++) {
$strResults .= '
<tr class="' . $strClass . '">
';
$strResults .= fxShowColumn($arrChamps, $arrListeParticipantsEquipe, $x2, $strLangue, 2);
$strResults .= '
</tr>
';
}
}
} else { // afficher les solos
$strResults .= '
<tr class="' . $strClass . '">
';
$strResults .= fxShowColumn($arrChamps, $arrListeParticipants, $intCtrParticipant, $strLangue);
$strResults .= '
</tr>
';
}
$strCategoriePrec = $strCategorie;
}
$strResults .= '
</tbody>
<tfoot>
<tr>
<th class="text-center" colspan="' . count($arrChamps) . '">
' . count($arrListeParticipants) . ' participants
</th>
</tr>
</tfoot>
</table>
';
} else {
$strResults = '';
}
echo $strResults;