<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Kecamatan extends CI_Controller {
	function __construct() {
		parent::__construct();
		if($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == ""){
          redirect("error");
       }
	   $this->load->model('app_model');
	   $this->load->model('model_utama');
	   $this->load->model('model_arsip_posbakum');
	}
	
	public function list_data_() {
		if($this->session->userdata('admin_valid')==FALSE){
			redirect("error");
			return;
		}
		$ta = $this->session->userdata('admin_ta');
		$ceksatker = $this->db->query("SELECT * FROM identitas");
		foreach ($ceksatker->result_array() as $row){
			$ceknamasatker = addslashes($row['nama_satker']);
			$rowbiayapos = $row['biaya_pos'];
		 }
				
		$total_row		= $this->db->query("SELECT * FROM tb_kelurahan_komdanas WHERE satker_name ='$ceknamasatker'")->num_rows();
		$per_page		= 10;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		$akhir	= $per_page;
		
		$a['pagi']	= _page($total_row, $per_page, 4, base_url()."kecamatan/list_data_/p");
		
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

	
		if ($mau_ke == "del") {
			$data['enc_act'] = $this->uri->segment(4);
			$id = $this->encrypt->decode(base64_decode($data['enc_act']));
			$this->model_radius->deleteData("tb_konsentrasi_mata_kuliah",array('kelompok_id' => $id));
				$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data berhasil dihapus </div>");
			redirect('kelompok_mk/list_data_');
		} else if ($mau_ke == "cari") {
			$a['record']		= $this->model_kecamatan->list_cari($cari);
			$a['page']		= "kecamatan/list_";
		} else if ($mau_ke == "add") {
			$a['page']		= "kecamatan/form_";
		} else {
			$a['record'] = $this->model_kecamatan->list_($awal,$akhir,$ceknamasatker);
	
			$a['page']		= "kecamatan/list_";
		}
		
		$this->load->view('admin/home_menu', $a);
	}
	
	function tambah_(){
		
		if (isset($_POST['submit'])){
			$cek = $this->db->query("SELECT * FROM kecamatan where nama_kec='".$this->input->post('a')."'");
		    $row = $cek->row_array();
		    $total = $cek->num_rows();
			
			if ($total > 0){
				$this->session->set_flashdata("k", "<div class=\"alert alert-warning\" id=\"alert\">Ups, Data Sudah ada [".$this->input->post('a')."],ulangi lagi.</div>");
				redirect('kecamatan/list_data_');
			}else{
				$this->model_kecamatan->tambah_baru();
				$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data berhasil ditambah</div>");
				redirect('kecamatan/list_data_');
			}
			
		}else{
			redirect("error");
		}
	$this->load->view('admin/home_menu', $a);
	}
	function edit_(){
	
		$data['enc_act'] = $this->uri->segment(3);
		$id = $this->encrypt->decode(base64_decode($data['enc_act']));
		if (isset($_POST['submit'])){
			$this->model_kecamatan->list_update($id);
			$this->session->set_flashdata("k", "<div class=\"alert alert-info\">Data berhasil diubah</div>");
			redirect('kecamatan/list_data_');
		}else{
			$a['rows'] = $this->model_kecamatan->list_detail($id)->row_array();
			$a['page']		= "kecamatan/edit_";
		}
		$this->load->view('admin/home_menu', $a);
	}
	function delete_(){
	
		$ect_id = $this->uri->segment(3);
		$id_enc_ = $this->encrypt->decode(base64_decode($ect_id));
		//hapus database
		$this->app_model->deleteData("kecamatan",array('id_kec' => $id_enc_));
		$this->session->set_flashdata("k", "<div class='alert alert-success'>Data Sukses dihapus..</div>");
		redirect('kecamatan/list_data_');
		
	}
	
}
