<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Service extends Admin_Controller {

    function __construct() {
        parent::__construct();
    }

    public function index() {
        $this->pending();
    }

    //***********************
    public function ludropoff() {
        $this->showServiceRequestList(1,'0,1', 'Lundry Drop Off', 'newrequest');
    }

    public function dryclean() {
        $this->showServiceRequestList(2, '0,1', 'Dry Cleaning Service', 'newrequest');
    }

    public function drycleanconfirmed() {
        $this->showServiceRequestList(2, '2', 'Confirmed - Dry Cleaning Service', 'newrequest');
    }

    public function drycleanassigned() {
        $this->showServiceRequestList(2, '4', 'Assigned - Dry Cleaning Service', 'newrequest');
    }

    public function drycleancompleted() {
        $this->showServiceRequestList(2, '4', 'Completed - Dry Cleaning Service', 'newrequest');
    }

    public function homecleaning() {
        $this->showServiceRequestList(3,'0,1', 'Home Cleaning', 'newrequest');
    }

    public function homelundry() {
        $this->showServiceRequestList(4,'0,1', 'Home Lundry', 'newrequest');
    }

    public function washandfold() {
        $this->showServiceRequestList(5,'0,1', 'Wash & Fold', 'newrequest');
    }

    public function showServiceRequestList($serviceType, $listType, $page_title, $pPath = '') {
        $data = array();
        $data['do_not_script'] = 0;
        $this->load->model('service_model');
        $outx = $this->service_model->getServiceRequestListStatus($serviceType, $listType, 1000);
        $data['transport_request'] = $outx['service_request_list'];
        $data["pagination_links"] = ""; // $this->pagination->create_links();
        $data['page_title'] = $page_title;
        $data['service_path'] = $pPath;
        $data['service_type'] = $serviceType;
        $this->renderAdminPage('service/view_genericlist_servicelist', $data);
    }

      public function selpending() {
        $data['transp_id'] = $this->input->get('transp_id');
        $this->load->model('combo_model');
        $data['provider_combo'] = '';

        if ($data["transp_id"] != '' and $data["transp_id"] > 0) {
            $mysql = " SELECT DATE_PART('hour', t.service_date - now() ) AS day_gap, t.*,m.firstname AS req_firstname,"
                    . " a.street AS to_street,a.city AS to_city,a.state AS to_state,a.zipcode AS to_zipcode,"
                    . " mp.city AS from_city,mp.state AS from_state,mp.street1 AS from_street,mp.zipcode AS from_zipcode,"
                    . " m.lastname AS req_lastname, m.username AS req_username,TO_CHAR(t.service_date :: TIMESTAMP, 'Day Mon dd, yyyy HH:MI AM') AS long_date,t.service_type "
                    . " FROM members_service_request t "
                    . " LEFT JOIN members m ON m.id=t.member_id "
                    . " LEFT JOIN members_profile mp ON mp.member_id =m.id "
                    . " LEFT JOIN agents a ON a.id = t.agent_id"
                    . " WHERE t.id=" . $data['transp_id'];

            //   $q = $this->db->query($mysql);
            $query = $this->db->query($mysql);
            $data['selected_transport'] = $query->row_array();
            $data['rect'] = $data['selected_transport'];
            $data['service_list'] = $this->GetServiceList($data['transp_id'],$data['rect']['service_type']);

            $data["payment_data"] = "Payment Information will show after payment confirmation";

            if ($data['rect']["payment_id"] != '' AND $data['rect']["payment_id"] > 0) {
                $data["payment_data"] = $this->paymentDetail($data['rect']["payment_id"]); //"Payment Information will show after payment confirmation-00";   
                $this->combo_model->defaultComboMessage = 'Select your driver';
                $data['provider_combo'] = $this->combo_model->getProvidersListTypeCombo('providers', '0');
                
            }
            $this->load->view('admin/service/extra/service_form', $data);
        }
    }
    
               

            
            
    
    public function GetServiceList($transp_id, $service_type) {
        $serive_detail = "";

        switch ($service_type) {
            case 1:
                $mysql = "SELECT * FROM members_service_request WHERE id = 115";
                $query = $this->db->query($mysql);
                $data['sel_service'] = $query->row_array();
                $serive_detail = $data['sel_service']["quantity"] . " Bag(s)";
                break;
            case 2:
                $mysql = "SELECT code,description,price*0.01 AS price,quantity,total*0.01 AS total "
                        . " FROM members_service_detail WHERE service_id=" . $transp_id;
                $this->load->library('table');
                            $this->table->set_template($this->template);

                $query = $this->db->query($mysql);
                //$this->table->set_heading(array('data' => 'Location Name', 'style' => 'width:220px'), 'Email', array('data' => 'Zipcode', 'style' => 'width:100px'));
                $serive_detail = $this->table->generate($query);

                break;
        }


        return $serive_detail;
}

//***********************
    
    public function assignDriver() {
        $ret = -1;
        $data['service_id'] = $this->input->get('service_id');
        $data['driver_id'] = $this->input->get('driver_id');
        if ($data['service_id'] != '' && $data['service_id'] > 0 && $data['driver_id'] != '' && $data['driver_id'] > 0) {

            $data['action'] = MOBIDELIV_TRANSP_ASSIGNTRANSPORT;
            $out = array();
            $ret = $this->medtrans_api($data, $out);
        }
        echo $ret;
    }

    private function paymentDetail($payment_id)
    {
        /*
        
kleen=> SELECT * FROM payment WHERE id  = 19;
 id | member_id | what |    location     |             time              | amount | fee | status | flags | confirmation | pid | random | account_id | partner_id | dt_cancelled |         dt_confirmed          | approval_code | target_partner | bal_prev | bal_final |       stripe_confirm        
----+-----------+------+-----------------+-------------------------------+--------+-----+--------+-------+--------------+-----+--------+------------+------------+--------------+-------------------------------+---------------+----------------+----------+-----------+-----------------------------
 19 |         1 |    1 | 104.238.127.115 | 2018-05-22 19:53:20.717772+00 |   7800 |   0 |      6 |       |              | 100 |        |          3 |          0 |              | 2018-05-22 19:53:22.100816+00 |             0 |              0 |        0 |         0 | ch_1CUgXtL48CvczxJJT6QkwFDT
(1 row)

         * 
         * 
         */
        $str='<table>';
        
            $mysql = "SELECT * FROM payment WHERE id  =".$payment_id;
            $query = $this->db->query($mysql);
            $data['pdata'] = $query->row_array();
         $str .="<tr><td><b>Amount Paid: </b></td><td>$".$data['pdata']["amount"]*0.01."</td></tr>";
            $str .="<tr><td><b>Date Paid: </b></td><td>".$data['pdata']["dt_confirmed"]."</td></tr>";
             $str .="<tr><td><b>Stripe Confirm: </b></td><td>".$data['pdata']["stripe_confirm"]."</td></tr>";
         $str .='</table>';
        return $str;
    }
    
    
    public function addnew() {
        $data = array();
        $data['firstname'] = $data['lastname'] = $data['transporter'] = '';
        $data['username'] = $data['phone'] = $data['street'] = '';
        $data['zipcode'] = $data['city'] = $data['state'] = '';

        if ($this->input->post()) {
            $data = $this->getCreateTrasporterPost();

            $data['action'] = MEDTRANS_TRANSP_CREATE;
            $out = array();
            $ret = $this->medtrans_api($data, $out);
        }

        $data['transports_list'] = $this->getRecentTransportersList(10);
        $this->renderAdminPage('transp/view_addnew_transporter', $data);
    }

    public function find() {
        $data = array();


        if ($this->input->post()) {
            $data = $this->input->post();
            //  print_r($data);
            $srcht = trim($data['searchtext']);
            $mysql = "SELECT t.*,a.username,a.agent_name FROM transporter t LEFT JOIN agents a ON a.id=t.agent_id ORDER BY a.id DESC LIMIT 20";
        } else {
            $data['searchtext'] = '';

            $mysql = " SELECT t.*,a.username,a.agent_name FROM transporter t LEFT JOIN agents a ON a.id=t.agent_id ORDER BY a.id DESC LIMIT 20";
        }
        $q = $this->db->query($mysql);
        $data['transporter_search'] = $q->result();





        $data['transports_list'] = $this->getRecentTransportersList(10);
        $this->renderAdminPage('transp/view_find_transporter', $data);
    }

    public function findbylinkid() {

        // get the user id 
        $transp_id = $this->input->get('transp_id');

        $mysql = "SELECT *,id AS transp_id  FROM transporters WHERE id=" . $transp_id;
        $q = $this->db->query($mysql);
        $out = $q->row();

        $_SESSION['selected_transporter_row'] = $out;
        redirect('transporter/profile');
    }

    private function getRecentTransportersList($plimit) {
        $mysql = "SELECT  * FROM transporters ORDER BY id DESC LIMIT $plimit";
        $q = $this->db->query($mysql);
        $recent_transporter_list = $q->result();
        return $recent_transporter_list;
    }

    private function getCreateTrasporterPost() {
        $out = array();

        $out['transporter'] = $this->input->post('transporter');
        $out['firstname'] = $this->input->post('firstname');
        $out['lastname'] = $this->input->post('lastname');

        $out['street'] = $this->input->post('street');
        $out['zipcode'] = $this->input->post('zipcode');

        $out['phone'] = $this->input->post('phone');
        $out['city'] = $this->input->post('city');
        $out['state'] = $this->input->post('state');

        $out['username'] = $this->input->post('username');
        $out['email'] = $out['username'];
        $out['password'] = $this->input->post('password');

        return $out;
    }

    public function pendingOLD() {

        $data = array();
        $data['do_not_script'] = 0;

        $this->load->model('admindash_model');

        $mysql = " SELECT r.*,r.service_date::time AS transport_time,DATE_PART('day', r.service_date - now() ) AS day_gap, r.id AS transport_request_id FROM members_service_request r "
                . " RIGHT JOIN transport_assignment a ON a.transport_id = r.id "
                . " WHERE a.status = 1 AND a.flags IN (0,1,2,3) ORDER BY r.id DESC ";

$mysql ="SELECT * FROM members_service_request";

        $this->load->library('pagination');
        $config = array();
        $query = $this->db->query($mysql);
        $config["total_rows"] = $query->num_rows();
        // $config["base_url"] = base_url() . "/dash/newpage";
        $config["base_url"] = base_url() . "/transp/pending";
        $config["per_page"] = 10;
        $config["uri_segment"] = 3;
        $config["num_links"] = 5;

        $config['full_tag_open'] = "<ul class='pagination'>";
        $config['full_tag_close'] = "</ul>";
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
        $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
        $config['next_tag_open'] = "<li>";
        $config['next_tagl_close'] = "</li>";
        $config['prev_tag_open'] = "<li>";
        $config['prev_tagl_close'] = "</li>";
        $config['first_tag_open'] = "<li>";
        $config['first_tagl_close'] = "</li>";
        $config['last_tag_open'] = "<li>";
        $config['last_tagl_close'] = "</li>";

        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $page = is_numeric($page) ? $page : 0;

        $mysql = " SELECT r.*,r.service_date::time AS transport_time,DATE_PART('day', r.service_date - now() ) AS day_gap, r.id AS transport_request_id FROM members_service_request r "
                . " RIGHT JOIN transport_assignment a ON a.transport_id = r.id "
                . " WHERE a.status = 1 AND r.transport=1 AND a.flags IN (0,1,2,3) ORDER BY r.id DESC  LIMIT " . $config["per_page"] . " OFFSET " . $page;
$mysql ="SELECT * FROM members_service_request";
        $data["pagination_links"] = $this->pagination->create_links();

        $q = $this->db->query($mysql);
        $data['transport_request'] = $q->result();

        $data['page_title'] = "Pending Transport";
        $this->renderAdminPage('transp/view_pending_trasport', $data);
    }

    
    public function newrequest2() {
        $data = $this->newrequestPageReal(array());
        $this->renderAdminPage('transp/view_pending_trasport', $data);
    }

    public function newrequestPage() {
        $data = $this->newrequestPageReal(array());
        $data['do_not_script'] = true;
        $this->load->view('admin/transp/view_pending_trasport_list', $data);
    }

    private function newrequestPageReal($data) {
        $data['do_not_script'] = false;
        $data['pageNumber'] = $this->input->get('pageNumber');
        if ($data['pageNumber'] == '' || $data['pageNumber'] < 1)
            $data['pageNumber'] = 1;

        $this->load->model('admindash_model');
        //   $out = $this->admindash_model->getAdminDashData($data);
        //   $data['recent_signup'] = $out['recent_signup'];

        $mysql = "SELECT DATE_PART('hour', service_date - now() ) AS day_gap, * FROM members_service_request";


        $mysql = " SELECT r.*,r.service_date::time AS transport_time,DATE_PART('day', r.service_date - now() ) AS day_gap, r.id AS transport_request_id FROM members_service_request r "
                . " LEFT JOIN transport_assignment a ON a.transport_id = r.id "
                . " WHERE r.status = 1 AND r.flags IN (0) ORDER BY r.id DESC";
$mysql ="SELECT * FROM members_service_request";
        $q = $this->db->query($mysql);
        $data['transport_request'] = $q->result();
        $data['result_per_page'] = 10;
        $data['result_total'] = count($data['transport_request']);
        $data['page_title'] = "New Transport Request(s)";

        $pages = ceil(1.0 * $data['result_total'] / $data['result_per_page']);
        if ($data['pageNumber'] > $pages)
            $data['pageNumber'] = 1;
        $offset = $data['result_per_page'] * ($data['pageNumber'] - 1);
        $data['transport_request'] = array_slice($data['transport_request'], $offset, $data['result_per_page']);
        return $data;
    }

    public function assignTranspoter() {
        $data['transport_id'] = $this->input->get('transport_id');
        $data['transporter_id'] = $this->input->get('transporter_id');
        $data['pid'] = 110;

        if ($data["transport_id"] != '' and $data["transport_id"] > 0 and $data["transporter_id"] != '' and $data["transporter_id"] > 0) {

            $data['action'] = MEDTRANS_TRANSP_ASSIGNTRANSPORT;
            $out = array();
            $ret = $this->medtrans_api($data, $out);
            echo $ret;
        } else {
            echo "Invalid transport id and/or transporter selected";
        }
    }

    function cancelTranspoter() {
        // url: "/transp/cancelTranspoter?transport_id=" + transport_id + "&cancel_reason=" + cancel_reasonv
        $data = array();
        $ret = -1;
        $data['transport_id'] = $this->input->get('transport_id');
        $data['reason'] = $this->input->get('cancel_reason');
        if ($data['transport_id'] > 0 and $data['reason'] != '') {
            $in["mode"] = MODE_CANCEL_ASSIGNMENT;
            $in["transport_id"] = $data['transport_id'];
            $in['reason'] = $data['reason'];
            $in['action'] = MEDTRANS_TRANSP_SET_TRANSSTATUS;
            $in['agent_id'] = 0; // not needed but send 0

            $out = array();
            $ret = $this->medtrans_api($in, $out);
        }

        echo $ret;
    }

  

    private function SelectTransporter($trasnport_id) {

        /*
         * THIS IS JUST AN EMULATOR FOR NOW - TRANSPORTERS WILL BE RECOMENDED BASED ON RULES AND PRECOMPUTATION USING MANY FACTORS LATTER
         */

        $out = array();
        $mysql = "SELECT id, loc_name||'-'||street||', '||city||', '||state||'-'||zipcode AS name FROM transporter ORDER BY random() LIMIT 3";
        $query = $this->db->query($mysql);

        $sel1 = "<select class=\"form-control\" id=\"sel1\" name=\"recomended_list\">";
        $sel1 .="<option value=\"0\">Select from recomended list</option>";
        foreach ($query->result() as $row) {
            $sel1 .="<option value=" . $row->id . ">" . $row->name . "</option>";
        }
        $sel1 .=" </select>";
        $out['recomended_list'] = $sel1;


        $mysql = "SELECT id, loc_name||'-'||street||', '||city||', '||state||'-'||zipcode AS name FROM transporter ORDER BY random() LIMIT 20";
        $query = $this->db->query($mysql);
        $sel2 = "<select class=\"form-control\" id=\"sel2\" name=\"search_list\" style=\"min-width:200px;\">";
        $sel2 .="<option value=\"0\">Search list to select</option>";
        foreach ($query->result() as $row) {
            $sel2 .="<option value=" . $row->id . ">" . $row->name . "</option>";
        }
        $sel2 .=" </select>";
        $out['search_list'] = $sel2;
        return $out;
    }

    private function constructTranspSelect($data) {

        $trnspPage = "
            <div class = \"panel-heading\">
            <h6 class = \"panel-title\"><b>Personal Information</b> This is the person to be transported</h6>
            </div>

            <div class = \"panel-heading\">
            <h6 class = \"panel-title\"><b>Created By</b> pay attention to the person that created it account</h6>
            </div>
            
            <div class = \"panel-heading\">
            <h6 class = \"panel-title\"><b>Destination :</b>" . $data['directionsEnd'] . "</h6>
             </div>

            <div class = \"panel-heading\">
            <h6 class = \"panel-title\"><b>Origin :</b> " . $data['directionsStart'] . "</h6>
            </div>

            <div class = \"panel-heading\">
            <h6 class = \"panel-title\"><b>Transporter</b></h6>
           </div>";
        return $trnspPage;
    }
    
    
    public function PrepPagination($perpage, $urlSegment) {

        $this->load->library('pagination');
        $config = array();
        $config["base_url"] = base_url() . "/transp/agents";
        $config["per_page"] = $perpage;
        $config["uri_segment"] = $urlSegment;
        $config["num_links"] = 5;
        $config['full_tag_open'] = "<ul class='pagination'>";
        $config['full_tag_close'] = "</ul>";
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
        $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
        $config['next_tag_open'] = "<li>";
        $config['next_tagl_close'] = "</li>";
        $config['prev_tag_open'] = "<li>";
        $config['prev_tagl_close'] = "</li>";
        $config['first_tag_open'] = "<li>";
        $config['first_tagl_close'] = "</li>";
        $config['last_tag_open'] = "<li>";
        $config['last_tagl_close'] = "</li>";
    }
    
 

    public function pending() {
        $this->showServiceRequestList('0,1', 'Pending Service Request', 'newrequest');
    }

    public function cancelled() {
        $this->showServiceRequestList(1,CANCELLED, 'Cancelled Service Request', 'cancelled');
    }

    public function completed() {
        $this->showServiceRequestList(1,COMPLETED, 'Completed Service Request', 'completed');
    }

    public function confirmed() {
    //    $this->showServiceRequestList(CONFIRMED, 'Confirmed Service Request', 'confirmed');
        $this->showServiceRequestList(1,CONFIRMED, 'Confirmed Lundry Drop Off', 'confirmed');
        
    }

    public function active() {
        $this->showServiceRequestList(1,INPROGRESS, 'Active Service Request', 'active');
    }

    public function active2() {

        $data = array();

        $this->load->model('admindash_model');
        //   $out = $this->admindash_model->getAdminDashData($data);
        //   $data['recent_signup'] = $out['recent_signup'];

        $mysql = "SELECT DATE_PART('hour', service_date - now() ) AS day_gap, * FROM members_service_request";


        $mysql = " SELECT r.*,r.service_date::time AS transport_time,DATE_PART('day', r.service_date - now() ) AS day_gap, r.id AS transport_request_id FROM members_service_request r "
                . " RIGHT JOIN transport_assignment a ON a.transport_id = r.id "
                . " WHERE a.status = 1 AND a.flags IN (4,5,6) ORDER BY r.id DESC ";


        $q = $this->db->query($mysql);
        $data['transport_request'] = $q->result();

        $data['page_title'] = "Active Transport(s)";

        $this->renderAdminPage('transp/view_active_trasport', $data);
    }



    public function agents() {


        $this->load->library('pagination');
        $config = array();
        $config["base_url"] = base_url() . "/transp/agents";
        $config["per_page"] = 10;
        $config["uri_segment"] = 3;
        $config["num_links"] = 5;
        $config['full_tag_open'] = "<ul class='pagination'>";
        $config['full_tag_close'] = "</ul>";
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
        $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
        $config['next_tag_open'] = "<li>";
        $config['next_tagl_close'] = "</li>";
        $config['prev_tag_open'] = "<li>";
        $config['prev_tagl_close'] = "</li>";
        $config['first_tag_open'] = "<li>";
        $config['first_tagl_close'] = "</li>";
        $config['last_tag_open'] = "<li>";
        $config['last_tagl_close'] = "</li>";

        $data = array();
        $selected_val = $this->input->post('searchparam');

        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $page = is_numeric($page) ? $page : 0;

        if ($this->input->post() and $selected_val != '') {
            $data = $this->input->post();
            //  print_r($data);
            $srcht = trim($data['searchtext']);
            $mysql = "SELECT * FROM agents WHERE LOWER(" . $selected_val . ") LIKE LOWER('$srcht%') limit 400";
            $mysql2 = "SELECT * FROM agents WHERE LOWER(" . $selected_val . ") LIKE LOWER('$srcht%') ORDER BY $selected_val DESC LIMIT " . $config["per_page"] . " OFFSET " . $page;   //ORDER BY id DESC limit 10";
        } else {
            $data['searchtext'] = '';

            $mysql = " SELECT * FROM agents";  // . $config["per_page"] . " OFFSET " . $page;   //ORDER BY id DESC limit 10";
            $mysql2 = " SELECT * FROM agents ORDER BY id DESC  LIMIT " . $config["per_page"] . " OFFSET " . $page;   //ORDER BY id DESC limit 10";
        }


        $data['page_title'] = "Agent Search";
        $data['search_combo'] = $this->agentSearchCombo('searchparam');

        // first run for count 
        $query = $this->db->query($mysql);
        $config["total_rows"] = $query->num_rows();
        $this->pagination->initialize($config);


        $q = $this->db->query($mysql2);
        $data['transporter_search'] = $q->result();
        $data['transports_list'] = $this->getRecentTransportersList(10);
        $data["pagination_links"] = $this->pagination->create_links();

        $this->renderAdminPage('agent/view_find_agent', $data);
    }

    private function agentSearchCombo($cmbName) {

        $selected_val = $this->input->post($cmbName);

        $agentSearchList = array(
            'agent_name' => 'Agent Name',
            'lastname' => 'Lastname',
            'firstname' => 'Firstname',
            'email' => 'Email',
            'phone' => 'Phone',
            'zipcode' => 'Zip Code'
        );

        $str_Combo = " <select class=\"form-control\" name ='" . $cmbName . "'>";
        foreach ($agentSearchList as $key => $value) {
            $selV = '';
            if ($selected_val == $key) {
                $selV = ' selected';
            }

            $str_Combo .="<option  value='" . $key . "' " . $selV . ">" . $value . "</option>";
            //echo "Key: $key, Value: $value\n";
        }
        $str_Combo .="</select>";
        return $str_Combo;
    }

    // this is the selected agent
    public function selagent() {
        $data['agent_id'] = $this->input->get('agent_id');

        if ($data["agent_id"] != '' and $data["agent_id"] > 0) {

            $mysql = "SELECT * FROM agents WHERE id  = " . $data['agent_id'];
            $query = $this->db->query($mysql);
            $data['selected_agent'] = $query->row_array();

            $this->load->library('table');
            $this->table->set_template($this->template);

            $mysql = "SELECT loc_name,street,zipcode FROM transporter WHERE agent_id = " . $data['agent_id'];
            $query = $this->db->query($mysql);
            $this->table->set_heading(array('data' => 'Location Name', 'style' => 'width:220px'), 'Email', array('data' => 'Zipcode', 'style' => 'width:100px'));
            $data['transporter_table'] = $this->table->generate($query);


            $mysql = "SELECT firstname,lastname,email,key,pin FROM interpreters WHERE agent_id = " . $data['agent_id'];
            $query = $this->db->query($mysql);
            $this->table->set_heading(array('data' => 'Firstname', 'style' => 'width:150px'), array('data' => 'Lastname', 'style' => 'width:150px'), 'Email', array('data' => 'Key', 'style' => 'width:50px'), array('data' => 'Pin', 'style' => 'width:10px'));
            $data['interpreter_table'] = $this->table->generate($query);

            $mysql = "SELECT firstname,lastname,email,phone,key,pin FROM transport_drivers WHERE agent_id=" . $data['agent_id'];
            $query = $this->db->query($mysql);
            $this->table->set_heading(array('data' => 'FirstName', 'style' => 'width:60px'), array('data' => 'LastName', 'style' => 'width:60px'), array('data' => 'Email', 'style' => 'width:100px'), 'Phone', array('data' => 'Key', 'style' => 'width:50px'), array('data' => 'Pin', 'style' => 'width:10px'));
            $data['driver_table'] = $this->table->generate($query);

            


            $this->load->view('/admin/agent/extra/agent_form', $data);
        }
        // echo 'A transport line was selected';
    }

    public function manage() {


        $data = array();
        $data['agent_id'] = $this->input->get('agent_id');
        if ($data["agent_id"] != '' and $data["agent_id"] > 0) {


            $mysql = "SELECT * FROM agents WHERE id  = " . $data['agent_id'];
            $query = $this->db->query($mysql);
            $data['selected_agent'] = $query->row_array();

            $this->load->library('table');
            $this->table->set_template($this->template);

            $mysql = "SELECT loc_name,street,zipcode,'<button type=\"button\" class=\"btn btn-warning btn-xs\" onclick=\"viewAgentLocation('||id||','||agent_id||');\" >Edit</button>' AS action FROM transporter WHERE agent_id = " . $data['agent_id'];
            $query = $this->db->query($mysql);
            $this->table->set_heading(array('data' => 'Location Name', 'style' => 'width:220px'), 'Email', array('data' => 'Zipcode', 'style' => 'width:100px'), array('data' => 'Action', 'style' => 'width:70px'));
            $data['transporter_table'] = $this->table->generate($query);


            $mysql = "SELECT firstname,lastname,email,'<button type=\"button\" class=\"btn btn-warning btn-xs\" onclick=\"viewTranslatorData('||id||','||agent_id||');\">View</button>' AS action FROM interpreters WHERE agent_id = " . $data['agent_id'];
            $query = $this->db->query($mysql);
            $this->table->set_heading(
                    array('data' => 'Firstname', 'style' => 'width:150px'), array('data' => 'Lastname', 'style' => 'width:150px'), 'Email', array('data' => 'Action', 'style' => 'width:70px'));
            $data['interpreter_table'] = $this->table->generate($query);
            // $this->load->view('/admin/agent/extra/agent_form', $data);

            $mysql = "SELECT *, id AS driver_id FROM transport_drivers WHERE agent_id = " . $data['agent_id'];
            $query = $this->db->query($mysql);
            $data['result_list'] = $query->result_array();

            $this->renderAdminPage('agent/view_agent_manage', $data);
        }
    }

    public function translators() {
        $data['agent_id'] = $this->input->post('agent_id');
        if ($data['agent_id'] > 0) {
            $this->load->library('table');
            $this->table->set_template($this->template);

            $mysql = "SELECT firstname,lastname,email,'<button type=\"button\" class=\"btn btn-warning btn-xs\" onclick=\"viewTranslatorData('||id||','||agent_id||');\">View</button>' AS action FROM interpreters WHERE agent_id = " . $data['agent_id'];
            $query = $this->db->query($mysql);
            $this->table->set_heading(
                    array('data' => 'Firstname', 'style' => 'width:150px'), array('data' => 'Lastname', 'style' => 'width:150px'), 'Email', array('data' => 'Action', 'style' => 'width:70px'));
            $data['interpreter_table'] = $this->table->generate($query);

            $this->load->view('admin/agent/extra/view_translators_list', $data);
        }
    }

    public function addtranslator() {
        $data = array();
        if ($this->input->post()) {
            $data = $this->input->post();
            $in = $data; // Do we validate?
            $in['action'] = MEDTRANS_TRANSP_ADD_TRANSLATOR;
            $out = array();
            $ret = $this->medtrans_api($in, $out);
            $data["message"] = isset($out["status"]) ? $out["status"] : "Translator added";
            if ($data["message"] == 1)
                $data["message"] = "Translator added";
            echo $data["message"];
        } else {
            $data = $this->input->get();
            $this->load->view('admin/agent/extra/view_translators_form', $data);
        }
    }

    public function locations() {
        $data['agent_id'] = $this->input->post('agent_id');
        if ($data['agent_id'] > 0) {
            $this->load->library('table');
            $this->table->set_template($this->template);

            $mysql = "SELECT loc_name,street,zipcode,'<button type=\"button\" class=\"btn btn-warning btn-xs\" onclick=\"viewAgentLocation('||id||','||agent_id||');\" >Edit</button>' AS action FROM transporter WHERE agent_id = " . $data['agent_id'];
            $query = $this->db->query($mysql);
            $this->table->set_heading(array('data' => 'Location Name', 'style' => 'width:220px'), 'Email', array('data' => 'Zipcode', 'style' => 'width:100px'), array('data' => 'Action', 'style' => 'width:70px'));
            $data['transporter_table'] = $this->table->generate($query);
            $this->load->view('admin/agent/extra/locations_list', $data);
        }
    }

    public function vseltransport() {
        $data = $this->input->get();
        if ($data['selection_id'] > 0) {
            $in['agent_id'] = $data['agent_id'];
            $in['transporter_id'] = $data['selection_id'];
            $in['action'] = MEDTRANS_TRANSP_GET_TRANSPORTER;
            $out = array();
            $ret = $this->medtrans_api($in, $out);
            $data = array_merge($data, $out);
        } else {
            $data['loc_name'] = '';
            $data['phone'] = '';
            $data['street'] = '';
            $data['city'] = '';
            $data['state'] = 'GA';
            $data['zipcode'] = '';
            $data['transporter_id'] = 0;
            $data['id'] = 0;
        }
        $this->load->model('combo_model');
        $this->combo_model->defaultComboMessage = 'Select your State';
        $data['states_combo'] = $this->combo_model->getStatesCombo('state', $data['state']);
        $this->load->view('admin/agent/extra/locations_form', $data);
    }

    public function add_edit_location() {
        $data = $this->input->post();
        $in = $data; // Do we validate?
        if ($data['transporter_id'] > 0) {
            $action = MEDTRANS_TRANSP_EDITLOCATION;
        } else {
            $action = MEDTRANS_TRANSP_ADDLOCATION;
        }
        $in["action"] = $action;
        $out = array();
        $ret = $this->medtrans_api($in, $out);
        $data["message"] = isset($out["status"]) ? $out["status"] : ($data['transporter_id'] > 0 ? "Location updated" : "Location added");
        if ($data["message"] == 1)
            $data["message"] = "Location added";
        echo $data["message"];
    }

    public function vseltranslator() {
        $data = array();
        $proc = $this->input->get('proc');
        $data['translator_id'] = $this->input->get('selection_id');
        if ($data['translator_id'] > 0) {
            $in['agent_id'] = $this->input->get('agent_id');
            $in['interpreter_id'] = $data['translator_id'];
            if ($proc == 'STATUS') {
                $in['language_id'] = $this->input->get('language_id');
                $in['lang_code'] = $this->input->get('lang_code');
                $in['mode'] = $this->input->get('status') == 'Disable' ? MODE_DELETE : MODE_ADD;
                $in['action'] = MEDTRANS_TRANSP_MANAGELANGUAGE;
                $out = array();
                $ret = $this->medtrans_api($in, $out);
                if ($ret != 0) {
                    var_dump($out);
                    echo "\\r";
                }
                echo $ret;
            } else if ($proc == 'FLAGS') {
                $in['language_id'] = $this->input->get('language_id');
                $in['lang_code'] = $this->input->get('lang_code');
                $in['flags'] = (int) $this->input->get('flags');
                $in['mode'] = MODE_UPDATE;
                $in['action'] = MEDTRANS_TRANSP_MANAGELANGUAGE;
                $out = array();
                $ret = $this->medtrans_api($in, $out);
                if ($ret != 0) {
                    var_dump($out);
                    echo "\\r";
                }
                echo $ret;
            } else {

                $in['language_id'] = 0; // LIST ALL

                $in['action'] = MEDTRANS_TRANSP_GET_TRANSLATOR;
                $translator_data = array();
                $ret = $this->medtrans_api($in, $translator_data);
                $in['action'] = MEDTRANS_USER_GET_LANGUAGE;
                $in['limit'] = 1000;
                $in['status'] = 0;
                $language_list = array();
                $ret = $this->medtrans_api($in, $language_list); // may load into global for speed latter
                $in['action'] = MEDTRANS_TRANSP_LANGUAGELIST;
                $my_language = array();
                $ret = $this->medtrans_api($in, $my_language); // may load into global for speed latter

                $this->renderlanguageConfig($translator_data, $language_list, $my_language);
            }
        } else {
            echo "{\"status\":\"-2\"}";
        }
    }

    protected function renderlanguageConfig($translator_data, $language_list, $my_language) {
        // echo json_encode($translator_data);
        $language_array = array();
        $total_record = $language_list["total_record"];
        for ($i = 0; $i < $total_record; $i++) {
            $idx = sprintf("%05d", $i);
            $language_array[] = array(
                "code" => $language_list["code_" . $idx],
                "language" => $language_list["language_" . $idx],
                "status" => $language_list["status_" . $idx]
            );
        }

        echo "
<form method=\"post\" id=\"add_language\" action=\"/transp/addlanguage\">
<input type=\"hidden\" name=\"agent_id\" value=\"" . $translator_data['agent_id'] . "\">
<input type=\"hidden\" name=\"mode\" value=\"add_language\">
<input type=\"hidden\" name=\"translator_id\" value=\"" . $translator_data['id'] . "\">
Configure languages for :
<table class=\"table table-striped\">
        <tr>
        <td><b>" . $translator_data['firstname'] . " " . $translator_data['lastname'] . "</b>-[PH: " . $translator_data['phone'] . "]
            " . $translator_data['street'] . "  " . $translator_data['city'] . "  " . $translator_data['state'] . "  " . $translator_data['zipcode'] . "  " . $translator_data['country'] . "
        </td>
        </tr>
        <td>
            <div class=\"row\">
                <div class=\"col-xs-2\">
                   Languages
                </div>
                <div class=\"col-xs-8\">
                " . $this->makeCombo($language_array, "language", "code", "lang_code") . "
                </div>
                <div class=\"col-xs-2\">
                <button class=\"btn btn-info btn-block btn-xs\"style=\"float: right\" onclick=\"return addlanguage('" . $translator_data['id'] . "','" . $translator_data['agent_id'] . "',this.form.lang_code.value,this);\">Add</button>
                </div>
            </div>
                <hr size='1'>
        </td>
        </tr>
        </table></form>" . $this->translatorLanguageList($my_language);



        // echo json_encode($language_list);
    }

    private function makeCombo($dataArray, $text1, $code1, $name = "") {
        $sl = "<select " . ($name != "" ? "name=\"${name}\"" : "") . " class='form-control'>";
        foreach ($dataArray as $drow) {
            $sl .= "<option value='" . $drow[$code1] . "'>" . $drow[$text1] . "</option>";
        }
        $sl .= "</select>";

        return $sl;
    }

    /*
     * translatorLanguageList
     * THIS FUNCTION LIST THE LANGUAGES THAT A TRANSLATOR HAVE CLAIMED TO UNDERSTAND
     * THERE IS NEED TO UPLOAD CETIFICATIONS FOR LEGEAL PURPOSE
     */

    private function translatorLanguageList($my_language) {

        $result_list = array();

        $total_record = $my_language["total_record"];
        for ($i = 0; $i < $total_record; $i++) {
            $idx = sprintf("%05d", $i);
            $result_list[] = array(
                "agent_id" => $my_language["agent_id_" . $idx],
                "document" => $my_language["document_" . $idx],
                "document_id" => $my_language["document_id_" . $idx],
                "flags" => $my_language["flags_" . $idx],
                "interpreter_id" => $my_language["interpreter_id_" . $idx],
                "lang_code" => $my_language["lang_code_" . $idx],
                "language" => $my_language["language_" . $idx],
                "language_id" => $my_language["language_id_" . $idx],
                "status" => $my_language["status_" . $idx],
                "weekend" => $my_language["weekend_" . $idx]
            );
        }


        $tb1 = "<table class='table'><tr><th>Language</th><th>Document</th><th>Approved</th><th>Disable</th></tr>";

        foreach ($result_list as $rect) {

            if ($rect['document_id'] == 0) {
                $flup = "<form method=\"post\" action=\"/transp/upload\" onsubmit=\"return uploadFile(this);\">
                <input type=\"hidden\" name=\"agent_id\" value=\"" . $rect["agent_id"] . "\">
                <input type=\"hidden\" name=\"language_id\" value=\"" . $rect["language_id"] . "\">
                <input type=\"hidden\" name=\"interpreter_id\" value=\"" . $rect["interpreter_id"] . "\">
                <div class=\"row\" style=\"float: right\">
                <label class=\"custom-file\">
                <input type=\"file\" name=\"file_contents\"  id=\"file_contents\" class=\"custom-file-input\" required>
                <span class=\"custom-file-control\"></span>
                </label>  <input type=\"submit\" value=\"Upload File\" class=\"btn btn-info btn-xs\" name=\"submit\">
                </form></row>";
            } else {
                $flup = "<a href='/transp/download?document_id=" . $rect['document_id'] . "&agent_id=" . $rect["agent_id"] . "&interpreter_id=" . $rect["interpreter_id"] . "&language_id=" . $rect["language_id"] . "&ts=" . time() . "'>" . $rect['document'] . "</a> | <a class=\"text-danger\" href=\"#\"><b>Del.</b></a>";
            }

            $tb1 .= "<tr><td style='width:180px;'>" . $rect['language'] . "</td>"
                    . "<td>" . $flup . "</td>"
                    . "<td style='width:45px;'><input class=\"form-control\" type=\"checkbox\" value=\"1\" onchange=\"return manageLanguageFlags(this, '" . $rect["interpreter_id"] . "','" . $rect["language_id"] . "','" . $rect["lang_code"] . "'," . $rect["agent_id"] . ")\"" . ($rect['flags'] == 1 ? " checked" : "") . "></td>";
            if ($rect['status'] == 0) {
                $tb1 .= "<td style='width:85px;'><button class=\"btn btn-primary btn-xs\" style=\"float: right\" onclick=\"return manageLanguageStatus(this,'" . $rect["interpreter_id"] . "','" . $rect["language_id"] . "','" . $rect["lang_code"] . "'," . $rect["agent_id"] . ");\">Enable</button></td></tr>";
            } else {
                $tb1 .= "<td style='width:85px;'><button class=\"btn btn-danger btn-xs\" style=\"float: right\" onclick=\"return manageLanguageStatus(this,'" . $rect["interpreter_id"] . "','" . $rect["language_id"] . "','" . $rect["lang_code"] . "'," . $rect["agent_id"] . ");\">Disable</button></td></tr>";
            }
        }

        // END TO BE REMOVED
        // END TO BE REMOVED

        $tb1 .= "</table>";
        return $tb1;
    }

    public function upload() {
        if ($this->input->post()) {
            $data = $this->input->post();
            echo $this->file_upload($data);
        } else {
            echo "{'error':'Invalid request'}";
        }
    }

    private function file_upload($data) {
        $in["agent_id"] = $data["agent_id"];
        $in["interpreter_id"] = $data["interpreter_id"];
        $in["language_id"] = $data["language_id"];
        $in["file_type"] = INTERPRETER_CERTIFICATE;

        $out = array();
        $x = array();
        //$ext = $_FILES["file_contents"]["type"];
        $ext = pathinfo($_FILES["file_contents"]['name'], PATHINFO_EXTENSION);
        $in['extension'] = $ext;
        if ($in['agent_id'] != '' and $in['agent_id'] > 0) {

            $storage_path = "/upload/"; //Must be in the config file
            $in["part"] = "AGT";
            $storage_path .= $in["part"] . "/"; // ALL AGENT FILES APART
            // you can be only be agent on this path creating documnent storage
            // 1. we need your local drive folder
            $in['action'] = 400006; //MEDTRANS_LOAD_AGENT;
            $in["pid"] = 115;
            $ret = $this->medtrans_api($in, $x);
            $user_folder = $x["folder"] . "/" . $in['file_type'] . "/";
            $in["folder"] = $x["folder"];
            $uploaddir = realpath('./') . $storage_path . $user_folder . $ext . '/';

            if (!is_dir($uploaddir))
                mkdir($uploaddir, 0777, true);
            do {
                $uploadname = strtoupper(uniqid("")) . '.' . $ext;
                $uploadfile = $uploaddir . $uploadname;
            } while (file_exists($uploadfile));
            if (!move_uploaded_file($_FILES["file_contents"]["tmp_name"], $uploadfile)) {
                return "{'error':'Failed to upload file'}";
            }
            unset($_FILES['file_contents']);
            unset($data['data']);


            $in["upload_file_path"] = $uploadfile;
            $in["upload_file_name"] = $uploadname;
            $in["file_name"] = $uploadname; // need this in back end
            $in['action'] = MEDTRANS_UPLOADS;
            // file_type is in the array already

            $ret = $this->medtrans_api($in, $out);
            return $ret == 0 ? "{'success':'File uploaded'}" : "{'error':'Failed to upload'}";
        }
        return "{'error':'Invalid agent ID'}";
    }

    public function download() {
        $data = $this->input->get();
        $in['agent_id'] = $data['agent_id'];
        $in['interpreter_id'] = $data['interpreter_id'];
        $in['language_id'] = $data['language_id'];
        $in['document_id'] = $data['document_id'];
        $in["file_type"] = INTERPRETER_CERTIFICATE;
        $in['action'] = MEDTRANS_DOWNLOAD;
        $out = array();
        $ret = $this->medtrans_api($in, $out);
// array(10) { ["added"]=> string(25) "2017-10-19 17:12:50.15149" ["extension"]=> string(3) "jpg" ["file_name"]=> string(17) "59E8DD12244EA.jpg" ["file_type"]=> string(5) "20005" ["folder"]=> string(10) "7W425W24W5" ["id"]=> string(2) "12" ["loc"]=> string(15) "104.238.127.115" ["part"]=> string(3) "AGT" ["pid"]=> string(3) "115" ["status"]=> string(1) "1" }
        if ($ret == 0 && isset($out["status"]) && $out["status"] == 1) {
            $file_path = "./upload/" . $out["part"] . "/" . $out["folder"] . "/" . $out["file_type"] . "/" . $out["extension"] . "/" . $out["file_name"];
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="' . $out["file_name"] . '"');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file_path));
            readfile($file_path);
            exit();
        } else {
            header('HTTP/1.1 400 Bad Request');
            header('Status: 400 Bad Request');
            echo "{\"status\":\"Cannot download file\"}";
        }
    }

    public function addlanguage() {
        $data["translator_id"] = $this->input->get('translator_id');
        $data["lang_code"] = $this->input->get('lang_code');
        $data["agent_id"] = $this->input->get('agent_id');
        $ret = $this->add_language($data);
        echo $ret == "Language added" ? "0" : $ret;
    }

    private function add_language($data) {
        $in = array();
        $in["mode"] = 100; // => MODE_ADD
        $in["interpreter_id"] = $data["translator_id"];
        $in["lang_code"] = $data["lang_code"];
        $in["agent_id"] = $data["agent_id"];
        $in["action"] = MEDTRANS_TRANSP_MANAGELANGUAGE;
        $out = array();
        $ret = $this->medtrans_api($in, $out);
        return $ret == 0 ? "Language added" : "Failed to add language";
    }

    public function vseldriver() {
        //   echo 'Driver';
        $data = $this->input->get();
        $data["driver_id"] = $data["selection_id"];
        if ($data["driver_id"] > 0) {
            $mysql = "SELECT * FROM transport_drivers WHERE agent_id = '" . $data['agent_id'] . "' AND id='" . $data["driver_id"] . "'";
            $query = $this->db->query($mysql);
            $result = $query->result_array();
            $data = array_merge($data, $result[0]);
        } else {
            $data['email'] = '';
            $data['lic_number'] = '';
            $data['lic_state'] = 'GA';
            $data['expr_month'] = '1';
            $data['expr_year'] = date("Y") + 20;
            $data['firstname'] = '';
            $data['lastname'] = '';
            $data['street'] = '';
            $data['city'] = '';
            $data['state'] = 'GA';
            $data['zipcode'] = '';
            $data['phone'] = '';
        }
        $this->load->model('combo_model');
        $this->combo_model->defaultComboMessage = 'Select your State';
        $data['states_combo'] = $this->combo_model->getStatesCombo('state', $data['state']);
        $this->combo_model->defaultComboMessage = 'Select your Licence State';
        $data['lic_states_combo'] = $this->combo_model->getStatesCombo('lic_state', $data['lic_state']);
        $this->load->view('admin/agent/extra/view_driver_form', $data);
    }

    public function drivers() {
        $data = $this->input->post();
        if ($data['proc'] == 'ADD') {
            $in = $data; // Do we validate?
            $in['mode'] = MODE_ADD;
            $in["action"] = MEDTRANS_TRANSP_DRIVERSCALL;
            $out = array();
            $ret = $this->medtrans_api($in, $out);
            $status = isset($out["status"]) ? $out["status"] : "Unknown error";
            if ($status == 1)
                $message = "{\"success\":\"Driver added\"}";
            else
                $message = "{\"error\":\"${status}\"}";
            echo $message;
        } else if ($data['proc'] == 'EDIT') {
            $in = $data; // Do we validate?
            $in['mode'] = MODE_UPDATE;
            $in["action"] = MEDTRANS_TRANSP_DRIVERSCALL;
            $out = array();
            $ret = $this->medtrans_api($in, $out);
            if (isset($out["id"]) && $out["id"] > 0)
                $message = "{\"success\":\"Driver updated\"}";
            else
                $message = "{\"error\":\"\Failed yo update driver\"}";
            echo $message;
        } else if ($data['proc'] == 'LOAD') {
            $mysql = "SELECT *, id AS driver_id FROM transport_drivers WHERE agent_id = '" . $data['agent_id'] . "'";
            $query = $this->db->query($mysql);
            $data['result_list'] = $query->result_array();
            $this->load->view('admin/agent/extra/view_driver_list', $data);
        } else {
            echo "{\"error\":\"Invalid action\"}";
        }
    }

    public function drivers_load() {
        $data['driver_id'] = $this->input->get('driver_id');
        $data['agent_id'] = $this->input->get('agent_id');

        if ($data['driver_id'] > 0) {
            $in['agent_id'] = $_SESSION['agent_id'];
            $in['driver_id'] = $data['driver_id'];
            $in['mode'] = MODE_LIST;
            $in['action'] = MEDTRANS_TRANSP_DRIVERSCALL;
            $out = array();
            $ret = $this->medtrans_api($in, $out);
            echo json_encode($out);
        } else {
            echo "{\"status\":\"-2\"}";
        }
    }

    public function maps() {
        $data = array();


        $this->load->library('googlemaps');

        // $config['center'] = '37.4419, -122.1419';
        $config['center'] = 'atlnta,GA,USA';
        $config['zoom'] = 'auto';
        $config['directions'] = TRUE;
        $config['map_height'] = '100%';
        $config['directionsStart'] = '4201 defoors farm trail, powder springs, GA 30127, USA';
        $config['directionsEnd'] = '2324 stancrest ln, lawrenceville, 30044, GA, USA';
        $config['directionsDivID'] = 'directionsDiv';
        $this->googlemaps->initialize($config);
        $data['map'] = $this->googlemaps->create_map();


        $this->renderAdminPage('view_maps', $data);
    }

    public function transp_modal() {
        // $data = $this->getSessionArray();
        $data['transport_request_id'] = trim($this->input->get('transport_request_id'));

        $mysql = " SELECT * FROM members_service_request WHERE id=" . $data['transport_request_id']; //'$contract_id' ";
        $query = $this->db->query($mysql);
        $num = $query->num_rows();
        if ($num > 0) {
            $data['transport_data'] = $query->row_array();

            $out = $this->makeGoogleAddress($data['transport_data']);
            $this->load->library('googlemaps');
            $config['center'] = 'atlanta,GA,USA';
            $config['zoom'] = 'auto';
            $config['directions'] = TRUE;
            $config['directionsStart'] = $out['directionsStart']; //'4201 defoors farm trail, powder springs, GA 30127, USA';
            $config['directionsEnd'] = $out['directionsEnd']; //'2324 stancrest ln, lawrenceville, 30044, GA, USA';
            $config['directionsDivID'] = 'directionsDiv';
            $this->googlemaps->initialize($config);
            $data['map'] = $this->googlemaps->create_map();

            $data['directionsStart'] = $out['directionsStart'];
            $data['directionsEnd'] = $out['directionsEnd'];
            // $lat_long = get_lat_long_from_address($config['center']);
            // $data['latCenter'] = $lat_long[0];
            // $data['longCenter'] = $lat_long[1];
            // $data['transport_request_id'] = $transport_request_id;
            $this->load->view('admin/modals/view_transp_modal', $data);
        }
    }

    /*
     * Array ( [id] => 1 [pid] => 115 [member_id] => 3744 [loc_type] => [firstname] => Adewumi [lastname] => Muyiwa [service_date] => 2017-10-01 08:30:30 [from_phone] => 7702222380 [from_street] => Lake City Nursing And Rehab [from_aptno] => [from_city] => Lake City [from_zipcode] => 30260 [from_state] => GA [to_street] => 2324 stancrest ln [to_aptno] => [to_city] => lawrenceville [to_zipcode] => 30044 [to_state] => GA [country] => US [added] => 2017-08-23 21:47:07.505538 [status] => 1 [loc] => 38.101.241.200 )
     */
}
