[ Mini Kiebo ]
Server: Windows NT AKFAR_SERVER 10.0 build 26200 (Windows 10) AMD64
Path:
D:
/
xampp
/
htdocs
/
smk
/
application
/
controllers
/
sms
/
[
Home
]
File: Kontak.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Kontak extends Member_Controller { private $kode_menu = 'sms-kontak'; private $url = 'sms/kontak'; function __construct(){ parent:: __construct(); $this->load->model('sms/grupkontak_model'); $this->load->model('sms/grup_model'); } public function index($page=null, $id=null){ $data['kode_menu'] = $this->kode_menu; $data['nama'] = $this->access->get_nama(); parent::cek_akses($data['kode_menu']); $this->template->display_admin($this->url.'/kontak_view', 'Daftar Kontak', $data); } function hapusgrup(){ $this->load->library('form_validation'); $this->form_validation->set_rules('hapusgrup-id', 'ID Grup','required|strip_tags'); if($this->form_validation->run() == TRUE){ $id = $this->input->post('hapusgrup-id', true); $this->grup_model->delete($id); $status['status'] = 1; $status['pesan'] = 'Grup berhasil dihapus'; }else{ $status['status'] = 0; $status['pesan'] = 'Grup harus dipilih'; } echo json_encode($status); } function addgrup(){ $this->load->library('form_validation'); $this->form_validation->set_rules('grup-grup', 'Grup Kontak','required|strip_tags'); $this->form_validation->set_rules('grup-keterangan', 'Keterangan','required|max_length[150]|strip_tags'); if($this->form_validation->run() == TRUE){ $grup = $this->input->post('grup-grup', true); $keterangan = $this->input->post('grup-keterangan', true); $hasil = $this->grup_model->cek_grup($grup)->row()->hasil; if($hasil){ $status['status'] = 0; $status['pesan'] = 'Nama Grup sudah dipakai, pakai nama yang lain.'; }else{ $data['grup'] = strtoupper($grup); $data['keterangan'] = $keterangan; $this->grup_model->save($data); $status['status'] = 1; $status['pesan'] = 'Grup berhasil disimpan'; } }else{ $status['status'] = 0; $status['pesan'] = validation_errors(); } echo json_encode($status); } function hapuskontak(){ $this->load->library('form_validation'); $this->form_validation->set_rules('hapuskontak-id', 'ID Kontak','required|strip_tags'); if($this->form_validation->run() == TRUE){ $id = $this->input->post('hapuskontak-id', true); $this->grupkontak_model->delete($id); $status['status'] = 1; $status['pesan'] = 'Kontak berhasil dihapus'; }else{ $status['status'] = 0; $status['pesan'] = 'Kontak harus dipilih'; } echo json_encode($status); } function addkontak(){ $this->load->library('form_validation'); $this->form_validation->set_rules('kontak-grup', 'Grup Kontak','required|strip_tags'); $this->form_validation->set_rules('kontak-nama', 'Nama Kontak','required|max_length[150]|strip_tags'); $this->form_validation->set_rules('kontak-hp', 'Nomor HP.','required|numeric|max_length[15]|strip_tags'); if($this->form_validation->run() == TRUE){ $grup = $this->input->post('kontak-grup', true); $nama = $this->input->post('kontak-nama', true); $hp = $this->input->post('kontak-hp', true); if($grup=='kosong'){ $status['status'] = 0; $status['pesan'] = 'Grup belum dibuat, silahkan tambah grup terlebih dahulu'; }else{ $data['grup'] = $grup; $data['nama'] = strtoupper($nama); $data['hp'] = $hp; $this->grupkontak_model->save($data); $status['status'] = 1; $status['pesan'] = 'Kontak berhasil disimpan'; } }else{ $status['status'] = 0; $status['pesan'] = validation_errors(); } echo json_encode($status); } function get_select_grup(){ $select = '<select name="kontak-grup" id="kontak-grup" class="form-control input-sm" disabled> <option value="kosong">KOSONG</option> </select>'; $query_grup = $this->grup_model->get_all(); if($query_grup->num_rows()>0){ $query_grup=$query_grup->result(); $select='<select name="kontak-grup" id="kontak-grup" class="form-control input-sm">'; foreach($query_grup as $temp){ $select=$select.'<option value="'.$temp->grup.'">'.$temp->grup.' - '.$temp->keterangan.'</option>'; } $select=$select.'</select>'; } echo $select; } function get_all_kontak(){ // 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->grupkontak_model->get_all_grupkontak($start, $rows, $search); $iFilteredTotal = $query->num_rows(); $iTotal=$this->grupkontak_model->get_all_grupkontak_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; $kontak = $query->result(); foreach ($kontak as $temp) { $record = array(); $record[] = ++$i; $record[] = $temp->grup; $record[] = $temp->nama; $record[] = '<a onClick="hapuskontak(\''.$temp->id.'\')" title="Klik untuk menghapus kontak" class="btn btn-default btn-xs">Hapus</a>'; $output['aaData'][] = $record; } // format it to JSON, this output will be displayed in datatable echo json_encode($output); } function get_all_grup(){ // 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->grup_model->get_all_grup($start, $rows, $search); $iFilteredTotal = $query->num_rows(); $iTotal=$this->grup_model->get_all_grup_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; $grup = $query->result(); foreach ($grup as $temp) { $record = array(); $record[] = ++$i; $record[] = $temp->grup; $record[] = $temp->keterangan; $record[] = '<a onClick="hapusgrup(\''.$temp->id.'\')" class="btn btn-default btn-xs">Hapus</a>'; $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; } }