334 lines
		
	
	
		
			17 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			334 lines
		
	
	
		
			17 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| use Glpi\Event;
 | |
| include ('../inc/includes.php');
 | |
| Session::checkLoginUser();
 | |
| require_once '../functionsophalglpi.php';
 | |
| if (isset($_GET['content'])){
 | |
|     $data_populated = false;
 | |
|     switch ($_GET['content']) {
 | |
|         case "HS":
 | |
|             $result = getHSEmployees(true,36);//Heurs sup
 | |
|             $title = "Export_Heur_Sup_";
 | |
|             $header = ['Nom','Matricule','Fonction','Structure','Date de requisition',
 | |
|             'Motif de requisition','Heure de debut','Heure de fin','Lieu de travail','Validation','Ticket'];
 | |
|             $final_data = array();
 | |
|             // print_r(explode("<br>",html_entity_decode(str_replace('<br />','<br>',$result[0]['content']))));
 | |
|             // print_r($result);
 | |
|             foreach($result as $res){
 | |
|                 // $temp = explode("<br />",html_entity_decode($res['content']));
 | |
|                 if($res){
 | |
|                     $temp = array();
 | |
|                     $temp_content = explode("<br>",html_entity_decode(str_replace("r /","r",$res['content'])));
 | |
|                     array_push($temp,$res['name']);
 | |
|                     array_push($temp,explode(':',$temp_content[0])[1]);
 | |
|                     array_push($temp,explode(':',$temp_content[1])[1]);
 | |
|                     array_push($temp,explode(':',$temp_content[2])[1]);
 | |
|                     array_push($temp,explode(':',$temp_content[4])[1]);
 | |
|                     array_push($temp,explode(':',$temp_content[5])[1]);
 | |
|                     array_push($temp,explode(':',$temp_content[6])[1]);
 | |
|                     array_push($temp,explode(':',$temp_content[7])[1]);
 | |
|                     array_push($temp,strip_tags(explode(':',$temp_content[8])[1]));
 | |
|                     array_push($temp,$res['Validation']);
 | |
|                     array_push($temp,'https://dsi.sophal.dz/front/ticket.form.php?id='.$res['id']);
 | |
|                     // print_r($temp);
 | |
|                     //print_r($temp);
 | |
|                     array_push($final_data,$temp);
 | |
|                 }
 | |
|             }
 | |
|             $data_populated = true;
 | |
|             break;
 | |
|         case "AA":
 | |
|             $result = getHSEmployees(true,15);//Autorisation Absenece
 | |
|             $title = "Export_Autorisation_abs_";
 | |
|             $header = ['Nom','Matricule','Fonction','Structure','la journee d\'absence','Commentaire','Validation','Ticket'];
 | |
|             $final_data = array();
 | |
|             //print_r(explode("<br>",html_entity_decode(str_replace('<br />','<br>',$result[0]['content']))));
 | |
|             foreach($result as $res){
 | |
|                 // $temp = explode("<br />",html_entity_decode($res['content']));
 | |
|                 if($res){
 | |
|                     $temp = array();
 | |
|                     $temp_content = explode("<br>",html_entity_decode(str_replace("r /","r",$res['content'])));
 | |
|                     
 | |
|                     if(str_contains($res['content'],"<table")){
 | |
|                         $DOM = new DOMDocument();
 | |
|                         $internalErrors = libxml_use_internal_errors(true);
 | |
| 	                    $DOM->loadHTML(html_entity_decode($res['content']));
 | |
|                         libxml_use_internal_errors($internalErrors);
 | |
| 	                    $Detail = $DOM->getElementsByTagName('td');
 | |
| 
 | |
|             
 | |
| 	                    foreach($Detail as $NodeHeader) 
 | |
| 	                    {
 | |
| 		                    $aDataTableHeaderHTML[] = trim($NodeHeader->textContent);
 | |
| 	                    }
 | |
|                         array_push($temp,$res['name']);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[1]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[3]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[5]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[7]);
 | |
|                         array_push($temp,"");
 | |
|                         array_push($temp,$res['Validation']);
 | |
|                         array_push($temp,'https://dsi.sophal.dz/front/ticket.form.php?id='.$res['id']);
 | |
|                         $aDataTableHeaderHTML = null;
 | |
|                         //print_r($temp);
 | |
|                         //echo"<br>";
 | |
|                         array_push($final_data,$temp);
 | |
|                         } else {
 | |
|                             array_push($temp,$res['name']);
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[0])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[1])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[2])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[3])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[4])[1] : "");
 | |
