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

296 lines
17 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// Initialiser les variables
$tabValidation = $tabRules = $tabMessages = $tabDates = $tabDateTimes = $tabConfirmation = array();
global $strAction ;
?>
<h1><?php if ($strLangue == 'fr') { ?>Rechercher dans<?php } else { ?>Search in<?php } ?> <?php echo strtolower(fxUnescape($tabResults['menu']['men_nom'])); ?></h1>
<form action="index.php" method="get" id="frm_search" name="frm_search">
<div class="error"></div>
<fieldset>
<legend><?php if ($strLangue == 'fr') { ?>Rechercher<?php } else { ?>Search<?php } ?></legend>
<input type="hidden" name="t" value="<?php echo urlencode(base64_encode(fxUnescape($tabResults['menu']['men_id']))); ?>">
<input type="hidden" name="a" value="<?php echo $_GET['a']; ?>">
<input type="hidden" name="lng" value="<?php echo $strLangue; ?>">
<?php
if ($strAction == 'report' && !empty($_GET['eve_id'])) {
?>
<input type="hidden" name="eve_id" value="<?php echo $_GET['eve_id']; ?>">
<?php
}
for ($intCtr = 1; $intCtr <= count($tabSearchData); $intCtr++) {
?>
<div class="form-group row">
<?php
// stocker les règles
$tabValidation[$tabSearchData[$intCtr]['for_field']]['rules'] = $tabValidation[$tabSearchData[$intCtr]['for_field']]['messages'] = array();
// VALIDATION
// DATE
if ($tabSearchData[$intCtr]['for_date'] == 1) {
$tabDates[] = $tabSearchData[$intCtr]['for_field'] . '_from';
$tabDates[] = $tabSearchData[$intCtr]['for_field'] . '_to';
}
// DATETIME
if ($tabSearchData[$intCtr]['for_datetime'] == 1) {
$tabDateTimes[] = $tabSearchData[$intCtr]['for_field'] . '_from';
$tabDateTimes[] = $tabSearchData[$intCtr]['for_field'] . '_to';
}
// Afficher l'étiquette
if ($tabSearchData[$intCtr]['for_type'] != 'radio' && $tabSearchData[$intCtr]['for_type'] != 'hidden') {
?>
<label for="<?php echo $tabSearchData[$intCtr]['for_field']; ?>" class="col-control-label col-sm-3"><?php echo fxUnescape($tabSearchData[$intCtr]['lab_texte_form']); ?> :</label>
<?php
} elseif ($tabSearchData[$intCtr]['for_type'] != 'hidden') {
?>
<label class="col-control-label col-sm-3"><?php echo fxUnescape($tabSearchData[$intCtr]['lab_texte_form']); ?> :</label>
<?php
}
?>
<div class="col-sm-9 col-lg-7">
<?php
$mem_bt_search = 1;
// Afficher le input selon le type
switch($tabSearchData[$intCtr]['for_type']) {
case 'mois';
$annee = date('Y');
$mois_courant = date('n'); // Mois courant (1-12)
$strLangue = 'fr'; // ou 'en'
$mois_fr = [
1 => 'Janvier', 2 => 'Février', 3 => 'Mars', 4 => 'Avril',
5 => 'Mai', 6 => 'Juin', 7 => 'Juillet', 8 => 'Août',
9 => 'Septembre', 10 => 'Octobre', 11 => 'Novembre', 12 => 'Décembre'
];
$mois_en = [
1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April',
5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August',
9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December'
];
// Récupérer les paramètres GET existants, sauf ceux quon va écraser
$current_params = $_GET;
unset($current_params['ach_maj_from'], $current_params['ach_maj_to'], $current_params['mois'], $current_params['annee']);
// Récupérer le nom de la page courante
$self = basename($_SERVER['PHP_SELF']);
// Toujours décembre de l'année passée
$annee_decembre = date('Y') - 1;
$mois_decembre = 12; // décembre
$mois_label = ($strLangue == 'fr') ? $mois_fr[$mois_decembre] : $mois_en[$mois_decembre];
$dateStart = new DateTime("$annee_decembre-12-01");
$dateEnd = clone $dateStart;
$dateEnd->modify('first day of next month')->modify('-1 second');
$from = $dateStart->format('Y-m-d 00:00:00');
$to = $dateEnd->format('Y-m-d 23:59:59');
$params = $current_params + [
'ach_maj_from' => $from,
'ach_maj_to' => $to,
'mois' => $mois_decembre,
'annee' => $annee_decembre
];
$query = http_build_query($params);
echo '<a class="btn btn-secondary m-1" href="' . $self . '?' . $query . '">';
echo $mois_label . ' ' . $annee_decembre . '</a>';
// 2. Les 12 mois de lannée courante
for ($i = 1; $i <= 12; $i++) {
$nomMois = ($strLangue == 'fr') ? $mois_fr[$i] : $mois_en[$i];
$dateStart = new DateTime("$annee-$i-01");
$dateEnd = clone $dateStart;
$dateEnd->modify('first day of next month')->modify('-1 second');
$from = $dateStart->format('Y-m-d 00:00:00');
$to = $dateEnd->format('Y-m-d 23:59:59');
$params = $current_params + [
'ach_maj_from' => $from,
'ach_maj_to' => $to,
'mois' => $i,
'annee' => $annee
];
$query = http_build_query($params);
echo '<a class="btn btn-primary m-1" href="' . $self . '?' . $query . '&btn_search=">';
echo $nomMois . ' ' . $annee . '</a>';
}
$mem_bt_search = 0;
break;
case 'text':
if ($tabSearchData[$intCtr]['for_date'] == 1 || $tabSearchData[$intCtr]['for_datetime'] == 1) {
?>
<label class="control-label border-straight"><?php if ($strLangue == 'fr') { ?>de<?php } else { ?>from<?php } ?></label>
<div class='input-group date' id='<?php echo $tabSearchData[$intCtr]['for_field'] . '_from_cal'; ?>'>
<input class="form-control" type="text" id="<?php echo $tabSearchData[$intCtr]['for_field'] . '_from'; ?>" name="<?php echo $tabSearchData[$intCtr]['for_field'] . '_from'; ?>" size="<?php echo $tabSearchData[$intCtr]['for_size']; ?>" maxlength="<?php echo $tabSearchData[$intCtr]['for_maxlength']; ?>"<?php if (isset($_GET['btn_search']) && isset($_GET[$tabSearchData[$intCtr]['for_field'] . '_from'])) { ?> value="<?php echo $_GET[$tabSearchData[$intCtr]['for_field'] . '_from']; ?>" <?php } ?>>
<span class="input-group-addon border-straight">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<label class="control-label"><?php if ($strLangue == 'fr') { ?>à<?php } else { ?>to<?php } ?></label>
<div class='input-group date' id='<?php echo $tabSearchData[$intCtr]['for_field'] . '_to_cal'; ?>'>
<input class="form-control border-straight" type="text" id="<?php echo $tabSearchData[$intCtr]['for_field'] . '_to'; ?>" name="<?php echo $tabSearchData[$intCtr]['for_field'] . '_to'; ?>" size="<?php echo $tabSearchData[$intCtr]['for_size']; ?>" maxlength="<?php echo $tabSearchData[$intCtr]['for_maxlength']; ?>"<?php if (isset($_GET['btn_search']) && isset($_GET[$tabSearchData[$intCtr]['for_field'] . '_to'])) { ?> value="<?php echo $_GET[$tabSearchData[$intCtr]['for_field'] . '_to']; ?>" <?php } ?> />
<span class="input-group-addon border-straight">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<?php
} else {
?>
<input class="form-control border-straight" type="text" id="<?php echo $tabSearchData[$intCtr]['for_field']; ?>" name="<?php echo $tabSearchData[$intCtr]['for_field']; ?>" size="<?php echo $tabSearchData[$intCtr]['for_size']; ?>" maxlength="<?php echo $tabSearchData[$intCtr]['for_maxlength']; ?>"<?php if (isset($_GET['btn_search']) && isset($_GET[$tabSearchData[$intCtr]['for_field']])) { ?> value="<?php echo $_GET[$tabSearchData[$intCtr]['for_field']]; ?>" <?php } ?>>
<?php
}
break;
case 'list':
case 'select':
// con-258
$tabListItems = (array) null;
if (trim($tabSearchData[$intCtr]['lab_data_type']) == 'json')
$tabListItems = json_decode(utf8_encode($tabSearchData[$intCtr]['lab_list']), true);
else {
$recListItems = $GLOBALS['db']->fxGetResults($tabSearchData[$intCtr]['lab_list']);
foreach ($recListItems as $tabResultat) {
$tabKeys = array_keys($tabResultat);
$tabListItems[utf8_encode($tabResultat[$tabKeys[1]])] = utf8_encode($tabResultat[$tabKeys[0]]);
}
}
?>
<select class="form-control border-straight" id="<?php echo $tabSearchData[$intCtr]['for_field']; ?>" name="<?php echo $tabSearchData[$intCtr]['for_field']; ?>">
<option value=""<?php if ((isset($_GET['btn_search']) && $_GET[$tabSearchData[$intCtr]['for_field']] == '') || !isset($_GET['btn_search'])) { ?> selected="selected"<?php } ?>>Tous les résultats</option>
<?php
foreach ($tabListItems as $strLabel => $strValue) {
?>
<option value="<?php echo utf8_decode(fxUnescape($strValue)); ?>"<?php if (isset($_GET['btn_search']) && isset($_GET[$tabSearchData[$intCtr]['for_field']]) && $_GET[$tabSearchData[$intCtr]['for_field']] === $strValue) { ?> selected="selected"<?php } ?>><?php echo utf8_decode(fxUnescape($strLabel)); ?></option>
<?php
}
?>
</select>
<?php
break;
case 'radio':
if ($tabSearchData[$intCtr]['for_yesno'] == 1) {
?>
<label class="radio-inline">
<input type="radio" id="<?php echo $tabSearchData[$intCtr]['for_field']; ?>_1"
name="<?php echo $tabSearchData[$intCtr]['for_field']; ?>" value="1"
class="chk_input"<?php if (isset($_GET['btn_search']) && isset($_GET[$tabSearchData[$intCtr]['for_field']]) && $_GET[$tabSearchData[$intCtr]['for_field']] == 1) { ?> checked="checked"<?php } ?>>
Oui
</label>
<label class="radio-inline">
<input type="radio" id="<?php echo $tabSearchData[$intCtr]['for_field']; ?>_0" name="<?php echo $tabSearchData[$intCtr]['for_field']; ?>" value="0" class="chk_input"<?php if (isset($_GET['btn_search']) && isset($_GET[$tabSearchData[$intCtr]['for_field']]) && $_GET[$tabSearchData[$intCtr]['for_field']] == 0) { ?> checked="checked"<?php } ?>> Non
</label>
<label class="radio-inline">
<input type="radio" id="<?php echo $tabSearchData[$intCtr]['for_field']; ?>_na" name="<?php echo $tabSearchData[$intCtr]['for_field']; ?>" value="" class="chk_input"<?php if ((isset($_GET['btn_search']) && isset($_GET[$tabSearchData[$intCtr]['for_field']]) && $_GET[$tabSearchData[$intCtr]['for_field']] == '') || !isset($_GET['btn_search'])) { ?> checked="checked"<?php } ?>> Tous les résultats
</label>
<?php
}
break;
default:
}
?>
</div>
</div>
<?php
}
?>
</fieldset>
<?php
if ($mem_bt_search == 1) {
?>
<div class="form-group row">
<div class="col-sm-9 col-lg-7 offset-sm-3">
<button class="btn btn-primary border-straight" type="submit" id="btn_search" name="btn_search"><i class="fa fa-search" aria-hidden="true"></i>&nbsp;<?php if ($strLangue == 'fr') { ?>Rechercher<?php } else { ?>Search<?php } ?></button>
<?php
if (isset($_GET['btn_search'])) {
$strLinkRetour = 'index.php?t=' . urlencode(base64_encode(fxUnescape($tabResults['menu']['men_id']))) . '&a=' . $_GET['a'] . '&lng=' . $strLangue;
if ($strAction == 'report' && !empty($_GET['eve_id'])) {
$strLinkRetour .= '&eve_id=' . $_GET['eve_id'] . '&btn_search=';
}
?>
<a class="btn btn-danger border-straight" href="<?php echo $strLinkRetour; ?>"><i class="fa fa-times" aria-hidden="true"></i>&nbsp;<?php if ($strLangue == 'fr') { ?>Effacer rechercher<?php } else { ?>Remove search<?php } ?></a>
<?php
}
?>
</div>
</div>
<?php
}
?>
<br>
</form>
<script type="text/javascript">
$().ready(function() {
<?php
foreach ($tabValidation as $field => $items) {
if (count($items['rules']) > 0) {
$tabRules[] = $field . ": {" . implode(',', $items['rules']) . "}";
$tabMessages[] = $field . ": {" . implode(',', $items['messages']) . "}";
}
}
if (count($tabRules) > 0) {
?>
$("#frm_search").validate({
rules: {
<?php echo implode(',', $tabRules); ?>
},
messages: {
<?php echo implode(',', $tabMessages); ?>
},
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
<?php
}
if (count($tabDates) > 0) {
foreach ($tabDates as $strField) {
?>
$('#<?php echo $strField . '_cal'; ?>').datetimepicker({
format: 'YYYY-MM-DD',
locale: '<?php echo $strLangue; ?>-ca'
});
<?php
}
}
if (count($tabDateTimes) > 0) {
foreach ($tabDates as $strField) {
?>
$('#<?php echo $strField . '_cal'; ?>').datetimepicker({
format: 'YYYY-MM-DD HH:mm:ss',
locale: '<?php echo $strLangue; ?>-ca',
sideBySide: true
});
<?php
}
}
?>
});
</script>