<!-- Button trigger modal -->

 <script src="/js/jquery-2.1.0.min.js"></script>


 <script type="text/javascript"> 
          
     	$(".swp").on('click',function(){
	//alert( $(this).attr('value').text());
     
     $(this).text($(this).attr('value'));    
     //alert( "ok");       
             //    var newstate = $(this).attr('value') ^ 1,
           // icon = newstate ? "minus" : "plus",
            //text = newstate ? "Cacher " : "Montrer ",
            //texticon=newstate ? "<i class='fa fa-angle-double-up'>&nbsp;</i>":"<i class='fa fa-angle-double-down'>&nbsp;</i>";
               
            

//        $(this).html( text +" détail "+texticon);

       // $(this).attr('state',newstate)
                 
             
                    
            });
           
          

             
         </script>
           
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalCenterTitle">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
      
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
    	
     
			
<?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);
} 
								
//$sql = "SELECT * FROM tete WHERE ( etat='0' OR etat='4' ) AND num like'%".$_POST['client']."%' ";
$sql = "SELECT * FROM tete WHERE ( etat='0' OR etat='4' ) AND num like'%".$_POST['client']."%' ";

            // print "<br>".$sql;	
	 
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
   // print "resultats";
    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"];
		
		// *********************    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 "<br>".$row1['societe']."  ".$row1['nom1'];
									$tempsoc=$row1['societe'];
									$tempnom1=$row1['nom1'];
									    } 
    
	
									} else {
										// echo "0 results";
									}




$conn1->close();
									
									
		
		
            
		$directory = "photos/".$tempnom1."/tmb/";
        $files = scandir ($directory);
        $firstFile = $directory . $files[2];// because [0] = "." [1] = ".." 
        $supported_file = array(
               
               'jpg',
               'png',
               'jpeg'
              
        );
 
        $ext = strtolower(pathinfo($firstFile, PATHINFO_EXTENSION));
        if (in_array($ext, $supported_file)) {
            
            $firstFile = $directory . $files[2];
            }else{
            $firstFile = $directory . $files[3];}
        
        
      print"  <div class='container'>";
        print"<div class='card'>";
        print"<div class='card-body'>";
        
           print"<div style='height:150px;width:150px;background-color:#dedddd;float:right;background-image:url(&quot;".$firstFile."&quot;);'>";
        print "<form method='post' action='picviewcar.php' name='demande'>";
        print "<button class='btn btn-dark fa fa-image rounded-0' name='dnumdevis' type='submit' value='". $tempnom1."'></button>";
        	print "</form>";
         
       // print "<button type='submit' class='swp btn btn-primary' data-toggle='modal' data-target='#exampleModalCenter' value='". $tempnom1."'>Launch demo modal</button>";
	
        print"</div>";
        
       print " <div style='float:left;width:80%;'>";
            print"    <h4>Devis : ". $NUM."</h4>";
            print"<h6 class='text-muted mb-2'>".$tempsoc."  ".$tempnom1." </h6>";
        print" <p>". $OBJET. " <br> ".$DATE."</p>";
         print "<div style='float:left;'><form method='post' action='indexlivelink.php' name='demande'>";
        print "<button class='btn btn-info' name='dnumdevis' id='liensubmit2' type='submit' value='". $IDX."'>Vers offre</button></form></div>";
     //      print "<div style='float:right;'><form method='post' action='texteditconcat.php' name='demande'>";
    //    print "<button class='btn btn-info' name='dnumdevis' id='liensubmit2' type='submit' value='". $IDX."'>Vers offre avec doc.</button></form></div>";
        
        print"</div>";
        print"</div>";
        print"<div class='card-footer'></div>";
        print"</div>";
        print"</div>";
        
        
    } 
    
	
	} else {
 //print "resultats 2";
    // Recherhce par nom
    $sql = "SELECT * FROM tete WHERE ( etat='0' OR etat='4' )  ";
	// $sql = "SELECT * FROM tete WHERE  etat>'0'  ";
	
    //print "<br>".$sql;	
	 
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    
    
 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"];
		
		// *********************    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 ( societe LIKE '%".$_POST['client']."%' OR nom1 LIKE '%".$_POST['client']."%') AND 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'];
                                    
       //nom afficher    
                                 	
		
            
		$directory = "photos/".$tempnom1."/tmb/";
        $files = scandir ($directory);
        $firstFile = $directory . $files[2];// because [0] = "." [1] = ".." 
        $supported_file = array(
               
               'jpg',
               'png',
               'jpeg'
              
        );
 
        $ext = strtolower(pathinfo($firstFile, PATHINFO_EXTENSION));
        if (in_array($ext, $supported_file)) {
            
            $firstFile = $directory . $files[2];
            }else{
            $firstFile = $directory . $files[3];}
        
        
      print"  <div class='container'>";
        print"<div class='card'>";
        print"<div class='card-body'>";
       
		
        
        print"<div style='height:150px;width:150px;background-color:#dedddd;float:right;background-image:url(&quot;".$firstFile."&quot;);'>";
        print "<form method='post' action='picviewcar.php' name='demande'>";
        print "<button class='btn btn-dark fa fa-image rounded-0' name='dnumdevis' type='submit' value='". $tempnom1."'></button>";
		print "</form>";
        print"</div>";
                                    
        print"    <div style='float:left;width:80%;'>";
            print"    <h4>Devis : ". $NUM."</h4>";
            print"<h6 class='text-muted mb-2'>".$tempsoc."  ".$tempnom1." </h6>";
        print" <p>". $OBJET. " <br> ".$DATE."</p>";
        print "<div style='float:left;'><form method='post' action='indexlivelink.php' name='demande'>";
        print "<button class='btn btn-info' name='dnumdevis' id='liensubmit2' type='submit' value='". $IDX."'>Vers offre</button></form></div>";
      //     print "<div style='float:right;'><form method='post' action='texteditconcat.php' name='demande'>";
    //    print "<button class='btn btn-info' name='dnumdevis' id='liensubmit2' type='submit' value='". $IDX."'>Vers offre avec doc.</button></form></div>";
        
                                    
        print"</div>";
        print"</div>";
        print"<div class='card-footer'></div>";
        print"</div>";
        print"</div>";
        
        
                                    
                                    
									    } 
    
	
									} else {
										// echo "0 results";
									}




$conn1->close();
									
									
		
		
            
		 

    } 
    
    
    
    
    
    
    }
    
}




$conn->close();
		

		?>	
			
     
     
          <form action="index.html">
               <input class="form-control" id="btst" type="submit" value="HOME" />
	            </form>
  
    </main>
  
  </body>
</html>