|                             array_push($temp,$res['Validation']);
 | |
|                             array_push($temp,'https://dsi.sophal.dz/front/ticket.form.php?id='.$res['id']);
 | |
| 
 | |
|                             //print_r($temp);
 | |
|                             array_push($final_data,$temp);
 | |
|                         }
 | |
|                 }
 | |
|             }
 | |
|             $data_populated = true;
 | |
|             // print_r($result);
 | |
|             break;
 | |
|         case "AE":
 | |
|             $result = getHSEmployees(true,16);//Autorisation Entrer
 | |
|             $title = "Export_Autorisation_entr_";
 | |
|             $header = ['Nom','Matricule','Fonction','Structure','la journee de reprise','Commentaire','Validation','Ticket'];
 | |
|             $final_data = array();
 | |
|             
 | |
|             foreach($result as $res){
 | |
|                 // $temp = explode("<br />",html_entity_decode($res['content']));
 | |
|                 if($res){
 | |
|                     $temp = array();
 | |
|                     $temp_content = explode("<br>",html_entity_decode(str_replace("r /","r",$res['content'])));
 | |
|                     array_push($temp,$res['name']);
 | |
|                     array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[0])[1] : "");
 | |
|                     array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[1])[1] : "");
 | |
|                     array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[2])[1] : "");
 | |
|                     array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[3])[1] : "");
 | |
|                     array_push($temp,str_contains($res['content'],"Commentaire:") ? explode(':',$temp_content[4])[1] : "");
 | |
|                     array_push($temp,$res['Validation']);
 | |
|                     array_push($temp,'https://dsi.sophal.dz/front/ticket.form.php?id='.$res['id']);
 | |
|                     
 | |
|                     //print_r($temp);
 | |
|                     array_push($final_data,$temp);
 | |
|                 }
 | |
|             }
 | |
|             $data_populated = true;
 | |
|             break;
 | |
|         case "AS":
 | |
|             $result = getHSEmployees(true,12);//Autorisation Sortie
 | |
|             $title = "Export_Bulletin_Sortie_";
 | |
|             $header = ['Nom','Matricule','Fonction','Structure','Date autorisation de sortie','Heure','Pour','Validation','Ticket'];
 | |
|             $final_data = array();
 | |
|             //print_r(explode("<br>",html_entity_decode(str_replace('<br />','<br>',$result[0]['content']))));
 | |
|             foreach($result as $res){
 | |
|                 // $temp = explode("<br />",html_entity_decode($res['content']));
 | |
|                 if($res){
 | |
|                     $temp = array();
 | |
|                     $temp_content = explode("<br>",html_entity_decode(str_replace("r /","r",$res['content'])));
 | |
|                     
 | |
|                     if(str_contains($res['content'],"<table")){
 | |
|                         $DOM = new DOMDocument();
 | |
|                         $internalErrors = libxml_use_internal_errors(true);
 | |
|                         $DOM->loadHTML(html_entity_decode($res['content']));
 | |
|                         libxml_use_internal_errors($internalErrors);
 | |
|                         $Detail = $DOM->getElementsByTagName('td');
 | |
|     
 | |
|             
 | |
|                         foreach($Detail as $NodeHeader) 
 | |
|                         {
 | |
|                             $aDataTableHeaderHTML[] = trim($NodeHeader->textContent);
 | |
|                         }
 | |
|                         
 | |
|                         array_push($temp,$res['name']);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[1]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[3]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[5]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[7]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[9]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[11]);
 | |
|                         array_push($temp,$res['Validation']);
 | |
|                         array_push($temp,'https://dsi.sophal.dz/front/ticket.form.php?id='.$res['id']);
 | |
|                         $aDataTableHeaderHTML = null;
 | |
|                         //print_r($temp);
 | |
|                         //echo"<br>";
 | |
|                         array_push($final_data,$temp);
 | |
|                         } else {
 | |
|                             array_push($temp,$res['name']);
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[0])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[1])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[2])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[3])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[4])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[5])[1] : "");
 | |
