<file_sep><?php
 $name   = urldecode($_POST['name']);
$datetime=urldecode($_POST['datetime']);
$imei=urldecode($_POST['imei']);
$activityStatus=urldecode($_POST['activityStatus']);
$InternetSpeed=urldecode($_POST['InternetSpeed']);
$StreamStatus=urldecode($_POST['StreamStatus']);

$con=mysqli_connect("localhost","root","root","bjp");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

mysqli_query($con,"INSERT INTO userinfo (name,datetime,imei,activityStatus)
VALUES ('$name','$datetime',$imei,$activityStatus)");
 print "$name";
//echo "hello"+$datetime;
$con1=mysqli_connect("localhost","root","root","bjp");
// Check connection
if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}	
$query="SELECT * FROM recentuserinfo WHERE imei like '%$imei%'";
$result=mysqli_query($con1,$query);
//echo "result".$result->num_rows;
if($result->num_rows==0)
{
	//echo "If"; 
	$res=mysqli_query($con1,"INSERT INTO recentuserinfo VALUES ($imei,'$datetime',$activityStatus,'$InternetSpeed','$StreamStatus')");

  	mysqli_close($con1);
}
else
{
	//echo "else";
	$res=mysqli_query($con1,"UPDATE recentuserinfo SET datetime='".$datetime."',activestatus='".$activityStatus."',InternetSpeed='".$InternetSpeed."',StreamStatus='".$StreamStatus."' WHERE imei=$imei");

 	mysqli_close($con1);
}
?> 
<file_sep><meta http-equiv="refresh" content="5" > 
<?php
echo  "<body style='background:#211213;'>";
function DisplayLatitude($strlatitude) {
    $latitude = (float)$strlatitude;
    if ($latitude > 0) {
        return $latitude . " N";
    }
    else if ($latitude < -999.0) {
        return "Unknown location";
    }
    else if ($latitude < 0) {
        $latitude = -1*$latitude;
        return $latitude . " S";
    }
    else {
        return $latitude;
    }
}


function DisplayLongitude($strlongitude) {
    $longitude = (float)$strlongitude;
    if ($longitude > 0) {
        return $longitude . " E";
    }
    else if ($longitude < -999.0) {
        return "";
    }
    else if ($longitude < 0) {
        $longitude = -1*$longitude;
        return $longitude . " W";
    }
    else {
        return $longitude;
    }
}
?>

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
 
            });
             
            function sendPushNotification(id){
                var data = $('form#'+id).serialize();
                $('form#'+id).unbind('submit');
                $.ajax({
                    url: "send_message.php",
                    type: 'GET',
                    data: data,
                    beforeSend: function() {
 
                    },
                    success: function(data, textStatus, xhr) {
                          $('.txt_message').val("");
                    },
                    error: function(xhr, textStatus, errorThrown) {
 
                    }
                });
                return false;
            }
        </script>
        <style type="text/css">
            .container{
                width: 1100px;
                margin: 0 auto;
                padding: 0;
            }
            h1{
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                font-size: 18px;
                color: #777;
            }
	    h2{
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                font-size: 14px;
                color: #777;
            }
            
            table.users {
                float: left;
                font-size: 12px;
                font-style: normal;
                font-weigth: bold;
                list-style: none;
                border: 1px solid #dedede;
                padding: 10px;
                margin: 0 5px 5px 0;
                border-radius: 3px;
                -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
                -moz-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
                box-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                color: #555;
            }

            table.users td {
                float: left;
                width: 200px;
                list-style: none;
                padding: 2px;
                margin: 0 2px 2px 0;
                border-radius: 2px;
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                color: #555;
            }

            table.users labelHeading {
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                font-size: 12px;
                font-style: normal;
                font-variant: normal;
                font-weight: bold;
                color: #393939;
                display: block;
                float: left;
            }

            table.users label {
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                font-size: 12px;
                font-style: normal;
                font-variant: normal;
                font-weight: normal;
                color: #393939;
                display: block;
                float: left;
            }
        </style>
    </head>
    <body >

        <?php
        include_once 'db_server_functions.php';
$con=mysqli_connect("localhost","root","root","bjp");
        $db = new DB_Functions();
        $users = $db->getAllLoggedInUserInfo();
        $userCnt = $db->getNumberOfUsersWithAccounts();
	$active=$db->getAllAppActiveInfo()		;
	
            $no_of_ActiveUsers = mysql_num_rows($active);	

        if ($users != false)
            $no_of_users = mysql_num_rows($users);
        else
            $no_of_users = 0;
        ?>
        <div class="container">
	<div style="float: center; background-color: #DBDBDB;">
	<table style="width:100%;height:10%;">
		<tr bgcolor="#2E8B57">
     			 <td style="padding-left: 5px; 
                  		 padding-bottom:3px; 
                   		color:#FF6347;
				font-size:3em; 
                   		font-weight:bold"><center>BJP Player</center>
			</td>
		</tr>
	</table>
</div>
<div style="float: center; background-color: #DBDBDB;">
	<table width="40%">
		<tr>
			<td> <h2>Number of Devices currently active </h2>
			</td>
			<td><h2><?php echo $no_of_ActiveUsers; ?></h2>
			</td>
		</tr>
		<tr>
		<td> <h2>Last Updated at </h2>
		</td>
		<td><h2><?php $date = date('Y-m-d H:i:s'); echo $date; ?></h2>
		</td>
		</tr>
		<tr>
		<td><h2>Currently Running</h2>
		</td>
		<td><h2><img src="green.png"  width="25" height="25"></h2>
		</td>
		</tr>
		<tr>
		<td><h2>Currently Not Running</h2>
		</td>
		<td><h2><img src="yellow.png"  width="25" height="25"></h2>
		</td>
		</tr>
		<tr>
		<td><h2>App Uninstalled</h2>
		</td>
		<td><h2><img src="red.png"  width="25" height="25"></h2>
		</td>
		</tr>
		</table>
</div>
     <!-- <h2>Number of Devices currently active : <?php echo $no_of_ActiveUsers; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h2>            
            <h2>Last Updated at : <?php $date = date('Y-m-d H:i:s'); echo $date; ?> 
	<h2>Currently Running<img src="green.png"  width="25" height="25"></h2>
	<h2>Currently Not Running<img src="yellow.png"  width="25" height="25"></h2>
	<h2>App Uninstalled<img src="red.png"  width="25" height="25"></h2> -->
            	
                <?php
 		if ($no_of_users > 0) {
                    ?>
<br><br>
                    <div class="table">
	<TABLE border=20 bgcolor=#d1be94 width="100%">
<TR BGCOLOR="#a1be94"> <TH>Device ID</TH><TH>Active Status</TH><TH>Location</TH><TH>NetSpeed</TH> <TH>Date Time
</TH><TH>Reset Button</TH><TH>Add Details</TH><TH>StreamStatus</TH></TR>
                    <tr>
                   <?php
		    session_start();
                    $cnt = 0;
                    while ($row = mysql_fetch_array($users)) {
			$status=$row["activestatus"];
			$InternetSpeed=$row["InternetSpeed"];
			$datetimetable=$row["datetime"];
			$imei=$row["imei"];
			$StreamStatus=$row["StreamStatus"];
			$dt = new DateTime();
			$datetimesys= $dt->format('Y-m-d h:i:s a');
			//calculating time diff for web status change
			$time1 = new DateTime($datetimesys);
			$time2 = new DateTime($datetimetable);
			$interval = $time1->diff($time2);
			$seconds=$interval->format('%s');
			$minutes=$interval->format('%i');
			$hours=$interval->format('%h');
			$years=$interval->format('%Y');
			$months=$interval->format('%m');
			$days=$interval->format('%d');
			//echo "years\t:".$years."<br>";
			//echo "months\t:".$months."<br>";
			//echo "days\t:".$days."<br>";
			//echo "hours\t:".$hours."<br>";
			//echo "minutes\t:".$minutes."<br>"	;
			//echo "second\t:".$seconds;
			$pKey = $row["imei"];
			   $cnt++;
                        ?>
                        <tr align="center">	
                      <td><label><?php echo $row["imei"];  ?></label></td> 
                      <?php if($status==1||$status=="true"){?>
		         <?php if($minutes>=2||$hours>=1){ 
			$con1=mysqli_connect("localhost","root","root","bjp");
			$res=mysqli_query($con1,"UPDATE recentuserinfo SET InternetSpeed='0',activestatus='deleted' WHERE imei='$imei'");
			$s = "enered in if";
			}else{ $s = "in else"; }?>
                    	<td ><label><?php if($s == "enered in if"){echo "<img src='red.png' style='width:30px;hieght:30px;' >";}
			else{echo "<img src='green.png' style='width:30px;hieght:30px;' >";}?></label></td>
			<?php 
			}
			elseif($minutes>=2){
			$con1=mysqli_connect("localhost","root","root","bjp");
			$res=mysqli_query($con1,"UPDATE recentuserinfo SET InternetSpeed='0',StreamStatus='0',activestatus='deleted' WHERE imei='$imei'");
			?>
			<td ><label><?php echo "<img src='red.png' style='width:30px;hieght:30px;' >" ;?></label></td>
			<?php	
			}
				
			elseif($status=="yellow")
			{
			?>
 			<td ><label><?php echo "<img src='yellow.png' style='width:30px;hieght:30px;' >"  ;    ?></label></td>
			<?php
			}
?>

<?php 
$xx=$db->getAllEntriesFromNetTable($row["imei"]);
if($row1 = mysql_fetch_array($xx)){
$town=$row1["town"];
}
//echo $town;
if($town == "")
{
?>
<td ><label>add Location</label></td>
<?php
}
else{
?>
 <td ><label><?php echo  $town ;    $town = "";?></label></td>	
<?php
}
?>
<td ><label><?php echo  $InternetSpeed ;    ?></label></td>
<td><label><?php echo $row["datetime"]     ?></label></td> 
<td><label><a href="sms.php?mobileNo=<?php echo $mobilenumber; ?>&imei=<?php  echo $imei; ?> &town=<?php  echo $town; ?>">
    <button>Reset</button>
</a></label></td>
<td><label><a href="entry.php?imeiNo=<?php echo $row['imei']; ?>">
    <button>addContact</button>
</a></label></td>
<td><label><?php echo $row["StreamStatus"]     ?></label></td> 
</tr>
<?php }//first while ending ?>
<tr>
</tr>
</table>
<?php } else { ?>
<li> IBPlayer - No users currently active. (Total number of user accounts : <?php echo $userCnt; ?>) </li>
 <?php } ?>
</div>
</body>
</html>
<file_sep>
<?php
$imeiNo = $_GET['imeino'];
//echo "asdfdsf".$imeiNo;
?>
<!DOCTYPE html>
<html>
    <head>
<script type="text/javascript">
 
function validateMyForm()

{
// Create validation tracking variable
var valid = true;
var validationMessage; 
var name1 = document.getElementById('name').value;
var pwd1=document.getElementById('pwd').value;
var imei1=document.getElementById('imei').value;

	if((name1.length==0)&&(pwd1.length==0)){
        // Validate all fields
	valid = false;
	alert("Please Enter all Details");
		return false;
 
    	}
	else if (document.getElementById('name').value.length == 0)

        {
            
            validationMessage = validationMessage + ' Name is missing\r\n';

            valid = false;
           alert("Username is missing");
		return false;
        }

	// Validate password
       else if (document.getElementById('pwd').value.length == 0)

        {

            validationMessage = validationMessage + 'Password is missing\r\n';

            valid = false;
alert("Password is missing");
		return false;

        }
else
{
 window.location.href =  'http://172.16.58.3/bjp/validate.php?name='+name1+'&pwd='+pwd1+'&imei='+imei1;

}

}//validateMyForm()

</script>
</head>
 <body style='background:#d1be94;'> 
