<?php
if($this->session->userdata('is_logged_in')===FALSE){
            redirect('login');
}

$jenisAkta=intval($jenisAkta);
if(!is_numeric($jenisAkta)){
    show_404();
    exit();
}

foreach ($template->result() as $template){
    $filename=$template->kdtemplate;
    $namafile=str_replace(" ","",$template->namatemplate);
}
$url = base_url("resources/template/relaas/perdata_agama/".$filename.".rtf");
$Template = file_get_contents($url);

if(!empty($dataPN)){
    foreach ($dataPN->result() as $row) {
        $namapa = $this->templatehelper->standradnaming($row->NamaPN);
        $alamatpn = $this->templatehelper->standradnaming($row->AlamatPN);
        $namapt = $this->templatehelper->standradnaming($row->NamaPT);
        $pansek = $this->templatehelper->standradnaming($row->Panses);
        $wapan = $this->templatehelper->standradnaming($row->Wapan);
        $Ketua = $this->templatehelper->standradnaming($row->Ketua);
        $Wakilketua = $this->templatehelper->standradnaming($row->Wakilketua);
    }
}
$Template = str_replace('#namapa#',''.$namapa.'',$Template);
$Template = str_replace('#kotakantor#',''.$this->templatehelper->namaKotaPA($namapa).'',$Template);
$Template = str_replace('#alamatpn#',''.$alamatpn.'',$Template);
$Template = str_replace('#namapt#',''.$namapt.'',$Template);
if($idpenandatangan==64){    
        $Template = str_replace('#ketua#',''.$Ketua.'',$Template);
        $Template = str_replace('#jabatan#','Ketua',$Template);
}else if($idpenandatangan==66){
        $Template = str_replace('#ketua#',''.$Wakilketua.'',$Template);
        $Template = str_replace('#jabatan#','Wakil Ketua',$Template);
}
#PENGADILAN DITUJU
if($jenisAkta==7 OR $jenisAkta==9 OR $jenisAkta==11 OR $jenisAkta==15 OR $jenisAkta==18 OR $jenisAkta==21){
    if($cetakNamaPN!=''){
        if($cetakNamaPN->num_rows>0){
            foreach ($cetakNamaPN->result() as $row) {
                $namaPengadilan = $this->templatehelper->standradnaming($row->nama);
            }
            $Template = str_replace('#namaPengadilanTujuan#',''.$namaPengadilan.'',$Template);
            $Template = str_replace('#namaKotaTujuan#',''.$this->templatehelper->namaKotaPA($namaPengadilan).'',$Template);
            $Template = str_replace('#tglsurat#',''.$this->templatehelper->convertKeTglIndo($tgldelegasi).'',$Template);
            $tahunSurat = substr($tgldelegasi,0,4);$bulanSurat = substr($tgldelegasi,5,2);
            $Template = str_replace('#tahunSurat#',''.$tahunSurat.'',$Template);
            $Template = str_replace('#bulanSurat#',''.$bulanSurat.'',$Template);
            $Template = str_replace('#biayapemberitahuan#',number_format(strval($biayapemberitahuan),2,",","."),$Template);
            $Template = str_replace('#biayaterbilang#',''.$this->templatehelper->Terbilang($biayapemberitahuan).' rupiah',$Template);
        }
    }
}
#DATA JURUSITA
if($cetakJurusita!=''){
    if($cetakJurusita->num_rows>0){
        foreach ($cetakJurusita->result() as $jurusita) {
            $namajurusita = $this->templatehelper->standradnaming($jurusita->nama_gelar);
            $jabatanjurusita = $this->templatehelper->standradnaming($jurusita->jabatan);
        }
        $Template = str_replace('#namajurusita#',''.$namajurusita.'',$Template);
		
		if($jabatanjurusita==1){
			$Template = str_replace('#jabatanjurusita#',''."Jurusita".'',$Template);
		}else{
			$Template = str_replace('#jabatanjurusita#',''."Jurusita Pengganti".'',$Template);
		}
    }
}
#DATA PERKARA
if(!empty($dataPerkara)){
    foreach ($dataPerkara->result() as $row) {
        $nomorperkara = $row->nomor_perkara;        
        $tglPendaftaran = $row->tanggal_pendaftaran;
    }
}
$Template = str_replace('#nomorperkara#',''.$nomorperkara.'',$Template);
#DATA PERKARA PUTUSAN
if(!empty($tanggalPutus)){
    $tglpts = $tanggalPutus->result();
    $tglputusan = $this->templatehelper->convertKeTglIndo($tglpts[0]->tanggal_putusan);     
    $amarpts = $this->templatehelper->cleanHtmlTag($tglpts[0]->amar_putusan);
    $tglputusanpt = $this->templatehelper->convertKeTglIndo($tglpts[0]->putusan_pk);     
    $amarptspt = $this->templatehelper->cleanHtmlTag($tglpts[0]->amar_putusan_pk);
    $nomorptspt = $tglpts[0]->nomor_putusan_pk;
}
$Template = str_replace('#tglputusan#',''.$tglputusan.'',$Template);
$Template = str_replace('#amarpts#',''.$amarpts.'',$Template);
$Template = str_replace('#tglPendaftaran#',''.$this->templatehelper->convertKeTglIndo($tglPendaftaran).'',$Template);
$Template = str_replace('#tglPenerimaan#',''.$this->templatehelper->convertKeTglIndo($tglPenerimaan).'',$Template);
$Template = str_replace('#tglPemberitahuan#',''.$this->templatehelper->convertKeTglIndo($tglpemberitahuan).'',$Template);
$Template = str_replace('#hariPemberitahuan#',''.$this->templatehelper->getHari($tglpemberitahuan).'',$Template);
$Template = str_replace('#nomorptspt#',''.$nomorptspt.'',$Template);
$Template = str_replace('#amarptspt#',''.$amarptspt.'',$Template);
$Template = str_replace('#tglputusanpt#',''.$tglputusanpt.'',$Template);
#DATA PEMpk
$tglpk = '..................';
$namapempk = '..................';
$statuspempk = '..................';
$memoripk = '..................';
$kontrapk = '..................';
if($jenisAkta>=1 && $jenisAkta<=19){
    if($cetaktglpk!=''){
        if($cetaktglpk->num_rows>0){
            foreach ($cetaktglpk->result() as $row) {
                $tglpk = $this->templatehelper->convertKeTglIndo($row->permohonan_pk);
                $namapempk = $this->templatehelper->standradnaming($row->pemohon_nama);
                $statuspempk = $row->status_pihak_text;
                $memoripk = $this->templatehelper->convertKeTglIndo($row->penerimaan_memori_pk);
                $kontrapk = $this->templatehelper->convertKeTglIndo($row->penerimaan_kontra_pk);
            } 
			$Template = str_replace('#tglpk#',''.$tglpk.'',$Template);
            $Template = str_replace('#namapempk#',''.$namapempk.'',$Template);
            $Template = str_replace('#statuspempk#',''.$statuspempk.'',$Template);           
            $Template = str_replace('#memoripk#',''.$memoripk.'',$Template);
            $Template = str_replace('#kontrapk#',''.$kontrapk.'',$Template);
        }    
    }
} 

#DATA PIHAK
$namaPihak = '..................';
$tempattinggal = '..................';
$pekerjaan = '..................';
$pihakasal = '..................';
$umur = '..................';
$agama = '..................';
$pendidikan = '..................';

if(!empty($infoPihak)){
    $infopihak = $infoPihak->result();        
    $namaPihak = $this->templatehelper->standradnaming($infopihak[0]->nama);    
    $tempattinggal = $infopihak[0]->alamat;
    $pekerjaan = $infopihak[0]->pekerjaan;
    $umur = $infopihak[0]->umur;
    $agama = $infopihak[0]->agama;
    $pendidikan = $infopihak[0]->pendidikan;
    $pihakasal = $infopihak[0]->pihak_asal_text;
    $statuspk = $infopihak[0]->status_pihak_text;
    $idjenispihak = $infopihak[0]->jenis_pihak_id;
}    

$Template = str_replace('#namaPihak#',''.$namaPihak.'',$Template);
$Template = str_replace('#umur#',$umur,$Template);
$Template = str_replace('#agama#',$agama,$Template);
$Template = str_replace('#pendidikan#',$pendidikan,$Template);
$Template = str_replace('#tempattinggal#',''.$tempattinggal.'',$Template);
$Template = str_replace('#pekerjaan#',''.$pekerjaan.'',$Template);
$Template = str_replace('#pihakasal#',''.$pihakasal.'',$Template);
$Template = str_replace('#statuspk#',''.$statuspk.'',$Template);

