<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Liste des commandes</title>
	
    <link rel="stylesheet" href="stylecli.css" media="all" />
  </head>
  <body >
    
    </header>
    <main>
      <div id="details" class="clearfix">
        <div id="client">
          <div class="to"><h1><br>
          Liste des commandes<br></h1></div>
          <h2 class="name"></h2>
          <div class="address"></div>
          <div class="email"></div>
        </div>
        <div id="invoice">
          <h1></h1>
          <div class="date"></div>
          <div class="date"></div>
        </div>
      </div>
		
		
      <table border="0" cellspacing="0" cellpadding="0">
        <thead>
          <tr>
			  
			              <th class="no">####</th>
			  
			  <form method = "post" action = "<?php $_PHP_SELF ?>">
              <th class="desc">
				
				
-Tous
  <input type="radio" checked="checked" name="radio" value="0">
  <br>

-En commande
  <input type="radio" name="radio" value="1">
  <br>

-Facuration
  <input type="radio" name="radio" value="2">
  <br>

-Clôturé
  <input type="radio" name="radio" value="3">
  
<br><br><br>
				
					<?php
				$descradio = array(0 => 'Tous',1 => 'En commande', 2 => 'Facturation', 3 => 'Clôturé');
									 
					   
				 if(isset($_POST['radio'])) {	
	 
					 $positionradio=intval($_POST['radio']);
					 
	print" <h3>DESCRIPTION ETAT COMMANDE : </h3><h1><span>" .$descradio[$positionradio]."</h1></span> <br>";
	
				 
				 
				 } else {
										
									
print"DESCRIPTION<br>";
	
		 }
				?>
				
				
	
	</th>
			  
			  
			  
          
            <th class="desc">
				
		
-Tous
  <input type="radio" checked="checked" name="radiot" value="0">
  <br>				
-Couvreurs
  <input type="radio"  name="radiot" value="1">
  <br>

-Toiture plate
  <input type="radio" name="radiot" value="2">
  <br>

-Les deux
  <input type="radio" name="radiot" value="3">
  <br>

-Autre
  <input type="radio" name="radiot" value="4">
  
<br><br>
			 
					<?php
				$descradiot = array(1 => 'Couvreur',2 => 'Toitplat', 3 => 'LesDeux', 4 => 'Autre',0=>'Tous');
									 
					   
				 if(isset($_POST['radiot'])) {	
	 
					 $positionradiot=intval($_POST['radiot']);
					 
					print"<h3 >DESCRIPTION TYPE TRAVAIL :</h3> <h1>" .$descradiot[$positionradiot]."</h1> <br>";
	
				 
				 
				 } else {
										
									
					 print"DESCRIPTION<br>";
	
		 }
				?>
				
				
	
	</th>
            <th class="unit"><?php
				 if(isset($_POST['update'])) {	
	 
	print"<input id='liensubmit2' name = 'update' type = 'submit' value = 'Go'><br>";
	 } else {
										
									
print"<input id='liensubmit2' name = 'update' type = 'submit' value = 'Go'><br>";
	// print "<br>".$sql;	
		 }
				?></form> </th>
       
          </tr>
        </thead>
		  
		  
        <tbody>
			
<?php
			
       


// on se connecte à notre base pour 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);
} 

	 if(isset($_POST['update'])) {
		 $sql = "SELECT * FROM tete WHERE ";
		 
		 
	 		if($descradiot[$positionradiot]=='Tous') {	
				$sqltype = " type>'' " ;
				 } else {
 				$sqltype = " type='".$descradiot[$positionradiot]."' " ;
				}

		 	if($positionradio==0) {	
				$sqletat = " etat>0 AND ";
				 } else {
 				$sqletat = " etat='".$positionradio."' AND ";
				}

		 $sql=$sql.$sqletat.$sqltype;
		 
		// print $sql.'<br>';
	 } else {
										
									
$sql = "SELECT * FROM tete WHERE etat>'0'";
	// print "<br>".$sql;	
		 }

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
				
		$NUM=$row["num"];
$IDX=$row["idx"];
$DATE=$row["date"];
$OBJET=$row["objet"];
$IDXCLI=$row["idxcli"];
$MEMO=$row["memo"];
$NumeroIdxClient=$row["idxcli"];;
$CHANTIER=$row["chantier"];
$TVA=$row["tva"];
$BANQUE=$row["banque"];
$REMARQUE=$row["remarque"];
$ETATC=$row["etat"];
$MONTANTHTVA=$row["montant"];
		
		// *********************    connection clients *************************
		
								$servername1 = "localhost:8889";
								$username1 = "root";
								$password1 = "root";
								$dbname1 = "Clients";

								// Create connection
								$conn1 = new mysqli($servername1, $username1, $password1, $dbname1);
								// Check connection
								if ($conn1->connect_error) {
								die("Connection failed: " . $conn1->connect_error);
								} 

			
								$sql1 = "SELECT * FROM data WHERE id=".$NumeroIdxClient." ";
								//print "<br>".$sql1;	
		 
								$result1 = $conn1->query($sql1);
		
								if ($result1->num_rows > 0) {
    							// output data of each row
								while($row1 = $result1->fetch_assoc()) {
								//print "echo <br>".$row1['societe']."  ".$row1['nom1'];
									$tempsoc=$row1['societe'];
									$tempnom1=$row1['nom1'];
                                    $tempnom2=$row1['tel'];
                                    $tempnom3=$row1['gsm'];
									    } 
    
	
									} else {
										// echo "0 results";
									}




$conn1->close();
									
									
		
		
            
		    print "<tr>";
            print " <td class='no'>". $NUM."</td>";
           // print " <td class='desc'><h3>".$tempsoc."  ".$tempnom1." ".$row1['nom1']."<br> ". $OBJET. " du ".$DATE."</h3>";
		    print "<form method='post' action='texteditcom.php' name='demande'>";
		    print "<td class='desc'><button name='dnumdevis' id='liensubmit' type='submit' value='". $IDX."'>".$tempsoc."  ".$tempnom1." <p style='font-size:14px'> ".$tempnom2." ".$tempnom3." ".$row1['nom1']."<br> ". $OBJET. " </p> <p style='font-size:12px'>".$DATE."</p></button>";print "</form>";
		
		print"<h4>";


		
		    print " <th class='desc'> Offre : ".$MONTANTHTVA." <p>";
		
			 
			print"</p>  ";
            
            // *********************    connection facture *************************
		
								$servername1 = "localhost:8889";
								$username1 = "root";
								$password1 = "root";
								$dbname1 = "facture";

								// Create connection
								$conn2 = new mysqli($servername1, $username1, $password1, $dbname1);
								// Check connection
								if ($conn2->connect_error) {
								die("Connection failed: " . $conn2->connect_error);
								} 

			
								$sql2 = "SELECT * FROM tete WHERE idxdevis=".$IDX." ";
                               // $sql2 = "SELECT * FROM tete WHERE idxdevis='72'";
        
								//print "<br>".$sql2;	
            
            
                                
		 
								$result2 = $conn2->query($sql2);
		
								if ($result2->num_rows > 0) {
    							// output data of each row
								while($row2 = $result2->fetch_assoc()) {
								//print "echo <br>".$row1['societe']."  ".$row1['nom1'];
									//print "Facturé : ".$row2['montant'];
                                    
                                    
                                    print "<form method='post' action='texteditfac.php' name='demande'> ";
            print "<button name='dnumdevis' id='liensubmit3' type='submit' value='". $row2['idx']."'>Facturé ".$row2['montant']."</button>";
		
			print "</form>";
                                    
                                    
                                    
                                    
                                    
									//print "<br>";
									    } 
    
	
									} else {
										// echo "0 results";
									}




$conn2->close();
									    
        
        
        //$TYPEDISPLAY=$row["type"];
		print "<br>". $row["type"];
            
            
           print"   </th>";
	//print "<form method='post' action='clientaf2.php' name='demande'>";
		    print "<form method='post' action='texteditcom.php' name='demande'> <p>";
			
		
            print "<td class='unit'><button name='dnumdevis' id='liensubmit2' type='submit' value='". $IDX."'>Offre</button></td>";
		
			print "</form>";
        
            print "</tr>";

    } 
    
	
	} else {
   // echo "0 results";
}




$conn->close();
		

		?>	
			
     
        </tbody>
        
      </table>
     
      <div id="notices">
        <div><br>&nbsp;<br> </div>
        <div class="notice"><br>&nbsp; ---<br></div>
      </div>
    </main>
  
  </body>
</html>