<div style="float: center; background-color: #DBDBDB;">
	<table style="width:100%;height:10%;">
		<tr bgcolor="#2E8B57">
     			 <td style="padding-left: 5px; 
                  		 padding-bottom:3px; 
                   		color:#FF6347;
				font-size:3em; 
                   		font-weight:bold"><center>Welcome To Login</center>
			</td>
		</tr>
	</table>
</div>  
<br />        
<form  action="http://183.82.9.60/bjp/validate.php" method="post">
<table align="center" style="width:10%;height:10%;">
<tr>
<td>Name</td><td> <input type="text" name="user" id="name" value="" placeholder="please enter Username" required></td>
</tr>
<tr>
<td>Password</td><td> <input type="<PASSWORD>" name="pwd" id="pwd" value="" placeholder="please enter Password" required></td>
</tr>
</table> 
<br> 
<table align="center">
<tr >
<input type="hidden" id="imei" name= "imei" value="<?php echo $imeiNo; ?>">
<td ><input type="submit" value="Login"></td>
</tr>
</table>
<br><br>
<table align="center">
<tr>
<td><?php
if($_GET['login_fail'] == "faild")
{
 echo "Login Failed Please try again!	";
}
?></td>
</tr>
</table>
</form>
</div>
</body>
</html> 
<file_sep>
<?php
session_start();
$imeiNo = $_SESSION['imeiNo'];
//echo "asdfdsf".$imeiNo;
?>
<!DOCTYPE html>
<html>
    <head>
<script type="text/javascript">
function validateMyForm()
{
 // Create validation tracking variables
 var valid = true;
var validationMessage; 
var name1 = document.getElementById('name').value;
var city1=document.getElementById('city').value;
var mobilenum=document.getElementById('mnumber').value;
var countryname=document.getElementById('country').value;
var imei1=document.getElementById('imei').value;

if((name1.length==0)&&(mobilenum.length==0)&&(city1.length==0)){
        // Validate all fields
		valid = false;
		alert("Please Enter all Details");
		return false;
 
   		 }
		else if (document.getElementById('name').value.length == 0)

        	{
            
            		validationMessage = validationMessage + ' Name is missing\r\n';

           		 valid = false;
           		alert("Name is missing");
			return false;
       		}
		
		// Validate mobile number
		else if (document.getElementById('mnumber').value.length == 0)

        	{

            		validationMessage = validationMessage + 'Mobile Number is missing\r\n';

            		valid = false;
			alert("Mobile Number is missing");
			return false;
		 }

        // Validate city name

       		else if (document.getElementById('city').value.length == 0)

        	{

            		validationMessage = validationMessage + 'City name is missing\r\n';

            		valid = false;
			alert("City name is missing");
			return false;

       		 }

		else
		{
			 window.location.href =  'http://172.16.31.10/bjp/addcontact.php?name='+name1+'&mnum='+mobilenum	+'&cityname='+city1+'&cname='+countryname+'&imei='+imei1;

		}

		}//validateMyForm()

</script>
</head>
<body style='background:#d1be94;'>   
<br />
<div style="float: center; background-color: #DBDBDB;">
	<table style="width:100%;height:10%;">
		<tr bgcolor="#2E8B57">
     			 <td style="padding-left: 5px; 
                  		 padding-bottom:3px; 
                   		color:#FF6347;
				font-size:3em; 
                   		font-weight:bold"><center>Add Contact Details</center>
			</td>
		</tr>
	</table>
</div>        
<form  onsubmit="return false;">
<table align="center" style="width:10%;height:10%;">
<tr>
<td>Name</td><td> <input type="text" name="user" id="name" value="" placeholder="please enter Name" ></td>
</tr>
<tr>
<td>MobileNumber</td><td> <input type="text" name="mnumber" id="mnumber" value="" placeholder="please enter mobile number" ></td>
</tr>
<tr>
<td>City</td><td> <input type="text" name="city" id="city" value="" placeholder="please enter City" ></td>
</tr>
<tr><label for="name"><td>Country</td></label><td><select name="country" id="country" >
                                        <option value="India">India</option>
                                        <option value="France">France</option>
                                        <option value="Italy">Italy</option>
</tr>
 						</td></select> 
</table> 
<br> 
<table align="center">
<tr >
<input type="hidden" id="imei" name= "imei" value="<?php echo $imeiNo; ?>">
<td ><input type="submit" value="Save" onClick="validateMyForm();"></td>
</tr>
</table>
</form>
</div>
</body>
</html> 
<file_sep><?php
$imeiNo = $_GET['imeiNo'];
//echo $imeiNo;
?>
<!DOCTYPE html>
<html>
</head>
<body style='background:#d1be94;'> 
<div style="float: center; background-color: #DBDBDB;">
	<table style="width:100%;height:10%;">
		<tr bgcolor="#2E8B57">
     			 <td style="padding-left: 5px; 
                  		 padding-bottom:3px; 
                   		color:#FF6347;
				font-size:3em; 
                   		font-weight:bold"><center>WelCome To BJP Player</center>
			</td>
		</tr>
	</table>
</div>
<br><br><br><br>
<table align="center">
<tr >
<input type="hidden" id="imei" name= "imei" value="<?php echo $imeiNo; ?>">
<td><a href="login.php?imeino=<?php echo $imeiNo ?>">
    <button>Login</button>
</tr>
</table>
<br>
<table align="center">
<tr>
<td><a href="createuser.php?imeiNo=<?php echo $row['imei']; ?>">
    <button>Create User</button>
</tr>
</table>
</body>
</head>
</html>

<file_sep><?php
$x='2010-07-29 12:43:54';
$y='2010-07-22 01:23:42';
   $time1 = new DateTime($x);
$time2 = new DateTime($y);
$interval = $time1->diff($time2);
$seconds=$interval->format('%s');
$minuts=$interval->format('%i');
$hours=$interval->format('%h');
$years=$interval->format('%Y');
$months=$interval->format('%m');
$days=$interval->format('%d');
echo "years\t:".$years."<br>";
echo "months\t:".$months."<br>";
echo "days\t:".$days."<br>";
echo "hours\t:".$hours."<br>";
echo "minutes\t:".$minuts."<br>"	;
echo "second\t:".$seconds;
    ?>
<file_sep><?php

 $name = $_POST['user'];  
$mobilenumber = $_GET['mobileNo'];
$town = $_POST['town'];
$country = $_POST['country'];
$imei = $_GET['imei'];
$deviceName = $imei;
//Multiple mobiles numbers seperated by comma

//echo  $deviceName."<br>";
$mobileNumber = $mobilenumber;
//echo $mobileNumber;
$mobilemsg="IB_start";
if(($deviceName == "") && ($mobilenumber == "") ){

echo "Please Add your contact Details First";
}
else
{

echo "DeviceName   ".$deviceName."<br>";
echo "Message    ".$mobilemsg."<br>";
echo "MobileNumber    ".$mobileNumber."<br>";
}	
//Your authentication key
$authKey = "62264A7RDpradwshV52d3be3d";

//Sender ID,While using route4 sender id should be 6 characters long.
$senderId = "octo";

//Your message to send, Add URL endcoding here.
$message = urlencode($mobilemsg);

//Define route 
$route = "1";
//Prepare you post parameters
$postData = array(
    'authkey' => $authKey,
    'mobiles' => $mobileNumber,
    'message' => $message,
    'sender' => $senderId,
    'route' => $route
);

//API URL
$url="http://india.msg91.com/api/sendhttp.php";

// init the resource
$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $postData
    //,CURLOPT_FOLLOWLOCATION => true
));

//get response
$output = curl_exec($ch);

curl_close($ch);

echo $output."Message has been sent to Device";?>
sleep(1000);
<script>
location.replace("http://www.bookingslot.com/ResetDevice.php");
</script>
<file_sep><?php

$username=$_GET['name'];
$town = $_GET['cityname'];
$email = $_GET['email'];
$password=$_GET['pwd'];
$imei = $_GET['imei'];

