<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" type="image/png" href="favicon.png">
    
	<link rel="stylesheet" href="w3a.css">
	<link rel="stylesheet" type="text/css" href="styletable.css">
	
	
    
	<script src="./js/jquery-2.1.0.min.js"></script>
	<script src="./js/bootstrap.min.js"></script>
	<script src="./js/blocs.min.js"></script>
	<script src="./js/lazysizes.min.js" defer></script>
    <title>Modifier prospect</title>

    
</head>
<body>
	
	
	<h2></h2> 

	
			
<?php
				
				 if(isset($_POST['update'])) {

					 
					 // on se connecte à notre base

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

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

$OLDNOM1=$_POST['old'];
$SOC=$_POST['SOC'];
$NOM1=$_POST["nom1"];
$NOM2=$_POST["nom2"];
$NOM3=$_POST["nom3"];
$NOM4=$_POST["nom4"];
$NOM5=$_POST["nom5"];
$TITRE=$_POST["titre"];
$PUB=$_POST["pub"];
$AC1=$_POST["ac1"];
$AC2=$_POST["ac2"];
$O1=$_POST["o1"];
$O2=$_POST["o2"];
$O3=$_POST["o3"];
$MAIL=$_POST["mail"];
$GSM=$_POST["gsm"];
$TEL=$_POST["tel"];
$SIDXCLI=$_POST["sidxcli"];		
$FAC1=$_POST['fac1'];
$FAC2=$_POST['fac2'];
$FAC3=$_POST['fac3'];
$FAC4=$_POST['fac4'];
$FAC5=$_POST['fac5'];
                     
                     
					 
//$sql = "SELECT * FROM data";
//$sql = "SELECT * FROM data WHERE id=3";
//$sql = "UPDATE 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') WHERE id=3";
//$sql = "UPDATE data SET societe='YEAAAAHHH'  WHERE id=3";
//$sql = "UPDATE\n". "  `data`\n"." SET\n". " societe = \'$SOC\'\n". "WHERE\n". " id = 3";
                     
if (($AC1==""))
{ $AC1=$NOM2;$AC2=$NOM3;}
                     
                     $SOC=str_replace("'","\'",$SOC);
                     $NOM1=str_replace("'","\'",$NOM1);
					 $NOM2=str_replace("'","\'",$NOM2);
					 $NOM3=str_replace("'","\'",$NOM3);
					 $NOM4=str_replace("'","\'",$NOM4);
					 $NOM5=str_replace("'","\'",$NOM5);
					 $AC1=str_replace("'","\'",$AC1);
				     $AC2=str_replace("'","\'",$AC2);
                     
					// $O1=str_replace('"','\"',$O1);
				//	 $O2=str_replace('"','\"',$O2);
				//	 $O3=str_replace('"','\"',$O3);
                     
                    
                     
                    
                     
                     $O1=str_replace("'","\'",$O1);
					 $O2=str_replace("'","\'",$O2);
					 $O3=str_replace("'","\'",$O3);
                     
                  //   $PUB=str_replace("\'","'",$PUB);
				//	 $PUB=str_replace("'","\'",$PUB);
                     
					 $FAC1=str_replace("'","\'",$FAC1);
					 $FAC2=str_replace("'","\'",$FAC2);
					 $FAC3=str_replace("'","\'",$FAC3);
					 $FAC4=str_replace("'","\'",$FAC4);
					 $FAC5=str_replace("'","\'",$FAC5);
				//	 $MAIL=str_replace("@","\@",$MAIL);
//$TEL=str_replace("@","\@",$TEL);
//$GSM=str_replace("@","\@",$GSM);
					 
$sql = "UPDATE data SET societe='$SOC', nom1='$NOM1', nom2='$NOM2', nom3='$NOM3', nom4='$NOM4', nom5='$NOM5', titre='$TITRE',  ac1='$AC1', ac2='$AC2', o1='$O1', o2='$O2', o3='$O3', mail='$MAIL', tel='$TEL', gsm='$GSM', pub='$PUB', fac1='$FAC1', fac2='$FAC2', fac3='$FAC3', fac4='$FAC4', fac5='$FAC5' WHERE id=".$SIDXCLI." ";
//print $sql;
		
$result = $conn->query($sql);

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

        //print "Soc: " . $row["societe"]. " - Nom: " . $row["nom1"]. " - idx: " . $row["id"]. " " . $row["fac5"]. "<br>";
		//echo "Soc: " . $row["societe"]. " - Nom: " . $row["nom1"]. "  " . $row["nom2"]. "<br>";
    } 
    
	
	} else {
   // echo "0 resultat. Erreur de base de données!";
}

