<style>

label
{
	display: inline-block;
	width: 150px;
	float: left;
}
</style>


<?php

date_default_timezone_set('Europe/Paris');

function nom_jour($date) 
{
	$jour_semaine = array(1=>"lundi", 2=>"mardi", 3=>"mercredi", 4=>"jeudi", 5=>"vendredi", 6=>"samedi", 7=>"dimanche");
	list($annee, $mois, $jour) = explode ("-", $date);
 
	$timestamp = mktime(0,0,0, date($mois), date($jour), date($annee));
	$njour = date("N",$timestamp);
 
	return $jour_semaine[$njour];
 
}
/////////////////////////////////////////////////////////////////////////////////
function jours_feries($annee)
{
		$date_paques = easter_date($annee);
        $jour_paques = date('d', $date_paques); // j
        $mois_paques = date('m', $date_paques); // n
		//echo "---- " .$date_paques . "  " .$jour_paques . "  "  .$mois_paques  . "  "  .$annee;
        $jours_feries = array(
                // Jours feries fixes
                mktime(0, 0, 0, 1, 1, $annee),// 1er janvier
                mktime(0, 0, 0, 5, 1, $annee),// Fete du travail
                mktime(0, 0, 0, 5, 8, $annee),// Victoire des allies
                mktime(0, 0, 0, 7, 14, $annee),// Fete nationale
                mktime(0, 0, 0, 8, 15, $annee),// Assomption
                mktime(0, 0, 0, 11, 1, $annee),// Toussaint
                mktime(0, 0, 0, 11, 11, $annee),// Armistice
                mktime(0, 0, 0, 12, 25, $annee),// Noel

                // Jour feries qui dependent de paques
                mktime(0, 0, 0, $mois_paques, $jour_paques , $annee),
                mktime(0, 0, 0, $mois_paques, $jour_paques + 1, $annee),// Lundi de paques
                mktime(0, 0, 0, $mois_paques, $jour_paques + 39, $annee),// Ascension
                mktime(0, 0, 0, $mois_paques, $jour_paques + 50, $annee), // Pentecote
        );

        sort($jours_feries);
		
		//print_r($jours_feries);
		
		/*for( $i=0; $i <count($jours_feries) ; $i++)
		{
			echo date('d/m/Y', $jours_feries[$i] );
			echo '<br>';
		} */
 
		return($jours_feries);
 
 }

/////////////////////////////////////////////////////////////////////////////////
function calendrier($annee)
{
	$tab_mois = array("janvier","fevrier","mars","avril","mai","juin","juillet","aout","septembre","octobre","novembre","decembre");
	$jour_semaine = array(1=>"lundi", 2=>"mardi", 3=>"mercredi", 4=>"jeudi", 5=>"vendredi", 6=>"samedi", 7=>"dimanche");
	$n = cal_days_in_month(CAL_GREGORIAN, 2, $annee);
	$nb_jours = array(31,$n,31,30,31,30,31,31,30,31,30,31);
		
	$jours_feries = jours_feries($annee);
	
	$listing_jours = array();
		
	for( $i=0; $i <12 ; $i++)
	{
			for( $j=1; $j <= $nb_jours[$i] ; $j++)
			{
				$jour = $j;
				if($jour<10)
					$jour = '0'.$jour;
			
				$mois = $i+1;
					if($mois<10)
				$mois = '0'.$mois;
			
			
				$date = $jour ."-" .$mois ."-" .$annee;
				$ts = strtotime($date);
				
				$jour_chiffre = date("N",$ts);
				$jour_lettre = $jour_semaine[$jour_chiffre];
			
				if($jour_chiffre == 1 || $jour_chiffre == 2 || $jour_chiffre == 3 || $jour_chiffre == 4 || $jour_chiffre == 5)
				{  	
					$infos = "";
					if(in_array($ts, $jours_feries)) 
					{ 
						//echo $date ." - " .$jour_lettre ."   " .$ts  ."  --> Ferie" ;
						//echo '<br>';
						//$listing_jours[] = $date ."_" .$jour_lettre ."_" .$ts  ."-" .'ferie' ;
						
					}
					else
					{	//echo $date ." - " .$jour_lettre ."   " .$ts;
						//echo '<br>';
						$listing_jours[$i][] = $date ."_" .$jour_lettre ."_" .$ts; 
					}	
				}
			
			}	
			
	}
	
	return($listing_jours);
		
}
//////////////////////////////////////////////////

