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

class c_template_relaas_agama extends CI_Controller {

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

    function popup_relaas(){
        if($this->session->userdata('is_logged_in')==FALSE){
        redirect('login'); }
        
        $segment = $this->uri->segment_array();
        $data['enc']=$this->uri->segment('3'); 
        $data['encsidang']=$this->uri->segment('4');
        $data['pihak_ke']=$this->uri->segment('5');
		$idjadwal =$this->encrypt->decode(base64_decode($data['encsidang']));
		//print_r($idjadwal);exit;
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));

        $this->load->model('generate_template/peradilan_agama/m_template_relaas_agama','template');
		$sidangke=$this->template->getTanggalPersidangan($idjadwal);	
		foreach($sidangke->result() as $row){
			$data['urutansidang']=$row->urutan;
		}
		
		$data['datajurusita']=$this->template->getDataJurusita($idperkara);
        $data['pihak']=$this->template->get_data_pihak_loop($idperkara,$data['pihak_ke']);

        $data['alurperkaraid'] =$this->template->getAlurPerkaraId($idperkara);
        $data['blangko_relaas']=$this->template->blangko_relaas($data['alurperkaraid']);
		$data['blangko_global']=$this->template->blangko_relaas_global();
        $idsidang=$this->encrypt->decode(base64_decode($data['encsidang']));
		//$data['urutan'] =$this->template->get_sidang_pertama_or_lanjutan($idperkara,$idsidang);
        $this->load->view('generate_template/peradilan_agama/popup_relaas', $data, FALSE);
    }

	function cetak_relaas(){  
        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){
            show_404();
            exit();
        }           
        $data['blangko_relaas'] = $this->input->post('blangko_relaas',TRUE);
        $data['encsidang']=$this->input->post('encsidang',TRUE);
        $idsidang=$this->encrypt->decode(base64_decode($data['encsidang']));
       // $filenya = $this->input->post('pilih_blangko',TRUE);
		$filenya="peradilan_agama/relaas/".$data['blangko_relaas'].".rtf";
		$filenya=str_replace('%20',' ',$filenya);
		$nama_jurusita = $this->input->post('nama_jurusita',TRUE);
		$data_id=array(
                    'source_file'=>$filenya,
                    'perkara_id'=>$idperkara,
					'jadwal_sidang_id'=>$idsidang,
					'jurusita_id'=>$nama_jurusita,
                    'pihak_id'=>$this->input->post('id_pihak',TRUE));  

        $this->load->model('generate_template/var_template_agama','var_template');
        $this->var_template->kirim_variabel($data_id);   
    }
	
	function popup_relaas_ikrar(){
        if($this->session->userdata('is_logged_in')==FALSE){
        redirect('login'); }

        $segment = $this->uri->segment_array();
        $data['enc']=$this->uri->segment('3'); 
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));
        

        
        $this->load->model('generate_template/peradilan_agama/m_template_relaas_agama','template');
        $data['blangko_relaas']=$this->template->blangko_relaas_ikrar();
        $data['datajurusita']=$this->template->getDataJurusita($idperkara);
        
       $this->load->view('generate_template/peradilan_agama/popup_relaas_ikrar', $data, FALSE);
    }

    function cetak_relaas_ikrar(){
        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){
            show_404();
            exit();
        }

       $temp = explode('|', $this->input->post('nama_jurusita',TRUE));
        $data['nama_jurusita'] = $temp[0];
        if($temp[1] == 1){
            $jabatan = 'Jurusita';
        }else{
            $jabatan = 'Jurusita Pengganti';
        }
        $data['jabatan'] = $jabatan;
        
        $data['blangko_relaas'] = $this->input->post('blangko_relaas',TRUE);
        
        $this->load->model('generate_template/m_template_penetapan_agama','template');
        $data['dataPihak1']=$this->template->get_data_pihak_loop($idperkara,1);
        $data['dataPihak2']=$this->template->get_data_pihak_loop($idperkara,2);
        $data['dataperkara'] = $this->template->getDataPerkara($idperkara);
        $data['datapengadilan'] = $this->template->getDataPA();
        //$data['datajurusita']=$this->template->getDataJurusitaIkrar($idperkara);
        $data['datapenetapansidang']=$this->template->getDataPenetapanSidangIkrar($idperkara);
        $data['dataputusan']=$this->template->getDataPutusan($idperkara);
        $this->load->view('generate_template/peradilan_agama/cetak_relaas_ikrar_talak',$data,FALSE);
    }
   
	function popup_template_pendukung(){
        if($this->session->userdata('is_logged_in')==FALSE){
        redirect('login'); }
        
        $segment = $this->uri->segment_array();
        $data['enc']=$this->uri->segment('3'); 
        $data['encsidang']=$this->uri->segment('4');
        $data['pihak_ke']=$this->uri->segment('5');
		$idjadwal =$this->encrypt->decode(base64_decode($data['encsidang']));
		if($data['pihak_ke'] ==1){ $penggugat =12;} else { $penggugat =14;}
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));

        $this->load->model('generate_template/peradilan_agama/m_template_relaas_agama','template');
		$sidangke=$this->template->getTanggalPersidangan($idjadwal);	
		foreach($sidangke->result() as $row){
			$data['urutansidang']=$row->urutan;
			$data['tanggal_sidang']=$this->tanggalhelper->convertDayDate($row->tanggal_sidang);
			
		}
		$getPerkara=$this->template->getDataPerkara($idperkara);	
		foreach($getPerkara->result() as $row){
			$data['nomor_perkara']=$row->nomor_perkara;
		}
		$databiayaPanggilan=$this->template->get_data_biaya_pihak($idperkara,$penggugat);
		foreach($databiayaPanggilan->result() as $row){
			$data['jumlahbiaya']=$row->jumlah;
		}
		
		$data['datajurusita']=$this->template->getDataJurusita($idperkara);
        $data['pihak']=$this->template->get_data_pihak_loop($idperkara,$data['pihak_ke']);

        $data['alurperkaraid'] =$this->template->getAlurPerkaraId($idperkara);
        $data['blangko_relaas']=$this->template->blangko_relaas($data['alurperkaraid']);
		$data['blangko_global']=$this->template->blangko_relaas_global();
        $idsidang=$this->encrypt->decode(base64_decode($data['encsidang']));
		//$data['urutan'] =$this->template->get_sidang_pertama_or_lanjutan($idperkara,$idsidang);
        $this->load->view('generate_template/peradilan_agama/popup_template_instrumen_panggilan', $data, FALSE);
    }
	function cetak_template_pendukung(){  
        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){
            show_404();
            exit();
        }           
        $data['blangko_relaas'] = "Instrumen Panggilan-Tanda Terima";
        $data['encsidang']=$this->input->post('encsidang',TRUE);
		
        $idsidang=$this->encrypt->decode(base64_decode($data['encsidang']));
     	$filenya="peradilan_agama/template_pendukung/".$data['blangko_relaas'].".rtf";
		$nama_jurusita = $this->input->post('nama_jurusita',TRUE);
		//$biaya = str_replace('.','',$this->input->post('biaya',TRUE));
		$biaya = $this->input->post('biaya',TRUE);
		$data_idpost =$this->templatehelper->Terbilang($biaya).' rupiah';
		$komar = $this->templatehelper->convertKeTglIndo(date());
		//print_r();exit;
		$data_id=array(
                    'source_file'=>$filenya,
                    'perkara_id'=>$idperkara,
					'jadwal_sidang_id'=>$idsidang,
					'jurusita_id'=>$nama_jurusita,
					'terbilang_post'=>$data_idpost,
					'angka_post'=>$biaya,
					'pihak_id'=>$this->input->post('id_pihak',TRUE));  
		$this->load->model('generate_template/var_template_agama','var_template');
        $this->var_template->kirim_variabel($data_id);   
    }
	function popup_template_amplop(){
        if($this->session->userdata('is_logged_in')==FALSE){
        redirect('login'); }
        
        $segment = $this->uri->segment_array();
        $data['enc']=$this->uri->segment('3'); 
        $data['encsidang']=$this->uri->segment('4');
        $data['pihak_ke']=$this->uri->segment('5');
		$idjadwal =$this->encrypt->decode(base64_decode($data['encsidang']));
		//print_r($idjadwal);exit;
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));

        $this->load->model('generate_template/peradilan_agama/m_template_relaas_agama','template');
		$sidangke=$this->template->getTanggalPersidangan($idjadwal);	
		foreach($sidangke->result() as $row){
			$data['urutansidang']=$row->urutan;
			$data['tanggal_sidang']=$this->tanggalhelper->convertDayDate($row->tanggal_sidang);
			
		}
		$getPerkara=$this->template->getDataPerkara($idperkara);	
		foreach($getPerkara->result() as $row){
			$data['nomor_perkara']=$row->nomor_perkara;
		}
		
		$data['datajurusita']=$this->template->getDataJurusita($idperkara);
        $data['pihak']=$this->template->get_data_pihak_loop($idperkara,$data['pihak_ke']);

        $data['alurperkaraid'] =$this->template->getAlurPerkaraId($idperkara);
        $data['blangko_relaas']=$this->template->blangko_relaas($data['alurperkaraid']);
		$data['blangko_global']=$this->template->blangko_relaas_global();
        $idsidang=$this->encrypt->decode(base64_decode($data['encsidang']));
		//$data['urutan'] =$this->template->get_sidang_pertama_or_lanjutan($idperkara,$idsidang);
        $this->load->view('generate_template/peradilan_agama/popup_template_amplop_panggilan', $data, FALSE);
    }
	function cetak_template_amplop(){  
        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){
            show_404();
            exit();
        }           
        $data['blangko_relaas'] = "amplop_relaas";
        $data['encsidang']=$this->input->post('encsidang',TRUE);
        $idsidang=$this->encrypt->decode(base64_decode($data['encsidang']));
       // $filenya = $this->input->post('pilih_blangko',TRUE);
		$filenya="peradilan_agama/template_pendukung/".$data['blangko_relaas'].".rtf";
		$nama_jurusita = $this->input->post('nama_jurusita',TRUE);
		$data_id=array(
                    'source_file'=>$filenya,
                    'perkara_id'=>$idperkara,
					'jadwal_sidang_id'=>$idsidang,
					'jurusita_id'=>$nama_jurusita,
                    'pihak_id'=>$this->input->post('id_pihak',TRUE));  
		$this->load->model('generate_template/var_template_agama','var_template');
        $this->var_template->kirim_variabel($data_id);   
    }
}
?>