<?php
$name=$_REQUEST['name'];
$zone1 = $_REQUEST['zone1'];
$zone2 = $_REQUEST['zone2'];
$zone3 = $_REQUEST['zone3'];
$wins = 0;
$dbhost = "localhost";
	    		$dbuser = "perthdes_fam_app";
$dbpass = "TW#7CCqKReDn";
$dbname = "perthdes_famcab_api";
if(!empty($zone1)){
			
	    		$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);
	    		$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
	    		
	    		
	    		$query   = "UPDATE lead_time_poly SET lead_time='".$zone1."' WHERE zone='1'";
	    		$success = $conn->query($query);
	    		if (!$success) {
    			die("Couldn't enter data: ".$conn->error);
    			} else {
    			$wins = $wins + 1;
    			}
    		
}
if(!empty($zone2)){
			
	    		$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);
	    		$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
	    		
	    		
	    		$query   = "UPDATE lead_time_poly SET lead_time='".$zone2."' WHERE zone='2'";
	    		$success = $conn->query($query);
	    		if (!$success) {
    			die("Couldn't enter data: ".$conn->error);
    			} else {
    			$wins = $wins + 1;
    			}
    		
}
if(!empty($zone3)){
			
	    		$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);
	    		$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
	    		
	    		
	    		$query   = "UPDATE lead_time_poly SET lead_time='".$zone3."' WHERE zone='3'";
	    		$success = $conn->query($query);
	    		if (!$success) {
    			die("Couldn't enter data: ".$conn->error);
    			} else {
    			$wins = $wins + 1;
    			}
    		
}



if(!empty($name))
{
   
	    		$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);
	    		$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
	    		
	    		if($name == "0") {
	    		$query   = "UPDATE flag_val SET flag=0 WHERE id=1";
	    		}
	    		if($name == "1") {
	    		$query   = "UPDATE flag_val SET flag=1 WHERE id=1";
	    		}
	    $success = $conn->query($query);
 
	    if (!$success) {
    		die("Couldn't enter data: ".$conn->error);
    		} 
    		if($name == "1") {
    		$status = "on";
    		} else {
    		$status = "off";
    		}
	$message = urlencode("App is now $status");
		$url = "https://api.smsbroadcast.com.au/api-adv.php?username=lewiscann&password=HNVcGTm5&to=0413774931&from=0413774931&message=$message&maxsplit=1";
	$curlObj = curl_init();
	curl_setopt($curlObj, CURLOPT_URL, $url);
	curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($curlObj, CURLOPT_HEADER, 0);
	curl_setopt($curlObj, CURLOPT_POST, 1);

	//$response = curl_exec($curlObj);

	curl_close($curlObj);
	
	


       
    $wins = $wins + 1;
    
    }
    if($wins == 4) {
    echo "OK";
    } else {
    echo $wins."/4 aint bad";
    }