//$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')";


$conn->close();
					
                 
				if ($OLDNOM1<>$NOM1) {
                    $olddirectory = "photos/".$OLDNOM1."/"; 
                    $directory = "photos/".$NOM1."/"; 
                    // Renames the directory
                  // print $olddirectory." new>> ".$directory;
                    rename($olddirectory,  $directory);
                    
                    
               } else {
   // pas de changement de nom de directory
                      $olddirectory = "photos/Hugét Jean-Louis/"; 
                    $directory = "photos/Hugétt Jean-Louis/"; 
                    // Renames the directory
                    rename($olddirectory,  $directory);
                    }      
                     
				   	 
					 
					 
					 }else {
                   
$SOC=" ";
$NOM1=" ";

$NOM2=" ";
$NOM3=" ";
$NOM4=" ";
$NOM5=" ";
$TITRE=" ";
$PUB=" ";
$AC1=" ";
$AC2=" ";
$O1=" ";
$O2=" ";
$O3=" ";
$MAIL=" ";
$GSM=" ";
$TEL=" ";
$SIDXCLI=" ";
$FAC1=" ";
$FAC2=" ";
$FAC3=" ";
$FAC4=" ";

// on se connecte à notre base

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

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

$SIDXCLI = htmlentities($_POST['idxcli']);
	// print "dans la boite<br>";

    
	

					 $sql = "SELECT * FROM data";
//$sql = "SELECT * FROM data WHERE id=3";
$sql = "SELECT * FROM data WHERE id=".intval($_POST['idxcli'])." ";
//print $sql;					 
					// $sql = "UPDATE\n". "  `data`\n"." SET\n". " societe = \'testoooyeahhh\'\n". "WHERE\n". " id = 3";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
		
$SOC=$row["societe"];
$NOM1=$row["nom1"];
$OLDNOM1=$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"];
$FAC1=$row["fac1"];
$FAC2=$row["fac2"];
$FAC3=$row["fac3"];
$FAC4=$row["fac4"];
$FAC5=$row["fac5"];
		
         // print "first ".$OLDNOM1." ".$NOM1;
       // echo "Soc: " . $row["societe"]. " - Nom: " . $row["nom1"]. " - idx: " . $row["id"]. " " . $row["nom2"]. "<br>";
		//echo "Soc: " . $row["societe"]. " - Nom: " . $row["nom1"]. "  " . $row["nom2"]. "<br>";
    } 
    
	
	} 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')";


$conn->close();
					 
	}			
				
?>
				
				
<form method = "post" action = "<?php $_PHP_SELF ?>">
	
	
	<div class="rTable">
	
		<div class="rTableRow"> 
			<div class="rTableHead" style='width: 50%'><strong>Modifier Client</strong></div> <div class="rTableHead"><span style="font-weight: bold;"></span></div> 
			
		<div class="rTableRow"> 
			<div class="rTableCellodd" style="padding-top: 10px;" >Nom de la société :</div> <div class="rTableCellodd" style='width: 50%'><input class="w3-input w3-hover-greyscale"		 size="30" id="coldonodd"
name="SOC" value="<?php echo $SOC ?>"></div>  </div> 
		
		<div class="rTableRow">
		<div class="rTableCelleven"><select name="titre" class="a-btn a-block"> >
            
           
            
<option value="M."  <?php if ($TITRE=='M.') { ?>selected="selected"<?php } ?>  >M.  </option>
<option value="Mme." <?php if ($TITRE=='Mme.') { ?>selected="selected"<?php } ?>  >Mme.  </option>
<option value="M.&amp;Mme." <?php if ($TITRE=='M.&Mme.') { ?>selected="selected"<?php } ?> >M.&amp;Mme.  </option>
</select></div> <div class="rTableCelleven" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="nom1" id="coldoneven" value="<?php echo $NOM1 ?>"></div> </div>
			
			
			
			<div class="rTableRow" > 
			<div class="rTableCellodd" style="padding-top: 10px;">Adresse :</div> <div class="rTableCellodd" style="width:50%" ><input class="w3-input w3-hover-greyscale" size="60"
name="nom2" id="coldonodd" value="<?php echo $NOM2 ?>"></div>  </div> 
			
			
			<div class="rTableRow"> 
			<div class="rTableCellodd"></div> <div class="rTableCellodd" style='width: 50%' ><input class="w3-input w3-hover-greyscale"size="30"
