<html>
<!--    cibl&eacute; par: gestion-contrat.php 

		cible:  gestion-contrat.php						
 -->
 
 <!-- param&egrave;tre &eacute;mis:        -session_id         le num&eacute;ro de la session
							-code_contrat
							-code_client

	 param&egrave;tre re&ccedil;evable :  -session_id         le num&eacute;ro de la session
	 						-code_contrat
							-code_client
	 
 -->	
 <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ajout d'une location</title>
<body>

<?php 

//Fichiers contenant les fonctions utilis&eacute;es dans le script.
require("../outils/gui.php");
require("../outils/session.php");
require("../outils/mise_en_page.php");
require("gestion-poste.php");
require("../historique.php");

//V&eacute;rifier si la session est valide.
$Bsession_id = $_GET["Bsession_id"];
verifierSession($Bsession_id);

//V&eacute;rifier les droits de l'utilisateur.
$privilege_base = lirePrivilege($Bsession_id);
if ($privilege_base != 2)
	die("Vous n'avez pas les droits!");
  
$code_contrat = $_GET["code_contrat"];
$etape = $_GET["etape"];
$location = $_GET["location"];
$quantite = $_GET["quantite"];
$plein_prix = $_GET["plein_prix"];
$prix_reel = $_GET["prix_reel"];
$inclu = $_GET["inclu"];
	
//*************************************************************************
// requ&ecirc;te pour avoir tout les clients

$sql = "SELECT num_materiel, nom  
          FROM base_ref1materiels
		 WHERE base_ref1materiels.actif = 'O'
		 ORDER BY nom asc;";

$result = mysqli_query($GLOBALS["___mysqli_ston"], $sql) or die ("Ne peut lire dans la table ref1materiels".$sql);




//*****************************************************************************************************
// afficher les r&eacute;sultats *****************************************************************************
//*****************************************************************************************************
	   
	

if ($etape ==1)//enregistrer les donn&eacute;es
{
	$sql = "INSERT INTO base_loc_materiels
				    SET num_materiel = '$location',
					    code_contrat = '$code_contrat',
						quantite = '$quantite',
					    prix_plein = '$plein_prix',
					    prix_rabais = '$prix_reel',
						inclu = '$inclu',
					    actif = 'O',
					    date_modif = now(),
					    mis_a_jour = now();";
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $sql) or die("Probl&egrave;me de cr&eacute;ation de la location!<br>".$sql);
	GestionPoste(6,$type,$code_contrat,$code_client,0,$prix_reel,0,'O');					
	historique("../historique.txt","---ajout location: ".$location.", quantite: ".$quantite.", prix: ".$plein_prix.", rabais: ".$prix_reel.", inclu: ".$inclu."",$Bsession_id);

		
	print("L'enregistrement &agrave; &eacute;t&eacute; un succ&egrave;s.<br><br><br>");
		
}	
	
	
	
if (empty($etape))//entrer les donn&eacute;es
{	
	historique("../historique.txt","MENU AJOUT D'UNE LOCATION",$Bsession_id);
	print("<center><table cellspacing=0 cellpadding=0 width=600px border=0>");
	print("<tr><td bgcolor=white width=27px><img src=coin-haut-gauche.gif></td>");
	print("<td bgcolor=#636300><center><font face=Arial,Helvetica size=3 color=white><b>Ajout d'une location</b></td>");
	print("<td bgcolor=white width=27px><img src=coin-haut-droit.gif></td>");
	print("</td></tr></table>");


	//titre	   
	print("<table cellspacing=0 cellpadding=0 width=600px border=0>");	
	print("<tr><td bgcolor=#D6E4AC>");
	print("<b>Location</b>");
	print("</td><td bgcolor=#C8DB8D>");
	print("<b>Quantit&eacute;</b>");
	print("</td><td bgcolor=#D6E4AC>");	
	print("<b>Prix</b>");
	print("</td><td bgcolor=#C8DB8D>");
	print("<b><br>Escompte</b>");
	print("</td><td bgcolor=#D6E4AC>");
	print("<b><br>Inclu</b>");

	print("<form action=\"ajout-location.php?Bsession_id=".$_GET['Bsession_id']."\" method=\"get\">");
	print("<input type=\"hidden\" name=\"Bsession_id\" value=\"".$_GET['Bsession_id']."\">");
	print("<input type=\"hidden\" name=\"code_contrat\" value=\"".$code_contrat."\">");
	print("<input type=\"hidden\" name=\"etape\" value=\"1\">");	
	print("</td></tr><tr><td bgcolor=#D6E4AC valign=top>");
	
	//boite de selection	
	print("<select name=\"location\">");
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $sql);
	while ($row = mysqli_fetch_row($result))
	{
		for ($i = 0; $i < (($___mysqli_tmp = mysqli_num_fields($result)) ? $___mysqli_tmp : false); $i++)
		{
			print ("<option value=\"");
			printf ("%s", htmlspecialchars ($row[$i++]));
			print ("\">");
			printf ("%s", htmlspecialchars ($row[$i]));
			print ("</option>");
		}
	}
	print("</td><td bgcolor=#C8DB8D>");
	//plein prix
	print("<input type=\"text\" name=\"quantite\" align=\"top\" maxlength=\"10\" size=\"10\">");
	print("</td><td bgcolor=#D6E4AC>");
	//plein prix
	print("<input type=\"text\" name=\"plein_prix\" align=\"top\" maxlength=\"10\" size=\"10\">");
	print("</td><td bgcolor=#C8DB8D>");
	//prix r&eacute;el
	print("<input type=\"text\" name=\"prix_reel\" align=\"top\" maxlength=\"10\" size=\"10\">");
	print("</td><td bgcolor=#D6E4AC>");
	//inclu
	print("<select name=\"inclu\">
		<option selected value=\"N\">N</option>
		<option value=\"O\">O</option>
		<option value=\"N\">N</option>
	</select>");
	
	
	
	//bouton ajouter
	print("</td></tr><tr><td bgcolor=#E7EFCE colspan = 5><b><center><div align=right>");	
	print("<input type=\"submit\" value=\"Ajouter\"></form>");
	print("</td></tr>");
	
	// ajouter une location
	print("<tr><td bgcolor=#E7EFCE colspan=5><div align=right>");
	print("<form action=\"../reference/ref1materiels.php?Bsession_id=".$_GET['Bsession_id']."\" method=post>");
   			print("<input type=hidden name=Bsession_id value=$Bsession_id>");
   			print("<input type=hidden name=etape value=2>");
			print("<input type=hidden name=pargestion value=1>");
   			print("<input type=submit name=back value=\"Cr&eacute;er une nouvelle location\">");
    print("</form></td></tr></table>");
	
print("<center><table cellspacing=0 cellpadding=0 width=600px border=0>");
print("<tr><td bgcolor=white width=27px><img src=coin-bas-gauche.gif></td>");
print("<td bgcolor=#636300 width=746px></td>");
print("<td bgcolor=white width=27px><img src=coin-bas-droit.gif></td>");
print("</tr></table>");	
	
	
}


	
?>

</body>
</html>	
	
	
	
	
