<?php
// include db connect class
       require_once __DIR__ . '/../DBConnect.php';
	if (isset($_POST['ClientID'])) {
      $ClientID = $_POST['ClientID'];
		
		$sql = "SELECT * FROM Account3Name WHERE ClientID = $ClientID";
	  
	$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
	if($result!=null &&  $result>0){
        $response["Account3Name"] = array();
       foreach($result as $row) { 
          $Account3Name["AcNameID"] = $row["AcNameID"];
          $Account3Name["AcName"] = $row["AcName"];
          $Account3Name["AcGroupID"] = $row["AcGroupID"];
          $Account3Name["AcAddress"] = $row["AcAddress"];
          $Account3Name["AcMobileNo"] = $row["AcMobileNo"];
          $Account3Name["AcContactNo"] = $row["AcContactNo"];
          $Account3Name["AcEmailAddress"] = $row["AcEmailAddress"];
          $Account3Name["AcDebitBal"] = $row["AcDebitBal"];
          $Account3Name["AcCreditBal"] = $row["AcCreditBal"];
          $Account3Name["AcPassward"] = $row["AcPassward"];
          $Account3Name["ClientID"] = $row["ClientID"];
          $Account3Name["ClientUserID"] = $row["ClientUserID"];
		  $Account3Name["SysCode"] = $row["SysCode"];
          $Account3Name["NetCode"] = $row["NetCode"];
          $Account3Name["UpdatedDate"] = $row["UpdatedDate"];
          $Account3Name["SerialNo"] = $row["SerialNo"];
          $Account3Name["UserRights"] = $row["UserRights"];
		  $Account3Name["SecurityRights"] = $row["SecurityRights"];
          $Account3Name["Salary"] = $row["Salary"];
			
		  $current_date = date("Y-m-d H:i:s");	
		  $Account3Name["SessionDate"] = $current_date;
			
          // push single product into final response array
          array_push($response["Account3Name"], $Account3Name);
        }
        // success
        $response["success"] = 1;
        // echoing JSON response
        echo json_encode($response);
      }else {
        // success
        $response["success"] = 0;
        $response["message"] = "No Data Availaible";
        // echoing JSON response
    		echo json_encode($response);
      }
	}else if(isset($_POST['Cliid']) && isset($_POST['cellno'])&& isset($_POST['AcPassward'])){
		$ClientID = $_POST['Cliid'];
		$cellno = $_POST['cellno'];
		$AcPassward = $_POST['AcPassward'];
		$sql = "SELECT * FROM Account3Name WHERE ClientID = $ClientID AND AcMobileNo = $cellno AND AcPassward = $AcPassward ";
	  
	$params = array();
     $stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
	if($result!=null &&  $result>0){
        $response["Account3Name"] = array();
       foreach($result as $row) { 
          $Account3Name["AcNameID"] = $row["AcNameID"];
          $Account3Name["AcName"] = $row["AcName"];
          $Account3Name["AcGroupID"] = $row["AcGroupID"];
          $Account3Name["AcAddress"] = $row["AcAddress"];
          $Account3Name["AcMobileNo"] = $row["AcMobileNo"];
          $Account3Name["AcContactNo"] = $row["AcContactNo"];
          $Account3Name["AcEmailAddress"] = $row["AcEmailAddress"];
          $Account3Name["AcDebitBal"] = $row["AcDebitBal"];
          $Account3Name["AcCreditBal"] = $row["AcCreditBal"];
          $Account3Name["AcPassward"] = $row["AcPassward"];
          $Account3Name["ClientID"] = $row["ClientID"];
          $Account3Name["ClientUserID"] = $row["ClientUserID"];
		  $Account3Name["SysCode"] = $row["SysCode"];
          $Account3Name["NetCode"] = $row["NetCode"];
          $Account3Name["UpdatedDate"] = $row["UpdatedDate"];
          $Account3Name["SerialNo"] = $row["SerialNo"];
          $Account3Name["UserRights"] = $row["UserRights"];
		  $Account3Name["SecurityRights"] = $row["SecurityRights"];
          $Account3Name["Salary"] = $row["Salary"];
			
		  $current_date = date("Y-m-d H:i:s");	
		  $Account3Name["SessionDate"] = $current_date;
			
          // push single product into final response array
          array_push($response["Account3Name"], $Account3Name);
        }
        // success
        $response["success"] = 1;
        // echoing JSON response
        echo json_encode($response);
	  }else {
        // success
        $response["success"] = 0;
        $response["message"] = "No Data Found";
        // echoing JSON response
    		echo json_encode($response);
      }
	  }else if(isset($_POST['Cliid']) && isset($_POST['AcEmailAddress'])&& isset($_POST['AcPassward'])){
		$ClientID = $_POST['Cliid'];
		$AcEmailAddress = $_POST['AcEmailAddress'];
		$AcPassward = $_POST['AcPassward'];
		$sql = "SELECT * FROM Account3Name WHERE ClientID = $ClientID AND AcEmailAddress = '$AcEmailAddress' AND AcPassward = $AcPassward ";
	  
	$params = array();
      $options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
      $result = sqlsrv_query( $conn, $sql , $params, $options );

      if (sqlsrv_num_rows($result) > 0) {
        $response["Account3Name"] = array();
        while ($row = sqlsrv_fetch_array($result)) {
          $Account3Name["AcNameID"] = $row["AcNameID"];
          $Account3Name["AcName"] = $row["AcName"];
          $Account3Name["AcGroupID"] = $row["AcGroupID"];
          $Account3Name["AcAddress"] = $row["AcAddress"];
          $Account3Name["AcMobileNo"] = $row["AcMobileNo"];
          $Account3Name["AcContactNo"] = $row["AcContactNo"];
          $Account3Name["AcEmailAddress"] = $row["AcEmailAddress"];
          $Account3Name["AcDebitBal"] = $row["AcDebitBal"];
          $Account3Name["AcCreditBal"] = $row["AcCreditBal"];
          $Account3Name["AcPassward"] = $row["AcPassward"];
          $Account3Name["ClientID"] = $row["ClientID"];
          $Account3Name["ClientUserID"] = $row["ClientUserID"];
		  $Account3Name["SysCode"] = $row["SysCode"];
          $Account3Name["NetCode"] = $row["NetCode"];
          $Account3Name["UpdatedDate"] = $row["UpdatedDate"];
          $Account3Name["SerialNo"] = $row["SerialNo"];
          $Account3Name["UserRights"] = $row["UserRights"];
		  $Account3Name["SecurityRights"] = $row["SecurityRights"];
          $Account3Name["Salary"] = $row["Salary"];
			
		  $current_date = date("Y-m-d H:i:s");	
		  $Account3Name["SessionDate"] = $current_date;
			
          // push single product into final response array
          array_push($response["Account3Name"], $Account3Name);
        }
        // success
        $response["success"] = 1;
        // echoing JSON response
        echo json_encode($response);
	  }else {
        // success
        $response["success"] = 0;
        $response["message"] = "No Data Found";
        // echoing JSON response
    		echo json_encode($response);
      }
	}else {
        // success
        $response["success"] = 0;
        $response["message"] = "Set All Parameter";
        // echoing JSON response
    		echo json_encode($response);
      }

?>