function calendrier_bis($annee)
{
	$tab_mois = array("janvier","fevrier","mars","avril","mai","juin","juillet","aout","septembre","octobre","novembre","decembre");
	$jour_semaine = array(1=>"lundi", 2=>"mardi", 3=>"mercredi", 4=>"jeudi", 5=>"vendredi", 6=>"samedi", 7=>"dimanche");
	$n = cal_days_in_month(CAL_GREGORIAN, 2, $annee);
	$nb_jours = array(31,$n,31,30,31,30,31,31,30,31,30,31);
		
	$jours_feries = jours_feries($annee);
	
	$listing_jours = array();
		
	for( $i=0; $i <12 ; $i++)
	{
			for( $j=1; $j <= $nb_jours[$i] ; $j++)
			{
				$jour = $j;
				if($jour<10)
					$jour = '0'.$jour;
			
				$mois = $i+1;
					if($mois<10)
				$mois = '0'.$mois;
			
			
				$date = $jour ."-" .$mois ."-" .$annee;
				$ts = strtotime($date);
				
				$jour_chiffre = date("N",$ts);
				$jour_lettre = $jour_semaine[$jour_chiffre];
			
				if($jour_chiffre == 1 || $jour_chiffre == 2 || $jour_chiffre == 3 || $jour_chiffre == 4 || $jour_chiffre == 5)
				{  	
					$infos = "";
					if(in_array($ts, $jours_feries)) 
					{ 
						//echo $date ." - " .$jour_lettre ."   " .$ts  ."  --> Ferie" ;
						//echo '<br>';
						//$listing_jours[] = $date ."_" .$jour_lettre ."_" .$ts  ."-" .'ferie' ;
						
					}
					else
					{	//echo $date ." - " .$jour_lettre ."   " .$ts;
						//echo '<br>';
						
						$week = ISOWeek($annee , $mois , $jour);
						
						$listing_jours[$i][] = $date ."_" .$jour_lettre ."_" .$ts ."_" .$week; 
					}	
				}
			
			}	
			
	}
	
	return($listing_jours);
		
}


	
	///////////////////////////////////////
	function ISOWeek($y , $m , $d)
	{
     $week=strftime("%W", mktime(0, 0, 0, $m, $d, $y)); 
      $dow0101=getdate(mktime(0, 0, 0, 1, 1, $y)); 
      if ($dow0101["wday"]>1 && $dow0101["wday"]<5) 
      $week++; 
      elseif ($week==0) 
      $week=53; 
      return(substr("00" . $week, -2)); 
    }	
	
