Advertisement
Guest User

Untitled

a guest
Feb 6th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.43 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Api extends CI_Controller {
  5.  
  6.     public function __construct()
  7.     {
  8.         parent::__construct();
  9.     }
  10.  
  11.     public function index()
  12.     {
  13.        
  14.     }
  15.  
  16.     public function login()
  17.     {
  18.         $this->form_validation->set_rules('username', 'Username', 'required');
  19.         $this->form_validation->set_rules('password', 'Password', 'required');
  20.         if ($this->form_validation->run() == FALSE) {
  21.             echo json_encode(array('status'=>500,
  22.                 'username' => form_error('username'),
  23.                 'password' => form_error('password')
  24.                 ));
  25.         } else {
  26.             $username = $this->input->post('username');
  27.             $password = $this->input->post('password');
  28.             $auth = $this->db->get_where('customer', array('username' => $username, 'password' => $password));
  29.             if($auth->num_rows() > 0) {
  30.                 $row = $auth->row_array();
  31.                 $res = array('status' => 200, 'username' => $row['username'], 'id_customer' => $row['id_customer']);
  32.                 echo json_encode($res);
  33.             } else {
  34.                 $res = array('status' => 404);
  35.                 echo json_encode($res);
  36.             }
  37.         }
  38.     }
  39.  
  40.     public function register()
  41.     {
  42.  
  43.         $this->form_validation->set_rules('nama', 'Nama', 'required');
  44.         $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
  45.         $this->form_validation->set_rules('username', 'Username', 'required');
  46.         $this->form_validation->set_rules('password', 'Password', 'required');
  47.         if ($this->form_validation->run() == FALSE) {
  48.             echo json_encode(array('status'=>500,
  49.                 'nama' => form_error('nama'),
  50.                 'email' => form_error('email'),
  51.                 'username' => form_error('username'),
  52.                 'password' => form_error('password')
  53.                 ));
  54.         } else {
  55.             $field['nama'] = $this->input->post('nama');
  56.             $field['email'] = $this->input->post('email');
  57.             $field['username'] = $this->input->post('username');
  58.             $field['password'] = $this->input->post('password');
  59.             $field['tgl_daftar'] = date('Y-m-d');
  60.             $this->db->insert('customer', $field);
  61.             echo json_encode(array('status' => 200));
  62.         }
  63.     }
  64.  
  65.     public function pilih_paket()
  66.     {
  67.  
  68.         $id_paket = $this->input->post('id_paket');
  69.         $row = $this->db->get_where('paket', array('id_paket' => $id_paket))->row_array();
  70.         echo json_encode(array('id_paket' => $row['id_paket'], 'nama_paket' => $row['nama_paket']));
  71.     }
  72.  
  73.     public function status_informasi()
  74.     {
  75.         $id_customer = $this->input->post('id_customer');
  76.         $res = $this->db->get_where('pendaftaran', array('id_customer' => $id_customer));
  77.         if($res->num_rows() > 0) {
  78.             $table = 'Untuk melengkapi dokumen dan administrasi silahkan datang ke kantor kami.<hr>';
  79.             $table .= '<div class="data-table">';
  80.             $table .= '<table id="tbl-pendaftaran">';
  81.             $table .= "<tr>";
  82.             $table .=   "<td><b>Kode Daftar</b></td>";
  83.             $table .=   "<td><b>Tgl.Daftar</b></td>";
  84.             $table .= "<tr>";
  85.             foreach ($res->result_array() as $row) {
  86.                  if($row['status'] == 0) {
  87.                       $status = "<span class='label label-danger'>No</span>";
  88.                     } else {
  89.                         $status = "<span class='label label-danger'>Yes</span>";
  90.                     }
  91.  
  92.                
  93.                 $table .= "<tr id=".$row['kode'].">";
  94.                 $table .= "<td><a class='status-pendaftaran' id=".$row['kode']." href='/detail_pendaftaran/'>".$row['kode']."</a></td>";
  95.                 $table .= "<td>".date_d_m_y($row['tanggal'])."</td>";
  96.                 $table .= "</tr>";
  97.             }
  98.             $table .= "</table>";
  99.             $table .= "</div>";
  100.             echo json_encode($table);
  101.         } else {
  102.             echo json_encode(0);
  103.         }
  104.  
  105.     }
  106.  
  107.     public function get_detail_pendaftaran()
  108.     {
  109.         $id_pendaftaran = $this->input->post('id_pendaftaran');
  110.         $this->db->join('paket', 'pendaftaran.id_paket = paket.id_paket');
  111.         $this->db->join('customer', 'customer.id_customer = pendaftaran.id_customer');
  112.         $data['row'] = $this->db->get_where('pendaftaran', array('pendaftaran.id_pendaftaran' => $id_pendaftaran))->row_array();
  113.         $this->load->view('detail_pendaftaran', $data);
  114.     }
  115.  
  116.     public function list_daftar()
  117.     {
  118.         $id_customer = $this->input->post('id_customer');
  119.         $this->db->join('paket', 'pendaftaran.id_paket = paket.id_paket');
  120.         $this->db->join('customer', 'customer.id_customer = pendaftaran.id_customer');
  121.         $data['row'] = $this->db->get_where('pendaftaran', array('pendaftaran.id_customer' => $id_customer))->row_array();
  122.  
  123.         $data['customer'] = $this->db->get_where('customer', array('id_customer' => $id_customer))->row_array();
  124.  
  125.         $this->load->view('list_pendaftaran', $data);
  126.     }
  127.  
  128.     public function form_paket()
  129.     {
  130.  
  131.         $data['id_paket'] = $this->input->post('id_paket');
  132.         $data['id_customer'] = $this->input->post('id_customer');
  133.         $data['nama_paket'] = get_nama_paket($this->input->post('id_paket'));
  134.         $data['kategori'] = get_nama_kategori($this->input->post('id_paket'));
  135.         $data['jenis_kamar'] = $this->input->post('jenis_kamar');
  136.         $this->load->view('api/form_paket', $data);
  137.     }
  138.  
  139.     public function get_paket_harga()
  140.     {
  141.         $id = $this->input->post('id_paket');
  142.         $row = $this->db->get_where('paket', array('id_paket' => $id))->row_array();
  143.         echo json_encode(array(
  144.             'sekamar_ber4' => rupiah($row['harga_sekamar_ber_4']),
  145.             'sekamar_ber3' => rupiah($row['harga_sekamar_ber_3']),
  146.             'sekamar_ber2' => rupiah($row['harga_sekamar_ber_2']),
  147.             )
  148.         );
  149.     }
  150.    
  151.     public function lupa_password()
  152.     {
  153.         $to_email = $this->input->post('email');
  154.         $check = $this->db->get_where('customer', array('email' => $to_email))->row_array();
  155.         if($check) {
  156.         $key = md5(date("Y-m-d h:i:sa"));
  157.         $updt['forgot_password'] = $key;
  158.         $wherex['email'] = $to_email;
  159.         $this->db->update('customer', $updt, $wherex);
  160.             $config = Array(
  161.                 'protocol' => 'smtp',
  162.                 'charset'=>'utf-8',
  163.                 'smtp_host' => 'ssl://mail.7setiawan.com',
  164.                 'smtp_port' => 465,
  165.                 'smtp_user' => 'info@7setiawan.com',
  166.                 'smtp_pass' => '~{lIPhUD4yp+',
  167.                 'mailtype'  => 'html',
  168.                 'charset'   => 'iso-8859-1'
  169.         );
  170.  
  171.  
  172.             $this->load->library('email', $config);
  173.             $this->email->set_newline("\r\n");  
  174.    
  175.    
  176.         $data['email'] = $to_email;
  177.        
  178.        
  179.         $data['key'] = $key;
  180.         $view = $this->load->view('template_email_lupa', $data, true);
  181.         $this->email->from('arminareka19@gmail.com', 'Admin Arminareka');
  182.         $this->email->to($to_email);
  183.         $this->email->subject('Lupa Password Arminareka Perdana');
  184.         $this->email->message($view);
  185.         $this->email->send();
  186.          echo json_encode(array('status' => 1));
  187.         } else {
  188.             echo json_encode(array('status' => 0));
  189.         }
  190.     }
  191.    
  192.     public function daftar_keberangkatan()
  193.     {
  194.  
  195.         if (in_array(null, $_POST['nik']))
  196.         {
  197.             $data['status'] = 500;
  198.             $data['msg_error'] = 'Lengkapi form !!';
  199.             echo json_encode($data);
  200.             return false;
  201.         }
  202.  
  203.         if (in_array(null, $_POST['nama_pendaftar']))
  204.         {
  205.             $data['status'] = 500;
  206.             $data['msg_error'] = 'Lengkapi form !!';
  207.             echo json_encode($data);
  208.             return false;
  209.         }
  210.  
  211.         if (in_array(null, $_POST['jenis_kelamin']))
  212.         {
  213.             $data['status'] = 500;
  214.             $data['msg_error'] = 'Lengkapi form !!';
  215.             echo json_encode($data);
  216.             return false;
  217.         }
  218.  
  219.        
  220.             $paket = $this->db->get_where('paket', array('id_paket' => $this->input->post('id_paket')))->row_array();
  221.             $a = strtolower($this->input->post('jns_kamar'));
  222.             $p_kmr = 'harga_'.str_replace(' ', '_', $a);
  223.             $harga = $paket[$p_kmr];
  224.  
  225.            
  226.            
  227.             $field['kode_daftar'] = generate_kode_daftar($this->input->post('id_paket'));
  228.             $field['id_customer'] = $this->input->post('id_customer');
  229.             $field['id_paket'] = $this->input->post('id_paket');
  230.             $field['pilihan_kamar'] = $this->input->post('jns_kamar');
  231.             $field['tgl_daftar'] = date('Y-m-d');
  232.             $field['no_handphone'] = $this->input->post('no_handphone');
  233.             $field['total_harga'] = $harga * count($this->input->post('nik'));
  234.             if(get_nama_paket($this->input->post('id_paket')) != 'HAJI') {
  235.                 $field['tahun_keberangkatan'] = $this->input->post('tahun_keberangkatan');
  236.                 $field['bulan_keberangkatan'] = strtoupper($this->input->post('bulan_keberangkatan'));
  237.             }
  238.  
  239.             /*
  240.             $field['id_paket'] = $this->input->post('id_paket');
  241.             $field['pilihan_kamar'] = $this->input->post('jns_kamar');
  242.             $field['total_harga'] = $harga ;
  243.             $field['nama_pendaftar'] = $this->input->post('nama_pendaftar');
  244.             $field['no_handphone'] = $this->input->post('no_handphone');
  245.             $field['alamat_lengkap'] = $this->input->post('alamat_lengkap');
  246.             $field['jenis_kelamin'] = $this->input->post('jenis_kelamin');
  247.             $field['tanggal_lahir'] = date_y_m_d($this->input->post('tanggal_lahir'));
  248.             $field['kota'] = $this->input->post('kota');
  249.             $field['kode_pos'] = $this->input->post('kode_pos');
  250.             $field['tanggal'] = date('Y-m-d');
  251.             if($rowxx['kategori'] != 'HAJI') {
  252.                 $field['tahun_keberangkatan'] = $this->input->post('tahun_keberangkatan');
  253.                 $field['bulan_keberangkatan'] = $this->input->post('bulan_keberangkatan');
  254.             }
  255.             */
  256.  
  257.            
  258.            
  259.             $this->db->insert('pendaftaran', $field);
  260.  
  261.             $nik = $this->input->post('nik');
  262.             $nama_jamaah = $this->input->post('nama_pendaftar');
  263.             $jenis_kelamin = $this->input->post('jenis_kelamin');
  264.             //$no_handphone = $this->input->post('no_handphone');
  265.             //$umur = $this->input->post('umur');
  266.            
  267.             $pakets = $this->db->get_where('paket', array('id_paket' => $this->input->post('id_paket')))->row_array();
  268.             $kode_jamaah = $pakets['kode'];
  269.            
  270.             $result = array();
  271.             foreach ($nik as $id => $key) {
  272.             $result[$key] = array(
  273.                 'id_pendaftaran'  => $this->db->insert_id(),
  274.                 'kode_jamaah'     => generate_kode_jamaah($this->input->post('id_paket')),
  275.                 'nama_jamaah' => $nama_jamaah[$id],
  276.                 'nik'    => $nik[$id],
  277.                 'jenis_kelamin'    => $jenis_kelamin[$id],
  278.                
  279.                
  280.             );
  281.  
  282.             $this->db->insert('pendaftaran_detail',  $result[$key]);
  283.  
  284.             }
  285.  
  286.         $last_ids = $this->db->query("SELECT id_pendaftaran FROM pendaftaran ORDER BY id_pendaftaran DESC LIMIT 1")->row_array();
  287.         $id_pendaftaran = $last_ids['id_pendaftaran'];
  288.         $data['id_pendaftaran'] = $id_pendaftaran;
  289.         $html = $this->load->view('pendaftaran/generate_pdf', $data, TRUE);
  290.         $this->load->library('dompdf_gen');
  291.         $this->dompdf->load_html($html);
  292.         $this->dompdf->render();
  293.         file_put_contents('./pdf/bukti_pendaftaran.pdf', $this->dompdf->output());
  294.         chmod('./pdf/bukti_pendaftaran.pdf', 0777);
  295.         $from_email = "arminareka19@gmail.com";
  296.         $to_email = get_email_customer($this->input->post('id_customer'));
  297.        
  298.        
  299.  
  300.    
  301.            
  302.    
  303. $config = Array(
  304.                 'protocol' => 'smtp',
  305.                 'charset'=>'utf-8',
  306.                 'smtp_host' => 'ssl://mail.7setiawan.com',
  307.                 'smtp_port' => 465,
  308.                 'smtp_user' => 'info@7setiawan.com',
  309.                 'smtp_pass' => '~{lIPhUD4yp+',
  310.                 'mailtype'  => 'html',
  311.                 'charset'   => 'iso-8859-1'
  312.         );
  313.  
  314.  
  315.             $this->load->library('email', $config);
  316.             $this->email->set_newline("\r\n");  
  317.    
  318.    
  319.         $data['nama'] = "GGWP";
  320.         $data['id_pendaftaran'] = $id_pendaftaran;
  321.         $view = $this->load->view('template_email_daftar', $data, true);
  322.         $this->email->from($from_email, 'Admin Arminareka');
  323.         $this->email->to($to_email);
  324.         $this->email->subject('Arminareka Perdana');
  325.         $this->email->message($view);
  326.         $this->email->attach('./pdf/bukti_pendaftaran.pdf');
  327.         $this->email->send();
  328.        
  329.  
  330.             echo json_encode(array('status' => 200));
  331.     }
  332.  
  333.     public function get_paket_umroh()
  334.     {
  335.         $data['record'] = $this->db->get_where('paket', array('kategori' => 'UMROH'))->result_array();
  336.         $this->load->view('api/get_paket_umroh', $data);
  337.     }
  338.  
  339.     public function get_paket_haji()
  340.     {
  341.         $data['record'] = $this->db->get_where('paket', array('kategori' => 'HAJI'))->result_array();
  342.         $this->load->view('api/get_paket_haji', $data);
  343.     }
  344.  
  345.     public function get_detail_paket_umroh($id_paket)
  346.     {
  347.         $data['row'] = $this->db->get_where('paket', array('id_paket' => $id_paket))->row_array();
  348.         $this->load->view('api/get_detail_paket_umroh', $data);
  349.     }
  350.  
  351.     public function sample()
  352.     {
  353.         $array = array('test','test2', 'test3');
  354.         echo json_encode($array);
  355.         //$this->load->view('api/get_detail_paket_umroh', $data);
  356.     }
  357.  
  358. }
  359.  
  360. /* End of file Api.php */
  361. /* Location: ./application/controllers/Api.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement