[ Mini Kiebo ]
Server: Windows NT AKFAR_SERVER 10.0 build 26200 (Windows 10) AMD64
Path:
D:
/
xampp
/
htdocs
/
smk
/
application
/
controllers
/
akademik
/
[
Home
]
File: Thnajaran.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Thnajaran extends Member_Controller { private $kode_menu = 'akademik-referensi'; private $url = 'akademik/thnajaran'; function __construct(){ parent:: __construct(); $this->load->model('akademik/thnajaran_model'); } public function index($page=null, $id=null){ $data['kode_menu'] = $this->kode_menu; $data['nama'] = $this->access->get_nama(); if($page=="add"){ parent::cek_akses_crud($data['kode_menu'], 0); $this->template->display_admin($this->url.'/add_view', 'Tambah Tahun Ajaran', $data); }else if($page=="edit"){ parent::cek_akses_crud($data['kode_menu'], 1); if(empty($id)){ redirect($this->url); }else{ $query = $this->thnajaran_model->get_thnajaran_by_id($id); if($query->num_rows()>0){ $temp = $query->row(); $data['id'] = $temp->id; $data['thnajaran'] = $temp->thnajaran; $data['tglmulai'] = $temp->tglmulai; $data['status'] = $temp->status; $data['keterangan'] = $temp->keterangan; }else{ redirect($this->url); } } $this->template->display_admin($this->url.'/edit_view', 'Edit Tahun Ajaran', $data); }else{ parent::cek_akses($data['kode_menu']); $this->template->display_admin($this->url.'/list_view', 'Daftar Tahun Ajaran', $data); } } function edit(){ $this->load->library('form_validation'); $this->form_validation->set_rules('id', 'ID Tahun Ajaran','required|strip_tags'); $this->form_validation->set_rules('aksi', 'Pilihan Aksi','required|strip_tags'); $this->form_validation->set_rules('thnajaran', 'Tahun Ajaran','required|strip_tags'); $this->form_validation->set_rules('tglmulai', 'Tanggal Mulai','required|strip_tags'); $this->form_validation->set_rules('keterangan', 'Keterangan','required|strip_tags'); if($this->form_validation->run() == TRUE){ $thnajaran = $this->input->post('thnajaran', true); $aksi = $this->input->post('aksi', TRUE); $id = $this->input->post('id', TRUE); $status_thnajaran = $this->input->post('status', TRUE); if($aksi==0){//hapus $this->load->model('akademik/kelas_model'); if($this->kelas_model->cek_kelas_by_thnajaran($thnajaran)->row()->hasil>0){ $status['status'] = 0; $status['pesan'] = 'Tahun Ajaran masih digunakan, Tidak bisa dihapus'; }else{ $this->thnajaran_model->delete($thnajaran); $status['status'] = 1; $status['pesan'] = 'Tahun Ajaran berhasil dihapus'; if($status_thnajaran=='AKTIF'){ $query = $this->thnajaran_model->get_thnajaran_by_last_ts(); if($query->num_rows()>0){ $query = $query->row(); $data['status'] = 'AKTIF'; $this->thnajaran_model->update($data, $query->thnajaran); } } } }else if($aksi==1){//simpan $data['tglmulai'] = $this->input->post('tglmulai', true); $data['keterangan'] = $this->input->post('keterangan', true); $this->thnajaran_model->update($data, $thnajaran); $status['status'] = 1; $status['pesan'] = 'Tahun Ajaran berhasil di Simpan'; } }else{ $status['status'] = 0; $status['pesan'] = validation_errors(); } echo json_encode($status); } function add(){ $this->load->library('form_validation'); $this->form_validation->set_rules('thnajaran', 'Tahun Ajaran','required|strip_tags'); $this->form_validation->set_rules('tglmulai', 'Tanggal Mulai','required|strip_tags'); $this->form_validation->set_rules('keterangan', 'Keterangan','required|strip_tags'); if($this->form_validation->run() == TRUE){ $thnajaran = $this->input->post('thnajaran', true); if($this->thnajaran_model->cek_thnajaran($thnajaran)->row()->hasil>0){ $status['status'] = 0; $status['pesan'] = 'Tahun Ajaran sudah terpakai'; }else{ $data_lama['status'] = 'NON AKTIF'; $this->thnajaran_model->update_all($data_lama); $data['thnajaran'] = $thnajaran; $data['tglmulai'] = $this->input->post('tglmulai', true); $data['keterangan'] = $this->input->post('keterangan', true); $this->thnajaran_model->save($data); $status['status'] = 1; $status['pesan'] = 'Tahun Ajaran berhasil disimpan'; } }else{ $status['status'] = 0; $status['pesan'] = validation_errors(); } echo json_encode($status); } function get_all_thnajaran(){ $is_edit = $this->access->cek_akses_crud($this->kode_menu, 1); // variable initialization $search = ""; $start = 0; $rows = 10; // get search value (if any) if (isset($_GET['sSearch']) && $_GET['sSearch'] != "" ) { $search = $_GET['sSearch']; } // limit $start = $this->get_start(); $rows = $this->get_rows(); // run query to get user listing $query = $this->thnajaran_model->get_all_thnajaran($start, $rows, $search); $iFilteredTotal = $query->num_rows(); $iTotal=$this->thnajaran_model->get_all_thnajaran_count($search)->row()->hasil; $output = array( "sEcho" => intval($_GET['sEcho']), "iTotalRecords" => $iTotal, "iTotalDisplayRecords" => $iTotal, "aaData" => array() ); // get result after running query and put it in array $i=$start; $user = $query->result(); foreach ($user as $temp) { $record = array(); $record[] = ++$i; $record[] = $temp->thnajaran; $record[] = date("d F Y",strtotime($temp->tglmulai)); $record[] = $temp->status; $record[] = $temp->keterangan; if($is_edit){ $record[] = '<a href="'.site_url($this->url.'/index/edit/'.$temp->id).'" class="btn btn-default btn-xs">Edit</a>'; }else{ $record[] = ''; } $output['aaData'][] = $record; } // format it to JSON, this output will be displayed in datatable echo json_encode($output); } /** * funsi tambahan * * */ function get_start() { $start = 0; if (isset($_GET['iDisplayStart'])) { $start = intval($_GET['iDisplayStart']); if ($start < 0) $start = 0; } return $start; } function get_rows() { $rows = 10; if (isset($_GET['iDisplayLength'])) { $rows = intval($_GET['iDisplayLength']); if ($rows < 5 || $rows > 500) { $rows = 10; } } return $rows; } function get_sort_dir() { $sort_dir = "ASC"; $sdir = strip_tags($_GET['sSortDir_0']); if (isset($sdir)) { if ($sdir != "asc" ) { $sort_dir = "DESC"; } } return $sort_dir; } }