<?php
	session_start ();	include('database.php');	DB_connexion(); 
	if (!isset($_SESSION['nom']) && !isset($_SESSION['password']))	{  			header("Location: login.php");   	}
	header( 'content-type: text/html; charset=utf-8' );
	if(isset($_GET['submit']))		{				//echo '<pre>';			//print_r($_GET);			$nbligne = $_GET['nbligne'];			$tab_selections = array();
			for( $i=0; $i < $nbligne ; $i++)			{				${'text'.$i} = "cached".$i;				$val = ${'text'.$i};				$path_parts = pathinfo($_GET[$val]);				$path_parts['basename'];				$tab_selections[] = $path_parts['basename'];					}		
			//echo '<pre>';			//print_r($tab_selections);
			$mois = $_GET['mois']; 			$annee = $_GET['annee'];  			$table = "reservation" .$annee;
			// remise à off de toutes les dates			$sql = "SELECT * FROM " .$table ." WHERE annee ='$annee' and mois ='$mois' ";				//echo $sql;			$result = mysqli_query($connexion, $sql );			//$n = mysqli_num_rows($result);			//echo $n;
			$val = "unactif";						$tab_id = array();						while($datas = mysqli_fetch_assoc($result))			{	$id = $datas['id'];				$tab_id[] = $id;
				$sql = "UPDATE " .$table ." SET mode = '$val' , indice = '' ,																seance1 = 'unselect' , 																seance2 = 'unselect' ,																seance3 = 'unselect' , 																seance4 = 'unselect' ,																seance5 = 'unselect' ,																seance6 = 'unselect' ,																seance7 = 'unselect' ,																seance8 = 'unselect' WHERE id ='$id' ";
				//echo $sql;				//echo '<br>';				mysqli_query($connexion, $sql );			}						//echo '<pre>';			//print_r($tab_id);						for( $i=0; $i < $nbligne  ; $i++)			{	$indice = $i + 1;				${'text'.$i} = "cached".$i;				$val = ${'text'.$i};				if($tab_selections[$i] == "yes.png")				{						$val = "actif";					$id = $tab_id[$i];					$sql = "UPDATE " .$table ." SET mode = '$val' , indice = '$indice' WHERE id ='$id' ";					//echo $sql .'  ' .$i;					//echo '<br>';					mysqli_query($connexion, $sql );					}				}
			echo "La selection a été enregistrée";			echo '<br><br>';
	}
?>	
 <script>
var newsrc = "yes.png";
function toto() {	var valeur = document.getElementById("nbligne").value;	
	for (i = 0; i < valeur; i++)	{ 		var cached = 'cached'+i;		var elt = 'id'+i;		document.getElementById(cached).value = document.images[elt].src; 	} }	 
 
function change_image(pic){
  if( newsrc == "yes.png" )  {    document.images[pic].src = "yes.png";    document.images[pic].alt = "Yes";    newsrc  = "no.png";  }  else  {    document.images[pic].src = "no.png";    document.images[pic].alt = "no";    newsrc  = "yes.png";  }
}

</script> 
<!--
Image switching with onclick
-->

<html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head></head><body><style>
th, td {    padding: 5px;}
input.largerCheckbox{		-moz-appearance: none;		height: 25px;		width: 25px;		zoom: 1.4;}
label{	display: inline-block;	width: 200px;	float: left;}
.increase {    width:30px;    height:30px;}
</style>
	<link rel="stylesheet" href="menu_style.css" type="text/css">
	<div id='cssmenu'>	<ul>		<li><a href='home.php'><span>Home</span></a></li>		<li><a href='selection_planning_mois.php'><span>Planning</span></a></li>		<li><a href='selection_gestion_mois.php'><span>Gestion</span></a></li>		<li><a href='selection_statistique_mois.php'><span>Statistiques</span></a></li>
<?php
		if($_SESSION['nom'] == "admin")		{ 			echo '<li class="active"><a href="configuration.php"><span>Configuration</span></a></li>';		}
?>
		<li><a href='change_password.php'><span>Changer password</span></a></li>		<li><a href='logout.php'><span>Déconnexion</span></a></li>		<li><a href='#'><span><?php echo $_SESSION['nom'] .' ' .$_SESSION['prenom'] .' connecté' ?></span></a></li>	</ul>	</div>	<br>	<br>
<?php
			//$mois = $_GET['mois'];			$mois = "mars";			$annee = date('Y');			$nom_table  = "reservation" .$annee;			echo ucfirst($mois) .' ' .$annee;			echo '<br><br>';
			$sql = "SELECT * FROM " .$nom_table ." WHERE annee ='$annee' and mois ='$mois'" ;				//echo $sql;			$result = mysqli_query($connexion, $sql );
			if(!$result)			{				die('Impossible d\'exécuter la requête :' . mysql_error());			}
			$nbligne = mysqli_num_rows($result);?>			<form action="#" name ="form_gestion" method="get"><?php			echo '<input type="hidden" name="nbligne" id="nbligne" value="' .$nbligne .'">';			echo '<input type="hidden" name="mois" id="mois" value="' .$mois .'">';			echo '<input type="hidden" name="annee" id="annee" value="' .$annee .'">';
			echo '<table>';			echo '<tr>';			echo '<th>Sem</th>';			echo '<th>Jour</th>';			echo '<th>Date</th>';			echo '<th>Selection</th>';			echo '</tr>';
			for( $i=0; $i < $nbligne ; $i++)			{					$cached = 'cached' .$i;				echo "<input type='hidden' name='$cached' id='$cached' value=''>";			}
			$cpt = 0;
			while($datas = mysqli_fetch_assoc ($result))			{		
				$semaine = $datas['semaine'];				$rendezvous = $datas['rendezvous'];				$jour = $datas['jour'];				$mode = $datas['mode'];					$objet = 'id' .$cpt;
				// pair ou impair ??				if ($semaine%2 == 1)				{						echo "<tr bgcolor = '#A6FF4D'>";				} 
				else				{					echo "<tr bgcolor = '#FFAC59'>";				}
				echo "  <td align='center'> $semaine </td>						<td align='center'> $rendezvous </td>								<td align='center'> $jour </td>";
				if($mode == "actif")				{  					//echo  '<td align="center"><input type="checkbox" class="largerCheckbox" name="options[]" checked value="' .$rendezvous  .'"></td>';					echo '<td align="center"><img src="yes.png" alt="non"" id=' .$objet .' onclick="change_image(' .$cpt .')" /></td>';				} 
				else				{					//echo '<td align="center"><input type="checkbox"  class="largerCheckbox" name="options[]" value="' .$rendezvous  .'"></td>';					echo '<td align="center"><img src="no.png" alt="non"" id=' .$objet .' onclick="change_image(' .$cpt .')" /></td>';				}
				echo '</tr>';				$cpt = $cpt + 1;
			}
			echo '<tr>';			echo '<td colspan="4" align = "center">			<input type="submit" name="submit" value="Enregistrer" onclick = "toto()";/>			</td>';				echo '</tr>';			echo '</table>';			echo '</form>';
/*			
			for( $i=0; $i <= $nbligne ; $i++)
			{	$objet = 'cached' .$i;
				echo "<input type='hidden' name='$objet' id='$objet' value=''>";
			
			}
			<table  id="matable" align="left" border="0" cellpadding="10" cellspacing="1" >
			<tbody>
			<tr bgcolor="#f1f3f5">
			<th class="center" >Id</th>
			<th align="center" >Utilisateur</th>
			</tr>	
			for( $i=0; $i <= $nbligne ; $i++)
			{	$objet = 'id' .$i;
				echo '<tr>';
				echo '<td>' .$i .'</td>';
				//echo "<td><img src='no.png' alt='non' id='$objet'  onclick='changeImage($id)' /></td>";
				echo '<td><img src="no.png" alt="non"" id=' .$objet .' onclick="changeImage(' .$i .')" /></td>';
				echo '</tr>';				}
		//$cheque_objet = 'cheque' .$id;
		//echo '<div class="mainimg"><img src="no.png" alt="non" id="pic"  onclick="changeImage()" /></div>';
 
			</tr>
			</tbody>
			</table>
			<input type="submit" name="submit" value="Enregistrer" onclick = "toto()";/>	
			</form>
			*/
?>

</body>
</html>
 

