<?php
 
/*
 * Following code will list all the city
 */
 
// array for JSON response
$response = array();
 
 require_once __DIR__ . '/catchexception.php';
// include db connect class
require_once __DIR__ . '/db_config.php';
  
$json = file_get_contents('php://input');
$obj = json_decode($json,true); 
$obj = json_decode($json,true);

$deviceid = $obj['deviceid'];
 //$deviceid = 'af1d3239fb6a4880';
 try {
if ($deviceid !="" ) {
   
    $paravanquery="SELECT *  from tblbranchdevicemapping as a where  statuscode='1' and deviceid=$1 and apptype like '%1%'";
      $resultmax=  pg_prepare($con,"paravanquery",$paravanquery);
      $data = [$deviceid];
      $result = pg_execute($con,"paravanquery",$data);

    if (!empty($result)) {
        // check for empty result
        if (pg_num_rows($result) > 0) {
      // user node
             $companyqry="SELECT distinct companyname  from tblcompanydetails limit 1";
             $result1 = pg_query($con,$companyqry );
      if (pg_num_rows($result1) > 0) {
 
              while ($row = pg_fetch_assoc($result1)) { 
                    
             $companyname = $row["companyname"];
            
              }
              
          } 
            // success
            $response["companyname"] = $companyname;
            $response["success"] = 1;
            $response["message"] = "success";
            // echoing JSON response
            echo  json_encode($response);


        } 
        else {
            // no user found
            $response["success"] = 0;
            $response["message"] = "Unauthorized";
 
            // echo no users JSON
            echo json_encode($response);
        }
    } else {
        // no user found
        $response["success"] = 0;
        $response["message"] = "Unauthorized";
 
        // echo no users JSON
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Device Id missing";
 
     echo  json_encode($response);
  }
  mch_db_release($con);
}
//catch exception
catch(Exception $e) {
mch_db_release($con);
echo 'Message: ' .$e->getMessage();
}
?>
