<!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>
	
	
	<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=1;
    $myboxesOffre = $_POST['descr'];
    $myboxesOffre1 = $_POST['qte'];
    $myboxesOffre2 = $_POST['pu'];
    $myboxesOffre3 = $_POST['unites'];
    $myboxesOffre4 = $_POST['didxcli'];
    $myboxesOffre5 = $_POST['ln'];
   
    
$myboxesSol = $_POST['SOLDATA'];  
$myboxesGraph = $_POST['GRAPH'];  
$NumeroIndexDevis=$myboxesSol[11]; 
$NumeroIdxClient= $_POST['didxcli'];  
    
	if ($debug==1)   { 
	if(empty($myboxesSol))
	 
	{
	 
	 // echo("You didn't select any boxes.");
  }
  else
  {
    $i = count($myboxesSol);
    echo("<br>You have vous avez $i box(es): <br>");
    for($j = 0; $j < $i; $j++)
    {
      echo($myboxesSol[$j] ."<br>");
    }
      
        $i = count($myboxesOffre);
    echo("<br>Devis vous avez $i box(es): <br>");
    for($j = 0; $j < $i; $j++)
    {
      echo($myboxesOffre[$j] ."<br>");
    }
  }
	
	if(empty($myboxesGraph))
	 
	{
	 
	 // echo("You didn't select any boxes.");
  }
  else
  {
    $i = count($myboxesGraph);
    echo("<br>You have $i box(es): <br>");
    for($j = 0; $j < $i; $j++)
    {
      echo($myboxesGraph[$j] ."<br>");
    }
  }
	
	} 
	
			        // on se connecte à notre base solaire

$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 = "UPDATE solaire SET panneaux='$myboxesSol[1]', marquepanneaux='$myboxesSol[2]',  puissance='$myboxesSol[3]', marqueonduleur='$myboxesSol[4]',MO='$myboxesSol[5]',cable='$myboxesSol[6]',typetoit='$myboxesSol[7]',pente='$myboxesSol[8]', azimut='$myboxesSol[9]',coef='$myboxesSol[10]',pertepanneaux='$myboxesSol[12]',difficulte='$myboxesSol[13]', compteur='$myboxesSol[14]',prixpanneau='$myboxesSol[15]',prixonduleur='$myboxesSol[16]',reception='$myboxesSol[17]',r1=$myboxesGraph[1],r2=$myboxesGraph[2],r3=$myboxesGraph[3],r4=$myboxesGraph[4],r5=$myboxesGraph[5],r6=$myboxesGraph[6],r7=$myboxesGraph[7],r8=$myboxesGraph[8],r9=$myboxesGraph[9],r10=$myboxesGraph[10],r11=$myboxesGraph[11],r12=$myboxesGraph[12],r13=$myboxesGraph[13],r14=$myboxesGraph[14],r15=$myboxesGraph[15],r16=$myboxesGraph[16],r17=$myboxesGraph[17],r18=$myboxesGraph[18],r19=$myboxesGraph[19],r20=$myboxesGraph[20],r21=$myboxesGraph[21],r22=$myboxesGraph[22],r23=$myboxesGraph[23],r24=$myboxesGraph[24] WHERE idxdevis='$NumeroIndexDevis'  ";
    

	//$sql = "UPDATE solaire SET num='$DDNUM', date='$DDATE', objet='$DOBJET', idxcli='$DIDXCLI', chantier='$DCHANTIER', tva='$DTVA', banque='$DBANQUE',memo='$MEMO', live='1',montant='$MONTANTHTVA',etat='$ETATC' WHERE idx='$NumeroIndexDevis' ";
		 
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";} 
}

    
  
    
    // ********* Efface les lignes **************
    
     $sql = "DELETE FROM corps WHERE numidxdevis='$NumeroIndexDevis' ";
		   if ($debug==1)   { print $sql;  print "<br>"; } 
	  $result = $conn->query($sql);
    //************************************
    
    	   // ********Inser les lignes ******************************* 
	  
	    $ic = count($myboxesOffre);
	 
    for($jc = 0; $jc < $ic; $jc++)
    {
echo "<br>+".$myboxesOffre3[$jc]."  ".floatval($myboxesOffre2[$jc]."<br>" );
		
		if (floatval($myboxesOffre2[$jc] ) <> 0) {

			$myboxesOffre[$jc]=str_replace("'","\'",$myboxesOffre[$jc]);		
	
		//echo($myboxes[$j] . " ".$myboxes1[$j] ."  ".$myboxes2[$j] ." ".$myboxes3[$j] ."<br>");
		// $sql = "SELECT * FROM tete WHERE idx=1";
	
		
		$sql = "INSERT INTO `corps`(`des`, `qt`, `pu`, `um`, `numidxdevis`, `ordre`) VALUES ('$myboxesOffre[$jc]','$myboxesOffre1[$jc]','$myboxesOffre2[$jc]','$myboxesOffre3[$jc]','$NumeroIndexDevis','$myboxesOffre5[$jc]')";
			
		if ($debug==1)   { print "+" . $sql;  print "<br>"; } 
  $result = $conn->query($sql);
			
			
			
		    }
		
    }
    


    

    $conn->close();
	
?>
	
	<script type="text/javascript">   
function Redirect() {  
	
 
   // alert("redirection");

 
$.redirect('texteditsol.php', {'dnumdevis': <?php echo $NumeroIndexDevis;?> , 'didxcli':<?php echo $NumeroIdxClient;?> });

} 


	

//document.write("You will be redirected to a new page in 5 seconds"); 
setTimeout('Redirect()', 600);   
</script>
	

<body>
</body>
</html>