<?php
include("include/data.php");
Init_boutique();
global $base, $MySQL_Host, $MySQL_User, $MySQL_Passw, $myart, $result, $NbLigne, $semaine, $limitesuivante, $limiteprecedente, $total, $page ;
// entete de la page

include 'menu/header.php';
/*
http://192.168.1.200/horius/ajout_plu.php?Num_entre=&ordre=1&num_plu=150&nom_plu=&nom_plu_compl=&num_cate_plu=1&num_type_plu=1&attribu_plu=&dlc_plu=&cpt_plu=70000000
*/

// Get ou Post existe ou pas ?
if (!isset($_GET['ordre'])) { 
		// Transmis en POST
		$ordre=$_POST['ordre'];
		if (isset($_POST['num_plu'])) { $num_plu=$_POST['num_plu']; }  else {$num_plu=''; }
		if (isset($_POST['nom_plu'])) { $nom_plu=$_POST['nom_plu']; } else {$nom_plu=''; }
		if (isset($_POST['nom_plu_compl'])) { $nom_plu_compl=$_POST['nom_plu_compl']; } else {$nom_plu_compl=''; }
		if (isset($_POST['num_cate_plu'])) { $num_cate_plu=$_POST['num_cate_plu']; } else {$num_cate_plu=''; }
		if (isset($_POST['num_type_plu'])) { $num_type_plu=$_POST['num_type_plu']; } else {$num_type_plu=''; }
		if (isset($_POST['attribu_plu'])) { $attribu_plu=$_POST['attribu_plu']; } else {$attribu_plu=''; }
		if (isset($_POST['dlc_plu'])) { $dlc_plu=$_POST['dlc_plu']; } else {$dlc_plu=''; }
		if (isset($_POST['cpt_plu'])) { $cpt_plu=$_POST['cpt_plu']; } else {$cpt_plu=''; }
		if (isset($_POST['str'])) { $str=$_POST['str']; } else {$str=''; }
		
		$valForm="POST" ;
} else {
		// Transmis en GET
		$ordre=$_GET['ordre'];
		if (isset($_GET['num_plu'])) { $num_plu=$_GET['num_plu']; }  else {$num_plu=''; }
		if (isset($_GET['nom_plu'])) { $nom_plu=$_GET['nom_plu']; } else {$nom_plu=''; }
		if (isset($_GET['nom_plu_compl'])) { $nom_plu_compl=$_GET['nom_plu_compl']; } else {$nom_plu_compl=''; }
		if (isset($_GET['num_cate_plu'])) { $num_cate_plu=$_GET['num_cate_plu']; } else {$num_cate_plu=''; }
		if (isset($_GET['num_type_plu'])) { $num_type_plu=$_GET['num_type_plu']; } else {$num_type_plu=''; }
		if (isset($_GET['attribu_plu'])) { $attribu_plu=$_GET['attribu_plu']; } else {$attribu_plu=''; }
		if (isset($_GET['dlc_plu'])) { $dlc_plu=$_GET['dlc_plu']; } else {$dlc_plu=''; }
		if (isset($_GET['cpt_plu'])) { $cpt_plu=$_GET['cpt_plu']; } else {$cpt_plu=''; }
		if (isset($_GET['str'])) { $str=$_GET['str']; } else {$str=''; }
		$valForm="GET" ;
}

echo "<br><center><b>Cr&eacute;ation d'un PLU ou article</b><br>" ;
if ($str==1){echo "<font color='#ff0000'>Cr&eacute;ation Impossible Num&eacute;ro existe d&eacute;j&agrave;</font>";}
echo "<center><HR size='1' width='500'></center>";
echo "<center><br>" ;
echo "<form name='Formplu' method='GET' action=''>";
echo "<input type='hidden' name='ordre' value='$ordre'/>";
echo "<table class='t-text' width='700' border='1' cellspacing='1' cellpadding='1'>";
echo "<tr>";

$sql  = "SELECT EXISTS (SELECT num_plu FROM plu WHERE Num_PLU = '".$num_plu."' AND `IdNumClient`=$IdNumClient)";
$req = mysqli_query($link, $sql);
$row = mysqli_fetch_row($req);
//echo "Requette : $sql | $row[0] <BR>" ;
$str = $row[0] ;

