Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Api extends CI_Controller {
- public function __construct()
- {
- parent::__construct();
- }
- public function index()
- {
- }
- public function login()
- {
- $this->form_validation->set_rules('username', 'Username', 'required');
- $this->form_validation->set_rules('password', 'Password', 'required');
- if ($this->form_validation->run() == FALSE) {
- echo json_encode(array('status'=>500,
- 'username' => form_error('username'),
- 'password' => form_error('password')
- ));
- } else {
- $username = $this->input->post('username');
- $password = $this->input->post('password');
- $auth = $this->db->get_where('customer', array('username' => $username, 'password' => $password));
- if($auth->num_rows() > 0) {
- $row = $auth->row_array();
- $res = array('status' => 200, 'username' => $row['username'], 'id_customer' => $row['id_customer']);
- echo json_encode($res);
- } else {
- $res = array('status' => 404);
- echo json_encode($res);
- }
- }
- }
- public function register()
- {
- $this->form_validation->set_rules('nama', 'Nama', 'required');
- $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
- $this->form_validation->set_rules('username', 'Username', 'required');
- $this->form_validation->set_rules('password', 'Password', 'required');
- if ($this->form_validation->run() == FALSE) {
- echo json_encode(array('status'=>500,
- 'nama' => form_error('nama'),
- 'email' => form_error('email'),
- 'username' => form_error('username'),
- 'password' => form_error('password')
- ));
- } else {
- $field['nama'] = $this->input->post('nama');
- $field['email'] = $this->input->post('email');
- $field['username'] = $this->input->post('username');
- $field['password'] = $this->input->post('password');
- $field['tgl_daftar'] = date('Y-m-d');
- $this->db->insert('customer', $field);
- echo json_encode(array('status' => 200));
- }
- }
- public function pilih_paket()
- {
- $id_paket = $this->input->post('id_paket');
- $row = $this->db->get_where('paket', array('id_paket' => $id_paket))->row_array();
- echo json_encode(array('id_paket' => $row['id_paket'], 'nama_paket' => $row['nama_paket']));
- }
- public function status_informasi()
- {
- $id_customer = $this->input->post('id_customer');
- $res = $this->db->get_where('pendaftaran', array('id_customer' => $id_customer));
- if($res->num_rows() > 0) {
- $table = 'Untuk melengkapi dokumen dan administrasi silahkan datang ke kantor kami.<hr>';
- $table .= '<div class="data-table">';
- $table .= '<table id="tbl-pendaftaran">';
- $table .= "<tr>";
- $table .= "<td><b>Kode Daftar</b></td>";
- $table .= "<td><b>Tgl.Daftar</b></td>";
- $table .= "<tr>";
- foreach ($res->result_array() as $row) {
- if($row['status'] == 0) {
- $status = "<span class='label label-danger'>No</span>";
- } else {
- $status = "<span class='label label-danger'>Yes</span>";
- }
- $table .= "<tr id=".$row['kode'].">";
- $table .= "<td><a class='status-pendaftaran' id=".$row['kode']." href='/detail_pendaftaran/'>".$row['kode']."</a></td>";
- $table .= "<td>".date_d_m_y($row['tanggal'])."</td>";
- $table .= "</tr>";
- }
- $table .= "</table>";
- $table .= "</div>";
- echo json_encode($table);
- } else {
- echo json_encode(0);
- }
- }
- public function get_detail_pendaftaran()
- {
- $id_pendaftaran = $this->input->post('id_pendaftaran');
- $this->db->join('paket', 'pendaftaran.id_paket = paket.id_paket');
- $this->db->join('customer', 'customer.id_customer = pendaftaran.id_customer');
- $data['row'] = $this->db->get_where('pendaftaran', array('pendaftaran.id_pendaftaran' => $id_pendaftaran))->row_array();
- $this->load->view('detail_pendaftaran', $data);
- }
- public function list_daftar()
- {
- $id_customer = $this->input->post('id_customer');
- $this->db->join('paket', 'pendaftaran.id_paket = paket.id_paket');
- $this->db->join('customer', 'customer.id_customer = pendaftaran.id_customer');
- $data['row'] = $this->db->get_where('pendaftaran', array('pendaftaran.id_customer' => $id_customer))->row_array();
- $data['customer'] = $this->db->get_where('customer', array('id_customer' => $id_customer))->row_array();
- $this->load->view('list_pendaftaran', $data);
- }
- public function form_paket()
- {
- $data['id_paket'] = $this->input->post('id_paket');
- $data['id_customer'] = $this->input->post('id_customer');
- $data['nama_paket'] = get_nama_paket($this->input->post('id_paket'));
- $data['kategori'] = get_nama_kategori($this->input->post('id_paket'));
- $data['jenis_kamar'] = $this->input->post('jenis_kamar');
- $this->load->view('api/form_paket', $data);
- }
- public function get_paket_harga()
- {
- $id = $this->input->post('id_paket');
- $row = $this->db->get_where('paket', array('id_paket' => $id))->row_array();
- echo json_encode(array(
- 'sekamar_ber4' => rupiah($row['harga_sekamar_ber_4']),
- 'sekamar_ber3' => rupiah($row['harga_sekamar_ber_3']),
- 'sekamar_ber2' => rupiah($row['harga_sekamar_ber_2']),
- )
- );
- }
- public function lupa_password()
- {
- $to_email = $this->input->post('email');
- $check = $this->db->get_where('customer', array('email' => $to_email))->row_array();
- if($check) {
- $key = md5(date("Y-m-d h:i:sa"));
- $updt['forgot_password'] = $key;
- $wherex['email'] = $to_email;
- $this->db->update('customer', $updt, $wherex);
- $config = Array(
- 'protocol' => 'smtp',
- 'charset'=>'utf-8',
- 'smtp_host' => 'ssl://mail.7setiawan.com',
- 'smtp_port' => 465,
- 'smtp_user' => 'info@7setiawan.com',
- 'smtp_pass' => '~{lIPhUD4yp+',
- 'mailtype' => 'html',
- 'charset' => 'iso-8859-1'
- );
- $this->load->library('email', $config);
- $this->email->set_newline("\r\n");
- $data['email'] = $to_email;
- $data['key'] = $key;
- $view = $this->load->view('template_email_lupa', $data, true);
- $this->email->from('arminareka19@gmail.com', 'Admin Arminareka');
- $this->email->to($to_email);
- $this->email->subject('Lupa Password Arminareka Perdana');
- $this->email->message($view);
- $this->email->send();
- echo json_encode(array('status' => 1));
- } else {
- echo json_encode(array('status' => 0));
- }
- }
- public function daftar_keberangkatan()
- {
- if (in_array(null, $_POST['nik']))
- {
- $data['status'] = 500;
- $data['msg_error'] = 'Lengkapi form !!';
- echo json_encode($data);
- return false;
- }
- if (in_array(null, $_POST['nama_pendaftar']))
- {
- $data['status'] = 500;
- $data['msg_error'] = 'Lengkapi form !!';
- echo json_encode($data);
- return false;
- }
- if (in_array(null, $_POST['jenis_kelamin']))
- {
- $data['status'] = 500;
- $data['msg_error'] = 'Lengkapi form !!';
- echo json_encode($data);
- return false;
- }
- $paket = $this->db->get_where('paket', array('id_paket' => $this->input->post('id_paket')))->row_array();
- $a = strtolower($this->input->post('jns_kamar'));
- $p_kmr = 'harga_'.str_replace(' ', '_', $a);
- $harga = $paket[$p_kmr];
- $field['kode_daftar'] = generate_kode_daftar($this->input->post('id_paket'));
- $field['id_customer'] = $this->input->post('id_customer');
- $field['id_paket'] = $this->input->post('id_paket');
- $field['pilihan_kamar'] = $this->input->post('jns_kamar');
- $field['tgl_daftar'] = date('Y-m-d');
- $field['no_handphone'] = $this->input->post('no_handphone');
- $field['total_harga'] = $harga * count($this->input->post('nik'));
- if(get_nama_paket($this->input->post('id_paket')) != 'HAJI') {
- $field['tahun_keberangkatan'] = $this->input->post('tahun_keberangkatan');
- $field['bulan_keberangkatan'] = strtoupper($this->input->post('bulan_keberangkatan'));
- }
- /*
- $field['id_paket'] = $this->input->post('id_paket');
- $field['pilihan_kamar'] = $this->input->post('jns_kamar');
- $field['total_harga'] = $harga ;
- $field['nama_pendaftar'] = $this->input->post('nama_pendaftar');
- $field['no_handphone'] = $this->input->post('no_handphone');
- $field['alamat_lengkap'] = $this->input->post('alamat_lengkap');
- $field['jenis_kelamin'] = $this->input->post('jenis_kelamin');
- $field['tanggal_lahir'] = date_y_m_d($this->input->post('tanggal_lahir'));
- $field['kota'] = $this->input->post('kota');
- $field['kode_pos'] = $this->input->post('kode_pos');
- $field['tanggal'] = date('Y-m-d');
- if($rowxx['kategori'] != 'HAJI') {
- $field['tahun_keberangkatan'] = $this->input->post('tahun_keberangkatan');
- $field['bulan_keberangkatan'] = $this->input->post('bulan_keberangkatan');
- }
- */
- $this->db->insert('pendaftaran', $field);
- $nik = $this->input->post('nik');
- $nama_jamaah = $this->input->post('nama_pendaftar');
- $jenis_kelamin = $this->input->post('jenis_kelamin');
- //$no_handphone = $this->input->post('no_handphone');
- //$umur = $this->input->post('umur');
- $pakets = $this->db->get_where('paket', array('id_paket' => $this->input->post('id_paket')))->row_array();
- $kode_jamaah = $pakets['kode'];
- $result = array();
- foreach ($nik as $id => $key) {
- $result[$key] = array(
- 'id_pendaftaran' => $this->db->insert_id(),
- 'kode_jamaah' => generate_kode_jamaah($this->input->post('id_paket')),
- 'nama_jamaah' => $nama_jamaah[$id],
- 'nik' => $nik[$id],
- 'jenis_kelamin' => $jenis_kelamin[$id],
- );
- $this->db->insert('pendaftaran_detail', $result[$key]);
- }
- $last_ids = $this->db->query("SELECT id_pendaftaran FROM pendaftaran ORDER BY id_pendaftaran DESC LIMIT 1")->row_array();
- $id_pendaftaran = $last_ids['id_pendaftaran'];
- $data['id_pendaftaran'] = $id_pendaftaran;
- $html = $this->load->view('pendaftaran/generate_pdf', $data, TRUE);
- $this->load->library('dompdf_gen');
- $this->dompdf->load_html($html);
- $this->dompdf->render();
- file_put_contents('./pdf/bukti_pendaftaran.pdf', $this->dompdf->output());
- chmod('./pdf/bukti_pendaftaran.pdf', 0777);
- $from_email = "arminareka19@gmail.com";
- $to_email = get_email_customer($this->input->post('id_customer'));
- $config = Array(
- 'protocol' => 'smtp',
- 'charset'=>'utf-8',
- 'smtp_host' => 'ssl://mail.7setiawan.com',
- 'smtp_port' => 465,
- 'smtp_user' => 'info@7setiawan.com',
- 'smtp_pass' => '~{lIPhUD4yp+',
- 'mailtype' => 'html',
- 'charset' => 'iso-8859-1'
- );
- $this->load->library('email', $config);
- $this->email->set_newline("\r\n");
- $data['nama'] = "GGWP";
- $data['id_pendaftaran'] = $id_pendaftaran;
- $view = $this->load->view('template_email_daftar', $data, true);
- $this->email->from($from_email, 'Admin Arminareka');
- $this->email->to($to_email);
- $this->email->subject('Arminareka Perdana');
- $this->email->message($view);
- $this->email->attach('./pdf/bukti_pendaftaran.pdf');
- $this->email->send();
- echo json_encode(array('status' => 200));
- }
- public function get_paket_umroh()
- {
- $data['record'] = $this->db->get_where('paket', array('kategori' => 'UMROH'))->result_array();
- $this->load->view('api/get_paket_umroh', $data);
- }
- public function get_paket_haji()
- {
- $data['record'] = $this->db->get_where('paket', array('kategori' => 'HAJI'))->result_array();
- $this->load->view('api/get_paket_haji', $data);
- }
- public function get_detail_paket_umroh($id_paket)
- {
- $data['row'] = $this->db->get_where('paket', array('id_paket' => $id_paket))->row_array();
- $this->load->view('api/get_detail_paket_umroh', $data);
- }
- public function sample()
- {
- $array = array('test','test2', 'test3');
- echo json_encode($array);
- //$this->load->view('api/get_detail_paket_umroh', $data);
- }
- }
- /* End of file Api.php */
- /* Location: ./application/controllers/Api.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement