<?php
     
             // on se connecte à notre base pour planning

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

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
								
$sql = "SELECT * FROM planning where idx=".$_POST['Idpass']." ";
   // $sql = "SELECT * FROM planning where idx=1 ";
 //print "<br>".$sql;	
	 
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    
    $idxarray=0;
    // output data of each row
   // print "resultats";
    
   
    while($row = $result->fetch_assoc()) {
	    
$id=$row["idx"];
$titre=$row["Titre"];
$start=$row["Debut"];
$enddate=$row["Fin"];
$weekend=$row["WeekEnd"];
$lien=$row["Lien"];
$Description=$row["Description"];;
$backgroundColor=$row["CouleurFonds"];
$IDD=$row["IdxDevis"];;
$IDC=$row["IdxClient"];
          
        
             
        // on se connecte à notre base pour devis

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

// Create connection
$connT = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($connT->connect_error) {
    die("Connection failed: " . $connT->connect_error);
} 
	
				//	 $sql = "SELECT * FROM tete";
$sql = "SELECT * FROM tete WHERE idx=".$IDD." ";

	
$resultD = $connT->query($sql);

if ($resultD->num_rows > 0) {
    // output data of each row
    while($row = $resultD->fetch_assoc()) {
		
$NUM=$row["num"];
$titre=$row["num"];
$IDX=$row["idx"];
$DATE=$row["date"];
$OBJETT=$row["objet"];
//$Description=$OBJETT;
$IDXCLI=$row["idxcli"];
$MEMO=$row["memo"];
//$Description=$Description."<br>".$MEMO;
$ETATC=$row["etat"];		
$NumeroIdxClient=$row["idxcli"];;
$CHANTIER=$row["chantier"];
$CHANTIER = str_replace("'", ' ', $CHANTIER);
//$Description=$Description."<br>".$CHANTIER;
$TVA=$row["tva"];
$BANQUE=$row["banque"];
$REMARQUE=$row["remarque"];
$TYPECOM=$row["type"];
$datecommande=$row["commande"];
$MontantT=$row["montant"];
    } 
    
	
	} else {
   // echo "0 results";
}
        
  $connT->close();  
        
        
        // on se connecte à notre base pour client

$servername = "localhost:8889";
$username = "test";
$password = "test";
$dbname = "Clients";

// Create connection
$connC = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($connC->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$sql = "SELECT * FROM data WHERE id=".$IDC." ";
$resultC = $connC->query($sql);

if ($resultC->num_rows > 0) {
    // output data of each row
    while($row = $resultC->fetch_assoc()) {
		
$SOC=$row["societe"];
$NOM1=$row["nom1"];
$NOM2=$row["nom2"];
$NOM3=$row["nom3"];
$NOM4=$row["nom4"];
$NOM5=$row["nom5"];
$TITRE=$row["titre"];
$PUB=$row["pub"];
$AC1=$row["ac1"];
$AC2=$row["ac2"];
$O1=$row["o1"];
$O2=$row["o2"];
$O3=$row["o3"];
$MAIL=$row["mail"];
$GSM=$row["gsm"];
$TEL=$row["tel"];
$SIDXCLI =$row["id"];
//$Description=$Description."<br>".$MAIL." ".$GSM." ".$TEL;
    } 
    
	
	} else {
   // echo "0 results";
}

//$sql = "INSERT INTO data (societe,nom1,nom2,nom3,nom4,nom5,titre,ac1,ac2,o1,o2,o3,mail,tel,gsm,pub,jour)
//VALUES ('$SOC' , '$NOM1', '$NOM2', '$NOM3', '$NOM4', '$NOM5', '$TITRE', '$AC1', '$AC2', '$O1', '$O2', '$O3', '$MAIL', '$TEL', '$GSM', '$PUB', //'$today')";


$connC->close();
        
$directory = "../photos/".$NOM1."/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];}        
        
        


        	}
       	}
   $conn->close();  
   
   $LigneModalW= "<div style='float:left;'><form target='_blank' method='post' action='../texteditcomprepa.php' name='demande'><button class='btn btn-info' name='dnumdevis' id='liensubmit2' type='submit' value='". $IDX."'>Préparation chantier.</button></form></div>";
    $LigneModalW1= "<div style='float:right;'><form target='_blank' method='post' action='../texteditcom.php' name='demande'><button class='btn btn-info' name='dnumdevis' id='liensubmit2' type='submit' value='". $IDX."'>Vers commande.</button></form></div>";
    
    print "<br><div style='height:150px;width:150px;margin-right: 25px;margin-bottom: 25px;background-repeat: no-repeat;background-color:#dedddd;float:left;background-image:url(&quot".$firstFile."&quot);')></div>";
    print $OBJETT."<br><hr>".$CHANTIER."<br>".$MontantT."<br><hr> ".$MAIL." ".$GSM." ".$TEL."<hr>Du ".$_POST['StartPass']."  au  ".$_POST['EndPass']." ";
   print "<hr><div class='memo' contenteditable='true'>".$_POST['DescriptionPass']."</div><br>".$LigneModalW.$LigneModalW1." " ;
  

      
        ?>
    