//echo $name;
//echo $imei."<br>I am in SMS";

   
$con1=mysqli_connect("localhost","root","root","bjp");
// Check connection
if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
	
$query="SELECT * FROM createuser WHERE username like '%$username%'";
$result=mysqli_query($con1,$query);
if($result->num_rows==0)
{
//echo "in if";
	$res=mysqli_query($con1,"INSERT INTO createuser (username,email,city,password,imei) VALUES ('$username','$email','$town','$password','$imei')");
echo "Details Saved";
  	mysqli_close($con);

}
else
{
echo "User Already Exist!";
}

?> 
<file_sep><?php
session_start();
$name=$_POST['user'];
$pwd = $_POST['pwd'];
$im=$_POST['imei'];
$_SESSION['imeiNo'] = $im;
//echo "Details Saved<br>";
//echo $_SESSION['imeiNo']."<br>";
//echo $pwd."<br>";
$con1=mysqli_connect("localhost","root","root","bjp");
 include_once 'db_server_functions.php';
$db = new DB_Functions();
// Check connection
if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}	
$query="SELECT password FROM createuser WHERE username like '%$name%'";
$result=mysqli_query($con1,$query);
			$xx=$db->getAllEntriesFromCreateTable($name);
                          while ($row1 = mysql_fetch_array($xx)) {
			
				$password=$<PASSWORD>["<PASSWORD>"];
//echo $password;

}
if($password==$pwd)
{
echo "Login Success";
?>
<script>
location.replace("http://1172.16.31.10/bjp/view_users.php");
</script>
<?php

}
else
{
//echo "Login Failed";
?>
<script>
location.replace("http://172.16.31.10/bjp/login.php?login_fail=faild");
</script>
<?php
}

?> 
<file_sep><?php 
class DB_Functions {
    private $passwordSeed = "<PASSWORD>";
 
    private $db;
 
    //put your code here
    // constructor
    function __construct() {
        include_once './db_connect.php';
        // connecting to database
        $this->db = new DB_Connect();
        $this->db->connect();
    }
 
    // destructor
    function __destruct() {
 
    }
 
    public function isAuthorized($email) {
       $result = mysql_query("SELECT Authorized FROM Users where email='$email'");
       $returned = mysql_fetch_array($result);
       if ($returned[0] == "1") {
          return true;
       }
       else {
          return false;
       }
    }


    private function decryptPassword($email,$password) {
	$result = mysql_query("SELECT AES_DECRYPT(encrypted_password,CONCAT('$email','$this->passwordSeed')) FROM Users WHERE email='$email'");
        $returned = mysql_fetch_array($result);
        return $returned[0]; 
    }


    public function validateUser($username,$password) {
        $result = mysql_query("SELECT Username, Email FROM Users where username='$username'");
        $returned = mysql_fetch_array($result);
        if ($username == $returned[0]) {
            $email = $returned[1];
            $decryptedPassword  = $this->decryptPassword($email,$password);
            if ($decryptedPassword == $password) {
                return  json_encode(array('Result' => 'AOK', 'Reason' => ''));
            }
            else {
                return json_encode(array('Result' => 'NOK', 'Reason' => 'Bad user credentials'));
            }
        }
        else {
            return json_encode(array('Result' => 'NOK', 'Reason' => 'User does not exists'));
        } 
    }


    public function BooleanResultValidateUser($username,$password) {
        $result = mysql_query("SELECT Email FROM Users where username='$username'");
        if ($result) {
            $returned = mysql_fetch_array($result);
            $email = $returned[0];
            $decryptedPassword = $this->decryptPassword($email,$password);
            if ($decryptedPassword == $password) {
                return true;
            }
            else {
                return false;
           }
        }
    }




    public function updatePosition($username, $password, $dateTime, $latitude, $longitude, $heading, $speed) {
        if ($this->validateUser($username,$password)) {
            if ($speed == 0.0) {
              $heading = -1.0;
            }
            $result = mysql_query("UPDATE Users SET lastUpdatedAt='$dateTime', latitude=$latitude, longitude=$longitude, speed=$speed, heading=$heading WHERE username='$username'");
            if ($result) {
                return json_encode(array('Result' => 'OK', 'Reason' => ''));
            }
            else {
                return json_encode(array('Result' => 'NOK', 'Reason' => 'Unknown Reason'));
            }
        }
        else {
            return json_encode(array('Result' => 'NOK', 'Reason' => 'Bad credentials'));
        }
    }

