<?php
   set_time_limit(0);
   date_default_timezone_set('Asia/Kolkata');
   error_reporting(0);
   $gtsserver="localhost";//up108eastlocal
   $gtsusername="gts";
   $gtspassword="opengts";
   $gtsdb="gts";
   $tacserver = "localhost";//up108eastlocal
   $tacusername = "root";
   $tacpassword = "gl0v1s10n";
   $tacdb = "autocare_gts";
   $LiveEventDBserver="up108westlocal";   //live server for east,west 
   $LiveEventDBserver2="up108eastlocal";
   $LiveGTS="up108westlocal";
   $apiusername="gvkemri";
   $apipassword="glovision";
   $hsptlaltingtime=180;//Alting Time in Hsptal Zone in Sec
   
   $caseCheckingTime=21600;//86400;//Checking Case For 86400 sec
   $formate='json';
   $accountID='gvk-up-108';
   //test url
   //$triggerUrl="http://test-crm.upeastemri.tk/api/glovision/saveGlovisionTripDetails";
   $triggerUrl="http://up108westcrm.emri.in/api/glovision/saveGlovisionTripDetails";



   function callService($jsonDataEncoded){
    //API URL

       global $triggerUrl;
       $url = $triggerUrl;
       //var_dump($jsonDataEncoded);
     //  $url = 'http://test-crm.upeastemri.tk/api/glovision/saveGlovisionTripDetails';
        //create a new cURL resource
        $ch = curl_init($url);
        //setup request to send json via POST
        $payload = json_encode($jsonDataEncoded);
        //attach encoded JSON string to the POST fields
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        //set the content type to application/json
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
        //return response instead of outputting
//        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        //execute the POST request
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT_MS, 2000);

        $result = curl_exec($ch);
        echo $result;
        //close cURL resource
        curl_close($ch);

}

 function getDeviceServer($accountID,$deviceID) {
    global $gtsserver, $gtsusername, $gtspassword, $gtsdb,$LiveEventDBserver;
    $gtsconnect = mysqli_connect($LiveEventDBserver,$gtsusername,$gtspassword) or die ($gtsserver." Unable to connect to the tacdb : " . mysqli_error($gtsconnect));
    mysqli_select_db($gtsconnect, $gtsdb);
    $request_time_query="Select deviceID from Device where accountID='$accountID' and deviceID='$deviceID' and isActive=1";
   // error_log($request_time_query."  ".$gtsserver);
    $qry_result=mysqli_query($gtsconnect,$request_time_query) or die(mysqli_error($gtsconnect));
   // error_log("completed");
    $deviceFound=false;
    while($row=mysqli_fetch_array($qry_result)) {
       $deviceFound=true;
    }
   // error_log($deviceFound);
    mysqli_close($gtsconnect);
    return $deviceFound;

}


?>
