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

class Cek_radius extends CI_Controller {
	function __construct() {
		parent::__construct();
		
	   $this->load->model('app_model');
	   $this->load->model('model_utama');
	   $this->load->model('model_arsip_posbakum');
	}
	
	public function list_data_() {
		
	
		$total_row		= $this->db->query("SELECT * FROM tb_kelurahan_komdanas")->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()."kelurahan_komdanas/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_kelurahan_komdanas->list_cari($cari);
			$a['page']		= "kelurahan_komdanas/list_";
		} else if ($mau_ke == "add") {
			$a['kecamatan'] = $this->model_kelurahan_komdanas->list_kecamatan();
			$a['radius'] = $this->model_kelurahan_komdanas->list_radius();
			$a['page']		= "kelurahan_komdanas/form_";
		} else {
			$a['record'] = $this->model_kelurahan_komdanas->list_($awal,$akhir);
	
			$a['page']		= "kelurahan_komdanas/list_";
		}
		
		$this->load->view('admin/home_menu', $a);
	}
	
	function tambah_(){
		
		if (isset($_POST['submit'])){
			$cek = $this->db->query("SELECT * FROM kelurahan where nama_kel='".$this->input->post('b')."'");
		    $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('b')."],ulangi lagi.</div>");
				redirect('kelurahan/list_data_');
			}else{
				$this->model_kelurahan->tambah_baru();
				$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data berhasil ditambah</div>");
				redirect('kelurahan/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_kelurahan->list_update($id);
			$this->session->set_flashdata("k", "<div class=\"alert alert-info\">Data berhasil diubah</div>");
			redirect('kelurahan/list_data_');
		}else{
			$a['kecamatan'] = $this->model_kelurahan->list_kecamatan();
			$a['radius'] = $this->model_kelurahan->list_radius();
			$a['rows'] = $this->model_kelurahan->list_detail($id)->row_array();
			$a['page']		= "kelurahan/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("kelurahan",array('id_kel' => $id_enc_));
		$this->session->set_flashdata("k", "<div class='alert alert-success'>Data Sukses dihapus..</div>");
		redirect('kelurahan/list_data_');
		
	}
	
}
