ion_auth->logged_in()){ redirect('auth'); }else if (!$this->ion_auth->is_admin()){ show_error('Hanya Administrator yang diberi hak untuk mengakses halaman ini, Kembali ke menu awal', 403, 'Akses Terlarang'); } $this->load->library(['datatables', 'form_validation']);// Load Library Ignited-Datatables $this->load->model('Master_model', 'master'); $this->form_validation->set_error_delimiters('',''); } public function output_json($data, $encode = true) { if($encode) $data = json_encode($data); $this->output->set_content_type('application/json')->set_output($data); } public function index() { $data = [ 'user' => $this->ion_auth->user()->row(), 'judul' => 'Kelompok Soal - Mata Kuliah', 'subjudul'=> 'Data Kelompok Soal - Mata Kuliah' ]; $this->load->view('_templates/dashboard/_header.php', $data); $this->load->view('relasi/ksoalmatkul/data'); $this->load->view('_templates/dashboard/_footer.php'); } public function data() { $this->output_json($this->master->getKsoalMatkulMKWU(), false); } public function getMatkulId($id) { $this->output_json($this->master->getAllMatkulAdd($id)); } public function add() { $data = [ 'user' => $this->ion_auth->user()->row(), 'judul' => 'Tambah Kelompok Soal - Mata Kuliah', 'subjudul' => 'Tambah Data Kelompok Soal - Mata Kuliah', 'ksoal' => $this->master->getAddKsoalMKWU() ]; $this->load->view('_templates/dashboard/_header.php', $data); $this->load->view('relasi/ksoalmatkul/add'); $this->load->view('_templates/dashboard/_footer.php'); } public function edit($id) { $data = [ 'user' => $this->ion_auth->user()->row(), 'judul' => 'Edit Kelompok Soal - Mata Kuliah', 'subjudul' => 'Edit Data Kelompok Soal - Mata Kuliah', 'ksoal' => $this->master->getKsoalById($id, true), 'id_ksoal' => $id, 'all_matkul' => $this->master->getALLMatkulM(), 'matkul' => $this->master->getMatkulMKWUByIdKsoal($id) ]; $this->load->view('_templates/dashboard/_header.php', $data); $this->load->view('relasi/ksoalmatkul/edit'); $this->load->view('_templates/dashboard/_footer.php'); } public function save() { $method = $this->input->post('method', true); $this->form_validation->set_rules('ksoal_id', 'Kelompok Soal', 'required'); $this->form_validation->set_rules('matkul_id[]', 'Mata Kuliah', 'required'); if($this->form_validation->run() == FALSE){ $data = [ 'status' => false, 'errors' => [ 'ksoal_id' => form_error('ksoal_id'), 'matkul_id[]' => form_error('matkul_id[]'), ] ]; $this->output_json($data); }else{ $ksoal_id = $this->input->post('ksoal_id', true); $matkul_id = $this->input->post('matkul_id', true); $input = []; foreach ($matkul_id as $key => $val) { $input[] = [ 'ksoal_id' => $ksoal_id, 'matkul_id' => $val ]; } if($method==='add'){ $action = $this->master->create('mkwu_ksoal_matkul', $input, true); }else if($method==='edit'){ $id = $this->input->post('ksoal_id', true); $this->master->delete('mkwu_ksoal_matkul', $id, 'ksoal_id'); $action = $this->master->create('mkwu_ksoal_matkul', $input, true); } $data['status'] = $action ? TRUE : FALSE ; } $this->output_json($data); } public function delete() { $chk = $this->input->post('checked', true); if(!$chk){ $this->output_json(['status'=>false]); }else{ if($this->master->delete('mkwu_ksoal_matkul', $chk, 'ksoal_id')){ $this->output_json(['status'=>true, 'total'=>count($chk)]); } } } }