name="nom3" id="coldonodd" value="<?php echo $NOM3 ?>"></div>  </div> 
			
			
		
			<div class="rTableRow"> 
			<div class="rTableCellodd"></div> <div class="rTableCellodd" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="nom4" id="coldonodd" value="<?php echo $NOM4 ?>"></div>  </div> 
			
			<div class="rTableRow"> 
			<div class="rTableCellodd"></div> <div class="rTableCellodd" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="nom5" id="coldonodd" value="<?php echo $NOM5 ?>"></div>  </div> 
			
			
			<div class="rTableRow"> 
			<div class="rTableCelleven" style="padding-top: 10px;">Objet :</div> <div class="rTableCelleven" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="o1" id="coldoneven" value="<?php echo $O1 ?>"></div>  </div> 
			
			<div class="rTableRow"> 
			<div class="rTableCelleven"></div> <div class="rTableCelleven" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="o2"  id="coldoneven" value="<?php echo $O2 ?>"></div>  </div> 
			
			<div class="rTableRow"> 
			<div class="rTableCelleven"></div> <div class="rTableCelleven" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="o3" id="coldoneven" value="<?php echo $O3 ?>"></div>  </div> 
			
			<div class="rTableRow"> 
			<div class="rTableCellodd" style="padding-top: 10px;">Tel. :</div> <div class="rTableCellodd" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="tel" id="coldonodd" value="<?php echo $TEL ?>"></div>  </div> 
			
			<div class="rTableRow"> 
			<div class="rTableCelleven" style="padding-top: 10px;" >GSM :</div> <div class="rTableCelleven" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="gsm" id="coldoneven" value="<?php echo $GSM ?>"></div>  </div> 
			
			<div class="rTableRow"> 
			<div class="rTableCellodd" style="padding-top: 10px;" >Mail </div> <div class="rTableCellodd" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="mail" id="coldonodd" value="<?php echo $MAIL ?>"></div>  </div> 
			
			<div class="rTableRow"> 
			<div class="rTableCelleven" style="padding-top: 10px">Adresse chantier :</div> <div class="rTableCelleven" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="ac1" id="coldoneven" value="<?php echo $AC1 ?>"></div>  </div> 
			
			
			<div class="rTableRow"> 
			<div class="rTableCelleven"></div> <div class="rTableCelleven" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="ac2" id="coldoneven" value="<?php echo $AC2 ?>"></div>  </div> 
			
			<div class="rTableRow"> 
			<div class="rTableCellodd" style="padding-top: 10px;" >Source :</div> <div class="rTableCellodd" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="pub" id="coldonodd" value="<?php echo $PUB ?>"></div>  </div> 
			
			
			<div class="rTableRow"> 
			<div class="rTableCell" >Facturation :</div> <div class="rTableCell" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="fac1" value="<?php echo $FAC1; ?>"></div>  </div> 
			<div class="rTableRow"> 
			<div class="rTableCell" >Facturation  :</div> <div class="rTableCell" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="fac2" value="<?php echo $FAC2; ?>"></div>  </div> 
			<div class="rTableRow"> 
			<div class="rTableCell" >Facturation  :</div> <div class="rTableCell" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="fac3" value="<?php echo $FAC3; ?>"></div>  </div> 
			<div class="rTableRow"> 
			<div class="rTableCell" >Facturation 4  :</div> <div class="rTableCell" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="fac4" value="<?php echo $FAC4; ?>"></div>  </div> 
			<div class="rTableCell" >Facturation 5 :</div> <div class="rTableCell" style='width: 50%'><input class="w3-input w3-hover-greyscale" size="30"
name="fac5" value="<?php echo $FAC5; ?>"></div>  </div> 
			
			
			
		<input type="hidden" class="w3-input w3-hover-greyscale" size="30"
name="sidxcli" value="<?php echo $SIDXCLI ?>"><br>
        
        <input type="hidden" class="w3-input w3-hover-greyscale" size="30"
name="old" value="<?php echo $NOM1 ?>"><br>
       
	
			<div class="rTableRow"> 
			<div class="rTableCell"><form action="index.html"><a href="index.html" >ACCUEIL</a></div> <div class="rTableCell" style='width: 50%'><input name = "update" type = "submit" id = "update" value = "Enregistrer"></div>  </div> 
			
	  
	
	</form>
			
			
			
			
	</div>
	
	
	

	
	
	
</td>
</tr>
</tbody>
	</table></h3>






			</div>

				</div>
			</div>
			
		</div>
	</div>



</body>
</html>
