<?php

//echo "<br>le cook est ".$_COOKIE['livecook'];
$NumeroIndexDevis=$_COOKIE['livecookidx'];
//echo "<br>le cookidx est ".$NumeroIndexDevis;

	
	 
?>
<html>
<head>
		
<script>

function setCookie(cname,cvalue,exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires=" + d.toGMTString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function getCookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

function checkCookie() {
    var user=getCookie("livecook");
	var user1=getCookie("livecookidx");
        //  alert("Welcome again " + user+"  "+user1);
	    //user = prompt("Please enter your name:","");
    
           setCookie("livecook", 0, 3);
		   //setCookie("livecookidx", ?php echo $idx ?>, 3);
       }
function checkCookie1() {
    var user=getCookie("livecook");
	var user1=getCookie("livecookidx");
        //  alert("Welcome again " + user+"  "+user1);
	    //user = prompt("Please enter your name:","");
    
           setCookie("livecook", 1, 3);
		   //setCookie("livecookidx", ?php echo $idx ?>, 3);
       }    


</script>
</head>
	
<?php
	// on se connecte à notre base devis

$servername = "localhost:8889";
$username = "root";
$password = "root";
$dbname = "devis";
$debug=0;
// 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 idx='$NumeroIndexDevis' ";
//	$LIVE=rand(1, 5);
//$sql = "UPDATE tete SET num='$DNUM', date='$DDATE', objet='$DOBJET', idxcli='$DIDXCLI', chantier='$DCHANTIER', tva='$DTVA', banque='$DBANQUE', remarque='$DREMARQUE',memo='$MEMO',live='$LIVE' WHERE idx='$NumeroIndexDevis' ";
			 
if ($debug==1)   { print "<br>";print $sql;  print "<br>"; } 
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
		
		if ($row["live"]==1) {print "<body onload='checkCookie1()'>";
				} else {print "<body onload='checkCookie()'>";} 
     
		// echo "live : " . $row["live"]. " <br> ";//
		
		//echo "Soc: " . $row["societe"]. " - Nom: " . $row["nom1"]. "  " . $row["nom2"]. "<br>";
    } 
	
	
	
	} else {
   if ($debug==1)   { echo "0 results";} 
}

$conn->close();


?>
	
	
	
	
	
	

	
	
	<meta http-equiv="refresh" content="5">
	
 		<link rel="stylesheet" href="stylei.css" media="all" />
	
		<?php
   
		header("Refresh: 5; ");		
			 
	
	
?><br><br>
	<INPUT type="button" id='liensubmit2' value="Go lIve" onClick="window.open('texteditlive.php')"> <br><br><br>
		<INPUT type="button" id='liensubmit2' value="Home" onClick="window.open('index.html')"> 

</body>
</html>


	
