<?php
error_reporting(0);

include('DB.php');

if($_REQUEST["action"]=="getdata"){
	$response=array();
	$product = array();
	$response["data"]= array();

	$qr="select mobile_no from call_customer where dept='".$_REQUEST['dept']."' and user_id='".$_REQUEST['user_id']."'";
	
	$result=mysqli_query($con,$qr);
	if($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
		 $product["value"]=$row['mobile_no'];
		 $qr1="delete from call_customer where dept='".$_REQUEST['dept']."' and user_id='".$_REQUEST['user_id']."'";
		 mysqli_query($con,$qr1);
	}else{
	  $product["value"]="none";
	}
	array_push($response["data"], $product);
	echo str_replace('\/','/',json_encode($response));
}else if($_REQUEST["action"]=="login"){
	$response=array();
	$product = array();
	$response["data"]= array();
	
	$username=$_REQUEST['username'];
	$password=$_REQUEST['password'];

	$query="select * from user where username='$username' and pwd='$password'";
	
	$result=mysqli_query($con,$query);
	
	if($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
		if($row['username']==$username && $row['pwd']==$password){
			
			$product["value"]="valid";
			 $product["user_id"]=$row['user_id'];
			 
			
		}else{$product["value"]="invalid";
		  $product["user_id"]="none";
		}
	}else{$product["value"]="invalid";
	  $product["user_id"]="none";
	}
	
	array_push($response["data"], $product);
	echo str_replace('\/','/',json_encode($response));
}
?>
