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

class c_template_agama_kasasi extends CI_Controller {
	function index() {
         if($this->session->userdata('is_logged_in')==FALSE){
            redirect('login');
        }  
    }

    function popup_akta_kasasi(){	
		if($this->session->userdata('is_logged_in')==FALSE){
            redirect('login');
        } 	
        $data['enc']=$this->uri->segment('3');
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));
		if(!is_numeric($idperkara) OR !intval($idperkara)>0){			
		    show_404();
			exit();
		}
		$data['pihakasal']=$this->uri->segment('4');        
		if(!is_numeric($data['pihakasal']) OR !intval($data['pihakasal'])>0){			
		    show_404();
			exit();
		}
		$data['encpemohon']=$this->uri->segment('5');
        $idpemohon=$this->encrypt->decode(base64_decode($data['encpemohon']));
		if(!is_numeric($idpemohon) OR !intval($idpemohon)>0){		    
		    show_404();
			exit();
		}
		$data['idakta'] = $this->uri->segment('6');	
		//echo $idperkara.'-'.$data['pihakasal'].'-'.$idpemohon.'-'.$data['idakta'];
		//exit();	
		$this->load->model('generate_template/peradilan_agama/m_template_akta_kasasi_agama','template');
		$data['dataPutusan']=$this->template->getDataPutusan($idperkara);
		$data['listPembuatAkta'] = $this->template->pembuatAkta($idperkara);
		$data['ttdKetua'] = $this->template->ttdKetua();
		$info=$this->template->getInfo($idperkara,$idpemohon);
		$info2=$this->template->getInfo2($idperkara,$idpemohon);
		if($data['idakta']!=5){
			if($info != ''){
	            $data['namapihak'] = '';
	            if($info->num_rows>0){
	                foreach ($info->result() as $row) {                                
	                    $diwakili = FALSE;
	                    $data['namapihak'] .= $this->templatehelper->standradnaming($row->pihak_nama);
	                    if($row->pihak_diwakili=='Y'){
	                        $diwakili = TRUE;
	                        $data['namapihak'] .= "</br>Diwakili oleh: ".$this->templatehelper->standradnaming($row->pemohon_nama);
	                    }
	                }
	            }
	        }
		}else{
			if($info2 != ''){
	            $data['namapihak'] = '';
	            if($info2->num_rows>0){
	                foreach ($info2->result() as $row) {                                
	                    $diwakili = FALSE;
	                    $data['namapihak'] .= $this->templatehelper->standradnaming($row->pihak_nama);
	                    if($row->pihak_diwakili=='Y'){
	                        $diwakili = TRUE;
	                        $data['namapihak'] .= "</br>Diwakili oleh: ".$this->templatehelper->standradnaming($row->pemohon_nama);
	                    }
	                }
	            }
	        }
		}
		
	    if($data['idakta']==1 && $data['pihakasal']==1){
	    	$data['template']=$this->template->getDataDocumentTemplate('15','30','410','1','');			
	    }elseif($data['idakta']==1 && $data['pihakasal']==2){
	    	$data['template']=$this->template->getDataDocumentTemplate('15','30','410','1','');		
	    }elseif($data['idakta']==1 && $data['pihakasal']==3){
	    	$data['template']=$this->template->getDataDocumentTemplate('15','30','410','1','');
	    }	    		
		
		$this->load->view('generate_template/peradilan_agama/popup_akta_kasasi',$data,FALSE);
	}

	function cetak_akta_kasasi(){
		if($this->session->userdata('is_logged_in')==FALSE){
            redirect('login');
        } 		
        $data['enc'] = $this->input->post('enc',TRUE);
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));
        if(!is_numeric($idperkara) OR !intval($idperkara)>0){
             echo 'idperkara';
             show_404();
             exit();
        }           
        $encpemohon = $this->input->post('encpemohon',TRUE);
        $idpemohon=$this->encrypt->decode(base64_decode($encpemohon));
        if(!is_numeric($idpemohon) OR !intval($idpemohon)>0){
             echo 'idpemohon';
             show_404();
             exit();
        }
		       
		$data['jenisAkta'] = $this->input->post('jenisAkta',TRUE);
		if(empty($data['jenisAkta']) OR intval($data['jenisAkta'])<1){
			echo 'idakta';
			show_404();
		}
		
		$encputusan = $this->input->post('putusan',TRUE);
		$idputusan=$this->encrypt->decode(base64_decode($encputusan));
		if(empty($idputusan) OR intval($idputusan)<1){
			echo 'idputusan';
			show_404();
		}
		$data['penandatangan'] = $this->input->post('penandaT',TRUE);
        $penandatangan=$this->encrypt->decode(base64_decode($data['penandatangan']));
		/*echo $idperkara.' - '.$idpemohon.' - '.$idputusan.' - '.$penandatangan;
		exit();*/
		$this->load->model('generate_template/peradilan_agama/m_template_akta_kasasi_agama','template');
		$data['dataPN'] = $this->template->getDataPN($idperkara); 		
		$data['dataPemohonKasasi'] = $this->template->listAllPemohonKasasi($idperkara); 
		$data['dataTermohonKasasi'] = $this->template->listAllTermohonKasasi($idperkara);
		$data['dataKuasaPemohon'] = $this->template->getKuasaPemohon($idperkara,$idpemohon);
		if($data['jenisAkta']!=28 && $data['jenisAkta']!=29 && $data['jenisAkta']!=30){
			$data['dataTemplate'] = $this->template->cetak_AktaPermohonanKasasi($idperkara,$penandatangan,$idpemohon,$idputusan);
		}else{
			$data['dataTemplate'] = $this->template->cetak_AktaKontraKasasi($idperkara,$penandatangan,$idpemohon,$idputusan);
		}
		
		
		if(($data['jenisAkta']==1)||($data['jenisAkta']==3)||($data['jenisAkta']==5)){
        	$data['template']=$this->template->getDataDocumentTemplate('15','30','410','1','');
		}elseif(($data['jenisAkta']==2)||($data['jenisAkta']==4)||($data['jenisAkta']==6)){
        	$data['template']=$this->template->getDataDocumentTemplate('15','30','410','2','');
		}elseif(($data['jenisAkta']==7)||($data['jenisAkta']==8)||($data['jenisAkta']==9)) {
        	$data['template']=$this->template->getDataDocumentTemplate('15','30','410','3','');
		}elseif(($data['jenisAkta']==10)||($data['jenisAkta']==11)||($data['jenisAkta']==12)){
        	$data['template']=$this->template->getDataDocumentTemplate('15','30','410','4','');
		}elseif(($data['jenisAkta']==13)||($data['jenisAkta']==15)||($data['jenisAkta']==17)){
        	$data['template']=$this->template->getDataDocumentTemplate('15','30','490','1','');
		}elseif(($data['jenisAkta']==14)||($data['jenisAkta']==16)||($data['jenisAkta']==18)){
        	$data['template']=$this->template->getDataDocumentTemplate('15','30','490','2','');
		}elseif(($data['jenisAkta']==19)||($data['jenisAkta']==21)||($data['jenisAkta']==23)){
        	$data['template']=$this->template->getDataDocumentTemplate('15','30','490','3','');
		}elseif(($data['jenisAkta']==20)||($data['jenisAkta']==22)||($data['jenisAkta']==24)){
        	$data['template']=$this->template->getDataDocumentTemplate('15','30','490','4','');
		}elseif(($data['jenisAkta']==25)||($data['jenisAkta']==26)||($data['jenisAkta']==27)){
        	$data['template']=$this->template->getDataDocumentTemplate('15','30','430','1','');
		}elseif(($data['jenisAkta']==28)||($data['jenisAkta']==29)||($data['jenisAkta']==30)){
        	$data['template']=$this->template->getDataDocumentTemplate('15','30','450','1','');
		}/*elseif(($data['jenisAkta']==31)||($data['jenisAkta']==32)||($data['jenisAkta']==33)){
        	$data['template']=$this->template->getDataDocumentTemplate('15','30','490','201','');
		}*/else{
			show_404();
		}
        $this->load->view('generate_template/peradilan_agama/cetak_akta_kasasi',$data,FALSE);
	}
}