Files
MYSOPHAL/front/drh.demandes.form.php
2025-08-07 13:15:31 +01:00

1504 lines
34 KiB
PHP
Raw Blame History

<?php
if (!defined('GLPI_ROOT')) {
define('GLPI_ROOT', dirname(__DIR__));
}
include_once GLPI_ROOT . '/inc/based_config.php';
// Init Timer to compute time of display
$TIMER_DEBUG = new Timer();
$TIMER_DEBUG->start();
/// TODO try to remove them if possible
include_once (GLPI_ROOT . "/inc/db.function.php");
// Standard includes
include_once (GLPI_ROOT . "/inc/config.php");
require_once '../functionsophalglpi.php';
Session::checkLoginUser();
//disbled errors =>pour le variable res (Ajax)
ini_set('display_errors', 0);
global $DB;
function ActivePayrollPeriode($date) {
global $DB;
// Prepare the SQL query to get the latest payroll period
$query = $DB->prepare("SELECT start_date, end_date FROM payroll_period where is_deleted = FALSE ORDER BY year DESC, month DESC LIMIT 1");
$query->execute();
$query->bind_result($start_date, $end_date);
$query->fetch();
$query->close();
// If no active payroll period, return false
if (!$start_date || !$end_date) {
return false;
}
// Convert dates to the same format for comparison
$start_date = date("Y-m-d", strtotime($start_date));
$end_date = date("Y-m-d", strtotime($end_date));
$check_date = date("Y-m-d", strtotime($date));
// Check if the given date is within the payroll period
return ($check_date >= $start_date && $check_date <= $end_date);
}
$name = "";
$table = "";
$isWorkOrder = false;
$isBLAC = false;
$isBCPROD = false;
$isBLMP = false;
$last_generated_Sequence_bl = last_generated_Sequence('bon de livraison ac')+1 ;
$last_generated_Sequence_mp = last_generated_Sequence('bon de livraison mp')+1 ;
$last_generated_Sequence_bc = last_generated_Sequence('Bon De Commande Production')+1 ;
$last_generated_Sequence_wo = last_generated_Sequence('work order')+1 ;
$unite = "";
if( isset($_SESSION['modele'])){
switch ($_SESSION['modele']) {
case 0: //BULLETIN DE SORTIE
// Get the submitted date
$bs_date_sortir = $_POST['bs_date_sortir'];
// Get the current date in 'Y-m-d' format
$current_date = date('Y-m-d');
if ($bs_date_sortir < $current_date) {
$_SESSION["bs_date_sortir"] = $bs_date_sortir;
Session::addMessageAfterRedirect(__('VOUS N\'ETES PAS PERMIS'),false, ERROR);
echo json_encode([
'is_valid' => false,
'modele' => $_SESSION['modele']
]);
return ;
}
unset($_SESSION["bs_date_sortir"]);
$name = "Bulletin de sortie";
$table='&lt;table style="height: 136px; width: 100%; border-collapse: collapse;" border="1" cellpadding="5"&gt;&lt;tbody&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 49.1195%; height: 17px;"&gt;&lt;strong&gt;
Matricule :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 50.8805%; height: 17px;"&gt;'.$_POST['matricule'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 49.1195%; height: 17px;"&gt;&lt;strong&gt;
Fonction :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 50.8805%; height: 17px;"&gt;'.$_POST['fonction'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr class="rowHover" style="height: 17px;"&gt;&lt;td style="width: 20%; height: 17px;"&gt;&lt;strong&gt;
Structure :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 50.8805%; height: 17px;"&gt;'.$_POST['structure'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 49.1195%; height: 17px;"&gt;&lt;strong&gt;
Est autorisé (e) de sortir le : &lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 50.8805%; height: 17px;"&gt;'.$_POST['bs_date_sortir'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 49.1195%; height: 17px;"&gt;&lt;strong&gt;
A : &lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 50.8805%; height: 17px;"&gt;'.$_POST['bs_heure'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 49.1195%; height: 17px;"&gt;&lt;strong&gt;
Pour affaire Personnelle :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 50.8805%; height: 17px;"&gt;'.$_POST['bs_affaire_personnelle'].'&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;';
break;
case 1://REQUETE ADMINISTRATIVE
$name = "Requete Administrative";
$table = '&lt;table style="border-collapse: collapse; width: 100%; height: 85px;" border="1"&gt;&lt;tbody&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 33.187%; height: 17px;"&gt;&lt;strong&gt;
Matricule :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 66.813%; height: 17px;"&gt;'.$_POST['matricule'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 33.187%; height: 17px;"&gt;&lt;strong&gt;
Fonction :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 66.813%; height: 17px;"&gt;'.$_POST['fonction'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr class="rowHover" style="height: 17px;"&gt;&lt;td style="width: 33.187%; height: 17px;"&gt;&lt;strong&gt;
Structure :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 66.813%; height: 17px;"&gt;'.$_POST['structure'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 33.187%; height: 17px;"&gt;&lt;strong&gt;
Demande :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 66.813%; height: 17px;"&gt;'.$_POST['ra_demande'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 33.187%; height: 17px;"&gt;&lt;strong&gt;
Préciser :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 66.813%; height: 17px;"&gt;'.$_POST['ra_autres'].'&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;';
break;
case 2://DEMANDE DE CONGE
// Get number de jours
$dc_nbr_jour = $_POST['dc_nbr_jour'];
if ($dc_nbr_jour < 7) {
Session::addMessageAfterRedirect(__('VOUS N\'ETES PAS PERMIS'),false, ERROR);
echo json_encode([
'is_valid' => false,
'modele' => $_SESSION['modele']
]);
return ;
}
$name = "Demande de congé";
$table = '&lt;table style="border-collapse: collapse; width: 100%; height: 136px;" border="1"&gt;&lt;tbody&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Matricule :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['matricule'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Fonction :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['fonction'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Structure :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['structure'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Nombre de jours :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['dc_nbr_jour'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr class="rowHover" style="height: 17px;"&gt;&lt;td style="width: 20%; height: 17px;"&gt;&lt;strong&gt;
Exercice : &lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['dc_exercice'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Date de Départ : &lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['dc_date_depart'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Intérimaire :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['dc_interimaire'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Adresse durant le Congé :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['dc_adresse'].'&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;';
break;
case 3://Autorisation d'absence
// Get the submitted date
$aa_date_absenter = $_POST['aa_date_absenter'];
// Get the current date in 'Y-m-d' format
$current_date = date('Y-m-d');
if ($aa_date_absenter < $current_date) {
$_SESSION["aa_date_absenter"] = $aa_date_absenter;
Session::addMessageAfterRedirect(__('VOUS N\'ETES PAS PERMIS'),false, ERROR);
echo json_encode([
'is_valid' => false,
'modele' => $_SESSION['modele']
]);
return ;
}
unset($_SESSION["aa_date_absenter"]);
$name = "Autorisation d'absence";
$table ='Matricule : '.$_POST['matricule'].'<br>Fonction : '.$_POST['fonction'].'<br> Structure : '.$_POST['structure'].'
<br> Est autorisé (e) à s&apos;absenter la journée du : '.$_POST['aa_date_absenter'].'<br> Commentaire : '.$_POST['aa_commentaire'].'';
break;
case 4://AUTORISATION D'ENTREE
// Get the submitted date
$ae_date_reprendre = $_POST['ae_date_reprendre'];
// Get the current date in 'Y-m-d' format
$current_date = date('Y-m-d');
if ($ae_date_reprendre < $current_date) {
$_SESSION["ae_date_reprendre"] = $ae_date_reprendre;
Session::addMessageAfterRedirect(__('VOUS N\'ETES PAS PERMIS'),false, ERROR);
echo json_encode([
'is_valid' => false,
'modele' => $_SESSION['modele']
]);
return ;
}
unset($_SESSION["ae_date_reprendre"]);
$name = "Autorisation d'entree";
$table ='Matricule : '.$_POST['matricule'].'<br>Fonction : '.$_POST['fonction'].'<br>Structure : '.$_POST['structure'].'
<br>Est autorisé (e) de reprendre à : '.$_POST['ae_date_reprendre'].'<br> Commentaire : '.$_POST['ae_commentaire'];
break;
case 5://DEMANDE DE RECRUTEMENT
$name = "DEMANDE DE RECRUTEMENT";
$table ='matricule : '.$_POST['matricule'].'<br>fonction : '.$_POST['fonction'].'<br>structure : '.$_POST['structure'].'<br><br>description : '.$_POST['description'];
break;
case 6://Heures supplémentaires
// Get the submitted date
$date_req = $_POST['date_req'];
$current_date = date('Y-m-d');
// Calculate the date two days ago from today
$two_days_ago = date('Y-m-d', strtotime('-2 days', strtotime($current_date)));
if ($date_req < $two_days_ago) {
$_SESSION["date_req"] = $date_req;
$_SESSION["mot_req"] = $_POST['mot_req'];
$_SESSION["heure_d"] = $_POST['heure_d'];
$_SESSION["heure_f"] = $_POST['heure_f'];
$_SESSION["lieu_de_travail"] = $_POST['lieu_de_travail'];
Session::addMessageAfterRedirect(__('VOUS N\'ETES PAS PERMIS'),false, ERROR);
echo json_encode([
'is_valid' => false,
'modele' => $_SESSION['modele']
]);
return ;
}
unset($_SESSION["date_req"]);
unset($_SESSION["mot_req"]);
unset($_SESSION["heure_d"]);
unset($_SESSION["heure_f"]);
unset($_SESSION["lieu_de_travail"]);
$name = "HEURES SUPPLEMENTAIRES";
$table ='matricule : '.$_POST['matricule'].'<br>fonction : '.$_POST['fonction'].'<br>structure : '.$_POST['structure'].'<br>
<br>Date de réquisition : '.$_POST['date_req'].'<br>Le motif de la réquisition : '.$_POST['mot_req'].'<br>Heure de début : '.$_POST['heure_d'].'
<br>Heure de fin : '.$_POST['heure_f'].'<br>Lieu de travail : '.$_POST['lieu_de_travail'];
break;
case 7://DEMANDE ORDRE DE MISSION
$name = "DEMANDE ORDRE DE MISSION";
$table ='matricule : '.$_POST['matricule'].'<br>fonction : '.$_POST['fonction'].'<br>structure : '.$_POST['structure'].'<br>
<br>Date de départ : '.$_POST['date_de_depart'].'<br>date de retour : '.$_POST['date_de_retour'].'<br>Destination : '.$_POST['destination'].'
<br>Moyens de Transport : '.$_POST['moy_transport'].'<br>Objet de la mission : '.$_POST['ob_mission'];
break;
case 8://CONGE DE RECUPERATION
$cr_date_debut = $_POST['cr_date_debut'];
$cr_date_fin = $_POST['cr_date_fin'];
$current_date = date('Y-m-d');
if ($cr_date_debut < $current_date || $cr_date_fin < $cr_date_debut) {
$_SESSION["cr_date_debut"] = $cr_date_debut;
$_SESSION["cr_date_fin"] = $cr_date_fin;
Session::addMessageAfterRedirect(__('VOUS N\'ETES PAS PERMIS'),false, ERROR);
echo json_encode([
'is_valid' => false,
'modele' => $_SESSION['modele']
]);
return ;
}
unset($_SESSION["cr_date_debut"]);
unset($_SESSION["cr_date_fin"]);
$name = "CONGE DE RECUPERATION";
$numberOfVariables = count($_POST);
$table ='matricule : '.$_POST['matricule'].'<br>fonction : '.$_POST['fonction'].'<br>structure : '.$_POST['structure'].'
<br>De : '.$_POST['cr_date_debut'].'<br>A : '.$_POST['cr_date_fin'].'<br>commentaire : '
.$_POST['cr_date_1'];
if(isset($_POST['cr_date_2']) && $_POST['cr_date_2'] != '') $table = $table.",".$_POST['cr_date_2'];
if(isset($_POST['cr_date_3']) && $_POST['cr_date_3'] != '') $table = $table.",".$_POST['cr_date_3'];
if(isset($_POST['cr_date_4']) && $_POST['cr_date_4'] != '') $table = $table.",".$_POST['cr_date_4'];
if(isset($_POST['cr_date_5']) && $_POST['cr_date_5'] != '') $table = $table.",".$_POST['cr_date_5'];
if(isset($_POST['cr_date_6']) && $_POST['cr_date_6'] != '') $table = $table.",".$_POST['cr_date_6'];
break;
case 9://Work Order
$name = "Work Order Form";
$unite = $_POST['wo_unitNum'] ?? '';
$table ='matricule : '.$_POST['matricule'].'<br>fonction : '.$_POST['fonction'].'<br>structure : '.$_POST['structure'].'
<br>Work order N° : '.str_pad($last_generated_Sequence_wo , 6, '0', STR_PAD_LEFT).'<br>Unite N°: '.$_POST['wo_unitNum'].'<br>From (Dept.): '.$_POST['wo_fromdep'].'<br>Location: '.$_POST['wo_location'].'
<br>Operator Name: '.$_POST['wo_opname'].'<br>Work Order Type : '.$_POST['wo_type'].'<br>Equipment/machine utility Name : '.$_POST['wo_equipment'].'
<br>Code N° : '.$_POST['wo_equipment_num'].'<br>Problem Type : '.$_POST['wo_prob_type'].'
<br>Date: '.$_POST['wo_date'].'<br>Time : '.$_POST['wo_heure'].'<br>Problem Description : '.$_POST['wo_description'];
$isWorkOrder = true;
break;
case 10:
$isBLAC = true;
$name = "AC : Bon De Livraison";
$table ='matricule : '.$_POST['matricule'].'<br>fonction : '.$_POST['fonction'].'<br>structure : '.$_POST['structure'].'<br>'.'
<br>N° de Piece : BL AC'.str_pad($last_generated_Sequence_bl , 6, '0', STR_PAD_LEFT).'/'.(date("y")).'<br>Référence : '.$_POST['acbc_reference'].'<br><br>';
$nbr = count($_POST["designation"]);
for($i=0;$i < $nbr ;$i++){
$table = $table.' '.$_POST['type'][$i].': <br>&nbsp;&nbsp;&nbsp; Désignation : '.
$_POST['designation'][$i].'<br>&nbsp;&nbsp;&nbsp; N° Lot : '.
$_POST['lot'][$i].'<br>&nbsp;&nbsp;&nbsp; Quantité Livrée : '.
$_POST['quantite'][$i].' <br>&nbsp;&nbsp;&nbsp; Observations : '.
$_POST['obs'][$i].' <br>&nbsp;&nbsp;&nbsp;'.
'<br>';
}
break;
case 11:
$name = "Demande de congé statutaire";
$table = '&lt;table style="border-collapse: collapse; width: 100%; height: 136px;" border="1"&gt;&lt;tbody&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Matricule :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['matricule'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Fonction :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['fonction'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Structure :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['structure'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Raison : &lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.explode("-",$_POST['dcs_raison'])[1].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Nombre de jours :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['dcs_nbr_jour'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr class="rowHover" style="height: 17px;"&gt;&lt;td style="width: 20%; height: 17px;"&gt;&lt;strong&gt;
Date de Départ : &lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['dcs_date_depart'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;
Intérimaire :&lt;/strong&gt;&lt;/td&gt;&lt;td style="width: 60.624%; height: 17px;"&gt; '.$_POST['dcs_interimaire'].'&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 17px;"&gt;&lt;td style="width: 39.376%; height: 17px;"&gt;&lt;strong&gt;';
break;
case 12:
$isBCPROD = true;
$name = "Production : Bon De Commande";
$table ='matricule : '.$_POST['matricule'].'<br>fonction : '.$_POST['fonction'].'<br>structure : '.$_POST['structure'].'<br>'.'
<br>N° de Piece : BC PROD'.str_pad($last_generated_Sequence_bc , 6, '0', STR_PAD_LEFT).'/'.(date("y")).'<br>Hangar : '.$_POST['acbc_reference'].'<br><br>';
$nbr = count($_POST["designation"]);
for($i=0;$i < $nbr ;$i++){
$table = $table.' '.$_POST['type'][$i].': <br>&nbsp;&nbsp;&nbsp; Désignation : '.
$_POST['designation'][$i].'<br>&nbsp;&nbsp;&nbsp; N° Lot : '.
$_POST['lot'][$i].'<br>&nbsp;&nbsp;&nbsp; Quantité Livrée : '.
$_POST['quantite'][$i].' <br>&nbsp;&nbsp;&nbsp; Observations : '.
$_POST['obs'][$i].' <br>&nbsp;&nbsp;&nbsp;'.
'<br>';
}
break;
case 13:
$isBLMP = true;
$name = "MP : Bon De Livraison";
$table ='matricule : '.$_POST['matricule'].'<br>fonction : '.$_POST['fonction'].'<br>structure : '.$_POST['structure'].'<br>'.'
<br>N° de Piece : BL '.str_pad($last_generated_Sequence_mp , 6, '0', STR_PAD_LEFT).'/'.(date("y")).'<br>Référence : '.$_POST['acbc_reference'].'<br><br>';
$nbr = count($_POST["designation"]);
for($i=0;$i < $nbr ;$i++){
$table = $table.' '.$_POST['type'][$i].': <br>&nbsp;&nbsp;&nbsp; Désignation : '.
$_POST['designation'][$i].'<br>&nbsp;&nbsp;&nbsp; N° Lot : '.
$_POST['lot'][$i].'<br>&nbsp;&nbsp;&nbsp; Quantité Livrée : '.
$_POST['quantite'][$i].' <br>&nbsp;&nbsp;&nbsp; Observations : '.
$_POST['obs'][$i].' <br>&nbsp;&nbsp;&nbsp;'.
'<br>';
}
break;
case 14:
// Get the submitted data
$ap_date = $_POST['ap_date'];
$ap_start_time = $_POST['ap_start_time'];
$ap_end_time = $_POST['ap_end_time'];
// Get the current date in 'Y-m-d' format
$current_date = date('Y-m-d');
// Check if the authorization date is within the active payroll period
if (!ActivePayrollPeriode($ap_date)) {
$_SESSION["ap_date"] = $ap_date;
$_SESSION["ap_start_time"] = $ap_start_time;
$_SESSION["ap_end_time"] = $ap_end_time;
Session::addMessageAfterRedirect(__('La date sp<73>cifi<66>e n\'est pas dans la p<>riode de paye active.'), false, ERROR);
echo json_encode([
'is_valid' => false,
'modele' => $_SESSION['modele']
]);
return;
}
if ($ap_date < $current_date) {
$_SESSION["ap_date"] = $ap_date;
$_SESSION["ap_start_time"] = $ap_start_time;
$_SESSION["ap_end_time"] = $ap_end_time;
Session::addMessageAfterRedirect(__('VOUS N\'ETES PAS PERMIS'),false, ERROR);
echo json_encode([
'is_valid' => false,
'modele' => $_SESSION['modele']
]);
return ;
}
if ($ap_end_time < $ap_start_time) {
$_SESSION["ap_date"] = $ap_date;
$_SESSION["ap_start_time"] = $ap_start_time;
$_SESSION["ap_end_time"] = $ap_end_time;
Session::addMessageAfterRedirect(__('Heure de d<>but est sup<75>rieur <20> la date du d<>but'),false, ERROR);
echo json_encode([
'is_valid' => false,
'modele' => $_SESSION['modele']
]);
return ;
}
// Calculate the duration between start and end times
$start_time = strtotime($ap_start_time);
$end_time = strtotime($ap_end_time);
$duration_in_hours = ($end_time - $start_time) / 3600;
// Check if the duration exceeds 4 hours
if ($duration_in_hours > 4) {
$_SESSION["ap_date"] = $ap_date;
$_SESSION["ap_start_time"] = $ap_start_time;
$_SESSION["ap_end_time"] = $ap_end_time;
Session::addMessageAfterRedirect(__('La dur<75>e de l\'autorisation ne doit pas d<>passer 4 heures'), false, ERROR);
echo json_encode([
'is_valid' => false,
'modele' => $_SESSION['modele']
]);
return;
}
unset($_SESSION["ap_date"]);
unset($_SESSION["ap_start_time"]);
unset($_SESSION["ap_end_time"]);
$name = "Autorisation de paie";
$table ='Matricule : '.$_POST['matricule'].'<br>Fonction : '.$_POST['fonction'].'<br>Structure : '.$_POST['structure'].'
<br>Est autorise le : '.$_POST['ap_date'].'<br> Du : '.$_POST['ap_start_time'].'<br> a : '.$_POST['ap_end_time'];
break;
}
}
//glpi_itilcategories =>itilcategories_id
$id_categorie = array("Bulletin de sortie"=>"12" ,"Requete Administrative"=>"13" , "Demande de congé"=>"14", "Autorisation d'absence"=>"15",
"Autorisation d'entree"=>"16" , "DEMANDE DE RECRUTEMENT"=>"35" , "HEURES SUPPLEMENTAIRES"=>"36" ,"DEMANDE ORDRE DE MISSION" => "37" ,
"CONGE DE RECUPERATION" => "38", "Work Order Form" => "40", "AC : Bon De Livraison" => "47","Demande de congé statutaire"=>"14",
"Production : Bon De Commande" => "54", "MP : Bon De Livraison" => "55", "Autorisation de paie" => "72");
if($_SESSION['token'] == $_POST['_glpi_csrf_token']){
unset($_SESSION['token']);
add_ticket($id_categorie[$name],$name,$table,$_SESSION["glpiID"]);
$tickets_id = $DB->insert_id();
add_User_Demandeur($tickets_id , $_SESSION["glpiID"]);
if ($isWorkOrder){
if ($unite == "" && $$_POST['wo_prob_type'] == "Climatisation") {
add_Group_Observateur($tickets_id , 30);
add_Group_Attribue($tickets_id , 30);
} else {
switch($unite){
case "U1":
if($_POST['wo_prob_type'] =="Mechanical"){
add_Group_Observateur($tickets_id , 20 );
add_Group_Attribue($tickets_id , 20) ;
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
add_Group_Observateur($tickets_id , 25 );
add_Group_Attribue($tickets_id , 25) ;
} else{
add_Group_Observateur($tickets_id , 26 );
add_Group_Attribue($tickets_id , 26) ;
}
break;
case "U2":
if($_POST['wo_prob_type'] =="Mechanical"){
add_Group_Observateur($tickets_id , 21 );
add_Group_Attribue($tickets_id , 21) ;
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
add_Group_Observateur($tickets_id , 25 );
add_Group_Attribue($tickets_id , 25) ;
} else{
add_Group_Observateur($tickets_id , 26 );
add_Group_Attribue($tickets_id , 26) ;
}
break;
case "U3":
if($_POST['wo_prob_type'] =="Mechanical"){
add_Group_Observateur($tickets_id , 22 );
add_Group_Attribue($tickets_id , 22) ;
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
add_Group_Observateur($tickets_id , 25 );
add_Group_Attribue($tickets_id , 25) ;
} else{
add_Group_Observateur($tickets_id , 26 );
add_Group_Attribue($tickets_id , 26) ;
}
break;
case "U4":
if($_POST['wo_prob_type'] =="Mechanical"){
add_Group_Observateur($tickets_id , 23 );
add_Group_Attribue($tickets_id , 23) ;
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
add_Group_Observateur($tickets_id , 25 );
add_Group_Attribue($tickets_id , 25) ;
} else{
add_Group_Observateur($tickets_id , 26 );
add_Group_Attribue($tickets_id , 26) ;
}
break;
case "U5":
if($_POST['wo_prob_type'] =="Mechanical"){
add_Group_Observateur($tickets_id , 24 );
add_Group_Attribue($tickets_id , 24) ;
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
add_Group_Observateur($tickets_id , 25 );
add_Group_Attribue($tickets_id , 25) ;
} else{
add_Group_Observateur($tickets_id , 26 );
add_Group_Attribue($tickets_id , 26) ;
}
break;
case "U6":
if($_POST['wo_prob_type'] =="Mechanical"){
add_Group_Observateur($tickets_id , 35 );
add_Group_Attribue($tickets_id , 35) ;
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
add_Group_Observateur($tickets_id , 25 );
add_Group_Attribue($tickets_id , 25) ;
} else{
add_Group_Observateur($tickets_id , 26 );
add_Group_Attribue($tickets_id , 26) ;
}
break;
default:
add_Group_Observateur($tickets_id , 19 );
add_Group_Attribue($tickets_id , 19) ;
break;
}
}
update_sequence($last_generated_Sequence_wo ,'work order');
}else if($isBLAC){
update_sequence($last_generated_Sequence_bl ,'bon de livraison ac');
atributeTo($tickets_id,$_SESSION["glpiID"]);
changeStatusTo($tickets_id,5);
}else if($isBLMP){
update_sequence($last_generated_Sequence_mp ,'bon de livraison mp');
atributeTo($tickets_id,$_SESSION["glpiID"]);
changeStatusTo($tickets_id,5);
}else if($isBCPROD){
update_sequence($last_generated_Sequence_bc ,'Bon De Commande Production');
if($_POST['acbc_magasin'] == 'AC')
atributeTo($tickets_id,647);// responsable Magasin AC // CHANGED TO KRATTAR
else
atributeTo($tickets_id,292);// responsable Magasin MP // CHANGED TO YAZIDI
changeStatusTo($tickets_id,5);
}else{
add_Group_Observateur($tickets_id , 10 );
add_Group_Attribue($tickets_id , 10) ;
}
switch ($name) {
case "Requete Administrative":
if($_POST['ra_demande'] == 'Attestation de travail'){
add_Attestation_Travail($tickets_id);
}
break;
case "DEMANDE DE RECRUTEMENT":
soumis_a_validation($tickets_id);
add_validation_percent($tickets_id);
add_Validation($tickets_id ,239,$_SESSION["glpiID"]); //validation DRH id=239
add_Validation($tickets_id ,23,$_SESSION["glpiID"]); //validation DGA id=23
break;
case "DEMANDE ORDRE DE MISSION":
soumis_a_validation($tickets_id);
add_Validation($tickets_id ,239,$_SESSION["glpiID"]);
break;
case "Demande de congé":
soumis_a_validation($tickets_id);
add_validation_percent($tickets_id);
// if(!empty($_SESSION['idResponsable'])){
// add_Validation($tickets_id ,$_SESSION['idResponsable'],$_SESSION["glpiID"]);
// }
//add validation de directeur
//si existe DGA dans la list alor leur index - 1
//si n'existe pas DGA dans la list alor obtenir le dernière
$list = getUserHierarchy($_SESSION["glpiID"]);
if(($index = array_search(23,$list)) !== false){ unset($list[$index]); } //delete DGA
if(($index = array_search(22,$list)) !== false){ unset($list[$index]); } //delete DG
for($k = 1 ; $k < count($list) ; $k++){
add_Validation($tickets_id ,$list[$k],$_SESSION["glpiID"]);
}
// $index = array_search(23,$list);
// if($index){
// if($index - 1 > 1){
// add_Validation($tickets_id ,$list[$index - 1],$_SESSION["glpiID"]);
// }
// }else{
// if(count($list) > 2) {
// add_Validation($tickets_id ,end($list),$_SESSION["glpiID"]);
// }
// }
add_Validation($tickets_id ,239,$_SESSION["glpiID"]);
add_conge($_POST , $tickets_id);
break;
case "Work Order Form":
soumis_a_validation($tickets_id);
add_validation_percent($tickets_id);
//validation résponsable
// if(!empty($_SESSION['idResponsable'])){
// add_Validation($tickets_id ,$_SESSION['idResponsable'],$_SESSION["glpiID"]);
// }
//add_Validation($tickets_id ,239,$_SESSION["glpiID"]);
if ($unite == "" && $_POST['wo_prob_type'] == "Climatisation") {
foreach(get_group_users(30) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} else {
switch($unite){
case "U1":
if($_POST['wo_prob_type'] =="Mechanical"){
foreach(get_group_users(20) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
foreach(get_group_users(25) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} else{
foreach(get_group_users(26) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
}
break;
case "U2":
if($_POST['wo_prob_type'] =="Mechanical"){
foreach(get_group_users(21) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
foreach(get_group_users(25) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} else{
foreach(get_group_users(26) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
}
break;
case "U3":
if($_POST['wo_prob_type'] =="Mechanical"){
foreach(get_group_users(22) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
foreach(get_group_users(25) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} else{
foreach(get_group_users(26) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
}
break;
case "U4":
if($_POST['wo_prob_type'] =="Mechanical"){
foreach(get_group_users(23) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
foreach(get_group_users(25) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} else{
foreach(get_group_users(26) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
}
break;
case "U5":
if($_POST['wo_prob_type'] =="Mechanical"){
foreach(get_group_users(24) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
foreach(get_group_users(25) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} else{
foreach(get_group_users(26) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
}
break;
case "U6":
if($_POST['wo_prob_type'] =="Mechanical"){
foreach(get_group_users(35) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} elseif ($_POST['wo_prob_type'] =="Instrumentation"){
foreach(get_group_users(25) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
} else{
foreach(get_group_users(26) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
}
break;
default:
foreach(get_group_users(19) as $usID){
add_Validation($tickets_id,$usID["users_id"],$_SESSION["glpiID"]);
}
break;
}
}
//add Observateurs
$ids = getUserHierarchy($_SESSION["glpiID"]);
foreach($ids as $id){
if($id != 23 && $id != 22){
add_User_Observateur($tickets_id ,$id);
}
}
break;
case "AC : Bon De Livraison":
//soumis_a_validation($tickets_id);
//add_validation_percent($tickets_id);
//validation résponsable
// if(!empty($_SESSION['idResponsable'])){
// add_Validation($tickets_id ,$_SESSION['idResponsable'],$_SESSION["glpiID"]);
// }
//add Observateurs
$ids = getUserHierarchy($_SESSION["glpiID"]);
foreach($ids as $id){
if($id != 23 && $id != 22){
add_User_Observateur($tickets_id ,$id);
}
}
break;
case "MP : Bon De Livraison":
$ids = getUserHierarchy($_SESSION["glpiID"]);
foreach($ids as $id){
if($id != 23 && $id != 22){
add_User_Observateur($tickets_id ,$id);
}
}
break;
case "Production : Bon De Commande":
//add Observateurs
$ids = getUserHierarchy($_SESSION["glpiID"]);
foreach($ids as $id){
if($id != 23 && $id != 22){
add_User_Observateur($tickets_id ,$id);
}
}
break;
case "Demande de congé statutaire":
soumis_a_validation($tickets_id);
add_validation_percent($tickets_id);
//add validation de directeur
//si existe DGA dans la list alor leur index - 1
//si n'existe pas DGA dans la list alor obtenir le dernière
$list = getUserHierarchy($_SESSION["glpiID"]);
if(($index = array_search(23,$list)) !== false){ unset($list[$index]); } //delete DGA
if(($index = array_search(22,$list)) !== false){ unset($list[$index]); } //delete DG
for($k = 1 ; $k < count($list) ; $k++){
add_Validation($tickets_id ,$list[$k],$_SESSION["glpiID"]);
}
add_Validation($tickets_id ,239,$_SESSION["glpiID"]);
add_conge($_POST , $tickets_id);
break;
default:
soumis_a_validation($tickets_id);
add_validation_percent($tickets_id);
//validation résponsable
if(!empty($_SESSION['idResponsable'])){
add_Validation($tickets_id ,$_SESSION['idResponsable'],$_SESSION["glpiID"]);
}
//add_Validation($tickets_id ,239,$_SESSION["glpiID"]);
//add Observateurs
$ids = getUserHierarchy($_SESSION["glpiID"]);
foreach($ids as $id){
if($id != 23 && $id != 22){
add_User_Observateur($tickets_id ,$id);
}
}
}
}