$jenisPihak='';
if($idjenispihak==1 OR $idjenispihak==2 OR $idjenispihak==3 OR $idjenispihak==4){
    $jenisPihak .= $namaPihak.", umur ".$umur." tahun, agama ".$agama.", pekerjaan ".$pekerjaan.", pendidikan terakhir ".$pendidikan.", bertempat tinggal/kediaman ".$tempattinggal.",";
    $jenisPihak .= " dahulu sebagai ".$pihakasal." sekarang ".$statuspk;  
}                                        
$Template = str_replace('#pihakdelegasi#',''.$jenisPihak.'',$Template);    


#looping pempk
$dataPihakPemohonPK = "";
$i = 0;
if(!empty($infoallpemohonpk)){
        foreach ($infoallpemohonpk->result() as $rows) { 
            if(($rows->jenis_pihak_id)==1 OR ($rows->jenis_pihak_id)==2 OR ($rows->jenis_pihak_id)==3 OR ($rows->jenis_pihak_id)==4){                       
                $dataPihakPemohonPK .= " \b ".$this->templatehelper->standradnaming($rows->nama).", \b0 ";                
                $dataPihakPemohonPK .= "dulu sebagai ".$rows->pihak_asal_text." sekarang ".$rows->status_pihak_text." ; ".($rows->urutan_pk>1 ? " \\par ":"");                                                    
            }
            $i++;
        }
}
$Template = str_replace('#pihak_pemohonpk#',''.$dataPihakPemohonPK.'',$Template);

$dataPihakTermohonPK = "";
$i = 0;
if(!empty($infoalltermohonPK)){
        foreach ($infoalltermohonPK->result() as $rows) { 
            if(($rows->jenis_pihak_id)==1 OR ($rows->jenis_pihak_id)==2 OR ($rows->jenis_pihak_id)==3 OR ($rows->jenis_pihak_id)==4){                       
                $dataPihakTermohonPK .= " \b ".$this->templatehelper->standradnaming($rows->nama).", \b0 ";                
                $dataPihakTermohonPK .= "dulu sebagai ".$rows->pihak_asal_text." sekarang ".$rows->status_pihak_text." ; ".($rows->urutan_pk>1 ? " \\par ":"");                                                    
            }
            $i++;
        }
}

$Template = str_replace('#pihak_termohonpk#',''.$dataPihakTermohonPK.'',$Template);


$jenisputusan = "...........................";
$nomorputusan = "...........................";
$tanggalputusan = "...........................";
if(!empty($infopkTerhadap)){
    if($infopkTerhadap->num_rows>0){
        foreach ($infopkTerhadap->result() as $row) {
            $jenisputusan = $this->templatehelper->standradnaming($row->namasatker);
            $nomorputusan = $row->nomor_perkara;
            $tanggalputusan = $row->tglputusan;
        }
    }
}



$Template = str_replace('#jenisputusan#',''.$jenisputusan.'',$Template);
$Template = str_replace('#nomorputusan#',''.$nomorputusan.'',$Template);
$Template = str_replace('#tanggalputusan#',''.$tanggalputusan.'',$Template);

$Template = str_replace("#TGL_SEKARANG#",$this->templatehelper->convertKeTglIndo(date('Y-m-d')),$Template);
$Template = str_replace("#HARI_INI#",$this->templatehelper->gethari(date('Y-m-d')),$Template);


header("Content-Type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control:  must-revalidate, post-check=0, pre-check=0");
header("Content-disposition: attachment; filename=\"".$namafile."-".$nomorperkara.".rtf\"");
echo $Template;
?>