public function search(TDispatch $td, $q = "", $limit = 10, $type = "")
 {
     $url2 = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $q . '&sensor=false';
     $json = file_get_contents(str_replace(" ", "%20", $url2));
     $obj = json_decode($json);
     $count = 0;
     $jsonNew = new stdClass();
     $jsonNew->locations = array();
     $jsonNew->status = $obj->status;
     foreach ($obj->results as $key) {
         if (++$count > 5) {
             break;
         }
         $jsonTemp = new stdClass();
         $jsonTemp->address = $key->formatted_address;
         $jsonTemp->location = array('lat' => $key->geometry->location->lat, 'lng' => $key->geometry->location->lng);
         $jsonTemp->postcode = "";
         array_push($jsonNew->locations, $jsonTemp);
     }
     $jsonss = json_encode($jsonNew);
     $res = $jsonNew;
     if (!isset($res->status) || $res->status !== 'OK') {
         $td->setError($res);
         return false;
     }
     return $res;
 }
 public function fare(TDispatch $td, $pickup_postcode, $dropoff_postcode, $pickup = array(), $dropoff = array(), $waypoints = array())
 {
     $data = array("access_token" => $td->getToken());
     $url = $td->getFullApiUrl() . 'locations/fare?' . http_build_query($data);
     $ch = curl_init();
     $dataSend = array('pickup_postcode' => $pickup_postcode, 'dropoff_postcode' => $dropoff_postcode, 'pickup_location' => $pickup, 'dropoff_location' => $dropoff, 'waypoints' => $waypoints);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, count($dataSend));
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataSend));
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $result = curl_exec($ch);
     $info = curl_getinfo($ch);
     curl_close($ch);
     return json_decode($result, true);
 }
Example #3
0
 public function vehicles_list(TDispatch $td, $limit = 4)
 {
     $data = array("access_token" => $td->getToken());
     $url = $td->getFullApiUrl() . 'vehicletypes?' . http_build_query($data);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $result = curl_exec($ch);
     $res = json_decode($result, true);
     $info = curl_getinfo($ch);
     curl_close($ch);
     if (!isset($res['status']) || $res['status'] !== 'OK') {
         $td->setError($res);
         return false;
     }
     return array_slice($res['vehicle_types'], 0, $limit);
 }
Example #4
0
 public function nearby(TDispatch $td, $limit, $location, $radius, $offset)
 {
     $data = array("access_token" => $td->getToken());
     $url = $td->getFullApiUrl() . 'drivers/nearby?' . http_build_query($data);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_URL, $url);
     $dataSend = array('limit' => $limit, 'location' => $location, 'radius' => $radius, 'offset' => $offset);
     curl_setopt($ch, CURLOPT_POST, count($dataSend));
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataSend));
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $result = curl_exec($ch);
     $res = json_decode($result, true);
     $info = curl_getinfo($ch);
     curl_close($ch);
     if (!isset($res['status']) || $res['status'] !== 'OK') {
         $td->setError($res);
         return false;
     }
     return $res['drivers'];
 }
Example #5
0
<?php

require_once './../app/core/loader.php';
$dispatch = new TDispatch();
$dispatch->dispatch();
$dbh = TDatabase::singleton();
Example #6
0
 public function changePassword(TDispatch $td, $requestBody)
 {
     $data = array("key" => $td->getApiKey());
     $url = $td->getFullApiUrl() . 'accounts/change-password?' . http_build_query($data);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, count($requestBody));
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestBody));
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     if ($td->debug) {
         error_log(__FILE__ . ' in line ' . __LINE__);
         error_log(__CLASS__ . ' in method ' . __METHOD__);
         error_log("URL: " . $url);
         error_log("DATA BODY: " . json_encode($requestBody));
     }
     $result = curl_exec($ch);
     $res = json_decode($result, true);
     $info = curl_getinfo($ch);
     curl_close($ch);
     if (!isset($res['status']) || $res['status'] !== 'OK') {
         $td->setError($res);
         return false;
     }
     return true;
 }
