14 or $modele < 0){Html::redirect($CFG_GLPI["root_doc"]."/front/ticket.php");}
}else{
Html::redirect($CFG_GLPI["root_doc"]."/front/ticket.php");
}
}else if (!isset($modele)){
Html::redirect($CFG_GLPI["root_doc"]."/front/ticket.php");
}
if( ($_SESSION['glpiactiveprofile']['name'] == "Self-Service" || $_SESSION['glpiactiveprofile']['name'] == "Utilisateur-standard") && $modele == 7){
Html::redirect($CFG_GLPI["root_doc"]."/front/ticket.php");
}
if (Session::getCurrentInterface() == "helpdesk") {
Html::helpHeader("DRH", '', $_SESSION["glpiname"]);
} else {
Html::header("DRH", '', "", "");
}
$title = array("Bulletin de sortie", "Requete Administrative", "Demande de conge" ,"Autorisation d'absence"
,"Autorisation d'entree" , "DEMANDE DE RECRUTEMENT" , "Heures supplémentaires" ,"Demande d'ordre de mission" ,"Congé de récupération"
, "Work Order Form", "AC : Bon De Livraison", "Demande de congé Statutaire","Production : Bon De Commande","MP : Bon De Livraison","Autorisation de paie");
$unites = array("U1", "U2", "U3", "U4", "U5", "U6");
$famtype = array("Matieres Premieres","Etuis","Notices","Aluminium","PVC","Cartons d'emballages","Vignettes"," Etiquettes carton"
,"Scotch","Etiquettes flacon","Injectable","Sirop","Collyre");
$famtypeMp = array("API","Excipient","Gelule","Désinfectant","Injectable");
$congeValues = array("1-Mon mariage","2-Naissance d’un enfant","3-Mariage de l’un des descendants (enfants)"
,"4-Décès d’ascendant (Mère, grande mère, Père, \ngrand père), descendant (Enfants), collatéral
\n(frère, sœur) du travailleur ou de son conjoint","5-Décès du conjoint","6-Circoncision d’un enfant du travailleur"
,"7-Mariage d’un collatéral du travailleur (frère, sœur)","8-Décès de l’un des ascendants (neveu, nièce),\n
(enfants du fils /ou fille du travailleur),\n de la petite famille (oncle)"
,"9-Le retour des parents des lieux saint (petit et grand pèlerinage)");
// $list = getUserHierarchy($_SESSION["glpiID"]);
// print_r($list);
// To check if we are in active payroll period
function ActivePayrollPeriode(){
global $DB;
// Get the current date
$current_date = date("Y-m-d");
// 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, id DESC LIMIT 1");
$query->execute();
$query->bind_result($start_date, $end_date);
$query->fetch();
$query->close();
// If there is no active payroll period, return false
if (!$start_date || !$end_date) {
return false;
}
// Convert the dates to the same format for comparison (Y-m-d)
$start_date = date("Y-m-d", strtotime($start_date));
$end_date = date("Y-m-d", strtotime($end_date));
// Check if the current date is within the start and end date range
if ($current_date >= $start_date && $current_date <= $end_date) {
return true; // Current date is within the active payroll period
}
return false; // Current date is outside the active payroll period
}
// limiter les autorisations(pas plus que 02 fois par mois).
function CountAutorisationByMonthAndYear($modele){
global $DB;
//modele => itilcategories_id
$modele_to_itilcategories_id= array(0=>12, 3=>15, 4=>16, 14=>72 );
$currentDate = new DateTime();
$year = $currentDate->format("Y");
$month = $currentDate->format("m");
$query = "SELECT count(*) as ligne FROM glpi_tickets , glpi_tickets_users
WHERE glpi_tickets.id = glpi_tickets_users.tickets_id
AND glpi_tickets.itilcategories_id = ".$modele_to_itilcategories_id[$modele]."
AND glpi_tickets_users.type = 1
AND EXTRACT(YEAR FROM glpi_tickets.date) = ".$year."
AND EXTRACT(MONTH FROM glpi_tickets.date) = ".$month."
AND glpi_tickets_users.users_id = ".$_SESSION["glpiID"]."
AND glpi_tickets.is_deleted = 0";
$result = $DB->query($query);
if ($result->num_rows > 0) {
$res = $result->fetch_assoc();
return $res['ligne'];
}
return null;
}
function CountPayAutorisation() {
global $DB;
// 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, id DESC LIMIT 1");
$query->execute();
$query->bind_result($start_date, $end_date);
$query->fetch();
$query->close();
// Convert to Y-m-d format
$start_date = date("Y-m-d", strtotime($start_date));
$end_date = date("Y-m-d", strtotime($end_date));
// Secure query with prepared statements
$query = $DB->prepare("
SELECT COUNT(*) as ligne
FROM glpi_tickets
INNER JOIN glpi_tickets_users ON glpi_tickets.id = glpi_tickets_users.tickets_id
WHERE glpi_tickets.itilcategories_id = ?
AND glpi_tickets_users.type = 1
AND DATE(glpi_tickets.date) BETWEEN ? AND ?
AND glpi_tickets_users.users_id = ?
AND glpi_tickets.is_deleted = 0
");
// Bind parameters
$itil_category_id = 72;
$user_id = $_SESSION["glpiID"];
$query->bind_param("issi", $itil_category_id, $start_date, $end_date, $user_id);
$query->execute();
// Fetch the result
$result = $query->get_result();
$row = $result->fetch_assoc();
$query->close();
return $row ? $row['ligne'] : null;
}
function getfullnameResponsable($idResponsable){
global $DB;
$stmt = $DB->prepare("SELECT id , CONCAT(realname,' ', firstname) as fullname from glpi_users where id = ? ");
$stmt->bind_param("i",$idResponsable);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$Responsable = $result->fetch_array(MYSQLI_ASSOC);
}else{
$Responsable['fullname'] = null;
$Responsable['id'] = null;
}
return $Responsable;
}
function getInformationUser(){
global $DB;
$query = "SELECT registration_number as matricule , realname as nom , firstname as prenom , users_id_supervisor as idResponsable from glpi_users where id ='".$_SESSION["glpiID"]."' ";
$result = $DB->query($query);
if ($result->num_rows > 0) {
$InformationUser = $result->fetch_assoc();
// print_r( $InformationUser);
}
return $InformationUser;
}
function getFonction(){
global $DB;
$query = "SELECT picklist.value as fonction from glpi_users , picklist where glpi_users.id_fonction = picklist.id and glpi_users.id ='".$_SESSION["glpiID"]."' ";
$result = $DB->query($query);
if ($result->num_rows > 0) {
$fonction = $result->fetch_assoc();
}
if(!empty($fonction['fonction'])){
return $fonction['fonction'];
}else{
return $fonction = "";
}
}
function getStructure(){
global $DB;
$query = "SELECT picklist.value as structure from glpi_users , picklist
where glpi_users.id_structure = picklist.id and glpi_users.id ='".$_SESSION["glpiID"]."' ";
$result = $DB->query($query);
if ($result->num_rows > 0) {
$structure = $result->fetch_assoc();
}
if(!empty($structure['structure'])){
return $structure['structure'];
}else{
return $structure ="";
}
}
$InformationUser = getInformationUser();
$Responsable = getfullnameResponsable( $InformationUser['idResponsable'] );
$fonction = getFonction() ;
$structure = getStructure();
if(isset($Responsable['id'])){
$_SESSION['idResponsable'] = $Responsable['id'];
}else{
$_SESSION['idResponsable'] = null;
}
$_SESSION['modele'] = $modele ;
$_SESSION['InformationUser'] = $InformationUser;
echo "";
echo "
";
echo "
";
if (Session::getCurrentInterface() == "helpdesk") {
Html::helpFooter();
} else {
Html::footer();
}
function modeles($modele ,$dc_nbr_jour, $type ){
global $unites;
global $famtype;
global $famtypeMp;
global $congeValues;
if(isset($modele)){
echo "";
switch ($modele) {
case 0:
echo"
Est autorisé (e) de sortir le : *
A : *
Heures
Pour affaire Personnelle :
";
break;
case 1:
$val = array("Certificat de travial (accompagné d'un bulletin de paie et attestaion de travail N° de Tél)");
echo'