Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Goexpress extends CI_Controller {
- public $cs_email = 'no-reply@com.com';
- public $is_firebase = false;
- public $bc_action = "";
- public $bc_txno = "";
- public $bc_start_lat = 0;
- public $bc_start_lng = 0;
- protected $linkPage;
- protected $segment = 3;
- protected $totalPage = 0;
- protected $perPage = 20;
- function __construct()
- {
- parent::__construct();
- $this->load->model('user_model');
- $this->load->model('app_model');
- $this->load->model('admin_model');
- $this->load->model('office_model');
- $this->load->model('model_goexpress');
- $this->load->model('security_model');
- $this->load->model('driver_model');
- $this->template->set_template('sbadmin2');
- //$user_info = $this->session->userdata('user_info');
- //if( !isset($user_info->username))
- // redirect('admin/index');
- //load Language
- if ( strlen($this->uri->segment(1)) == 2 )
- $this->lang->load( $this->uri->segment(1), 'gox');
- //Define Api key
- if ( $this->uri->segment(1) == "apikey" ) {
- $apikey = $this->uri->segment(2);
- }
- else {
- $apikey = $this->uri->segment(3);
- }
- $this->apikey = $apikey;
- if ( !$this->security_model->check_api($apikey) )
- {
- if ( $this->uri->segment(4) == "add_txno" )
- die('1@@Your Session is expired, please relogin.');
- else {
- $error_m = array("error" => 1, "error_message" => "Your Session is expired, please relogin.");
- die(json_encode($error_m));
- }
- }
- if ( strlen($this->uri->segment(1)) == 2 )
- $this->client_lang = $this->uri->segment(1);
- else
- $this->client_lang = "en";
- $this->PROMO_ACTIVE = false;
- }
- protected function pagination() {
- $this->load->library('pagination');
- $config = array();
- $config['uri_segment'] = $this->segment;
- $config['base_url'] = $this->linkPage;
- $config['total_rows'] = $this->totalPage;
- $config['per_page'] = $this->perPage;
- $config['full_tag_open'] = '<ul class="pagination">';
- $config['full_tag_close'] = '</ul>';
- $this->pagination->initialize($config);
- return $this->pagination->create_links();
- }
- protected function start_page($uri) {
- if ($this->uri->segment($uri) > 0) {
- $start = $this->uri->segment($uri);
- } else {
- $start = 0;
- }
- return $start;
- }
- function check_new_notif()
- {
- $res = array("error" => 0,
- "notif_id" => 3,
- "show" => 0,
- "message" => "Dear All Driver, \nWe launch lucky draw promotion. So all client will get new lucky point when they completed 5 trip and recursive. \n\nThank you.");
- die(json_encode($res));
- }
- function current_millis()
- {
- list($usec, $sec) = explode(" ", microtime());
- return round(((float)$usec + (float)$sec) * 1000);
- }
- function broadcast_tx($tx, $range)
- {
- $tx_detail = $this->model_goexpress->get_tx_detail(array( 'txno' => $tx));
- $payload = $tx_detail->payload;
- if( !$payload )
- {
- echo '1@@Error: Empty payload';
- die();
- }
- $txno = $tx;
- $json = json_decode($payload);
- $jTarget = $this->_process_jsontarget( $json );
- $start_detail = sprintf("%s\n*) %s", $json->data->Start->Name, $json->data->Start->Note);
- $target_detail = sprintf("%s\n*) %s", $jTarget->Name, $jTarget->Note);
- $USERTYPE_DRIVER = 50;
- $UPTIME = UPTIME; // in Minutes.
- $gcparams = array(
- 'range' => $range,
- 'uptime' => $UPTIME,
- 'client_lat' => $json->data->Start->Lat,
- 'client_lng' => $json->data->Start->Lng,
- );
- $gcresult = $this->_get_coord_nearby($gcparams);
- $dnparams = array(
- 'user_type' => $USERTYPE_DRIVER,
- 'transport' => $json->data->Vehicle,
- 'last_up_time' => $gcresult['last_up_time'],
- 'X1' => $gcresult['X1'],
- 'X2' => $gcresult['X2'],
- 'Y1' => $gcresult['Y1'],
- 'Y2' => $gcresult['Y2'],
- );
- $driver_nearby = $this->model_goexpress->get_driver_nearby($dnparams);
- $this->bc_start_lat = $json->data->Start->Lat;
- $this->bc_start_lng = $json->data->Start->Lng;
- $token_driver = array();
- $token_driver = $this->filter_driver($driver_nearby);
- $data = array(
- "Actionmode" => $json->data->Actionmode,
- "PromoCode" => $tx_detail->promo_code,
- "Vehicle" => $json->data->Vehicle,
- "TxNo" => $txno,
- "Distance" => $json->data->DistanceTotalText,
- "Duration" => $json->data->DurationTotalText,
- "Fares" => $json->data->Fares,
- "Payment" => $json->data->Payment,
- "From" => $start_detail,
- "To" => $target_detail,
- "SToken" => $json->data->SToken,
- "StartLat" => $json->data->Start->Lat,
- "StartLng" => $json->data->Start->Lng,
- "TargetLat" => $jTarget->Lat,
- "TargetLng" => $jTarget->Lng,
- "Timestamp" => number_format($this->current_millis(),0,'',''),
- );
- if( !empty($token_driver) )
- $this->sendFirebaseCloudMessage(
- $data,
- $ids = array() ,
- array('separate' => True, 'registration_ids' => $token_driver ),
- array('ret_int' => True) );
- }
- function second_bc($tx)
- {
- // validate the driver
- $this->bc_action = "Second Broadcast";
- $this->bc_txno = $tx;
- $this->broadcast_tx($tx, (SECOND_BC_RANGE * COORD_IN_KM));
- $res = array( 'error' => 0, 'error_message' => '');
- query_log('Second Broadcast Work');
- die(json_encode($res));
- }
- function third_bc($tx)
- {
- $this->bc_action = "Third Broadcast";
- $this->bc_txno = $tx;
- $this->broadcast_tx($tx, (THIRD_BC_RANGE * COORD_IN_KM));
- $res = array('error' => 0, 'error_message' => '');
- query_log('Third Broadcast Work');
- die(json_encode($res));
- }
- function manual_bc($tx, $token)
- {
- $tx_detail = $this->model_goexpress->get_tx_detail(array( 'txno' => $tx));
- $payload = $tx_detail->payload;
- if( !$payload )
- {
- echo '1@@Error: Empty payload';
- die();
- }
- $txno = $tx;
- $json = json_decode($payload);
- $jTarget = $this->_process_jsontarget( $json );
- $start_detail = sprintf("%s\n*) %s", $json->data->Start->Name, $json->data->Start->Note);
- $target_detail = sprintf("%s\n*) %s", $jTarget->Name, $jTarget->Note);
- $this->bc_action = "Manual Broadcast";
- $this->bc_txno = $tx;
- $drvparams = array('last_bc' => time(),
- 'bc_action' => "Manual Broadcast",
- 'bc_tx' => $tx );
- $driverdata = $this->model_goexpress->get_user(array("token" => $token));
- $this->model_goexpress->update_driver_lastbc($drvparams, $driverdata->id);
- $token_driver[0] = $token;
- $data = array(
- "Actionmode" => $json->data->Actionmode,
- "PromoCode" => $tx_detail->promo_code,
- "Vehicle" => $json->data->Vehicle,
- "TxNo" => $txno,
- "Distance" => $json->data->DistanceTotalText,
- "Duration" => $json->data->DurationTotalText,
- "Fares" => $json->data->Fares,
- "Payment" => $json->data->Payment,
- "From" => $start_detail,
- "To" => $target_detail,
- "SToken" => $json->data->SToken,
- "StartLat" => $json->data->Start->Lat,
- "StartLng" => $json->data->Start->Lng,
- "TargetLat" => $jTarget->Lat,
- "TargetLng" => $jTarget->Lng,
- "Timestamp" => number_format($this->current_millis(),0,'',''),
- );
- if( !empty($token_driver) )
- $this->sendFirebaseCloudMessage(
- $data,
- $ids = array() ,
- array('separate' => True, 'registration_ids' => $token_driver ),
- array('ret_int' => True) );
- $resjson = array( 'error' => 0,
- 'error_message' => "Broadcast Tx Success");
- die(json_encode($resjson));
- }
- function _process_jsontarget( $json )
- {
- $targetlength = count($json->data->Target);
- $iTgt = $targetlength - 1;
- $jTarget = new StdClass();
- $jTarget->Name = $json->data->Target[$iTgt]->Name;
- $jTarget->Note = $json->data->Target[$iTgt]->Note;
- $jTarget->Lat = $json->data->Target[$iTgt]->Lat;
- $jTarget->Lng = $json->data->Target[$iTgt]->Lng;
- if ( isset($json->data->UserID) )
- $userid = $json->data->UserID;
- else
- $userid = "";
- $this->model_goexpress->add_search_data($json->data->Target, $userid, "target");
- $this->model_goexpress->add_search_data($json->data->Start, $userid, "start");
- return $jTarget;
- }
- function getPromoCode($transport)
- {
- $promo_code = "";
- if ( priceRate() == floatval("0.1") ) {
- if ( $transport == "MOTOBIKE")
- $promo_code = "GOXBIKE10";
- else if ( $transport == "TUK-TUK")
- $promo_code = "GOXTUKTUK10";
- else if ( $transport == "TAXI" )
- $promo_code = "GOXCAR10";
- else if ( $transport == "CAR" )
- $promo_code = "GOXMVAN10";
- }
- else if ( priceRate() == floatval("0.2") ) {
- if ( $transport == "MOTOBIKE")
- $promo_code = "GOXBIKE20";
- else if ( $transport == "TUK-TUK")
- $promo_code = "GOXTUKTUK20";
- else if ( $transport == "TAXI" )
- $promo_code = "GOXCAR20";
- else if ( $transport == "CAR" )
- $promo_code = "GOXMVAN20";
- }
- else if ( priceRate() == floatval("0.15") ) {
- if ( $transport == "MOTOBIKE")
- $promo_code = "GOXBIKE15";
- else if ( $transport == "TUK-TUK")
- $promo_code = "GOXTUKTUK15";
- else if ( $transport == "TAXI" )
- $promo_code = "GOXCAR15";
- else if ( $transport == "CAR" )
- $promo_code = "GOXMVAN15";
- }
- else if ( priceRate() == floatval("0.3") ) {
- if ( $transport == "MOTOBIKE")
- $promo_code = "GOXBIKE30";
- else if ( $transport == "TUK-TUK")
- $promo_code = "GOXTUKTUK30";
- else if ( $transport == "TAXI" )
- $promo_code = "GOXCAR30";
- else if ( $transport == "CAR" )
- $promo_code = "GOXMVAN30";
- }
- else {
- if ( $transport == "MOTOBIKE")
- $promo_code = "GOXBIKE";
- else if ( $transport == "TUK-TUK")
- $promo_code = "GOXTUKTUK";
- else if ( $transport == "TAXI" )
- $promo_code = "GOXCAR";
- else if ( $transport == "CAR" )
- $promo_code = "GOXMVAN";
- }
- return $promo_code;
- }
- function getfares()
- {
- $input_payload = file_get_contents('php://input');
- // validate the driver
- $json = json_decode($input_payload,true);
- if ( $this->model_goexpress->checkDistance($json) == 1 )
- {
- $returndata = array(
- "error" => 3,
- "error_message" => "Your total distance exceed ".getMaxdistance($json['transport'])." km..");
- }
- else {
- $userRecord = $this->model_goexpress->get_user(array("username" => $json["id"]));
- $json["id"] = $userRecord->id;
- $json["all_data"] = 1;
- // PROMO DIFFERENT DISCOUNT FOR EACH TRANSPORT
- if( !(isset($json["promo_code"]) and $json["promo_code"] != "" and $json["promo_code"] != " " )) {
- if ( $this->PROMO_ACTIVE == true ) {
- $json["promo_code"] = $this->getPromoCode($json["transport"]);
- }
- }
- list($total_price, $normal_fare, $promo_value) = $this->model_goexpress->getFares($json);
- $returndata = array(
- "error" => 0,
- "fares" => $total_price,
- "promo_value" => $promo_value,
- "normal_fare" => $normal_fare,
- "error_message" => "");
- }
- die( json_encode($returndata));
- }
- function gethistory()
- {
- $payload = file_get_contents('php://input');
- if( !$payload )
- {
- echo '1@@Error: Empty payload';
- die();
- }
- $json = json_decode( $payload );
- $params['userid'] = $json->id;
- $params['searchtype'] = $json->type;
- $res = $this->model_goexpress->get_location_data($params);
- echo json_encode($res);
- }
- function add_txno()
- {
- $payload = file_get_contents('php://input');
- if( !$payload )
- {
- echo '1@@Error: Empty payload';
- die();
- }
- $txno = number_format($this->current_millis(),0,'','');
- $json = json_decode( $payload );
- if( !isset( $json->data->UserEmail ) )
- {
- echo '1@@Error: Empty Email';
- die();
- }
- $distanceData = array("transport" => $json->data->Vehicle,
- "distance" => floatval(str_replace(" km","",$json->data->DistanceTotalText))*1000);
- if ( $this->model_goexpress->checkDistance($distanceData) == 1 )
- {
- echo '1@@Your total distance exceed '.getMaxdistance($distanceData['transport']).' km..';
- die();
- }
- $uparams = array(
- 'email' => $json->data->UserEmail,
- 'username' => $json->data->UserID,
- );
- if ( isset($json->map_data))
- {
- $this->model_goexpress->save_map(array( 'txno' => $txno,
- 'map_data' => json_encode($json->map_data)
- )
- );
- }
- $url_parts = parse_url(current_url());
- $source= "unknown";
- $source_list = array("goexpress", "demo", "alpha");
- if ( isset($url_parts) ) {
- $raw_path = explode("/",$url_parts['path']);
- if ( isset($raw_path[1]) ) {
- if ( in_array($raw_path[1], $source_list )) {
- $source = $raw_path[1];
- }
- }
- }
- $userrecord = $this->model_goexpress->get_user($uparams);
- if ( $userrecord->firebase == 1 )
- $this->is_firebasse = true;
- $this->db->trans_start();
- if( !isset($userrecord->id))
- {
- echo "1@@Error: User is not registered. Please clear data and relogin/register new User";
- die();
- $USERTYPE_CLIENT = 90;
- $uparams['name'] = $json->data->UserName;
- $uparams['user_type_id'] = $USERTYPE_CLIENT;
- $uparams['source_type_id'] = SOURCETYPE_STR_TO_INT($json->data->ModeLogin);
- $uparams['create_date'] = date('Y-m-d H:i:s');
- list($flag, $client_id, $msg ) = $this->model_goexpress->add_user($uparams);
- if( !$flag )
- {
- echo '1@@'.$msg;
- $this->db->trans_rollback();
- die();
- }
- }
- else
- {
- $client_id = $userrecord->id;
- }
- // For testing purpose
- //echo "1@@Error: User is registered";
- //die();
- $promo_code = "";
- if( isset($json->data->PromoCode) and $json->data->PromoCode != "" and $json->data->PromoCode != " ")
- $promo_code = $json->data->PromoCode;
- else {
- // DIFFERENT DISCOUNT FOR EACH TRANSPORT
- if ( $this->PROMO_ACTIVE == true ) {
- $json->data->PromoCode = $this->getPromoCode($json->data->Vehicle);
- $promo_code = $this->getPromoCode($json->data->Vehicle);
- }
- }
- // PROMO FIX PRICE 2000 KHR FOR EACH MODE
- if ( PROMO_ONLY_2000 == true ) {
- if ( $promo_code == "" )
- $promo_code = "PROMO_ONLY_2000";
- }
- $calculate_data = array(
- "promo_code" => $promo_code,
- "transport" => $json->data->Vehicle,
- "distance" => floatval(str_replace(" km","",$json->data->DistanceTotalText))*1000,
- "duration" => $json->data->DurationTotalText,
- "id" => $userrecord->id
- );
- $json->data->Fares = $this->model_goexpress->getFares($calculate_data);
- $normalPrice = $this->model_goexpress->getNormalFares($calculate_data);
- // Temp Promo 1 Dollar
- $defaultPromo = 0;
- if ( PROMO_ONLY_2000 == true && getPromoOneDollar($json->data->Vehicle) < $normalPrice ) {
- $defaultPromo = $normalPrice - getPromoOneDollar($json->data->Vehicle);
- }
- if( isset($userrecord->id) ) {
- $promoValue = $this->model_goexpress->getDeduction(
- array("promo_code" => $promo_code,
- "userid" => $userrecord->id ));
- }
- else
- $promoValue = 0;
- $comissionParams = array ( "transport" => $json->data->Vehicle,
- "mode" => $json->data->Actionmode);
- $officeComission = $normalPrice * getComissionRate($comissionParams);
- $driverFee = $normalPrice - $officeComission;
- if ( floatval($promoValue) <= 1 )
- {
- $promoValue = $normalPrice*floatval($promoValue);
- }
- // Temp Promo 1 Dollar
- $promoValue += $defaultPromo;
- if ( $promoValue > $normalPrice ) {
- $promoValue = $normalPrice;
- }
- query_log("Payment value is ". $json->data->Payment);
- if ( $json->data->Payment == "WALLET")
- {
- $balance =$this->model_transactions->get_wallet_balance($json->data->UserID);
- query_log("Balance is ".$balance);
- if ( $json->data->Fares > $balance )
- {
- query_log("You don't have anough balance. Needed Fares is ".$json->data->Fares);
- die("1@@You don't have anough balance to complete the payment. Your balance is ".$balance);
- }
- else
- {
- $data = array( "id" => $json->data->UserID,
- "type" => 99,
- "note" => "Make a payment for TX with no $txno",
- "txno" => $txno,
- "tx_data" => date('Y-m-d H:i:s'),
- "amount" => intval($json->data->Fares*(-1)));
- $this->model_transactions->rm_wallet($data);
- query_log("Processing Remove wallet! Now balance is ".$this->model_transactions->get_wallet_balance($json->data->UserID));
- }
- }
- else {
- }
- if ( strlen($promo_code) == 4 ) {
- $referal = 1;
- }
- else
- $referal = 0;
- query_log("Referal is $referal and Model referal data is " . $this->model_goexpress->referal );
- $USERTYPE_DRIVER = 50;
- $RANGE = FIRST_BC_RANGE * COORD_IN_KM; // in Km.
- $UPTIME = UPTIME; // in Minutes.
- $gcparams = array(
- 'range' => $RANGE,
- 'uptime' => $UPTIME,
- 'client_lat' => $json->data->Start->Lat,
- 'client_lng' => $json->data->Start->Lng,
- );
- $gcresult = $this->_get_coord_nearby($gcparams);
- $dnparams = array(
- 'user_type' => $USERTYPE_DRIVER,
- 'transport' => $json->data->Vehicle,
- 'last_up_time' => $gcresult['last_up_time'],
- 'X1' => $gcresult['X1'],
- 'X2' => $gcresult['X2'],
- 'Y1' => $gcresult['Y1'],
- 'Y2' => $gcresult['Y2'],
- );
- $driver_nearby = $this->model_goexpress->get_driver_nearby($dnparams);
- // echo '1@@TEST@@';
- //var_dump($driver_nearby, $this->db->last_query());
- //error_log(json_encode($driver_nearby),$this->db->last_query());
- //die();
- $newpayload = json_decode($payload);
- $newpayload->data->hp = $userrecord->hp;
- $newpayload->data->office_phone = OFFICE_PHONE;
- $newpayload->data->Fares = $json->data->Fares;
- $newpayload->data->lang = $this->uri->segment(1);
- $payload = json_encode($newpayload);
- $tx_date = date('Y-m-d H:i:s');
- $data = array(
- 'txno' => $txno,
- 'payload' => $payload,
- 'client_id' => $client_id,
- 'tx_date' => $tx_date,
- 'fares' => $json->data->Fares,
- 'payment' => $json->data->Payment,
- 'action_mode' => $json->data->Actionmode,
- 'promo_code' => $promo_code,
- 'ack_status_id' => 0,
- 'is_referal' => $referal,
- 'promo_deduction' => $promoValue,
- 'normal_price' => $normalPrice,
- 'comission' => $officeComission,
- 'comission_rate' => getComissionRate($comissionParams)
- );
- if ( count($driver_nearby) == 0 ) {
- list($tx2_flag, $tx2_id, $tx2_msg) = $this->model_goexpress->save_tx_no_driver($data);
- $vhc_params = array("str" => $json->data->Vehicle);
- $vehicle_record = $this->model_goexpress->get_vehicle($vhc_params);
- // do gcm sending
- $ordermon_params = array(
- "title" => "tx2",
- "id" => $tx2_id,
- "txno" => $txno,
- "lat" => $json->data->Start->Lat,
- "lng" => $json->data->Start->Lng,
- "vehicleID" => $vehicle_record->id,
- "vehicleName" => $json->data->Vehicle,
- "payload" => "",
- "actionMode" => $json->data->Actionmode,
- "clientHp" => $userrecord->hp,
- "clientName" => $userrecord->name,
- "clientEmail" => $userrecord->email,
- "txDate" => $tx_date,
- "source" => $source
- );
- $this->gcm_ordermon("tx2", $ordermon_params);
- if ( $this->uri->segment(1) == "km") {
- die("1@@សូមអភ័យទោស មិនមានអ្នកបើកបររបស់យើងនៅក្បែរលោកអ្នកនោះទេ។ សូមអរគុណដល់អតិថិជនទាំងអស់ដែលជួយគ្រាំទ្រដល់ GO-X។ សូមមេត្តាព្យាយាមម្តងទៀត នៅខណះពេលណាមួយ។");
- }
- else {
- die("1@@Sorry, our driver aren't near you. \nThank you to keep support us by retrying after a few moment");
- }
- }
- list($flag, $id, $msg ) = $this->model_goexpress->add_tx($data);
- $tx_id = $id;
- if ( ACTIVITY_RECORD == true ) {
- $map_data = $json->map_data;
- //var_dump($map_data);
- if ( is_array($map_data) ) {
- $directions = array();
- for ( $directionno = 0; $directionno < count($map_data); $directionno++ ) {
- $mapDetail = json_decode($map_data[$directionno]);
- if ( isset($mapDetail->routes[0]->overview_polyline->points)) {
- $directions[$directionno] = $mapDetail->routes[0]->overview_polyline->points;
- }
- else if ( isset($mapDetail->routes->overview_polyline)) {
- $directions[$directionno] = $mapDetail->routes->overview_polyline;
- }
- else if ( isset($mapDetail->routes[0]->polyline->points) ) {
- $directions[$directionno] = $mapDetail->routes[0]->polyline->points;
- }
- else {
- }
- }
- }
- $txDetail= array ( "txno" => $data["txno"],
- "start" => $json->data->Start,
- "target" => $json->data->Target,
- "direction" => $directions,
- "client_username" => $userrecord->username );
- $activityDetail = array ( "type" => "tx_add",
- "tx" => $txDetail);
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- if( $flag )
- {
- echo '0@@'.$txno.'@@';
- $this->db->trans_commit();
- }
- else
- {
- echo '1@@'.$msg.'@@';
- $this->db->trans_rollback();
- }
- // ******* Update TX_EMAIL ****** //
- if($flag)
- {
- $txeparams = array(
- 'txno' => $txno,
- 'mail_type' => 1,
- 'tx_date' => $data['tx_date'],
- 'mail_status' => 99,
- );
- list($flag, $id, $msg) = $this->_update_tx_email($txeparams);
- if(!$flag)
- {
- log_message('error',sprintf('%s (%s): %s, %s', __FILE__,__LINE__,'TX_EMAIL with ID:'.$id.' '.$msg, $txeparams));
- }
- }
- // ********* END TX_EMAIL ********* //
- $jTarget = $this->_process_jsontarget( $json );
- $start_detail = sprintf("%s\n*) %s", $json->data->Start->Name, $json->data->Start->Note);
- $target_detail = sprintf("%s\n*) %s", $jTarget->Name, $jTarget->Note);
- $token_driver = array();
- $this->bc_action = "First Broadcast";
- $this->bc_txno = $txno;
- $this->bc_start_lat = $json->data->Start->Lat;
- $this->bc_start_lng = $json->data->Start->Lng;
- $token_driver = $this->filter_driver($driver_nearby);
- $data = array(
- "Actionmode" => $json->data->Actionmode,
- "PromoCode" => $promo_code,
- "Vehicle" => $json->data->Vehicle,
- "TxNo" => $txno,
- "Distance" => $json->data->DistanceTotalText,
- "Duration" => $json->data->DurationTotalText,
- "Fares" => $json->data->Fares,
- "Payment" => $json->data->Payment,
- "From" => $start_detail,
- "To" => $target_detail,
- "SToken" => $json->data->SToken,
- "StartLat" => $json->data->Start->Lat,
- "StartLng" => $json->data->Start->Lng,
- "TargetLat" => $jTarget->Lat,
- "TargetLng" => $jTarget->Lng,
- "Hp" => $userrecord->hp,
- "NormalFare" => $normalPrice,
- "PromoDeduction" => $promoValue,
- "Timestamp" => number_format($this->current_millis(),0,'',''),
- );
- if( !empty($token_driver) )
- {
- $this->sendFirebaseCloudMessage( $data, $ids = array() , array('separate' => True, 'registration_ids' => $token_driver ));
- $vhc_params = array("str" => $json->data->Vehicle);
- $vehicle_record = $this->model_goexpress->get_vehicle($vhc_params);
- // do gcm sending
- $ordermon_params = array(
- "title" => "tx",
- "id" => $tx_id,
- "txno" => $txno,
- "lat" => $json->data->Start->Lat,
- "lng" => $json->data->Start->Lng,
- "vehicleID" => $vehicle_record->id,
- "vehicleName" => $json->data->Vehicle,
- "txDate" => $tx_date,
- "source" => $source,
- "actionMode" => $json->data->Actionmode,
- "clientHp" => $userrecord->hp,
- "clientName" => $userrecord->name,
- "clientEmail" => $userrecord->email,
- "payload" => "",
- );
- $this->gcm_ordermon("tx", $ordermon_params);
- }
- die();
- }
- function tx_list()
- {
- $this->gox_acl->validate_read();
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data = array();
- if( isset($_GET['status']) and $_GET['status'] == 'ALL')
- { /* Do nothing, since null will query all*/ }
- elseif( isset($_GET['status']) and $_GET['status'] != '')
- $params['status_id'] = array($_GET['status']) ;
- if($this->input->get('view') == 'P') {
- $this->linkPage = site_url("goexpress/tx_list/");
- $this->segment = 3;
- $this->perPage = 20;
- $params['offset']= $this->start_page($this->segment);
- $params['limit'] = $this->perPage;
- $this->totalPage = $this->model_goexpress->get_tx($params, true);
- }
- $params['from'] = isset($_GET['from']) ? to_date($this->input->get('from')) : date('Y-m-01');
- $params['to'] = isset($_GET['to']) ? to_date($this->input->get('to')) : date('Y-m-t');
- $params['driver'] = trim($this->input->get('driver'));
- $params['client'] = trim($this->input->get('client'));
- $params['txno'] = trim($this->input->get('txno'));
- $data['records'] = $this->model_goexpress->get_tx($params, false);
- $data['paging'] = $this->pagination();
- $data['params'] = $params;
- $this->template->write_view('content','goexpress/tx_list',$data);
- $this->template->render();
- }
- function tx_detail($id)
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data = array();
- $data['records'] = $this->model_goexpress->get_tx_detail(array('txno'=>$id));
- $this->load->view('goexpress/tx_detail', $data);
- }
- function client_profile($id)
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data = array();
- $data['records'] = $this->model_goexpress->get_client(array('client_id'=>$id));
- $this->load->view('goexpress/client_detail', $data);
- }
- function tx_tracking($id)
- {
- $data = array();
- $data['records'] = $this->model_goexpress->get_tx_detail(array('txno'=>$id));
- $this->load->view('goexpress/tx_tracking', $data);
- }
- function tx_history($id)
- {
- $data = array();
- $data['records'] = $this->model_goexpress->get_tx_all(array('driver_id'=>$id));
- $this->load->view('goexpress/tx_history', $data);
- }
- function tx_list_dummy()
- {
- $data = array();
- $_POST['order_by'] = 'id desc';
- $data['records'] = $this->model_goexpress->get_tx($this->input->post());
- $this->template->write_view('content','goexpress/tx_list',$data);
- $this->template->render();
- }
- /*BAP*/
- function tx_list_two()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data = array();
- if( isset($_GET['status']) and $_GET['status'] == 'ALL')
- { /* Do nothing, since null will query all*/ }
- elseif( isset($_GET['status']) and $_GET['status'] != '')
- $params['status_id'] = array($_GET['status']) ;
- if($this->input->get('view') == 'P') {
- $this->linkPage = site_url("goexpress/tx_list_two/");
- $this->segment = 3;
- $this->perPage = 20;
- $params['offset']= $this->start_page($this->segment);
- $params['limit'] = $this->perPage;
- $this->totalPage = $this->model_goexpress->get_tx_two($params, true);
- }
- $params['from'] = isset($_GET['from']) ? to_date($this->input->get('from')) : date('Y-m-01');
- $params['to'] = isset($_GET['to']) ? to_date($this->input->get('to')) : date('Y-m-t');
- $params['driver'] = trim($this->input->get('driver'));
- $params['client'] = trim($this->input->get('client'));
- $params['txno'] = trim($this->input->get('txno'));
- $data['records'] = $this->model_goexpress->get_tx_two($params, false);
- $data['paging'] = $this->pagination();
- $data['params'] = $params;
- $this->template->write_view('content','goexpress/tx_list_two',$data);
- $this->template->render();
- }
- function tx_detail_two($id)
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data = array();
- $data['records'] = $this->model_goexpress->get_tx_detail_two(array('txno'=>$id));
- $this->load->view('goexpress/tx_detail_two', $data);
- }
- function order_receipt_detail_two($id){
- $dataList = array();
- $rawdata = $this->model_goexpress->get_tx_detail1_two(array('txno'=>$id));
- $data = json_decode($rawdata->payload)->data;
- if(isset($data->Actionmode)){
- if($data->Actionmode == 'FOOD'){
- if(isset($data->Start->XfoodNote)){
- if(isset($data->Start->XfoodNote->restoname)){
- $dataList['resto_name'] = $data->Start->XfoodNote->restoname;
- } else {
- $dataList['resto_name'] = null;
- }
- if(isset($data->Start->XfoodNote->restoaddress)){
- $dataList['resto_address'] = $data->Start->XfoodNote->restoaddress;
- } else {
- $dataList['resto_address'] = null;
- }
- if(isset($data->Start->XfoodNote->list_order)){
- $dataList['records'] = $data->Start->XfoodNote->list_order;
- } else {
- $dataList['records'] = null;
- }
- if(isset($data->Start->XfoodNote->notes)){
- $dataList['notes'] = $data->Start->XfoodNote->notes;
- } else {
- $dataList['notes'] = null;
- }
- if(isset($data->Start->XfoodNote->total)){
- $dataList['est_total'] = $data->Start->XfoodNote->total;
- } else {
- $dataList['est_total'] = null;
- }
- // die(var_dump($dataList));
- $this->load->view('webview/xfood_receipt_detail', $dataList);
- }
- }
- // *** If Shopping *** //
- // else if($data->Actionmode == 'SHOPPING') {
- // if(isset($data->Start->XshoppingNote)){
- // $dataList['records'] = $data->Start->XshoppingNote->list_order;
- // $this->load->view('webview/xshopping_receipt', $dataList);
- // }
- // }
- // *** END If Shopping *** //
- else {
- if(isset($data->Start->Note) && strlen($data->Start->Note) >= 3){
- $dataList['note'] = $data->Start->Note;
- }
- else {
- $dataList['note'] = "No Note Available!";
- }
- $this->load->view('webview/global_receipt_detail', $dataList);
- }
- }
- }
- /*BAP*/
- function gcm_send_json($txno = null)
- {
- $RANGE = THIRD_BC_RANGE * COORD_IN_KM; // in Km.
- $UPTIME = UPTIME; // in Minutes.
- $user_info = $this->session->userdata('user_info');
- $USERTYPE_DRIVER = 50;
- if( !isset($user_info->username))
- show_404();
- if(is_null($txno))
- {
- $resjson = array('error' => 1,'error_message' => lang('ErrorIdIsNull'));
- die(json_encode($resjson));
- }
- $OPEN = 0;
- //------------------------------
- // Payload data you want to send
- // to Android device (will be
- // accessible via intent extras)
- //------------------------------
- $tparams = array('txno'=> $txno);
- $record = $this->model_goexpress->get_tx($tparams);
- if( empty($record) )
- {
- $resjson = array('error' => 1,'error_message' => lang('ErrorRecordEmpty'));
- die(json_encode($resjson));
- }
- $record = $record[0];
- if( !isset($record->payload) )
- {
- $resjson = array('error' => 1,'error_message' => lang('ErrorPayloadEmpty'));
- die(json_encode($resjson));
- }
- $json = json_decode( $record->payload );
- $jTarget = $this->_process_jsontarget( $json );
- $start_detail = sprintf("%s\n*) %s", $json->data->Start->Name, $json->data->Start->Note);
- $target_detail = sprintf("%s\n*) %s", $jTarget->Name, $jTarget->Note);
- $promo_code = "";
- if( isset($json->data->PromoCode) and $json->data->PromoCode != "")
- $promo_code = $json->data->PromoCode;
- $bBc_all = true;
- $token_driver = array();
- if( $json->data->SToken == OFFICE_LOGIN )
- {
- $office_tx = $this->office_model->get_order(array("txno"=> $txno ));
- if( isset($office_tx->driver_stoken ) and $office_tx->driver_stoken != "" )
- {
- $token_driver[] = $office_tx->driver_stoken;
- $bBc_all = false;
- }
- }
- if( $bBc_all )
- {
- $gcparams = array(
- 'range' => $RANGE,
- 'uptime' => $UPTIME,
- 'client_lat' => $json->data->Start->Lat,
- 'client_lng' => $json->data->Start->Lng,
- );
- $gcresult = $this->_get_coord_nearby($gcparams);
- $dnparams = array(
- 'user_type' => $USERTYPE_DRIVER,
- 'transport' => $json->data->Vehicle,
- 'last_up_time' => $gcresult['last_up_time'],
- 'X1' => $gcresult['X1'],
- 'X2' => $gcresult['X2'],
- 'Y1' => $gcresult['Y1'],
- 'Y2' => $gcresult['Y2'],
- );
- $driver_nearby = $this->model_goexpress->get_driver_nearby($dnparams);
- $this->bc_start_lat = $json->data->Start->Lat;
- $this->bc_start_lng = $json->data->Start->Lng;
- $token_driver = $this->filter_driver($driver_nearby);
- }
- $data = array(
- "Actionmode" => $json->data->Actionmode,
- "PromoCode" => $promo_code,
- "Vehicle" => $json->data->Vehicle,
- "TxNo" => $txno,
- "Distance" => $json->data->DistanceTotalText,
- "Duration" => $json->data->DurationTotalText,
- "Fares" => $json->data->Fares,
- "Payment" => $json->data->Payment,
- "From" => $start_detail,
- "To" => $target_detail,
- "SToken" => $json->data->SToken,
- "StartLat" => $json->data->Start->Lat,
- "StartLng" => $json->data->Start->Lng,
- "TargetLat" => $jTarget->Lat,
- "TargetLng" => $jTarget->Lng,
- "Timestamp" => number_format($this->current_millis(),0,'',''),
- );
- //------------------------------
- // The recipient registration IDs
- // that will receive the push
- // (Should be stored in your DB)
- //
- // Read about it here:
- // http://developer.android.com/google/gcm/
- //------------------------------
- $ids = array( 'abc', 'def' );
- //------------------------------
- // Call our custom GCM function
- //------------------------------
- if( !empty($token_driver))
- $bresult = $this->sendFirebaseCloudMessage( $data, $ids, array('registration_ids' => $token_driver ), array('ret_int' => true));
- else
- $bresult = false;
- if( $bresult )
- {
- $resjson = array('error' => 0, 'error_message' => 'Success');
- }
- else
- {
- $resjson = array('error' => 1, 'error_message' => 'Error: BC to Drivers are failed');
- }
- die(json_encode($resjson));
- }
- function gcm_send($txno = null)
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $OPEN = 0;
- //------------------------------
- // Payload data you want to send
- // to Android device (will be
- // accessible via intent extras)
- //------------------------------
- if( $txno != null )
- {
- $tparams = array('txno'=>$txno);
- }
- else
- {
- $tparams = array(
- 'limit'=>1,
- 'status_id' => $OPEN,
- 'order_by' => 'id desc',
- );
- }
- $record = $this->model_goexpress->get_tx($tparams);
- if( empty($record) )
- {
- die('1@@No Tx');
- }
- $record = $record[0];
- if( !isset($record->payload) )
- {
- die('1@@No Payload');
- }
- $json = json_decode( $record->payload );
- $jTarget = $this->_process_jsontarget( $json );
- $start_detail = sprintf("%s\n*) %s", $json->data->Start->Name, $json->data->Start->Note);
- $target_detail = sprintf("%s\n*) %s", $jTarget->Name, $jTarget->Note);
- $promo_code = "";
- if( isset($json->data->PromoCode) and $json->data->PromoCode != "")
- $promo_code = $json->data->PromoCode;
- $data = array(
- "Actionmode" => $json->data->Actionmode,
- "PromoCode" => $promo_code,
- "Vehicle" => $json->data->Vehicle,
- "TxNo" => $record->txno,
- "Distance" => $json->data->DistanceTotalText,
- "Duration" => $json->data->DurationTotalText,
- "Fares" => $json->data->Fares,
- "Payment" => $json->data->Payment,
- "From" => $start_detail,
- "To" => $target_detail,
- "SToken" => $json->data->SToken,
- "StartLat" => $json->data->Start->Lat,
- "StartLng" => $json->data->Start->Lng,
- "TargetLat" => $jTarget->Lat,
- "TargetLng" => $jTarget->Lng,
- "Timestamp" => number_format($this->current_millis(),0,'',''),
- );
- //------------------------------
- // The recipient registration IDs
- // that will receive the push
- // (Should be stored in your DB)
- //
- // Read about it here:
- // http://developer.android.com/google/gcm/
- //------------------------------
- $ids = array( 'abc', 'def' );
- //------------------------------
- // Call our custom GCM function
- //------------------------------
- $bresult = $this->sendFirebaseCloudMessage( $data, $ids, null, array('stoken'=>'fxsN86pecxA:APA91bGbIFQYOWD26w44Ws3hytx6fSBnSZr9r4MmvHnrShDwv3dgcW8wgM8frU4a7Iz12RF9GiIuIzD2hOV-mBClK1k8cDpb8MLcKySAngGxOwKbLjlof8Fpcpeyr9JOX0Bhser18lAq'));
- var_dump($bresult);
- }
- function send_data_fcm($token)
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data = array(
- "test" => "Hello GoX",
- );
- $bresult = $this->sendFirebaseCloudMessage( $data, null, null, array('stoken'=> $token, 'separate' => true, 'ret_int' => 1) );
- var_dump($bresult);
- }
- //------------------------------
- // Define custom GCM function
- //------------------------------
- function sendGoogleCloudMessage( $data, $ids, $params = array(), $options = array() )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- $apiKey = 'AIzaSyAMC9GU3zMDCOf8r2kZvVfJMhbGrh2iJTM';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://android.googleapis.com/gcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $post = array(
- 'data' => $data,
- );
- if( isset( $params['registration_ids'] ) )
- {
- $post['registration_ids'] = $params['registration_ids'];
- }
- else if( isset( $options['stoken'] ) )
- {
- $post['to'] = $options["stoken"];
- }
- else
- {
- if( isset($data['Vehicle'] ))
- $post['to'] = "/topics/" . $data['Vehicle'];
- else
- $post['to'] = "/topics/goexglobal";
- }
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- if ( curl_errno( $ch ) )
- {
- echo '1@@GCM error: ' . curl_error( $ch );
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- if( isset($options['ret_int']) )
- return $result;
- if( isset($params['separate']))
- echo '@@0@@'.$data['TxNo'].'@@'.$result;
- else
- echo '0@@'.$data['TxNo'].'@@'.$result;
- }
- function sendFirebaseCloudMessage( $data, $ids, $params = array(), $options = array() )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- // if ( $this->is_firebase == false ) {
- // return $this->sendGoogleCloudMessage($data,$ids,$params,$options);
- // }
- $apiKey = 'AIzaSyAFUpRaVZCEcOrAZy-jc2iz_OaAAWEjgd4';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://fcm.googleapis.com/fcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $post = array(
- 'data' => $data,
- );
- if( isset( $params['registration_ids'] ) )
- {
- $post['registration_ids'] = $params['registration_ids'];
- }
- else if( isset( $options['stoken'] ) )
- {
- $post['to'] = $options["stoken"];
- }
- else
- {
- // @TODO REMOVE THIS VALIDATION SINCE redundant
- // and already filtered at registration_ids filter
- if( isset($data['Vehicle'] ))
- $post['to'] = "/topics/" . $data['Vehicle'];
- else
- $post['to'] = "/topics/goexglobal";
- }
- query_log("Post Data " . json_encode($post));
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- if ( curl_errno( $ch ) )
- {
- if( isset($options['ret_int']) and $options['ret_int'] === True )
- error_log('1@@FCM error: ' . curl_error( $ch ));
- else
- echo '1@@FCM error: ' . curl_error( $ch );
- // set a flag
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- //if( @$result->results[0]->error == "MissmatchSenderId")
- // return $this->sendFirebaseCloudMessageIOS($data, $ids, $params, $options);
- $this->sendFirebaseCloudMessageIOS($data, $ids, $params, $options);
- if( isset($options['ret_int']) )
- {
- //error_log("BC is ". $result);
- return $result;
- }
- if( isset($params['separate']))
- echo '@@0@@'.$data['TxNo'].'@@'.$result;
- else
- echo '0@@'.$data['TxNo'].'@@'.$result;
- }
- function sendFirebaseCloudMessageIOS( $data, $ids, $params = array(), $options = array() )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- // if ( $this->is_firebase == false ) {
- // return $this->sendGoogleCloudMessage($data,$ids,$params,$options);
- // }
- //$apiKey = 'AIzaSyBBUQNwpcJCk5wnqP_Z9gX49w8UWLevc_4';
- $apiKey = 'AIzaSyA7GZ8In7gav2nD0wDejYRWU2zOxCqCQWI';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://fcm.googleapis.com/fcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $post = array(
- 'data' => $data,
- );
- if( isset( $params['registration_ids'] ) )
- {
- $post['registration_ids'] = $params['registration_ids'];
- }
- else if( isset( $options['stoken'] ) )
- {
- $post['to'] = $options["stoken"];
- }
- else
- {
- // @TODO REMOVE THIS VALIDATION SINCE redundant
- // and already filtered at registration_ids filter
- if( isset($data['Vehicle'] ))
- $post['to'] = "/topics/" . $data['Vehicle'];
- else
- $post['to'] = "/topics/goexglobal";
- }
- query_log("Post Data " . json_encode($post));
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- if ( curl_errno( $ch ) )
- {
- error_log('@@1@@FCM error: ' . curl_error( $ch ));
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- $this->sendFirebaseCloudMessageIOS3($data, $ids, $params, $options);
- if( isset($options['ret_int']) )
- return $result;
- if( isset($params['separate']))
- echo '@@0@@'.$data['TxNo'].'@@'.$result;
- else
- echo '0@@'.$data['TxNo'].'@@'.$result;
- }
- function sendFirebaseCloudMessageIOS3( $data, $ids, $params = array(), $options = array() )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- // if ( $this->is_firebase == false ) {
- // return $this->sendGoogleCloudMessage($data,$ids,$params,$options);
- // }
- // ade dashboard
- $apiKey = 'AIzaSyBBUQNwpcJCk5wnqP_Z9gX49w8UWLevc_4';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://fcm.googleapis.com/fcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $post = array(
- 'data' => $data,
- );
- if( isset( $params['registration_ids'] ) )
- {
- $post['registration_ids'] = $params['registration_ids'];
- }
- else if( isset( $options['stoken'] ) )
- {
- $post['to'] = $options["stoken"];
- }
- else
- {
- // @TODO REMOVE THIS VALIDATION SINCE redundant
- // and already filtered at registration_ids filter
- if( isset($data['Vehicle'] ))
- $post['to'] = "/topics/" . $data['Vehicle'];
- else
- $post['to'] = "/topics/goexglobal";
- }
- query_log("Post Data " . json_encode($post));
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- if ( curl_errno( $ch ) )
- {
- error_log('@@1@@FCM error: ' . curl_error( $ch ));
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- if( isset($options['ret_int']) )
- return $result;
- if( isset($params['separate']))
- echo '@@0@@'.$data['TxNo'].'@@'.$result;
- else
- echo '0@@'.$data['TxNo'].'@@'.$result;
- }
- function fcm_manual( )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- $apiKey = 'AIzaSyAFUpRaVZCEcOrAZy-jc2iz_OaAAWEjgd4';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://fcm.googleapis.com/fcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $notification = array(
- "title" => "DRIVER MEET",
- "body" => "test BOS",
- "sound" => "default");
- $data = array(
- "AA" => "BB");
- $post = array(
- 'data' => $data,
- 'notification' => $notification
- );
- $post['to'] = "feWQXuGLlD8:APA91bEnc8IfCwA6DsP8Uz1bXaIIWx3-BYfXB9yEYaabCTX7uOSrzLq8z9KYQkjPsMhETtC-LVEEihACP_SwkWNZMMGmuy6c7QdfQFKvrrxn4HshWqdDXRTf4vgrXkcOLN599FvFyk2F";
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- var_dump($result);
- if ( curl_errno( $ch ) )
- {
- return array(1, curl_error( $ch ), -1);
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- return array(0,'Success', $result);
- }
- function sendFirebaseCloudMessage2( $data, $params = array(), $notification = null )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- $apiKey = 'AIzaSyAFUpRaVZCEcOrAZy-jc2iz_OaAAWEjgd4';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://fcm.googleapis.com/fcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $post = array(
- 'data' => $data,
- );
- if( isset( $params['registration_ids'] ) )
- {
- $post['registration_ids'] = $params['registration_ids'];
- }
- else if( isset( $params['stoken'] ) )
- {
- $post['to'] = $params["stoken"];
- }
- else
- {
- $post['to'] = "/topics/global";
- }
- if ( $notification != null )
- {
- $post['notification'] = $notification;
- }
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- if ( curl_errno( $ch ) )
- {
- // This is crazy, we are returning value as
- // we had promised but will never return ERROR = 1
- // since we are trying to trigger other FCM funcs
- error_log('FCM2 '.curl_error( $ch ));
- //return array(1, curl_error( $ch ), -1);
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- $this->sendFirebaseCloudMessageIOS2($data, $params, $notification);
- //------------------------------
- // Debug GCM response
- //------------------------------
- return array(0,'Success', $result);
- }
- function sendFirebaseCloudMessageIOS2( $data, $params = array(), $notification = null )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- //$apiKey = 'AIzaSyBBUQNwpcJCk5wnqP_Z9gX49w8UWLevc_4';
- $apiKey = 'AIzaSyA7GZ8In7gav2nD0wDejYRWU2zOxCqCQWI';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://fcm.googleapis.com/fcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $post = array(
- 'data' => $data,
- );
- if( isset( $params['registration_ids'] ) )
- {
- $post['registration_ids'] = $params['registration_ids'];
- }
- else if( isset( $params['stoken'] ) )
- {
- $post['to'] = $params["stoken"];
- }
- else
- {
- $post['to'] = "/topics/global";
- }
- if ( $notification != null )
- {
- $post['notification'] = $notification;
- }
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- if ( curl_errno( $ch ) )
- {
- // This is crazy, we are returning value as
- // we had promised but will never return ERROR = 1
- // since we are trying to trigger other FCM funcs
- error_log('FCMIOS2 '.curl_error( $ch ));
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- $this->sendFirebaseCloudMessageIOS4($data, $params);
- //------------------------------
- // Debug GCM response
- //------------------------------
- return array(0,'Success', $result);
- }
- function sendFirebaseCloudMessageIOS4( $data, $params = array() )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- // ade dashboard
- $apiKey = 'AIzaSyBBUQNwpcJCk5wnqP_Z9gX49w8UWLevc_4';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://fcm.googleapis.com/fcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $post = array(
- 'data' => $data,
- );
- if( isset( $params['registration_ids'] ) )
- {
- $post['registration_ids'] = $params['registration_ids'];
- }
- else if( isset( $params['stoken'] ) )
- {
- $post['to'] = $params["stoken"];
- }
- else
- {
- $post['to'] = "/topics/global";
- }
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- if ( curl_errno( $ch ) )
- {
- // This is crazy, we are returning value as
- // we had promised but will never return ERROR = 1
- // since we are trying to trigger other FCM funcs
- error_log('FCMIOS4 '.curl_error( $ch ));
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- return array(0,'Success', $result);
- }
- function sendGoogleCloudMessage2( $data, $params = array() )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- $apiKey = 'AIzaSyAMC9GU3zMDCOf8r2kZvVfJMhbGrh2iJTM';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://android.googleapis.com/gcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $post = array(
- 'data' => $data,
- );
- if( isset( $params['registration_ids'] ) )
- {
- $post['registration_ids'] = $params['registration_ids'];
- }
- else if( isset( $params['stoken'] ) )
- {
- $post['to'] = $params["stoken"];
- }
- else
- {
- $post['to'] = "/topics/global";
- }
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- if ( curl_errno( $ch ) )
- {
- return array(1, curl_error( $ch ), -1);
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- return array(0,'Success', $result);
- }
- function gcm()
- {
- $this->sendgcmdevice();
- }
- function sendgcmdevice2( $params = array() )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- $apiKey = 'AIzaSyAMC9GU3zMDCOf8r2kZvVfJMhbGrh2iJTM';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://android.googleapis.com/gcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $params['Timestamp'] = number_format($this->current_millis(),0,'','');
- $post = array(
- 'to' => $params['SToken'],
- 'data'=> $params,
- );
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- $SUCCESS = 0;
- $STR_SUCCESS = "SUCCESS";
- $ERROR = 1;
- $STR_ERROR = "ERROR";
- $resjson = array();
- if ( curl_errno( $ch ) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => curl_error( $ch ),
- );
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- if( empty($resjson) )
- return $resjson = array(
- 'error' => $SUCCESS,
- 'error_message' => $STR_SUCCESS,
- 'data' => $params,
- );
- else
- return $resjson;
- }
- function sendfcmdevice( $params = array() )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- $apiKey = 'AIzaSyAFUpRaVZCEcOrAZy-jc2iz_OaAAWEjgd4';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://fcm.googleapis.com/fcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $data = array('message' => 'Hey test',
- "Timestamp"=> number_format(30303,0,'',''),
- 'driver_info' => 'driver_map',
- 'driver_lat' => '6.98111',
- 'driver_lng' => '-116.98766',
- );
- $post = array(
- // 'registration_ids' => $ids,
- 'to' => "eA2HaLmxWOE:APA91bGV6o8UGW9ageFwCv9xqX_URkUw2_IHWzO82jX830A3LCDJL4LMD9dt0ShZdfxQ0FYAPKKE3d1PqPKlnwNDRu-AszErE9F-a8UIVrQthFJEg5UZYGs0GIrZBF_G-IjDoBcuY79I",
- 'data' => $data,
- );
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization:key=' . $apiKey,
- 'Content-Type:application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- if ( curl_errno( $ch ) )
- {
- echo '1@@GCM error: ' . curl_error( $ch );
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- if( isset($params['separate']))
- echo '@@0@@'.$result;
- else
- echo '0@@'.$result;
- }
- function sendgcmdevice( $params = array() )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- $apiKey = 'AIzaSyAMC9GU3zMDCOf8r2kZvVfJMhbGrh2iJTM';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://android.googleapis.com/gcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $data = array('message' => 'Hey test',
- "Timestamp"=> number_format($this->current_millis(),0,'',''),
- 'driver_info' => 'driver_map',
- 'driver_lat' => '6.98111',
- 'driver_lng' => '-116.98766',
- );
- $post = array(
- // 'registration_ids' => $ids,
- 'to' => "fFO5k2imbDU:APA91bGr3xSGvPJPvxRHle6rJClmvWMxpkXWliKAJRdYv5tIondUjZ8eNpzE38xXukLkDTuORDvoq_p2bijxdyQkn7F2ki0JPo977UT3Xo6ZtWW4VjhiHGFt0EDVb9V4YE2c4EwD8PWf",
- 'data' => $data,
- );
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- if ( curl_errno( $ch ) )
- {
- echo '1@@GCM error: ' . curl_error( $ch );
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- if( isset($params['separate']))
- echo '@@0@@'.$result;
- else
- echo '0@@'.$result;
- }
- // FIXME shud use more secure ways
- function driver_payload($txno, $client_userid)
- {
- $ERROR = 1;
- error_log('Driver Payload logging');
- // validate the tx
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: No TX",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- $txrecord = $txrecord[0];
- $json = json_decode($txrecord->payload);
- $resjson = array(
- 'error' => 0,
- 'error_message' => '',
- 'msgid' => '',
- 'payload' => json_encode($json->data->driver_payload),
- );
- $retstr = json_encode($resjson);
- error_log('driver_payload ' . $retstr);
- die( $retstr );
- }
- function tx_checkack_version($txno)
- {
- $CLIENT = 90;
- $DRIVER = 50;
- $FATAL_ERROR = 2;
- $PERMISSIVE_ERROR = 1;
- $SUCCESS = 0;
- $txno = validateTxno($txno);
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload );
- error_log("CHECK_VERSION ". $payload);
- //Check Version
- //COMMENT SIR ADE UPDATE START 1
- if( $json->isclt == $DRIVER )
- {
- query_log("Current version is " . $json->version);
- // $json->version = "2.1.0";
- if( intval(str_replace(".","",$json->version)) >= I_DRIVER_VERSION )
- {
- $resjson = array(
- 'error' => $SUCCESS,
- 'error_message' => 'Your permissive error is working!',
- );
- // die(json_encode($resjson));
- }
- else {
- $resjson = array(
- 'error' => $FATAL_ERROR,
- 'error_message' => lang('NewVersionNeeded'),
- 'driver_bc' => ''
- );
- //$resjson = array(
- // 'error' => $SUCCESS,
- // 'error_message' => 'Your permissive error is working!',
- //);
- error_log("CHECK_VERSION CLIENT REPLY". json_encode($resjson));
- die(json_encode($resjson));
- }
- }
- // Check tx status
- $txrecord = $this->model_goexpress->get_tx_by_txno_only(array('txno'=>$txno));
- if ( empty($txrecord) )
- {
- // No need to show Alert to CLIENT because this supporting system not main system
- $resjson = array(
- 'error' => 0,
- 'driver_bc' => "",
- 'error_message' => "EMPTY PAYLOAD"
- );
- die( json_encode($resjson) );
- }
- if ( $txrecord->cancel_type_id > 0 )
- {
- $resjson = array(
- 'error' => 0,
- 'driver_bc' => "tx_canceled",
- 'driver_remark' => $txrecord->cancel_remark
- );
- die( json_encode($resjson) );
- }
- elseif ( $txrecord->complete_type_id > 0 )
- {
- $resjson = array (
- 'error' => 0,
- 'driver_bc' => "tx_completed",
- 'driver_remark' => $txrecord->complete_remark
- );
- die( json_encode($resjson) );
- }
- elseif ( strlen($txrecord->driver_username) > 5 ) {
- $json = json_decode($txrecord->payload);
- $driver_latlng = $this->model_goexpress->get_driver_last_latlng($txno);
- $driver_lat = "";
- $driver_lng = "";
- if ( isset($driver_latlng) and isset($driver_latlng->lat) ) {
- $driver_lat = $driver_latlng->lat;
- $driver_lng = $driver_latlng->lng;
- }
- $bMeet = $txrecord->has_meet;
- if( $txrecord->flag_meet == 1 AND $txrecord->has_meet == 1)
- $bMeet = 0;
- $resjson = array (
- 'error' => 0,
- 'driver_bc' => "tx_ack",
- 'txno' => $txrecord->txno,
- 'has_meet' => $bMeet,
- 'payload' => json_encode($json->data->driver_payload),
- 'driver_lat' => $driver_lat,
- 'driver_lng' => $driver_lng
- );
- if( $txrecord->flag_meet == 0 AND $txrecord->has_meet == 1)
- {
- $uparams = array('flag_meet' => 1 );
- $this->model_goexpress->update_tx($uparams, $txrecord->id);
- }
- die( json_encode($resjson) );
- }
- elseif( $txrecord->status_id == 1 ){
- $resjson = array(
- 'error' => 0,
- 'driver_bc' => "tx_cancel"
- );
- die( json_encode($resjson) );
- }
- else {
- $bMeet = $txrecord->has_meet;
- if( $txrecord->flag_meet == 1 AND $txrecord->has_meet == 1)
- $bMeet = 0;
- if( $txrecord->flag_meet == 0 AND $txrecord->has_meet == 1)
- {
- $uparams = array('flag_meet' => 1 );
- $this->model_goexpress->update_tx($uparams, $txrecord->id);
- }
- die( json_encode(array(
- 'error' => 0,
- 'has_meet' => $bMeet,
- 'driver_bc' => "",
- 'normal_fare' => $txrecord->normal_price,
- 'promo_value' => $txrecord->promo_deduction
- )
- )
- );
- }
- }
- function tx_checkack($txno)
- {
- $CANCEL = 1;
- $DRIVER_CANCEL = 5;
- $COMPLETE = 1;
- $WORKING = 9;
- $txno = validateTxno($txno);
- $txrecord = $this->model_goexpress->get_tx_by_txno_only(array('txno'=>$txno));
- // No need to show Alert to CLIENT because this supporting system not main system
- if ( empty($txrecord) )
- {
- $resjson = array(
- 'error' => 0,
- 'driver_bc' => "",
- 'error_message' => "EMPTY PAYLOAD"
- );
- die( json_encode($resjson) );
- }
- if ( $txrecord->cancel_type_id > 0 )
- {
- $resjson = array(
- 'error' => 0,
- 'driver_bc' => "tx_canceled",
- 'driver_remark' => $txrecord->cancel_remark
- );
- die( json_encode($resjson) );
- }
- elseif ( $txrecord->complete_type_id > 0 )
- {
- $resjson = array (
- 'error' => 0,
- 'driver_bc' => "tx_completed",
- 'driver_remark' => $txrecord->complete_remark
- );
- die( json_encode($resjson) );
- }
- elseif( $txrecord->status_id == 1 ){
- $resjson = array(
- 'error' => 0,
- 'driver_bc' => "tx_cancel"
- );
- die( json_encode($resjson) );
- }
- elseif ( $txrecord->status_id == $WORKING ) {
- $json = json_decode($txrecord->payload);
- $driver_latlng = $this->model_goexpress->get_driver_last_latlng($txno);
- $driver_lat = "";
- $driver_lng = "";
- if ( isset($driver_latlng) and isset($driver_latlng->lat) ) {
- $driver_lat = $driver_latlng->lat;
- $driver_lng = $driver_latlng->lng;
- }
- $bMeet = $txrecord->has_meet;
- if( $txrecord->flag_meet == 1 AND $txrecord->has_meet == 1)
- $bMeet = 0;
- $resjson = array (
- 'error' => 0,
- 'driver_bc' => "tx_ack",
- 'txno' => $txrecord->txno,
- 'has_meet' => $bMeet,
- 'payload' => json_encode($json->data->driver_payload),
- 'driver_lat' => $driver_lat,
- 'driver_lng' => $driver_lng
- );
- if( $txrecord->flag_meet == 0 AND $txrecord->has_meet == 1)
- {
- $uparams = array('flag_meet' => 1 );
- $this->model_goexpress->update_tx($uparams, $txrecord->id);
- }
- die( json_encode($resjson) );
- }
- else {
- $bMeet = $txrecord->has_meet;
- if( $txrecord->flag_meet == 1 AND $txrecord->has_meet == 1)
- $bMeet = 0;
- if( $txrecord->flag_meet == 0 AND $txrecord->has_meet == 1)
- {
- $uparams = array('flag_meet' => 1 );
- $this->model_goexpress->update_tx($uparams, $txrecord->id);
- }
- die( json_encode(array(
- 'error' => 0,
- 'has_meet' => $bMeet,
- 'driver_bc' => ""
- )
- )
- );
- }
- }
- function tx_ack($txno, $driver_userid)
- {
- error_log('tx ack logging');
- // TODO make sure driver sent its GCM token
- $input_payload = file_get_contents('php://input');
- //error_log($input_payload);die();
- $txno = validateTxno($txno);
- $ERROR = 1;
- $NOTIF_ERROR = 2;
- $SOFT_NOTIF = 3;
- $OPEN = 0;
- $WORKING =
- $DRIVING = 9;
- $DRIVER_ACK = 10;
- // validate the driver
- $json_input = json_decode($input_payload);
- if( empty($json_input->data->driver_phoneno)) {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: No Phone Empty",
- 'msgid' => "",
- 'payload' => "",
- );
- error_log(json_encode($resjson));
- error_log($input_payload);
- die( json_encode($resjson) );
- }
- if( empty($json_input->data->driver_name)) {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: Driver Name Empty",
- 'msgid' => "",
- 'payload' => ""
- );
- error_log(json_encode($resjson));
- error_log($input_payload);
- die( json_encode($resjson) );
- }
- query_log("Execute checkValid");
- list($flag,$maxval,$remainval) = $this->model_goexpress->checkvalid($json_input->data->driver_userid);
- if ( $this->uri->segment(1) == "km" ) {
- if ( $flag == 1 ) {
- $resjson = array (
- 'error' => $NOTIF_ERROR,
- 'error_message' => "សូមអភ័យទោស ទឹកប្រាក់កម្រៃជើងសារដែលក្រុមហ៊ុន Go-X តម្រូវឲ្យបង់បានកើនលើសពីកំរិតកំណត់ហើយ! ចំនួនទឹកប្រាក់កម្រៃជើងសាររបស់ការិយាល័យច្រើនបំផុតគឺ ".$maxval."រៀល។
- សូមមេត្តាមកកាន់ការិយាល័យ Go-X ដើម្បីធ្វើការបង់ប្រាក់ និងអាចទទួលយកការកម្ម៉ងបន្តទៀត។",
- 'msgid' => "",
- 'payload' => ""
- );
- die( json_encode($resjson) );
- }
- elseif ( $flag == 2 ) {
- $resjson = array (
- 'error' => $NOTIF_ERROR,
- 'error_message' => "សូមអភ័យទោស ថ្ងៃបរិច្ឆេទដែលលោកអ្នកត្រូវមកកាន់ក្រុមហ៊ុន GO-X ដើម្បីធ្វើការទូទាត់ប្រាក់កម្រៃជើងសារត្រូវបានផុតកំណត់ហើយ! សូមមេត្តាមកកាន់ការិយាល័យ Go-X ដើម្បីធ្វើការបង់ប្រាក់ និងអាចទទួលយកការកម្ម៉ងបន្តទៀត។",
- 'msgid' => "",
- 'payload' => ""
- );
- die( json_encode($resjson) );
- }
- elseif ( $flag == 3 ) {
- $notifjson = array (
- 'error' => $SOFT_NOTIF,
- 'error_message' => "ទឹកប្រាក់កម្រៃជើងសារដែលក្រុមហ៊ុនកំណត់ឲ្យលោកអ្នកច្រើនបំផុតគឺ ".$maxval."រៀល។ លោកអ្នកនៅសល់ចំនួនទឹកប្រាក់ ".$remainval."រៀល ទៀត ដែលនឹងឈានទៅដល់ទឹកប្រាក់កម្រៃជើងសារច្រើនបំផុតដែលក្រុមហ៊ុនបានកំណត់ឲ្យ!",
- 'msgid' => "",
- 'payload' => ""
- );
- // die( json_encode($resjson) );
- }
- elseif ( $flag == 4 ) {
- $notifjson = array (
- 'error' => $SOFT_NOTIF,
- 'error_message' => "Yសូមអភ័យទោស ថ្ងៃបរិច្ឆេទដែលលោកអ្នកត្រូវមកកាន់ក្រុមហ៊ុន GO-X ដើម្បីធ្វើការទូទាត់ប្រាក់កម្រៃជើងសារនឹងផុតកំណត់នៅថ្ងៃទី ".$maxval."! រយៈពេលដែលនៅសល់ពីថ្ងៃផុតកំណត់គឺ ".$remainval." ថ្ងៃទៀត។",
- 'msgid' => "",
- 'payload' => ""
- );
- // die( json_encode($resjson) );
- }
- }
- else {
- if ( $flag == 1 ) {
- $resjson = array (
- 'error' => $NOTIF_ERROR,
- 'error_message' => "Sorry, you already exceed maximum pending office comission. Maximum pending office comission is ".$maxval." KHR. Please go to office to continue take new order",
- 'msgid' => "",
- 'payload' => ""
- );
- die( json_encode($resjson) );
- }
- elseif ( $flag == 2 ) {
- $resjson = array (
- 'error' => $NOTIF_ERROR,
- 'error_message' => "Sorry, your date to visit GO-X company is expired, please come to our office to continue take new order",
- 'msgid' => "",
- 'payload' => ""
- );
- die( json_encode($resjson) );
- }
- elseif ( $flag == 3 ) {
- $notifjson = array (
- 'error' => $SOFT_NOTIF,
- 'error_message' => "Your maximum pending office comission is ".$maxval." KHR. The remaining ".$remainval." KHR before reaching the maximum limit",
- 'msgid' => "",
- 'payload' => ""
- );
- // die( json_encode($resjson) );
- }
- elseif ( $flag == 4 ) {
- $notifjson = array (
- 'error' => $SOFT_NOTIF,
- 'error_message' => "The date that you have to visit GO-X Company for commision payment will expired at .".$maxval."! The days remain is ".$remainval,
- 'msgid' => "",
- 'payload' => ""
- );
- // die( json_encode($resjson) );
- }
- }
- // validate the tx
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: No TX",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- $txrecord = $txrecord[0];
- if( !isset($txrecord->txno) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: TX is Broken",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- error_log('ID '.$driver_userid.' status_id '.$txrecord->status_id);
- if( $txrecord->status_id != $OPEN )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: TX is Taken",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- $json = json_decode($txrecord->payload);
- $json->data->driver_payload = json_decode($input_payload);
- $reqparams = array('username' => $driver_userid );
- $driverinfo = $this->model_goexpress->get_user($reqparams);
- $json->data->driver_payload->driver_picurl = $driverinfo->picurl;
- $json->data->NormalFare = $txrecord->normal_price;
- $json->data->PromoDeduction = $txrecord->promo_deduction;
- $tsparams = array(
- 'payload' => json_encode($json),
- 'ack_status_id' => $DRIVER_ACK,
- 'status_id' => $WORKING,
- 'driver_username' => $json_input->data->driver_userid,
- 'driver_name' => $json_input->data->driver_name
- );
- // FIXME validate if the driver is previous accepted
- if( $txrecord->ack_status_id < $DRIVER_ACK )
- {
- list($flag, $void, $msg ) = $this->model_goexpress->add_tx($tsparams, $txrecord->id);
- $resjson = array(
- 'error' => ERROR_WISE_iFLAG($flag),
- 'error_message' => $msg,
- 'msgid' => '',
- );
- if ( isset($notifjson) && $resjson['error'] == 0 ) {
- $resjson = $notifjson;
- }
- }
- else
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: TX taken, ACK is no longer DRIVER_ACK is '. $txrecord->ack_status_id,
- );
- }
- if( !isset($resjson['msgid'] ) )
- $resjson['msgid'] = '';
- $resjson['payload'] = $json;
- $resjson['phone'] = $json_input->data->driver_phoneno;
- if ( ACTIVITY_RECORD == true ) {
- $ackDetail = array( "driver_username" => $json_input->data->driver_userid,
- "txno" => $txrecord->txno );
- $activityDetail = array ( "type" => "tx_ack",
- "tx" => $ackDetail
- );
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- $accepted = 3;
- $params = array( "driver_username" => $json_input->data->driver_userid,
- "txno" => $txrecord->txno,
- "accept_time" => time(),
- "bc_status" => $accepted);
- $this->model_goexpress->update_bc_status($params);
- //error_log(json_encode($resjson));
- die( json_encode($resjson) );
- }
- function tx_ack_sendFcm($txno, $driver_id = null)
- {
- $tparams = array('txno' => $txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: No TX",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- $txrecord = $txrecord[0];
- if( !isset($txrecord->txno) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: TX is Broken",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- $json = json_decode($txrecord->payload);
- // send gcm to client
- $data = array(
- "driver_info" => "tx_ack",
- "txno" => $txno,
- "payload" => $txno,
- );
- if( $json->data->SToken == OFFICE_LOGIN)
- {
- error_log('tx_ack_send_gcm, gcm '.OFFICE_LOGIN.' '.OFFICE_LOGIN);
- $oparams = array('txno' => $txno);
- $officeorder = $this->office_model->get_order($oparams);
- $oiparams = array('driver_ack' => 1);
- $this->office_model->save_order($oiparams, $officeorder->id);
- $resjson = array(
- 'error' => 0,
- 'error_message' => OFFICE_LOGIN,
- 'msgid' => OFFICE_LOGIN,
- );
- die(json_encode($resjson));
- }
- $gparams = array('stoken' => $json->data->SToken );
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams );
- //$flag = 0;
- //$msg = "test";
- //$msgid= 0;
- error_log('tx_ack_send_gcm, gcm '.$msg.' '.$msgid);
- $resjson = array(
- 'error' => $flag,
- 'error_message' => $msg,
- 'msgid' => $msgid,
- );
- die(json_encode($resjson));
- }
- function tx_reack($txno, $driver_userid)
- {
- // TODO make sure driver sent its GCM token
- $ERROR = 1;
- $OPEN = 0;
- $WORKING = 9;
- $DRIVER_ACK = 10;
- // validate the driver
- // validate the tx
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: No TX",
- 'msgid' => "",
- 'payload' => "",
- 'source'=> 'tx_reack',
- );
- die( json_encode($resjson) );
- }
- $txrecord = $txrecord[0];
- if( !isset($txrecord->txno) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: TX is Broken",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- if( $txrecord->status_id != $OPEN )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: TX is Taken",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- //$tsparams = array('status_id' => $WORKING );
- $json = json_decode($txrecord->payload);
- $json->data->driver_payload = json_decode($input_payload);
- $tsparams = array(
- 'payload' => json_encode($json ),
- 'ack_status_id' => $DRIVER_ACK,
- );
- // FIXME validate if the driver is previous accepted
- if( $txrecord->ack_status_id < $DRIVER_ACK )
- $this->model_goexpress->add_tx($tsparams, $txrecord->id);
- // send gcm to client
- $data = array(
- "driver_info" => "tx_ack",
- "payload" => $input_payload,
- );
- $gparams = array('stoken' => $json->data->SToken );
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams );
- $resjson = array(
- 'error' => $flag,
- 'error_message' => $msg,
- 'msgid' => $msgid,
- 'payload' => $txrecord->payload,
- );
- $retstr = json_encode($resjson);
- error_log('tx_ack : '.$txno.' '.$retstr);
- die( $retstr );
- }
- function _get_coord_nearby($params = array())
- {
- if ( !isset($params['minrange']) )
- $params['minrange'] = $params['range'];
- $const = GET_COORD_CONST();
- $result = array('X1' => 0, 'X2' => 0, 'Y1' => 0, 'Y2' => 0);
- $range = $params['range'];
- $ddmax_result = ($params['range']/$const['distance'])*$const['degree'];
- $result['X1'] = $params['client_lat'] - $ddmax_result;
- $result['Y1'] = $params['client_lng'] - $ddmax_result;
- $result['X2'] = $params['client_lat'] + $ddmax_result;
- $result['Y2'] = $params['client_lng'] + $ddmax_result;
- $now_time = date('Y-m-d H:i:s', strtotime('now'));
- $result['last_up_time'] = CALC_TIME($params['uptime'], '-');
- return $result;
- }
- function driver_nearby()
- {
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload );
- $response = array();
- $RANGE = 3; // in Km.
- $UPTIME = UPTIME; // in Minutes.
- $gcparams = array(
- 'range' => $RANGE,
- 'uptime' => $UPTIME,
- 'client_lat' => $json->lat,
- 'client_lng' => $json->lng,
- );
- $gcresult = $this->_get_coord_nearby($gcparams);
- $user_type_id = $json->isdrv;
- $transport = $json->transport;
- $params = array(
- 'user_type'=> $user_type_id,
- 'transport' => $transport,
- 'X1' => $gcresult['X1'],
- 'X2' => $gcresult['X2'],
- 'Y1' => $gcresult['Y1'],
- 'Y2' => $gcresult['Y2'],
- 'last_up_time' => $gcresult['last_up_time']
- );
- $records = $this->model_goexpress->get_driver_nearby($params);
- if(count($records) > 0 )
- {
- $result = new StdClass();
- $results = array();
- foreach ($records as $index => $record)
- {
- $result->driver_id = $record->id;
- $result->driver_lat = $record->lat;
- $result->driver_lng = $record->lng;
- $results[$index] = $result;
- unset($result);
- }
- $response['error'] = 0;
- $response['result'] = $results;
- }
- else
- {
- $response['error'] = 1;
- $response['result'] = null;
- }
- die(json_encode($response));
- }
- function get_all_driver()
- {
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload );
- $response = array();
- $RANGE = 3; // in Km.
- $UPTIME = UPTIME; // in Minutes.
- $now_time = date('Y-m-d H:i:s', strtotime('now'));
- $last_up_time = CALC_TIME($UPTIME, '-');
- $user_type_id = $json->isdrv;
- $transport = $json->transport;
- $params = array(
- 'user_type'=> $user_type_id,
- 'transport' => $transport,
- 'last_up_time' => $last_up_time
- );
- $records = $this->model_goexpress->get_driver_nearby($params);
- if(count($records) > 0 )
- {
- $result = new StdClass();
- $results = array();
- foreach ($records as $index => $record)
- {
- $result->driver_id = $record->id;
- $result->driver_lat = $record->lat;
- $result->driver_lng = $record->lng;
- $result->driver_name = $record->name;
- $result->driver_hp = $record->hp;
- $results[$index] = $result;
- unset($result);
- }
- $response['error'] = 0;
- $response['result'] = $results;
- }
- else
- {
- $response['error'] = 1;
- $response['result'] = null;
- }
- die(json_encode($response));
- }
- function tx_ack_refresh($txno)
- {
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if ( isset($txrecord[0]->ack_status_id))
- die(json_encode(array( 'tx_ack_status' => $txrecord[0]->ack_status_id)));
- else
- die(json_encode(array( 'tx_ack_status' => 0)));
- }
- function txclient_ack($txno)
- {
- error_log('start client ACK ');
- $ERROR = 1;
- $SUCCESS = 0;
- $STR_SUCCESS = "SUCCESS";
- $CLIENT_ACK = 20;
- $WORKING = 9;
- // validate the driver
- // validate the tx
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: No TX",
- 'msgid' => "",
- 'payload' => "",
- );
- error_log('Error '. json_encode($resjson));
- die( json_encode($resjson) );
- }
- $txrecord = $txrecord[0];
- if( !isset($txrecord->txno) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: TX is Broken",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- $tsparams = array('ack_status_id' => $CLIENT_ACK );
- $this->model_goexpress->add_tx($tsparams, $txrecord->id);
- // send gcm to driver
- $data = array(
- "client_info" => "tx_ack",
- "payload" => "",
- );
- $json = json_decode($txrecord->payload);
- $gparams = array('stoken' => $json->data->driver_payload->data->driver_stoken );
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams );
- error_log('txclient_ack, gcm '.$msg.' '.$msgid.' '. $json->data->driver_payload->data->driver_stoken);
- $resjson = array(
- 'error' => $SUCCESS,
- 'error_message' => $STR_SUCCESS,
- 'msgid' => $msgid,
- 'payload' => "",
- );
- $retstr = json_encode($resjson);
- error_log('txclient_ack : '.$txno.' '.$retstr);
- die( $retstr );
- }
- function txclientdriver_ack($txno, $driver_userid)
- {
- $ERROR = 1;
- $SUCCESS = 0;
- $STR_SUCCESS = "SUCCESS";
- $CLIENT_ACK = 20;
- $WORKING = 9;
- // validate the driver
- // validate the tx
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: No TX",
- 'msgid' => "",
- 'payload' => "",
- 'source'=> 'txclientdriver_ack',
- 'txno'=> $txno,
- );
- die( json_encode($resjson) );
- }
- $txrecord = $txrecord[0];
- if( !isset($txrecord->txno) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: TX is Broken",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- if( $txrecord->ack_status_id != $CLIENT_ACK )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: Client not ACK",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- $resjson = array(
- 'error' => $SUCCESS,
- 'error_message' => $STR_SUCCESS,
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- function driver_registration()
- {
- // insert the driver
- // create the verification code
- }
- function payload_request( $driver_id, $txno)
- {
- }
- function tx_drivercomplete($txno)
- {
- $DRIVER_COMPLETE = 5;
- $COMPLETE = 3;
- $WORKING = 9;
- $payload = file_get_contents('php://input');
- if ( $payload != null && strlen($payload) > 5) {
- $payload = json_decode($payload);
- }
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- die("1@@Error: TxNo not registered");
- }
- $txrecord = $txrecord[0];
- if( $txrecord->status_id != $WORKING )
- {
- die("1@@Error: TxNo is not in DRIVING status");
- }
- $complete_remark = "Driver Complete";
- if( isset($payload->complete_remark) and $payload->complete_remark !='' )
- $complete_remark = $payload->complete_remark;
- $tsparams = array('status_id' => $COMPLETE,
- 'complete_type_id' => $DRIVER_COMPLETE,
- 'complete_timestamp' => date('Y-m-d H:i:s'),
- 'complete_remark' => $complete_remark
- );
- $this->model_goexpress->add_tx($tsparams, $txrecord->id);
- // Send GCM
- $json = json_decode( $txrecord->payload );
- $data = array(
- "driver_info" => "tx_completed",
- );
- // ******* Update TX_EMAIL ****** //
- $txeparams = array(
- 'txno' => $txno,
- 'mail_type' => 6,
- 'tx_date' => $txrecord->tx_date,
- 'mail_status' => 99,
- );
- list($flag, $id, $msg) = $this->_update_tx_email($txeparams);
- if(!$flag)
- {
- log_message('error',sprintf('%s (%s): %s, %s', __FILE__,__LINE__,'TX_EMAIL with ID:'.$id.' '.$msg, $txeparams));
- }
- // ********* END TX_EMAIL ********* //
- $this->model_goexpress->tx_complete($txrecord);
- query_log("DriverComplete, Start FCM");
- query_log("DriverComplete, Client FCM ". @$json->data->SToken);
- if( isset($json->data->SToken) and $json->data->SToken != OFFICE_LOGIN)
- {
- query_log("DriverComplete, Token to sent " . $json->data->SToken);
- $gparams = array('stoken' => $json->data->SToken );
- if ( $json->data->lang == "km") {
- switch($json->data->Actionmode)
- {
- case 'TRANSPORT':
- $title = "អេច ដឹកជញ្ជូន";
- break;
- case 'DELIVERY':
- $title = "អេច ដឹកទំនិញ";
- break;
- case 'SHOP':
- $title = "អេច ទិញទំនិញ";
- break;
- default:
- $title = $json->data->Actionmode;
- }
- $bodymsg = "ការបញ្ជារបស់លោកអ្នកត្រូវបានបញ្ចប់";
- }
- else {
- $title = $json->data->Actionmode;
- $bodymsg = "Your order has completed";
- }
- $notification = array(
- 'title' => $title,
- 'body' => $bodymsg,
- 'sound' => "default");
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams, $notification );
- query_log("DriverComplete, result " . $flag. " msg " . $msg ." msgid ". $msgid);
- }
- else
- $msgid = OFFICE_LOGIN;
- if ( ACTIVITY_RECORD == true ) {
- $completeDetail = array( "txno" => $txno,
- "complete_date" => TO_MySQL_DATE(),
- "complete_by" => "driver");
- $activityDetail = array( "type" => "tx_complete",
- "tx" => $completeDetail);
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- die("0@@Success@@". $msgid);
- }
- function tx_clientcomplete($txno)
- {
- $CLIENT_COMPLETE = 0;
- $COMPLETE = 3;
- $WORKING = 9;
- $payload = file_get_contents('php://input');
- if ( $payload != null && strlen($payload) > 5) {
- $payload = json_decode($payload);
- }
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- die("1@@Error: TxNo not registered");
- }
- $txrecord = $txrecord[0];
- if( $txrecord->status_id != $WORKING )
- {
- die("1@@Error: TxNo is not in DRIVING status");
- }
- $complete_remark = "Client Complete";
- if( isset($payload->complete_remark) and $payload->complete_remark !='' )
- $complete_remark = $payload->complete_remark;
- $tsparams = array('status_id' => $COMPLETE,
- 'complete_type_id' => $CLIENT_COMPLETE,
- 'complete_timestamp' => date('Y-m-d H:i:s'),
- 'complete_remark' => $complete_remark
- );
- $this->model_goexpress->add_tx($tsparams, $txrecord->id);
- // Send GCM
- $json = json_decode( $txrecord->payload );
- $data = array(
- "client_info" => "tx_completed",
- "client_remark" => "Client Completed",
- );
- // ***** Update TX_EMAIL ***** //
- $txeparams = array(
- 'txno' => $txno,
- 'mail_type' => 4,
- 'tx_date' => $txrecord->tx_date,
- 'mail_status' => 99,
- );
- list($flag, $id, $msg) = $this->_update_tx_email($txeparams);
- if(!$flag)
- {
- log_message('error',sprintf('%s (%s): %s, %s', __FILE__,__LINE__,'TX_EMAIL with ID:'.$id.' '.$msg, $txeparams));
- }
- // ****** END TX_EMAIL ****** //
- $this->model_goexpress->tx_complete($txrecord);
- $gparams = array('stoken' => $json->data->driver_payload->data->driver_stoken );
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams );
- if ( ACTIVITY_RECORD == true ) {
- $completeDetail = array( "txno" => $txno,
- "complete_date" => TO_MySQL_DATE(),
- "complete_by" => "client");
- $activityDetail = array( "type" => "tx_complete",
- "tx" => $completeDetail);
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- die("0@@Success@@". $msgid);
- }
- function tx_complete($txno)
- {
- $COMPLETE = 3;
- $WORKING = 9;
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- die("1@@Error: TxNo not registered");
- }
- $txrecord = $txrecord[0];
- if( $txrecord->status_id != $WORKING )
- {
- die("1@@Error: TxNo is not in DRIVING status");
- }
- $tsparams = array('status_id' => $COMPLETE,
- 'complete_timestamp' => date('Y-m-d H:i:s'),
- );
- $this->model_goexpress->add_tx($tsparams, $txrecord->id);
- // Send GCM
- $json = json_decode( $txrecord->payload );
- $data = array(
- "driver_info" => "tx_completed",
- );
- $this->model_goexpress->tx_complete($txrecord);
- $gparams = array('stoken' => $json->data->SToken );
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams );
- if ( ACTIVITY_RECORD == true ) {
- $completeDetail = array( "txno" => $txno,
- "complete_date" => TO_MySQL_DATE(),
- "complete_by" => "office");
- $activityDetail = array( "type" => "tx_complete",
- "tx" => $completeDetail);
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- die("0@@Success@@". $msgid);
- }
- function tx_drivercancel($txno)
- {
- $payload = file_get_contents('php://input');
- $payload = json_decode($payload);
- $CANCEL = 1;
- $DRIVER_CANCEL= 5;
- $COMPLETE = 1;
- $WORKING = 9;
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- die("1@@Error: TxNo not registered");
- }
- $txrecord = $txrecord[0];
- if( $txrecord->status_id != $WORKING )
- {
- //die("1@@Error: TxNo is not in DRIVING status");
- }
- $cancel_remark = "Driver cancel";
- if( isset($payload->cancel_remark) and $payload->cancel_remark !='' )
- $cancel_remark = $payload->cancel_remark;
- $tsparams = array('status_id' => $CANCEL,
- 'cancel_type_id' => $DRIVER_CANCEL,
- 'complete_timestamp' => date('Y-m-d H:i:s'),
- 'cancel_remark' => $cancel_remark,
- );
- $this->model_goexpress->add_tx($tsparams, $txrecord->id);
- // Send GCM
- $json = json_decode( $txrecord->payload );
- $data = array(
- "driver_info" => "tx_canceled",
- "driver_remark" => $cancel_remark,
- );
- // ******* Update TX_EMAIL ****** //
- $txeparams = array(
- 'txno' => $txno,
- 'mail_type' => 5,
- 'tx_date' => $txrecord->tx_date,
- 'mail_status' => 99,
- );
- list($flag, $id, $msg) = $this->_update_tx_email($txeparams);
- if(!$flag)
- {
- log_message('error',sprintf('%s (%s): %s, %s', __FILE__,__LINE__,'TX_EMAIL with ID:'.$id.' '.$msg, $txeparams));
- }
- // ********* END TX_EMAIL ********* //
- if( $json->data->SToken != OFFICE_LOGIN)
- {
- $gparams = array('stoken' => $json->data->SToken );
- if ( $json->data->lang == "km") {
- switch($json->data->Actionmode)
- {
- case 'TRANSPORT':
- $title = "អេច ដឹកជញ្ជូន";
- break;
- case 'DELIVERY':
- $title = "អេច ដឹកទំនិញ";
- break;
- case 'SHOP':
- $title = "អេច ទិញទំនិញ";
- break;
- default:
- $title = $json->data->Actionmode;
- }
- $bodymsg = "ការបញ្ជារបស់លោកអ្នកត្រូវបានលុបចោល";
- }
- else {
- $title = $json->data->Actionmode;
- $bodymsg = "Your order has canceled";
- }
- if ( ACTIVITY_RECORD == true ) {
- $cancelDetail = array( "txno" => $txno,
- "cancel_date" => TO_MySQL_DATE(),
- "cancel_by" => "driver",
- "cancel_remark" => $cancel_remark);
- $activityDetail = array( "type" => "tx_cancel",
- "tx" => $cancelDetail);
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- $notification = array(
- 'title' => $title,
- 'body' => $bodymsg,
- 'sound' => 'default');
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams, $notification );
- }
- else
- $msgid = OFFICE_LOGIN;
- die("0@@Success@@". $msgid);
- }
- function tx_clientcancel($txno)
- {
- $CLIENT_CANCEL = 0;
- $CANCEL = 1;
- $COMPLETE = 1;
- $WORKING = 9;
- $payload = file_get_contents('php://input');
- if ( $payload != null && strlen($payload) > 5) {
- $payload = json_decode($payload);
- }
- // var_dump($payload);
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- die("1@@Error: TxNo not registered");
- }
- $cancel_remark = "Client cancel";
- if( isset($payload->cancel_remark) and $payload->cancel_remark !='' )
- $cancel_remark = $payload->cancel_remark;
- $txrecord = $txrecord[0];
- $tsparams = array('status_id' => $CANCEL,
- 'cancel_type_id' => $CLIENT_CANCEL,
- 'complete_timestamp' => date('Y-m-d H:i:s'),
- 'cancel_remark' => $cancel_remark,
- );
- $this->model_goexpress->add_tx($tsparams, $txrecord->id);
- // Send GCM
- $json = json_decode( $txrecord->payload );
- $data = array(
- "client_info" => "tx_canceled",
- "client_remark" => "Client Canceled",
- );
- // Checking TriggerType
- $cancel_onwait = 2;
- $cancel_by_cust = 3;
- if($txrecord->driver_username == '')
- $email_type = $cancel_onwait;
- else
- $email_type = $cancel_by_cust;
- // ******** Update TX_EMAIL ******** //
- $txeparams = array(
- 'txno' => $txno,
- 'mail_type' => $email_type,
- 'tx_date' => $txrecord->tx_date,
- 'mail_status' => 99,
- );
- list($flag, $id, $msg) = $this->_update_tx_email($txeparams);
- if(!$flag)
- {
- log_message('error',sprintf('%s (%s): %s, %s', __FILE__,__LINE__,'TX_EMAIL with ID:'.$id.' '.$msg, $txeparams));
- }
- // ************ END TX_EMAIL *********** //
- if( isset( $json->data->driver_payload) )
- {
- $gparams = array('stoken' => $json->data->driver_payload->data->driver_stoken );
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams );
- if ( ACTIVITY_RECORD == true ) {
- $cancelDetail = array( "txno" => $txno,
- "cancel_date" => TO_MySQL_DATE(),
- "cancel_by" => "client",
- "cancel_remark" => $cancel_remark);
- $activityDetail = array( "type" => "tx_cancel",
- "tx" => $cancelDetail);
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- }
- else
- {
- $msgid='{"message_id": -1, "message" : "No Driver Payload, this is no driver cancellation"}';
- }
- die("0@@Success@@". $msgid);
- }
- function tx_cancel($txno)
- {
- $CANCEL = 1;
- $COMPLETE = 1;
- $WORKING = 9;
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- die("1@@Error: TxNo not registered");
- }
- $txrecord = $txrecord[0];
- if( $txrecord->status_id != $WORKING )
- {
- // die("1@@Error: TxNo is not in DRIVING status");
- }
- $tsparams = array('status_id' => $CANCEL,
- 'complete_timestamp' => date('Y-m-d H:i:s'),
- );
- $this->model_goexpress->add_tx($tsparams, $txrecord->id);
- // Send GCM
- $json = json_decode( $txrecord->payload );
- $data = array(
- "driver_info" => "tx_canceled",
- );
- // FIXME sent gcm to driver
- $gparams = array('stoken' => $json->data->SToken );
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams );
- if ( ACTIVITY_RECORD == true ) {
- $cancelDetail = array( "txno" => $txno,
- "cancel_date" => TO_MySQL_DATE(),
- "cancel_by" => "office");
- $activityDetail = array( "type" => "tx_cancel",
- "tx" => $cancelDetail);
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- die("0@@Success@@". $msgid);
- }
- function tx_refresh($txno)
- {
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- $driver_latlng = $this->model_goexpress->get_driver_last_latlng($txno);
- if(count($txrecord) > 0 )
- {
- $result = new StdClass();
- $result->tx_ack = $txrecord[0]->ack_status_id;
- $result->status_id = $txrecord[0]->status_id;
- if( isset($driver_latlng->lat) )
- {
- $result->driver_lat = $driver_latlng->lat;
- $result->driver_lng = $driver_latlng->lng;
- }
- else
- {
- $result->driver_lat = "";
- $result->driver_lng = "";
- }
- die(json_encode($result));
- }
- else
- die();
- }
- function proxy_gcm($userid, $salt = null, $authtoken = null)
- {
- $ERROR = 1;
- $SUCCESS = 0;
- $payload = file_get_contents('php://input');
- //error_log('proxy_gcm logging');
- //
- if( !$payload )
- {
- $resultjson = array(
- 'error' => 1,
- 'error_message' => 'Empty payload',
- );
- $retstr = json_encode($resultjson);
- error_log('proxy_gcm error ' . $retstr);
- die( $retstr );
- }
- $json = json_decode($payload);
- //error_log('proxy_gcm txno ' . $json->data->txno );
- if( !isset($json->data->SToken) OR strlen($json->data->SToken) == 0)
- {
- $tparams = array('txno'=> $json->data->txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: No TX",
- 'driver_info' => 'driver_map',
- 'driver_lat' => '',
- 'driver_lng' => '',
- 'SToken' => '',
- );
- die( json_encode($resjson) );
- }
- $txrecord = $txrecord[0];
- $jsonrecord = json_decode($txrecord->payload);
- $SToken = $jsonrecord->data->SToken;
- //error_log('proxy_gcm record ' . $txrecord->SToken);
- //error_log('proxy_gcm payload ' . serialize($json->data));
- }
- else
- $SToken = $json->data->SToken;
- //error_log('proxy_gcm SToken ' . $SToken);
- if( isset($json->data->txno) and $json->data->txno != '' )
- {
- error_log('proxy_gcm txno in pre insert ' . $json->data->txno);
- $dparams = array(
- 'tstamp' => date('Y-m-d H:i:s'),
- 'txno' => $json->data->txno,
- 'driver_id' => $userid,
- 'lat'=> $json->data->driver_lat,
- 'lng'=> $json->data->driver_lng,
- );
- list($flag, $void, $msg) = $this->model_goexpress->save_driving_log($dparams);
- error_log(sprintf('Result %s of %s ', $flag, $msg));
- }
- if( $SToken != OFFICE_LOGIN)
- {
- $resultjson = array(
- 'error' => 0,
- 'error_message' => 'Success',
- 'driver_info' => 'driver_map',
- //'driver_lat' => "-6.1111",
- 'driver_lat' => $json->data->driver_lat,
- //'driver_lng' => "116.787878",
- 'driver_lng' => $json->data->driver_lng,
- 'SToken' => $SToken,
- );
- $params = array('stoken' => $SToken);
- $this->sendFirebaseCloudMessage2($resultjson, $params);
- die(json_encode($resultjson));
- }
- else
- {
- $resultjson = array(
- 'error' => 0,
- 'error_message' => 'Success, '.OFFICE_LOGIN,
- 'data' => '',
- );
- die(json_encode($$resultjson));
- }
- }
- public function gox_promotion(){
- $promo = $this->model_goexpress->get_promotion();
- if ( $promo != null ) {
- die(json_encode($promo));
- }
- else {
- die(array( 'has_promotion' => 0,
- 'link' => "",
- 'redirect' => 0));
- }
- }
- public function promotion_page($userid)
- {
- if ( $this->model_goexpress->check_has_promotion() ) {
- $this->linkPage = site_url("goexpress/promotion_page/$userid/");
- $this->segment = 4;
- $this->perPage = 10;
- $params['offset']= $this->start_page($this->segment);
- $params['limit'] = $this->perPage;
- $params['userid']= $userid;
- $this->totalPage = $this->model_goexpress->getLuckyPromo($params, true);
- $data['records'] = $this->model_goexpress->getLuckyPromo($params, false);
- $data['total'] = $this->totalPage;
- $data['start'] = $params['offset']+1;
- $data['paging'] = $this->pagination();
- $data['lang'] = $this->client_lang;
- //$data['records'] = $this->model_goexpress->getLuckyPromo(array( 'userid' => $userid));
- $this->load->view("webview/lucky_draw",$data);
- }
- else
- $this->load->view("webview/no_promotion"); // temporary when no promotion
- }
- public function driver_meet($txno)
- {
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- $txrecord = $txrecord[0];
- $json = json_decode($txrecord->payload);
- if ( $json->data->lang == "km") {
- switch($json->data->Actionmode)
- {
- case 'TRANSPORT':
- $title = "អេច ដឹកជញ្ជូន";
- $msg = "អ្នកបើកបររបស់ GO-X បានត្រៀមខ្លួនរួចរាល់ក្នុងការដឹកជញ្ជូនលោកអ្នកហើយ";
- break;
- case 'DELIVERY':
- $title = "អេច ដឹកទំនិញ";
- $msg = "អ្នកបើកបររបស់ GO-X បានត្រៀមខ្លួនរួចរាល់ក្នុងការដឹកជញ្ជូនទំនិញរបស់លោកអ្នកហើយ";
- break;
- case 'SHOP':
- $title = "អេច ទិញទំនិញ";
- $msg = "អ្នកបើកបររបស់ GO-X បានត្រៀមខ្លួនរួចរាល់ក្នុងការដើរទិញទំនិញជូនលោកអ្នកហើយ";
- default:
- $title = $json->data->Actionmode;
- $msg = "អ្នកបើកបររបស់ GO-X បានត្រៀមខ្លួនរួចរាល់ក្នុងការទទួលការបញ្ជារបស់លោកអ្នកហើយ";
- }
- }
- else {
- switch($json->data->Actionmode)
- {
- case 'TRANSPORT':
- $title = "TRANSPORT";
- $msg = "Your Driver ready to transport";
- break;
- case 'DELIVERY':
- $title = "DELIVERY";
- $msg = "Your Driver ready to delivery";
- break;
- case 'SHOP':
- $title = "SHOP";
- $msg = "Your Driver ready to start shopping";
- default:
- $title = $json->data->Actionmode;
- $msg = "Your Driver ready to carry your order";
- }
- }
- $uparams = array('has_meet' => 1 );
- $this->model_goexpress->update_tx($uparams, $txrecord->id);
- $resultjson = array(
- 'error' => 0,
- 'error_message' => 'Success',
- 'driver_info' => 'driver_meet',
- 'driver_remark' => $msg,
- 'SToken' => $json->data->SToken,
- );
- $notification = array(
- "title" => $title,
- "body" => $msg,
- "sound" => "default"
- );
- if ( ACTIVITY_RECORD == true ) {
- $meetDetail = array("txno" => $txno,
- "driver_username" => $txrecord->driver_username);
- $activityDetail = array("type" => "driver_meet",
- "meet" => $meetDetail);
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- die(json_encode(
- $this->sendFirebaseCloudMessage2($resultjson, array('stoken' => $json->data->SToken), $notification)
- ));
- }
- public function driver_meet2($txno)
- {
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- $txrecord = $txrecord[0];
- $json = json_decode($txrecord->payload);
- switch($json->data->Actionmode)
- {
- case 'TRANSPORT':
- $msg = "Your Driver ready to transport";
- break;
- case 'DELIVERY':
- $msg = "Your Driver ready to delivery";
- break;
- case 'SHOP':
- $msg = "Your Driver ready to shop";
- default:
- $msg = "Your Driver ready to carry your order";
- }
- $uparams = array('has_meet' => 1 );
- $this->model_goexpress->update_tx($uparams, $txrecord->id);
- $resultjson = array(
- 'error' => 0,
- 'error_message' => 'Success',
- 'driver_info' => 'driver_meet',
- 'driver_remark' => $msg,
- 'SToken' => $json->data->SToken,
- );
- die(json_encode(
- $this->sendFirebaseCloudMessageIOS2($resultjson, array('stoken' => $json->data->SToken))
- ));
- }
- public function get_driver_marker($user_id, $txno){
- if( $user_id == -1 )
- {
- $resjson = array('error' => 1, 'error_message' => 'Error: UserID is -1 meaning no driver');
- die(json_encode($resjson));
- }
- $txno = validateTxno($txno);
- $makers = array();
- $tparams = array('driver_id'=>$user_id, 'txno' => $txno);
- $mapsrecord = $this->model_goexpress->get_driving_log($tparams);
- foreach ($mapsrecord as $row) {
- $makers['steps'][] = array('lat' => $row['lat'], 'lng' => $row['lng']);
- $makers['driver'] = $row['name'];
- }
- echo json_encode($makers);
- }
- function save_remark()
- {
- $this->gox_acl->validate_update();
- $OFFICE_CANCEL_or_COMPLETE = 10;
- $params['tx_id'] = $this->input->post('tx_no');
- $params['claim_id'] = $this->input->post('tx_id');
- $txrecord = $this->model_goexpress->get_tx($params);
- if( empty($txrecord) )
- {
- die("1@@Error: TxNo not registered");
- }
- $txrecord = $txrecord[0];
- query_log("Referal Value is ".$txrecord->is_referal);
- query_log("Tx data is ". json_encode($txrecord));
- if ( $txrecord->is_referal == 1 ) {
- $dataReferal = array( 'id' => $txrecord->client_id,
- 'promo_code' => $txrecord->promo_code
- );
- $status = $this->model_goexpress->add_referal($dataReferal);
- query_log("Referal Work with status $status");
- }
- $push['status_id'] = $this->input->post('status');
- if($push['status_id'] == 1){
- $push['cancel_remark'] = $this->input->post('remark');
- $push['cancel_type_id'] = $OFFICE_CANCEL_or_COMPLETE;
- }
- if($push['status_id'] == 3){
- $push['complete_timestamp'] = TO_MySQL_DATE();
- $push['complete_remark'] = $this->input->post('remark');
- $push['complete_type_id'] = $OFFICE_CANCEL_or_COMPLETE;
- }
- // *** Checking TriggerType *** //
- $cancel_by_office = 7;
- $comp_by_office = 8;
- if($push['status_id'] == 1)
- $email_type = $cancel_by_office;
- else
- $email_type = $comp_by_office;
- // ******* Update TX_EMAIL ****** //
- $txeparams = array(
- 'txno' => $txrecord->txno,
- 'mail_type' => $email_type,
- 'tx_date' => $txrecord->tx_date,
- 'mail_status' => 99,
- );
- list($flag, $id, $msg) = $this->_update_tx_email($txeparams);
- if(!$flag)
- {
- log_message('error',sprintf('%s (%s): %s, %s', __FILE__,__LINE__,'TX_EMAIL with ID:'.$id.' '.$msg, $txeparams));
- }
- // ********* END TX_EMAIL ********* //
- if ($this->model_goexpress->save_remark($params, $push) == true) {
- $data['message'] = 'successfully';
- $data['status'] = 'true';
- } else {
- $data['message'] = 'failed';
- $data['status'] = 'false';
- }
- echo json_encode($data);
- }
- function slink()
- {
- echo '<a href="http://bit.ly/1nH5HD6">Download</a>';
- die();
- }
- function _return_json($arr)
- {
- die(json_encode($arr));
- }
- function tx_rate($txno = null,$irating = 0)
- {
- $payload = file_get_contents('php://input');
- $json = json_decode($payload);
- $txno = validateTxno($txno);
- if(is_null($txno))
- {
- $arr = array(
- 'error' => 1,
- 'error_message' => 'Error: TXNO is NULL',
- );
- return $this->_return_json($arr);
- }
- $params['txno'] = $txno;
- $records = $this->model_goexpress->get_tx($params);
- if( empty($records) )
- {
- $arr = array(
- 'error' => 1,
- 'error_message' => 'Error: No data with this txno',
- );
- return $this->_return_json($arr);
- }
- $record = $records[0];
- $tsparams = array('rating' => $irating,
- );
- list($flag, $void, $msg) = $this->model_goexpress->add_tx($tsparams, $record->id);
- $dparams = (array)$json;
- $dparams['tx_id'] = $record->id;
- list($flag, $void, $msg) = $this->model_goexpress->add_tx_survey($dparams);
- if( $flag )
- $arr['error'] = 0;
- else
- $arr['error'] = 1;
- $arr['error_message'] = $msg;
- return $this->_return_json($arr);
- }
- //fungsi khusus untuk mengextrack payload dan mengisi driver_username dan driver_name yang kosong di tx
- function extract_payload_tx() {
- $tparams = array('txno' => $this->uri->segment(3) );
- $txrecord = $this->model_goexpress->get_tx($tparams);
- foreach ( $txrecord as $row ) {
- $json = json_decode($row->payload);
- if( count($json) > 0 ) {
- $data = array(
- 'driver_username' => $json->data->UserID,
- 'driver_name' => $json->data->UserName
- );
- list($flag, $id, $msg ) = $this->model_goexpress->update_tx($data, $row->id);
- if( $flag )
- {
- echo 'successfully : '.$row->id.'<br>';
- $this->db->trans_commit();
- }
- else
- {
- echo 'failed : '.$msg.'<br>';
- $this->db->trans_rollback();
- }
- }else{
- print_r($json);
- }
- }
- }
- function check_driver_ack($txno)
- {
- error_log('check driver ack logging');
- $CLIENT_ACK = 20;
- $ERROR = 1;
- $OPEN = 0;
- $WORKING =
- $DRIVING = 9;
- $DRIVER_ACK = 10;
- // validate the tx
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- if( empty($txrecord) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: No TX",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- $txrecord = $txrecord[0];
- if( !isset($txrecord->txno) )
- {
- $resjson = array(
- 'error' => $ERROR,
- 'error_message' => "Error: TX is Broken",
- 'msgid' => "",
- 'payload' => "",
- );
- die( json_encode($resjson) );
- }
- $json = json_decode($txrecord->payload);
- if( !isset($json->data->driver_payload->data))
- {
- $resjson = array(
- 'error' => 2,
- 'error_message' => 'Info: waiting a Driver to ACK',
- 'msgid' => '',
- );
- die(json_encode($resjson));
- }
- $json_driver = $json->data->driver_payload->data;
- error_log('ID '.$json_driver->driver_userid.' status_id '.$txrecord->status_id);
- // validate if it is closed
- //if( $txrecord->status_id != $OPEN )
- //{
- // $resjson = array(
- // 'error' => $ERROR,
- // 'error_message' => "Error: TX is TAKEN",
- // 'msgid' => "",
- // 'payload' => "",
- // );
- // die( json_encode($resjson) );
- //}
- $oparams = array('txno' => $txrecord->txno);
- $officeorder = $this->office_model->get_order($oparams);
- if( $officeorder->driver_ack == 0)
- {
- $resjson = array('error' => 4, 'error_message' => 'Waiting Driver ACK, queueing OFFICE ACK');
- die(json_encode($resjson));
- }
- $resjson = array('error' => 1, 'error_message' => 'Error: default value');
- $tsparams = array('ack_status_id' => $CLIENT_ACK );
- $this->model_goexpress->add_tx($tsparams, $txrecord->id);
- // send gcm to driver
- $data = array(
- "client_info" => "tx_ack",
- "payload" => "",
- );
- $json = json_decode($txrecord->payload);
- $gparams = array('stoken' => $json->data->driver_payload->data->driver_stoken );
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams );
- if( $flag == 0)
- {
- $resjson = array(
- 'error' => 0,
- 'error_message' => 'Success',
- 'payload' => $json_driver,
- );
- }
- else
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: ClientACK sent to Driver failed',
- 'payload' => $json_driver,
- );
- }
- die(json_encode($resjson));
- }
- function broadcast_softupdate()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- // send gcm to CLIENT channel
- $data = array(
- "driver_info" => "driver_softupdate",
- "message" => "hello",
- );
- $gparams = array('stoken' => '/topics/goxupdate' );
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams );
- if( $flag == 0)
- {
- $resjson = array(
- 'error' => 0,
- 'error_message' => 'Success',
- );
- }
- else
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: broadcast update failed',
- );
- }
- die(json_encode($resjson));
- }
- function broadcast_driver_loginreset()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- // send gcm to CLIENT channel
- $data = array(
- "server_info" => "server_loginreset",
- "message" => "hello",
- );
- $gparams = array('stoken' => '/topics/MOTOBIKE' );
- list($flag, $msg, $msgid ) = $this->sendFirebaseCloudMessage2( $data, $gparams );
- if( $flag == 0)
- {
- $resjson = array(
- 'error' => 0,
- 'error_message' => 'Success',
- );
- }
- else
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: broadcast update failed',
- );
- }
- die(json_encode($resjson));
- }
- function verify_promocode()
- {
- $ACTIVE = 0;
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload );
- if( !isset($json->user_id) or $json->user_id == '')
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: PromoCode invalid',
- 'error_code' => 1,
- );
- die(json_encode($resjson));
- }
- if( !isset($json->promo_code) or $json->promo_code == '')
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: PromoCode invalid',
- 'error_code' => 2,
- );
- die(json_encode($resjson));
- }
- if( !isset($json->isclt) or $json->isclt == '')
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: PromoCode invalid',
- 'error_code' => 3,
- );
- die(json_encode($resjson));
- }
- $reqparams = array('username' => $json->user_id );
- $user_req = $this->model_goexpress->get_user($reqparams);
- if( isset($user_req->id) )
- {
- // continue
- }
- else
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: Requester invalid',
- 'error_code' => 3,
- );
- die(json_encode($resjson));
- }
- // *******************************
- // check if is referral
- // *******************************
- $pFlag = false;
- $isReferralMode = false;
- $REFERRAL_MODE = 1;
- $REFERRAL_LEN = 4;
- $str_promocode = strtolower($json->promo_code);
- $deduction = 0;
- if( strlen($str_promocode) == $REFERRAL_LEN)
- {
- $isReferralMode = true;
- $pparams = array('referal_code' => $str_promocode);
- $user_rec = $this->model_goexpress->get_user($pparams);
- if(isset($user_rec->id))
- {
- $promo_params = array(
- 'user_id' => $user_rec->id ,
- 'dpromo_code' => $str_promocode ,
- );
- $promo_detail = $this->model_goexpress->get_promo_detail($promo_params);
- if( count($promo_detail) == 1 )
- {
- $promo_detail = $promo_detail[0];
- // we have the promo code set to this userid
- // but not taken then it is valid
- if( isset($promo_detail->id) and $promo_detail->is_used == 0 )
- $pFlag = true;
- }
- }
- if(!isset($user_rec->id) and $pFlag === false)
- {
- $pparams = array('username' => $json->user_id);
- $user_rec = $this->model_goexpress->get_user($pparams);
- if( isset($user_rec->id))
- {
- // check if this user already taken someone promo?
- $promo_params = array(
- 'user_id' => $user_rec->id ,
- 'promo_id' => $REFERRAL_MODE,
- );
- $promo_detail = $this->model_goexpress->get_promo_detail($promo_params);
- if( count($promo_detail) == 0 )
- {
- // if have not create one
- $promo_params = array(
- 'dpromo_code' => $str_promocode ,
- 'user_id' => $user_rec->id,
- 'promo_id' => $REFERRAL_MODE,
- );
- $promo_detail = $this->model_goexpress->add_promo_detail($promo_params);
- $pFlag = true;
- }
- }
- }
- }
- // *******************************
- // if not then PROMOCODE
- // *******************************
- if( $pFlag === false and $isReferralMode == false)
- {
- $promo_params = array(
- 'idelete' => $ACTIVE ,
- 'name' => $str_promocode ,
- );
- $promo_record = $this->model_goexpress->get_promo_code2($promo_params);
- if( isset($promo_record->id) )
- {
- $pparams = array('username' => $json->user_id);
- $user_rec = $this->model_goexpress->get_user($pparams);
- if( isset($user_rec->id))
- {
- $promo_params = array(
- 'user_id' => $user_rec->id ,
- 'dpromo_code' => $str_promocode ,
- 'is_used' => 0,
- );
- $promo_detail = $this->model_goexpress->get_promo_detail($promo_params);
- if( count($promo_detail) > 0 )
- {
- $pFlag = true;
- }
- else
- {
- $promo_params = array(
- 'dpromo_code' => $str_promocode ,
- 'user_id' => $user_rec->id,
- 'promo_id' => $promo_record->id,
- );
- $promo_detail = $this->model_goexpress->add_promo_detail($promo_params);
- $pFlag = true;
- }
- }
- }
- else
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Invalid PromoCode',
- 'error_code' => 1,
- );
- die(json_encode($resjson));
- }
- }
- $params = array(
- 'username' => $json->user_id,
- 'idelete' => $ACTIVE,
- );
- $user = $this->model_goexpress->get_user($params);
- if( !isset($user->id) )
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: PromoCode invalid',
- 'error_code' => 4,
- );
- die(json_encode($resjson));
- }
- $resjson = array(
- 'error' => 0,
- 'error_message' => 'Success',
- 'error_code' => 0,
- );
- die(json_encode($resjson));
- }
- function verify_promocode2()
- {
- $ACTIVE = 0;
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload );
- if( !isset($json->user_id) or $json->user_id == '')
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: PromoCode Invalid',
- 'error_code' => 1,
- );
- die(json_encode($resjson));
- }
- if( !isset($json->promo_code) or $json->promo_code == '')
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: PromoCode Invalid',
- 'error_code' => 2,
- );
- die(json_encode($resjson));
- }
- if( !isset($json->isclt) or $json->isclt == '')
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: PromoCode Invalid',
- 'error_code' => 3,
- );
- die(json_encode($resjson));
- }
- $reqparams = array('username' => $json->user_id );
- $user_req = $this->model_goexpress->get_user($reqparams);
- if( isset($user_req->id) )
- {
- // continue
- }
- else
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: Requester Invalid',
- 'error_code' => 3,
- );
- die(json_encode($resjson));
- }
- // ******************************* //
- // check Promo Code //
- // ******************************* //
- $str_promocode = strtoupper($json->promo_code);
- $uparams = array('username' => $json->user_id);
- $user_rec = $this->model_goexpress->get_user($uparams);
- $promoValue = $this->model_goexpress->getDeduction(
- array("promo_code" => $str_promocode,
- "userid" => $user_rec->id ));
- if($promoValue == 0) {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: PromoCode Invalid',
- 'error_code' => 5,
- );
- die(json_encode($resjson));
- }
- $params = array(
- 'username' => $json->user_id,
- 'idelete' => $ACTIVE,
- );
- $user = $this->model_goexpress->get_user($params);
- if( !isset($user->id) )
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => 'Error: PromoCode Invalid',
- 'error_code' => 4,
- );
- die(json_encode($resjson));
- }
- $resjson = array(
- 'error' => 0,
- 'error_message' => 'Success',
- 'error_code' => 0,
- );
- die(json_encode($resjson));
- }
- function promo_deduction()
- {
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload );
- $REFERRAL_LEN = 4;
- if( !isset($json->user_id) or $json->user_id == '')
- {
- $resjson = array(
- 'error' => 0,
- 'error_message' => 'Error: PromoCode invalid',
- 'error_code' => 1,
- 'deduction' => 0,
- );
- die(json_encode($resjson));
- }
- if( !isset($json->promo_code) or $json->promo_code == '')
- {
- $resjson = array(
- 'error' => 0,
- 'error_message' => 'Error: PromoCode invalid',
- 'error_code' => 2,
- 'deduction' => 0,
- );
- die(json_encode($resjson));
- }
- $resjson = array(
- 'error' => 0,
- 'error_message' => 'Success',
- 'error_code' => 0,
- 'deduction' => 2000,
- );
- die(json_encode($resjson));
- }
- function driver_token_reg()
- {
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload );
- list($flag, $skip, $msg) = $this->user_model->update_driver_token_reg($json);
- $this->user_model->add_driver_token_log($json);
- if( isset($json->driving_session) AND $json->driving_session == true)
- {
- // save into driving log
- $dparams = array(
- 'tstamp' => date('Y-m-d H:i:s'),
- 'txno' => $json->txno,
- "driver_id" => $json->user_id,
- 'lat'=> $json->lat,
- 'lng'=> $json->lng,
- );
- list($flag, $void, $msg) = $this->model_goexpress->save_driving_log($dparams);
- if(!$flag)
- error_log("Save driving log error ". $json->txno);
- }
- if ( ACTIVITY_RECORD == true ) {
- $uparams = array(
- 'username' => $json->user_id
- );
- $driverRecord = $this->model_goexpress->get_user($uparams);
- $driverDetail = array( "lat" => $json->lat,
- "lng" => $json->lng,
- "username" => $json->user_id,
- "name" => $driverRecord->name,
- "online" => $json->status
- );
- $activityDetail = array( "type" => "driver_update",
- "client" => $driverDetail);
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- $resjson = array(
- 'error' => REVERSE_iFLAG($flag),
- 'error_message' => $msg
- );
- die(json_encode($resjson));
- }
- function getrating()
- {
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload ,true);
- if ( !isset($json['userid']) OR !isset($json['isclt']) OR $json['isclt'] != 50 )
- {
- $resjson = array(
- 'error' => 1,
- 'error_message' => "Failed to get rating data"
- );
- die(json_encode($resjson));
- }
- $data =$this->model_goexpress->getRating($json);
- $resjson = array(
- 'error' => 0,
- 'totalRating' => number_format($data['totalRating'],2,",","."),
- 'lifetimeTrips' => $data['lifetimeTrips'],
- 'ratedTrips' => $data['ratedTrips'],
- 'fiveStars' => $data['fiveStars'],
- 'error_message' => "Failed to get rating data"
- );
- die(json_encode($resjson));
- }
- //function place_autocomplete($str)
- //{
- // $uri = sprintf("https://maps.googleapis.com/maps/api/place/autocomplete/json/?key=%s&components=%s&input=%s",
- // "AIzaSyAZJF74FLkXGZ4VhXXRetiO8gaMlL6lsZI",
- // "country:kh",
- // $str
- // );
- //}
- function earning($userid=null)
- {
- if ( isset($_GET["userid"])) {
- $userid = $_GET["userid"];
- }
- $payload = file_get_contents('php://input');
- $this->linkPage = site_url("goexpress/earning/".$userid."/");
- $this->segment = 4;
- $this->perPage = 10;
- $params['userid']= $userid;
- $params['offset']= $this->start_page($this->segment);
- $params['limit'] = $this->perPage;
- $this->totalPage = $this->model_goexpress->get_earning_data($params, true);
- $records = $this->model_goexpress->get_earning_data($params, false);
- $data['total'] = $this->totalPage;
- $data['start'] = $params['offset']+1;
- $data['paging'] = $this->pagination();
- $this->load->view('webview/header');
- $this->load->view('webview/earning', array('earning' => $records, 'data'=> $data ));
- $this->load->view('webview/footer');
- }
- function wallet()
- {
- $payload = file_get_contents('php://input');
- $userid= $this->input->get('userid');
- $total_wallet =$this->model_goexpress->get_driver_wallet_total($userid);
- $this->load->view('webview/header');
- $this->load->view('webview/driver_wallet', array('total_wallet' => $total_wallet));
- $this->load->view('webview/footer');
- }
- function news_update()
- {
- $this->load->model('news_model');
- $params['date'] = date('Y-m-d');
- $params['status'] = 1;
- $data['records'] = $this->news_model->get_all($params);
- $this->load->view('goexpress/news_update', $data);
- }
- function send_sms()
- {
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload );
- $smsparams = array(
- 'update_date' => date('Y-m-d H:i:s'),
- 'isms_status' => $json->isms_status,
- );
- list($flag, $void, $msg) = $this->user_model->add_sendsms2($smsparams, $json->user_id);
- $resjson = array(
- 'error' => REVERSE_iFLAG($flag),
- 'error_message' => $msg,
- );
- error_log($json. " resjson ". $resjson);
- die(json_encode($resjson));
- }
- function check_version()
- {
- $CLIENT = 90;
- $DRIVER = 50;
- $FATAL_ERROR = 2;
- $PERMISSIVE_ERROR = 1;
- $SUCCESS = 0;
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload );
- error_log("CHECK_VERSION ". $payload);
- if ( $this->uri->segment(1) == "km") {
- $message = "តម្រូវឲ្យធ្វើការទាញយកកំណែទម្រង់ថ្មី";
- }
- else {
- $message = "New Version Needed.";
- }
- //COMMENT SIR ADE UPDATE START 1
- if( $json->isclt == $DRIVER )
- {
- query_log("Current version is " . $json->version);
- if( intval(str_replace(".","",$json->version)) >= I_DRIVER_VERSION )
- {
- $resjson = array(
- 'error' => $SUCCESS,
- 'error_message' => 'Your permissive error is working!',
- );
- die(json_encode($resjson));
- }
- }
- //COMMENT SIR ADE UPDATE END 1
- if( $json->isclt == $CLIENT )
- {
- if( isset($json->is_android) && $json->is_android == 1 )
- {
- if( intval(str_replace(".","",$json->version)) >= I_CLIENT_VERSION_ANDROID )
- {
- $resjson = array(
- 'error' => $SUCCESS,
- 'error_message' => 'Your permissive error is working!',
- );
- die(json_encode($resjson));
- }
- }
- if( isset($json->is_ios) && $json->is_ios == 1 )
- {
- if( intval(str_replace(".","",$json->version)) >= I_CLIENT_VERSION_IOS )
- {
- $resjson = array(
- 'error' => $SUCCESS,
- 'error_message' => 'Your permissive error is working!',
- );
- die(json_encode($resjson));
- }
- }
- $resjson = array(
- 'error' => $FATAL_ERROR,
- 'error_message' => $message,
- );
- //$resjson = array(
- // 'error' => $SUCCESS,
- // 'error_message' => 'Your permissive error is working!',
- //);
- error_log("CHECK_VERSION CLIENT REPLY". json_encode($resjson));
- die(json_encode($resjson));
- }
- //COMMENT SIR ADE UPDATE START 2
- $resjson = array(
- 'error' => $FATAL_ERROR,
- 'error_message' => $message,
- );
- //COMMENT SIR ADE UPDATE END 2
- error_log("CHECK_VERSION DRIVER REPLY". json_encode($resjson));
- die(json_encode($resjson));
- }
- function tx_refresh2($txno)
- {
- $txno = validateTxno($txno);
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- $driver_latlng = $this->model_goexpress->get_driver_last_latlng($txno);
- if(count($txrecord) > 0 )
- {
- $result = new StdClass();
- $result->status_id = $txrecord[0]->status_id;
- if( isset($driver_latlng->lat) )
- {
- $result->driver_lat = $driver_latlng->lat;
- $result->driver_lng = $driver_latlng->lng;
- }
- else
- {
- $result->driver_lat = "";
- $result->driver_lng = "";
- }
- die(json_encode($result));
- }
- else
- die();
- }
- function my_history($userid)
- {
- $this->linkPage = site_url("goexpress/my_history/$userid/");
- $this->segment = 4;
- $this->perPage = 10;
- $params['offset']= $this->start_page($this->segment);
- $params['limit'] = $this->perPage;
- $params['userid']= $userid;
- $this->totalPage = $this->model_goexpress->get_history_data($params, true);
- $data['history'] = $this->model_goexpress->get_history_data($params, false);
- $data['total'] = $this->totalPage;
- $data['start'] = $params['offset']+1;
- $data['paging'] = $this->pagination();
- $this->load->view('webview/header');
- $this->load->view('webview/history', $data);
- $this->load->view('webview/footer');
- }
- function send_email()
- {
- $payload = file_get_contents('php://input');
- query_log($payload);
- $json = json_decode( $payload );
- $uparams = array(
- 'username' => $json->username
- );
- $user = $this->model_goexpress->get_user($uparams);
- if ( strlen($json->email_message) < 5 ) {
- die(json_encode(array( 'error' => 1, 'error_message' => 'Please insert minimal 5 char!' )));
- }
- $to = 'info@goexpress-kh.com';
- //$to = 'williamgunawan22@gmail.com';
- $from = $user->email;
- //$from = "mailerdaemon@goexpress-kh.com";
- $subject_text = "Question from customer " . $user->name . " (".$user->hp.")\n";
- $email_text = $subject_text;
- $email_text .= $json->email_message;
- $this->load->library('phpmailer2');
- query_log($email_text);
- $this->phpmailer2->addAddress($to, "GoExpress Office");
- $this->phpmailer2->addFrom($from, $user->name);
- $this->phpmailer2->subject($subject_text);
- $this->phpmailer2->message($email_text );
- if ( !$this->phpmailer2->send() )
- {
- query_log( $this->phpmailer2->ErrorInfo);
- log_message('error',sprintf('%s (%s): %s, %s', __FILE__,__LINE__,'Email not sent', $this->phpmailer2->ErrorInfo));
- }
- die(json_encode(array( 'error' => 0, 'error_message' => 'Success to send email to office!' )));
- }
- /**
- * @param Trigger Type
- * @param TX Number
- * Email Trigger
- */
- function send_email2()
- {
- // ******* TRIGGER TYPE ****** //
- $confirm_order = 1;
- $cancel_onwait = 2;
- $cancel_by_cust = 3;
- $comp_by_cust = 4;
- $cancel_by_driver = 5;
- $comp_by_driver = 6;
- $cancel_by_office = 7;
- $comp_by_office = 8;
- $data = array();
- $payload = file_get_contents('php://input');
- query_log($payload);
- $json = json_decode($payload);
- // NOTE: For Testing without phone
- // if(empty($json->trigger_type)) {
- // $json->trigger_type = $confirm_order;
- // $json->txno = '1479112492228'; // tx on demo
- // }
- if(empty($json->trigger_type) || empty($json->txno))
- {
- echo "JSON Object is not Defined";
- die();
- }
- $txparams = array('txno' => $json->txno);
- $tx = $this->model_goexpress->get_tx_detail1($txparams);
- $data_payload = json_decode($tx->payload)->data;
- if($tx->transport == null)
- {
- $tx->transport = $data_payload->Vehicle;
- }
- $data['txrecord'] = $tx;
- $data['payload'] = json_decode($tx->payload);
- $data['payload'] = $data['payload']->data;
- $uparams = array(
- 'username' => $data['payload']->UserID
- );
- $user = $this->model_goexpress->get_user($uparams);
- $from = 'info@goexpress-kh.com';
- $to = $user->email;
- switch ($json->trigger_type) {
- case $confirm_order:
- $email_subject = lang('MailSubjConfirmation');
- $data['item_title'] = $email_subject;
- $data['email_info'] = $this->load->view('mail/booking_confirmation', $data, TRUE);
- break;
- case $cancel_onwait:
- $email_subject = lang('MailSubjCancelWait');
- $data['item_title'] = $email_subject;
- $data['email_info'] = $this->load->view('mail/cancel_on_wait', $data, TRUE);
- break;
- case $cancel_by_cust:
- $email_subject = lang('MailSubjCancelCust');
- $data['item_title'] = $email_subject;
- $data['email_info'] = $this->load->view('mail/cancel_by_cust', $data, TRUE);
- break;
- case $cancel_by_driver:
- $email_subject = lang('MailSubjCancelDriver');
- $data['item_title'] = $email_subject;
- $data['email_info'] = $this->load->view('mail/cancel_by_driver', $data, TRUE);
- break;
- case $cancel_by_office:
- $email_subject = lang('MailSubjCancelOffice');
- $data['item_title'] = $email_subject;
- $data['email_info'] = $this->load->view('mail/cancel_by_office', $data, TRUE);
- break;
- case $comp_by_cust:
- $email_subject = lang('MailSubjCompCust');
- $data['item_title'] = $email_subject;
- $data['email_info'] = $this->load->view('mail/complete_by_customer', $data, TRUE);
- break;
- case $comp_by_driver:
- $email_subject = lang('MailSubjCompDriver');
- $data['item_title'] = $email_subject;
- $data['email_info'] = $this->load->view('mail/complete_by_driver', $data, TRUE);
- break;
- case $comp_by_office:
- $email_subject = lang('MailSubjCompOffice');
- $data['item_title'] = $email_subject;
- $data['email_info'] = $this->load->view('mail/complete_by_office', $data, TRUE);
- break;
- default:
- $email_subject = lang('MailSubjConfirmation');
- $data['item_title'] = $email_subject;
- $data['email_info'] = $this->load->view('mail/booking_confirmation', $data, TRUE);
- break;
- }
- $email_message = $this->load->view('mail/mail_template', $data, TRUE);
- $this->load->library('phpmailer2');
- query_log($email_message);
- $this->phpmailer2->addFrom($from, 'GoExpress Server');
- $this->phpmailer2->addAddress($to, $user->name);
- $this->phpmailer2->subject($email_subject);
- $this->phpmailer2->message($email_message);
- if ( !$this->phpmailer2->send() )
- {
- query_log( $this->phpmailer2->ErrorInfo);
- log_message('error',sprintf('%s (%s): %s, %s', __FILE__,__LINE__,'Email not sent', $this->phpmailer2->ErrorInfo));
- }
- }
- function measure_distance2($lat1, $lat2, $lng1, $lng2)
- {
- $pochentong_coord = new StdClass();
- $pochentong_coord->lat = $lat1;
- $pochentong_coord->lng = $lng1;
- $driver_coord = new StdClass();
- $driver_coord->lat = $lat2;
- $driver_coord->lng = $lng2;
- $theta = $pochentong_coord->lng - $driver_coord->lng;
- $dist = sin(deg2rad($pochentong_coord->lat)) * sin(deg2rad($driver_coord->lat)) +
- cos(deg2rad($pochentong_coord->lat)) * cos(deg2rad($driver_coord->lat)) *
- cos(deg2rad($theta));
- $dist = acos($dist);
- $dist = rad2deg($dist);
- $miles = $dist * 60 * 1.1515;
- // Km
- $KM = 1.609344;
- $output = $miles * $KM;
- return $output;
- }
- function filter_driver($driver_records)
- {
- $DRIVER_TOKEN = 0;
- $DRIVER_ID = 1;
- $SEND_THRESHOLD = 8;
- $NO_DRIVER = 0;
- $THRESHOLD = 8; // secs
- $driver_idx = 0;
- $curtime = time();
- $ret_array = array();
- $token_driver = array();
- $bcList = array();
- $bUse = false;
- $many_driver = count($driver_records);
- foreach($driver_records as &$drvr )
- {
- $distance_r = $this->measure_distance2(
- $this->bc_start_lat,
- $drvr->lat,
- $this->bc_start_lng,
- $drvr->lng
- );
- $drvr->distance_r = $distance_r;
- }
- usort($driver_records, function($a,$b)
- {return strcmp($a->distance_r, $b->distance_r);}
- );
- foreach ($driver_records as $index => $driver)
- {
- $token_driver[] = array($driver->token,$driver->id);
- $ret_array[] = $driver->token;
- $bcList[] = array('driver_id' => $driver->id);
- // update lastbc of driver
- $drvparams = array(
- 'last_bc' => $curtime,
- 'bc_action' => $this->bc_action,
- 'bc_tx' => $this->bc_txno );
- $this->model_goexpress->update_driver_lastbc(
- $drvparams,
- $driver->id
- );
- if( $index == $SEND_THRESHOLD )
- break;
- }
- if ( ACTIVITY_RECORD == true )
- {
- foreach ($token_driver as $index => $tkn_drv)
- {
- $drvparams = array(
- 'last_bc' => $curtime,
- 'bc_action' => $this->bc_action,
- 'bc_tx' => $this->bc_txno
- );
- $this->model_goexpress->update_driver_lastbc(
- $drvparams,
- $tkn_drv[$DRIVER_ID]
- );
- }
- }
- // Record the BC activity
- if ( ACTIVITY_RECORD == true ) {
- $bcData = array( "txno" => $this->bc_txno,
- "list" => $bcList);
- $activityDetail = array( "type" => "tx_bc",
- "bc" => $bcData);
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- return $ret_array;
- // No More penalties
- }
- function promotion_banner($last_id = NULL)
- {
- $npic = $this->model_goexpress->get_npic();
- $lastId = $this->model_goexpress->get_lastId();
- $pic_url = $this->model_goexpress->get_pic_url();
- $i = 0;
- $allpic = array();
- foreach ($pic_url as $pic) {
- $allpic[$i] = base_url() . "upload/promo_banner/" .$pic->img;
- $i++;
- }
- if ( count($allpic) == 0 ) {
- $SHOW = 0;
- }
- else {
- $SHOW = SHOW_BANNER;
- }
- $resjson = array(
- "error" => 0,
- "error_message" => "Success",
- "npic" => $npic,
- "last_id" => $lastId->id,
- "show" => $SHOW,
- "pic_url" => $allpic
- );
- if( $last_id == NULL )
- $resjson["error_message"] = "Success, send latest";
- die(json_encode($resjson)) ;
- }
- function _update_tx_email($params = array())
- {
- // MAIL_TYPE
- // ORDER_CONFIRM 1
- // CANCEL_ONWAIT 2
- // CANCEL_BY_CUST 3
- // COMP_BY_CUST 4
- // CANCEL_BY_DRIVER 5
- // COMP_BY_DRIVER 6
- // CANCEL_BY_OFFICE 7
- // COMP_BY_OFFICE 8
- // MAIL_STATUS
- // PENDING 99
- // 5
- // 1
- // SUCCESS 0
- $ret_array = array(false, '', "Parameters is null");
- if(empty($params['txno']) || empty($params['mail_type']) || empty($params['tx_date']) || empty($params['mail_status']))
- {
- return $ret_array;
- }
- $txeparams = array(
- 'txno' => $params['txno'],
- 'email_type' => $params['mail_type'],
- 'tr_date' => $params['tx_date'],
- 'idelete' => $params['mail_status'],
- 'sent_date' => TO_MySQL_DATE()
- );
- return $this->model_goexpress->update_tx_email($txeparams);
- }
- function tmp_registration()
- {
- $params = $this->input->post();
- if ( count($params) < 5 ) {
- $resjson = array( 'error' => 1,
- 'error_message' => "Failed to complete the registration!"
- );
- die(json_encode($resjson));
- }
- foreach( $params as $key => $val ) {
- if ( $val == null || $val == "" ) {
- if ( $key != "submit" ) {
- $resjson = array( 'error' => 1,
- 'error_message' => "All field must be filled!"
- );
- die(json_encode($resjson));
- }
- }
- }
- if ( !isset($params['email']) ) {
- $resjson = array( 'error' => 1,
- 'error_message' => "Failed to complete the registration!"
- );
- die(json_encode($resjson));
- }
- $params['name'] = $params['firstname'] . " " . $params['lastname'];
- $params['register_date'] = TO_MySQL_DATE();
- $params['birthdate'] = TO_MySQL_DATE($params['birthdate']);
- unset($params['firstname']);
- unset($params['lastname']);
- unset($params['submit']);
- $res = $this->driver_model->add_tmp_registration($params);
- if ( $res ) {
- $resjson = array( 'error' => 0,
- 'error_message' => ""
- );
- die(json_encode($resjson));
- }
- else {
- $resjson = array( 'error' => 1,
- 'error_message' => "Failed to complete the registration!"
- );
- die(json_encode($resjson));
- }
- }
- function get_tx_nearby($tx)
- {
- $tx_detail = $this->model_goexpress->get_tx_detail(array( 'txno' => $tx));
- $payload = $tx_detail->payload;
- if( !$payload )
- {
- echo '1@@Error: Empty payload';
- die();
- }
- $txno = $tx;
- $json = json_decode($payload);
- $jTarget = $this->_process_jsontarget( $json );
- $start_detail = sprintf("%s\n*) %s", $json->data->Start->Name, $json->data->Start->Note);
- $target_detail = sprintf("%s\n*) %s", $jTarget->Name, $jTarget->Note);
- $USERTYPE_DRIVER = 50;
- $UPTIME = UPTIME; // in Minutes.
- $RANGE = 3;
- $gcparams = array(
- 'range' => $RANGE,
- 'uptime' => $UPTIME,
- 'client_lat' => $json->data->Start->Lat,
- 'client_lng' => $json->data->Start->Lng,
- );
- $gcresult = $this->_get_coord_nearby($gcparams);
- $dnparams = array(
- 'user_type' => $USERTYPE_DRIVER,
- 'transport' => $json->data->Vehicle,
- 'last_up_time' => $gcresult['last_up_time'],
- 'X1' => $gcresult['X1'],
- 'X2' => $gcresult['X2'],
- 'Y1' => $gcresult['Y1'],
- 'Y2' => $gcresult['Y2'],
- );
- $driver_nearby = $this->model_goexpress->get_driver_nearby($dnparams);
- return $driver_nearby;
- }
- function get_driver_tracking($active, $tx) {
- $alldata = $this->model_goexpress->get_bc_data_all($tx);
- $bc_data = array();
- $last_driver_id = null;
- $current_index = -1;
- foreach( $alldata AS $row => $each) {
- if ( $last_driver_id == $each->driver_id)
- $bc_data[$current_index][] = $each;
- else {
- $current_index++;
- $last_driver_id = $each->driver_id;
- $bc_data[$current_index] = array();
- $bc_data[$current_index][] = $each;
- }
- }
- $data['alldata'] = $bc_data;
- $data['firstbc'] = $this->model_goexpress->get_bc_data($tx,"First Broadcast");
- $data['secondbc'] = $this->model_goexpress->get_bc_data($tx,"Second Broadcast");
- $data['thirdbc'] = $this->model_goexpress->get_bc_data($tx,"Third Broadcast");
- $data['manualbc'] = $this->model_goexpress->get_bc_data($tx,"Manual Broadcast");
- $data['nearbylist'] = $this->get_tx_nearby($tx);
- $data['tx'] = $tx;
- die(json_encode($data));
- }
- function load_category_menu() {
- $category_menu_data = $this->model_goexpress->get_category_menu();
- die(json_encode($category_menu_data));
- }
- function load_food_tags() {
- $food_tags = $this->model_goexpress->get_food_tags();
- die(json_encode($food_tags));
- }
- function load_resto_nearme() {
- $postdata = file_get_contents("php://input");
- $json = json_decode($postdata);
- //lat
- //lng
- if (isset($json->lat) and isset($json->lng) )
- $USERTYPE_DRIVER = 50;
- $UPTIME = UPTIME; // in Minutes.
- $range = 7;
- $gcparams = array(
- 'range' => $range,
- 'uptime' => $UPTIME,
- 'client_lat' => $json->lat,
- 'client_lng' => $json->lng,
- );
- $gcresult = $this->_get_coord_nearby($gcparams);
- $dnparams = array(
- 'X1' => $gcresult['X1'],
- 'X2' => $gcresult['X2'],
- 'Y1' => $gcresult['Y1'],
- 'Y2' => $gcresult['Y2'],
- 'lat' => $json->lat,
- 'lng' => $json->lng,
- );
- $resto_nearby = $this->model_goexpress->get_nearby_resto2($dnparams);
- die(json_encode($resto_nearby));
- }
- function load_all_resto() {
- $all_resto = $this->model_goexpress->get_all_resto();
- die(json_encode($all_resto));
- }
- function load_all_resto_per_page($page){
- $postdata = file_get_contents("php://input");
- $client_loc = json_decode($postdata);
- if(isset($client_loc->lat) && isset($client_loc->lng)){
- if(($client_loc->lat != null || $client_loc->lat != "") && ($client_loc->lng != null || $client_loc->lng != "")){
- $cltLoc['lat'] = $client_loc->lat;
- $cltLoc['lng'] = $client_loc->lng;
- return($this->load_all_resto_per_page2($page, $cltLoc));
- }
- }
- $this->segment = 3;
- $this->perPage = 5;
- $params['offset']= ($page-1)*$this->perPage;
- $params['limit'] = $this->perPage;
- $this->totalData = $this->model_goexpress->get_all_resto($params, true);
- $this->totalPage = ceil($this->totalData/$this->perPage);
- $resto_data = $this->model_goexpress->get_all_resto($params, false);
- $json_data = array(
- 'show_all' => false,
- 'current_page' => $page,
- 'resto_data' => $resto_data,
- 'max_page' => $this->totalPage
- );
- die(json_encode($json_data));
- }
- function load_all_resto_per_page2($page, $cltLoc = null){
- $this->segment = 3;
- $this->perPage = 5;
- $params['lat'] = $cltLoc['lat'];
- $params['lng'] = $cltLoc['lng'];
- $params['offset']= ($page-1)*$this->perPage;
- $params['limit'] = $this->perPage;
- $this->totalData = $this->model_goexpress->get_all_resto2($params, true);
- $this->totalPage = ceil($this->totalData/$this->perPage);
- $resto_data = $this->model_goexpress->get_all_resto2($params, false);
- $json_data = array(
- 'show_all' => false,
- 'current_page' => $page,
- 'resto_data' => $resto_data,
- 'max_page' => $this->totalPage
- );
- die(json_encode($json_data));
- }
- // Load Resto List based on resto Category
- function load_resto_list() {
- $postdata = file_get_contents("php://input");
- if (isset($postdata)){
- $cat_id = json_decode($postdata);
- $cat = $this->model_goexpress->check_resto_cat($cat_id);
- }
- die(json_encode($cat));
- }
- // Load Resto List based on Food Tags
- function load_resto_list2() {
- $postdata = file_get_contents("php://input");
- if (isset($postdata)){
- $tag_id = json_decode($postdata);
- $tag = $this->model_goexpress->check_food_tag($tag_id);
- }
- die(json_encode($tag));
- }
- // Load Resto List based on resto Category per page
- function load_resto_list_new($page){
- $postdata = file_get_contents("php://input");
- $data = json_decode($postdata);
- $cat_id = $data->cat_id;
- if(isset($data->lat) && isset($data->lng)){
- if(($data->lat != null || $data->lat != "") && ($data->lng != null || $data->lng != "")){
- $cltLoc['lat'] = $data->lat;
- $cltLoc['lng'] = $data->lng;
- return($this->load_resto_list_with_clientloc($page, $cltLoc, $cat_id));
- }
- }
- $this->segment = 3;
- $this->perPage = 5;
- $params['offset']= ($page-1)*$this->perPage;
- $params['limit'] = $this->perPage;
- $this->totalData = $this->model_goexpress->check_resto_cat_all($params, true, $cat_id);
- $this->totalPage = ceil($this->totalData/$this->perPage);
- $resto_data = $this->model_goexpress->check_resto_cat_all($params, false, $cat_id);
- $json_data = array(
- 'current_page' => $page,
- 'resto_data' => $resto_data,
- 'max_page' => $this->totalPage
- );
- die(json_encode($json_data));
- }
- function load_resto_list_with_clientloc($page, $cltLoc, $cat_id){
- $this->segment = 3;
- $this->perPage = 5;
- $params['lat'] = $cltLoc['lat'];
- $params['lng'] = $cltLoc['lng'];
- $params['offset']= ($page-1)*$this->perPage;
- $params['limit'] = $this->perPage;
- $this->totalData = $this->model_goexpress->check_resto_cat_all_with_clientloc($params, true, $cat_id);
- $this->totalPage = ceil($this->totalData/$this->perPage);
- $resto_data = $this->model_goexpress->check_resto_cat_all_with_clientloc($params, false, $cat_id);
- $json_data = array(
- 'current_page' => $page,
- 'resto_data' => $resto_data,
- 'max_page' => $this->totalPage
- );
- die(json_encode($json_data));
- }
- // Load Resto List based on Food Tags per page
- function load_resto_list2_new($page){
- $postdata = file_get_contents("php://input");
- $data = json_decode($postdata);
- $tag_id = $data->tag_id;
- $tag_id = 5;
- if(isset($data->lat) && isset($data->lng)){
- if(($data->lat != null || $data->lat != "") && ($data->lng != null || $data->lng != "")){
- $cltLoc['lat'] = $data->lat;
- $cltLoc['lng'] = $data->lng;
- return($this->load_resto_list2_with_clientloc($page, $cltLoc, $tag_id));
- }
- }
- $this->segment = 3;
- $this->perPage = 5;
- $params['offset']= ($page-1)*$this->perPage;
- $params['limit'] = $this->perPage;
- $this->totalData = $this->model_goexpress->check_food_tag_all($params, true, $tag_id);
- $this->totalPage = ceil($this->totalData/$this->perPage);
- $resto_data = $this->model_goexpress->check_food_tag_all($params, false, $tag_id);
- $json_data = array(
- 'show_all' => true,
- 'current_page' => $page,
- 'resto_data' => $resto_data,
- 'max_page' => $this->totalPage
- );
- die(json_encode($json_data));
- }
- function load_resto_list2_with_clientloc($page, $cltLoc, $tag_id){
- $this->segment = 3;
- $this->perPage = 5;
- $params['lat'] = $cltLoc['lat'];
- $params['lng'] = $cltLoc['lng'];
- $params['offset']= ($page-1)*$this->perPage;
- $params['limit'] = $this->perPage;
- $this->totalData = $this->model_goexpress->check_food_tag_all_with_clientloc($params, true, $tag_id);
- $this->totalPage = ceil($this->totalData/$this->perPage);
- $resto_data = $this->model_goexpress->check_food_tag_all_with_clientloc($params, false, $tag_id);
- $json_data = array(
- 'show_all' => true,
- 'current_page' => $page,
- 'resto_data' => $resto_data,
- 'max_page' => $this->totalPage
- );
- die(json_encode($json_data));
- }
- function load_food_list() {
- $postdata = file_get_contents("php://input");
- if (isset($postdata))
- $restoId = json_decode($postdata);
- $cat_food_list = $this->model_goexpress->get_cat_food($restoId);
- die(json_encode($cat_food_list));
- }
- function load_food_list_new() {
- $postdata = file_get_contents("php://input");
- if (isset($postdata))
- $restoId = json_decode($postdata);
- $cat_food_list = $this->model_goexpress->get_resto_cat_with_menu($restoId);
- die(json_encode($cat_food_list));
- }
- function load_food_list2() {
- $postdata = file_get_contents("php://input");
- if (isset($postdata))
- $data = json_decode($postdata);
- $catId = $data->submenu_id;
- $restoId = $data->resto_id;
- $food_list = $this->model_goexpress->get_food($catId, $restoId);
- die(json_encode($food_list));
- }
- function search_resto() {
- $postdata = file_get_contents("php://input");
- if (isset($postdata))
- $data = json_decode($postdata);
- $resto_list = $this->model_goexpress->get_search_resto($data);
- die(json_encode($resto_list));
- }
- function check_home_menu_flag(){
- // Flag for MINIVAN Active or Inactive
- // 0 for INACTIVE
- // 1 for ACTIVE
- $flag = array(
- "flag" => 1
- );
- die(json_encode($flag));
- }
- function save_resto_rating(){
- $postdata = file_get_contents("php://input");
- if(isset ($postdata)){
- $data = json_encode($postdata);
- $save_params = array(
- 'id_resto' => $data->restoid,
- 'restoname' => $data->restoname,
- 'address' => $data->address,
- 'id_user' => $data->userid,
- 'name' => $data->name,
- 'rating' => $data->rating,
- 'comment' => $data->comment,
- 'txno' => $data->txno,
- 'is_rated' => 1
- );
- $save_rating = $this->model_goexpress->save_resto_rating($save_params);
- }
- if($save_rating){
- $data['status'] = 'true';
- $data['message'] = 'success';
- } else {
- $data['status'] = 'false';
- $data['message'] = 'failed';
- }
- die(json_encode($data));
- }
- function load_xfood_orders(){
- // $postdata = file_get_contents("php://input");
- // $data = json_decode($postdata);
- // if(isset($data)){
- // $userid = $data->userid;
- // }
- $userid = "6d9a1f3ee8a67402144ab62f8f927063";
- $get = $this->model_goexpress->get_xfood_orders($userid);
- // die(var_dump($get));
- $index = 0;
- $index2 = 0;
- $index3 = 0;
- $null = array();
- if(isset($get)){
- foreach ($get as $object) {
- $data0[$index3] = $object;
- $data = json_decode($object->payload)->data;
- if(isset($data->Start->XfoodNote->list_order)){
- $menu[$index] = $data->Start->XfoodNote->list_order;
- foreach ($menu[$index] as $value) {
- $check[$index] = $this->model_goexpress->check_is_rated($value->id);
- if($check[$index]->is_rated == 0){
- $res[$index2]->orders = $value;
- $res[$index2]->is_rated = 0;
- $res[$index2]->txno = $data0[$index3]->txno;
- $res[$index2]->tx_id = $data0[$index3]->id;
- } else {
- $res[$index2]->orders = $value;
- $res[$index2]->is_rated = 1;
- $res[$index2]->txno = $data0[$index3]->txno;
- $res[$index2]->tx_id = $data0[$index3]->id;
- }
- $index2++;
- }
- $index++;
- }
- $index3++;
- }
- if(isset($res)){
- die(json_encode($res));
- } else {
- die(json_encode($null));
- }
- }
- die(json_encode($null));
- }
- function search_embassy() {
- $postdata = file_get_contents("php://input");
- if (isset($postdata))
- $data = json_decode($postdata);
- $embassy_list = $this->model_goexpress->get_search_embassy($data);
- die(json_encode($embassy_list));
- }
- function iSendSmsViaGateway( )
- {
- $ERROR = 0;
- $CODE_SUCCESS = 0;
- $SUCCESS = 1;
- $apiKey = 'username=goexpress_sms@mekongnet&pass=dd5ad747f4c1659a1236bd37169e2fd0&sender=GO-X&smstext=';
- $sms = "GO-X.\nYour verification number is 123456\n លេខកូដរបស់អ្នកគឺ "."123456";
- $sms = str_replace(" ","+",$sms);
- $sms = str_replace("\n","%0A",$sms);
- $apiEnder = "&isflash=1&gsm=85587898689;85510759542";
- $url = 'http://client.mekongsms.com/api/sendsms.aspx?' .
- $apiKey.
- $sms.
- $apiEnder;
- $headers = array(
- "Content-Type: application/x-www-form-urlencoded; charset=utf-8",
- );
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_URL, $url );
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec( $ch );
- if ( curl_errno( $ch ) )
- {
- echo '1@@FCM error: ' . curl_error( $ch );
- // set a flag
- }
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- //if( @$result->results[0]->error == "MissmatchSenderId")
- // return $this->sendFirebaseCloudMessageIOS($data, $ids, $params, $options);
- $response = explode("\n", $result);
- if(count($response) > 0)
- {
- $arrResponse = explode(" ", $response[0]);
- if( $assResponse[0] == $CODE_SUCCESS)
- return $SUCCESS;
- else
- return $ERROR;
- }
- else
- {
- return $ERROR;
- }
- }
- function driver_get_notification($userid, $txno)
- {
- $receive = 1;
- $decline = 2;
- query_log("Driver get $txno notification");
- if ( ACTIVITY_RECORD == true ) {
- $receiveDetail = array( "driver_username" => $userid,
- "txno" => $txno,
- "receive_date" => TO_MySQL_DATE());
- $activeDetail = array( "type" => "driver_get_notif",
- "bc" => $receiveDetail);
- $this->model_goexpress->add_activity(json_encode($activeDetail));
- }
- $params = array( "driver_username" => $userid,
- "txno" => $txno,
- "receive_time" => time(),
- "bc_status" => $receive);
- $this->model_goexpress->update_bc_status($params);
- }
- function release_driver_bc($userid)
- {
- $receive = 1;
- $decline = 2;
- $postdata = file_get_contents("php://input");
- $decline_type = 0;
- if ( isset($userid) and strlen($userid) > 5 ) {
- $this->model_goexpress->update_release_lastbc($userid);
- if ( strlen($postdata) > 5 ) {
- $json = json_decode($postdata);
- if ( isset($json->release_type) ) {
- $decline_type = $json->release_type;
- }
- else {
- }
- query_log("Save release data " . $json->release_type);
- }
- $resjson = array( "error" => 0,
- "error_message" => "");
- $params = array( "driver_username" => $userid,
- "txno" => $txno,
- "decline_time" => time(),
- "decline_type" => $decline_type,
- "bc_status" => $decline);
- $this->model_goexpress->update_bc_status($params);
- if ( ACTIVITY_RECORD == true ) {
- $declineDetail = array( "driver_username" => $userid,
- "decline_date" => TO_MySQL_DATE());
- $activityDetail = array( "type" => "driver_decline_notif",
- "bc" => $declineDetail);
- $this->model_goexpress->add_activity(json_encode($activityDetail));
- }
- }
- else {
- $resjson = array( "error" => 1,
- "error_message" => "No user id");
- }
- die(json_encode($resjson));
- }
- function load_police_nearme() {
- $postdata = file_get_contents("php://input");
- $json = json_decode($postdata);
- if (isset($json->lat) and isset($json->lng) ){
- $USERTYPE_DRIVER = 50;
- $UPTIME = UPTIME; // in Minutes.
- $range = 7;
- $gcparams = array(
- 'range' => $range,
- 'uptime' => $UPTIME,
- 'client_lat' => $json->lat,
- 'client_lng' => $json->lng,
- );
- $gcresult = $this->_get_coord_nearby($gcparams);
- $dnparams = array(
- 'X1' => $gcresult['X1'],
- 'X2' => $gcresult['X2'],
- 'Y1' => $gcresult['Y1'],
- 'Y2' => $gcresult['Y2'],
- );
- $police_nearby = $this->model_goexpress->get_nearby_police($dnparams);
- }
- die(json_encode($police_nearby));
- }
- function load_firefighter_nearme() {
- $postdata = file_get_contents("php://input");
- $json = json_decode($postdata);
- if (isset($json->lat) and isset($json->lng) ){
- $USERTYPE_DRIVER = 50;
- $UPTIME = UPTIME; // in Minutes.
- $range = 7;
- $gcparams = array(
- 'range' => $range,
- 'uptime' => $UPTIME,
- 'client_lat' => $json->lat,
- 'client_lng' => $json->lng,
- );
- $gcresult = $this->_get_coord_nearby($gcparams);
- $dnparams = array(
- 'X1' => $gcresult['X1'],
- 'X2' => $gcresult['X2'],
- 'Y1' => $gcresult['Y1'],
- 'Y2' => $gcresult['Y2'],
- );
- $firefighter_nearby = $this->model_goexpress->get_nearby_firefighter($dnparams);
- }
- die(json_encode($firefighter_nearby));
- }
- function load_hospital_nearme() {
- $postdata = file_get_contents("php://input");
- $json = json_decode($postdata);
- if (isset($json->lat) and isset($json->lng) ){
- $USERTYPE_DRIVER = 50;
- $UPTIME = UPTIME; // in Minutes.
- $range = 7;
- $gcparams = array(
- 'range' => $range,
- 'uptime' => $UPTIME,
- 'client_lat' => $json->lat,
- 'client_lng' => $json->lng,
- );
- $gcresult = $this->_get_coord_nearby($gcparams);
- $dnparams = array(
- 'X1' => $gcresult['X1'],
- 'X2' => $gcresult['X2'],
- 'Y1' => $gcresult['Y1'],
- 'Y2' => $gcresult['Y2'],
- );
- $hospital_nearby = $this->model_goexpress->get_nearby_hospital($dnparams);
- }
- die(json_encode($hospital_nearby));
- }
- function load_embassy() {
- $embassy = $this->model_goexpress->get_embassy();
- die(json_encode($embassy));
- }
- function load_police() {
- $police = $this->model_goexpress->get_police();
- die(json_encode($police));
- }
- function load_client_news() {
- $postdata = file_get_contents("php://input");
- if(isset($postdata)){
- $json = json_decode($postdata);
- $promo_start = strtotime("2017-4-7 14:00:00");
- $promo_end = strtotime("2018-4-7 23:59:59");
- $now = time();
- if ( $now >= $promo_start && $now <= $promo_end ) {
- $userRecord = $this->model_goexpress->get_user(array("username" => $json->userID));
- query_log("Promotion still run so check promotion executed ");
- query_log("Username is " .$userRecord->username. "Registration date is " . $userRecord->registration_date . " time is " . strtotime($userRecord->registration_date));
- if ( strtotime($userRecord->registration_date) >= $promo_start && strtotime($userRecord->registration_date) <= $promo_end ) {
- query_log("Execute check registration promotion because in range promotion with username " .$userRecord->username." Name ". $userRecord->name);
- $this->model_goexpress->check_tmp_promo($userRecord);
- }
- else
- query_log("Discard check because registration date out of promotion range");
- }
- else {
- query_log("out of range promotion");
- }
- $username = $json->userID;
- $global = $this->model_goexpress->get_client_news(null);
- $client = $this->model_goexpress->get_client_news($username);
- $index = 0;
- foreach ($global as $record) {
- unset($record->is_broadcasted);
- unset($record->status);
- $news[strtotime($record->create_date)] = $record;
- }
- foreach ($client as $record) {
- unset($record->is_broadcasted);
- unset($record->status);
- $news[strtotime($record->create_date)] = $record;
- }
- krsort($news);
- foreach( $news as $each ) {
- $newdata[$index] = $each;
- $index++;
- }
- }
- die(json_encode($newdata));
- }
- function lucky_code_page($userid)
- {
- $this->linkPage = site_url("goexpress/lucky_code_page/$userid/");
- $this->segment = 4;
- $this->perPage = 10;
- $params['offset']= $this->start_page($this->segment);
- $params['limit'] = $this->perPage;
- $params['userid']= $userid;
- $this->totalPage = $this->model_goexpress->get_lucky_code($params, true);
- $data['records'] = $this->model_goexpress->get_lucky_code($params, false);
- $data['total'] = $this->totalPage;
- $data['start'] = $params['offset']+1;
- $data['paging'] = $this->pagination();
- $this->load->view("webview/lucky_code",$data);
- }
- function get_xfood_lang(){
- $lang = array(
- array(
- "lang" => 'en',
- "name" => "English"
- ),
- array(
- "lang" => 'km',
- "name" => "ខ្មែរ"
- ),
- array(
- "lang" => 'cn',
- "name" => "中文"
- )
- );
- die(json_encode($lang));
- }
- function order_receipt($id){
- $dataList = array();
- $rawdata = $this->model_goexpress->get_tx_detail(array('txno'=>$id));
- $data = json_decode($rawdata->payload)->data;
- $user = $this->security_model->getUsersFromApi($this->apikey);
- if(isset($data->Actionmode)){
- if($data->Actionmode == 'FOOD'){
- $this->load->model("xfood_model");
- if(isset($data->Start->XfoodNote)){
- if(isset($data->Start->XfoodNote->restoname)){
- $dataList['resto_name'] = $data->Start->XfoodNote->restoname;
- $restodata = $this->xfood_model->get_all(array("restoname" => $data->Start->XfoodNote->restoname, "limit" => 1, "offset" => 0));
- } else {
- $dataList['resto_name'] = null;
- }
- if(isset($data->Start->XfoodNote->restoaddress)){
- $dataList['resto_address'] = $data->Start->XfoodNote->restoaddress;
- } else {
- $dataList['resto_address'] = null;
- }
- if(isset($data->Start->XfoodNote->list_order)){
- $dataList['records'] = $data->Start->XfoodNote->list_order;
- } else {
- $dataList['records'] = null;
- }
- if(isset($data->Start->XfoodNote->notes)){
- $dataList['notes'] = $data->Start->XfoodNote->notes;
- } else {
- $dataList['notes'] = null;
- }
- if(isset($data->Start->XfoodNote->total)){
- $dataList['est_total'] = $data->Start->XfoodNote->total;
- } else {
- $dataList['est_total'] = null;
- }
- if(isset($data->Start->XfoodNote->deliveryFee)){
- $dataList['delivery_fee'] = $data->Start->XfoodNote->deliveryFee;
- } else {
- $dataList['delivery_fee'] = null;
- }
- if(isset($data->Start->XfoodNote->xfoodTotalOrder)){
- $dataList['totalTotal'] = $data->Start->XfoodNote->xfoodTotalOrder;
- } else {
- $dataList['totalTotal'] = null;
- }
- if(isset($data->Start->XfoodNote->restoPhone)){
- $dataList['resto_phone'] = $data->Start->XfoodNote->restoPhone;
- } else {
- if ( isset($restodata) && isset($restodata[0]) && isset($restodata[0]->phone_number)) {
- $dataList['resto_phone'] = $restodata[0]->phone_number;
- }
- else {
- $dataList['resto_phone'] = null;
- }
- }
- if(isset($data->Start->XfoodNote->restoPhone2)){
- $dataList['resto_phone_2'] = $data->Start->XfoodNote->restoPhone2;
- } else {
- if ( isset($restodata) && isset($restodata[0]) && isset($restodata[0]->phone_number_2)) {
- $dataList['resto_phone_2'] = $restodata[0]->phone_number_2;
- }
- else {
- $dataList['resto_phone_2'] = null;
- }
- }
- $dataList['txno'] = $id;
- $dataList['user_type'] = $user->user_type_id;
- $this->load->view('webview/xfood_receipt', $dataList);
- }
- }
- else if($data->Actionmode == 'MART'){
- $this->load->model("xmart_model");
- if(isset($data->Start->XmartNote)){
- if(isset($data->Start->XmartNote->martname)){
- $dataList['mart_name'] = $data->Start->XmartNote->martname;
- $martdata = $this->xmart_model->get_xmart_all(array("mart_name" => $data->Start->XmartNote->martname, "limit" => 1, "offset" => 0));
- } else {
- $dataList['mart_name'] = null;
- }
- if(isset($data->Start->XmartNote->martaddress)){
- $dataList['mart_address'] = $data->Start->XmartNote->martaddress;
- } else {
- $dataList['mart_address'] = null;
- }
- if(isset($data->Start->XmartNote->list_order)){
- $dataList['records'] = $data->Start->XmartNote->list_order;
- } else {
- $dataList['records'] = null;
- }
- if(isset($data->Start->XmartNote->notes)){
- $dataList['notes'] = $data->Start->XmartNote->notes;
- } else {
- $dataList['notes'] = null;
- }
- if(isset($data->Start->XmartNote->total)){
- $dataList['est_total'] = $data->Start->XmartNote->total;
- } else {
- $dataList['est_total'] = null;
- }
- if(isset($data->Start->XmartNote->deliveryFee)){
- $dataList['delivery_fee'] = $data->Start->XmartNote->deliveryFee;
- } else {
- $dataList['delivery_fee'] = null;
- }
- if(isset($data->Start->XmartNote->xmartTotalOrder)){
- $dataList['totalTotal'] = $data->Start->XmartNote->xmartTotalOrder;
- } else {
- $dataList['totalTotal'] = null;
- }
- if(isset($data->Start->XmartNote->martPhone)){
- $dataList['mart_phone'] = $data->Start->XmartNote->martPhone;
- } else {
- if ( isset($martdata) && isset($martdata[0]) && isset($martdata[0]->phone_number)) {
- $dataList['mart_phone'] = $martdata[0]->phone_number;
- }
- else {
- $dataList['mart_phone'] = null;
- }
- }
- if(isset($data->Start->XmartNote->martPhone2)){
- $dataList['mart_phone_2'] = $data->Start->XmartNote->martPhone2;
- } else {
- if ( isset($martdata) && isset($martdata[0]) && isset($martdata[0]->phone_number_2)) {
- $dataList['mart_phone_2'] = $martdata[0]->phone_number_2;
- }
- else {
- $dataList['mart_phone_2'] = null;
- }
- }
- $dataList['txno'] = $id;
- $dataList['user_type'] = $user->user_type_id;
- $this->load->view('webview/xmart_receipt', $dataList);
- }
- }
- // *** If Shopping *** //
- // else if($data->Actionmode == 'SHOPPING') {
- // if(isset($data->Start->XshoppingNote)){
- // $dataList['records'] = $data->Start->XshoppingNote->list_order;
- // $this->load->view('webview/xshopping_receipt', $dataList);
- // }
- // }
- // *** END If Shopping *** //
- else {
- if(isset($data->Start->Note) && strlen($data->Start->Note) >= 3){
- $dataList['note'] = $data->Start->Note;
- }
- else {
- $dataList['note'] = "No Note Available!";
- }
- $this->load->view('webview/global_receipt', $dataList);
- }
- }
- }
- function get_target_address(){
- $postdata = file_get_contents("php://input");
- if (isset($postdata))
- $data = json_decode($postdata);
- $target_address = $this->model_goexpress->getting_target_address($data);
- die(json_encode($target_address));
- }
- function order_receipt_detail($id){
- $dataList = array();
- $rawdata = $this->model_goexpress->get_tx_detail(array('txno'=>$id));
- $data = json_decode($rawdata->payload)->data;
- if(isset($data->Actionmode)){
- if($data->Actionmode == 'FOOD'){
- if(isset($data->Start->XfoodNote)){
- if(isset($data->Start->XfoodNote->restoname)){
- $dataList['resto_name'] = $data->Start->XfoodNote->restoname;
- } else {
- $dataList['resto_name'] = null;
- }
- if(isset($data->Start->XfoodNote->restoaddress)){
- $dataList['resto_address'] = $data->Start->XfoodNote->restoaddress;
- } else {
- $dataList['resto_address'] = null;
- }
- if(isset($data->Start->XfoodNote->list_order)){
- $dataList['records'] = $data->Start->XfoodNote->list_order;
- } else {
- $dataList['records'] = null;
- }
- if(isset($data->Start->XfoodNote->notes)){
- $dataList['notes'] = $data->Start->XfoodNote->notes;
- } else {
- $dataList['notes'] = null;
- }
- if(isset($data->Start->XfoodNote->total)){
- $dataList['est_total'] = $data->Start->XfoodNote->total;
- } else {
- $dataList['est_total'] = null;
- }
- // die(var_dump($dataList));
- $this->load->view('webview/xfood_receipt_detail', $dataList);
- }
- }
- else if($data->Actionmode == 'MART'){
- if(isset($data->Start->XmartNote)){
- if(isset($data->Start->XmartNote->martname)){
- $dataList['mart_name'] = $data->Start->XmartNote->martname;
- } else {
- $dataList['mart_name'] = null;
- }
- if(isset($data->Start->XmartNote->martaddress)){
- $dataList['mart_address'] = $data->Start->XmartNote->martaddress;
- } else {
- $dataList['mart_address'] = null;
- }
- if(isset($data->Start->XmartNote->list_order)){
- $dataList['records'] = $data->Start->XmartNote->list_order;
- } else {
- $dataList['records'] = null;
- }
- if(isset($data->Start->XmartNote->notes)){
- $dataList['notes'] = $data->Start->XmartNote->notes;
- } else {
- $dataList['notes'] = null;
- }
- if(isset($data->Start->XmartNote->total)){
- $dataList['est_total'] = $data->Start->XmartNote->total;
- } else {
- $dataList['est_total'] = null;
- }
- // die(var_dump($dataList));
- $this->load->view('webview/xmart_receipt_detail', $dataList);
- }
- }
- // *** If Shopping *** //
- // else if($data->Actionmode == 'SHOPPING') {
- // if(isset($data->Start->XshoppingNote)){
- // $dataList['records'] = $data->Start->XshoppingNote->list_order;
- // $this->load->view('webview/xshopping_receipt', $dataList);
- // }
- // }
- // *** END If Shopping *** //
- else {
- if(isset($data->Start->Note) && strlen($data->Start->Note) >= 3){
- $dataList['note'] = $data->Start->Note;
- }
- else {
- $dataList['note'] = "No Note Available!";
- }
- $this->load->view('webview/global_receipt_detail', $dataList);
- }
- }
- }
- function gcm_ordermon($title = null, $data = null)
- {
- $OPEN = 0;
- // Structure as follow:
- //$data = array(
- // "title" => $title,
- // "id" => 283,
- // "txno" =>"1491366092405",
- // "lat" => 11.482171339779,
- // "lng" => 104.94448235527,
- // "vehicleID" => 2, // moto
- // "payload" => "",
- //);
- $data['title'] = $title;
- //------------------------------
- // The recipient registration IDs
- // that will receive the push
- // (Should be stored in your DB)
- //
- // Read about it here:
- // http://developer.android.com/google/gcm/
- //------------------------------
- $ids = array( 'abc', 'def' );
- //------------------------------
- // Call our custom GCM function
- //------------------------------
- $bresult = $this->sendFirebaseCloudMessageOM( $data, $ids, null, array());
- return null;
- }
- function get_ordermon_payload($txno)
- {
- $tparams = array('txno'=>$txno);
- $txrecord = $this->model_goexpress->get_tx($tparams);
- $data = array('payload' => $txrecord[0]->payload);
- die(json_encode($txrecord[0]->payload));
- }
- function gcm_ordermon2()
- {
- $OPEN = 0;
- $txno = '1493434635288';
- // Structure as follow:
- $data = array(
- "title" => "tx",
- "id" => 283,
- "txno" => $txno,
- "lat" => 11.482171339779,
- "lng" => 104.94448235527,
- "vehicleID" => 2, // moto
- "payload" => "",
- );
- //$data['title'] = $title;
- //------------------------------
- // The recipient registration IDs
- // that will receive the push
- // (Should be stored in your DB)
- //
- // Read about it here:
- // http://developer.android.com/google/gcm/
- //------------------------------
- $ids = array( 'abc', 'def' );
- //------------------------------
- // Call our custom GCM function
- //------------------------------
- $bresult = $this->sendFirebaseCloudMessageOM( $data, $ids, null, array());
- return null;
- }
- function sendFirebaseCloudMessageOM( $data, $ids, $params = array(), $options = array() )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- // if ( $this->is_firebase == false ) {
- // return $this->sendGoogleCloudMessage($data,$ids,$params,$options);
- // }
- $apiKey = 'AIzaSyBVtIzVFE7zyPDOREWYffkwOAOxw8RjYo0';
- //$apiKey = 'AIzaSyDSaYxDq8Fu8HfjYgb0w2rRqKxZbh0RiRM';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://fcm.googleapis.com/fcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $post = array(
- 'data' => $data,
- );
- if( isset( $params['registration_ids'] ) )
- {
- $post['registration_ids'] = $params['registration_ids'];
- }
- else if( isset( $options['stoken'] ) )
- {
- $post['to'] = $options["stoken"];
- }
- else
- {
- // @TODO REMOVE THIS VALIDATION SINCE redundant
- // and already filtered at registration_ids filter
- if( isset($data['Vehicle'] ))
- $post['to'] = "/topics/" . $data['Vehicle'];
- else
- $post['to'] = "/topics/ordermon";
- }
- query_log("OM Post Data " . json_encode($post));
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- // if ( curl_errno( $ch ) )
- // {
- // if( isset($options['ret_int']) and $options['ret_int'] === True )
- // error_log('1@@FCM error: ' . curl_error( $ch ));
- // else
- // echo '1@@FCM error: ' . curl_error( $ch );
- // // set a flag
- // }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- if( isset($options['ret_int']) )
- {
- error_log("gcm_ordermon BC is ". $result);
- return $result;
- }
- if( isset($params['separate']))
- error_log("gcm_ordermon :" .'@@0@@'.@$data['text'].'@@'.$result );
- else
- error_log("gcm_ordermon :" .'0@@'.@$data['text'].'@@'.$result );
- }
- // BAP
- function update_token()
- {
- //Define Api key
- if ( $this->uri->segment(1) == "apikey" )
- $apikey = $this->uri->segment(2);
- else
- $apikey = $this->uri->segment(3);
- $min_length = 20;
- if ( strlen($apikey) <= $min_length ) {
- $error_m = array("error" => 0, "error_message" => "Failed Api Key.");
- echo json_encode($error_m);
- die();
- }
- $data = file_get_contents('php://input');
- if( !$data )
- {
- $error_m = array("error" => 0, "error_message" => "Empty data.");
- echo json_encode($error_m);
- die();
- }
- $json = json_decode($data,true);
- if( !isset($json['fcm_token']) )
- {
- $error_m = array("error" => 0, "error_message" => "Empty Token.");
- echo json_encode($error_m);
- die();
- }
- $json["apikey"] = $apikey;
- if($this->model_goexpress->get_update_token($json))
- {
- $error_m = array("error" => 0, "error_message" => "Success Token Upadate.");
- echo json_encode($error_m);
- die();
- }
- $error_m = array("error" => 0, "error_message" => "Failed Upadate Token.");
- echo json_encode($error_m);
- }
- function email_ignore()
- {
- $this->gox_acl->validate_read();
- $this->linkPage = site_url("goexpress/email_ignore/");
- $this->segment = 3;
- $this->perPage = 10;
- $params['offset']= $this->start_page($this->segment);
- $params['limit'] = $this->perPage;
- $this->totalPage = $this->model_goexpress->get_email_ignore($params, true);
- $data['records'] = $this->model_goexpress->get_email_ignore($params, false);
- $data['start'] = $params['offset']+1;
- $data['link'] = $this->pagination();
- $data['subTitle']= 'Email Ignore';
- $this->template->write_view('content', 'goexpress/list_email_ignore', $data);
- $this->template->render();
- }
- function add_email_ignore()
- {
- $data['subTitle'] = "Add Email Ignore";
- $this->load->view('goexpress/add_email_ignore', $data);
- }
- function edit_email_ignore($id)
- {
- $params['id'] = $id;
- $data['subTitle'] = "Update Email Ignore";
- $data['records'] = $this->model_goexpress->get_email_ignore($params, false);
- $this->load->view('goexpress/edit_email_ignore', $data);
- }
- function save_email_ignore()
- {
- $data['status'] = "false";
- $data['message']= lang('msg_failed_saved');
- $key = $this->input->post('id');
- $params['user_id'] = $this->input->post('user_id');
- $params['tr_date'] = $this->input->post('tr_date');
- if ( $this->model_goexpress->get_save_email_ignore( $params, $key) ) {
- $data['status'] = "true";
- $data['message'] = lang('msg_success_saved');
- }
- echo json_encode($data);
- }
- function destroy_email_ignore($id)
- {
- $data['status'] = "false";
- $data['message']= lang('msg_failed_saved');
- $params['idelete'] = "1";
- if ($this->model_goexpress->get_save_email_ignore($params, $id)) {
- $data['message'] = lang('msg_success_delete');
- $data['status'] = 'true';
- }
- echo json_encode($data);
- }
- function s_email_ignore()
- {
- $term = $this->input->post('term');
- $params = array(
- 'name' => $term,
- 'limit' => 50
- );
- $data['records'] = $this->model_goexpress->get_search_email_ignore($params);
- die( $this->load->view('goexpress/s_email_ignore', $data, TRUE) );
- }
- // BAP
- function my_barcode($username)
- {
- $data['barcode'] = shuffle_username($username);
- $this->load->view('webview/my_barcode',$data);
- }
- function load_all_mart_per_page($page){
- $postdata = file_get_contents("php://input");
- $client_loc = json_decode($postdata);
- if(isset($client_loc->lat) && isset($client_loc->lng)){
- if(($client_loc->lat != null || $client_loc->lat != "") && ($client_loc->lng != null || $client_loc->lng != "")){
- $cltLoc['lat'] = $client_loc->lat;
- $cltLoc['lng'] = $client_loc->lng;
- return($this->load_all_mart_per_page2($page, $cltLoc));
- }
- }
- $this->segment = 3;
- $this->perPage = 5;
- $params['offset']= ($page-1)*$this->perPage;
- $params['limit'] = $this->perPage;
- $this->totalData = $this->model_goexpress->get_all_mart($params, true);
- $this->totalPage = ceil($this->totalData/$this->perPage);
- $mart_data = $this->model_goexpress->get_all_mart($params, false);
- $json_data = array(
- 'show_all' => true,
- 'current_page' => $page,
- 'mart_data' => $mart_data,
- 'max_page' => $this->totalPage
- );
- die(json_encode($json_data));
- }
- function load_all_mart_per_page2($page, $cltLoc = null){
- $this->segment = 3;
- $this->perPage = 5;
- $params['lat'] = $cltLoc['lat'];
- $params['lng'] = $cltLoc['lng'];
- $params['offset']= ($page-1)*$this->perPage;
- $params['limit'] = $this->perPage;
- $this->totalData = $this->model_goexpress->get_all_mart2($params, true);
- $this->totalPage = ceil($this->totalData/$this->perPage);
- $resto_data = $this->model_goexpress->get_all_mart2($params, false);
- $json_data = array(
- 'show_all' => true,
- 'current_page' => $page,
- 'mart_data' => $resto_data,
- 'max_page' => $this->totalPage
- );
- die(json_encode($json_data));
- }
- function load_category_item() {
- $category_item_data = $this->model_goexpress->get_category_item();
- die(json_encode($category_item_data));
- }
- function load_mart_tags() {
- $food_tags = $this->model_goexpress->get_mart_tags();
- die(json_encode($food_tags));
- }
- function load_mart_nearme() {
- $postdata = file_get_contents("php://input");
- $json = json_decode($postdata);
- //lat
- //lng
- if (isset($json->lat) and isset($json->lng) )
- $USERTYPE_DRIVER = 50;
- $UPTIME = UPTIME; // in Minutes.
- $range = 7;
- $gcparams = array(
- 'range' => $range,
- 'uptime' => $UPTIME,
- 'client_lat' => $json->lat,
- 'client_lng' => $json->lng,
- );
- $gcresult = $this->_get_coord_nearby_mart($gcparams);
- $dnparams = array(
- 'X1' => $gcresult['X1'],
- 'X2' => $gcresult['X2'],
- 'Y1' => $gcresult['Y1'],
- 'Y2' => $gcresult['Y2'],
- 'lat' => $json->lat,
- 'lng' => $json->lng,
- );
- $resto_nearby = $this->model_goexpress->get_nearby_mart2($dnparams);
- die(json_encode($resto_nearby));
- }
- function _get_coord_nearby_mart($params = array())
- {
- if ( !isset($params['minrange']) )
- $params['minrange'] = $params['range'];
- $const = GET_COORD_CONST();
- $result = array('X1' => 0, 'X2' => 0, 'Y1' => 0, 'Y2' => 0);
- $range = $params['range'];
- $ddmax_result = ($params['range']/$const['distance'])*$const['degree'];
- $result['X1'] = $params['client_lat'] - $ddmax_result;
- $result['Y1'] = $params['client_lng'] - $ddmax_result;
- $result['X2'] = $params['client_lat'] + $ddmax_result;
- $result['Y2'] = $params['client_lng'] + $ddmax_result;
- $now_time = date('Y-m-d H:i:s', strtotime('now'));
- $result['last_up_time'] = CALC_TIME($params['uptime'], '-');
- return $result;
- }
- function load_mart_list() {
- $postdata = file_get_contents("php://input");
- if (isset($postdata))
- $cat_id = json_decode($postdata);
- $cat = $this->model_goexpress->check_mart_cat($cat_id);
- die(json_encode($cat));
- }
- function load_mart_list_new() {
- $postdata = file_get_contents("php://input");
- if (isset($postdata))
- $martId = json_decode($postdata);
- $cat_mart_list = $this->model_goexpress->get_mart_cat_with_item($martId);
- die(json_encode($cat_mart_list));
- }
- function load_mart_list2() {
- $postdata = file_get_contents("php://input");
- if (isset($postdata))
- $tag_id = json_decode($postdata);
- $tag = $this->model_goexpress->check_mart_tag($tag_id);
- die(json_encode($tag));
- }
- function search_mart() {
- $postdata = file_get_contents("php://input");
- if (isset($postdata))
- $data = json_decode($postdata);
- $resto_list = $this->model_goexpress->get_search_mart($data);
- die(json_encode($resto_list));
- }
- /* function getfares_mart()
- {
- $input_payload = file_get_contents('php://input');
- // validate the driver
- $json = json_decode($input_payload,true);
- if ( $this->model_goexpress->checkDistance($json) == 1 )
- {
- $returndata = array(
- "error" => 3,
- "error_message" => "Your total distance exceed ".getMaxdistance($json['transport'])." km..");
- }
- else {
- $userRecord = $this->model_goexpress->get_user(array("username" => $json["id"]));
- $json["id"] = $userRecord->id;
- $json["all_data"] = 1;
- if( !(isset($json["promo_code"]) and $json["promo_code"] != "" and $json["promo_code"] != " " )) {
- if ( $this->PROMO_ACTIVE == true ) {
- $json["promo_code"] = $this->getPromoCode($json["transport"]);
- }
- }
- list($total_price, $normal_fare, $promo_value) = $this->model_goexpress->getFares($json);
- $returndata = array(
- "error" => 0,
- "fares" => $total_price,
- "promo_value" => $promo_value,
- "normal_fare" => $normal_fare,
- "error_message" => "");
- }
- die( json_encode($returndata));
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement