<?php

  // array for JSON response
  $response = array();

   if (isset($_POST['ClientID']) && isset($_POST['Password']) && isset($_POST['ClientUserID'])){
    $ClientID = $_POST['ClientID'];
	  $ClientUserID = $_POST['ClientUserID'];
	  $Password = $_POST['Password'];

    // include db connect class
    require_once __DIR__ . '/DBConnect.php';

    $sql = "SELECT ActiveClient FROM Client WHERE ClientID = $ClientID";
	  //$sql = "SELECT * FROM Client WHERE LoginMobileNo = '03138934156'";

   $stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
	if($result!=null &&  $result>0){
		foreach($result as $row) { 
			if ($row["ActiveClient"] == true) {

        $sql = "SELECT * FROM Account3Name WHERE ClientID = $ClientID AND AcNameID = $ClientUserID AND AcPassward = '$Password'";
          
	$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
	if($result!=null &&  $result>0){
			
				foreach($result as $row) { 
				$UserRights = $row["UserRights"];
			}
			
          $sql = "SELECT * FROM Client WHERE ClientID = $ClientID";
             
	$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
	if($result!=null &&  $result>0){
            $response["UserInfo"] = array();
          foreach($result as $row) { 
			
			$UserInfo["UserRights"] = $UserRights;
              $UserInfo["ClientID"] = $row["ClientID"];
              $UserInfo["ClientParentID"] = $row["ClientParentID"];
              $UserInfo["EntryType"] = $row["EntryType"];
              $UserInfo["LoginMobileNo"] = $row["LoginMobileNo"];
              $UserInfo["CompanyName"] = $row["CompanyName"];
              $UserInfo["CompanyAddress"] = $row["CompanyAddress"];
              $UserInfo["CompanyNumber"] = $row["CompanyNumber"];
              $UserInfo["NameOfPerson"] = $row["NameOfPerson"];
              $UserInfo["Email"] = $row["Email"];
              $UserInfo["WebSite"] = $row["WebSite"];
              $UserInfo["ActiveClient"] = $row["ActiveClient"];
              $UserInfo["Country"] = $row["Country"];
              $UserInfo["City"] = $row["City"];
              $UserInfo["SubCity"] = $row["SubCity"];
              $UserInfo["CapacityOfPersons"] = $row["CapacityOfPersons"];
              $UserInfo["ClientUserID"] = $ClientUserID;
              $UserInfo["SysCode"] = $row["SysCode"];
              $UserInfo["NetCode"] = $row["NetCode"];
              $UserInfo["UpdatedDate"] = $row["UpdatedDate"];
              $UserInfo["Lat"] = $row["Lat"];
              $UserInfo["Lng"] = $row["Lng"];
              $UserInfo["CBEditCharges"] = $row["CBEditCharges"];
              $UserInfo["CBEntryCharges"] = $row["CBEntryCharges"];
              $UserInfo["BillEditCharges"] = $row["BillEditCharges"];
              $UserInfo["BillEntryCharges"] = $row["BillEntryCharges"];
              $UserInfo["CountryUserID"] = $row["CountryUserID"];
              $UserInfo["CountryClientID"] = $row["CountryClientID"];
              $UserInfo["ProjectID"] = $row["ProjectID"];

              // push single product into final response array
        			array_push($response["UserInfo"], $UserInfo);
            }
            // success
        		$response["success"] = 1;
            $response["message"] = "User Info";
            // echoing JSON response
        		echo json_encode($response);
          }else{
			  	// success
        $response["success"] = -4;
        $response["message"] = "Client Not Exist in Client Table ";
        // echoing JSON response
        echo json_encode($response);
		  }
        }else{
			// success
        $response["success"] = -2;
        $response["message"] = "Client Password Not Matched";
        // echoing JSON response
        echo json_encode($response);
		}
      }else {
        // client not active...
        // success
        $response["success"] = -1;
        $response["message"] = "Client Not Active";
        // echoing JSON response
        echo json_encode($response);
      }
		}
    }else {
      // client not found...
      // success
      $response["success"] = 2;
      $response["message"] = "Client Not Found";
      // 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);
  }
?>
