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

227 lines
12 KiB
PHP

<?php
function fxBookVolunteerShift($int_pec_id, $int_bps_id, $str_action, $int_eve_id){
if($str_action == 'book'){
// verifier si equipe a deja un volunteer shift de book?
$tabBooked = fxSelectQuery('*', 'resultats_benevoles_positions_shifts', ' where pec_id = ' . intval($int_pec_id) . ' and bps_id = ' . intval($int_bps_id), '', 'row');
if($tabBooked == null){
//get par_id du volunteer
$sqlVolunteer = "SELECT par_id FROM resultats_participants WHERE pec_id = " . intval($int_pec_id) . " AND rol_id = 3";
$tabVolunteer = $objDatabase->fxGetRow($sqlVolunteer);
if($tabVolunteer != null){
// todosl: update resultats_benevolets_positions_shifts par_id =
// echo "infjsdkfjsdk";
// exit;
$intParId = $tabVolunteer['par_id'];
} else{
$intParId = 0;
}
$qry = "insert into resultats_benevoles_positions_shifts (pec_id, bps_id, com_id, par_id) values (" . intval($int_pec_id) . ", " . intval($int_bps_id) . ", ". intval($_SESSION['com_info']['com_id']) . ", " . intval($intParId) . ")";
$result = $objDatabase->fxQuery($qry);
if(!$result){
fxcreer_log('CAN24HVOL_ERROR: Error creating new volunteer record.\n' . $result);
} else
// log info about "transaction"
fxcreer_log('CAN24HVOL_REPORT: Volunteer BOOKED.', 24, 0, intval($int_eve_id), intval($_GET['epr_id']), 0, '', intval($_SESSION['com_info']['com_id']), $_SESSION['com_info']['com_courriel']);
}
} elseif($str_action == 'cancel'){
$qry = "delete from resultats_benevoles_positions_shifts where pec_id = " . intval($int_pec_id) . " and bps_id = " . intval($int_bps_id);
$result = $objDatabase->fxQuery($qry);
if(!$result){
fxcreer_log('CAN24HVOL_ERROR: Error deleting volunteer record.\n' . $result);
} else
// log info about "transaction"
fxcreer_log('CAN24HVOL_REPORT: Volunteer CANCELLED.', 24, 0, intval($int_eve_id), intval($_GET['epr_id']), 0, '', intval($_SESSION['com_info']['com_id']), $_SESSION['com_info']['com_courriel']);
}
}
/**
*
*/
function fxDrawVolunteersTab($str_permissions, $int_eve_id){
global $tabEpreuve;
global $tabAllowedResources;
global $tabReservedResources;
$strButtonDisabled = '';
if($str_permissions == 'view'){
$strButtonDisabled = "disabled='disabled' style='cursor:default' class='camp_reserve'";
}
?>
<table class="resultats" style="width: 100%" id="canmore_dash_volunteers">
<tr>
<td style="width: 100%"><h2><?php afficheTexte('dashboard_racevolunteers')?></h2></td>
<td style="width: 25%;" id="td_volunteer_status"><div class="<?php
$sqlNbVolunteers = "SELECT COUNT(*) FROM resultats_benevoles_positions_shifts where pec_id = " . intval($_GET['pec_id_original']);
$intNbVolunteers = $objDatabase->fxGetVar($sqlNbVolunteers);
if($intNbVolunteers == $tabEpreuve['epr_nb_benevole']) echo "green_light"; else echo "yellow_light" ?>"><span></span></div></td>
</tr>
</table>
<table class="canmore-inner-center" style="width: 100%">
<tr class="EvenRow">
<td style="font-weight: bold">
Number of volunteers required
</td>
<td class="canmore-inner-center">
<?php
echo $tabEpreuve['epr_nb_benevole'];
?>
</td>
</tr>
<tr class="OddRow">
<?php
// tableau des infos du benevole booke, s'il y a lieu
$tabVolunteerBooked = fxSelectQuery('*', 'resultats_benevoles_positions_shifts', ' where pec_id = ' . $_GET['pec_id_original'], '', 'row');
if(count($tabVolunteerBooked) != 0){
$bookedJob = fxSelectQuery('bs_nom_' . $strLangue . ', bp_nom_' . $strLangue, ' inscriptions_benevoles_shifts bs, inscriptions_benevoles_positions bp, inscriptions_benevoles_positions_shifts bps', ' where bp.bp_id = bps.bp_id and bs.bs_id = bps.bs_id and bps.bps_id = ' . intval($tabVolunteerBooked['bps_id']), '', 'row');
echo "<td>Volunteer shift</td><td><ul><li><strong>" . $bookedJob['bs_nom_' . $strLangue] . "</li><li style='margin-left:10px'><em>" . $bookedJob['bp_nom_' . $strLangue] . "</em></strong></li></ul></td>";
}
else{
echo "<td colspan='2'>No volunteer scheduled.";
}
?>
</td>
</tr>
</table>
<br />
<table class="canmore" id="table_volunteer_shifts" style="width: 100%;background: #a3a3a3">
<tr class="HeaderRow">
<td style="width: 75%"><?php echo "Day"; ?></td>
<td><?php echo "Time"; ?></td>
<td></td>
</tr>
<?php
// tableau des shifts pour l'evenement
$tabShifts = fxSelectQuery('*', 'inscriptions_benevoles_shifts', ' where eve_id = ' . $int_eve_id, ' order by bs_tri', 'results');
// $tabShifts = fxSelectQuery('*', 'inscriptions_benevoles_shifts', ' where eve_id = ' . $tabEvenement['general']['eve_id'], ' order by bs_tri', 'results');
for($i = 1; $i <= count($tabShifts); $i++){
if ($i % 2 == 0) {
$strEcho = '<tr class="td_section" data-bs_id="' . $tabShifts[$i]['bs_id'] . '" id="tr_vol_shift_' . $tabShifts[$i]['bs_id'] . '"style="background: #222">';
}
else {
$strEcho = '<tr class="td_section" data-bs_id="' . $tabShifts[$i]['bs_id'] . '" id="tr_vol_shift_' . $tabShifts[$i]['bs_id'] . '"style="background: #000">';
}
$strDate = explode("-", $tabShifts[$i]['bs_nom_en']);
$strDay = $strDate[0];
$strTime = $strDate[1];
// tableau des places pour chaque position (spots) de la rangee
$tabSpots = fxSelectQuery('*', 'inscriptions_benevoles_positions_shifts', ' where bps_id = ' . intval($tabShifts[$i]['bs_id']), '', 'row');
$strEcho .= "<td style='width:75%'>" . $strDay . "</td><td class='td_vol_time'>" . $strTime . "</td><td class='td_vol_time'><button style='width: 75px' data-bs_id='" . $tabShifts[$i]['bs_id'] . "' id='btn_vol_shift_" . $tabShifts[$i]['bs_id'] . "'>Select</button></td><tr><td colspan=4>" . fxDrawShiftTable($tabSpots['bps_id'], count($tabVolunteerBooked), $tabVolunteerBooked, $strButtonDisabled, $int_eve_id) . "</td></tr>";
echo $strEcho;
echo "</tr>";
}
?>
</table>
<?php
}
function fxDrawShiftTable($int_bs_id, $bool_shift_booked, $tab_volunteer_booked, $str_disabled = '', $int_eve_id){
//function fxDrawShiftTable($int_bs_id, $bool_shift_booked, $tab_volunteer_booked){
global $tabEvenement;
$return = '<table data-debug="debug" id="table_'. $int_bs_id . '" style="width: 100%; display: none"><tr><td>';
$tabJobs = fxSelectQuery('*', 'inscriptions_benevoles_positions', ' WHERE bp_actif = 1 AND eve_id = ' . intval($int_eve_id), ' ORDER BY bp_id', 'results');
// $tabJobs = fxSelectQuery('*', 'inscriptions_benevoles_positions', ' WHERE eve_id = ' . intval($tabEvenement['general']['eve_id']), '', 'results');
if ($strLangue == 'fr')
$strPage = '/reserver/';
else
$strPage = '/book/';
$strPostUrl = $strPage . $tabEvenement['general']['eve_label_url'] . '/0';
for($i = 1; $i <= count($tabJobs); $i++){
$tabBenevolePosShift = fxSelectQuery('*', 'inscriptions_benevoles_positions_shifts', ' where bp_id = ' . intval($tabJobs[$i]['bp_id']) . ' and bs_id = ' . intval($int_bs_id), '', 'row');
// get number of booked jobs for current position_shift
$tabJobsShiftQtyBooked = fxSelectQuery('count(*)', 'resultats_benevoles_positions_shifts', ' where bps_id = ' . intval($tabBenevolePosShift['bps_id']), '', 'row');
// var_dump($tabBenevolePosShift['bps_qte']);
if($tab_volunteer_booked['bps_id'] == $tabBenevolePosShift['bps_id']){
$strReservee ='This is your job!';
}
elseif(!$bool_shift_booked && $tabBenevolePosShift['bps_qte'] != $tabJobsShiftQtyBooked['count(*)']){
$strReservee = '<form action="'. $vDomaine .'/canmore24h/en/manage?pec_id_original='. $_GET['pec_id_original'] .'&epr_id=' . $_GET['epr_id'] .'" method="post">
<input type="hidden" name="bs_id" value="' . intval($int_bs_id) . '">
<input type="hidden" name="pec_id" value="' . $_GET['pec_id_original'] . '">
<input type="hidden" name="int_bps_id" value="' . $tabBenevolePosShift['bps_id'] . '">
<button id="btn_book_vol" name="btn_book_vol" ' . $str_disabled . ' data-pec_id="'.$_GET['pec_id_original'].'" data-bps_id="'. $tabBenevolePosShift['bps_id']. '">Book</button></form>';
}
elseif(!$bool_shift_booked && $tabBenevolePosShift['bps_qte'] == $tabJobsShiftQtyBooked['count(*)']){
$strReservee = '<div style="font-weight: bold;color:darkred">All taken.</div>';
}
else{
$strReservee = '';
}
$strStyle = 'style="color: black; font-size:80%; font-weight: bold"';
if($tab_volunteer_booked['bps_id'] == $tabBenevolePosShift['bps_id']){
$strClass = 'yours';
// $strStyle = '';
$strReservee = '<form id="frm_book_vol" name="frm_book_vol" action="'. $vDomaine .'/canmore24h/en/manage?pec_id_original='. $_GET['pec_id_original'] .'&epr_id=' . $_GET['epr_id'] .'" method="post">
<input type="hidden" name="bs_id" value="' . intval($int_bs_id) . '">
<input type="hidden" name="pec_id" value="' . $_GET['pec_id_original'] . '">
<input type="hidden" name="int_bps_id" value="' . $tabBenevolePosShift['bps_id'] . '">
<button id="btn_cancel_vol" name="btn_cancel_vol" ' . $str_disabled . ' data-pec_id="'.$_GET['pec_id_original'].'" data-bps_id="'. $tabBenevolePosShift['bps_id']. '">Cancel</button></form>';
}
elseif($tabBenevolePosShift['bps_qte'] <= $tabJobsShiftQtyBooked['count(*)']){
// elseif($tabBenevolePosShift['bps_qte'] == $tabJobsShiftQtyBooked['count(*)']){
$strClass = 'taken';
$strReservee = '<div>All taken.</div>';
}
else{
$strClass = 'available';
}
if($tabBenevolePosShift['bps_qte'] - $tabJobsShiftQtyBooked['count(*)'] <= 0) {
$intQteTaken = $tabBenevolePosShift['bps_qte'];
$intNbDispoRestant = 0;
}
else {
$intQteTaken = $tabJobsShiftQtyBooked['count(*)'];
$intNbDispoRestant = $tabBenevolePosShift['bps_qte'] - $tabJobsShiftQtyBooked['count(*)'];
}
$return .= '<div class="camping ' . $strClass . '">';
$return .= '<span class="titre">#'. $i . 'job ' . $tabBenevolePosShift['bps_id'] . '</span>';
$return .= '<span class="taille">' . $tabJobs[$i]['bp_nom_en'] .'</span><br />';
$return .= '<span '.$strStyle.'>' . $intQteTaken . ' taken / ' . $intNbDispoRestant. ' free<br /></span>';
// $return .= '<span '.$strStyle.'>' . $tabJobsShiftQtyBooked['count(*)'] . ' taken / ' . $intNbDispoRestant. ' free<br /></span>';
// $return .= '<span '.$strStyle.'>' . $tabJobsShiftQtyBooked['count(*)'] . ' taken / ' . ($tabBenevolePosShift['bps_qte'] - $tabJobsShiftQtyBooked['count(*)']). ' free<br /></span>';
$return .= '<span class="reserve">' .$strReservee. '</span>';
$return .= '<span class="details"><img class="tooltip" src="'.$vDomaine.'/images/information.png" title="'. htmlspecialchars(fxUnescape($tabJobs[$i]['bp_description_' . $strLangue])) .'" />' . '</span>';
$return .= '</div>';
}
$return .= '</td></tr></table>';
return $return;
}
function fxGetBenevoles($intEvenement) {
global $objDatabase;
$sqlBenevoles = "SELECT * FROM inscriptions_epreuves WHERE epr_actif = 1 AND tep_id = 2 AND eve_id = " . intval($intEvenement);
$arrBenevoles = $objDatabase->fxGetResults($sqlBenevoles);
return $arrBenevoles;
}
function fxGetQteBenevoles($intEpreuve) {
global $objDatabase;
$sqlQte = "SELECT (epr_qte + COUNT(ec.pec_id)) AS dispo, COUNT(ec.pec_id) AS booked FROM inscriptions_epreuves e, resultats_epreuves_commandees ec WHERE e.epr_id = ec.epr_id AND ec.is_cancelled = 0 AND ec.pec_actif = 1 AND e.epr_id = " . intval($intEpreuve);
$arrQte = $objDatabase->fxGetRow($sqlQte);
return $arrQte;
}