<?php

  // array for JSON response
  $response = array();
if (isset($_POST['CountryClientID']) && isset($_POST['MobileNoOrEmail']) && isset($_POST['ColumnName']) ){
       //Two values below can be assign to ColumnName
       //AcEmailAdress 
       //AcMobileNo
   
           $CountryClientID = $_POST['CountryClientID'];
	       $MobileNoOrEmail = $_POST['MobileNoOrEmail'];
	       $ColumnName=$_POST['ColumnName'];
	
//	 $sql = "SELECT * FROM Account3Name WHERE ClientID = $CountryClientID AND AcMobileNo = $MobileNoOrEmail";
    $sql="SELECT * FROM Account3Name WHERE ClientID = $CountryClientID AND $ColumnName='$MobileNoOrEmail'";
 // include db connect class
    require_once __DIR__ . '/../DBConnect.php';
			$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["NameOfPerson"] = $row["NameOfPerson"];
        $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;
      $response["message"] = "Numer is Found";
      // echoing JSON response
      echo json_encode($response);
    }else {
      // success
      $response["success"] = 0;
      $response["message"] = "PHone Nubmer Not Register";
      // echoing JSON response
      echo json_encode($response);
    }
  

    
  }else if (isset($_POST['ClientID']) &&isset($_POST['email'])&&isset($_POST['Pass']) ){
       
   
           $ClientID = $_POST['ClientID'];
	  $Email = $_POST['email'];
	  $Pass = $_POST['Pass'];
	 $sql = "SELECT * FROM Account3Name WHERE ClientID = $ClientID AND AcEmailAddress = '$Email' AND AcPassward = '$Pass'";
 // include db connect class
    require_once __DIR__ . '/../DBConnect.php';
			$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["NameOfPerson"] = $row["NameOfPerson"];
        $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"] = "Either Email Not Register Or Wrong Email/Password Entered";
      // echoing JSON response
      echo json_encode($response);
    }
  

    
  }else if (isset($_POST['ClientID']) &&isset($_POST['mobile'])&&isset($_POST['Pass']) ){
       
   
           $ClientID = $_POST['ClientID'];
	  $Email = $_POST['mobile'];
	  $Pass = $_POST['Pass'];
	 $sql = "SELECT * FROM Account3Name WHERE ClientID = $ClientID AND AcMobileNo = '$Email' AND AcPassward = '$Pass'";
 // include db connect class
    require_once __DIR__ . '/../DBConnect.php';
			$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["NameOfPerson"] = $row["NameOfPerson"];
        $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"] = "Mobile Nubmer Not Register";
      // echoing JSON response
      echo json_encode($response);
    }
  

    
  }else{
    // success
    $response["success"] = 3;
    $response["message"] = "Please Send Required Detail For Login";
    // echoing JSON response
    echo json_encode($response);
  }
?>
