load->model('profile_model', 'profile'); // $this->load->model('news_model', 'news'); $this->load->library('form_validation'); } public function index() { // $data['news'] = $this->news->getallnews(); $data['pengguna'] = $this->profile->getadmin(); $data['admin_role'] = $this->profile->getadminRole(); $data['role_privilage'] = $this->profile->getadminRolePrivilage(); $this->load->view('includes/header'); $this->load->view('profile/index', $data); $this->load->view('includes/footer'); } public function user_pengguna($id="") { $data['region'] = $this->profile->getRegion(); $id_admin = html_escape($this->input->post('id', TRUE)); $username = html_escape($this->input->post('username', TRUE)); $password = html_escape($this->input->post('password', TRUE)); $countrycode = html_escape($this->input->post('countrycode', TRUE)); $phone = html_escape($this->input->post('phone', TRUE)); $email = html_escape($this->input->post('e_mail', TRUE)); $this->form_validation->set_rules('username', 'USERNAME', 'trim|prep_for_form'); $this->form_validation->set_rules('fullnama', 'NAME', 'trim|prep_for_form'); $this->form_validation->set_rules('phone', 'PHONE', 'trim|prep_for_form|is_unique[pelanggan.phone]'); $this->form_validation->set_rules('e_mail', 'E_MAIL', 'trim|prep_for_form|is_unique[pelanggan.email]'); $this->form_validation->set_rules('password', 'PASSWORD', 'trim|prep_for_form'); if ($this->form_validation->run() == TRUE) { $config['upload_path'] = './images/admin/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = '100000'; $config['file_name'] = 'name'; $config['encrypt_name'] = true; $this->load->library('upload', $config); if ($this->upload->do_upload('image_profile')) { $foto = html_escape($this->upload->data('file_name')); } else { $foto = 'noimage.jpg'; } $data = [ 'id' => html_escape($this->input->post('id', TRUE)), 'user_name' => html_escape($this->input->post('username', TRUE)), 'password' => sha1($password), 'email' => html_escape($this->input->post('e_mail', TRUE)), 'image' => $foto, 'nama' => html_escape($this->input->post('fullnama', TRUE)), 'wilayah' => html_escape($this->input->post('region', TRUE)), 'no_telepon' => str_replace("+", "", $countrycode) . $phone, 'admin_role' => html_escape($this->input->post('role', TRUE)), 'status' => html_escape($this->input->post('status', TRUE)), ]; if ($id_admin !="") { $this->profile->ubahdataadmin($data); $this->session->set_flashdata('tambah', 'Berhasil merubah data role user'); redirect('profile/index'); } else { $this->profile->tambahadmin($data); $this->session->set_flashdata('tambah', 'User Has Been Added'); redirect('profile/index'); } } else { if($id !=""){ // echo $id; $data['data'] = $this->profile->getadmingedit($id); $data['role'] = $this->profile->getRole(); $data['role1'] = $this->profile->getRole1(); // dd ($data['nama_fitur']); $this->load->view('includes/header'); $this->load->view('profile/tambahuseradmin', $data); $this->load->view('includes/footer'); }else{ $data['role'] = $this->profile->getRole(); $data['role1'] = $this->profile->getRole1(); $data['data'] =""; $this->load->view('includes/header'); $this->load->view('profile/tambahuseradmin',$data); $this->load->view('includes/footer'); } // } } } public function hapus_pengguna($id) { $data = $this->profile->getadmingedit($id); if ($data['image'] != 'noimage.jpg') { $gambar = $data['image']; unlink('images/promo/' . $gambar); } $this->profile->hapus_pengguna($id); $this->session->set_flashdata('hapus', 'User berhasil dihapus'); redirect('profile'); } public function ubah() { $this->form_validation->set_rules('user_name', 'user_name', 'trim|prep_for_form'); $this->form_validation->set_rules('nama', 'nama', 'trim|prep_for_form'); $this->form_validation->set_rules('email', 'email', 'trim|prep_for_form'); $data = $this->profile->getadmin(); if ($this->form_validation->run() == TRUE) { $config['upload_path'] = './images/admin/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = '10000'; $config['file_name'] = 'name'; $config['encrypt_name'] = true; $this->load->library('upload', $config); if ($this->upload->do_upload('image')) { if ($data['image'] != 'noimage.jpg') { $image = $data['image']; unlink('images/admin/' . $image); } $gambar = html_escape($this->upload->data('file_name')); } else { $gambar = $data['image']; } if ($this->input->post('password', TRUE) == NULL) { $pass = $data['password']; } else { $pass = html_escape(sha1($this->input->post('password', TRUE))); } $data = [ 'id' => html_escape($this->input->post('id', TRUE)), 'image' => $gambar, 'user_name' => html_escape($this->input->post('user_name', TRUE)), 'nama' => html_escape($this->input->post('nama', TRUE)), 'email' => html_escape($this->input->post('email', TRUE)), 'password' => $pass ]; if (demo == TRUE) { $this->session->set_flashdata('demo', 'NGAPAIN DIGANTI PASSWORDNYA :D :P'); redirect('profile/index'); } else { $this->profile->ubahdataadmin($data); $this->session->set_userdata($data); $this->session->set_flashdata('diubah', 'Has Been Changed'); redirect('profile'); } } else { $data['data'] = $this->profile->ubahdataadmin(); $this->load->view('includes/header'); $this->load->view('profile/ubahpengguna', $data); $this->load->view('includes/footer'); } } public function role($id="") { $id_prifilage = html_escape($this->input->post('id', TRUE)); $role = html_escape($this->input->post('role', TRUE)); $this->form_validation->set_rules('role', 'NAME', 'trim|prep_for_form'); if ($this->form_validation->run() == TRUE) { $data = [ 'id' => html_escape($this->input->post('id', TRUE)), 'nama_role' => html_escape($this->input->post('role', TRUE)), ]; if ($id_prifilage !="") { $this->profile->editrole($data); $this->session->set_flashdata('tambah', 'Berhasil merubah data role user'); redirect('profile/index'); } else { $this->profile->tambahrole($data); $this->session->set_flashdata('tambah', 'Berhasil menambahkan data role user'); redirect('profile/index'); } } else { if($id !=""){ // echo $id; $data['data'] = $this->profile->getadminrolegedit($id); // dd ($data['nama_fitur']); $this->load->view('includes/header'); $this->load->view('profile/tambahrole', $data); $this->load->view('includes/footer'); }else{ $data['data'] =""; $this->load->view('includes/header'); $this->load->view('profile/tambahrole', $data); $this->load->view('includes/footer'); } // } } } public function privilage($id="") { $id_prifilage = html_escape($this->input->post('id', TRUE)); $namafitur = html_escape($this->input->post('namafitur', TRUE)); $url = html_escape($this->input->post('url', TRUE)); $icon = html_escape($this->input->post('icon', TRUE)); $this->form_validation->set_rules('fullnama', 'NAME', 'trim|prep_for_form'); $this->form_validation->set_rules('icon', 'ICON', 'trim|prep_for_form'); if ($this->form_validation->run() == TRUE) { $data = [ 'id' => html_escape($this->input->post('id', TRUE)), 'nama_fitur' => html_escape($this->input->post('namafitur', TRUE)), 'url' => html_escape($this->input->post('url', TRUE)), 'icon' => html_escape($this->input->post('icon', TRUE)), ]; if ($id_prifilage !="") { $this->profile->editprifilage($data); $this->session->set_flashdata('tambah', 'Berhasil merubah data privilage'); redirect('profile/index'); } else { $this->profile->tambahprifilage($data); $this->session->set_flashdata('tambah', 'Berhasil menambahkan data privilage'); redirect('profile/index'); } } else { if($id !=""){ // echo $id; $data['data'] = $this->profile->getadminPrifilagedit($id); // dd ($data['nama_fitur']); $this->load->view('includes/header'); $this->load->view('profile/tambahprivilage', $data); $this->load->view('includes/footer'); }else{ $data['data'] =""; $this->load->view('includes/header'); $this->load->view('profile/tambahprivilage', $data); $this->load->view('includes/footer'); } // } } } public function sub_privilage($id="") { $id_prifilage = html_escape($this->input->post('id', TRUE)); $namafitur = html_escape($this->input->post('namafitur', TRUE)); $url = html_escape($this->input->post('url', TRUE)); $icon = html_escape($this->input->post('icon', TRUE)); $this->form_validation->set_rules('fullnama', 'NAME', 'trim|prep_for_form'); $this->form_validation->set_rules('icon', 'ICON', 'trim|prep_for_form'); if ($this->form_validation->run() == TRUE) { $data = [ 'id' => html_escape($this->input->post('id', TRUE)), 'nama_fitur' => html_escape($this->input->post('namafitur', TRUE)), 'url' => html_escape($this->input->post('url', TRUE)), 'foregn' => html_escape($this->input->post('role', TRUE)), ]; if ($id_prifilage !="") { $this->profile->editprifilage($data); $this->session->set_flashdata('tambah', 'Berhasil merubah data privilage'); redirect('profile/index'); } else { $this->profile->tambahprifilage($data); $this->session->set_flashdata('tambah', 'Berhasil menambahkan data privilage'); redirect('profile/index'); } } else { if($id !=""){ // echo $id; $data['data'] = $this->profile->getadminPrifilagedit($id); // dd ($data['nama_fitur']); $data['menu_sub'] = $this->profile->getmenuSubPrifilage(); $this->load->view('includes/header'); $this->load->view('profile/tambahprivilagesub', $data); $this->load->view('includes/footer'); }else{ $data['data'] =""; $data['menu_sub'] = $this->profile->getmenuSubPrifilage(); // dd( $data); $this->load->view('includes/header'); $this->load->view('profile/tambahprivilagesub',$data); $this->load->view('includes/footer'); } // } } } public function role_privilage($id="") { $cek_menu_prifilage = $this->profile->getmenuPrifilage($id); // dd($cek_menu_prifilage); $id_prifilage = html_escape($this->input->post('id', TRUE)); $role = html_escape($this->input->post('role', TRUE)); $this->form_validation->set_rules('role', 'NAME', 'trim|prep_for_form'); if ($this->form_validation->run() == TRUE) { $id_role = $_POST['id_role']; $parent = $_POST['parent']; $child = $_POST['child']; foreach ($parent as $pr) { $id_privilage = isset($pr['id_privilage']) ? ($pr['id_privilage']) : NULL; $id_menu_role = isset($pr['id_menu_role']) ? ($pr['id_menu_role']) : NULL; $cek = isset($pr['cek']) ? ($pr['cek']) : NULL; if($id_menu_role !=""){ $this->profile->deledemenurolprifilage($id_menu_role); } if($cek !=""){ $data = [ 'id_privilage' => html_escape($id_privilage, TRUE), 'id_role' => html_escape($id_role, TRUE), 'parent' => 'Y', ]; $this->profile->tambahmenurolprifilage($data); } } foreach ($child as $ch) { $id_privilage = isset($ch['id_privilage']) ? ($ch['id_privilage']) : NULL; $id_menu_role_child = isset($ch['id_menu_role']) ? ($ch['id_menu_role']) : NULL; $cek_child = isset($ch['cek_child']) ? ($ch['cek_child']) : NULL; // dd($child); if($id_menu_role_child !=""){ $this->profile->deledemenurolprifilage($id_menu_role_child); } if($cek_child !=""){ $data = [ 'id_privilage' => html_escape($id_privilage, TRUE), 'id_role' => html_escape($id_role, TRUE), ]; $this->profile->tambahmenurolprifilage($data); } } $this->session->set_flashdata('tambah', 'Berhasil menambahkan menu role'); redirect('profile/index'); // $data = [ // 'id' => html_escape($this->input->post('id', TRUE)), // 'nama_role' => html_escape($this->input->post('role', TRUE)), // ]; // if ($id_prifilage !="") { // $this->profile->editrole($data); // $this->session->set_flashdata('tambah', 'Berhasil merubah data role user'); // redirect('profile/index'); // } else { // $this->profile->tambahrole($data); // $this->session->set_flashdata('tambah', 'Berhasil menambahkan data role user'); // redirect('profile/index'); // } } else { if($cek_menu_prifilage !=""){ $data['act'] = $this->profile->getadminRolePrivilage(); $data['sub'] = $this->profile->getadminRolePrivilage(); $data['role'] = $this->profile->getadminrolegedit($id); $data['privilage_menu'] = $this->profile->getmenuPrifilage($id); // dd ($data['nama_fitur']); $this->load->view('includes/header'); $this->load->view('profile/tambahroleprivilage', $data); $this->load->view('includes/footer'); }else{ $data['act'] = $this->profile->getadminRolePrivilage(); $data['sub'] = $this->profile->getadminRolePrivilage(); $data['role'] = $this->profile->getadminrolegedit($id); $data['privilage_menu'] = $this->profile->getmenuPrifilage($id); $this->load->view('includes/header'); $this->load->view('profile/tambahroleprivilage', $data); $this->load->view('includes/footer'); } // } } } public function unblock($id) { $this->profile->unblockuserbyid($id); redirect('profile'); } public function userblock($id) { $this->profile->blockuserbyid($id); redirect('profile'); } }