AnonSec Team
Server IP : 10.128.40.6  /  Your IP : 216.73.216.233
Web Server : Apache
System : Linux webd006.cluster128.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User : logmcpe ( 111175)
PHP Version : 7.3.33
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/logmcpe/www/mcg/pages/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/logmcpe/www/mcg/pages/Pres_jours2_new.php
<?php
	// require __DIR__ . '/vendor_sms_recu/autoload.php';
	// include 'includes_sms_recu/ovhhh.php';

include 'includes/config_tmcpro.php' ;
	include 'includes/stable_functions_tmcpro.php' ;
	
	$non_valide = 0 ; 
		// echo "<pre>" ;
	// print_r ($_POST) ; 
	// echo "</pre>"  ; 
	
	if(!empty($_GET)){


	// echo "<pre>" ;
	// print_r($_GET) ; 
	// echo "</pre>"  ; 
	
	// echo "<pre>" ;
	// print_r($_POST) ; 
	// echo "</pre>"  ; 
	
	// exit() ; 
	
		}	
	
	// echo "-k-------l---------- <br/>" ;
	

	if(!empty($_GET['sup_dep']) OR  !empty($_GET['sup_fin']) OR !empty($_POST['devalider']) ){
		
		if(!empty($_POST['devalider'])){
			
			if(!empty($_POST['id_pDD'])){
			// echo "ggg <br/>" ; 
			dbi_query("UPDATE `telepointage` SET `pointage_valider` = '0', `presta_id` = '0' WHERE `telepointage`.`id_p` = ".$_POST['id_pDD']) ;
			// dbi_query("DELETE FROM telepointage WHERE `telepointage`.`id_p`  = ".$_POST['id_pDD']) ;
			
			
		}
		
		
		if(!empty($_POST['id_pFF'])){
			// echo "hhhh <br/>" ; 
			dbi_query("UPDATE `telepointage` SET `pointage_valider` = '0', `presta_id` = '0' WHERE `telepointage`.`id_p` = ".$_POST['id_pFF']) ;
			// dbi_query("DELETE FROM telepointage WHERE `telepointage`.`id_p` = ".$_POST['id_pFF']) ;
			
		}
		
			
		
		
		}
		
		// echo "zzz <br/>" ; 
		if(!empty($_GET['sup_dep'])){
			// echo "ggg <br/>" ; 
			dbi_query("UPDATE `telepointage` SET `pointage_valider` = '0', `presta_id` = '0' WHERE `telepointage`.`id_p` = ".$_GET['sup_dep']) ;
			// dbi_query("DELETE FROM telepointage WHERE `telepointage`.`id_p`  = ".$_GET['sup_dep']) ;
			
			
		}
	
		if(!empty($_GET['sup_fin'])){
			// echo "hhhh <br/>" ; 
			dbi_query("UPDATE `telepointage` SET `pointage_valider` = '0', `presta_id` = '0' WHERE `telepointage`.`id_p` = ".$_GET['sup_fin']) ;
			// dbi_query("DELETE FROM telepointage WHERE `telepointage`.`id_p` = ".$_GET['sup_fin']) ;
			
		}
		
		
		
		dbi_query("DELETE FROM pointage_rapport WHERE  id_pDD = '".$_GET['sup_dep']."' AND id_pFF =  ".$_GET['sup_fin']) ; 
		
	        // echo "tttt <br/>" ; 
			// exit() ; 
            header('Location:Pres_jours2_new.php?msg=Pointages bien dévalidé  &color=success');
	}
	

	if(!empty($_POST) and !empty($_POST['date_message_pointage'])  ){
	
	 dbi_query("INSERT INTO `telepointage` (`id_p`, `agence`, `jour`, `heure`, `telephone`, `matricule`, `action`, `test`, `test2`, `client_id`, `pointage_valider`, `presta_id`) VALUES 
	(NULL, '', '".dateformaint($_POST['date_message_pointage'])."', '".$_POST['heure']."', '', '".$_POST['matricule']."', '".$_POST['action']."', NULL, NULL, '".$_POST['client_id']."', '0', '')") ; 
	// exit() ;
		header('Location:Pres_jours2_new.php?msg=Pointage bien ajouté&color=success');
	}
	
	// echo "--------------------------------- <br/>" ; 
	// if(!empty($_GET)){
	// echo "<pre>" ;
	// print_r($_GET) ; 
	// echo "</pre>"  ; 
	// }
	
	
	// print_r($_GET) ; 
	
	function count_week_days($__date_from, $__date_to, $__holidays_between=array(), $__weekend_days=array()) {
   $total_days_count = $__date_to > $__date_from ? round(($__date_to - $__date_from)/(24*3600)) : 0;
   $full_weeks_count = floor($total_days_count/7);
   return  $full_weeks_count;
}
	
	function diff_time($t1 , $t2){
     //Heures au format (hh:mm:ss) la plus grande puis le plus petite

       $tab=explode(":", $t1);
       $tab2=explode(":", $t2);

       $h=$tab[0];
       $m=$tab[1];
       $s=$tab[2];
       $h2=$tab2[0];
       $m2=$tab2[1];
       $s2=$tab2[2];

       if ($h2>$h) {
       $h=$h+24;
       }
       if ($m2>$m) {
       $m=$m+60;
       $h2++;
       }
       if ($s2>$s) {
       $s=$s+60;
       $m2++;
       }

       $ht=$h-$h2;
       $mt=$m-$m2;
       $st=$s-$s2;
       if (strlen($ht)==1) {
       $ht="0".$ht;
       }
       if (strlen($mt)==1) {
       $mt="0".$mt;
       }
       if (strlen($st)==1) {
       $st="0".$st;
       }
       return $ht.":".$mt.":".$st;

    }


	
	
	// echo "<pre>" ;
// print_r($_SESSION) ;
// echo "</pre>" ;

// echo "------------------ <br/>" ;


// echo "<pre>" ;
// print_r($_POST) ;
// echo "</pre>" ;

	// echo "yyyyyyyyyy <br/>" ;

// if(!empty($_POST) and $_POST['validerr'] == "Valider")
// {
		// echo "<pre>" ; 
	// print_r($_POST) ;
	// echo "</pre>" ; 
	 // echo "test <br/>" ;
	// exit() ; 
// }

if(!empty($_POST) and $_POST['validerr'] == "Valider")
{
	
	 	 list($tele1,$tele2,$tele3,$tele4,$tele5) = dbi_fetch_row(dbi_query(" SELECT 	tele1,	tele2, tele3 , tele4, tele5  FROM `client` WHERE `client_id` = ".$_POST['client_id'])) ; 
	// echo "aaaa <br/>" ;
	$num_tele = $tele1  ; 
	if($tele1 == ""){
   $num_tele = $tele2 ; } ;
	if($tele1 == "" and $tele2=="" ){$num_tele = $tele3 ; } ;
	if($tele1 == "" and $tele2=="" and $tele3=="" ){$num_tele = $tele4 ;} ;
	if($tele1 == "" and $tele2=="" and $tele3=="" and $tele4=="" ){$num_tele = $tele5 ;} ;
	
	 // -------------------------------   validation heure fin manuel et debut normal -----------------------------
	if(!empty($_POST["point_heure_debut"]) AND !empty($_POST["heure_fin_manuel"]) ){ 
		
         dbi_query(" UPDATE `telepointage`  SET `pointage_valider` = '1' ,  presta_id =".$_POST['presta_iddd']." WHERE `telepointage`.`id_p` = ".$_POST['id_pDD']." and action LIKE 'DEBUT' ") ;
	     
		 dbi_query("INSERT INTO `telepointage` (`id_p`, `agence`, `jour`, `heure`, `telephone`, `matricule`, `action`, `test`, `test2`, `client_id`, `pointage_valider`, `presta_id`) VALUES
	     (NULL, '', '".$_SESSION['datej']."', '".$_POST['heure_fin_manuel']."', '".$num_tele."', '".$_POST['salarie_id']."', 'FIN', NULL, NULL, '".$_POST['client_id']."', '1', '".$_POST['presta_iddd']."')");
	  		$heure_debut_manuel=$_POST['point_heure_debut'].":00" ; $heure_fin_manuel=$_POST['heure_fin_manuel'].":00" ;
		$durepointage = diff_time($heure_fin_manuel , $heure_debut_manuel)."<br/>";
		$prestfin = $_POST['pres_heure_fin'].":00" ; $prestdebut= $_POST['pres_heure_debut'].":00" ;
		$durepresta = diff_time($prestfin , $prestdebut);$a=0 ;$dpoint= mktime($durepointage); $dpre= mktime($durepresta);
		if($durepresta >= $durepointage)
				{
				$ecart = diff_time($durepresta , $durepointage) ;
				$a= 1 ;
				$statu_ecart = 1 ;  // ecart négatif
				}else
				{
				$ecart = diff_time($durepointage,$durepresta) ;
				$a=2 ;
				$statu_ecart = 2  ;// ecart positif
				}if($ecart == ""){
	             $ecart ="NULL" ;
				$statu_ecart = 0  ;// ecart positif
				}
    list($id_pFF) = dbi_fetch_row(dbi_query("SELECT MAx(id_p) FROM `telepointage` where ACTION LIKE 'FIN'")) ; 
    dbi_query("INSERT INTO `pointage_rapport` (`pointage_rapport_id`, `client_id`, `salarie_id`, `pres_heure_debut`, `pres_heure_fin`, `point_heure_debut`, `point_heure_fin`, `ecart`, `prest_id`, `id_pDD`, `id_pFF` , `statu_ecart` , date_pointage) VALUES
	(NULL, '".$_POST['client_id']."', '".$_POST['salarie_id']."', '".$_POST['pres_heure_debut']."', '".$_POST['pres_heure_fin']."', '".$heure_debut_manuel."', '".$heure_fin_manuel."', '".$ecart."', '".$_POST['presta_iddd']."', '".$_POST['id_pDD']."', '".$id_pFF."' , '".$statu_ecart."' , '".$_SESSION['datej']."')") ; 
		
	}
	// ---------------------------------------------------------Fin -----------------------------------------------------------------------------
	
	
	
		 // -------------------------------   validation heure debut manuel et fin normal -----------------------------
	if(!empty($_POST["heure_debut_manuel"]) AND !empty($_POST["point_heure_fin"]) ){ 
		
         dbi_query(" UPDATE `telepointage`  SET `pointage_valider` = '1' ,  presta_id =".$_POST['presta_iddd']." WHERE `telepointage`.`id_p` = ".$_POST['id_pFF']." and action LIKE 'FIN' ") ;
	     
		 dbi_query("INSERT INTO `telepointage` (`id_p`, `agence`, `jour`, `heure`, `telephone`, `matricule`, `action`, `test`, `test2`, `client_id`, `pointage_valider`, `presta_id`) VALUES
	     (NULL, '', '".$_SESSION['datej']."', '".$_POST['heure_debut_manuel']."', '".$num_tele."', '".$_POST['salarie_id']."', 'DEBUT', NULL, NULL, '".$_POST['client_id']."', '1', '".$_POST['presta_iddd']."')");
	  		
			
			
			
					// $heure_debut_manuel=$_POST['heure_debut_manuel'].":00" ;
		             // $heure_fin_manuel=$_POST['point_heure_fin'].":00" ;
		
			  		$heure_debut_manuel=$_POST['heure_debut_manuel'].":00" ; $heure_fin_manuel=$_POST['point_heure_fin'].":00" ;
		$durepointage = diff_time($heure_fin_manuel , $heure_debut_manuel)."<br/>";
		$prestfin = $_POST['pres_heure_fin'].":00" ; $prestdebut= $_POST['pres_heure_debut'].":00" ;
		$durepresta = diff_time($prestfin , $prestdebut);$a=0 ;$dpoint= mktime($durepointage); $dpre= mktime($durepresta);
		if($durepresta >= $durepointage)
				{
				$ecart = diff_time($durepresta , $durepointage) ;
				$a= 1 ;
				$statu_ecart = 1 ;  // ecart négatif
				}else
				{
				$ecart = diff_time($durepointage,$durepresta) ;
				$a=2 ;
				$statu_ecart = 2  ;// ecart positif
				}if($ecart == ""){
	             $ecart ="NULL" ;
				$statu_ecart = 0  ;// ecart positif
				}
		
		 list($id_pDD) = dbi_fetch_row(dbi_query("SELECT MAx(id_p) FROM `telepointage` where ACTION LIKE 'DEBUT'")) ;
		dbi_query("INSERT INTO `pointage_rapport` (`pointage_rapport_id`, `client_id`, `salarie_id`, `pres_heure_debut`, `pres_heure_fin`, `point_heure_debut`, `point_heure_fin`, `ecart`, `prest_id`, `id_pDD`, `id_pFF` , `statu_ecart` , date_pointage) VALUES
	    (NULL, '".$_POST['client_id']."', '".$_POST['salarie_id']."', '".$_POST['pres_heure_debut']."', '".$_POST['pres_heure_fin']."', '".$heure_debut_manuel."', '".$heure_fin_manuel."', '".$ecart."', '".$_POST['presta_iddd']."', '".$id_pDD."', '".$_POST['id_pFF']."' , '".$statu_ecart."' , '".$_SESSION['datej']."')") ; 
		
			
			
			
			

		
	}
	// ---------------------------------------------------------Fin -----------------------------------------------------------------------------
	
	
	
	
	
	
	  // -------------------------------   validation normale ou ils existe les deux pointages  (debut et fin) -----------------------------
	
	if(!empty($_POST["point_heure_debut"]) AND !empty($_POST["point_heure_fin"]) ){ 
		
         dbi_query(" UPDATE `telepointage`  SET `pointage_valider` = '1' ,  presta_id =".$_POST['presta_iddd']." WHERE `telepointage`.`id_p` = ".$_POST['id_pDD']." and action LIKE 'DEBUT' ") ;
	     dbi_query(" UPDATE `telepointage` SET `pointage_valider` = '1' ,  presta_id =".$_POST['presta_iddd']." WHERE `telepointage`.`id_p` = ".$_POST['id_pFF']." and action LIKE 'FIN' ") ;
	
	  dbi_query("INSERT INTO `pointage_rapport` (`pointage_rapport_id`, `client_id`, `salarie_id`, `pres_heure_debut`, `pres_heure_fin`, `point_heure_debut`, `point_heure_fin`, `ecart`, `prest_id`, `id_pDD`, `id_pFF` , `statu_ecart` , date_pointage) VALUES
	(NULL, '".$_POST['client_id']."', '".$_POST['salarie_id']."', '".$_POST['pres_heure_debut']."', '".$_POST['pres_heure_fin']."', '".$_POST['point_heure_debut']."', '".$_POST['point_heure_fin']."', '".$_POST['ecart']."', '".$_POST['presta_iddd']."', '".$_POST['id_pDD']."', '".$_POST['id_pFF']."' , '".$_POST['statu_ecart']."' , '".$_SESSION['datej']."')") ; 

		
	}
      //--------------------------------------------------------------------- FIN ------------------------------------------------
	// -------------------------------******************************   validation manule DEBUT et FIN *************************** -----------------------------
	if(!empty($_POST["heure_debut_manuel"]) AND !empty($_POST["heure_fin_manuel"]) ){
		
		
		
		
	  dbi_query("INSERT INTO `telepointage` (`id_p`, `agence`, `jour`, `heure`, `telephone`, `matricule`, `action`, `test`, `test2`, `client_id`, `pointage_valider`, `presta_id`) VALUES
	  (NULL, '', '".$_SESSION['datej']."', '".$_POST['heure_debut_manuel']."', '".$num_tele."', '".$_POST['salarie_id']."', 'DEBUT', NULL, NULL, '".$_POST['client_id']."', '1', '".$_POST['presta_iddd']."')");
	
	  dbi_query("INSERT INTO `telepointage` (`id_p`, `agence`, `jour`, `heure`, `telephone`, `matricule`, `action`, `test`, `test2`, `client_id`, `pointage_valider`, `presta_id`) VALUES
	  (NULL, '', '".$_SESSION['datej']."', '".$_POST['heure_fin_manuel']."', '".$num_tele."', '".$_POST['salarie_id']."', 'FIN', NULL, NULL, '".$_POST['client_id']."', '1', '".$_POST['presta_iddd']."')");

		
		// $heure_debut_manuel=$_POST['heure_debut_manuel'].":00" ;
		// $heure_fin_manuel=$_POST['heure_fin_manuel'].":00" ;
		
		
	$heure_debut_manuel=$_POST['heure_debut_manuel'].":00" ; $heure_fin_manuel=$_POST['heure_fin_manuel'].":00" ;
		$durepointage = diff_time($heure_fin_manuel , $heure_debut_manuel)."<br/>";
		$prestfin = $_POST['pres_heure_fin'].":00" ; $prestdebut= $_POST['pres_heure_debut'].":00" ;
		$durepresta = diff_time($prestfin , $prestdebut);$a=0 ;$dpoint= mktime($durepointage); $dpre= mktime($durepresta);
		if($durepresta >= $durepointage)
				{
				$ecart = diff_time($durepresta , $durepointage) ;
				$a= 1 ;
				$statu_ecart = 1 ;  // ecart négatif
				}else
				{
				$ecart = diff_time($durepointage,$durepresta) ;
				$a=2 ;
				$statu_ecart = 2  ;// ecart positif
				}if($ecart == ""){
	             $ecart ="NULL" ;
				$statu_ecart = 0  ;// ecart positif
				}
							                                                                   
																								
	 list($id_pFF) = dbi_fetch_row(dbi_query("SELECT MAx(id_p) FROM `telepointage` where ACTION LIKE 'FIN'")) ; 						
	 list($id_pDD) = dbi_fetch_row(dbi_query("SELECT MAx(id_p) FROM `telepointage` where ACTION LIKE 'DEBUT'")) ;
	  dbi_query("INSERT INTO `pointage_rapport` (`pointage_rapport_id`, `client_id`, `salarie_id`, `pres_heure_debut`, `pres_heure_fin`, `point_heure_debut`, `point_heure_fin`, `ecart`, `prest_id`, `id_pDD`, `id_pFF` , `statu_ecart` , date_pointage) VALUES
	 (NULL, '".$_POST['client_id']."', '".$_POST['salarie_id']."', '".$_POST['pres_heure_debut']."', '".$_POST['pres_heure_fin']."', '".$heure_debut_manuel."', '".$heure_fin_manuel."', '".$ecart."', '".$_POST['presta_iddd']."', '".$id_pDD."', '".$id_pFF."' , '".$statu_ecart."' , '".$_SESSION['datej']."')") ; 
		
		
		
		// echo "les deux <br/>" ; 
	}
	
	
	

	// if(!empty($_POST['point_heure_fin'])){  // dans le cas ou l'utilisateur saisi le point départ
		
		
		// $heure_debut_manuel=$_POST['heure_debut_manuel'].":00" ;
		// $heure_fin_manuel=$_POST['point_heure_fin'].":00" ;
		
		
		
							                                                                    // $durepointage = diff_time($heure_fin_manuel , $heure_debut_manuel)."<br/>";
																								// $prestfin = $_POST['pres_heure_fin'].":00" ;
																								// $prestdebut= $_POST['pres_heure_debut'].":00" ;
																								// $durepresta = diff_time($prestfin , $prestdebut);
																								// $a=0 ;
																								
																												// $dpoint= mktime($durepointage);
																												// $dpre= mktime($durepresta);

																												// if($durepresta >= $durepointage)
																												// {
																												// $ecart = diff_time($durepresta , $durepointage) ;
																												// $a= 1 ;
																												// $statu_ecart = 1 ;  // ecart négatif
																												// }
																												// else
																												// {
																												// $ecart = diff_time($durepointage,$durepresta) ;
																												// $a=2 ;
																												// $statu_ecart = 2  ;// ecart positif
																												// }
																								
																								
																								// if($ecart == "")
																								// {
																									// $ecart ="NULL" ;
																									// $statu_ecart = 0  ;// ecart positif
																								// }
		
		// dbi_query("INSERT INTO `pointage_rapport` (`pointage_rapport_id`, `client_id`, `salarie_id`, `pres_heure_debut`, `pres_heure_fin`, `point_heure_debut`, `point_heure_fin`, `ecart`, `prest_id`, `id_pDD`, `id_pFF` , `statu_ecart` , date_pointage) VALUES
	 // (NULL, '".$_POST['client_id']."', '".$_POST['salarie_id']."', '".$_POST['pres_heure_debut']."', '".$_POST['pres_heure_fin']."', '".$heure_debut_manuel."', '".$heure_fin_manuel."', '".$ecart."', '".$_POST['presta_iddd']."', '".$id_pDD."', '".$id_pFF."' , '".$statu_ecart."' , '".$_SESSION['datej']."')") ; 
		
		
		   
	// }
	
	
	// exit() ; 
	
	 list($tele1,$tele2,$tele3,$tele4,$tele5) = dbi_fetch_row(dbi_query(" SELECT 	tele1,	tele2, tele3 , tele4, tele5  FROM `client` WHERE `client_id` = ".$_POST['client_id'])) ; 
	// echo "aaaa <br/>" ;
	$num_tele = $tele1  ; 
	if($tele1 == ""){
		$num_tele = $tele2 ; } ;
	if($tele1 == "" and $tele2=="" ){$num_tele = $tele3 ; } ;
	if($tele1 == "" and $tele2=="" and $tele3=="" ){$num_tele = $tele4 ;} ;
	if($tele1 == "" and $tele2=="" and $tele3=="" and $tele4=="" ){$num_tele = $tele5 ;} ;
	
	
	
																										
	
	
	
	// echo "<pre>" ; 
	// print_r($_POST) ; 
	// echo "</pre>" ;
	
	// if(!empty($_POST["heure_debut_manuel"])){
		// if(!empty($_POST['id_pFF'])){ // ma3rafth had req 3lach hnaya o ma9darch nmsss7a
		// dbi_query("UPDATE `telepointage` SET `pointage_valider` = '1', `presta_id` = '".$_POST['presta_iddd']."' WHERE `telepointage`.`id_p` = ".$_POST['id_pFF']);}
		
	
	  // dbi_query("INSERT INTO `telepointage` (`id_p`, `agence`, `jour`, `heure`, `telephone`, `matricule`, `action`, `test`, `test2`, `client_id`, `pointage_valider`, `presta_id`) VALUES
	  // (NULL, '', '".$_SESSION['datej']."', '".$_POST['heure_debut_manuel']."', '".$num_tele."', '".$_POST['salarie_id']."', 'DEBUT', NULL, NULL, '".$_POST['client_id']."', '1', '".$_POST['presta_iddd']."')");
	
	// }

	// if(!empty($_POST["heure_fin_manuel"])){
		
		
		
		  // dbi_query("INSERT INTO `telepointage` (`id_p`, `agence`, `jour`, `heure`, `telephone`, `matricule`, `action`, `test`, `test2`, `client_id`, `pointage_valider`, `presta_id`) VALUES
	  // (NULL, '', '".$_SESSION['datej']."', '".$_POST['heure_fin_manuel']."', '".$num_tele."', '".$_POST['salarie_id']."', 'FIN', NULL, NULL, '".$_POST['client_id']."', '1', '".$_POST['presta_iddd']."')");
// if(!empty($_POST['id_pDD'])){ 
// dbi_query("UPDATE `telepointage` SET `pointage_valider` = '1', `presta_id` = '".$_POST['presta_iddd']."' WHERE `telepointage`.`id_p` = ".$_POST['id_pDD']); }
	// }
	
	if(!empty($_POST["deux_prest_par_jour"])){
		
		// echo "ssss <br/>" ; 
	// echo "<pre>" ;
	// print_r($_POST) ; 
	// echo "</pre>"  ; 
	// exit() ; 
		
				list($heure_debut_manuel)=  dbi_fetch_row(dbi_query("SELECT heure FROM `telepointage` WHERE `id_p` = ".$_POST['id_p_debut']));
		       list( $heure_fin_manuel)=    dbi_fetch_row(dbi_query("SELECT heure FROM `telepointage` WHERE `id_p` = ".$_POST['id_p_fin']));
		
		
		
							                                                                    $durepointage = diff_time($heure_fin_manuel , $heure_debut_manuel)."<br/>";
																								$prestfin = $_POST['pres_heure_fin'].":00" ;
																								$prestdebut= $_POST['pres_heure_debut'].":00" ;
																								$durepresta = diff_time($prestfin , $prestdebut);
																								$a=0 ;
																								
																												$dpoint= mktime($durepointage);
																												$dpre= mktime($durepresta);
																												if($durepresta >= $durepointage)
																												{
																												$ecart = diff_time($durepresta , $durepointage) ;
																												$a= 1 ;
																												$statu_ecart = 1 ;  // ecart négatif
																												}
																												else
																												{
																													// echo "mmm <br/>" ;
																												$ecart = diff_time($durepointage,$durepresta) ;
																												$a=2 ;
																												$statu_ecart = 2  ;// ecart positif
																												}
																								
																								
																								if($ecart == "")
																								{
																									$ecart ="NULL" ;
																									$statu_ecart = 0  ;// ecart positif
																								}
		
		
		dbi_query("INSERT INTO `pointage_rapport` (`pointage_rapport_id`, `client_id`, `salarie_id`, `pres_heure_debut`, `pres_heure_fin`, `point_heure_debut`, `point_heure_fin`, `ecart`, `prest_id`, `id_pDD`, `id_pFF` , `statu_ecart` , date_pointage) VALUES 
	 (NULL, '".$_POST['client_id']."', '".$_POST['salarie_id']."', '".$_POST['pres_heure_debut']."', '".$_POST['pres_heure_fin']."', '".$heure_debut_manuel."', '".$heure_fin_manuel."', '".$ecart."', '".$_POST['presta_iddd']."', '".$id_pDD."', '".$id_pFF."' , '".$statu_ecart."' , '".$_SESSION['datej']."')") ; 
		
		
	dbi_query(" UPDATE `telepointage`  SET `pointage_valider` = '1' ,  presta_id =".$_POST['presta_iddd']." WHERE `telepointage`.`id_p` = ".$_POST['id_p_debut']." and action LIKE 'DEBUT' ") ;
	dbi_query(" UPDATE `telepointage` SET `pointage_valider` = '1' ,  presta_id =".$_POST['presta_iddd']." WHERE `telepointage`.`id_p` = ".$_POST['id_p_fin']." and action LIKE 'FIN' ") ;
	
	
	
	
	
	      
	
	// list($heure_debut_manuel , $id_p_debutt ) = dbi_fetch_row(dbi_query("SELECT heure , id_p FROM `telepointage` WHERE `jour` LIKE '20230706' AND `matricule` = '".$_POST['salarie_id']."' AND `client_id` = '".$_POST['client_id']."' and action LIKE 'DEBUT' and id_p <> ".$_POST['id_p_debut']))  ; 
	// list($heure_fin_manuel , $id_p_fint)= dbi_fetch_row(dbi_query("SELECT heure , id_p FROM `telepointage` WHERE `jour` LIKE '20230706' AND `matricule` = '".$_POST['salarie_id']."' AND `client_id` = '".$_POST['client_id']."' and action LIKE 'FIN' and id_p <> ".$_POST['id_p_fin']))  ; 
	// $_POST['id_p_debut'] = $id_p_debutt ; 
	// $_POST['id_p_fin'] = $id_p_fint; 
		// list($heure_debut_manuel)=  dbi_fetch_row(dbi_query("SELECT heure FROM `telepointage` WHERE `id_p` = ".$_POST['id_p_debut']));
		       // list( $heure_fin_manuel)=    dbi_fetch_row(dbi_query("SELECT heure FROM `telepointage` WHERE `id_p` = ".$_POST['id_p_fin']));
		
		
		
							                                                                    // $durepointage = diff_time($heure_fin_manuel , $heure_debut_manuel)."<br/>";
																								// $prestfin = $_POST['pres_heure_fin'].":00" ;
																								// $prestdebut= $_POST['pres_heure_debut'].":00" ;
																								// $durepresta = diff_time($prestfin , $prestdebut);
																								// $a=0 ;
																								
																												// $dpoint= mktime($durepointage);
																												// $dpre= mktime($durepresta);
																												// if($durepresta >= $durepointage)
																												// {
																												// $ecart = diff_time($durepresta , $durepointage) ;
																												// $a= 1 ;
																												// $statu_ecart = 1 ;  
																												// }
																												// else
																												// {
																												
																												// $ecart = diff_time($durepointage,$durepresta) ;
																												// $a=2 ;
																												// $statu_ecart = 2  ;
																												// }
																								
																								
																								// if($ecart == "")
																								// {
																									// $ecart ="NULL" ;
																									// $statu_ecart = 0  ;
																								// }
		
		
		// dbi_query("INSERT INTO `pointage_rapport` (`pointage_rapport_id`, `client_id`, `salarie_id`, `pres_heure_debut`, `pres_heure_fin`, `point_heure_debut`, `point_heure_fin`, `ecart`, `prest_id`, `id_pDD`, `id_pFF` , `statu_ecart` , date_pointage) VALUES 
	 // (NULL, '".$_POST['client_id']."', '".$_POST['salarie_id']."', '".$_POST['pres_heure_debut']."', '".$_POST['pres_heure_fin']."', '".$heure_debut_manuel."', '".$heure_fin_manuel."', '".$ecart."', '".$_POST['presta_iddd']."', '".$id_pDD."', '".$id_pFF."' , '".$statu_ecart."' , '".$_SESSION['datej']."')") ; 
		
		
	// dbi_query(" UPDATE `telepointage`  SET `pointage_valider` = '1' ,  presta_id =".$_POST['presta_iddd']." WHERE `telepointage`.`id_p` = ".$_POST['id_p_debut']." and action LIKE 'DEBUT' ") ;
	// dbi_query(" UPDATE `telepointage` SET `pointage_valider` = '1' ,  presta_id =".$_POST['presta_iddd']." WHERE `telepointage`.`id_p` = ".$_POST['id_p_fin']." and action LIKE 'FIN' ") ;
	
	
	
	}
	// exit() ; 
}


session_start();
// $a= gmdate("01:00:00", s);
//l echo "==> $a <br/>" ;
// exit(l)l ;



										$_SESSION["id_etab"]= 111 ;



										if(!empty( $_GET["id_etab"]))
										{
										$_SESSION["id_etab"] = $_GET["id_etab"];
										}


										if($_SESSION["id_etab"]== 111){
											$where_etablissement_id="" ;
										}
										else{
										$where_etablissement_id = " AND c.etablissement_id = ".$_SESSION["id_etab"] ;
										}


if(empty($_SESSION['datej'])){$_SESSION['datej'] = date('Ymd');}


// exit() ; // $date_jour = date('Ymd');
// echo int2date($date_jour );

if(isset($_GET['date_j']))
{
	$_SESSION['datej'] = $_GET['date_j'];
	
}


if(isset($_POST['date_jour']))
{
	$_SESSION['datej'] = dateformaint($_POST['date_jour']);
}



$date_jour = $_SESSION['datej'] ;


// echo  "===>".$date_jour."<br/>" ; 
// echo  "===>".$_SESSION['datej']."<br/>" ; 


// echo "<pre>" ;
// print_r($_SESSION) ;
// echo "</pre>" ;

// echo "========> ".$date_jour."<br/>" ;


// Start the session





	 // $uuu = diff_time('06:04:00' , '06:00:00') ;

	// echo "$uuu<br/>" ;
	// exit() ;


// mise a jour de la table télépoinatage ( ajout de id client pour chaqur pointage)


$qo =dbi_query("SELECT *  FROM `telepointage` WHERE jour >= 20210801 AND (`client_id` IS NULL OR client_id = 0 )") ;
while($j= dbi_fetch_row($qo))
{

    $telephone= $j['telephone'] ;

	list($client_id) = dbi_fetch_row(dbi_query("SELECT client_id FROM `client` WHERE `tele1` LIKE '$telephone'  or `tele2` LIKE '$telephone' or `tele3` LIKE '$telephone' or `tele4` LIKE '$telephone' or `tele5` LIKE '$telephone' ")) ;

// echo "$telephone ==> $client_id	<br/>" ;

 dbi_query("UPDATE `telepointage` SET `client_id` = '$client_id' WHERE `id_p` = ".$j['id_p'] );



}

// echo $date_jour ;
?>
<html>
<head>
<?php include('header.php'); ?>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
    <script type='text/javascript' src='jquery-3.6.0.min.js'></script>
</head>

<body class="hold-transition sidebar-mini">

<div class="wrapper">


												<nav class="main-header navbar navbar-expand navbar-white navbar-light">
													<ul class="navbar-nav">
															<li class="nav-item">
																	  <h3><a href="#myModal_tache_all"  id="custId" data-toggle="modal" >   <button type="button"  class="btn btn-primary" > <i class="fas fa-plus"></i> Nouveau Pointage</button> </a></h3>

															</li>


													</ul>
												</nav>


<!-- BARRE DE NAVIGATION -->

<aside class="main-sidebar sidebar-dark-primary elevation-4">

	<!-- Brand Logo -->
	<a href="index3.html" class="brand-link">
		<img src="dist/img/logomcpro.png" alt="AdminLTE Logo" class="brand-image img-circle elevation-3"
				 style="opacity: .8">
		<span class="brand-text font-weight-light">MC PRO</span>
	</a>

	<!-- Sidebar -->
	<div class="sidebar">
		<!-- Sidebar user panel (optional) -->
		<div class="user-panel mt-3 pb-3 mb-3 d-flex">
			<div class="image">
				<img src="dist/img/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image">
			</div>
			<div class="info">
				<a href="#" class="d-block">Steeven ROBLOT</a>
			</div>
		</div>

	<?php include('menu.php'); ?>

		<!-- Sidebar Menu -->

	</div>
	<!-- /.sidebar -->
</aside>


 <!-- DEMARRAGE DE LA PAGE PRINCIPALE -->
  <div class="content-wrapper">

		<section class="content-header">
		 <div class="container-fluid">
			 <div class="row mb-2">
				 <div class="col-sm-6">
					 <h1>Validation des pointages </h1>
				 </div>
				 <div class="col-sm-6">
					 <ol class="breadcrumb float-sm-right">
						 <li class="breadcrumb-item"><a href="index.php">Accueil</a></li>
						 <li class="breadcrumb-item"><a href="fourinc.php">Pointages</a></li>
						 <li class="breadcrumb-item active">Validation Pointages </li>
					 </ol>
				 </div>
			 </div>
		 </div><!-- /.container-fluid -->
		</section>

    <!-- Content Header (Page header) -->

													<div class="row mb-2">
																			<div  class="modal fade" id="myModal" role="dialog" class="modal fade task-modal-single in" tabindex="-1"  aria-labelledby="myLargeModalLabel" >
																			  <div class="modal-dialog modal-lg">
																				<div class="modal-content data">
																					<div id="fetch" >
																					</div>

																					</div>
																				</div>
																			</div>
													</div><!-- /.row -->
													
														 <div  class="modal fade" id="myModal_tache_all" role="dialog" class="modal fade task-modal-single in" tabindex="-1"  aria-labelledby="myLargeModalLabel" >
														  <div class="modal-dialog modal-lg">
															<div class="modal-content data">
																<div id="fetch_tache_all" ></div>


																</div>
															</div>
														</div>

												<!-- /.content-header -->





				<section class="content">
					<div class="row">
						<div class="col-12">
							<div class="card">

									<div class="card-body">
									
									
																							<?php
			      if(isset($_GET["msg"])){
        ?>
        <div class="alert alert-<?php echo $_GET["color"]; ?>  alert-dismissible col-12" role="alert">
          <strong><?php echo $_GET["color"].': '; ?></strong><?php echo $_GET["msg"]; ?>
          <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <?php
        }
       ?>
                                      <h3>  <?=int2date($_SESSION['datej'])?> </h3>

											<?php

// if(!empty($_POST))
// {
// echo "<pre>" ;
// print_r($_POST) ;
// echo "<pre>" ;
// }
$ino = 0 ; 

if(!empty($_POST))
{

	$an= $_POST['ans'] ;
	$mois =  $_POST['mois'] ;
// $ismai = $_POST['ans']."".$_POST['mois']  ;
$ismai =  $an."".$mois ;
$salarie_id=$_POST['salarie_id'] ;
// $qa = dbi_query(" SELECT * FROM `telepointage` where matricule = $salarie_id and `jour` LIKE '$ismai%' ORDER BY `telepointage`.`jour` DESC ,heure DESC ") ;


}





// echo "ppp=> $an <br/>" ;

// $a = dbi_query("SELEC * FROM `etablissement` $where1")

function dateDifference($date1, $date2)
{
    $first = DateTime::createFromFormat('m/d/Y', $date1);
    $second = DateTime::createFromFormat('m/d/Y', $date2);
    if($date1 > $date2) return week_between_two_dates($date2, $date1);
    return floor($first->diff($second)->days/7);
}

// if(!empty($_POST))
// {
// echo "<pre>" ;
// print_r($_POST) ;
// echo "</pre>" ;

// }

$var_fom = 6 ;

if($var_fom == 7) // bach may2afiche formulaire de date
{

 ?>













							<form id="bureau_mois" name="mois_form" method="POST" action="">
							  <div class="form-row">

								<div class="form-group col-md-4">
									 <div class="input-group">
										<label></label>
								   </div>
								</div>

								<div class="form-group col-md-3">
									<div class="input-group">
										<div class="input-group-prepend"><span class="input-group-text"><i class="far fa-calendar-alt"></i></span></div>
										<input type="date" class="form-control" id="date_jour" name="date_jour" value='<?php echo int2date_autre_format($date_jour); ?>' placeholder="jj/mm/aaaa"/>
									</div>
								</div>





								<div class="form-group col-md-2">
									 <div class="input-group">
											<button type="submit" name="Afficher" class="btn btn-primary">Afficher </button>
								   </div>
								</div>
						</div>
						</form>

<?}?>



										<div class="onglet_dotted">
											<div style="width:100%; float:left; vertical-align:top" class="header_ray">
												<div id="tab">
													<div class="box-body">
														<table id="example1" class="table table-bordered table-striped">
															<thead>
																<TR>
																  <th align="center">Client</th>
																  <th align="center">Début</th>
																  <th align="center">Fin</th>
																  <th align="center">Salarié</th>
																    <th align="center">Arrivée</th>
																  <th align="center">Départ</th>
																  <th align="center">Statu pointage</th>
																  <th align="center"> Écart</th>
																  
																  <th align="center"> Valider </th>

																</TR>
															</thead>
                                                            <tbody>

                                                            <?php
															// $date_jour = "20200716" ;
															// $ab =  dbi_query(" SELECT *  FROM telepointage WHERE jour LIKE $date_jour ") ;

															// while($c=dbi_fetch_row($ab))
																// {
																	// if($i<10)
																	  // $date_jour=  $ismai."0".$i ;
																	// else
																	// $date_jour=  $ismai."".$i ;

															 // $chaine ='' ;
															 // $sqlah = " SELECT *  FROM telepointage WHERE jour LIKE '".$date_jour."' and matricule = '".$c['matricule']."' ";
															 // $ah = dbi_query($sqlah) ;


                                                             $number_ligne = 0 ; 

																// $salarie_id = $c['matricule'];

																$date = $date_jour;
																$i = 1;
																$q = dbi_query("
																	SELECT * FROM PRESTATIONS p,client c , salarie s where c.client_id=p.client_id AND s.salarie_id = p.salarie_id  AND client_statut = '1' AND client_acces_pointage ='2' AND presta_date_debut <= $date AND (p.presta_date_fin >= $date OR p.presta_date_fin IS NULL) $where_etablissement_id ORDER BY presta_Hdeb ASC

																");
																$chaine ="" ;
																
																
																	
																	while($prest = dbi_fetch_row($q))
																{
																		$date_presta_sem = $prest['presta_date_debut'] ;
																		$q1 = dbi_query("SELECT * FROM PRESTATIONS_MODIF WHERE presta_id = ".$prest['presta_id']." order by start, modif_id ") ;
																			while (($m = dbi_fetch_row($q1)) )
																	{
																		// if( $m['presta_sem'] != NULL ) $date_presta_sem = $m['start'];
																		
																		if( $prest['presta_sem'] > 1 ) {
																			if($m['presta_jour'] !== NULL && $date >= $m['start'])  {
																				$date_presta_sem = $m['start'];
																				$date_presta_sem = date("Ymd", strtotime('monday this week', strtotime(int2date_autre_format($date_presta_sem))));
																			}
																		}
																		if( $date >= $m['start'] )
																		{	
																			$prest['presta_sem'] = $m['presta_sem'] === NULL ? $prest['presta_sem'] : $m['presta_sem'] ;
																			$prest['presta_jour'] = $m['presta_jour'] === NULL ? $prest['presta_jour'] : $m['presta_jour'] ;
																			$prest['presta_Hdeb'] = $m['presta_Hdeb'] === NULL ? $prest['presta_Hdeb'] : $m['presta_Hdeb'] ;
																			$prest['presta_Hduree'] = $m['presta_Hduree'] === NULL ? $prest['presta_Hduree'] : $m['presta_Hduree'] ;
																			$prest['salarie_id'] = $m['salarie_id'] === NULL ? $prest['salarie_id'] : $m['salarie_id'] ;
																			$prest['chantier_id'] = $m['chantier_id'] === NULL ? $prest['chantier_id'] : $m['chantier_id'] ;
																			$prest['presta_forfait'] = $m['presta_forfait'] === NULL ? $prest['presta_forfait'] : $m['presta_forfait'] ;	
																		}
																	}
																		$accs = 0 ; 
																				// if( $prest['salarie_id'] == $salarie_id ) {
																					$day = date("w", strtotime( int2date_autre_format($date)));
																					// if( $day == $prest['presta_jour']){
																					if( $day == $prest['presta_jour'] OR  ( $date == $prest['presta_date_debut'] &&  $prest['presta_date_debut']	== $prest['presta_date_fin'] ) ){

																						$EXP = dbi_fetch_row(dbi_query("SELECT date_presta FROM EXCEPTIONS WHERE presta_id = ".$prest['presta_id']." AND date_presta = ".$date." " )) ;	   ;
																						if($EXP ){}   else {
																							if( $prest['presta_sem'] == 1 )
																							{
																								$accs = 1 ; 
																								 
																							}
																							 
																							// echo  "-".$prest['presta_sem'] ; 
																							if($prest['presta_sem']>1)
																								{
																									// echo "<br/>tt " ;
																									
																									$nbre =count_week_days(strtotime(int2date_autre_format($date_presta_sem,'d.m.Y')), strtotime(int2date_autre_format($date,'d.m.Y')));
																								
																									$modolo = $nbre % $prest['presta_sem'] ;
																									
																									if( $modolo == 0) {
																										$accs = 1 ; 
																								}}
																							
																							if( $accs == 1)
																							{
																								$SAL = dbi_fetch_row(dbi_query("SELECT * FROM salarie WHERE salarie_id = ".$prest['salarie_id'] ." " )) ;
																								   // $Clt = dbi_fetch_row(dbi_query("SELECT * FROM client WHERE client_id = ".$prest['client_id'] ." " )) ;
																									// $chaine =  " $i".' -La prestation Débute avec <strong>'.$prest["client_nom"]."</strong> de <strong>".int2heure($prest['presta_Hdeb'])."</strong> à <strong>".int2heure(addDuree($prest['presta_Hdeb'], $prest['presta_Hduree']))."</strong> ** ".$SAL["salarie_nom"]." ** <br/>";

																								// echo "==> ".$prest['salarie_id']."  ==> ".$prest['client_id']."<br/>" ;

																									list($cmpt_heureD) = dbi_fetch_row( dbi_query("SELECT count(heure) FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT'  AND pointage_valider = 0 ")) ;
																									
																									list($ctm_D) =  dbi_fetch_row( dbi_query( "SELECT count(heure) FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT'")) ;
																									// echo "SELECT count(heure) FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT'  AND pointage_valider = 0 <br/>" ; 
																									// list($pointage_valider_debut) = dbi_fetch_row( dbi_query("SELECT count(heure) FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT' ")) ;
																								    list($cmpt_heureF) = dbi_fetch_row(dbi_query("SELECT count(heure) FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'FIN'  AND pointage_valider = 0 "    )) ;
																									  list($ctm_F) = dbi_fetch_row(dbi_query("SELECT count(heure) FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'FIN'  "    )) ;
																									
																									
                                                                                                    // zid had le code bach lakan 2 prestation de meme client et meme salarie maydirch insertion   
																									list($nbr_1) = dbi_fetch_row( dbi_query("SELECT count(heure) FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT'  AND pointage_valider = 1  AND   presta_id = ".$prest['presta_id'])) ;
																								    list($nbr_2) = dbi_fetch_row(dbi_query("SELECT count(heure) FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'FIN'  AND pointage_valider = 1  AND  presta_id = ".$prest['presta_id']   )) ;
																								    $nbr_tot =   $nbr_1+  $nbr_2  ; 
																									
																									// --------------------------*******************-------------------------
																								list($heureD,$id_pDD , $presta_idDD , $pointage_valider_debut) = dbi_fetch_row(dbi_query("SELECT heure , id_p, presta_id , pointage_valider  FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT' and (presta_id = ".$prest['presta_id']." OR presta_id = 0) ")) ;
																								
																								if($ctm_D == 2 ){
																								list($heureD,$id_pDD , $presta_idDD , $pointage_valider_debut) = dbi_fetch_row(dbi_query("SELECT heure , id_p, presta_id , pointage_valider  FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT' and (presta_id = ".$prest['presta_id']." ) ")) ;
																								if($heureD == ""){
																									list($heureD,$id_pDD , $presta_idDD , $pointage_valider_debut) = dbi_fetch_row(dbi_query("SELECT heure , id_p, presta_id , pointage_valider  FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT' AND  presta_id = 0 ")) ;
																								}
																								}	
																								
																								
																								
																									

                  																								// echo "SELECT heure , id_p, presta_id , pointage_valider  FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT' and (presta_id = ".$prest['presta_id']." OR presta_id = 0) <br/>" ; 
																								 
																								 
																								 
																								 list($heureF,$id_pFF ,$presta_idFF , $pointage_valider_fin ) = dbi_fetch_row(dbi_query("SELECT heure , id_p, presta_id , pointage_valider  FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'FIN'   and (presta_id = ".$prest['presta_id']." OR presta_id = 0) ")) ;
                                                                                                 
                                                                                                 if($ctm_F == 2 ){
																								 list($heureF,$id_pFF ,$presta_idFF , $pointage_valider_fin ) = dbi_fetch_row(dbi_query("SELECT heure , id_p, presta_id , pointage_valider  FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'FIN'   and (presta_id = ".$prest['presta_id']." ) ")) ;
																								 if($heureF ==""){
																								list($heureF,$id_pFF ,$presta_idFF , $pointage_valider_fin ) = dbi_fetch_row(dbi_query("SELECT heure , id_p, presta_id , pointage_valider  FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'FIN'   and  presta_id = 0 ")) ;
																								 }
																								
																								}
                                                                                                
																								 // echo "SELECT heure , id_p FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT' and (presta_id = ".$prest['presta_id']." OR presta_id = 0) <br/>"  ;
																								    
																									$somme_hdeb_hfin =  $cmpt_heureD  + $cmpt_heureF ;  // cette ligne pour savoir la somme entre h_deb et h_fin  dans me cas de resultalt 2 donc il ya le début et le fin
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																									
																										$durepointage = diff_time($heureF , $heureD)."<br/>";
																								$prestfin = int2heure(addDuree($prest['presta_Hdeb'], $prest['presta_Hduree'])).":00" ;
																								$prestdebut= int2heure($prest['presta_Hdeb']).":00" ;

																								// echo "$prestfin <==> $prestdebut <br/>" ;
																								$durepresta = diff_time($prestfin , $prestdebut);


																								// echo "===> $heureD === $heureF <br/>" ;
																								$a=0 ;
																								if($heureD != "" AND $heureF != "" )
																								{
																												$dpoint= mktime($durepointage);
																												$dpre= mktime($durepresta);


																												// if($dpre > $dpoint)
																												// {
																												// $ecart = diff_time($durepresta , $durepointage) ;
																												// $a= 1 ;
																												// }
																												// else
																												// {
																												// $ecart = diff_time($durepointage,$durepresta) ;
																												// $a=2 ;
																												// }


																												if($durepresta >= $durepointage)
																												{
																													// echo "ooo <br/>" ;
																												$ecart = diff_time($durepresta , $durepointage) ;
																												$a= 1 ;
																												$statu_ecart = 1 ;  // ecart négatif
																												}
																												else
																												{
																													// echo "mmm <br/>" ;
																												$ecart = diff_time($durepointage,$durepresta) ;
																												$a=2 ;
																												$statu_ecart = 2  ;// ecart positif
																												}
																								}
																								else
																								{
																									$ecart ="NULL" ;
																									$statu_ecart = 0  ;// ecart positif
																								}
																									
																									// ------------------ la validations de  pointage automatique ------------------
																									
																									if($somme_hdeb_hfin == 2 AND $nbr_tot != 2 AND $_SESSION['automatique'] == 1)
																									{ 
																										
																										dbi_query("UPDATE `telepointage` SET `pointage_valider` = '1', `presta_id` = '".$prest['presta_id']."' WHERE `telepointage`.`id_p` = ".$id_pDD);
																									
																									
																									    dbi_query("UPDATE `telepointage` SET `pointage_valider` = '1', `presta_id` = '".$prest['presta_id']."' WHERE `telepointage`.`id_p` = ".$id_pFF);
																									
																										
																									
																										$pointage_deb =dbi_fetch_row(dbi_query("SELECT * FROM `telepointage` WHERE `id_p`  = ".$id_pDD));
																									
																										
																										
																										$pointage_fin =dbi_fetch_row(dbi_query("SELECT * FROM `telepointage` WHERE `id_p`  = ".$id_pFF));
																										
																								
																										dbi_query("INSERT INTO `pointage_rapport` (`pointage_rapport_id`, `client_id`, `salarie_id`, `pres_heure_debut`, `pres_heure_fin`, `point_heure_debut`, `point_heure_fin`, `ecart`, `prest_id`, `id_pDD`, `id_pFF` , `statu_ecart` , date_pointage ) VALUES
																										(NULL, '".$prest['client_id']."', '".$prest["salarie_id"]."', '".int2heure($prest['presta_Hdeb'])."', '".int2heure(addDuree($prest['presta_Hdeb'], $prest['presta_Hduree']))."', '".$pointage_deb['heure']."', '".$pointage_fin['heure']."', '".$ecart."', '".$prest['presta_id']."', '".$id_pDD."', '".$id_pFF."' , '".$statu_ecart."'  , '".$_SESSION['datej']."')") ; 
																									
																									}
																									
																									// ---------------------------------------  Fin -------------------------------------------------
																									 list($presta_idDD) = dbi_fetch_row(dbi_query("SELECT presta_id FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT'  AND `action` LIKE 'DEBUT' and (presta_id = ".$prest['presta_id']." OR presta_id = 0) ")) ;
																								     list($presta_idFF ) = dbi_fetch_row(dbi_query("SELECT presta_id FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'FIN'   AND `action` LIKE 'DEBUT' and (presta_id = ".$prest['presta_id']." OR presta_id = 0) ")) ;
                                                                                                  
																								   $q_heureD = dbi_query("SELECT heure , id_p FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'DEBUT'  ") ;
																								   $q_heureF = dbi_query("SELECT heure , id_p FROM `telepointage` WHERE `jour` LIKE '$date' AND `matricule` =".$prest['salarie_id']." AND `client_id` = ".$prest['client_id']." AND `action` LIKE 'FIN' ") ;
                                                                                                    
																									
																									   // if($somme_hdeb_hfin == 2 AND $nbr_tot == 2)
																									// {
																											// $ino = 100  ;
																										
																									// } 
																								  
																							
																								// echo ""

																								// echo diff_time($int2heure(addDuree($prest['presta_Hdeb'], $prest['presta_Hduree'])), int2heure($prest['presta_Hdeb']))."<br/>";
																								++$i;
																								 echo $chaine  ;
																								 $classe="btn btn-info btn-sm";
																								 list($presta_id_sms)=dbi_fetch_row(dbi_query("SELECT presta_id FROM sms_salarie_avertissement WHERE presta_id = ".$prest["presta_id"])) ;
																							  if($presta_id_sms!=""){ $classe="btn btn-block btn-default disabled"; ;}

																								 ?>
																								 <tr>
																								 <form name="inscription[]" method="post" action="">
																								 <?php $number_ligne ++  ?>
																								   <td> <?php echo $prest["client_nom"]." (".$prest["presta_id"]." )"." -- ".$cmpt_heureF."----".$cmpt_heureD ; ?> </td>
																								   <td> <?php echo int2heure($prest['presta_Hdeb']) ; ?> </td>
																								   <td> <?php echo int2heure(addDuree($prest['presta_Hdeb'], $prest['presta_Hduree'])); ?> </td>
																								   <td> <?php echo $SAL["salarie_nom"]." ".$SAL["salarie_prenom"] ; ?> </td>
																								
																								  
																								    <td> 
																									
																									<input type="hidden" name="id_pDD" value="<?=$id_pDD ?>">
																									<input type="hidden" name="id_pFF" value="<?=$id_pFF ?>">
																									<input type="hidden" name="statu_ecart" value="<?=$statu_ecart ?>">
																									<input type="hidden" name="ecart" value="<?=$ecart ?>">
																									<input type="hidden" name="pres_heure_fin" value="<?=int2heure(addDuree($prest['presta_Hdeb'], $prest['presta_Hduree'])); ?>">
																									 
																									<input type="hidden" name="pres_heure_debut" value="<?=int2heure($prest['presta_Hdeb']) ;?>">
																									 <input type="hidden" name="presta_iddd" value="<?=$prest["presta_id"]?>">
																									 <input type="hidden" name="salarie_id" value="<?=$prest["salarie_id"]?>">
																									 <input type="hidden" name="client_id" value="<?=$prest["client_id"]?>">
																									 
																									 <?php if($cmpt_heureD > 1) {?>
																									 <input type="hidden" name="deux_prest_par_jour" value="deux_prest_par_jour">
																									      <select name="id_p_debut" id="lang">
																										  <?php while($res_hd = dbi_fetch_row($q_heureD)) {?> 
																											<option value="<?=$res_hd["id_p"] ?>"><?php echo $res_hd["heure"] ; ?> </option>
																										  <?php }?> 
																											
																										  </select>
																									<?php }elseif($heureD == ""){
																										
																										$non_valide = 1 ; // ce variable permet de determiner que il y a des pointage sans validation 
																									?>
																									 <input type="time"  name="heure_debut_manuel"   placeholder="00:00:00">
																									 <?
																									}else{ echo $heureD ;?>
																									
																									<input type="hidden" name="point_heure_debut" value="<?=$heureD ?>"> <!--inforùation utiliser  dans l'enregistriment dans la table  pointage_rapport (dans le cas ou le salarie pointe le debut on utilise cette information au lieu de heure_debut_manuel ) -->
																									<?
																									}  ?> 
																									</td>
																								   <td> 
																									 <?php if($cmpt_heureF > 1) {?>
																									       <select name="id_p_fin" id="lang">
																										  <?php while($res_hf = dbi_fetch_row($q_heureF)) {?> 
																											<option value="<?=$res_hf["id_p"] ?>"><?php echo $res_hf["heure"] ; ?> </option>
																										  <?php }?> 
																											
																										  </select>
																									<?php }elseif($heureF == ""){
																										$non_valide = 1 ; // ce variable permet de determiner que il y a des pointage sans validation 
																									 ?>
																									 <input type="time"  name="heure_fin_manuel"   placeholder="00:00:00">
																									 <?
																									}
																									else{ echo $heureF ; ?>
																									<input type="hidden" name="point_heure_fin" value="<?=$heureF ?>">
																									
																									<?}  ?> 
																									</td>
																									   
																									<?php  if($pointage_valider_debut == 1 OR $pointage_valider_fin== 1){ $valider_p = "valider" ; }else{$valider_p = "" ;}?>
																									<td> <?php echo $valider_p ; ?> </td>																								   <?php if($a==0){?><td> <?php echo $ecart ; ?> </td><?php }?>
																								   <?php if($a==1){?><td style="color:red;"> <?php echo "<strong>".$ecart."</strong>" ; ?> </td><?php }?>
																								   <?php if($a==2){?><td style="color:green;"> <?php echo "<strong>".$ecart."</strong>"  ; ?> </td><?php }?>

																								 <?php 

																								 $value['id_table_1'] = $SAL["salarie_id"]  ;
																								  // echo "==>.". $value['id_table_1']."<br/>" ;
																								     $id_table_one=$value['id_table_1'];
    $select_table2_data=dbi_query("SELECT COUNT(*) FROM `controle_pointage` WHERE `salarie_id`= ".$SAL["salarie_id"]);
     $ary_value=dbi_fetch_row($select_table2_data);
        if($ary_value[0] == 0){
           
            
        }
                                                                                                 echo " <td>" ;
                                                                                                 if($pointage_valider_debut == 0 OR $pointage_valider_fin == 0 ) {
																								 ?>
																							    <input type="submit"  name="validerr"  value="Valider" class="btn btn-info"> 
																						
																							 <?php } ?>
																								  </form>
																								 
																						    <? if($pointage_valider_debut != 0 AND $pointage_valider_fin != 0 ) {?>
																							 <a href="Pres_jours2_new.php?sup_dep=<?=$id_pDD?>&sup_fin=<?=$id_pFF?>" target="" > <input type="submit"  name="devalider"  value="Devalider" class="btn btn-danger" >  </a>
																		
																								<? }?> 
																								</td>
																						  	
                       																						   
																								</tr>
																								<?
																							}

																						}

																					}
																				// }
																}

															// echo $client_nom."  --- ".$tel['heure']." --- ".$tel['action'];






          
			// echo "==k=>".$date_jour."<br/>" ; 
			
			
			                                                                                // zidt had la ligne pour actualiser la page / hit min taykounou 2 prestation meme client meme salarie meme jour et je les valide f/ f mara lowla l'affichage taykoun khassre 
                                                                                          
			
			$nombre_pointage =  $number_ligne*2 ;
			
			
              // echo "******===>".$nombre_pointage."<br/>" ;  
          list($nombre_validation) = dbi_fetch_row(dbi_query("SELECT count(*) FROM `telepointage` WHERE `jour` LIKE '$date_jour' and  pointage_valider = 1 ")) ;
          
     	  list($nombre_pointage_reel) = dbi_fetch_row(dbi_query("SELECT count(*) FROM `telepointage` WHERE `jour` LIKE '$date_jour' ")) ; 	  
		  
		  // echo "pointage reel==>".$nombre_pointage_reel."<br/>" ; 
		  // echo " *****  pointage validé ==>".$nombre_validation."<br/>" ; 
		  // echo " nombre de prestation  ==>".$number_ligne."<br/>" ; 
		  
		  // echo "nombre_validation ===OOO>".$nombre_validation."<br/>" ;
		  
		  
		  // echo 
		  
		     // echo "------------------------------------- <br/> " ;
		    // echo " nombre_ligne*2 ******===>".$nombre_pointage."<br/>" ;  
			   // echo " nombre_validation ******===>".$nombre_validation."<br/>" ;  
			   
			   // echo "  --------------------------------- <br/> " ;
			   
			  
		  
		  // if($nombre_validation == $nombre_pointage ){
			  
			  dbi_query("UPDATE `verification_pointage` SET nombre_prestation =  '".$number_ligne."'  WHERE date = $date_jour ") ;
		  // }
																// }
															?>






															</tbody>
														</table><!-- /.table -->
														
														<?php
																										if( $_SESSION['automatique'] == 1){
																 $_SESSION['automatique'] =  2 ;												
echo("<script>location.href = '".Pres_jours2."_new.php';</script>");
												}
														
														 $_SESSION['automatique'] =  2 ;
												
error_reporting(E_ALL | E_WARNING | E_NOTICE);
ini_set('display_errors', TRUE);
// echo "lkllllllllll <br/>" ;

// echo("<script>location.href = '".Pres_jours2."_new.php?msg=$msg';</script>");

// echo "ddddddddddd <br/>" ;
												// if($ino == 100){
// echo("<script>location.href = '".Pres_jours2."_new.php?msg=$msg';</script>");
												// }
												?>
					
													</div><!-- /.box-body -->
												</div><!-- /.tab -->
											</div><!-- /.header_ray -->
										</div><!-- /.onglet_dotted -->
								    </div><!-- /.card-body -->
							    </div><!-- /.card card-primary card-outline -->
							</div> <!-- /.col-12 -->
						</div>  <!-- /.row -->
				</section> <!-- /.section -->




	</div>


<?
if($non_valide == 1){
  dbi_query("UPDATE `verification_pointage` SET `non_valide` = '1' WHERE `date` = ".$_SESSION['datej']) ; 
}

if($non_valide == 0){
  dbi_query("UPDATE `verification_pointage` SET `non_valide` = '0' WHERE `date` = ".$_SESSION['datej']) ; 
}

?>

<?php include('footerr.php'); ?>


<script>

        function insertdata(inid, element){

            $.ajax({
                url:"without_reloading.php",
                type:"GET",
                data:{
                    "inid":inid
                },
                success:function(data){
                    element.removeAttr('onclick');
                }
            });

        }
        function change(elements){
            elements.style.backgroundColor="brown";
            elements.style.color="white";
        }

</script>

<script type="text/javascript">
// $(document).ready(function(){
    // $('#myModal').on('show.bs.modal', function (e) {
        // var rowid = $(e.relatedTarget).data('id');
        // $.ajax({
            // type : 'post',
            // url : 'ajaxAjoutMat.php', //Here you will fetch records
            // data :  'rowid='+ rowid, //Pass $id
            // success : function(data){
            // $('#fetch').html(data);//Show fetched data from database
            // }
        // });
     // });
// });


</script>

<script type="text/javascript">
$(document).ready(function(){
    $('#myModal').on('show.bs.modal', function (e) {
        var rowid = $(e.relatedTarget).data('id');
		var rowid_type = $(e.relatedTarget).data('type');
		var rowid_presta_id = $(e.relatedTarget).data('presta_id');


        $.ajax({
            type : 'post',
            url : 'envioi_SMS_sal.php', //Here you will fetch records
            data :  'rowid='+ rowid +'&rowid_type='+ rowid_type +'&rowid_presta_id='+ rowid_presta_id, //Pass $id
            success : function(data){
            $('#fetch').html(data);//Show fetched data from database
            }
        });
     });
});


</script>

<script type="text/javascript">
$(document).ready(function(){
    $('#myModal_tache_all').on('show.bs.modal', function (e) {
        var rowid = $(e.relatedTarget).data('id');
        $.ajax({
            type : 'post',
            url : 'nouveau_pointage_ajax', //Here you will fetch records
            data :  'rowid='+ rowid, //Pass $id
            success : function(data){
            $('#fetch_tache_all').html(data);//Show fetched data from database
            }
        });
     });
});


</script>



</body>
</html>

AnonSec - 2021