<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
	
	
	
</head>
	
		<script src="/js/jquery-2.1.0.min.js"></script>
	<script src="/js/jquery.redirect.js"></script>
	<script type="text/javascript">   
function Redirect() 
{  
	

$.redirect('indexdevlecture.php', {'dnumdevis': document.getElementById("dnumdevis").value , 'didxcli': document.getElementById("didxcli").value });

	
} 
//document.write("You will be redirected to a new page in 5 seconds"); 
setTimeout('Redirect()', 500);   
</script>
	
	<style>
	
.attente{
	width:110px;
	height:110px;
	position:absolute;
	left:50%;
	top:50%;
	margin:-75px 0 0 -135px;
}
	</style>
	<img class="attente" src="spinner.gif">
	
	<?php 
	
		$debug=0;
 $myboxes = $_POST['DES'];
 $myboxes1 = $_POST['QTE'];  
 $myboxes2 = $_POST['PRIX']; 
 $myboxes3 = $_POST['UNITE'];  
 $myboxes4 = $_POST['ORDRELIGNE'];  
	 
	
	$NumeroIndexDevis=$_POST['dnum'];
	$NumeroIdxClient=$_POST['didxcli'];
	
	
	if ($debug==1)   { 
	print "Index devis ".$_POST['dnum']; //numeros idxdevis
	print "<br> Idx client ".$_POST['didxcli'];
	print "<br> date devis ".$_POST['ddate'];
	print "<br> Objet ".$_POST['object'];
	print "<br> chantier ".$_POST['dchantier'];
	print "<br> tva ".$_POST['dtva'];
	print "<br> banque ".$_POST['dbanque'];
	print "<br> Remarque ".$_POST['dremarque'];
		
		}
	
	
	//update tete
	
$DNUM=$_POST['devisnum'];
$DDATE=$_POST["ddate"];
$DOBJET=$_POST["object"];
$DIDXCLI=$_POST["didxcli"];
$DCHANTIER=$_POST["dchantier"];
$DTVA=$_POST["dtva"];
$DBANQUE=$_POST["dbanque"];
$DREMARQUE=$_POST["dremarque"];

		
					 
				
			        // on se connecte à notre base devis

$servername = "localhost:8889";
$username = "root";
$password = "root";
$dbname = "devis";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

 //$sql = "SELECT * FROM tete";
	
$sql = "UPDATE tete SET num='$DNUM', date='$DDATE', objet='$DOBJET', idxcli='$DIDXCLI', chantier='$DCHANTIER', tva='$DTVA', banque='$DBANQUE', remarque='$DREMARQUE',live='1' WHERE idx='$NumeroIndexDevis' ";
			 
//print $sql;
	if ($debug==1)   { print $sql;  print "<br>"; } 
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {

        //echo "Num: " . $row["dnum"]. " - Date: " . $row["ddate"]. " - Objet: " . $row["objet"]. " Idex" . $row["didxcli"]. "<br>";
		//echo "Soc: " . $row["societe"]. " - Nom: " . $row["nom1"]. "  " . $row["nom2"]. "<br>";
    } 
	
	
	
	} else {
      if ($debug==1)   { echo "0 results";} 
}

$conn->close();
			 
	
	
	
	
	// update corps
	
	if(empty($myboxes))
	 
	{
	 
	// echo("You didn't select any boxes.");
  }
  else
  {
    $i = count($myboxes);
   // echo("<br>You have $i box(es): <br>");
    for($j = 0; $j < $i; $j++)
    {
      //echo($myboxes[$j] . " ".$myboxes1[$j] ."  ".$myboxes2[$j] ." ".$myboxes3[$j] ."<br>");
    }
  }
	
	
	

		
$servername = "localhost:8889";
$username = "root";
$password = "root";
$dbname = "devis";

	// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
			 
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 	
		

			 
 $myboxes = $_POST['DES'];
 $myboxes1 = $_POST['QTE'];  
 $myboxes2 = $_POST['PRIX']; 
 $myboxes3 = $_POST['UNITE'];  
	
	if(empty($myboxes))
	 
	{
	 
	// echo("You didn't select any boxes.");
  }
  else
  {
    $ic = count($myboxes);
	$ordl=0;
	$jc=0;
    //echo("You have $ic box(es): <br>");
    for($jc = 0; $jc < $ic; $jc++)
    {
		if (floatval($myboxes1[$jc] ) > 0) {
		$myboxes[$jc]=str_replace("'","\'",$myboxes[$jc]);		
		$ordl++;
		//echo($myboxes[$j] . " ".$myboxes1[$j] ."  ".$myboxes2[$j] ." ".$myboxes3[$j] ."<br>");
		// $sql = "SELECT * FROM tete WHERE idx=1";
		//$sql = "UPDATE corps SET des='$myboxes[$j]', qt='$myboxes1[$j]', pu='$myboxes2[$j]', um='$myboxes3[$j]', numidxdevis='1'";
		$sql = "INSERT INTO `corps`(`des`, `qt`, `pu`, `um`, `numidxdevis`, `ordre`) VALUES ('$myboxes[$jc]','$myboxes1[$jc]','$myboxes2[$jc]','$myboxes3[$jc]','$NumeroIndexDevis','$ordl')";
		//$sql = "INSERT INTO corps des='$myboxes[$j]', qt='$myboxes1[$j]', pu='$myboxes2[$j]', um='$myboxes3[$j]', numidxdevis='1'";
		//echo "'<script type='text/javascript'>alert('enregistrement".$jc."')</script>";	 
		
if ($debug==1)   { print $sql;  print "<br>"; } 
$result = $conn->query($sql);
		    }
		
    }
		
    }

			 
if ($result->num_rows > 0) {
    // output data of each row
    while($drow = $result->fetch_assoc()) {
	//  
			
    } 
	
	} else {
      if ($debug==1)   { echo "0 results";} 
}
			 
$conn->close();		
	
	
	
?>
			<form method = "post" action = "indexdevlecture.php">	

			<input type="hidden" size="60" name="dnumdevis" id="dnumdevis" value="<?php echo $NumeroIndexDevis; ?>" > 
		
       		<input type="hidden" size="60" name="didxcli" id="didxcli" value="<?php echo $NumeroIdxClient; ?>" >
			
			<input type = "hidden" type = "submit" id = "update" value = "suivant"><br> 
	
		

	

<body>
</body>
</html>