|                             array_push($temp,$res['Validation']);
 | |
|                             array_push($temp,'https://dsi.sophal.dz/front/ticket.form.php?id='.$res['id']);
 | |
|     
 | |
|                             //print_r($temp_content);
 | |
|                             //echo"<br>";
 | |
|                             array_push($final_data,$temp);
 | |
|                         }
 | |
|                 }
 | |
|             }
 | |
|             $data_populated = true;
 | |
|             // print_r($result);
 | |
|             break;
 | |
|         case "CR":
 | |
|             $result = getHSEmployees(true,38);//Conge de recuperation
 | |
|             $title = "Export_Conge_Recup_";
 | |
|             $header = ['Nom','Matricule','Fonction','Structure','Date debut','Date fin','Commentaire','Validation','Ticket'];
 | |
|             $final_data = array();
 | |
|             //print_r(explode("<br>",html_entity_decode(str_replace('<br />','<br>',$result[0]['content']))));
 | |
|             foreach($result as $res){
 | |
|                 // $temp = explode("<br />",html_entity_decode($res['content']));
 | |
|                 if($res){
 | |
|                     $temp = array();
 | |
|                     $temp_content = explode("<br>",html_entity_decode(str_replace("r /","r",$res['content'])));
 | |
|                     
 | |
|                     if(str_contains($res['content'],"<table")){
 | |
|                         $DOM = new DOMDocument();
 | |
|                         $internalErrors = libxml_use_internal_errors(true);
 | |
|                         $DOM->loadHTML(html_entity_decode($res['content']));
 | |
|                         libxml_use_internal_errors($internalErrors);
 | |
|                         $Detail = $DOM->getElementsByTagName('td');
 | |
|     
 | |
|             
 | |
|                         foreach($Detail as $NodeHeader) 
 | |
|                         {
 | |
|                             $aDataTableHeaderHTML[] = trim($NodeHeader->textContent);
 | |
|                         }
 | |
|                         
 | |
|                         array_push($temp,$res['name']);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[1]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[3]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[5]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[7]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[9]);
 | |
|                         array_push($temp,$aDataTableHeaderHTML[11]);
 | |
|                         array_push($temp,$res['Validation']);
 | |
|                         array_push($temp,'https://dsi.sophal.dz/front/ticket.form.php?id='.$res['id']);
 | |
|                         $aDataTableHeaderHTML = null;
 | |
|                         //print_r($temp);
 | |
|                         //echo"<br>";
 | |
|                         array_push($final_data,$temp);
 | |
|                         } else {
 | |
|                             array_push($temp,$res['name']);
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[0])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[1])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[2])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[3])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[4])[1] : "");
 | |
|                             array_push($temp,str_contains($res['content'],":") ? explode(':',$temp_content[5])[1] : "");
 | |
|                             array_push($temp,$res['Validation']);
 | |
|                             array_push($temp,'https://dsi.sophal.dz/front/ticket.form.php?id='.$res['id']);
 | |
|     
 | |
|                             //print_r($temp_content);
 | |
|                             //echo"<br>";
 | |
|                             array_push($final_data,$temp);
 | |
|                         }
 | |
|                 }
 | |
|             }
 | |
|             $data_populated = true;
 | |
|             // print_r($result);
 | |
|             break;
 | |
| 
 | |
|          case "RE":
 | |
|              $result = getReclamations(true,33); //Reclamation
 | |
|              $title = "Export_Reclamation_";
 | |
|              $header = ['Matricule','Nom','Titre','Description','Date','Ticket'];
 | |
|              $final_data = array();
 | |
| 
 | |