if ($str==1){
	$sql1 = "SELECT * FROM plu WHERE Num_PLU='$num_plu' AND `IdNumClient`=$IdNumClient";  
	$req1 = mysqli_query($link, $sql1);
	while ($row = mysqli_fetch_assoc($req1)) {
			$PLU_ex = $row["PLU"]; 
			$Plu_complement_ex = $row["Plu_complement"]; 
			}  
	echo "<th align='center' valign='middle'>Num&eacute;ro PLU : </th>";
	echo "<td colspan='0'><input name='num_plu' type='text' id='num_plu' accesskey='1' tabindex='1' value='$num_plu' size='10' maxlength='20' onChange='submit()'> &nbsp; <img src='images/Alert.png'> &nbsp;&nbsp;
	<font color='#ff0000'> $PLU_ex - $Plu_complement_ex</font>&nbsp;&nbsp;&nbsp;<img src='images/Alert.png'></td>";
} else {
	echo "<th align='center' valign='middle'>Num&eacute;ro PLU : </th>";
	echo "<td colspan='0'><input name='num_plu' type='text' id='num_plu' accesskey='1' tabindex='1' value='$num_plu' size='10' maxlength='20' onChange='submit()'>&nbsp;<img src='images/Apply.png'>&nbsp;&nbsp;&nbsp;
	<font color='green'>Libre &nbsp;&nbsp;&nbsp; </font><img src='images/Apply.png'></td>";
}


echo "</tr></form>";

echo "<form name='Formplu' method='GET' action='traitement_ajout_plu.php'>";
echo "<input type='hidden' name='str' value='$str'/>";
echo "<input type='hidden' name='Num_entre' value='$num_plu'/>";
echo "<input type='hidden' name='ordre' value='$ordre'/>";
echo "<tr>";
echo "<th align='center' valign='middle'>Nom PLU : </th>
      <td colspan='0'>
      <input name='nom_plu' type='text' id='nom_plu' accesskey='1' tabindex='1' value='$nom_plu' size='30' maxlength='30'>
	 		</td>";
echo "</tr>";


echo "<tr>";
echo "<th align='center' valign='middle'>Nom PLU compl&eacute;ment: </th>
      <td colspan='0'>
      <input name='nom_plu_compl' type='text' id='nom_plu_compl' accesskey='2' tabindex='2' value='$nom_plu_compl' size='30' maxlength='30'>
	 		</td>";
echo "</tr>";

echo "<th width='120' align='center' valign='middle'>Categorie :</th>
	  <th width='120' align='left' valign='middle'>";
echo "<select name='num_cate_plu' id='num_cate_plu' accesskey='3' tabindex='3'>";

$myart =new categorieplu;
$select = 'select * FROM categorieplu';
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $num_cate_plu=$myart->Num_CatPlu ;
  $categorie_plu=$myart->CategoriePlu ;

 if ($num_cate==$num_cate_plu) {
	echo "<option value='$num_cate_plu' selected='selected'>$categorie_plu</option>";
 } else {
	echo "<option value='$num_cate_plu'>$categorie_plu</option>";
}}

echo "</select>";

echo "</th></tr> ";
echo "<tr>";
echo "<th width='120' align='center' valign='middle'>Type : </th>
	  <th width='120' align='left' valign='middle'>";
echo "<select name='num_type_plu' id='num_type_plu' accesskey='4' tabindex='4'>";

$myart =new type_plu;
$select = 'select * FROM type_plu';
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $num_cate_plu=$myart->Num_TypePlu ;
  $categorie_plu=$myart->TypePlu ;

 if ($num_type==$num_cate_plu) {
	echo "<option value='$num_cate_plu' selected='selected'>$categorie_plu</option>";
 } else {
	echo "<option value='$num_cate_plu'>$categorie_plu</option>";
}}
echo "</select>";

echo "</th></tr> ";
echo "<tr>";
echo "<th align='center' valign='middle'>Code tra&#231;abilit&#233;e : </th>
      <td colspan='0'>
      <input name='attribu_plu' type='text' id='attribu_plu' accesskey='5' tabindex='5' value='$attribu_plu' size='10' maxlength='4'>
	 </td>";
echo "</tr>";
echo "<tr>";
echo "<th align='center' valign='middle'>D.L.C </th>
      <td colspan='0'>
	  <input name='dlc_plu' type='text' id='dlc_plu' accesskey='6' tabindex='6' value='$dlc_plu'  size='10' maxlength='4'> jours</td>";
echo "</tr>";

echo "<tr>";
echo "<th colspan='2' align='center' valign='middle'>
	  <input type='submit' name='ok' id='ok' value='Valider' accesskey='11' tabindex='11'>
	  &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
	  <input name='an' type='button' id='an' accesskey='12' tabindex='12' value='Retour' onClick='history.back()'></th>";
echo " </tr></div>";
echo "</table>";
echo "</form>";
echo "</center><br>" ;
//echo $sql1;

include 'menu/footer.php';
?>
