load->model('m_setting');
if ($this->session->userdata("logged_in") == FALSE){
redirect("user/login", "location");
}
}
/**************************/
/*** Manajemen Akun ***/
/**************************/
public function manajemen_akun(){
// Otoritas //
$menu_id = '14';
is_akses($menu_id);
$data['base_url'] = base_url().'setting/manajemen_akun';
$data['total_rows'] = $this->db->count_all('akun_unlasys'); //belom
$data['per_page'] = '10';
$data['uri_segment']= '3';
$data['first_link'] = 'Pertama';
$data['last_link'] = 'Terakhir';
$data['next_link'] = '>';
$data['prev_link'] = '<';
$this->pagination->initialize($data);
$offset = $this->uri->segment(3);
if ($offset == '') { $offset = 0; }
$paging = $data['per_page'];
$data['id_menu'] = $menu_id;
$data['title'] = 'Manajemen Akun';
$data['query'] = $this->m_setting->list_akun($paging, $offset);
$this->load->view('v_header.php',$data);
$this->load->view('v_menu.php');
$this->load->view('setting/v_manajemen_akun.php');
$this->load->view('v_footer.php');
}
public function tambah_akun(){
// Otoritas //
$menu_id = '14';
is_akses($menu_id);
$this->_validation_akun();
if($this->form_validation->run()==false){
$id_menu = "9";
$menu["id_menu"] = $id_menu;
$data["title"] = "Tambah Akun";
$data["judul_form"] = "Tambah";
$data["action_form"] = base_url().'setting/tambah_akun';
$data["drop_otoritas"] = $this->m_setting->get_drop_otoritas();
$data["user_id"] = "";
$data["pass"] = "";
$data["konf_pass"] = "";
$data["otoritas"] = "";
$data["ubahpass"] = "";
$this->load->view('v_header.php',$data);
$this->load->view('v_menu.php',$menu);
$this->load->view('setting/v_manajemen_akun_form.php');
$this->load->view('v_footer.php');
}else{
$data = array(
'id_otoritas' => $this->input->post('otoritas'),
'userid' => $this->input->post('user_id'),
'passwd' => md5($this->input->post('pass'))
);
$this->m_setting->simpan_akun($data);
$this->session->set_flashdata('success', 'Data Akun berhasil ditambah');
redirect('setting/manajemen_akun');
}
}
public function ubah_akun($id_akun){
// Otoritas //
$menu_id = '14';
is_akses($menu_id);
$this->_validation_ubah_akun();
if($this->form_validation->run()==false){
$id_menu = "14";
$menu["id_menu"] = $id_menu;
$data["title"] = "Ubah Akun";
$data["judul_form"] = "Ubah";
$data["drop_otoritas"] = $this->m_setting->get_drop_otoritas();
$data["action_form"] = base_url().'setting/ubah_akun/'.$id_akun;
$detail_akun = $this->m_setting->detail_akun($id_akun);
foreach($detail_akun->result() as $row_akun) {
$data["user_id"] = $row_akun->userid;
$data["otoritas"] = $row_akun->id_otoritas;
}
$data["ubahpass"] = "isi jika mengubah password";
$data["pass"] = "";
$data["konf_pass"] = "";
$this->load->view('v_header.php',$data);
$this->load->view('v_menu.php',$menu);
$this->load->view('setting/v_manajemen_akun_form.php');
$this->load->view('v_footer.php');
}else{
$pass_new = $this->input->post('pass');
if(empty($pass_new)){
$detail_akun = $this->m_setting->detail_akun($id_akun);
foreach($detail_akun->result() as $row_akun) {
$post_pass = $row_akun->passwd;
}
}else{
$post_pass = md5($pass_new);
}
$data = array(
'id_otoritas' => $this->input->post('otoritas'),
'userid' => $this->input->post('user_id'),
'passwd' => $post_pass
);
$this->m_setting->update_akun($id_akun, $data);
$this->session->set_flashdata('success', 'Data Akun berhasil diubah');
redirect('setting/manajemen_akun');
}
}
public function hapus_akun($id_akun){
// Otoritas //
$menu_id = '14';
is_akses($menu_id);
$this->m_setting->delete_akun($id_akun);
$this->session->set_flashdata('success', 'Data Akun berhasil dihapus');
redirect('setting/manajemen_akun');
}
function _validation_akun(){
$this->form_validation->set_rules("user_id", "User ID", "required|min_length[4]|max_length[15]");
$this->form_validation->set_rules("otoritas", "Otoritas", "required");
$this->form_validation->set_rules("pass", "Password", "required|min_length[4]|max_length[20]");
$this->form_validation->set_rules("konf_pass", "Konfirmasi Password", "required|min_length[4]|max_length[20]|matches[pass]");
$this->form_validation->set_message("required","%s tidak boleh kosong");
$this->form_validation->set_message("max_length", "%s tidak boleh lebih dari %s karakter");
$this->form_validation->set_message("min_length", "%s Minimal %s karakter");
$this->form_validation->set_message("matches", "%s Tidak sama");
$this->form_validation->set_error_delimiters("
", "
");
}
function _validation_ubah_akun(){
$this->form_validation->set_rules("user_id", "User ID", "required|min_length[4]|max_length[15]");
$this->form_validation->set_rules("otoritas", "Otoritas", "required");
$this->form_validation->set_rules("pass", "Password", "min_length[4]|max_length[20]");
$this->form_validation->set_rules("konf_pass", "Konfirmasi Password", "min_length[4]|max_length[20]|matches[pass]");
$this->form_validation->set_message("required","%s tidak boleh kosong");
$this->form_validation->set_message("max_length", "%s tidak boleh lebih dari %s karakter");
$this->form_validation->set_message("min_length", "%s Minimal %s karakter");
$this->form_validation->set_message("matches", "%s Tidak sama");
$this->form_validation->set_error_delimiters("", "
");
}
/**************************/
/*** Otoritas Akun ***/
/**************************/
public function otoritas_akun_cari(){
// Otoritas //
$menu_id = '11';
is_akses($menu_id);
$otoritas_id = $this->input->post('otoritas');
if (!empty($otoritas_id)){
redirect("setting/otoritas_akun/$otoritas_id",'refresh');
}else{
$menu["id_menu"] = $menu_id;
$data['title'] = 'Otoritas Akun';
$data["otoritas"] = "";
$data["drop_otoritas"] = $this->m_setting->get_drop_otoritas();
$data["action_1"] = base_url().'setting/otoritas_akun_cari';
$this->load->view('v_header.php',$data);
$this->load->view('v_menu.php',$menu);
$this->load->view('setting/v_otoritas_akun.php');
$this->load->view('v_footer.php');
}
}
public function otoritas_akun($otoritas_id){
$id_menu = '15';
is_akses($id_menu);
$menu["id_menu"] = $id_menu;
$data['title'] = 'Otoritas Akun';
$data["drop_otoritas"] = $this->m_setting->get_drop_otoritas();
$data["action_1"] = base_url().'setting/otoritas_akun_cari';
$data["action_2"] = base_url().'setting/proses_otoritas/'.$otoritas_id;
$data["otoritas"] = $otoritas_id;
$data_menu = $this->m_setting->list_menu();
$no = 1;
$detail = '
ID Menu
Nama Menu
Akses
Ubah
Hapus
';
foreach ($data_menu as $row){
$id_menu = $row->id_menu;
$cek_ubah = $this->m_setting->cek_ubah($otoritas_id, $id_menu);
$cek_hapus = $this->m_setting->cek_hapus($otoritas_id, $id_menu);
$cek_menu = $this->m_setting->cek_menu_id($otoritas_id, $id_menu);
if ($cek_menu=="ADA"){
$checkbox = anchor("setting/hapus_hak_akses/$otoritas_id/$id_menu", 'Hapus', array('class'=>'delete','onclick'=>"return confirm('Anda yakin hapus Hak Akses untuk menu $row->nama_menu ?')"));
//--Anchor untuk ubah--//
if ($cek_ubah=="ADA"){
$check_ubah = anchor("setting/hapus_hak_ubah/$otoritas_id/$id_menu", 'Hapus', array('class'=>'delete','onclick'=>"return confirm('Anda yakin hapus Akses Ubah pada menu $row->nama_menu ?')"));
}else if($cek_ubah=="KOSONG" OR $cek_ubah=="BELUM"){
$check_ubah = " ";
}
//--Anchor untuk hapus--//
if ($cek_hapus=="ADA"){
$check_hapus = anchor("setting/hapus_hak_hapus/$otoritas_id/$id_menu", 'Hapus', array('class'=>'delete','onclick'=>"return confirm('Anda yakin hapus Akses Hapus pada menu $row->nama_menu ?')"));
}else if($cek_hapus=="KOSONG" OR $cek_hapus=="BELUM"){
$check_hapus = " ";
}
}else{
$checkbox = " ";
$check_ubah = "-";
$check_hapus = "-";
}
if (($row->parent_menu) != 0){
$detail .= "
$row->kode_menu
$row->nama_menu
$checkbox
$check_ubah
$check_hapus
";
}else{
$detail .= "
$row->kode_menu
$row->nama_menu
";
}
$no++;
}
$detail .= '
';
$data['detail'] = $detail;
$this->load->view('v_header.php',$data);
$this->load->view('v_menu.php',$menu);
$this->load->view('setting/v_otoritas_akun.php');
$this->load->view('setting/v_otoritas_detail.php');
$this->load->view('v_footer.php');
}
public function proses_otoritas($otoritas_id){
$menu_id = '15';
is_akses($menu_id);
$id_menu = $this->input->post('id_menu');
$ubah = $this->input->post('ubah');
$hapus = $this->input->post('hapus');
if (!empty($id_menu)){
//--Simpan Otoritas Id dan Menu Id--//
$count = count($id_menu);
$i = 0;
for ($i=0; $i<$count; $i++){
$menu = $id_menu[$i];
$data = array(
'id_otoritas' => $otoritas_id,
'id_menu' => $menu,
'lihat' => 'T'
);
$this->m_setting->simpan_otoritas_akun($data);
}
if (!empty($ubah)){
//--Simpan hak ubah berdasarkan otoritas id dan menu id--//
$count_ubah = count($ubah);
$u = 0;
for ($u=0; $u<$count_ubah; $u++){
$ub = $ubah[$u];
$data = array( 'ubah' => 'TRUE' );
$this->m_setting->update_ubah_hapus($otoritas_id, $ub, $data);
}
}
if (!empty($hapus)){
//--Simpan hak hapus berdasarkan otoritas id dan menu id--//
$count_hapus = count($hapus);
$h = 0;
for ($h=0; $h<$count_hapus; $h++){
$hap = $hapus[$h];
$data = array( 'hapus' => 'TRUE' );
$this->m_setting->update_ubah_hapus($otoritas_id, $hap, $data);
}
}
$this->session->set_flashdata('success', 'Hak Akses berhasil ditambah');
redirect("setting/otoritas_akun/$otoritas_id",'refresh');
}else{
if($ubah || $hapus != NULL){
if (!empty($ubah)){
//--Simpan hak ubah berdasarkan otoritas id dan menu id--//
$count_ubah = count($ubah);
$u = 0;
for ($u=0; $u<$count_ubah; $u++){
$ub = $ubah[$u];
$data = array( 'ubah' => 'TRUE' );
$this->m_setting->update_ubah_hapus($otoritas_id, $ub, $data);
}
}
if (!empty($hapus)){
//--Simpan hak hapus berdasarkan otoritas id dan menu id--//
$count_hapus = count($hapus);
$h = 0;
for ($h=0; $h<$count_hapus; $h++){
$hap = $hapus[$h];
$data = array( 'hapus' => 'TRUE' );
$this->m_setting->update_ubah_hapus($otoritas_id, $hap, $data);
}
}
$this->session->set_flashdata('success', 'Otoritas Menu berhasil ditambah');
redirect("setting/otoritas_akun/$otoritas_id",'refresh');
}
else {
$this->session->set_flashdata('error', 'Tidak ada Hak Akses yg dipilih');
redirect("setting/otoritas_akun/$otoritas_id",'refresh');
}
}
}
function hapus_hak_akses($otoritas_id, $id_menu){
$menu_id = '15';
is_akses($menu_id);
$this->m_setting->delete_otoritas_akun($otoritas_id, $id_menu);
$this->session->set_flashdata('success', 'Otoritas Akun berhasil dihapus');
redirect("setting/otoritas_akun/$otoritas_id",'refresh');
}
function hapus_hak_ubah($otoritas_id, $id_menu){
$menu_id = '15';
is_akses($menu_id);
$data = array( 'ubah' => 'FALSE' );
$this->m_setting->update_ubah_hapus($otoritas_id, $id_menu, $data);
$this->session->set_flashdata('success', 'Hak Akses Ubah berhasil dihapus');
redirect("setting/otoritas_akun/$otoritas_id",'refresh');
}
function hapus_hak_hapus($otoritas_id, $id_menu){
$menu_id = '15';
is_akses($menu_id);
$data = array( 'hapus' => 'FALSE' );
$this->m_setting->update_ubah_hapus($otoritas_id, $id_menu, $data);
$this->session->set_flashdata('success', 'Hak Akses Hapus berhasil dihapus');
redirect("setting/otoritas_akun/$otoritas_id",'refresh');
}
}