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

class Search extends CI_Model{

	function getKlasifikasiPerkara($idalurperkara){
		try {
			$where = ' ';
			if(!empty($idalurperkara)){
				$where .= ' WHERE id IN (
							SELECT jenis_perkara_id FROM jenis_alur_perkara 
								WHERE alur_perkara_id = '.$idalurperkara.') ';
			}
			return $this->db->query("SELECT id, nama_lengkap FROM jenis_perkara 
						".$where." ORDER BY nama_lengkap ASC");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getKlasifikasiPerkara2($idalurperkara){
		try {
			$where = ' ';
			if(!empty($idalurperkara)){
				$where .= ' WHERE id IN (
							SELECT jenis_perkara_id FROM jenis_alur_perkara 
								WHERE alur_perkara_id IN ('.$idalurperkara.')) ';
			}
			return $this->db->query("SELECT id, nama_lengkap FROM jenis_perkara 
						".$where." ORDER BY nama_lengkap ASC");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}




	function getJenisPutusanPerkara($idalurperkara){
		$id = ($idalurperkara>110)? 2:1;
		try {
			$where = ' ';
			if(empty($idalurperkara)){
				$where = ' WHERE jenis_perkara_id = $id ';
			}
			return $this->db->query("SELECT id, nama FROM status_putusan 
					 ORDER BY nama ASC");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getTahapanPerkara(){
		try {
			$jenis_pengadilan = $this->session->userdata('jenis_pengadilan');
			$this->db->where('jenis_pengadilan',$jenis_pengadilan);
			return $this->db->get("tahapan_proses");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}
	
	function getAlurPerkara(){
		try {
			return $this->db->get("alur_perkara");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getHakim(){
		try {
			return $this->db->get("hakim_pn");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getPanitera(){
		try {
			return $this->db->get("panitera_pn");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getJurusita(){
		try {
			return $this->db->get("jurusita");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getMediator(){
		try {
			return $this->db->get("mediator");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getProsesPerkara($idalurperkara){
		try {
			if(!empty($idalurperkara)){
				$this->db->where('alur_perkara_id',$idalurperkara);
			}
			return $this->db->get("proses_alur_perkara");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getRuangSidang(){
		try{
			$this->db->where('aktif','Y');
			return $this->db->get("ruangan_sidang");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}


	function getProsesPerkaraTahapan($idalurperkara,$idtahapan){
		try {
			if(!empty($idalurperkara)){
				$this->db->where_in('alur_perkara_id',$idalurperkara);
			}
			$this->db->where('tahapan_id',$idtahapan);
			return $this->db->get("proses_alur_perkara");
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}



}