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 Role extends Admin_Controller { function __construct() { parent::__construct(); //admin role module check $this->check_admin_role('admin role'); //method from Admin_controller $this->load->model('role_m'); $current_role_id = $this->session->userdata('admin')['role_id']; //ambil role item dgn role id skrg $this->db->select('role_item_name')->from('role_item')->where('role_id', $current_role_id); $role_item_names = $this->db->get()->result(); $allowed_items = array(); foreach ($role_item_names as $item) { $allowed_items[] = $item->role_item_name; } // if(!in_array("role", $allowed_items)) { // redirect(base_url('admin/dashboard')); // } } //this is to list all roles public function index() { //pagination in action. 50 results per page $this->load->library('pagination'); $config['base_url'] = base_url() . 'admin/role/index'; $config['per_page'] = 10; $config["uri_segment"] = 4; //fetch all roles $config['total_rows'] = $this->role_m->record_count(); $this->pagination->initialize($config); $this->data['roles'] = $this->role_m->get_all_menus($config["per_page"], $this->uri->segment(4)); //load view $this->data['subview'] = 'admin/role/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } //to add a new role public function add() { $this->data['roles'] = $this->role_m->get_new(); //validation in action //validation check in action $config = $this->role_m->rules; $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run($this) == TRUE) { $role_name = $this->input->post('role_name'); $data = array( 'role_name' => $role_name ); $this->db->insert('role', $data); $role_id = $this->db->insert_id(); if($_POST){ $checkboxes = $this->input->post('module_cek'); foreach ($checkboxes as $checkbox) { $data = array( 'role_item_name' => $checkbox, 'role_id' => $role_id ); $this->role_m->add_role_item($data); } } $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Role Add Successful</p>'); redirect('admin/role'); } $this->data['subview'] = 'admin/role/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 page in admin public function edit($id = NULL) { //check if id exist. If not exist, show 404. $count = $this->role_m->count_exist($id); if ($count == 0 || $id == 1) redirect('admin/role'); //get all chosen (active) categories $this->db->select('*')->from('role_item')->where('role_id', $id); $this->data['chosen_role'] = $this->db->get()->result(); $this->data['roles'] = $this->role_m->get($id); $this->role_current_id = (int) $id; //validation check in action $config = $this->role_m->rules; $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run($this) == TRUE) { $role_name = $this->input->post('role_name'); $data = array( 'role_name' => $role_name ); $this->role_m->edit_role($id, $data); //hapus dulu role item yg ada skrg ini.... $this->db->where('role_id', $id); $this->db->delete('role_item'); if($_POST){ $checkboxes = $this->input->post('module_cek'); foreach ($checkboxes as $checkbox) { $data = array( 'role_item_name' => $checkbox, 'role_id' => $id ); $this->role_m->add_role_item($data); } } $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Role Berhasil Diedit</p>'); redirect('admin/role'); } $this->data['subview'] = 'admin/role/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 delete a role public function delete($id) { //check if id exist. If not exist, show 404. id 1 (super admin) cannot be deleted $count = $this->role_m->count_exist($id); if ($count == 0 || $id == 1) redirect('admin/role'); //delete role $this->role_m->delete($id); //set role_id in users table to become NULL $users = $this->db->select('id')->from('users')->where('role_id', $id)->get()->result(); foreach ($users as $user) { $data = array( 'role_id' => NULL ); $this->db->where('id', $user->id); $this->db->update('users', $data); } $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Role Berhasil Dihapus</p>'); redirect('admin/role'); } }