//////////////////////////////////////////////////	
function creation_table_annuelle($annee)
{	
	$connexion = DB(); 
	
	$nom_table  = "reservation" .$annee ."_v3_test";
	
	$sql = "CREATE TABLE IF NOT EXISTS " .$nom_table ."
			(
				id int(11) NOT NULL AUTO_INCREMENT,
				annee varchar(30) NOT NULL,
				mois varchar(30) NOT NULL,
				rendezvous varchar(30) NOT NULL,
				ts varchar(30) NOT NULL,
				jour varchar(30) NOT NULL,
				semaine varchar(30) NOT NULL,
				mode varchar(30) NOT NULL,        
				indice varchar(30) NOT NULL,        
				normal varchar(30) NOT NULL,
				etendu varchar(30) NOT NULL,
				formule varchar(30) NOT NULL,
				seance1 varchar(50) NOT NULL,
				seance2 varchar(50) NOT NULL,
				seance3 varchar(50) NOT NULL,
				seance4 varchar(50) NOT NULL,
				seance5 varchar(50) NOT NULL,
				seance6 varchar(50) NOT NULL,
				seance7 varchar(50) NOT NULL,
				seance8 varchar(50) NOT NULL,
				horairedebut varchar(50) NOT NULL,
				horairefin varchar(50) NOT NULL,
				avant varchar(50) NOT NULL,
				apres varchar(50) NOT NULL,
				PRIMARY KEY (id))";
			
			//echo $sql;
			
			
			$result = mysqli_query($connexion, $sql );
			if(!$result)
			{
				die('Impossible d\'exécuter la requête :' . mysql_error());
			}

	echo "Table done : " .$nom_table; 
	echo '<br>';	
			
	return($nom_table);		
			
}
//////////////////////////////////////////////////	
function remplir_table_calendrier($table,$annee,$mois,$rendezvous,$ts,$jour,$semaine,$mode,$indice,$normal,$etendu,$formule)
{
		
	$connexion = DB(); 	
		
	//$sql = "INSERT INTO " .$table ." (id, annee, mois, rendezvous, ts, jour, semaine , mode, indice, normal,etendu,formule,seance1,seance2,seance3,seance4,seance5,seance6,seance7,seance8 ) 
	//						VALUES('', '$annee' ,'$mois' , '$rendezvous' ,'$ts', '$jour', '$semaine', '$mode' , '0', '0', 'courte' ,'unselect','unselect','unselect','unselect','unselect','unselect','unselect','unselect')"; 
	
	$sql = "INSERT INTO " .$table ." (id, annee, mois, rendezvous, ts, jour, semaine , mode, indice, normal,etendu,formule,seance1,seance2,seance3,seance4,seance5,seance6,seance7,seance8 ) 
							VALUES('', '$annee' ,'$mois' , '$rendezvous' ,'$ts', '$jour', '$semaine', '$mode' , '$indice' , '$normal', '$etendu', '$formule', 'unselect','unselect','unselect','unselect','unselect','unselect','unselect','unselect')"; 
	
	
	echo $sql;
	
	$result = mysqli_query($connexion, $sql );
	if(!$result)
	{
		die('Impossible d\'exécuter la requête :' . mysql_error());
	}
	
}			
//////////////////////////////////////////////////	
function generateur_calendrier()
{	
	$liste_annee = array("2024");  
	$liste_mois = array("janvier","fevrier","mars","avril","mai","juin","juillet","aout","septembre","octobre","novembre","decembre");
		
	for( $i=0; $i < count($liste_annee) ; $i++)
	{		
			////$table = creation_table_annuelle($liste_annee[$i]);

			$listing_jours = calendrier($liste_annee[$i]);	
			
			echo "<pre>";
			print_r($listing_jours);
			echo "</pre>";
			
			/*for( $j=0; $j < count($listing_jours) ; $j++)
			{ 
		         $tab_mois = $listing_jours[$j];
				 for( $k=0; $k < count($tab_mois) ; $k++)
			     { 
						$pieces = explode('_',$tab_mois[$k]);
						$annee = $liste_annee[$i];
						$mois = ucfirst($liste_mois[$j]);
						$rendezvous = $pieces[0];
						$jour = ucfirst($pieces[1]);
						$ts = $pieces[2];
						$semaine = date('W',$ts);
						//remplir_table_calendrier($table,$annee,$mois,$rendezvous,$ts,$jour,$semaine,"noactif","courte");
						
						$inc = $k+1;
						
						remplir_table_calendrier($table,$annee,$mois,$rendezvous,$ts,$jour,$semaine,"noactif", $inc,"0","0","courte");
						
						//function remplir_table_calendrier($table,$annee,$mois,$rendezvous,$ts,$jour,$semaine,,$indice,$normal,$etendu,$formule)

						
				 }
			}
			*/
	 	
	}
}
//////////////////////////////////////////////////	
function blabla_calendrier($annee)
{	
	echo "++++++" .$annee;
	echo "<br>";

	/*$listing_jours = calendrier($annee);	
			
	echo "<pre>";
	print_r($listing_jours);
	echo "</pre>";*/
	
}


/*CREATE TABLE IF NOT EXISTS gestion (
  id int(11) NOT NULL AUTO_INCREMENT,
  annee varchar(30) NOT NULL,
  mois varchar(30) NOT NULL,
  jour varchar(30) NOT NULL,
  client varchar(30) NOT NULL,
  mode varchar(30) NOT NULL,
  seance varchar(30) NOT NULL,
  compteur varchar(30) NOT NULL,
  montant varchar(30) NOT NULL,
  statut varchar(30) NOT NULL,
  cheque varchar(30) NOT NULL,
  banque varchar(30) NOT NULL,
  PRIMARY KEY (id)
)*/


	
	

	//difference_date_1($str_date1,$str_date2);	


	
/*
	
*/


/*$days = array(
    1 => 'Monday',
    2 => 'Tuesday',
    3 => 'Wednesday',
    4 => 'Thursday',
    5 => 'Friday',
    6 => 'Saturday',
    7 => 'Sunday'
);

$num = 7;
echo $days[$num];
echo "<br>";*/


// Prints October 3, 1975 was on a Friday
//echo "Oct 3,1975 was on a ".date("l", mktime(0,0,0,10,3,1975)) . "<br>";

//	echo " ---->>>> ".date("l", mktime(0,0,0,3,1,2024)) . "<br>";
	
	
	
function test()
{	
	
	$currentDate = date('Y-m-d');
	echo $currentDate;
	echo "<br>";
	
	
	list($annee, $mois, $jour) = explode ("-", $currentDate);
	echo " ---- " .$annee ." - " .$mois ." - " .$mois;
	echo "<br>";
	
	echo "** Day number *** " .getDayOfWeekNumber(1, 3, 2024);
	echo "<br>";
	
	echo "Name of day : " .getNameOfDay(1, 3, 2024);
	echo "<br>";
	
	echo "There was " .getDayInMonth(3, 2024) ." days in March 2024";
	echo "<br>";

	echo "Bisextile ?: " .bisextile("2024");
	echo "<br>";

	echo "Get day number: " .getDay("2024-02-29");
	echo "<br>";

	echo "Weeknumber: " .getWeek("2024-02-28");
	echo "<br>";
	$val = getWeek("2024-02-28");
	echo gettype($val);
	echo "<br>";
	echo intval($val);  
	echo "<br>";
	
	$weekNumber = date("W"); 
	echo "Semaine en cours " .$weekNumber; 
	echo "<br>";
	
	
	// pour supprimer les 0 au début d'une chaine
	//$str = ltrim($str, "0");  
	
	//echo "$$$$$ " .idate('W', mktime(0,0,0,3,1,2024) );
	//echo "<br>";
	
	
	
	echo "Ecart en jours : " .difference_date_1('2022-04-01', '2022-04-10');
	echo "<br>";

	echo "Ecart en jours : " .difference_date_2('2024-04-01', '2024-04-05');
	echo "<br>";

	generateur_calendrier();
	
}	
	
/**********************************************************/
function convert_date_to_timestamp()
{

}
/**********************************************************/
function difference_date_1($str_date1,$str_date2)
{
	$date1 = new DateTime($str_date1);
	$date2 = new DateTime($str_date2);
	$interval = $date1->diff($date2);
	//echo $interval->days;
	return $interval->days;
}	
/**********************************************************/
function difference_date_2($str_date1,$str_date2)
{
	$date1 = strtotime($str_date1);
	$date2 = strtotime($str_date2);
	$diff = $date2 - $date1;
	$days = floor($diff / (60 * 60 * 24));
	return $days;
}	
/**********************************************************/
function getDay($date)
{
	$timestamp = strtotime($date);
	$day = date("z", $timestamp)+1;
	return $day;
}
/**********************************************************/
function getWeek($date)
{
	$date = new DateTime($date);
	$week = $date->format("W");
	return $week;
}
/**********************************************************/
function bisextile($year)
{
    return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year %400) == 0)));
}
/**********************************************************/
function getDayInMonth($mois, $annee)
{
	$day = cal_days_in_month(CAL_GREGORIAN,$mois,$annee);
	return $day;
	//echo "There was $d days in " .$mois ." " .$annee;
}
/**********************************************************/
function fff()
{
	$DayOfWeekNumber = date("w");
	switch($DayOfWeekNumber)
	{
	   case 0 : echo("Today is Sunday."); break;
	   case 1 : echo("Today is Monday."); break;
	   case 2 : echo("Today is Tuesday."); break;
	   case 3 : echo("Today is Wednesday."); break;
	   case 4 : echo("Today is Thursday."); break;
	   case 5 : echo("Today is Friday."); break;
	   case 6 : echo("Today is Saturday.");
	}
}
/**********************************************************/
/*
function aaa($jour, $mois, $annee)
{
	// Prints October 3, 1975 was on a Friday
	
	$day = date("l", mktime(0,0,0, $mois,$jour,$annee));
	return $day;
	//echo "Oct 3,1975 was on a ".date("l", mktime(0,0,0, $mois,$jour,$annee)) . "<br>";
}
*/
/**********************************************************/
function getNameOfDay($jour, $mois, $annee)
{
	// Prints October 3, 1975 was on a Friday
	
	//echo " ++++++ "  .date("l", mktime(0,0,0, $mois , $jour, $annee));
	
	$day_name = date("l", mktime(0,0,0, $mois , $jour, $annee));
	return $day_name;
	
}
/**********************************************************/
// https://www.pierre-giraud.com/php-mysql-apprendre-coder-cours/obtenir-formater-date/
function getDayOfWeekNumber($jour, $mois, $annee)
{
	$day_number = date('N', mktime(0,0,0, $mois , $jour, $annee));
	return $day_number;
	
		
	/*$days = array(
    1 => 'Monday',
    2 => 'Tuesday',
    3 => 'Wednesday',
    4 => 'Thursday',
    5 => 'Friday',
    6 => 'Saturday',
    7 => 'Sunday'
);

$num = 7;
echo $days[$num];
echo "<br>";*/

}

// https://www.tutorialspoint.com/how-to-calculate-the-difference-between-two-dates-in-php
// https://www.tutorialkart.com/php/php-difference-between-two-dates/#gsc.tab=0
/**********************************************************/
function pipo()
{

	// Creates DateTime objects
	$datetime1 = date_create('2017-05-29');
	$datetime2 = date_create('2023-06-20');

	// Calculates the difference between DateTime objects
	$interval = date_diff($datetime1, $datetime2);

	// Printing result in years & months format
	echo $interval->format('%R%y years %m months');
	
	$date1 = date_create( "2022-01-15" );
	$dateInterval = DateInterval::createFromDateString( "8 days" );
	$outputDate = date_add( $date1, $dateInterval );
	echo $outputDate -> format( 'Y-m-d' );
	
}
/**********************************************************/



//DEV 00001385

//VLT612E2
?>