<?php
// include db connect class
require_once __DIR__ . '/../DBConnect.php';
if (isset($_POST['MobileNoOrEmail']) && isset($_POST['ColumnName'])) {
    $MobileNoOrEmail = $_POST['MobileNoOrEmail'];
    $ColumnName=$_POST['ColumnName'];
    $sql = "Select 
    Account3Name.AcNameID As ClientUserID1,
    Account3Name.AcName as UserName,
    Client.NameOfPerson as OwnerName,
    Client.*
From
    Account3Name Left Join
    Client On Client.ClientID = Account3Name.ClientID
Where
    $ColumnName = '$MobileNoOrEmail' And
    Account3Name.UserRights <> 'NotAllowLogin'";

    $stmt = $conn->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    if ($result != null &&  $result > 0) {
        $response["Clients"] = array();
        foreach ($result as $row) {
            $Clients["NameOfPerson"] = $row["OwnerName"];
            $Clients["ID"] = $row["ID"];
            $Clients["ClientID"] = $row["ClientID"];
            $Clients["ClientParentID"] = $row["ClientParentID"];
            $Clients["EntryType"] = $row["EntryType"];
            $Clients["LoginMobileNo"] = $row["LoginMobileNo"];
            $Clients["CompanyName"] = $row["CompanyName"];
            $Clients["CompanyAddress"] = $row["CompanyAddress"];
            $Clients["CompanyNumber"] = $row["CompanyNumber"];
            $Clients["NameOfPerson"] = $row["NameOfPerson"];
            $Clients["Email"] = $row["Email"];
            $Clients["WebSite"] = $row["WebSite"];
            $Clients["CompanyLogo"] = $row["CompanyLogo"];
            $Clients["Password"] = $row["Password"];
            $Clients["ActiveClient"] = $row["ActiveClient"];
            $Clients["Country"] = $row["Country"];
            $Clients["City"] = $row["City"];
            $Clients["SubCity"] = $row["SubCity"];
            $Clients["CapacityOfPersons"] = $row["CapacityOfPersons"];
            $Clients["ClientUserID"] = $row["ClientUserID1"];
            $Clients["UserName"] = $row["UserName"];
            $Clients["SysCode"] = $row["SysCode"];
            $Clients["NetCode"] = $row["NetCode"];
            $Clients["UpdatedDate"] = $row["UpdatedDate"];
            $Clients["Theme"] = $row["Theme"];
            $Clients["Background"] = $row["Background"];
            $Clients["Lat"] = $row["Lat"];
            $Clients["Lng"] = $row["Lng"];
            $Clients["BookingTermsAndCondition"] = $row["BookingTermsAndCondition"];
            $Clients["CBEditCharges"] = $row["CBEditCharges"];
            $Clients["CBEntryCharges"] = $row["CBEntryCharges"];
            $Clients["BillEditCharges"] = $row["BillEditCharges"];
            $Clients["BillEntryCharges"] = $row["BillEntryCharges"];
            $Clients["CountryUserID"] = $row["CountryUserID"];
            $Clients["CountryClientID"] = $row["CountryClientID"];
            $Clients["ProjectID"] = $row["ProjectID"];
            $Clients["BusinessDescriptions"] = $row["BusinessDescriptions"];
            $Clients["FinancialYear"] = $row["FinancialYear"];

            // push single product into final response array
            array_push($response["Clients"], $Clients);
        }
        // success
        $response["success"] = 1;
        // echoing JSON response
        echo json_encode($response);
    } else {
        // success
        $response["success"] = 0;
        $response["message"] = "No Client Availaible";
        // echoing JSON response
        echo json_encode($response);
    }
} else {
    // success
    $response["success"] = 0;
    $response["message"] = "Set All Parameter";
    // echoing JSON response
    echo json_encode($response);
}