Example #7
0
         }
     }
     break;
 case 'resetPassword':
     $email = isset($_POST['email']) ? $_POST['email'] : '';
     if ($email != '') {
         $out = $td->Account_resetPassword($email);
         if ($out) {
             header('Content-type: application/json');
             echo json_encode($out);
             exit;
         }
     }
     break;
 case 'getLocation':
     $td = new TDispatch();
     $location = isset($_POST['location']) ? $_POST['location'] : '';
     $limit = (int) (isset($_POST['limit']) ? $_POST['limit'] : 10);
     $pickup = isset($_POST['pickup']) && $_POST['pickup'] === 'pickup' ? $_POST['pickup'] : null;
     $out = $td->Location_search($location, $limit, $pickup);
     if ($out) {
         header('Content-type: application/json');
         echo json_encode($out);
         exit;
     }
     break;
 case 'getTrack':
     $td = new TripThru();
     if ($td->Account_checkLogin()) {
         $bookingPk = isset($_POST['bookingPk']) ? $_POST['bookingPk'] : '';
         $partnerId = isset($_POST['partnerId']) ? $_POST['partnerId'] : '';
<?php

/*
 * Script créant et vérifiant que les champs requis s'ajoutent bien
 * 
 */
if (!defined('INC_FROM_DOLIBARR')) {
    define('INC_FROM_CRON_SCRIPT', true);
    require '../config.php';
    $PDOdb = new TPDOdb();
    $PDOdb->debug = true;
} else {
    $PDOdb = new TPDOdb();
}
dol_include_once('/dispatch/class/dispatchdetail.class.php');
dol_include_once('/dispatch/class/dispatchasset.class.php');
dol_include_once('/asset/class/asset.class.php');
$o = new TDispatchDetail();
$o->init_db_by_vars($PDOdb);
$o = new TRecepDetail();
$o->init_db_by_vars($PDOdb);
$o = new TDispatch();
$o->init_db_by_vars($PDOdb);
$o = new TDispatchAsset();
$o->init_db_by_vars($PDOdb);
Example #9
0
 /**
  Obtain an Authorization Code from the API
 */
 public function obtainAutorizationCode(TDispatch $td, $anonimously = true, $CLUsername = "", $CLPassword = "", $fbLogin = false)
 {
     //URL parameters data
     $buildparams = array("client_id" => $this->client_id, "response_type" => "code", "key" => $this->key, "scope" => "");
     //For anonimously requests
     if ($anonimously) {
         $buildparams["grant_type"] = "anonymous";
         $buildparams["response_format"] = "json";
         $databody = json_encode(array());
     } else {
         $buildparams["grant_type"] = "user";
         $buildparams["response_format"] = "json";
         $databody = json_encode(array("username" => $CLUsername, "password" => $CLPassword));
     }
     //TD url
     $url = $this->url . "auth?" . http_build_query($buildparams);
     //Open connection
     $ch = curl_init();
     //Set the url, Number of POST vars, POST data
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $databody);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     //WRITE URL
     //Execute post
     $authrezult = curl_exec($ch);
     $info = curl_getinfo($ch);
     //Close connection
     curl_close($ch);
     $authcode = json_decode($authrezult, true);
     //New call for access_token
     if ($info["http_code"] == "200") {
         //Decode response
         if ($authcode['status'] === 'Failed') {
             $td->setError($authcode);
             return false;
         } else {
             //TD url
             $url = $this->url . "token";
             //Access token parameters
             $data = array("code" => $authcode["auth_code"], "client_id" => $this->client_id, "client_secret" => $this->secret, "redirect_uri" => $this->callback_url, "grant_type" => "authorization_code");
             //Open connection
             $token = curl_init();
             //Set the url, Number of POST vars, POST data
             curl_setopt($token, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($token, CURLOPT_URL, $url);
             curl_setopt($token, CURLOPT_POST, count($data));
             curl_setopt($token, CURLOPT_POSTFIELDS, json_encode($data));
             curl_setopt($token, CURLOPT_SSL_VERIFYPEER, false);
             //Execute post
             $result = curl_exec($token);
             $info = curl_getinfo($token);
             //Close connection
             curl_close($token);
             $response = json_decode($result, true);
             //Check result
             if ($info["http_code"] == "200") {
                 //Revoke anonimous first
                 if (isset($_SESSION['TDISPATCH']['access']["anonimously"])) {
                     $revoke = $this->revokeAuthorization();
                     if ($revoke["status_code"] == "200") {
                         unset($_SESSION['TDISPATCH']['access']["anonimously"]);
                         unset($_SESSION['TDISPATCH']['access']["refresh"]);
                         if (isset($_SESSION['TDISPATCH']['access']) && count($_SESSION['TDISPATCH']['access']) == 0) {
                             unset($_SESSION['TDISPATCH']['access']);
                         }
                         if (isset($_SESSION['TDISPATCH']) && count($_SESSION['TDISPATCH']) == 0) {
                             unset($_SESSION['TDISPATCH']);
                         }
                     }
                 }
                 //Decode json response
                 //Auth info
                 if (!$anonimously) {
                     $_SESSION['TDISPATCH']['access']["refresh"] = $response["refresh_token"];
                     $_SESSION['TDISPATCH']['access']["access_token"] = $response["access_token"];
                 } else {
                     $_SESSION['TDISPATCH']['access']["anonimously"] = $response["access_token"];
                     $_SESSION['TDISPATCH']['access']["refresh"] = $response["refresh_token"];
                 }
                 $this->access_token = $response["access_token"];
                 return true;
             } else {
                 //Show error message
                 $td->setError($response);
                 return false;
             }
         }
     } else {
         //Show error message
         $td->setError($authcode);
         return false;
     }
 }
<?php

require 'config.php';
dol_include_once('/dispatch/class/dispatchasset.class.php');
dol_include_once('/contrat/class/contrat.class.php');
dol_include_once('/product/class/html.formproduct.class.php');
dol_include_once('/fichinter/class/fichinter.class.php');
dol_include_once('/asset/class/asset.class.php');
dol_include_once('/core/lib/product.lib.php');
$PDOdb = new TPDOdb();
$type_object = GETPOST('type_object');
$id = (int) GETPOST('id');
$dispatch = new TDispatch();
$dispatch->loadByObject($PDOdb, $id, $type_object);
$action = GETPOST('action');
switch ($action) {
    case 'save':
        $TLine = GETPOST('TLine');
        if (!empty($TLine[-1]['serial_number']) && (!empty($TLine[-1]['fk_object']) || GETPOST('type_object') === 'ticketsup')) {
            $asset = new TAsset();
            $asset->loadReference($PDOdb, $TLine[-1]['serial_number']);
            if ($asset->getId() > 0) {
                $k = $dispatch->addChild($PDOdb, 'TDispatchAsset');
                $dispatch->TDispatchAsset[$k]->fk_asset = $asset->getId();
                $dispatch->TDispatchAsset[$k]->fk_object = $TLine[-1]['fk_object'];
                $dispatch->TDispatchAsset[$k]->object_type = $type_object;
                $dispatch->TDispatchAsset[$k]->asset = $asset;
                $dispatch->save($PDOdb);
            }
        }
        break;
Example #11
0
 public function Bookings_customfields(TDispatch $td)
 {
     $data = array("access_token" => $td->getToken());
     $url = $td->getFullApiUrl() . 'bookings/custom-fields?' . http_build_query($data);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $result = curl_exec($ch);
     $res = json_decode($result, true);
     $info = curl_getinfo($ch);
     curl_close($ch);
     if (!isset($res['status']) || $res['status'] !== 'OK') {
         $td->setError($res);
         return false;
     }
     return $res['custom_fields'];
 }