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

class Autocomplete extends CI_Controller
{
	//private $db2;
	public function __construct()
	{
		parent::__construct();
	//	 $this->db2 = $this->load->database('dbperkara', TRUE);
	}
	
 
	public function search()
	{
		// tangkap variabel keyword dari URL
		$keyword = $this->uri->segment(3);

		// cari di database
		$datax = $this->db->from('kelurahan')->like('nama_kel',$keyword)->get();	
			$data	= $this->db->query("SELECT A.*,B.nama_kec FROM kelurahan A 
									LEFT JOIN kecamatan B ON A.id_kec=B.id_kec
								 WHERE A.nama_kel LIKE '%$keyword%'
								 ORDER BY A.nama_kel DESC");	
		// format keluaran di dalam array
		foreach($data->result() as $row)
		{
			$arr['query'] = $keyword;
			$arr['suggestions'][] = array(
				'value'	=>$row->nama_kel,
				'id_kel' =>$row->id_kel,
				'nama_kec'=>$row->nama_kec,
				'id_kec'=>$row->id_kec,
				'id_radius'	=>$row->id_radius

			);
		}
		// minimal PHP 5.2
		echo json_encode($arr);
	}
	public function json_komdanas($keyword)
	{
		// tangkap variabel keyword dari URL
		
		$keyword = urldecode($this->uri->segment(3));
		$data = $this->db->from('tb_kelurahan_komdanas')->like('kel',$keyword)->get();
		
		// format keluaran di dalam array
		foreach($data->result() as $row)
		{
			$arr['query'] = $keyword;
			$arr['suggestions'][] = array(
				'value'	=>$row->kel.', '.$row->kabkota.', '.$row->prop_name,
				'id' =>$row->id,
				'prop_name' =>$row->prop_name,
				'kabkota'=>$row->kabkota,
				'satker_name'=>$row->satker_name,
				'kec'=>$row->kec,
				'nilai'	=>$row->nilai

			);
		}
		// minimal PHP 5.2
		echo json_encode($arr);
	}
	public function dosen()
	{
		// tangkap variabel keyword dari URL
		$keyword = $this->uri->segment(3);

		// cari di database
		$data = $this->db->from('tb_dosen')->like('nama_lengkap',$keyword)->get();	

		// format keluaran di dalam array
		foreach($data->result() as $row)
		{
			$arr['query'] = $keyword;
			$arr['suggestions'][] = array(
				'value'	=>$row->nama_lengkap,
				'dosen_id'	=>$row->dosen_id,
				'kategori_dosen_id'	=>$row->kategori_dosen_id

			);
		}
		// minimal PHP 5.2
		echo json_encode($arr);
	}
	public function mahasiswa()
	{
		// tangkap variabel keyword dari URL
		$keyword = $this->uri->segment(3);

		// cari di database
		$data = $this->db->from('tb_mahasiswa')->like('nama_lengkap',$keyword)->get();	

		// format keluaran di dalam array
		foreach($data->result() as $row)
		{
			$arr['query'] = $keyword;
			$arr['suggestions'][] = array(
				'value'	=>$row->nama_lengkap,
				'stambuk'	=>$row->stambuk,
				'mahasiswa_id'	=>$row->mahasiswa_id

			);
		}
		// minimal PHP 5.2
		echo json_encode($arr);
	}
	public function detail()
	{
	    $this->load->model('model_main');
			$cek = $this->db->query("SELECT * FROM perkara where nomor_perkara='".$this->input->post('nomor_perkara')."'");
		    $row = $cek->row_array();
		    $total = $cek->num_rows();
			 foreach ($cek->result_array() as $row){
				 $idperkara = $row['perkara_id'];
			 }
			// echo " ID PErkar :".$idperkara;exit;
			if ($total > 0){
				$data['record'] = $this->model_main->perkara_detail()->row_array();
				$data['recordsidang'] = $this->model_main->perkara_detailsidang($idperkara);
				$data['recordbiaya'] = $this->model_main->perkara_detailbiaya($idperkara);
				$data['recordputusan'] = $this->model_main->perkara_detailputusan($idperkara)->row_array();
				$this->load->view('detail',$data);	

			}else{
				$this->session->set_flashdata("k", "<div class=\"alert alert-info\">Data tidak ditemukan</div>");
				redirect('welcome');
			}
	}
	
}
?>