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

$jenisAkta=intval($jenisAkta);
if(!is_numeric($jenisAkta)){
    show_404();
    exit();
}
//print_r($jenisAkta);
//exit();
foreach ($template->result() as $template2){
    $filename=$template2->kdtemplate;
    $namafile=str_replace(" ","",$template2->namatemplate);
}
$url = base_url("resources/template/relaas/perdata_agama/".$filename.".rtf");
$Template = file_get_contents($url);
//--------------MULAI--------------------------------------------//
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);
$Template = str_replace('#tglsekarang#',''.$this->templatehelper->convertKeTglIndo(date('Y-m-d')).'',$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);
}elseif($idpenandatangan==68){    
        $Template = str_replace('#pansek#',''.$pansek.'',$Template);
        $Template = str_replace('#jabatan#','Panitera',$Template);
}else if($idpenandatangan==70){
        $Template = str_replace('#pansek#',''.$wapan.'',$Template);
        $Template = str_replace('#jabatan#','a.n. Panitera',$Template);
}
#PENGADILAN DITUJU
if($jenisAkta==7 OR $jenisAkta==9 OR $jenisAkta==11 OR $jenisAkta==15 OR $jenisAkta==18 OR $jenisAkta==21 OR $jenisAkta==31 OR $jenisAkta==32 OR $jenisAkta==33){
    if($cetakNamaPN!=''){
        if($cetakNamaPN->num_rows>0){
            foreach ($cetakNamaPN->result() as $row) {
                $namaPengadilan = $this->templatehelper->standradnaming($row->nama);
            }
            $Template = str_replace('#namaPengadilan#',''.$namaPengadilan.'',$Template);
            $Template = str_replace('#namaKota#',''.$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;        
    }
}
$Template = str_replace('#nomorperkara#',''.$nomorperkara.'',$Template);
#DATA PERKARA PUTUSAN
$tglpts = '..............';
$tglputusan = '..............';
$amarpts = '..............';
$tglputusanpt = '..............';
$amarptspt = '..............';
$nomorptspt = '..............';
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_banding);     
    $amarptspt = $this->templatehelper->cleanHtmlTag($tglpts[0]->amar_putusan_banding);
    $nomorptspt = $tglpts[0]->nomor_putusan_banding;
}
$Template = str_replace('#tglputusan#',''.$tglputusan.'',$Template);
$Template = str_replace('#amarpts#',''.$amarpts.'',$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 PEMBANDING
$tglbanding = '..................';
$namapembanding = '..................';
$statuspembanding = '..................';
$memoribanding = '..................';
$kontrabanding = '..................';
if($jenisAkta>=1 && $jenisAkta<=12){
    if($cetaktglbanding!=''){
        if($cetaktglbanding->num_rows>0){
            foreach ($cetaktglbanding->result() as $row) {
                $tglbanding = $this->templatehelper->convertKeTglIndo($row->permohonan_banding);
                $namapembanding = $this->templatehelper->standradnaming($row->pemohon_nama);
                $statuspembanding = $row->status_pihak_text;
                $memoribanding = $this->templatehelper->convertKeTglIndo($row->penerimaan_memori_banding);
                $kontrabanding = $this->templatehelper->convertKeTglIndo($row->penerimaan_kontra_banding);
            } 
           
        }    
    }
}

 $Template = str_replace('#tglbanding#',''.$tglbanding.'',$Template);
            $Template = str_replace('#namapembanding#',''.$namapembanding.'',$Template);
            $Template = str_replace('#statuspembanding#',''.$statuspembanding.'',$Template);           
            $Template = str_replace('#memoribanding#',''.$memoribanding.'',$Template);
            $Template = str_replace('#kontrabanding#',''.$kontrabanding.'',$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;
    $statusbanding = $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('#statusbanding#',''.$statusbanding.'',$Template);

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

#looping pembanding
$dataPihakPembanding = "";
$i = 0;
if(!empty($infoallpembanding)){
        foreach ($infoallpembanding->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){                       
                $dataPihakPembanding .= " \b ".$this->templatehelper->standradnaming($rows->nama).", \b0 ";                
                $dataPihakPembanding .= "dulu sebagai ".$rows->pihak_asal_text." sekarang ".$rows->status_pihak_text." ; ".($rows->urutan_banding>1 ? " \\par ":"");                                                    
            }
            $i++;
        }
}
$Template = str_replace('#pihak_pembanding#',''.$dataPihakPembanding.'',$Template);
$pihakPembanding = "";
$i = 0;
if(!empty($infoallpembanding)){
        foreach ($infoallpembanding->result() as $rows) { 
            if(($rows->jenis_pihak_id)==1){                       
                $pihakPembanding .= "Nama \t:\t ".$this->templatehelper->standradnaming($rows->nama)." \\par ";
                $pihakPembanding .= "Kewarganegaraan \t:\t Indonesia \\par ";                                       
                $pihakPembanding .= "Tempat Tinggal \t:\t ".$rows->alamat." \\par ";                                                    
                $pihakPembanding .= "Pekerjaan \t:\t ".$rows->pekerjaan." \\par ";
                $pihakPembanding .= " \t \t Sebagai Pihak ".$rows->pihak_asal_text."/Pemohon Banding \\par \\par ";
            }elseif(($rows->jenis_pihak_id)==2 OR ($rows->jenis_pihak_id)==3 OR ($rows->jenis_pihak_id)==4 ){          
                $pihakPembanding .= "Nama Jabatan \t:\t ".$this->templatehelper->standradnaming($rows->nama)." \\par ";
                $pihakPembanding .= "Tempat Kedudukan \t:\t ".$rows->alamat." \\par \\par "; 
                $pihakPembanding .= " \t \t Sebagai Pihak ".$rows->pihak_asal_text."/Pemohon Banding \\par \\par ";                                                      
            }
            $i++;
        }
}
$Template = str_replace('#pihak_pembanding_looping#',''.$pihakPembanding.'',$Template);
#looping terbanding
$dataPihakTerbanding = "";
$i = 0;
if(!empty($infoallterbanding)){
        foreach ($infoallterbanding->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){  
                $dataPihakTerbanding .= " \b ".$this->templatehelper->standradnaming($rows->nama).", \b0 ";                
                $dataPihakTerbanding .= "dulu sebagai ".$rows->pihak_asal_text." sekarang ".$rows->status_pihak_text." ; ".($rows->urutan_banding>1 ? " \\par ":"");                                                                                                        
            }
            $i++;
        }
}
$Template = str_replace('#pihak_terbanding#',''.$dataPihakTerbanding.'',$Template);

$pihakTerbanding = "";
$i = 0;
if(!empty($infoallterbanding)){
        foreach ($infoallterbanding->result() as $rows) { 
            if(($rows->jenis_pihak_id)==1){                       
                $pihakTerbanding .= "Nama \t:\t ".$this->templatehelper->standradnaming($rows->nama)." \\par ";
                $pihakTerbanding .= "Kewarganegaraan \t:\t Indonesia \\par ";                                       
                $pihakTerbanding .= "Tempat Tinggal \t:\t ".$rows->alamat." \\par ";                                                    
                $pihakTerbanding .= "Pekerjaan \t:\t ".$rows->pekerjaan." \\par ";
                $pihakTerbanding .= " \t \t Sebagai Pihak ".$rows->pihak_asal_text."/Termohon Banding \\par \\par ";
            }elseif(($rows->jenis_pihak_id)==2 OR ($rows->jenis_pihak_id)==3 OR ($rows->jenis_pihak_id)==4 ){          
                $pihakTerbanding .= "Nama Jabatan \t:\t ".$this->templatehelper->standradnaming($rows->nama)." \\par ";
                $pihakTerbanding .= "Tempat Kedudukan \t:\t ".$rows->alamat." \\par ";
                $pihakTerbanding .= " \t \t Sebagai Pihak ".$rows->pihak_asal_text."/Termohon Banding \\par \\par ";                                                       
            }
            $i++;
        }
}
$Template = str_replace('#pihak_terbanding_looping#',''.$pihakTerbanding.'',$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);

$temp = explode(' ', $namapa);
$Template = str_replace("#pa/ms#",''.$temp[0].' '.$temp[1].'',$Template);
//exit();
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;
?>