Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2016
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 36.34 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Api extends CI_Controller {
  4.     function __construct(){
  5.         parent::__construct();
  6.  
  7.         date_default_timezone_set('Asia/Jakarta');
  8.         error_reporting(E_ALL);
  9.         ini_set('display_errors', 1);
  10.        
  11.     }
  12.     private function check_sesi(){
  13.         $token = $this->input->post('f_token');
  14.         $device = $this->input->post('f_device');
  15.  
  16.         //$token = 'a6bccee9979eef5c66532b5a36880d39';
  17.         //$device = 'ffffffff-be46-4574-ffff-ffffbdceeae1';
  18.        
  19.         if($token || $device){
  20.             $sql = "SELECT * FROM sesi WHERE
  21.                 sesi_key = ? AND sesi_device = ?
  22.                 AND sesi_status = ?";
  23.             // $this->db->where('sesi_key', $token);
  24.             // $this->db->where('sesi_status', 1);
  25.             // $this->db->where('sesi_device', $device);
  26.             $query = $this->db->query($sql, array($token, $device, 1));
  27.             if($query->num_rows() > 0){
  28.                 return true;
  29.             }else{
  30.                 return false;
  31.             }
  32.         }else{
  33.             return false;
  34.         }
  35.  
  36.        
  37.        
  38.     }
  39.  
  40.     public function daftar($isDriver = ''){
  41.         $data = array();
  42.         $nama = $this->input->post('nama');
  43.         $email = $this->input->post('email');
  44.         $password = $this->input->post('password');
  45.         $hp = $this->input->post('phone');
  46.        
  47.         //check email in di database
  48.         $this->db->where('user_email', $email);
  49.         $this->db->where_not_in('user_status', array(9));
  50.         $q = $this->db->get('user');
  51.  
  52.         if($q->num_rows() > 0) {
  53.             $data['result'] = 'false';
  54.             $data['msg'] = 'Email anda sudah terdaftar, silahkan untuk login.';
  55.         }else{     
  56.             $simpan = array();
  57.            
  58.             if($isDriver != ''){
  59.                 $level = 2;
  60.             }else{
  61.                 $level = 3;
  62.             }
  63.             $simpan['user_level'] = $level;
  64.             $simpan['user_password'] = md5x($password);
  65.             $simpan['user_nama'] = $nama;
  66.             $simpan['user_email'] = $email;
  67.             $simpan['user_register'] = date('Y-m-d H:i:s');
  68.             $simpan['user_hp'] = $hp;
  69.  
  70.             $status = $this->db->insert('user',$simpan);
  71.            
  72.             if($status){               
  73.                 $data['result'] = 'true';
  74.                 $data['msg'] = 'Pendaftaran berhasil, silahkan untuk login';
  75.  
  76.  
  77.                
  78.             }else{
  79.                 $data['result'] = 'false';
  80.                 $data['msg'] = 'Pendafatran gagal, silahkan coba kembali';
  81.             }
  82.  
  83.         }
  84.        
  85.         #pre($this->db->last_query());
  86.         echo json_encode($data);
  87.     }
  88.     public function send_notification($penerima, $message) {
  89.             $api_key = "AIzaSyCu0dAbLJlIHrL-LnGhsSYDdAOl27_1hjA";
  90.            
  91.             $url = 'https://android.googleapis.com/gcm/send';
  92.             $fields = array(
  93.                         'registration_ids'  => $penerima,
  94.                         'data'              => array( "message" => $message ),
  95.                         );
  96.  
  97.             $headers = array(
  98.                             'Authorization: key=' . $api_key,
  99.                             'Content-Type: application/json');                     
  100.                            
  101.                            
  102.             $ch = curl_init();
  103.             curl_setopt($ch, CURLOPT_URL, $url);
  104.             curl_setopt( $ch, CURLOPT_POST, true );
  105.             curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
  106.             curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  107.             curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
  108.             $result = curl_exec($ch);
  109.             curl_close($ch);
  110.            
  111.             return $result;
  112.     }
  113.  
  114.     public function login(){
  115.         $data = array();
  116.         $device = $this->input->post('device');
  117.         $email =  $this->input->post("t_email");
  118.         $password =  $this->input->post("t_password");
  119.  
  120.         //$email = 'riyadi.rb@gmail.com';
  121.         //$password = '123456';
  122.        
  123.         if($email == '' || $password == ''){
  124.             $data['result'] = 'false';
  125.             $data['msg'] = 'Silahkan isi email dan atau password anda.';
  126.             echo json_encode($data);
  127.             return;
  128.            
  129.         }
  130.        
  131.         $this->db->where('user_email', $email);
  132.         $this->db->where('user_password', md5x($password));
  133.         $this->db->where('user_status', 1);
  134.         $this->db->where('user_level', 3);
  135.         $query = $this->db->get('user');
  136.         if($query->num_rows() > 0){
  137.             $q = $query->row();
  138.  
  139.             //delete semua sesi user ini sebelumnya
  140.             $this->db->where('id_user' , $q->id_user);
  141.             $this->db->update('sesi', array('sesi_status' => 9));                  
  142.             //create token
  143.             $key = md5(date('Y-m-d H:i:s').$device);
  144.             //masukkan kedlam tabel sesi
  145.             $simpan = array();
  146.             $simpan['sesi_key'] =  $key;
  147.             $simpan['id_user'] = $q->id_user;
  148.             $simpan['sesi_device'] = $device;
  149.             $status = $this->db->insert('sesi', $simpan);
  150.             if($status){
  151.                 $data['result'] = 'true';
  152.                 $data['token'] =  $key;
  153.                 $data['data'] = $q;
  154.                 $data['msg'] = 'Login berhasil.';
  155.                 $data['idUser'] = $q->id_user;
  156.             }else{
  157.                 $data['result'] = 'false';
  158.                 $data['token'] = '';
  159.                 $data['idUser'] = '';
  160.                 $data['msg'] = 'Error create sesi login, Silahkan coba lagi.';
  161.             }
  162.         }else{         
  163.             $data['result'] = 'false';
  164.             $data['msg'] = 'Username atau password salah.';
  165.            
  166.         }      
  167.         echo json_encode($data);
  168.     }
  169.  
  170. //  private function check_sesi(){
  171. //      $token = $this->input->post('f_token');
  172. //      $device = $this->input->post('f_device');
  173.  
  174. //      //$token = 'a6bccee9979eef5c66532b5a36880d39';
  175. //      //$device = 'ffffffff-be46-4574-ffff-ffffbdceeae1';
  176.        
  177. //      if($token || $device){
  178. //          $sql = "SELECT * FROM sesi WHERE
  179. //              sesi_key = ? AND sesi_device = ?
  180. //              AND sesi_status = ?";
  181. //          // $this->db->where('sesi_key', $token);
  182. //          // $this->db->where('sesi_status', 1);
  183. //          // $this->db->where('sesi_device', $device);
  184. //          $query = $this->db->query($sql, array($token, $device, 1));
  185. //          if($query->num_rows() > 0){
  186. //              return true;
  187. //          }else{
  188. //              return false;
  189. //          }
  190. //      }else{
  191. //          return false;
  192. //      }
  193.  
  194.        
  195.        
  196. //  }
  197. //  public function getDataUser(){
  198. //      $data = array();
  199. //      $sikil = "SELECT * FROM user WHERE user_nama = '" . $_GET['nama']."'";// . " AND user_email = " . $_GET['email'];
  200. //      $query = $this->db->query($sikil);
  201.  
  202. //      // $nama = $this->input->get('nama');
  203. //      // $email = $this->input->get('email');
  204.  
  205. //      // $this->db->where('user_nama',$nama);
  206. //      // $this->db->where('user_email',$email);
  207. //      // $q = $this->db->get('user');
  208. //      // $query->result_array();
  209. // foreach($query->result() as $row){
  210. //              $data[$row->id_user] = $row->user_nama;
  211. //          }
  212.            
  213. //          print_r($data);     //$q = $query();
  214. //      /*$data['nama'] = $query['user_nama'];
  215. //      $data['email'] = $query['user_email'];
  216. //      $data['nomor hp'] = $query['user_hp'];
  217. //      $data['avatar'] = $query['user_avatar'];*/
  218.  
  219.  
  220. //  }
  221.  
  222. //  public function daftar($isDriver = ''){
  223. //      $data = array();
  224. //      $nama = $this->input->post('nama');
  225. //      $email = $this->input->post('email');
  226. //      $password = $this->input->post('password');
  227. //      $hp = $this->input->post('phone');
  228.        
  229. //      //check email in di database
  230. //      $this->db->where('user_email', $email);
  231. //      $this->db->where_not_in('user_status', array(9));
  232. //      $q = $this->db->get('user');
  233.  
  234. //      if($q->num_rows() > 0) {
  235. //          $data['result'] = 'false';
  236. //          $data['msg'] = 'Email anda sudah terdaftar, silahkan untuk login.';
  237. //      }else{     
  238. //          $simpan = array();
  239.            
  240. //          if($isDriver != ''){
  241. //              $level = 2;
  242. //          }else{
  243. //              $level = 3;
  244. //          }
  245. //          $simpan['user_level'] = $level;
  246. //          $simpan['user_password'] = md5x($password);
  247. //          $simpan['user_nama'] = $nama;
  248. //          $simpan['user_email'] = $email;
  249. //          $simpan['user_register'] = date('Y-m-d H:i:s');
  250. //          $simpan['user_hp'] = $hp;
  251.  
  252. //          $status = $this->db->insert('user',$simpan);
  253.            
  254. //          if($status){               
  255. //              $data['result'] = 'true';
  256. //              $data['msg'] = 'Pendaftaran berhasil, silahkan untuk login';
  257.  
  258.  
  259.                
  260. //          }else{
  261. //              $data['result'] = 'false';
  262. //              $data['msg'] = 'Pendafatran gagal, silahkan coba kembali';
  263. //          }
  264.  
  265. //      }
  266.        
  267. //      #pre($this->db->last_query());
  268. //      echo json_encode($data);
  269. //  }
  270.  
  271.  
  272. //  public function send_notification($penerima, $message) {
  273. //          $api_key = "AIzaSyCu0dAbLJlIHrL-LnGhsSYDdAOl27_1hjA";
  274.            
  275. //          $url = 'https://android.googleapis.com/gcm/send';
  276. //          $fields = array(
  277. //                      'registration_ids'  => $penerima,
  278. //                      'data'              => array( "message" => $message ),
  279. //                      );
  280.  
  281. //          $headers = array(
  282. //                          'Authorization: key=' . $api_key,
  283. //                          'Content-Type: application/json');                     
  284.                            
  285.                            
  286. //          $ch = curl_init();
  287. //          curl_setopt($ch, CURLOPT_URL, $url);
  288. //          curl_setopt( $ch, CURLOPT_POST, true );
  289. //          curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
  290. //          curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  291. //          curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
  292. //          $result = curl_exec($ch);
  293. //          curl_close($ch);
  294.            
  295. //          return $result;
  296. //     }
  297.  
  298. //     public function login(){
  299. //      $data = array();
  300. //      $device = $this->input->post('device');
  301. //      $email =  $this->input->post("f_email");
  302. //      $password =  $this->input->post("f_password");
  303.  
  304. //      //$email = 'riyadi.rb@gmail.com';
  305. //      //$password = '123456';
  306.        
  307. //      if($email == '' || $password == ''){
  308. //          $data['result'] = 'false';
  309. //          $data['msg'] = 'Silahkan isi email dan atau password anda.';
  310. //          echo json_encode($data);
  311. //          return;
  312.            
  313. //      }
  314.        
  315. //      $this->db->where('user_email', $email);
  316. //      $this->db->where('user_password', md5x($password));
  317. //      $this->db->where('user_status', 1);
  318. //      $this->db->where('user_level', 3);
  319. //      $query = $this->db->get('user');
  320. //      if($query->num_rows() > 0){
  321. //          $q = $query->row();
  322.  
  323. //          //delete semua sesi user ini sebelumnya
  324. //          $this->db->where('id_user' , $q->id_user);
  325. //          $this->db->update('sesi', array('sesi_status' => 9));                  
  326. //          //create token
  327. //          $key = md5(date('Y-m-d H:i:s').$device);
  328. //          //masukkan kedlam tabel sesi
  329. //          $simpan = array();
  330. //          $simpan['sesi_key'] =  $key;
  331. //          $simpan['id_user'] = $q->id_user;
  332. //          $simpan['sesi_device'] = $device;
  333. //          $status = $this->db->insert('sesi', $simpan);
  334. //          if($status){
  335. //              $data['result'] = 'true';
  336. //              $data['token'] =  $key;
  337. //              $data['data'] = $q;
  338. //              $data['msg'] = 'Login berhasil.';
  339. //              $data['idUser'] = $q->id_user;
  340. //          }else{
  341. //              $data['result'] = 'false';
  342. //              $data['token'] = '';
  343. //              $data['idUser'] = '';
  344. //              $data['msg'] = 'Error create sesi login, Silahkan coba lagi.';
  345. //          }
  346. //      }else{         
  347. //          $data['result'] = 'false';
  348. //          $data['msg'] = 'Username atau password salah.';
  349.            
  350. //      }      
  351. //      echo json_encode($data);
  352. //  }
  353.  
  354. //     public function registerGcm(){
  355. //      $data = array();
  356.        
  357. //      $this->db->where('id_user', $this->input->post("f_idUser"));
  358. //      $data_simpan['user_gcm'] = $this->input->post("f_gcm");
  359. //      $simpan = $this->db->update('user', $data_simpan);
  360. //      if($simpan){
  361. //          $data['result'] = 'true';
  362. //          $data['msg'] = 'gcm berhasil disimpan';
  363. //      }else{
  364. //          $data['result'] = 'false';
  365. //          $data['msg'] = 'id Gcm gagal disimpan.';
  366. //      }
  367.                
  368. //      echo json_encode($data);
  369. //  }
  370.    
  371.  
  372. //  public function upload($folder = 'produk')
  373. //  {
  374. //     $status = "gagal, upload file";
  375. //     $file_element_name = $this->input->post('userfile');
  376. //     #pre($_FILES);
  377. //     $folder = 'img/'.$folder.'/';
  378.  
  379.        
  380. //      if (!empty($_FILES)) {
  381. //          buatDir($folder);
  382. //          $file_path = $folder . basename( $_FILES['userfile']['name']);
  383. //          //file_put_contents('f.txt',$file_path);
  384. //          if(move_uploaded_file($_FILES['userfile']['tmp_name'], $file_path)) {
  385. //              $status =  "success";
  386. //          } else{
  387. //              $status =  "fail";
  388. //          }
  389. //      }
  390. //     #pre($status);
  391. //     return $status;
  392. //  }
  393.  
  394. //  public function insert_booking(){
  395. //      $data = array();
  396.  
  397. //      if(!$this->check_sesi()){
  398. //          $data['result'] = 'false';
  399. //          $data['msg'] = 'Sesi login expired, silahkan login kembali';       
  400. //          #pre($this->db->last_query());
  401. //          echo json_encode($data);
  402. //          return;
  403. //      }
  404.  
  405. //      $idUser = $this->input->post('f_idUser');
  406. //      $latAwal = $this->input->post('f_latAwal');
  407. //      $lngAwal = $this->input->post('f_lngAwal');
  408. //      $awal = $this->input->post('f_awal');
  409. //      $latAkhir = $this->input->post('f_latAkhir');
  410. //      $lngAkhir = $this->input->post('f_lngAkhir');
  411. //      $akhir = $this->input->post('f_akhir');
  412. //      $alamat = $this->input->post('f_alamat');
  413. //      $jarak = $this->input->post('f_jarak');
  414.  
  415. //      $tarifUser = $jarak * 10000;
  416. //      $tarifDriver = $jarak * 15000;
  417. //      $waktu = date('Y-m-d H:i:s');
  418. //      $simpan['booking_user'] = $idUser;
  419. //      $simpan['booking_tanggal'] = $waktu;
  420. //      $simpan['booking_from'] = $awal;
  421. //      $simpan['booking_from_lat'] = $latAwal;
  422. //      $simpan['booking_from_lng'] = $lngAwal;
  423. //      $simpan['booking_from_alamat'] = $alamat;
  424. //      $simpan['booking_tujuan'] = $akhir;
  425. //      $simpan['booking_tujuan_lat'] = $latAkhir;
  426. //      $simpan['booking_tujuan_lng'] = $lngAkhir;
  427. //      $simpan['booking_biaya_user'] = $tarifUser;
  428. //      $simpan['booking_biaya_driver'] = $tarifDriver;
  429. //      $simpan['booking_jarak'] = $jarak;
  430.  
  431. //      $status = $this->db->insert('booking',$simpan);
  432.        
  433. //      if($status){   
  434. //          $idBooking = $this->db->insert_id();           
  435. //          $data['result'] = 'true';
  436. //          $data['msg'] = 'Booking berhasil';
  437. //          $data['tarif'] = $tarifUser;
  438. //          $data['waktu'] = $waktu;
  439. //          $data['id_booking'] =
  440.  
  441. //          //kirimkan pushnotif kepada driver
  442. //          $this->push_notif($idBooking);
  443. //      }else{
  444. //          $data['result'] = 'false';
  445. //          $data['msg'] = 'Booking gagal, silahkan coba kembali';
  446. //      }
  447.        
  448. //      #pre($this->db->last_query());
  449. //      echo json_encode($data);
  450. //  }
  451.  
  452. //  public function cancel_booking($id = ''){
  453. //      $data = array();
  454.  
  455. //      if(!$this->check_sesi()){
  456. //          $data['result'] = 'false';
  457. //          $data['msg'] = 'Sesi login expired, silahkan login kembali';       
  458. //          #pre($this->db->last_query());
  459. //          echo json_encode($data);
  460. //          return;
  461. //      }
  462.  
  463. //      if($id == ''){
  464. //          $data['result'] = 'false';
  465. //          $data['msg'] = 'Booking tidak dikenali';       
  466. //          #pre($this->db->last_query());
  467. //          echo json_encode($data);
  468. //          return;
  469. //      }
  470. //      $simpan = array();
  471. //      $simpan['booking_status'] = 3; //3. Booking cancel
  472. //      $this->db->where('id_booking', $id);
  473. //      $status = $this->db->update('booking',$simpan);
  474.        
  475. //      if($status){               
  476. //          $data['result'] = 'true';
  477. //          $data['msg'] = 'Booking berhasil dicancel';
  478. //      }else{
  479. //          $data['result'] = 'false';
  480. //          $data['msg'] = 'Cancel Booking gagal.';
  481. //      }
  482.        
  483. //      #pre($this->db->last_query());
  484. //      echo json_encode($data);
  485. //  }
  486.  
  487. //  public function get_booking($status = 1){
  488. //      $data = array();
  489.  
  490. //      if(!$this->check_sesi()){
  491. //          $data['result'] = 'false';
  492. //          $data['msg'] = 'Sesi login expired, silahkan login kembali';       
  493. //          #pre($this->db->last_query());
  494. //          echo json_encode($data);
  495. //          return;
  496. //      }
  497.  
  498.        
  499. //      $idUser = $this->input->post('f_idUser');
  500. //      if($status == 1){
  501. //          $this->db->where_in('booking_status', array(1,2));
  502. //      }else if($status == 4){
  503. //          $this->db->join('user', 'user.id_user=booking.booking_driver');
  504. //          $this->db->where('booking_status', $status);
  505. //      }else{
  506. //          $this->db->where('booking_status', $status);
  507. //      }
  508.        
  509. //      $this->db->where('booking_user', $idUser);
  510. //      $this->db->order_by('id_booking', 'DESC');
  511. //      $q = $this->db->get('booking ');
  512.        
  513. //      if($q->num_rows() > 0){            
  514. //          $data['result'] = 'true';
  515. //          $data['msg'] = 'Data booking ada';
  516. //          $data['data'] = $q->result();
  517. //      }else{
  518. //          $data['result'] = 'false';
  519. //          $data['msg'] = 'Data booking tidak ada.';
  520. //      }
  521.        
  522. //      #pre($this->db->last_query());
  523. //      echo json_encode($data);
  524. //  }
  525.  
  526. //  // ===================== xrb21 | riyadi.rb@gmail.com ======================
  527. //  // Training Android "5 Hari Membangun aplikasi Ojeg Online" IMASTUDIO Jogja
  528. //  // Yogyakarta, 8-12 Feb 2016
  529.  
  530. //  // API for DRIVER
  531. //  public function login_driver(){
  532. //      $data = array();
  533. //      $device = $this->input->post('device');
  534. //      $email =  $this->input->post("f_email");
  535. //      $password =  $this->input->post("f_password");
  536.  
  537.  
  538. //      //$email = 'riyadi.rb@gmail.com';
  539. //      //$password = '123456';
  540.        
  541. //      if($email == '' || $password == ''){
  542. //          $data['result'] = 'false';
  543. //          $data['msg'] = 'Silahkan isi email dan atau password anda.';
  544. //          echo json_encode($data);
  545. //          return;
  546.            
  547. //      }
  548.        
  549. //      $this->db->where('user_email', $email);
  550. //      $this->db->where('user_password', md5x($password));
  551. //      $this->db->where('user_level', 2);
  552. //      $this->db->where('user_status', 1);
  553. //      $query = $this->db->get('user');
  554. //      if($query->num_rows() > 0){
  555. //          $q = $query->row();
  556.  
  557. //          //delete semua sesi user ini sebelumnya
  558. //          $this->db->where('id_user' , $q->id_user);
  559. //          $this->db->update('sesi', array('sesi_status' => 9));                  
  560. //          //create token
  561. //          $key = md5(date('Y-m-d H:i:s').$device);
  562. //          //masukkan kedlam tabel sesi
  563. //          $simpan = array();
  564. //          $simpan['sesi_key'] =  $key;
  565. //          $simpan['id_user'] = $q->id_user;
  566. //          $simpan['sesi_device'] = $device;
  567. //          $status = $this->db->insert('sesi', $simpan);
  568. //          if($status){
  569. //              $data['result'] = 'true';
  570. //              $data['token'] =  $key;
  571. //              $data['data'] = $q;
  572. //              $data['msg'] = 'Login berhasil.';
  573. //              $data['idUser'] = $q->id_user;
  574. //          }else{
  575. //              $data['result'] = 'false';
  576. //              $data['token'] = '';
  577. //              $data['idUser'] = '';
  578. //              $data['msg'] = 'Error create sesi login, Silahkan coba lagi.';
  579. //          }
  580. //      }else{         
  581. //          $data['result'] = 'false';
  582. //          $data['msg'] = 'Username atau password salah.';
  583.            
  584. //      }      
  585. //      echo json_encode($data);
  586. //  }
  587.  
  588. //  public function get_request_booking(){
  589. //      $data = array();
  590.  
  591. //      if(!$this->check_sesi()){
  592. //          $data['result'] = 'false';
  593. //          $data['msg'] = 'Sesi login expired, silahkan login kembali';       
  594. //          #pre($this->db->last_query());
  595. //          echo json_encode($data);
  596. //          return;
  597. //      }
  598.  
  599. //      $this->db->join('user', 'user.id_user=booking.booking_user');
  600. //      $this->db->where('booking_status', 1);
  601. //      $this->db->order_by('id_booking', 'DESC');
  602. //      $q = $this->db->get('booking');
  603.        
  604. //      if($q->num_rows() > 0){            
  605. //          $data['result'] = 'true';
  606. //          $data['msg'] = 'Data booking ada';
  607. //          $data['data'] = $q->result();
  608. //      }else{
  609. //          $data['result'] = 'false';
  610. //          $data['msg'] = 'Data booking tidak ada.';
  611. //      }
  612.        
  613. //      #pre($this->db->last_query());
  614. //      echo json_encode($data);
  615. //  }
  616.  
  617. //  public function take_booking($id = ''){
  618. //      $data = array();
  619.  
  620. //      if(!$this->check_sesi()){
  621. //          $data['result'] = 'false';
  622. //          $data['msg'] = 'Sesi login expired, silahkan login kembali';       
  623. //          #pre($this->db->last_query());
  624. //          echo json_encode($data);
  625. //          return;
  626. //      }
  627.  
  628. //      if($id == ''){
  629. //          $data['result'] = 'false';
  630. //          $data['msg'] = 'Booking tidak dikenali';       
  631. //          #pre($this->db->last_query());
  632. //          echo json_encode($data);
  633. //          return;
  634. //      }
  635.  
  636. //      //check apakah booking sudah ada yang ambil atau tidak
  637. //      $this->db->where('id_booking', $id);
  638. //      $this->db->where('booking_status', 1);
  639. //      $q = $this->db->get('booking');
  640. //      if($q->num_rows() == 0){
  641. //          $data['result'] = 'false';
  642. //          $data['msg'] = 'Booking sudah ada yang take,coba booking yang lainnya.';       
  643. //          #pre($this->db->last_query());
  644. //          echo json_encode($data);
  645. //          return;
  646. //      }
  647.  
  648. //      $idUser = $this->input->post('f_idUser');
  649. //      $simpan = array();
  650. //      $simpan['booking_status'] = 2; //2. Booking diambil oleh driver
  651. //      $simpan['booking_driver'] = $idUser;
  652. //      $simpan['booking_take_tanggal'] = date('Y-m-d H:i:s');
  653. //      $this->db->where('id_booking', $id);
  654. //      $status = $this->db->update('booking',$simpan);
  655.        
  656. //      if($status){               
  657. //          $data['result'] = 'true';
  658. //          $data['msg'] = 'Take Booking berhasil';
  659. //      }else{
  660. //          $data['result'] = 'false';
  661. //          $data['msg'] = 'Take Booking gagal.';
  662. //      }
  663.        
  664. //      #pre($this->db->last_query());
  665. //      echo json_encode($data);
  666. //  }
  667.  
  668. //  public function get_handle_booking(){
  669. //      $data = array();
  670.  
  671. //      if(!$this->check_sesi()){
  672. //          $data['result'] = 'false';
  673. //          $data['msg'] = 'Sesi login expired, silahkan login kembali';       
  674. //          #pre($this->db->last_query());
  675. //          echo json_encode($data);
  676. //          return;
  677. //      }
  678.  
  679. //      $idUser = $this->input->post('f_idUser');
  680. //      $this->db->join('user', 'user.id_user=booking.booking_user');
  681. //      $this->db->where('booking_status', 2);
  682. //      $this->db->where('booking_driver', $idUser);
  683. //      $this->db->order_by('id_booking', 'DESC');
  684. //      $q = $this->db->get('booking');
  685.        
  686. //      if($q->num_rows() > 0){            
  687. //          $data['result'] = 'true';
  688. //          $data['msg'] = 'Data handle booking ada';
  689. //          $data['data'] = $q->result();
  690. //      }else{
  691. //          $data['result'] = 'false';
  692. //          $data['msg'] = 'Data handle booking tidak ada.';
  693. //      }
  694.        
  695. //      #pre($this->db->last_query());
  696. //      echo json_encode($data);
  697. //  }
  698.  
  699. //  public function complete_booking($id = ''){
  700. //      $data = array();
  701.  
  702. //      if(!$this->check_sesi()){
  703. //          $data['result'] = 'false';
  704. //          $data['msg'] = 'Sesi login expired, silahkan login kembali';       
  705. //          #pre($this->db->last_query());
  706. //          echo json_encode($data);
  707. //          return;
  708. //      }
  709.  
  710. //      if($id == ''){
  711. //          $data['result'] = 'false';
  712. //          $data['msg'] = 'Booking tidak dikenali';       
  713. //          #pre($this->db->last_query());
  714. //          echo json_encode($data);
  715. //          return;
  716. //      }
  717.  
  718. //      //check apakah booking sudah ada yang ambil atau tidak
  719. //      $idUser = $this->input->post('f_idUser');
  720. //      $this->db->where('id_booking', $id);
  721. //      $this->db->where('booking_status', 2);
  722. //      $this->db->where('booking_driver', $idUser);
  723. //      $q = $this->db->get('booking');
  724. //      if($q->num_rows() == 0){
  725. //          $data['result'] = 'false';
  726. //          $data['msg'] = 'Ini bukan data booking ada.';      
  727. //          #pre($this->db->last_query());
  728. //          echo json_encode($data);
  729. //          return;
  730. //      }
  731.  
  732. //      $simpan = array();
  733. //      $simpan['booking_status'] = 4; //2. Booking diambil oleh driver
  734. //      $simpan['booking_complete_tanggal'] = date('Y-m-d H:i:s');
  735. //      $this->db->where('id_booking', $id);
  736. //      $status = $this->db->update('booking',$simpan);
  737.        
  738. //      if($status){               
  739. //          $data['result'] = 'true';
  740. //          $data['msg'] = 'Booking Completed';
  741. //      }else{
  742. //          $data['result'] = 'false';
  743. //          $data['msg'] = 'Complete booking gagal.';
  744. //      }
  745.        
  746. //      #pre($this->db->last_query());
  747. //      echo json_encode($data);
  748. //  }
  749.  
  750. //  public function get_complete_booking(){
  751. //      $data = array();
  752.  
  753. //      if(!$this->check_sesi()){
  754. //          $data['result'] = 'false';
  755. //          $data['msg'] = 'Sesi login expired, silahkan login kembali';       
  756. //          #pre($this->db->last_query());
  757. //          echo json_encode($data);
  758. //          return;
  759. //      }
  760.  
  761. //      $idUser = $this->input->post('f_idUser');
  762. //      $this->db->join('user', 'user.id_user=booking.booking_user');
  763. //      $this->db->where('booking_status', 4);
  764. //      $this->db->where('booking_driver', $idUser);
  765. //      $this->db->order_by('id_booking', 'DESC');
  766. //      $q = $this->db->get('booking');
  767.        
  768. //      if($q->num_rows() > 0){            
  769. //          $data['result'] = 'true';
  770. //          $data['msg'] = 'Data complete ada';
  771. //          $data['data'] = $q->result();
  772. //      }else{
  773. //          $data['result'] = 'false';
  774. //          $data['msg'] = 'Data complete tidak ada.';
  775. //      }
  776.        
  777. //      #pre($this->db->last_query());
  778. //      echo json_encode($data);
  779. //  }
  780.  
  781. //  //send totikasi kepada driver
  782. //  public function push_notif($idBooking){
  783. //      $last = $idBooking;
  784. //      if (isCurl()){
  785. //          //ambil semua id dari data gcm
  786. //          $datax = array();
  787. //          $this->db->join('user', 'user.id_user=booking.booking_user');
  788. //          $this->db->where('booking_status', 1);
  789. //          $this->db->where('id_booking', $idBooking);
  790. //          $q = $this->db->get('booking');
  791.            
  792. //          if($q->num_rows() > 0){            
  793. //              $datax['result'] = 'true';
  794. //              $datax['msg'] = 'Data booking ada';
  795. //              $datax['data'] = $q->row();
  796. //          }else{
  797. //              $datax['result'] = 'false';
  798. //              $datax['msg'] = 'Data booking tidak ada.';
  799. //          }
  800.            
  801. //          $this->db->where('user_level', 2);
  802. //          $this->db->where('user_status', 1);
  803. //          $this->db->where_not_in('user_gcm', array(""));
  804. //          $qq = $this->db->get('user');
  805. //          #pre($datax);  
  806. //          if($qq->num_rows() > 0){
  807.  
  808. //              $receivers = array();
  809. //              $message = array("datax" => $datax);
  810. //              foreach ($qq->result() as $r) {
  811. //                  $receivers[] = $r->user_gcm;
  812. //              }
  813. //              #pre($receivers);
  814. //              $hasil = $this->send_notification($receivers, $message);
  815. //              #pre($hasil);
  816. //          }else{
  817. //              echo "data tidak ada";
  818. //          }
  819. //      }else{
  820. //          $pesan .= ' Curl tidak aktif tidak bisa kirim notifikasi berita ke user.';
  821. //      }
  822. //  }
  823.  
  824. //  public function insert_posisi(){
  825. //      $data = array();
  826.  
  827. //      if(!$this->check_sesi()){
  828. //          $data['result'] = 'false';
  829. //          $data['msg'] = 'Sesi login expired, silahkan login kembali';       
  830. //          #pre($this->db->last_query());
  831. //          echo json_encode($data);
  832. //          return;
  833. //      }
  834.  
  835. //      $idUser = $this->input->post('f_idUser');
  836. //      $lat = $this->input->post('f_lat');
  837. //      $lng = $this->input->post('f_lng');
  838.        
  839. //      $waktu = date('Y-m-d H:i:s');
  840. //      $simpan['tracking_driver'] = $idUser;
  841. //      $simpan['tracking_waktu'] = $waktu;
  842. //      $simpan['tracking_lat'] = $lat;
  843. //      $simpan['tracking_lng'] = $lng;
  844.  
  845. //      $status = $this->db->insert('tracking',$simpan);
  846.        
  847. //      if($status){   
  848. //          $data['result'] = 'true';
  849. //          $data['msg'] = 'input tracking berhasil';
  850. //      }else{
  851. //          $data['result'] = 'false';
  852. //          $data['msg'] = 'input tracking gagal, silahkan coba kembali';
  853. //      }
  854.        
  855. //      #pre($this->db->last_query());
  856. //      echo json_encode($data);
  857. //  }
  858.  
  859. //  public function get_driver(){
  860. //      $data = array();
  861.  
  862. //      $this->db->join('user', 'user.id_user=tracking.tracking_driver');
  863. //      $this->db->where('tracking_status', 1);
  864. //      $this->db->order_by('id_tracking', 'DESC');
  865. //      $this->db->group_by('tracking_driver');
  866. //      $q = $this->db->get('tracking');
  867.        
  868. //      if($q->num_rows() > 0){            
  869. //          $data['result'] = 'true';
  870. //          $data['msg'] = 'Data driver ada';
  871. //          $data['data'] = $q->result();
  872. //      }else{
  873. //          $data['result'] = 'false';
  874. //          $data['msg'] = 'Data driver tidak ada.';
  875. //      }
  876.        
  877. //      #pre($this->db->last_query());
  878. //      echo json_encode($data);
  879. //  }
  880.  
  881. //  public function insert_review(){
  882. //      $data = array();
  883.  
  884. //      if(!$this->check_sesi()){
  885. //          $data['result'] = 'false';
  886. //          $data['msg'] = 'Sesi login expired, silahkan login kembali';       
  887. //          #pre($this->db->last_query());
  888. //          echo json_encode($data);
  889. //          return;
  890. //      }
  891.  
  892. //      $idUser = $this->input->post('f_idUser');
  893. //      $driver = $this->input->post('f_driver');
  894. //      $idBooking = $this->input->post('f_idBooking');
  895. //      $rating = $this->input->post('f_ratting');
  896. //      $comment = $this->input->post('f_comment');
  897.        
  898. //      $waktu = date('Y-m-d H:i:s');
  899. //      $simpan['review_driver'] = $driver;
  900. //      $simpan['review_user'] = $idUser;
  901. //      $simpan['review_tanggal'] = $waktu;
  902. //      $simpan['review_rating'] = $rating;
  903. //      $simpan['review_komentar'] = $comment;
  904. //      $simpan['id_booking'] = $idBooking;
  905.  
  906. //      $status = $this->db->insert('review',$simpan);
  907.        
  908. //      if($status){   
  909. //          $data['result'] = 'true';
  910. //          $data['msg'] = 'input review berhasil';
  911. //      }else{
  912. //          $data['result'] = 'false';
  913. //          $data['msg'] = 'input review gagal, silahkan coba kembali';
  914. //      }
  915.        
  916. //      #pre($this->db->last_query());
  917. //      echo json_encode($data);
  918. //  }
  919.     public function transaksi(){
  920.      $data = array();
  921.      $status=1;
  922.      //parameter array
  923.  
  924.      
  925.      $id_produk                      = $this->input->post('id_produk');
  926.      $product_name                       = $this->input->post('product_name');
  927.      $desc_product                       = $this->input->post('desc_product');
  928.      $detail_gbr                     = $this->input->post('detail_gbr');
  929.      $price2                     = $this->input->post('price2');
  930.      $transaksi_subtotal                     = $this->input->post('transaksi_subtotal');
  931.      $transaksi_total                        = $this->input->post('transaksi_total');
  932.  
  933.      //parameter biasa bukan array
  934.      $id_user    = $this->input->post('id_user');
  935.      $kode       = $this->input->post('kode');
  936.      $subtotal    = $this->input->post('subtotal');
  937.      $total      = $this->input->post('total');
  938.      $alamat     = $this->input->post('alamat');
  939.      $nm_penerima            = $this->input->post('nm_penerima');
  940.      $tlp_penerima       = $this->input->post('tlp_penerima');
  941.      $tgl_pengiriman     = $this->input->post('tgl_pengiriman');
  942.      $psn_penerima       = $this->input->post('psn_penerima');
  943.  
  944.  
  945.  
  946.      
  947.      //temporary parameter
  948.      $temp =count($this->input->post('id_produk'));
  949.  
  950.      //simpan ke tb_transaksi
  951.      $simpan_transaksi = array();
  952.      $simpan_transaksi['transaksi_kode']     = $kode;
  953.      $simpan_transaksi['transaksi_biaya']     = $price2;
  954.      $simpan_transaksi['transaksi_total']     = $total;
  955.      $simpan_transaksi['transaksi_subtotal'] = $subtotal;
  956.      $simpan_transaksi['transaksi_status']     = $status;
  957.      $simpan_transaksi['transaksi_user']     = $id_user;
  958.      $simpan_transaksi['transaksi_alamat']     = $alamat;
  959.      $simpan_transaksi['nm_penerima']     = $nm_penerima;
  960.      $simpan_transaksi['tlp_penerima']     = $tlp_penerima;
  961.      $simpan_transaksi['tgl_pengiriman']     = $tgl_pengiriman;
  962.      $simpan_transaksi['psn_penerima']     = $psn_penerima;
  963.      $q = $this->db->insert('tb_transaksi', $simpan_transaksi);
  964.  
  965.      // for ($i=0; $i<$temp; $i++) {
  966.         //  $simpan[$i] = array(
  967.         //       'detail_kode'       =>$kode,
  968.         //       'detail_produk'     =>$id_produk[$i],
  969.         //       'detail_nama'       =>$product_name[$i],
  970.         //       'detail_des'        =>$desc_product[$i],
  971.         //       'detail_gbr'        =>$detail_gbr[$i],
  972.         //       'detail_harga'      =>$price2[$i],
  973.         //       'detail_jumlah'     =>$transaksi_subtotal[$i],
  974.         //       'detail_total'      =>$transaksi_total[$i]
  975.         //   );
  976.  
  977.      // }
  978.      // $s = $this->db->insert_batch('tb_detail', $simpan);
  979.      
  980.  
  981.      if($q && $s){               
  982.          $data['result'] = 'true';
  983.          $data['msg']     = 'order Sukses';
  984.          
  985.      }else{
  986.          $data['result'] = 'false';
  987.          $data['msg']     = 'order Gagal';
  988.      }
  989.      echo json_encode($data);
  990.     }
  991.  
  992.     //function get  slider
  993.     public function get_slider(){
  994.         $data = array();
  995.         $q = $this->db->get('tb_slider');
  996.         if($q->num_rows() > 0){            
  997.             $data['result'] = 'true';
  998.             $data['msg'] = 'Data semua Slider';
  999.             $data['data'] = $q->result();
  1000.         }else{
  1001.             $data['result'] = 'false';
  1002.             $data['msg'] = 'Tidak ada data Slider';
  1003.         }
  1004.        
  1005.    
  1006.         echo json_encode($data);
  1007.     }
  1008.  
  1009.     //function get  category product
  1010.     public function get_kategori(){
  1011.         $data = array();
  1012.         $q = $this->db->get('tb_kategori_produk');
  1013.         if($q->num_rows() > 0){            
  1014.             $data['result'] = 'true';
  1015.             $data['msg'] = 'Data semua Category Product';
  1016.             $data['data'] = $q->result();
  1017.         }else{
  1018.             $data['result'] = 'false';
  1019.             $data['msg'] = 'Tidak ada data Category Product';
  1020.         }
  1021.        
  1022.    
  1023.         echo json_encode($data);
  1024.     }
  1025.  
  1026.         //function get  merk
  1027.     public function get_merk(){
  1028.         $data = array();
  1029.         $q = $this->db->get('merk_product');
  1030.         if($q->num_rows() > 0){            
  1031.             $data['result'] = 'true';
  1032.             $data['msg'] = 'Data semua Merk ';
  1033.             $data['data'] = $q->result();
  1034.         }else{
  1035.             $data['result'] = 'false';
  1036.             $data['msg'] = 'Tidak ada data merk';
  1037.         }
  1038.        
  1039.    
  1040.         echo json_encode($data);
  1041.     }
  1042.         public function get_merkid(){
  1043.         $data = array();
  1044.         $idmerk = $this->input->post('k_idMerk');
  1045.         $sql = "select * from tb_produk a, tb_spek_produk b, merk_product c, tb_kategori_produk d WHERE c.id_merk = a.id_merk and a.id_merk = '$idmerk' GROUP BY c.id_merk DESC";
  1046.         $q = $this->db->query($sql);
  1047.         if($q->num_rows() > 0){            
  1048.             $data['result'] = 'true';
  1049.             $data['msg'] = 'Data Merk product';
  1050.             $data['data'] = $q->result();
  1051.         }else{
  1052.             $data['result'] = 'false';
  1053.             $data['msg'] = 'Tidak ada data Merk product';
  1054.         }
  1055.        
  1056.         #pre($this->db->last_query());
  1057.         echo json_encode($data);
  1058.     }
  1059.  
  1060.         public function get_catid(){
  1061.         $data = array();
  1062.         $idkategori = $this->input->post('k_idKategori');
  1063.         $sql = "select * from tb_produk a, tb_spek_produk b, merk_product c, tb_kategori_produk d WHERE d.id_kategori_produk = a.id_kategori_produk and a.id_kategori_produk = '$idkategori' GROUP BY d.id_kategori_produk DESC";
  1064.         // $sql = "SELECT * FROM tb_produk, tb_spek_produk , merk_product , tb_kategori_produk WHERE merk_product.id_merk = tb_produk.id_merk AND tb_produk.id_produk = tb_spek_produk.id_produk AND tb_produk.id_kategori_produk='$idkategori'";
  1065.         $q = $this->db->query($sql);
  1066.         if($q->num_rows() > 0){            
  1067.             $data['result'] = 'true';
  1068.             $data['msg'] = 'Data Kategori product';
  1069.             $data['data'] = $q->result();
  1070.         }else{
  1071.             $data['result'] = 'false';
  1072.             $data['msg'] = 'Tidak ada data Kategori product';
  1073.         }
  1074.        
  1075.         #pre($this->db->last_query());
  1076.         echo json_encode($data);
  1077.     }
  1078.         public function get_product(){
  1079.         $data = array();
  1080.         $q = $this->db->get('tb_produk');
  1081.         if($q->num_rows() > 0){            
  1082.             $data['result'] = 'true';
  1083.             $data['msg'] = 'Data semua Produk ';
  1084.             $data['data'] = $q->result();
  1085.         }else{
  1086.             $data['result'] = 'false';
  1087.             $data['msg'] = 'Tidak ada data Produk';
  1088.         }
  1089.        
  1090.    
  1091.         echo json_encode($data);
  1092.     }
  1093.             public function get_productid(){
  1094.         $data = array();
  1095.         $idproduk = $this->input->post('k_idProduk');
  1096.         // $sql = "select * from tb_produk a, tb_spek_produk b, merk_product c, tb_kategori_produk d WHERE d.id_kategori_produk = a.id_kategori_produk and a.id_kategori_produk = '$idkategori' GROUP BY d.id_kategori_produk DESC";
  1097.         $sql = "SELECT * FROM merk_product, tb_kategori_produk, tb_produk, tb_spek_produk WHERE tb_produk.id_merk = merk_product.id_merk and tb_kategori_produk.id_kategori_produk = tb_produk.id_kategori_produk AND tb_spek_produk.id_produk = tb_produk.id_produk AND tb_produk.id_produk='$idproduk'";
  1098.         $q = $this->db->query($sql);
  1099.         if($q->num_rows() > 0){            
  1100.             $data['result'] = 'true';
  1101.             $data['msg'] = 'Data all Product ';
  1102.             $data['data'] = $q->result();
  1103.         }else{
  1104.             $data['result'] = 'false';
  1105.             $data['msg'] = 'Tidak ada data all product';
  1106.         }
  1107.        
  1108.         #pre($this->db->last_query());
  1109.         echo json_encode($data);
  1110.     }
  1111.         // //cat product by id
  1112. //  public function get_catid(){
  1113. //      $data = array();
  1114. //      $id = $this->input->post('k_idcat');
  1115. //      $this->db->where('id_kategori_produk', $id);
  1116. //      $q = $this->db->get('tb_kategori_produk');
  1117. //      $data['data'] = $q->result();
  1118. //      if($q->num_rows() > 0){            
  1119. //          $data['result'] = 'true';
  1120. //          $data['msg'] = 'Data  Category Product';
  1121. //          $data['data'] = $q->result();
  1122. //      }else{
  1123. //          $data['result'] = 'false';
  1124. //          $data['msg'] = 'Data  Category Product tidak ada.';
  1125. //      }
  1126. //     
  1127. //      #pre($this->db->last_query());
  1128. //      echo json_encode($data);
  1129. //  }
  1130.  
  1131.  
  1132.     //menu product berdasarkan id
  1133.     // public function kategori_product(){
  1134.     //  $data = array();
  1135.     //  $idKategori = $this->input->post('k_idKategori');
  1136.     //  //$this->db->where('id_resto', $idresto);
  1137.     //  $sql = "SELECT * FROM merk_product, tb_kategori_produk, tb_produk, tb_spek_produk WHERE tb_produk.id_merk = merk_product.id_merk and tb_kategori_produk.id_kategori_produk = tb_produk.id_kategori_produk AND tb_spek_produk.id_produk = tb_produk.id_produk and tb_produk.id_kategori_produk='$idKategori'";
  1138.     //  $q = $this->db->query($sql);
  1139.     //  if($q->num_rows() > 0){            
  1140.     //      $data['result'] = 'true';
  1141.     //      $data['msg'] = 'Data menu Kategori';
  1142.     //      $data['data'] = $q->result();
  1143.     //  }else{
  1144.     //      $data['result'] = 'false';
  1145.     //      $data['msg'] = 'Tidak ada data menu Kategori';
  1146.     //  }
  1147.        
  1148.     //  #pre($this->db->last_query());
  1149.     //  echo json_encode($data);
  1150.     // }
  1151.  
  1152.     // //product by id
  1153. //  public function product_id(){
  1154. //      $data = array();
  1155. //      $id = $this->input->post('k_idProduct');
  1156. //      $this->db->where('id_produk', $id);
  1157. //      $q = $this->db->get('tb_produk');
  1158. //      $data['data'] = $q->result();
  1159. //      if($q->num_rows() > 0){            
  1160. //          $data['result'] = 'true';
  1161. //          $data['msg'] = 'Data  Product';
  1162. //          $data['data'] = $q->result();
  1163. //      }else{
  1164. //          $data['result'] = 'false';
  1165. //          $data['msg'] = 'Data  Product tidak ada.';
  1166. //      }
  1167. //     
  1168. //      #pre($this->db->last_query());
  1169. //      echo json_encode($data);
  1170. //  }
  1171. //
  1172.  
  1173. //  //merk by id
  1174. //  public function get_merk_id(){
  1175. //      $data = array();
  1176. //      $id = $this->input->post('k_idmerk');
  1177. //      $this->db->where('id_merk', $id);
  1178. //      $q = $this->db->get('merk_product');
  1179. //      $data['data'] = $q->result();
  1180. //      if($q->num_rows() > 0){            
  1181. //          $data['result'] = 'true';
  1182. //          $data['msg'] = 'Data Merk Product';
  1183. //          $data['data'] = $q->result();
  1184. //      }else{
  1185. //          $data['result'] = 'false';
  1186. //          $data['msg'] = 'Data Merk Product tidak ada.';
  1187. //      }
  1188. //     
  1189. //      #pre($this->db->last_query());
  1190. //      echo json_encode($data);
  1191. //  }
  1192.  
  1193.    
  1194. }
  1195.  
  1196. /* End of file welcome.php */
  1197. /* Location: ./application/controllers/welcome.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement