<html>

<head>
	<meta http-equiv='content-type' content='text/html;charset=utf-8'>
	<title>WebBike V1.0</title>
	<link href="style.css" rel="stylesheet" media="screen">
</head>

<body>
	<script language=javascript>
		function valide_suppresion() {
			if (confirm("Voulez-vous vraiment supprimer ces vacances ?")) {
				this.document.infodel.submit();
			}
		}
	</script>
	<?php
	require 'database.inc.php';
	//session_start();
	//session_register("lg_user");
	//session_register("lg_password");
	//session_register("lg_admin");
	//session_register("lg_menu1");
	//session_register("lg_menu2");
	//session_register("lg_menu3");
	//session_register("lg_menu4");
	//session_register("lg_menu5");
	//session_register("lg_menu6");
	if ((!empty($User)) && (!empty($Passwd))) {
		$lg_user = $User;
		$lg_password = $Passwd;
	}
	if (Test_User($lg_user, $lg_password) == TRUE) {
		//  $annee=date("Y");
		if ($new == 0) {
			$NoClient = $emp;
			$requette = "SELECT * FROM absenceemploye" . ID_GARAGE . " WHERE NoClient=$NoClient AND Debut='" . substr($Start, 0, 10) . "' AND DebutMA=" . substr($Start, 10, 1);
			if ($resultat = Connection::executeRawQueryWithfetchAll($requette)) {
				if ($ligne = $resultat[0]) {
					if ($ligne['Type'] == 3 && !(Is_Admin())) {
						echo "Vacances validées";
					} else {
						echo "<form METHOD='GET' name='info' action='ok_employe.php'>";
						echo "<TABLE border=1><input type='hidden' name='NoClient' value='$NoClient'><input type='hidden' name='Start' value='$Start'>\n";
						echo "<TR><TH>Type</TH><TD><select name='Type'><option value='0'";
						if ($ligne['Type'] == 0)
							echo " selected";
						echo ">Vacances</option><option value='1'";
						if ($ligne['Type'] == 1)
							echo " selected";
						echo ">Indisponibilité atelier</option><option value='2'";
						if ($ligne['Type'] == 2)
							echo " selected";
						echo ">Récupération</option>";
						if (Is_Admin()) {
							echo "<option value='3'";
							if ($ligne['Type'] == 3)
								echo " selected";
							echo ">Vacances validées</option>";
						}
						echo "</select></TD></TR>\n";
						echo "<TR><TH>Motif</TH><TD><Input type='text' name='Motif' value='" . $ligne['Motif'] . "'></TD></TR>\n";
						echo "<TR><TH>Date debut</TH><TD>" . Input_Date("Debut", substr($ligne['Debut'], 0, 4), substr($ligne['Debut'], 5, 2), substr($ligne['Debut'], 8, 2)) . "<select name='Debut_periode'><option value='0'";
						if ($ligne['DebutMA'] == 0)
							echo " selected";
						echo ">matin</option><option value='1'";
						if ($ligne['DebutMA'] == 1)
							echo " selected";
						echo ">après-midi</option></select></TD></TR>\n";
						echo "<TR><TH>Date fin</TH><TD>" . Input_Date("Fin", substr($ligne['Fin'], 0, 4), substr($ligne['Fin'], 5, 2), substr($ligne['Fin'], 8, 2)) . "<select name='Fin_periode'><option value='0'";
						if ($ligne['FinMA'] == 0)
							echo " selected";
						echo ">matin</option><option value='1'";
						if ($ligne['FinMA'] == 1)
							echo " selected";
						echo ">après-midi</option></select></TD></TR>\n";
						echo "</TABLE>\n";
						echo "<button type='submit'>Valider</button><BR>\n";
						echo "</form>";
						if (Is_Admin()) {
							echo "<form METHOD='GET' name='infodel' action='del_employe.php'>";
							echo "<input type='hidden' name='NoClient' value='$NoClient'><input type='hidden' name='Start' value='$Start'>\n";
							echo "<button type='button' onClick='valide_suppresion();'>Supprimer</button><BR>\n";
							echo "</form>";
						}
					}
				}
			}
		} else {
			echo "<form METHOD='GET' name='info' action='ok_employe.php'>";
			echo "<TABLE border=1><input type='hidden' name='NoClient' value='$NoClient'><input type='hidden' name='new' value='1'>\n";
			echo "<TR><TH>Type</TH><TD><select name='Type'><option value='0'>Vacances</option><option value='1'>Indisponibilité atelier</option><option value='2'>Récupération</option></select></TD></TR>\n";
			echo "<TR><TH>Motif</TH><TD><Input type='text' name='Motif'></TD></TR>\n";
			echo "<TR><TH>Date debut</TH><TD>" . Input_Date("Debut", $annee, $mois, $jour) . "<select name='Debut_periode'><option value='0'";
			if ($periode == 0)
				echo " selected";
			echo ">matin</option><option value='1'";
			if ($periode == 1)
				echo " selected";
			echo ">après-midi</option></select></TD></TR>\n";
			$date = mktime(0, 0, 0, $mois, $jour, $annee);
			$a_jour = date("d", $date);
			$a_mois = date("m", $date);
			$a_annee = date("Y", $date);
			echo "<TR><TH>Date fin</TH><TD>" . Input_Date("Fin", $a_annee, $a_mois, $a_jour) . "<select name='Fin_periode'><option value='0'";
			//	  if($periode==0)
			//	    echo " selected";
			echo ">matin</option><option value='1'";
			//	  if($periode==1)
			echo " selected";
			echo ">après-midi</option></select></TD></TR>\n";
			if (Is_Admin()) {
				echo "<TR><TH>Admin</TH><TD>true</TD></TR>";
			}
			echo "</TABLE>\n";

			echo "<button type='submit'>Valider</button><BR>\n";
			echo "</form>";
		}
	}
	?>
</body>

</html>