Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/blue-sky.co.id/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Menus extends Admin_Controller { //this property is used for validating existing menu title on call back edit menu private $menu_current_id = NULL; function __construct() { parent::__construct(); //admin role module check $this->check_admin_role('menu navigasi'); //method from Admin_controller $this->load->model('menu_m'); } //this is to list all menus public function index() { //Add pagination $this->load->helper('pagination_helper'); add_pagination(base_url() . 'admin/menus/index', $this->menu_m->record_count(), 100, 4); //get parent menus only $this->data['parent_menus'] = $this->menu_m->get_all_parent_menus(100, $this->uri->segment(4)); //load view $this->data['subview'] = 'admin/menus/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } function refreshDisplayPriority(){ $this_data = $this->input->post('this_data'); foreach ($this_data as $key) { $u_data = array( 'priority'=>$key['val'], ); $this->db->update('menus', $u_data, array('id_menus' => $key['id'])); } $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Menu Navigasi Prioritas berhasil diubah</p>'); echo json_encode(array( "res"=>"sukses", // "data"=>$this_data, )); } function changeStatusAct(){ $this_id = $this->input->post('this_id'); $toStat = $this->input->post('toStat'); $codeStat = null; if ($toStat == "Ya") { $codeStat = '1'; }else{ $codeStat = '0'; } $data = array( "status"=>$codeStat, ); $upd = $this->db->update('menus', $data, array('id_menus' => $this_id)); if ($upd) { echo json_encode(array( "res"=>"sukses", )); } } //to add a new menu public function add() { $this->data['menus'] = $this->menu_m->get_new(); $this->data['parent_menus'] = $this->menu_m->get_parent_menus(); //get ordering number and display at add form $this->db->select_max('priority')->from('menus'); $current_priority = $this->db->get()->row()->priority; if($current_priority == NULL) { $this->data['menus']->priority = 1; } else { $this->data['menus']->priority = $current_priority + 1; } //validation in action //validation check in action $rules = $this->menu_m->rules; $config = $this->check_form_validation($rules, $_POST); $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); //above is to add class to form validation error, to be styled $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run($this) == TRUE) { $data = $this->process_data($_POST); $this->menu_m->add_menu($data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Menu Navigasi Berhasil Dibuat</p>'); redirect('admin/menus'); } $this->data['subview'] = 'admin/menus/edit'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } //to edit menu in admin public function edit($id = NULL) { //check if id exist. If not exist, show 404. $count = $this->menu_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } $this->menu_current_id = (int) $id; $this->data['menus'] = $this->menu_m->get($id); //validation check in action $rules = $this->menu_m->rules; $config = $this->check_form_validation($rules, $_POST); $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); //above is to add class to form validation error, to be styled $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run($this) == TRUE) { $data = $this->process_data($_POST); $this->menu_m->edit_menu($id, $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Menu Berhasil Diedit</p>'); redirect('admin/menus'); } $this->data['parent_menus'] = $this->menu_m->get_parent_menus(); $this->data['subview'] = 'admin/menus/edit'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } public function delete_all(){ $checkbox_for_del = $this->input->post('checkbox_del'); if (empty($checkbox_for_del)) { redirect('admin/menus'); } for ($i=0; $i<count($checkbox_for_del) ; $i++) { $id = $checkbox_for_del[$i]; //delete menu $this->menu_m->delete($id); } $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Menu Berhasil Dihapus</p>'); echo json_encode(array( 'result'=>'sukses', )); } //to delete a menu public function delete($id) { //check if id exist. If not exist, show 404. $count = $this->menu_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } //delete menu $this->menu_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Menu Berhasil Dihapus</p>'); redirect('admin/menus'); } public function ajax_get_menutype() { $this->load->helper('form'); //test if ajax call to prevent direct access if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $menu_type = $this->input->post('menu_type'); $current_menu_id = $this->input->post('current_menu_id'); switch ($menu_type) { case "form_page": $data['current_menu_link'] = NULL; if ($current_menu_id != NULL) { $this->db->select('menu_link')->from('menus')->where('id_menus', (int) $current_menu_id); $data['current_menu_link'] = $this->db->get()->row()->menu_link; } $this->load->view('admin/menus/ajax_get_form_pages', $data); break; case "info_page": //get all pages $this->db->select('*')->from('halaman_info') ->where('status', 1) ->order_by('id_halaman_info', 'ASC'); $data['halaman_info'] = $this->db->get()->result(); if ($current_menu_id == NULL) { $data['current_page_id'] = NULL; } else { //get current active page_id $this->db->select('info_page_id')->from('menus')->where('id_menus', (int) $current_menu_id); $data['current_page_id'] = $this->db->get()->row()->info_page_id; } $this->load->view('admin/menus/ajax_get_info_pages', $data); break; case 'category': //get all parent categories $this->db->select('*')->from('categories')->where('status', 1)->where('parent', NULL)->order_by('id_categories', 'ASC'); $data['categories'] = $this->db->get()->result(); if ($current_menu_id == NULL) { $data['current_category_id'] = NULL; } else { //get current active category_id $this->db->select('category_id, menu_link')->from('menus')->where('id_menus', (int) $current_menu_id); $category_id = $this->db->get()->row(); if ($category_id->category_id == NULL) { if ($category_id->menu_link == 'category/all-categories') { $data['current_category_id'] = 'category/all'; } elseif ($category_id->menu_link == 'category/new') { $data['current_category_id'] = 'category/new'; } elseif ($category_id->menu_link == 'category/sale') { $data['current_category_id'] = 'category/sale'; } elseif ($category_id->menu_link == 'category/bestseller') { $data['current_category_id'] = 'category/bestseller'; } } else { $data['current_category_id'] = $category_id->category_id; } } $this->load->view('admin/menus/ajax_get_category', $data); break; case 'brand': //get all brands $this->db->select('*')->from('brands')->where('status', 1)->order_by('id_brands', 'ASC'); $data['brands'] = $this->db->get()->result(); if ($current_menu_id == NULL) { $data['current_brand_id'] = NULL; } else { //get current active brand_id $this->db->select('brand_id, menu_link')->from('menus')->where('id_menus', (int) $current_menu_id); $brand_id = $this->db->get()->row(); if ($brand_id->brand_id == NULL) { if ($brand_id->menu_link == 'brand/all') { $data['current_brand_id'] = 'all'; } } else { $data['current_brand_id'] = $brand_id->brand_id; } } $this->load->view('admin/menus/ajax_get_brands', $data); break; case 'page': //get all pages $this->db->select('*')->from('pages')->where('status', 1)->where('parent', NULL)->order_by('id_pages', 'ASC'); $data['pages'] = $this->db->get()->result(); if ($current_menu_id == NULL) { $data['current_page_id'] = NULL; } else { //get current active page_id $this->db->select('page_id')->from('menus')->where('id_menus', (int) $current_menu_id); $data['current_page_id'] = $this->db->get()->row()->page_id; } $this->load->view('admin/menus/ajax_get_pages', $data); break; case 'hotel': //get all hotels $this->db->select('*')->from('hotels')->where('status', 1)->order_by('id', 'ASC'); $data['hotels'] = $this->db->get()->result(); if ($current_menu_id == NULL) { $data['current_hotel_id'] = NULL; } else { //get current active hotel_id $this->db->select('hotel_id')->from('menus')->where('id_menus', (int) $current_menu_id); $data['current_hotel_id'] = $this->db->get()->row()->hotel_id; } $this->load->view('admin/menus/ajax_get_hotels', $data); break; case 'external': if ($current_menu_id == NULL) { $this->load->view('admin/menus/ajax_get_external'); } else { //get current external link $this->db->select('menu_link')->from('menus')->where('id_menus', (int) $current_menu_id); $data['current_external_link'] = $this->db->get()->row(); $this->load->view('admin/menus/ajax_get_external', $data); } break; } } //callback function validation add new menu public function _cek_existing_menu_title($str) { $num_rows = $this->menu_m->cek_existing_menu_title($str, $this->menu_current_id); if ($num_rows != 0 ) { $this->form_validation->set_message('_cek_existing_menu_title', 'Nama menu bahasa Indonesia sudah ada !'); return FALSE; } else { return TRUE; } } //callback function validation add new menu english public function _cek_existing_menu_en_title($str) { $num_rows = $this->menu_m->cek_existing_menu_en_title($str, $this->menu_current_id); if ($num_rows != 0 ) { $this->form_validation->set_message('_cek_existing_menu_en_title', 'Nama menu bahasa Inggris sudah ada !'); return FALSE; } else { return TRUE; } } private function check_form_validation($config, $post_data) { if (isset($post_data['category'])) { $config[] = array( 'field' => 'category', 'label' => 'category', 'rules' => 'trim|required' ); } if (isset($post_data['brand'])) { $config[] = array( 'field' => 'brand', 'label' => 'brand', 'rules' => 'trim|required' ); } if (isset($post_data['page'])) { $config[] = array( 'field' => 'page', 'label' => 'page', 'rules' => 'trim|required' ); } if (isset($post_data['external_link'])) { $config[] = array( 'field' => 'external_link', 'label' => 'External Link', 'rules' => 'trim|required' ); } return $config; } private function process_data($post_data) { $menu_type = $post_data['menu_type']; $data = array( 'menu' => $this->security->xss_clean($post_data['menu']), 'alias' => url_title($this->security->xss_clean($post_data['menu'])), 'menu_type' => $menu_type, 'status' => $post_data['status'], 'priority' => (int) $post_data['priority'], ); if(empty($this->input->post('menu_en'))) { $data['menu_en'] = $this->security->xss_clean($this->input->post('menu')) . ' En'; $data['alias_en'] = url_title($this->security->xss_clean($this->input->post('menu')) . ' en'); } else { $data['menu_en'] = $this->security->xss_clean($this->input->post('menu_en')); $data['alias_en'] = url_title($this->security->xss_clean($this->input->post('menu_en'))); } if ($this->input->post('parent_id') == 'no-parent') { $data['parent_id'] = NULL; } else { $data['parent_id'] = (int) $this->input->post('parent_id'); } if ($menu_type == 'category') { if ($post_data['category'] == 'all') { $data['menu_link'] = 'category/all-categories'; $data['menu_link_en'] = 'category/all-categories'; $data['category_id'] = NULL; $data['brand_id'] = NULL; $data['page_id'] = NULL; } elseif ($post_data['category'] == 'new') { $data['menu_link'] = 'category/new'; $data['menu_link_en'] = 'category/new'; $data['category_id'] = NULL; $data['brand_id'] = NULL; $data['page_id'] = NULL; } elseif ($post_data['category'] == 'sale') { $data['menu_link'] = 'category/sale'; $data['menu_link_en'] = 'category/sale'; $data['category_id'] = NULL; $data['brand_id'] = NULL; $data['page_id'] = NULL; } elseif ($post_data['category'] == 'bestseller') { $data['menu_link'] = 'category/bestseller'; $data['menu_link_en'] = 'category/bestseller'; $data['category_id'] = NULL; $data['brand_id'] = NULL; $data['page_id'] = NULL; } else { //individual category item.. $category_id = (int) $post_data['category']; $this->db->select('parent')->from('categories')->where('id_categories', $category_id); $parent_id = $this->db->get()->row()->parent; //check parent_id if($parent_id === NULL) { //this category is level 1 category $this->db->select('alias, alias_en')->from('categories')->where('id_categories', $category_id); $aliases = $this->db->get()->row(); $data['menu_link'] = 'category/' . strtolower($aliases->alias); $data['menu_link_en'] = 'category/' . strtolower($aliases->alias_en); } elseif($parent_id !== NULL) { $this->db->select('parent')->from('categories')->where('id_categories', $parent_id); $parent2_id = $this->db->get()->row()->parent; if($parent2_id == NULL) { //this is level 2 category.. //get level 1 alias $this->db->select('alias, alias_en')->from('categories')->where('id_categories', $parent_id); $aliases_level1 = $this->db->get()->row(); //get level 2 alias $this->db->select('alias, alias_en')->from('categories')->where('id_categories', $category_id); $aliases_level2 = $this->db->get()->row(); $data['menu_link'] = 'category/' . strtolower($aliases_level1->alias) . '/' . strtolower($aliases_level2->alias); $data['menu_link_en'] = 'category/' . strtolower($aliases_level1->alias_en) . '/' . strtolower($aliases_level2->alias_en); } else { //this is level 3 category.. //get level 3 alias $this->db->select('alias, alias_en')->from('categories')->where('id_categories', $category_id); $aliases_level3 = $this->db->get()->row(); //get level 2 alias $this->db->select('alias, alias_en')->from('categories')->where('id_categories', $parent_id); $aliases_level2 = $this->db->get()->row(); //get level 1 parent id $this->db->select('parent')->from('categories')->where('id_categories', $parent_id); $level1_id = $this->db->get()->row()->parent; $this->db->select('alias, alias_en')->from('categories')->where('id_categories', $level1_id); $aliases_level1 = $this->db->get()->row(); $data['menu_link'] = 'category/' . strtolower($aliases_level1->alias) . '/' . strtolower($aliases_level2->alias) . '/' . strtolower($aliases_level3->alias); $data['menu_link_en'] = 'category/' . strtolower($aliases_level1->alias_en) . '/' . strtolower($aliases_level2->alias_en) . '/' . strtolower($aliases_level3->alias_en); } } $data['category_id'] = $category_id; $data['brand_id'] = NULL; $data['page_id'] = NULL; } } if ($menu_type == 'brand') { if ($post_data['brand'] == 'all') { $data['menu_link'] = 'brand/all'; $data['menu_link_en'] = 'brand/all'; $data['category_id'] = NULL; $data['brand_id'] = NULL; $data['page_id'] = NULL; } else { $brand_id = (int) $post_data['brand']; $this->db->select('alias')->from('brands')->where('id_brands', $brand_id); $brand_alias = $this->db->get()->row(); $data['menu_link'] = 'brand/' . strtolower($brand_alias->alias); $data['menu_link_en'] = 'brand/' . strtolower($brand_alias->alias); $data['brand_id'] = $brand_id; $data['category_id'] = NULL; $data['page_id'] = NULL; } } if ($menu_type == 'page') { $page_id = (int) $post_data['page']; $this->db->select('alias, alias_en')->from('pages')->where('id_pages', $page_id); $page_alias = $this->db->get()->row(); $data['menu_link'] = 'page/' . strtolower($page_alias->alias); $data['menu_link_en'] = 'page/' . strtolower($page_alias->alias_en); if ($page_id == '30') { $data['menu_link'] = 'careers'; $data['menu_link_en'] = 'careers'; } $data['page_id'] = $page_id; $data['category_id'] = NULL; $data['brand_id'] = NULL; } if ($menu_type == 'hotel') { $hotel_id = (int) $post_data['hotel']; $this->db->select('alias')->from('hotels')->where('id', $hotel_id); $hotel_alias = $this->db->get()->row(); $data['menu_link'] = 'hotel/' . strtolower($hotel_alias->alias); $data['menu_link_en'] = 'hotel/' . strtolower($hotel_alias->alias); $data['hotel_id'] = $hotel_id; $data['category_id'] = NULL; $data['brand_id'] = NULL; $data['page_id'] = NULL; } if ($menu_type == 'blue_sky_mantau') { $data['menu_link'] = 'page/blue-sky-mantau'; $data['menu_link_en'] = 'page/blue-sky-mantau'; $data['page_id'] = null; $data['info_page_id'] = NULL; $data['category_id'] = NULL; $data['brand_id'] = NULL; } if ($menu_type == 'jenis_kain_page') { $data['menu_link'] = 'jenis_kain'; $data['menu_link_en'] = 'jenis_kain'; $data['page_id'] = null; $data['info_page_id'] = NULL; $data['category_id'] = NULL; $data['brand_id'] = NULL; } if ($menu_type == 'price_page') { $data['menu_link'] = 'daftar_harga'; $data['menu_link_en'] = 'daftar_harga'; $data['page_id'] = null; $data['info_page_id'] = NULL; $data['category_id'] = NULL; $data['brand_id'] = NULL; } if ($menu_type == 'faqpage') { $data['menu_link'] = 'faq'; $data['menu_link_en'] = 'faq'; $data['page_id'] = null; $data['info_page_id'] = NULL; $data['category_id'] = NULL; $data['brand_id'] = NULL; } if ($menu_type == 'ide_produk_page') { $data['menu_link'] = '#'; $data['menu_link_en'] = '#'; $data['page_id'] = null; $data['info_page_id'] = NULL; $data['category_id'] = NULL; $data['brand_id'] = NULL; } if ($menu_type == 'form_page') { $data['menu_link'] = 'form/'.$post_data['form_page']; $data['menu_link_en'] = 'form/'.$post_data['form_page']; $data['page_id'] = null; $data['info_page_id'] = NULL; $data['category_id'] = NULL; $data['brand_id'] = NULL; } if ($menu_type == 'info_page') { $page_id = (int) $post_data['info_page']; $this->db->select('alias, alias_en, halaman') ->from('halaman_info') ->where('id_halaman_info', $page_id); $page_alias = $this->db->get()->row(); switch ($page_alias->halaman) { case 'Print': $data['menu_link'] = "cetak"; $data['menu_link_en'] = "cetak"; break; case 'Jahit': $data['menu_link'] = "jahit"; $data['menu_link_en'] = "jahit"; break; case 'Dropship': $data['menu_link'] = "dropship"; $data['menu_link_en'] = "dropship"; break; case 'Manfaat untuk bisnis anda': $data['menu_link'] = "business"; $data['menu_link_en'] = "business"; break; case 'Sponsor untuk bisnis kecil': $data['menu_link'] = "sponsorship"; $data['menu_link_en'] = "sponsorship"; break; case 'Tentang kami': $data['menu_link'] = "about"; $data['menu_link_en'] = "about"; break; default: # code... break; } $data['page_id'] = null; $data['info_page_id'] = $page_id; $data['category_id'] = NULL; $data['brand_id'] = NULL; } if ($menu_type == 'external') { $data['menu_link'] = $this->security->xss_clean($post_data['external_link']); $data['menu_link_en'] = $this->security->xss_clean($post_data['external_link']); $data['category_id'] = NULL; $data['brand_id'] = NULL; $data['page_id'] = NULL; } if ($menu_type == 'homepage') { $data['menu_link'] = ''; $data['menu_link_en'] = ''; $data['category_id'] = NULL; $data['brand_id'] = NULL; $data['page_id'] = NULL; } if ($menu_type == 'blog') { $data['menu_link'] = 'blog/all'; $data['menu_link_en'] = 'blog/all'; $data['category_id'] = NULL; $data['brand_id'] = NULL; $data['page_id'] = NULL; } if ($menu_type == 'contact') { $data['menu_link'] = 'contact'; $data['menu_link_en'] = 'contact'; $data['category_id'] = NULL; $data['brand_id'] = NULL; $data['page_id'] = NULL; } return $data; } }