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 Administrator extends CI_Controller
- {
- public function __construct ()
- {
- parent::__construct();
- //Codeigniter : Write Less Do More
- $this->is_logged_in();
- $this->load->library(array('upload'));
- }
- public function is_logged_in ()
- {
- $sess = $this->session->userdata('logged_in');
- $level = $this->session->userdata('level');
- if ($sess != true || $level != 'admin') {
- $this->session->set_flashdata('not_login', 'Anda harus login!');
- redirect('welcome/form_login');
- }
- }
- public function dashboard ()
- {
- $data['title'] = 'Admin Pages';
- $this->load->view('admin/v_home', $data);
- }
- // manajemen meja
- public function meja ()
- {
- $getmeja = $this->crud_model->get_db('meja');
- if ($getmeja->num_rows() > 0) {
- $data['data'] = $getmeja;
- }
- $data['title'] = 'Admin Pages';
- $this->load->view('admin/v_data_meja', $data);
- }
- public function add_meja ()
- {
- $no_max = $this->crud_model->getNoMax('meja', 'nomor_meja');
- if ($no_max->num_rows() > 0) {
- foreach ($no_max->result() as $key) {
- $data['nomor_meja'] = $key->nomor_meja;
- }
- }
- $data['title'] = 'Admin Pages';
- $this->load->view('admin/v_form_add_meja', $data);
- }
- public function validation_add_table ()
- {
- // validation
- $config = array(
- // username
- array(
- 'field' => 'nomor_table',
- 'label' => 'Nomor',
- 'rules' => 'trim|required'
- ),
- array(
- 'field' => 'kapasitas',
- 'label' => 'Kapasitas Kursi',
- 'rules' => 'trim|required|max_length[2]'
- )
- );
- $this->form_validation->set_rules($config);
- if ($this->form_validation->run() == false) {
- $this->add_meja();
- } else {
- // ambil value form
- $data = array(
- 'nomor_meja' => $this->input->post('nomor_table'),
- 'kapasitas' => $this->input->post('kapasitas')
- );
- $insert = $this->crud_model->insert_db('meja', $data);
- if ($insert) {
- // flash success
- $this->session->set_flashdata('successfull', 'Tambah Data Berhasil!');
- redirect('pages/administrator/meja');
- }
- }
- }
- public function edit_meja ($id)
- {
- $model = $this->crud_model->get_update('meja', array('nomor_meja' => $id), 1);
- if ($model->num_rows() > 0) {
- foreach ($model->result() as $key) {
- $data['result'] = $key;
- }
- }
- $data['title'] = 'Pages Admin';
- $this->load->view('admin/v_edit_meja', $data);
- }
- // edit meja
- public function validation_edit_table ()
- {
- // validation
- $config = array(
- // username
- array(
- 'field' => 'nomor_meja',
- 'label' => 'Nomor Meja',
- 'rules' => 'trim|required'
- ),
- array(
- 'field' => 'kapasitas',
- 'label' => 'Kapasitas Kursi',
- 'rules' => 'trim|required|max_length[2]'
- )
- );
- $this->form_validation->set_rules($config);
- $id = $this->input->post('nmr_meja');
- if ($this->form_validation->run() == false) {
- $this->edit_meja($id);
- } else {
- // lolos validasi
- $data = array(
- 'nomor_meja' => $this->input->post('nomor_meja'),
- 'kapasitas' => $this->input->post('kapasitas')
- );
- $where = array('nomor_meja' => $id);
- // update ke database
- $update = $this->crud_model->set_update('meja', $data, $where);
- if ($update) {
- $this->session->set_flashdata('successfull', 'Update Data Berhasil');
- redirect('pages/administrator/meja');
- }
- }
- }
- public function delete_meja ($id)
- {
- $delete = $this->crud_model->delete('meja', array('nomor_meja' => $id));
- if ($delete) {
- $this->session->set_flashdata('successfull', 'Data berhasil di hapus!');
- redirect('pages/administrator/meja');
- }
- }
- // manajemen menu
- public function menu ($data = array())
- {
- $getmenu = $this->crud_model->get_db('menu');
- if ($getmenu->num_rows() > 0) {
- $data['data'] = $getmenu;
- }
- $data['title'] = 'Admin Pages';
- $this->load->view('admin/v_data_menu', $data);
- }
- public function add_menu ()
- {
- // ambil nomor id menu terakhir
- $no_max = $this->crud_model->getNoMax('menu', 'id_menu');
- foreach ($no_max->result() as $key => $value) {
- if ($value->id_menu != null) {
- $id = substr($value->id_menu, 2, 2);
- $id++;
- if ($id < 10) {
- $kode = 'NU0' . $id;
- } else {
- $kode = 'NU' . $id;
- }
- $data['last_id'] = $kode;
- } else {
- $data['last_id'] = "NU01";
- }
- }
- $data['title'] = 'Admin Pages';
- $this->load->view('admin/v_form_add_menu', $data);
- }
- public function do_upload ()
- {
- // mengambil ekstensi file
- $ext = pathinfo($_FILES['upload_menu']['name']);
- $ext = $ext['extension'];
- // sett conf upload image
- $filename = 'menu_' . time();
- $conf_upload = array(
- 'upload_path' => 'assets/upload/images_menu/',
- 'allowed_types' => 'jpg|png',
- 'max_size' => 2048,
- 'max_height' => 1200,
- 'max_width' => 675,
- 'file_name' => $filename,
- 'file_ext' => $ext
- );
- // validation form
- $config = array(
- // kode nomor
- array(
- 'field' => 'kd_menu',
- 'label' => 'Kode Menu',
- 'rules' => 'trim|required|min_length[4]|max_length[4]'
- ),
- // nama menu makanan
- array(
- 'field' => 'nama_menu',
- 'label' => 'Nama Menu',
- 'rules' => 'required'
- ),
- // harga
- array(
- 'field' => 'harga_menu',
- 'label' => 'Harga',
- 'rules' => 'trim|required|numeric|regex_match[/^[0-9]/]'
- ),
- // keterangan
- array(
- 'field' => 'keterangan',
- 'label' => 'Keterangan',
- 'rules' => 'trim|required'
- )
- );
- $this->upload->initialize($conf_upload);
- $this->form_validation->set_rules($config);
- if ($this->form_validation->run() == false || $this->upload->do_upload('upload_menu') == false) {
- $data = array('error' => $this->upload->display_errors());
- $this->add_menu($data);
- } else {
- // lulus validasi
- $path_images = $conf_upload['upload_path'];
- $path_images .= $conf_upload['file_name'];
- $path_images .= '.' . $conf_upload['file_ext'];
- // resize images
- // $conf_resize = array (
- // 'image_library' => 'gd2',
- // 'source_image' => $this->upload->upload_path.$this->upload->file_name,
- // 'create_thumb' => true,
- // 'maintain_ratio' => true,
- // 'width' => 100,
- // 'height' => 100
- // );
- //
- // // load library image_lib
- // $this->load->library('image_lib', $conf_resize);
- // $resize = $this->image_lib->resize();
- // ambil value form
- $data = array(
- 'id_menu' => $this->input->post('kd_menu'),
- 'nama_menu' => $this->input->post('nama_menu'),
- 'harga_menu' => $this->input->post('harga_menu'),
- 'path_images' => $path_images,
- 'keterangan' => $this->input->post('keterangan')
- );
- // insert ke database
- $insert = $this->crud_model->insert_db('menu', $data);
- if ($insert) {
- // flash success
- $this->session->set_flashdata('successfull', 'Tambah Data Berhasil!');
- redirect('pages/administrator/menu');
- }
- }
- }
- public function delete_menu ($id)
- {
- $delete = $this->crud_model->delete('menu', array('id_menu' => $id));
- if ($delete) {
- $this->session->set_flashdata('successfull', 'Data berhasil di hapus!');
- redirect('pages/administrator/menu');
- }
- }
- /* Crud Admin */
- public function data_admin ()
- {
- $get_data = $this->crud_model->join_db('admin', '*', 'user', 'admin.username=user.username');
- if ($get_data->num_rows() > 0) {
- $data['data'] = $get_data;
- }
- $data['title'] = 'Admin Pages';
- $this->load->view('admin/v_data_admin', $data);
- }
- public function add_user ($level)
- {
- $data['title'] = 'Admin Pages';
- $data['level'] = $level;
- $this->load->view('admin/v_form_add_user', $data);
- }
- // validation form user (admin && pemilik)
- public function validation_user ()
- {
- // rules
- $rules = array(
- array(
- 'field' => 'username',
- 'label' => 'username',
- //'rules'=>'trim|required|is_unique[user.username]',
- 'rules' => 'callback_username_check'
- ),
- array(
- 'field' => 'password',
- 'label' => 'password',
- 'rules' => 'trim|required|min_length[8]'
- ),
- array(
- 'field' => 'confirmPassword',
- 'label' => 'confirmPassword',
- 'rules' => 'trim|required|matches[password]'
- ),
- array(
- 'field' => 'fullname',
- 'label' => 'fullname',
- 'rules' => 'required'
- ),
- array(
- 'field' => 'email',
- 'label' => 'email',
- 'rules' => 'trim|required|valid_email'
- ),
- array(
- 'field' => 'alamat',
- 'label' => 'alamat',
- 'rules' => 'required'
- )
- );
- $this->form_validation->set_rules($rules);
- $level = $this->input->post('level');
- if ($this->form_validation->run() == false) {
- $this->add_user($level);
- } else {
- // lolos validasi
- # ambil nilai dari form
- $username = $this->input->post('username');
- $password = $this->input->post('password');
- $table_user = array(
- 'username' => $username,
- 'password' => password_hash($password, PASSWORD_DEFAULT),
- 'level' => $level
- );
- $table_data = array(
- 'username' => $username,
- 'password' => password_hash($password, PASSWORD_DEFAULT),
- 'fullname' => $this->input->post('fullname'),
- 'email' => $this->input->post('email'),
- 'alamat' => $this->input->post('alamat')
- );
- // panggil db_insert
- $this->crud_model->insert_db('user', $table_user);
- $insert = $this->crud_model->insert_db($level, $table_data);
- if ($insert) {
- $this->session->set_flashdata('successfull', 'Data berhasil ditambahkan!');
- redirect('pages/administrator/data_' . $level);
- }
- }
- }
- public function edit_user ($table, $id)
- {
- $get_where = $this->crud_model->get_db_where($table, array('id_' . $table => $id));
- $get = $get_where;
- if ($get->num_rows() > 0) {
- foreach ($get->result() as $key) {
- $data['user'] = $key;
- $data['table'] = $table;
- }
- } else {
- $data = 'No data is available';
- }
- $data['title'] = 'Pages Admin';
- $this->load->view('admin/v_form_edit_user', $data);
- }
- public function validation_update ()
- {
- $table = $this->input->post('level');
- $id = $this->input->post('id');
- // set rules
- $config = array(
- // username
- array(
- 'field' => 'username',
- 'label' => 'Username',
- 'rules' => 'trim|required'
- ),
- array(
- 'field' => 'fullname',
- 'label' => 'Nama Lengkap',
- 'rules' => 'required'
- ),
- array(
- 'field' => 'email',
- 'label' => 'Email',
- 'rules' => 'trim|required'
- ),
- array(
- 'field' => 'alamat',
- 'label' => 'Alamat',
- 'rules' => 'required'
- )
- );
- $this->form_validation->set_rules($config);
- if ($this->form_validation->run() == false) {
- // gagal validasi
- $this->edit_user($table, $id);
- } else {
- // lulus validasi
- $data = array(
- 'username' => $this->input->post('username'),
- 'fullname' => $this->input->post('fullname'),
- 'alamat' => $this->input->post('alamat'),
- 'email' => $this->input->post('email')
- );
- $where = array($table, 'id_' . $table => $id);
- $update = $this->crud_model->set_update($table, $data, $where);
- if ($update) {
- // update berhasil
- $this->session->set_flashdata('successfull', 'Update data berhasil');
- redirect('pages/administrator/data_' . $table);
- }
- }
- }
- public function username_check ($username)
- {
- $get = $this->crud_model->get_db_where('user', array('username' => $username));
- foreach ($get->result() as $key) {
- $user = $key->username;
- if ($user == $username) {
- $this->form_validation->set_message('username_check', '{field} sudah digunakan. Silahkan coba yang lain');
- return false;
- } else {
- return true;
- }
- }
- }
- # crud pemilik
- public function data_pemilik ()
- {
- $getdb = $this->crud_model->join_db('user', '*', 'pemilik', 'user.username=pemilik.username');
- $data['data'] = $getdb;
- $data['title'] = 'Pages Admin';
- $this->load->view('admin/v_data_pemilik', $data);
- }
- # crud pelanggan
- public function data_pelanggan ()
- {
- $get_data = $this->crud_model->join_db('pelanggan', '*', 'user', 'pelanggan.username=user.username');
- if ($get_data->num_rows() > 0) {
- $data['data'] = $get_data;
- }
- $data['title'] = 'Admin Pages';
- $this->load->view('admin/v_data_pelanggan', $data);
- }
- # crud data pelayan
- public function data_pelayan ()
- {
- $get = $this->crud_model->join_db('user', '*', 'pelayan', 'user.username=pelayan.username');
- $data['data'] = $get;
- $data['title'] = 'Pages Admin';
- $this->load->view('admin/v_data_pelayan', $data);
- }
- public function add_pelayan ()
- {
- // ambil ID terakhir
- $max_id = $this->crud_model->getNoMax('pelayan', 'id_pelayan');
- foreach ($max_id->result() as $key => $value) {
- if (!empty($value)) {
- $id = substr($value->id_pelayan, 1, 2);
- $id++;
- if ($id < 10) {
- $id = "P0" . $id;
- } else {
- $id = "P" . $id;
- }
- $data['id_pelayan'] = $id;
- } else {
- $data['id_pelayan'] = 'P01';
- }
- }
- $data['title'] = 'Pages Admin';
- $this->load->view('admin/v_form_add_pelayan', $data);
- }
- public function validation_pelayan ()
- {
- $id_pelayan = $this->input->post('id');
- //validasi form
- $rules = array(
- // username
- array(
- 'field' => 'username',
- 'label' => 'Username',
- 'rules' => 'trim|required|is_unique[user.username]',
- array('rule3' => 'username sudah digunakan.')
- //'rules'=>'callback_username_check'
- ),
- // password
- array(
- 'field' => 'password',
- 'label' => 'Password',
- 'rules' => 'required|min_length[8]'
- ),
- // password confirm
- array(
- 'field' => 'confirmPassword',
- 'label' => 'Konfirmasi Password',
- 'rules' => 'required|matches[password]'
- ),
- // nama pelayan
- array(
- 'field' => 'nama_pelayan',
- 'label' => 'Nama Pelayan',
- 'rules' => 'required'
- ),
- // nomor telepon
- array(
- 'field' => 'no_tlp',
- 'label' => 'Nomor Telepon',
- 'rules' => 'trim|required|min_length[12]|max_length[15]'
- ),
- // alamat
- array(
- 'field' => 'alamat',
- 'label' => 'Alamat',
- 'rules' => 'required'
- )
- );
- $role = $this->form_validation->set_rules($rules);
- $this->form_validation->set_message('is_unique', '{field} sudah digunakan. Silahkan ganti yang lain');
- if ($this->form_validation->run() == false) {
- $this->add_pelayan();
- } else {
- //lolos validasi
- $data = array(
- 'id_pelayan' => $id_pelayan,
- 'username' => $this->input->post('username'),
- 'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT),
- 'nama_pelayan' => $this->input->post('nama_pelayan'),
- 'alamat' => $this->input->post('alamat'),
- 'no_telepon_pelayan' => $this->input->post('no_tlp')
- );
- $data_user = array(
- 'username' => $this->input->post('username'),
- 'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT),
- 'level' => 'pelayan'
- );
- $insert_user = $this->crud_model->insert_db('user', $data_user);
- if ($insert_user == true) {
- // insert ke table pelayan
- $insert = $this->crud_model->insert_db('pelayan', $data);
- if ($insert) {
- $this->session->set_flashdata('successfull', 'Data berhasil ditambahkan!');
- redirect('pages/administrator/data_pelayan');
- }
- }
- }
- }
- public function edit_pelayan ($id)
- {
- $get = $this->crud_model->get_update('pelayan', array('id_pelayan' => $id));
- if (!empty($get)) {
- foreach ($get->result() as $v) {
- $data['table'] = $v;
- }
- }
- $data['title'] = 'Pages Admin';
- $this->load->view('admin/v_form_edit_pelayan', $data);
- }
- public function validation_editpelayan ()
- {
- // ambil nilai id pelayan
- $id = $this->input->post('id');
- $oldusername = $this->input->post('olduser');
- $rules = array(
- array(
- 'field' => 'username',
- 'label' => 'Username',
- 'rules' => 'trim|required'
- ),
- array(
- 'field' => 'nama_pelayan',
- 'label' => 'Nama Pelayan',
- 'rules' => 'required'
- ),
- array(
- 'field' => 'no_tlp',
- 'label' => 'Nomor Telepon',
- 'rules' => 'trim|required|min_length[11]|max_length[15]'
- ),
- array(
- 'label' => 'Alamat',
- 'field' => 'alamat',
- 'rules' => 'required'
- )
- );
- $this->form_validation->set_rules($rules);
- if ($this->form_validation->run() == false) {
- $this->edit_pelayan($id);
- } else {
- $data = array(
- 'username' => $this->input->post('username'),
- 'nama_pelayan' => $this->input->post('nama_pelayan'),
- 'alamat' => $this->input->post('alamat'),
- 'no_telepon_pelayan' => $this->input->post('no_tlp')
- );
- $where = array('id_pelayan' => $id);
- $user = array('username' => $oldusername);
- $update = $this->crud_model->set_update('user', array('username' => $this->input->post('username')), $user);
- $updatte = $this->crud_model->set_update('pelayan', $data, $where);
- if ($update == true && $updatte == true) {
- $this->session->set_flashdata('successfull', 'Update data berhasil!');
- redirect('pages/administrator/data_pelayan');
- }
- }
- }
- ########################## CodeIgniter ###############################
- # Delete All Data User
- public function delete_user ($level, $id)
- {
- $uri = $this->uri->segment(4);
- $uri = explode("_", $uri);
- $uri_segment = $uri[1];
- if ($uri_segment == 'pelanggan') {
- $get = $this->crud_model->get_db_where('pelanggan', array('id_pelanggan' => $id));
- } elseif ($uri_segment == 'admin') {
- $get = $this->crud_model->get_db_where('admin', array('id_admin' => $id));
- } elseif ($uri_segment == 'pelayan') {
- $get = $this->crud_model->get_db_where('pelayan', array('id_pelayan' => $id));
- } elseif ($uri_segment == 'pemilik') {
- $get = $this->crud_model->get_db_where('pemilik', array('id_pemilik' => $id));
- } else {
- $get = '';
- }
- if (!empty($get)) {
- foreach ($get->result() as $key) {
- // ambil data username
- $username = $key->username;
- }
- }
- // delete
- $del_id = $this->crud_model->delete($uri_segment, array('id_' . $uri_segment => $id));
- $del_lv = $this->crud_model->delete('user', array('username' => $username));
- if ($del_id && $del_lv) {
- $this->session->set_flashdata('successfull', 'Data berhasil dihapus!');
- redirect('pages/administrator/data_' . $uri_segment);
- }
- }
- # kelola menu pemesanan
- public function pemesanan ()
- {
- $where = array('status_order !=' => '0');
- $getData = $this->crud_model->join_db_where('*', 'pesan', 'pelanggan', 'pesan.pelanggan_id=pelanggan.id_pelanggan', $where);
- if ($getData->num_rows() > 0) {
- $r = $getData;
- }
- $data['title'] = 'Pages Pemesanan';
- $data['data'] = $r;
- $this->load->view('admin/v_data_pemesanan', $data);
- }
- public function detail($id_pesan)
- {
- $this->detail_pemesanan($id_pesan);
- }
- public function detail_pesanan ($id_pesan)
- {
- // join pesan-booking
- $get = $this->crud_model->join_db_where('*', 'booking', 'menu', 'booking.menu_id=menu.id_menu', array('booking.pesan_id' => $id_pesan))->result();
- $select = 'pelanggan.id_pelanggan, pelanggan.nama, pelanggan.email, pelanggan.alamat, pelanggan.no_telp,';
- $select .= 'pesan.id_pesan, pesan.meja_nomor, pesan.tanggal_pesan, pesan.tanggal_booking, pesan.total_pesanan, pesan.total_biaya, pesan.status_order, pesan.keterangan';
- // data pelanggan
- $get_pelanggan = $this->crud_model->join_db_where($select, 'pesan', 'pelanggan', 'pesan.pelanggan_id = pelanggan.id_pelanggan', array('pesan.id_pesan' => $id_pesan))->result();
- // echo "<pre>";
- // var_dump($get_pelanggan);
- // echo "</pre>";
- // die();
- $data['title'] = 'Detail Transaksi';
- $data['list_menu'] = $get;
- $data['pelanggan'] = $get_pelanggan;
- $this->load->view('admin/v_pemesanan_detail', $data);
- }
- public function pembayaran($id_pesan)
- {
- // data transaksi pembayaran
- $get_pembayaran = $this->crud_model->join_db_where('*', 'pesan', 'pembayaran', 'pesan.id_pesan = pembayaran.pesan_id', array('pesan.id_pesan'=>$id_pesan))->result();
- $data['title'] = 'Pages Kasir';
- $data['data'] = $get_pembayaran;
- $this->load->view('admin/v_bukti_pembayaran', $data);
- }
- public function updatestatusorder($id_pesan)
- {
- $val = $this->input->post('updateStatusOrder');
- if (empty($val)) {
- $this->session->set_flashdata('error', 'Data tidak ditemukan');
- redirect('pages/administrator/detail_pesanan/'.$id_pesan);
- } else {
- $data['status_order'] = $val;
- $where = array('id_pesan' => $id_pesan);
- // update ke table pesan
- $updateStatusOrder = $this->crud_model->set_update('pesan', $data, $where);
- if ($updateStatusOrder) {
- $this->session->set_flashdata('successfull', 'Status Pembayaran sudah terupdate');
- //send email konfirmasi pembayaran telah diterima
- // redirect ke halaman pemesanan
- redirect('pages/administrator/detail_pesanan/' . $id_pesan);
- }
- }
- }
- public function cancel_pesanan($id_pesan)
- {
- $get = $this->crud_model->get_db_where('pesan', array('id_pesan'=>$id_pesan));
- $data = array(
- 'id_pesan' => $id_pesan,
- 'data' => $get->result()
- );
- $this->load->view('admin/cancel_order', $data);
- }
- public function process_cancel()
- {
- //set rules
- $rules = array(
- // array(
- // 'field' => 'no_pesanan',
- // 'label' => 'Nomor Pesanan',
- // 'rules' => 'trim|required|numeric'
- // ),
- array(
- 'field' => 'keterangan',
- 'label' => 'Keterangan Pesan',
- 'rules' => 'required'
- )
- );
- $this->form_validation->set_rules($rules);
- $id_pesan = $this->input->post('id_pesan');
- if ($this->form_validation->run() === false) {
- $this->session->set_flashdata('required', 'Form tidak boleh kosong!');
- $this->detail_pesanan($id_pesan);
- } else {
- $data = array(
- 'pesan_id' => $this->input->post('id_pesan'),
- 'keterangan' => $this->input->post('keterangan')
- );
- // insert ke table cancel
- $insertCancel = $this->crud_model->insert_db('cancel', $data);
- if ($insertCancel) {
- // insert cancel berhasil, update status order di table pesan
- $where = array('id_pesan'=>$id_pesan);
- $data = array(
- 'status_order' => '0',
- 'keterangan' => 'CANCEL: '.$this->input->post('keterangan')
- );
- $updateStatusOrder = $this->crud_model->set_update('pesan', $data, $where);
- if ($updateStatusOrder) {
- $this->session->set_flashdata('successfully', 'Pesanan berhasil dibatalkan');
- redirect('pages/administrator/detail_pesanan/'.$id_pesan);
- }
- } else {
- $this->session->set_flashdata('required', 'Ada kesalahan');
- $this->detail_pesanan($id_pesan);
- }
- }
- }
- public function send_mail_payment($id_pesan, $email_to)
- {
- $this->is_logged_in();
- $this->load->library('email');
- $where = array('id_pesan'=>$id_pesan);
- $get = $this->crud_model->join_db_where('*', 'pesan', 'booking', 'pesan.id_pesan=booking.pesan_id', $where, 1);
- if ($get->num_rows() != null) {
- $r = $get->result();
- } else {
- $r = '';
- }
- $subject = 'Njun Njan Restaurant';
- $message = '
- <h1>This message has been sent for testing purposes.</h1>
- ';
- $bulan = array(
- '01' => 'Januari', '02' => 'Februari', '03' => 'Maret', '04' => 'April', '05' => 'Mei',
- '06' => 'Juni', '07' => 'Juli', '08' => 'Agustus', '09' => 'September', '10' => 'Oktober',
- '11' => 'November', '12' => 'Desember'
- );
- $hari = array(
- 0=>'Minggu', 1=>'Senin', 2=>'Selasa', 3=>'Rabu', 4=>'Kamis', 5=>'Jumat', 6=>'Sabtu'
- );
- $tgl = $r[0]->tanggal_pesan;
- // Get full html:
- $body = '
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>A Simple Responsive HTML Email</title>
- <style type="text/css">
- body {margin: 0; padding: 0; min-width: 100%!important;}
- .content {width: 100%; max-width: 600px;}
- body[yahoo] .class {}
- @media only screen and (min-device-width: 601px) {
- .content {width: 600px !important;}
- }
- .header {padding: 40px 30px 20px 30px;}
- .col425 {width: 425px!important;}
- .subhead {font-size: 15px; color: #ffffff; font-family: sans-serif; letter-spacing: 10px;}
- .h1 {font-size: 33px; line-height: 38px; font-weight: bold;}
- .h1, .h2, .bodycopy {color: #153643; font-family: sans-serif;}
- .innerpadding {padding: 30px 30px 30px 30px;}
- .borderbottom {border-bottom: 1px solid #f2eeed;}
- .h2 {padding: 0 0 15px 0; font-size: 24px; line-height: 28px; font-weight: bold;}
- .bodycopy {font-size: 16px; line-height: 22px;}
- .button {text-align: center; font-size: 18px; font-family: sans-serif; font-weight: bold; padding: 0 30px 0 30px;}
- .button a {color: #ffffff; text-decoration: none;}
- @media only screen and (min-device-width: 601px) {
- .content {width: 600px !important;}
- .col425 {width: 425px!important;}
- .col380 {width: 380px!important;}
- }
- img {height: auto;}
- .footer {padding: 20px 30px 15px 30px;}
- .footercopy {font-family: sans-serif; font-size: 14px; color: #ffffff;}
- .footercopy a {color: #ffffff; text-decoration: underline;}
- @media only screen and (max-width: 550px), screen and (max-device-width: 550px) {
- body[yahoo] .buttonwrapper {background-color: transparent!important;}
- body[yahoo] .button a {background-color: #e05443; padding: 15px 15px 13px!important; display: block!important;}
- }
- body[yahoo] .unsubscribe {display: block; margin-top: 20px; padding: 10px 50px; background: #2f3942; border-radius: 5px; text-decoration: none!important; font-weight: bold;}
- body[yahoo] .hide {display: none!important;}
- </style>
- </head>
- <body yahoo bgcolor="#f6f8f1">
- <table width="100%" bgcolor="#f6f8f1" border="0" cellpadding="0" cellspacing="0">
- <tr>
- <td>
- <table class="content" align="center" cellpadding="0" cellspacing="0" border="0">
- <tr>
- <td class="header" bgcolor="#c7d8a7">
- <table width="100%" border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td class="subhead" style="padding: 0 0 0 3px;">
- Restaurant
- </td>
- </tr>
- <tr>
- <td class="h1" style="padding: 5px 0 0 0;">
- Njun Njan
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td class="innerpadding borderbottom">
- <table width="100%" border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td class="h2">
- Mohon segera selesaikan pembayaran Anda!
- </td>
- </tr>
- <tr>
- <td class="bodycopy">
- Checkout berhasil pada hari '.
- $hari[date('w', strtotime($tgl))].', '.
- date('d', strtotime($tgl)).' '.
- $bulan[date('m', strtotime($tgl))].' '. date('Y H:i', strtotime($tgl)) .' WIB
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td class="innerpadding borderbottom">
- <strong>BANK BCA</strong> Nomor Rekening <strong>731 025 2527</strong> a.n Ibnoe Farid
- </td>
- </tr>
- <tr>
- <td class="innerpadding borderbottom">
- <strong>BANK BNI</strong> Nomor Rekening <strong>023 827 2088</strong> a.n Ibnoe Farid
- </td>
- </tr>
- <tr>
- <td class="innerpadding borderbottom">
- <strong>BANK MANDIRI</strong> Nomor Rekening <strong>0700 000 899 992</strong> a.n Ibnoe Farid
- </td>
- </tr>
- <tr>
- <td class="innerpadding borderbottom bodycopy">'; ?>
- <?php foreach ($r as $v): ?>
- <?php $body .= "Kode Booking : <strong>".$v->kode_booking."</strong>
- <br>
- Nomor Pesanan : <strong>".$v->id_pesan."</strong>
- <br>
- Total Pembayaran : Rp <strong>".number_format($v->total_biaya, 0, '', '.')."</strong>,-";
- ?>
- <?php endforeach;?>
- <?php $body .= '</td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td class="footer" bgcolor="#44525f">
- <table width="100%" border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td align="center" class="footercopy">
- Email dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.<br/>
- </td>
- </tr>
- <tr><td></td></tr>
- <tr>
- <td align="center" style="padding: 20px 0 0 0;">
- <table border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td align="center" class="footercopy">
- <span class="bodycopy" style="color: whitesmoke">
- Jika butuh bantuan, gunakan halaman Kontak Kami <br>
- © 2017, <span style="color: #0bcb9a">Njun Njan Restaurant</span>
- </span>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </body>
- </html>
- ';
- // Also, for getting full html you may use the following internal method:
- //$body = $this->email->full_html($subject, $message);
- $result = $this->email
- ->from('eko.okda@gmail.com')
- ->to($email_to)
- ->subject($subject)
- ->message($body)
- ->send();
- if ($result) {
- return true;
- }
- return false;
- }
- public function order_cancel()
- {
- // get data cancel
- $this->db->select('pelanggan.*, pesan.*, cancel.id_cancel, cancel.tanggal_cancel');
- $this->db->from('pesan');
- $this->db->join('cancel', 'pesan.id_pesan=cancel.pesan_id');
- $this->db->join('pelanggan', 'pesan.pelanggan_id=pelanggan.id_pelanggan');
- $get = $this->db->get()->result();
- $data['title'] = 'Page Admin';
- $data['result'] = $get;
- $this->load->view('admin/v_data_cancel', $data);
- }
- public function cancel_detail($id_cancel)
- {
- // get data cancel
- $this->db->select('pelanggan.*, pesan.*, cancel.id_cancel, cancel.tanggal_cancel');
- $this->db->from('pesan');
- $this->db->join('cancel', 'pesan.id_pesan=cancel.pesan_id');
- $this->db->join('pelanggan', 'pesan.pelanggan_id=pelanggan.id_pelanggan');
- $this->db->where(array('cancel.id_cancel'=>$id_cancel));
- $get = $this->db->get();
- $data['title'] = 'Page Admin';
- $data['result'] = $get->result();
- $this->load->view('admin/v_data_cancel_detail', $data);
- }
- public function cetak($id_cancel)
- {
- // get data cancel
- $this->db->select('pelanggan.*, pesan.*, cancel.id_cancel, cancel.tanggal_cancel');
- $this->db->from('pesan');
- $this->db->join('cancel', 'pesan.id_pesan=cancel.pesan_id');
- $this->db->join('pelanggan', 'pesan.pelanggan_id=pelanggan.id_pelanggan');
- $this->db->where(array('cancel.id_cancel'=>$id_cancel));
- $get = $this->db->get();
- $data['title'] = 'Page Admin';
- $data['result'] = $get->result();
- $this->load->view('admin/v_data_cetak', $data);
- }
- public function do_cetak_pesanan()
- {
- // get data
- $this->form_validation->set_rules('pilihBulan', 'Bulan', 'trim|required');
- if ($this->form_validation->run() === false) {
- $this->session->set_flashdata('error', 'Data tidak ditemukan');
- redirect('pages/administrator/pemesanan');
- } else {
- $bulan = $this->input->post('pilihBulan');
- // get data cancel
- $sql = "SELECT DISTINCT booking.kode_booking, pesan.*, pelanggan.id_pelanggan, pelanggan.nama FROM booking LEFT JOIN pesan ON pesan.id_pesan=booking.pesan_id LEFT JOIN pelanggan ON pelanggan.id_pelanggan=pesan.pelanggan_id WHERE MONTH(pesan.tanggal_booking)='$bulan' AND pesan.status_order != '0' ORDER BY booking.kode_booking ASC";
- $sql = $this->db->query($sql);
- if ($sql->num_rows() < 1) {
- $data['result'] = '';
- $this->session->set_flashdata('error', 'Data tidak ditemukan');
- redirect('pages/administrator/pemesanan');
- } else {
- $data['result'] = $sql;
- }
- }
- $data['title'] = 'Page Admin';
- $data['bulan'] = $bulan;
- $this->load->view('admin/v_data_cetak_pemesanan_bulanan', $data);
- }
- public function do_cetak_bulanan()
- {
- // get data
- $this->form_validation->set_rules('pilihBulan', 'Bulan', 'trim|required');
- if ($this->form_validation->run() === false) {
- redirect('pages/administrator/order_cancel');
- } else {
- $bulan = $this->input->post('pilihBulan');
- // get data cancel
- $sql = "SELECT * FROM cancel LEFT JOIN pesan ON pesan.id_pesan=cancel.pesan_id LEFT JOIN pelanggan ON pelanggan.id_pelanggan=pesan.pelanggan_id WHERE MONTH(cancel.tanggal_cancel)='$bulan';";
- $sql = $this->db->query($sql);
- if ($sql->num_rows() < 1) {
- $data['result'] = '';
- $this->session->set_flashdata('error', 'Data tidak ditemukan');
- redirect('pages/administrator/order_cancel');
- } else {
- $data['result'] = $sql;
- }
- }
- $data['title'] = 'Page Admin';
- $data['bulan'] = $bulan;
- $this->load->view('admin/v_data_cetak_bulanan', $data);
- }
- public function edit_menu($id_menu)
- {
- $where = array('id_menu' => $id_menu);
- $set = $this->crud_model->get_update('menu', $where)->result();
- $data['title'] = 'Pages Admin';
- $data['data'] = $set;
- $this->load->view('admin/v_form_edit_menu', $data);
- }
- public function update_menu()
- {
- $picture = $_FILES['upload_menu']['name'];
- $id_menu = $this->input->post('id_menu');
- if (!empty($picture)) {
- // mengambil ekstensi file
- $ext = pathinfo($_FILES['upload_menu']['name']);
- $ext = $ext['extension'];
- // sett conf upload image
- $filename = 'menu_' . time();
- $conf_upload = array(
- 'upload_path' => 'assets/upload/images_menu/',
- 'allowed_types' => 'jpg|png',
- 'max_size' => 2048,
- 'max_height' => 1200,
- 'max_width' => 960,
- 'file_name' => $filename,
- 'file_ext' => $ext
- );
- $this->upload->initialize($conf_upload);
- if ($this->upload->do_upload('upload_menu') === false) {
- $this->session->set_flashdata('error', $this->upload->display_errors().' min: 768px dan max: 1200px');
- $this->edit_menu($id_menu);
- return false;
- }
- $path_images = $conf_upload['upload_path'];
- $path_images .= $conf_upload['file_name'];
- $path_images .= '.' . $conf_upload['file_ext'];
- }
- // rules
- $rules = array(
- array(
- 'field' => 'kode_menu',
- 'label' => 'Kode Menu',
- 'rules' => 'trim|required|max_length[4]'
- ),
- array(
- 'field' => 'nama_menu',
- 'label' => 'Nama Menu',
- 'rules' => 'required'
- ),
- array(
- 'field' => 'harga_menu',
- 'label' => 'Harga Menu',
- 'rules' => 'trim|required|numeric'
- ),
- array(
- 'field' => 'keterangan',
- 'label' => 'Keterangan',
- 'rules' => 'required'
- )
- );
- $this->form_validation->set_rules($rules);
- if ($this->form_validation->run() === false) {
- $data = array('error' => $this->upload->display_errors());
- $this->edit_menu($this->input->post('id_menu'));
- } else {
- // lulus validasi
- $data = array(
- 'id_menu' => $this->input->post('kode_menu'),
- 'nama_menu' => $this->input->post('nama_menu'),
- 'harga_menu' => $this->input->post('harga_menu'),
- 'keterangan' => $this->input->post('keterangan')
- );
- if (!empty($_FILES['upload_menu']['name'])) {
- $data['path_images'] = $path_images;
- }
- // var_dump($data);
- // die();
- // update ke database
- $where = array('id_menu'=>$this->input->post('id_menu'));
- $update = $this->crud_model->set_update('menu', $data, $where);
- if ($update) {
- // flash success
- $data['title'] = 'Pages Admin';
- $this->session->set_flashdata('successfull', 'Update Data Berhasil!');
- redirect('pages/administrator/menu');
- }
- }
- }
- // validate image upload
- public function validate_image()
- {
- $pict = $_FILES['upload_menu']['name'];
- if (empty($pict)) {
- return true;
- } else {
- // mengambil ekstensi file
- $ext = pathinfo($_FILES['upload_menu']['name']);
- $ext = $ext['extension'];
- // sett conf upload image
- $filename = 'menu_' . time();
- $conf_upload = array(
- 'upload_path' => 'assets/upload/images_menu/',
- 'allowed_types' => 'jpg|png',
- 'max_size' => 2048,
- 'max_height' => 1200,
- 'max_width' => 768,
- 'file_name' => $filename,
- 'file_ext' => $ext
- );
- $this->upload->initialize($conf_upload);
- if (!$this->upload->do_upload('upload_menu')) {
- $this->form_validation->set_message('validate_image', $this->upload->display_errors());
- return false;
- } else {
- // echo "<pre>";
- // print_r($this->upload->initialize($conf_upload));
- // echo "</pre>";
- // die();
- return true;
- }
- }
- }
- }
- /* End of file */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement