<?php
include("include/data.php");
Init_boutique();
global $link, $base, $MySQL_Host, $MySQL_User, $MySQL_Passw, $myart, $result, $NbLigne, $semaine, 
$limitesuivante, $limiteprecedente, $total, $page ;
// entete de la page
/*
http://192.168.1.200/horius/traitement_ajout_clients_base.php?last_num_entre=53
let_client=45+741
Nom_Client=RELIER+Jean+Loup
observations=
Adresse_1=Le+Bourg
Adresse_2=A+cot%C3%A9+Eglise
Adresse_3=Face+Cimeti%C3%A8re
Code_postal=46+240
Ville=USSEL
Telephone=05+65+20+00+39
Portable=06+61+33+49+46
Email=jean.loup.relier%40gmail.com
Ccpta=411RELIER
CodeTrsp=1
CodePaiement=1
num_cate_clt=5
Tarifs=3
ok=Valider
*/


if (!isset($_GET['ordre'])) { 
		// Transmis en POST
		$ordre=$_POST['ordre'];
		if (isset($_POST['Nom_Client'])) { $Nom_Client=$_POST['Nom_Client']; }  else {$Nom_Client=''; }
		if (isset($_POST['let_client'])) { $Ident_Client=$_POST['let_client']; }  else {$Ident_Client=''; }
		if (isset($_POST['Adresse_1'])) { $Adr_Client1=$_POST['Adresse_1']; } else {$Adr_Client1=''; }
		if (isset($_POST['Adresse_2'])) { $Adr_Client2=$_POST['Adresse_2']; }  else {$Adr_Client2=''; }
		if (isset($_POST['Adresse_3'])) { $Adr_Client3=$_POST['Adresse_3']; } else {$Adr_Client3=''; }
		if (isset($_POST['Telephone'])) { $Telephone=$_POST['Telephone']; }  else {$Telephone=''; }
		if (isset($_POST['Code_postal'])) { $Code_postal=$_POST['Code_postal']; } else {$Code_postal=''; }
		if (isset($_POST['Ville'])) { $Ville=$_POST['Ville']; }  else {$Ville=''; }
		if (isset($_POST['Portable'])) { $Portable=$_POST['Portable']; } else {$Portable=''; }
		if (isset($_POST['observations'])) { $observations=$_POST['observations']; }  else {$observations=''; }
		if (isset($_POST['Ccpta'])) { $Ccpta=$_POST['Ccpta']; }  else {$Ccpta=''; }
		if (isset($_POST['num_cate_clt'])) { $num_cate_clt=$_POST['num_cate_clt']; }  else {$num_cate_clt=''; }
		if (isset($_POST['Email'])) { $Email=$_POST['Email']; } else {$Email=''; }
		if (isset($_POST['Tarifs'])) { $Tarifs=$_POST['Tarifs']; }  else {$Tarifs=''; }
		if (isset($_POST['CodeTrsp'])) { $CodeTrsp=$_POST['CodeTrsp']; }  else {$CodeTrsp=''; }
		if (isset($_POST['CodePaiement'])) { $CodePaiement=$_POST['CodePaiement']; }  else {$CodePaiement=''; }
		$valForm="POST" ;
} else {
		// Transmis en GET
		$ordre=$_GET['ordre'];
		if (isset($_GET['Nom_Client'])) { $Nom_Client=$_GET['Nom_Client']; }  else {$Nom_Client=''; }
		if (isset($_GET['let_client'])) { $Ident_Client=$_GET['let_client']; }  else {$Ident_Client=''; }
		if (isset($_GET['Adresse_1'])) { $Adr_Client1=$_GET['Adresse_1']; } else {$Adr_Client1=''; }
		if (isset($_GET['Adresse_2'])) { $Adr_Client2=$_GET['Adresse_2']; }  else {$Adr_Client2=''; }
		if (isset($_GET['Adresse_3'])) { $Adr_Client3=$_GET['Adresse_3']; } else {$Adr_Client3=''; }
		if (isset($_GET['Telephone'])) { $Telephone=$_GET['Telephone']; }  else {$Telephone=''; }
		if (isset($_GET['Code_postal'])) { $Code_postal=$_GET['Code_postal']; } else {$Code_postal=''; }
		if (isset($_GET['Ville'])) { $Ville=$_GET['Ville']; }  else {$Ville=''; }
		if (isset($_GET['Portable'])) { $Portable=$_GET['Portable']; } else {$Portable=''; }
		if (isset($_GET['observations'])) { $observations=$_GET['observations']; }  else {$observations=''; }
		if (isset($_GET['Ccpta'])) { $Ccpta=$_GET['Ccpta']; }  else {$Ccpta=''; }
		if (isset($_GET['num_cate_clt'])) { $num_cate_clt=$_GET['num_cate_clt']; }  else {$num_cate_clt=''; }
		if (isset($_GET['Email'])) { $Email=$_GET['Email']; } else {$Email=''; }
		if (isset($_GET['Tarifs'])) { $Tarifs=$_GET['Tarifs']; }  else {$Tarifs=''; }
		if (isset($_GET['CodeTrsp'])) { $CodeTrsp=$_GET['CodeTrsp']; }  else {$CodeTrsp=''; }
		if (isset($_GET['CodePaiement'])) { $CodePaiement=$_GET['CodePaiement']; }  else {$CodePaiement=''; }
		$valForm="GET" ;
}

$Nom_Client = htmlspecialchars($Nom_Client, ENT_QUOTES);
$Adr_Client1 = htmlspecialchars($Adr_Client1, ENT_QUOTES);
$Adr_Client2 = htmlspecialchars($Adr_Client2, ENT_QUOTES);
$Adr_Client3 = htmlspecialchars($Adr_Client3, ENT_QUOTES);
$observations = htmlspecialchars($observations, ENT_QUOTES);


$last_num_entre = 0 ;
$sql = 'SELECT max(Num_Client_Base) FROM clients_base';
$req = mysqli_query($link, $sql); 
$row = mysqli_fetch_row($req);
$last_num_entre = $row[0];
$last_num_entre = $last_num_entre + 1 ;


if (empty($Ident_Client)) {
	$str = 1 ;	} 
else {
	$sql  = "SELECT EXISTS (SELECT Num_Client_Base FROM clients_base WHERE Num_Client = '".$Ident_Client."')";
$req = mysqli_query($link, $sql);
$row = mysqli_fetch_row($req);
//echo "Requette : $sql | $row[0] <BR>" ;
$str = $row[0] ;
}



switch ($str) {
    case 0:

echo " Num Clt : ".$last_num_entre." | ident Clt : ".$Ident_Client."<br> 
nom clt : ".$Nom_Client."<br> adr 1 :".$Adr_Client1."<br>
adr 2 : ".$Adr_Client2."<br> adr 3 : ".$Adr_Client3."<br>
CodePostal : ".$Code_postal."<br> Ville : ".$Ville."<br>
tel : ".$Telephone."<br> Port : ".$Portable."<br> 
num_cate_clt :".$num_cate_clt."<br>Ccpta : ".$Ccpta."<br> 
observations : ".$observations."<br> Code Tarifs : ".$Tarifs."
<br> Email : ".$Email."<br>" ;

$sql = "INSERT INTO clients_base VALUES (
'".$last_num_entre."',
'".$IdNumClient."',   
'".$Ident_Client."', 
'".$Nom_Client."', 
'".$Adr_Client1."', 
'".$Adr_Client2."', 
'".$Adr_Client3."', 
'".$Code_postal."', 
'".$Ville."', 
'".$Telephone."', 
'".$Portable."', 
'".$Email."', 
'', 
'".$num_cate_clt."', 
'".$Tarifs."',
'".$CodeTrsp ."', 
'".$CodePaiement."', 
'".$Ccpta."',  
'".$observations."')";


echo $sql;
 
$res = mysqli_query($link, $sql);

echo "<br>Requette : ".$res ;

Header("Location: clients_bases.php?limite=0");

  break;   

case 1:
include 'menu/header.php';
echo "<center><b>Ajout Clients<br></b></center>" ;
echo "<center><b>Saisie Incorecte<br></b></center>" ;

echo "<center><HR size='1' width='500'></center>";
echo "<center>";
echo "<form name='FormClient' method='post' action='traitement_ajout_clients_base.php'>";
echo "<input type='hidden' name='last_num_entre' value='$last_num_entre'/>";
echo "<table class='t-text' width='600' border='2' cellspacing='2' cellpadding='2'>";
echo "<tr>";
echo "<th width='120' align='center' valign='middle' scope='col'><font color=#ff0000>Ident :</font> </th>
      <th width='117' scope='col'>
	  <input name='let_client' type='text' id='let_client' accesskey='2' tabindex='2' value='' size='20' maxlength='10'></th>";
echo "<th width='120' align='center' valign='middle' scope='col'>Num base</th>
	  <th width='120' scope='col'>";
echo "$last_num_entre</th> ";
echo "</tr>";
echo "<tr>";
echo "<th align='center' valign='middle' scope='row'>Nom </th>
      <td colspan='0'>
      <input name='Nom_Client' type='text' id='Nom_Client' accesskey='3' tabindex='3' value='$Nom_Client' size='30' maxlength='30'>
	<td rowspan='4' colspan='3'>
	<center> Observations :
	<TEXTAREA name='observations' id='observations' accesskey='15' tabindex='15' value='$observations' rows=6 COLS=25>$observations</TEXTAREA></td>
        </center>
      </td>";
echo "</tr>";
echo "<tr>";
echo "<th align='center' valign='middle' scope='row'>Adresse </th>
      <td colspan='0'>
	  <input name='Adresse_1' type='text' id='Adresse_1' accesskey='4' tabindex='4' value='$Adr_Client1' size='30' maxlength='30'></td>";
echo "</tr>";
echo "<tr>";
echo "<th align='center' valign='middle' scope='row'>Adresse</th>
      <td colspan='0'>
	  <input name='Adresse_2' type='text' id='Adresse_2' accesskey='5' tabindex='5' value='$Adr_Client2'  size='30' maxlength='30'></td>";
echo "</tr>";
echo "<tr>";
echo "<th align='center' valign='middle' scope='row'>Adresse</th>
      <td colspan='0'>
	  <input name='Adresse_3' type='text' id='Adresse_3' accesskey='6' tabindex='6' value='$Adr_Client3'  size='30' maxlength='30'></td>";
echo "</tr>";
echo "<tr>";
echo "<th align='center' valign='middle' scope='row'>Code Postal</th>
    <td Colspan='3'><input name='Code_postal' type='text' id='Code_postal' accesskey='7' tabindex='7' value='$Code_postal' size='6'>
	Ville <input type='text' name='Ville' id='Ville' accesskey='8' tabindex='8' value='$Ville' size='40'></td>";
echo "</tr>";
echo "<tr>";
echo "<th align='center' valign='middle' scope='row'>T&eacute;l&eacute;phone</th>
      <td><input name='Telephone' type='text' id='Telephone' accesskey='9' tabindex='9' value='$Telephone'></td>";
echo "<th align='center' valign='middle' >Portable</th>
      <td><input type='text' name='Portable' id='Portable' accesskey='10' tabindex='10' value='$Portable'></td>";
echo "</tr>";
echo "</tr>";
echo "<th align='center' valign='middle' scope='row'>Email</th>
    <td><input name='Email' type='text' id='Email' accesskey='11' tabindex='11' value='$Email' size='30'>";
echo "</td>";
echo "<th align='center' valign='middle' scope='row'>Compte Cpta</th>
    	<td Colspan='2'><input name='Ccpta' type='text' id='Ccpta' accesskey='12' tabindex='12' value='$Ccpta'>";
echo "</td></tr>";
echo "<tr>";
echo "<th align='center' valign='middle' scope='row'>Code Transport</th>";
echo "<td><select style=' width: 200px;' name='CodeTrsp' id='CodeTrsp' accesskey='13' tabindex='13'>";
$sql = 'SELECT * FROM categorie_trsp';
$sql.=" WHERE `IdNumClient`='".$IdNumClient."'";  
$req = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($req)) {
  $num_li_trsp = $row["Num_Ligne_Cate_Trsp"];
  $Code_Trsp = $row["Code_Trsp"];
//  echo "$num_li_bl | $num_bl_base <br>" ;

  echo "<option value='$num_li_trsp'>$num_li_trsp | $Code_Trsp</option>";
}

echo "</select></td>";	

echo "<th align='center' valign='middle' >Code Paiement</th>";
echo "<td><select style=' width: 200px;' name='CodePaiement' id='CodePaiement' accesskey='14' tabindex='14'>";

$sql1 = 'SELECT * FROM categorie_paiement';
$sql1.=" WHERE `IdNumClient`='".$IdNumClient."'";  
$req1 = mysqli_query($link, $sql1);
while ($row = mysqli_fetch_assoc($req1)) {
  $num_li_paiement = $row["Num_Ligne_Cate_Paiement"];
  $Code_paiement = $row["Code_Paiement"];
//  echo "$num_li_bl | $num_bl_base <br>" ;

  echo "<option value='$num_li_paiement'>$num_li_paiement | $Code_paiement</option>";
}

echo "</select></td>";	
echo "</tr>";

echo "<tr>";
echo "<th align='center' valign='middle' scope='row'>Cat&eacute;gorie Client</th>";
echo "<td><select style=' width: 200px;' name='num_cate_clt' id='num_cate_clt' accesskey='15' tabindex='15'>";

$sql = 'SELECT * FROM categorie_Clients';
$sql.=" WHERE `IdNumClient`='".$IdNumClient."'";  
$req = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($req)) {
  $num_cate_clt = $row["num_cate_clt"];
  $cate_client = $row["categorie_clt"];
//  echo "$num_li_bl | $num_bl_base <br>" ;

  echo "<option value='$num_cate_clt'>$num_cate_clt | $cate_client</option>";
}

echo "</select></td>";	
echo "<th align='center' valign='middle' scope='row'>Code Tarifs</th>
    	<td Colspan='2'>";
//<input name='Tarifs' type='text' id='Tarifs' accesskey='12' tabindex='12' value='$Tarifs' size='10'>
echo "<select style=' width: 150px;' name='Tarifs' id='Tarifs' accesskey='16' tabindex='16'>";
$myart =new categorie_tarif;
$select = 'select * FROM categorie_tarif';
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $num_cate_plu_intran=$myart->Num_Code_Tarif ;
  $categorie_plu_intran=$myart->Code_Tarif ;
  echo "<option value='$num_cate_plu_intran'>$num_cate_plu_intran | $categorie_plu_intran</option>";
}

echo "</select>";	
echo "</td></tr>";



echo "<tr>";
echo "<th colspan='2' align='center' valign='middle' scope='row'>
	  <input type='submit' name='ok' id='ok' value='Valider' accesskey='17' tabindex='17'></th>";
echo "<td colspan='2' align='center' valign='middle'>
	  <input name='an' type='button' id='an' accesskey='18' tabindex='18' value='Retour' onClick='history.back()'></td>";
echo " </tr></div>";
echo "</table>";
echo "</form>";

include 'menu/footer.php';
 break;  
}

?>