    public function getRegId($email, $password) {
        $validUser = $this->validateUser($email,$password);
        if ($validUser == "NOK") {
           return "NOK";
        } 
        $result = mysql_query("SELECT gcm_regid FROM Users where email='$email'");
        $returned = mysql_fetch_array($result);
        return $returned[0];
    }



 
 
  
    public function AddRequest($eventName ,$eventDescription, $eventExpiry, $eventAddress,$latitude, $longitude, $notificationDistance, $recordDistance) {
        $sql = "INSERT INTO Request(RequestDateTime,EventName,EventDescription,EventExpiry,Address,Latitude,Longitude,NotificationDistance,RecordDistance) VALUES (NOW(),'$eventName','$eventDescription','$eventExpiry','$eventAddress',$latitude,$longitude,$notificationDistance,$recordDistance)";        
        //error_log($sql,0);
        $result = mysql_query($sql);
        error_log($result,0);
        return $result;
    }
    
    
    public function getAllContactsForUser($username) {
        
        $response_array = Array();
        $result = mysql_query("SELECT FriendUsername FROM FriendList WHERE Username='$username' ORDER BY FriendUsername");
        while($row = mysql_fetch_array($result)){
            $result2 = mysql_query("SELECT Fullname, Email FROM Users WHERE Username='$row[0]'");
            $row2 = mysql_fetch_array($result2);
            $row_array['Username'] = $row[0];
            $row_array['Fullname'] = $row2[0];
            $row_array['Email'] = $row2[1];
            array_push($response_array,$row_array);            
        }
        echo json_encode($response_array);
     }


     public function getAllGroupsForUser($username) {
        $response_array = Array();
        $result = mysql_query("SELECT Groupname, GroupDescription FROM GroupNames WHERE Username='$username' ORDER BY Groupname");
        while($row = mysql_fetch_array($result)){
            $groupname = $row[0];
            $groupdesc = $row[1];
            $result = mysql_query("SELECT FriendList.FriendUsername FROM FriendList,GroupNames WHERE GroupNames.Groupname='$groupname' ORDER BY FriendList.FriendUsername");
            while($row = mysql_fetch_array($result)){
                $username = $row[0];
                $result2 = mysql_query("SELECT Fullname, Email FROM Users WHERE Username='$row[0]'");
                $row2 = mysql_fetch_array($result2);
                $row_array['Groupname'] = $groupname;
                $row_array['Groupdesc'] = $groupdesc;
                $row_array['FriendUsername'] = $username;
                $row_array['FriendFullname'] = $row2[0];  
               array_push($response_array,$row_array);            
            }
        }
        echo json_encode($response_array);
     }
public function getAllAppActiveInfo() { 
        //$result = mysql_query("select name, datetime, imei,activityStatus FROM userinfo Where activityStatus='1'"); old
$result = mysql_query("select * FROM recentuserinfo WHERE activestatus='true'"); 
        return $result; 	
    }
public function getAllEntriesFromNetTable($x)
{
$result = mysql_query("select town from userdetails where imei='$x' "); 
        return $result; 
}
public function getAllEntriesFromCreateTable($x)
{
$result = mysql_query("select password from createuser where username like'%$x%' "); 
        return $result; 
}
    public function getAllLoggedInUserInfo() { 
        //$result = mysql_query("select name, datetime, imei,activityStatus FROM userinfo Where activityStatus='1'"); old
$result = mysql_query("select * FROM recentuserinfo"); 
        return $result; 
    } 
    
    public function getNumberOfUsersWithAccounts() {
        $result = mysql_query("select count(*) from recentuserinfo");
        $row = mysql_fetch_array($result);
        return $row[0];
    }
}
?>
