load->model('m_data'); $this->load->model('m_login'); // cek session yang login, jika session status tidak sama dengan session admin_login,maka halaman akan di alihkan kembali ke halaman login. if($this->session->userdata('status')!="admin_login"){ $this->session->set_flashdata('flash_error', 'Silahkan Login Terlebih dahulu.'); redirect('landing','refresh'); }elseif ($this->session->userdata('status')=="admin_login") { $this->db_ = $this->load->database('skpv',TRUE); } } //menampilkan view header, index dan footer function index(){ $data['mhs'] = $this->db_->get('mahasiswa')->num_rows(); $data['dosen'] = $this->db_->get('dosen')->num_rows(); $data['matkul'] = $this->db_->get('matakuliah')->num_rows(); $data['user'] = $this->m_data->get_data('user')->num_rows(); $data['dhmd'] = $this->m_data->get_data('dhmd')->num_rows(); $this->load->view('admin/v_dashboard',$data); } function logout(){ $this->session->sess_destroy(); redirect(base_url().'landing'); } //Syntax $this->session->sess_destroy(); merupakan fungsi codeigniter untuk menghapus semua session dan akan dialihkan ke halaman login // function logout(){ // $this->session->sess_destroy(); // redirect(base_url().'landing'); // } public function edit_profile() { if ($this->input->post()) { $uname = $this->input->post('username', true); $pw = MD5($this->input->post('old_pw')); $npw = MD5($this->input->post('new_pw')); $cpw = MD5($this->input->post('conf')); if ($npw != $cpw) { $this->session->set_flashdata('flash_error','Konfirmasi Password Salah.'); redirect('admin/edit_profile'); } else { $where = array( 'username' => $uname, 'password' => $pw ); $this->load->model('m_login'); $cek = $this->m_login->cek_login('admin', $where); if ($cek > 0) { $value = array( 'password' => $npw ); $this->db->where('id', $_SESSION['id']); $this->db->update('admin', $value); $this->session->set_flashdata('flash_success','Password berhasil diperbaharui.'); redirect('admin/edit_profile'); } else { $this->session->set_flashdata('flash_error','Password Salah.'); redirect('admin/edit_profile'); } } } else { $this->load->view('v_profile'); } } //================================================= CRUD USER ========================================== function user(){ if($this->input->post()){ // Perlu dilakukan pengecekan terdahulu apakah sudah ada username dan status yang sama telah terdaftar $uname = $this->input->post('username',true); $stat = $this->input->post('status',true); $where_ = array( 'username' => $uname, 'status' => $stat ); $cek = $this->m_login->cek_login('user',$where_); if ($cek > 0) { // kondisi username dan status sudah terdaftar $this->session->set_flashdata('flash_error','Username sudah terdaftar dengan status tersebut.'); redirect('admin/user'); }else{ if($this->input->post('pw') == $this->input->post('conf')){ $data = array( 'username' => $this->input->post('username',true), 'password' => MD5($this->input->post('pw').'**'), 'status' => $this->input->post('status',true), 'iddsn' => $this->input->post('iddsn',true), 'status' => $this->input->post('status',true) ); $this->db->insert('user', $data); $this->session->set_flashdata('flash_success','ditambahkan.'); redirect('admin/user'); }else{ $this->session->set_flashdata('flash_error','Konfirmasi Password salah.'); redirect('admin/user'); } } } $this->db->select('nidu, nmdostpgelar'); $this->db->order_by('nmdostpgelar','ASC'); $data['nmdosen'] = $this->db_->get('dosen'); $this->load->view('admin/v_user.php',$data); } function get_all_user(){ $data = $this->m_data->get_data('user'); echo json_encode($data->result()); } function get_user() { $id=$this->input->get('id'); $where = array( 'id' => $id ); $hsl=$this->m_data->cek_where('user',$where); if($hsl->num_rows()>0){ foreach ($hsl->result() as $i) { $data = array( 'id' => $i->id, 'iddsn' => $i->iddsn, 'username' => $i->username, 'status' => $i->status ); } } echo json_encode($data); } function edit_user($id = NULL) { if ($this->input->post('pw') == $this->input->post('conf')) { if($this->input->post('pw') != ''){ $update = array( 'username' => $this->input->post('ed_username'), 'password' => MD5($this->input->post('pw')), 'status' => $this->input->post('ed_status') ); }elseif ($this->input->post('pw') == '') { $update = array( 'username' => $this->input->post('ed_username'), 'status' => $this->input->post('ed_status') ); } $where = array( 'id' => $id ); $this->m_data->update_data($where,$update,'user'); }else{ $this->session->set_flashdata('flash_error', 'Konfirmasi Password salah.'); redirect('admin/user'); } $this->session->set_flashdata('flash_success', 'Data User Telah Diperbaharui.'); redirect('admin/user'); } function delete_user($id = NULL) { $this->db->where('id', $id); $this->db->delete('user'); $this->session->set_flashdata('flash_success','dihapus.'); redirect('admin/user'); } // ============================================ MANAGE DATA MASTER ========================================================== function master_dosen(){ $this->load->view('admin/v_mDosen.php'); } function get_dosen(){ $this->db_->select('iddsn, kdprodi, nidu, nidn, nmdostpgelar, nmdosdgngelar'); $data = $this->db_->get('dosen'); echo json_encode($data->result()); } function master_matkul(){ $this->load->view('admin/v_mMatkul.php'); } function get_matkul(){ $this->db_->select('idmk, kdprodi, kdmk, nmmkind, nmmkeng, kdkelmk'); $data= $this->db_->get('matakuliah'); echo json_encode($data->result()); } function master_mahasiswa(){ $this->load->view('admin/v_mMahasiswa.php'); } function get_mahasiswa(){ $this->db_->select('idmhs, nim, nmmhs, kdjnskelamin, kdstsemester, kdprodi, thnmasuk'); $data = $this->db_->get('mahasiswa'); echo json_encode($data->result()); } // ==================================================================================================================== function getIDdosen_bynidu(){ $nidu = $this->input->get('nidu'); $this->db->select('iddsn'); $this->db->where('nidu', $nidu); $data = $this->db_->get('dosen'); echo json_encode($data->result()); } //================================================== Kelola DHMD ============================================== function dhmd(){ $this->load->view('admin/v_dhmd'); } function get_dhmd(){ $data = $this->m_data->get_data('dhmd'); echo json_encode($data->result()); } }