|              foreach($result as $res){
 | |
|                  if($res){
 | |
|                      $temp = array();
 | |
|                      
 | |
|                      array_push($temp,$res['matricule']);
 | |
|                      array_push($temp,$res['name']);
 | |
|                      array_push($temp,$res['ticket_name']);
 | |
| 
 | |
|                      // Remove HTML tags and decode entities to keep only plain text
 | |
|                     $plain_content = html_entity_decode(strip_tags($res['content']), ENT_QUOTES | ENT_HTML5, 'UTF-8');
 | |
|                     array_push($temp, $plain_content); // Description
 | |
| 
 | |
|                      array_push($temp,$res['date']);
 | |
| 		     array_push($temp,$res['status']);
 | |
|                      array_push($temp,'https://dsi.sophal.dz/front/ticket.form.php?id='.$res['id']);
 | |
|                      $aDataTableHeaderHTML = null;
 | |
|                      //print_r($temp);
 | |
|                      //echo"<br>";
 | |
|                      array_push($final_data,$temp);
 | |
|                  }
 | |
|              }
 | |
|              $data_populated = true;
 | |
|              // print_r($result);
 | |
|              break;
 | |
| 
 | |
|     }
 | |
|     
 | |
| 
 | |
|     if($data_populated){
 | |
|         switch ($_GET['content']){
 | |
|             case "RE":
 | |
|                 header("Content-Disposition: attachment; filename=\"".$title.Date('Y-m-d').".xls\"");
 | |
|                 header("Content-Type: application/vnd.ms-excel;");
 | |
|                 header("Pragma: no-cache");
 | |
|                 header("Expires: 0");
 | |
| 
 | |
|                 // Start output buffering
 | |
|                 ob_start();
 | |
| 
 | |
|                 // Start the HTML table
 | |
|                 echo "<table border='1'>";
 | |
|                 
 | |
|                 // Output the header row
 | |
|                 echo "<tr>";
 | |
|                 foreach ($header as $col) {
 | |
|                     echo "<th>" . htmlspecialchars($col) . "</th>";
 | |
|                 }
 | |
|                 echo "</tr>";
 | |
|                 
 | |
|                 // Output the data rows
 | |
|                 foreach ($final_data as $data) {
 | |
|                     echo "<tr>";
 | |
|                     foreach ($data as $index => $cell) {
 | |
|                         // Check if this is the column with HTML content
 | |
|                         if ($index === 3) { // for the content colomn
 | |
|                             $cell = strip_tags(html_entity_decode($cell, ENT_QUOTES | ENT_HTML5, 'UTF-8'));
 | |
|                         }
 | |
|                         echo "<td>" . htmlspecialchars($cell) . "</td>";
 | |
|                     }
 | |
|                     echo "</tr>";
 | |
|                 }
 | |
|                 
 | |
|                 // Close the table
 | |
|                 echo "</table>";
 | |
| 
 | |
|                 // Send the buffered content to output
 | |
|                 ob_end_flush();
 | |
|                 break;
 | |
|             default: 
 | |
|                 header("Content-Disposition: attachment; filename=\"".$title.Date('Y-m-d-H:i:s').".xls\"");
 | |
|                 header("Content-Type: application/vnd.ms-excel;");
 | |
|                 header("Pragma: no-cache");
 | |
|                 header("Expires: 0");
 | |
|                 $out = fopen("php://output", 'w');
 | |
| 
 | |
|             
 | |
|                 fputcsv($out, $header,"\t");
 | |
|                 // print_r($final_data);
 | |
|                 foreach ($final_data as $data)
 | |
|                 {
 | |
|                     fputcsv($out, $data,"\t");
 | |
|                 }
 | |
|                 fclose($out);
 | |
|                 break;
 | |
|         }
 | |
|         #print_r(strip_tags(html_entity_decode(),""));
 | |
|     }else{
 | |
|        // echo"<script>alert('Erreur! Contactez votre administrateur.');window.location = 'central.php';</script>";
 | |
|     }
 | |
| }else{
 | |
|     echo"<script>alert('invalide!');window.location = 'central.php';</script>";
 | |
| } |