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

$jenisAkta=intval($jenisAkta);
if(!is_numeric($jenisAkta)){
    show_404();
    exit();
}
$penandatangan=$this->encrypt->decode(base64_decode($penandatangan));
$penandatangan=intval($penandatangan);
if(!is_numeric($penandatangan)){
    show_404();
    exit();
}

foreach ($template->result() as $template){
    $filename=$template->kdtemplate;
    $namafile=str_replace(" ","",$template->namatemplate);
}
$url = base_url("resources/template/akta/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);
    }
}
$Template = str_replace('#namapa#',''.$namapa.'',$Template);
$Template = str_replace('#namakota#',''.$this->templatehelper->namaKotaPA($namapa).'',$Template);
$Template = str_replace('#tglsekarang#',''.$this->templatehelper->convertKeTglIndo(date('Y-m-d')).'',$Template);
$Template = str_replace('#alamatpn#',''.$alamatpn.'',$Template);
$Template = str_replace('#namapt#',''.$namapt.'',$Template);
if($penandatangan==68){    
        $Template = str_replace('#pansek#',''.$pansek.'',$Template);
        $Template = str_replace('#jabatan#','Panitera',$Template);
}else if($penandatangan==70){
        $Template = str_replace('#pansek#',''.$wapan.'',$Template);
        $Template = str_replace('#jabatan#','a.n. Panitera',$Template);
}
#DATA PERKARA
if(!empty($dataPerkara)){
    foreach ($dataPerkara->result() as $row) {
        $nomorperkara = $row->nomor_perkara;        
    }
}
$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);
}
$Template = str_replace('#tglputusan#',''.$tglputusan.'',$Template);
$Template = str_replace('#amarpts#',''.$amarpts.'',$Template);
//if($jenisAkta>=1 && $jenisAkta<=18 ){
    $Template = str_replace('#haripermohonanbanding#',''.$this->templatehelper->getHari($tglpermohonan).'',$Template);
    $Template = str_replace('#tglpermohonanbanding#',''.$this->templatehelper->convertKeTglIndo($tglpermohonan).'',$Template);    
/*}else{
    $Template = str_replace('#tglsurat#',''.$this->templatehelper->convertKeTglIndo($tglsurat).'',$Template);    
    $Template = str_replace('#nomorsurat#',''.$nomorsurat.'',$Template);
    $Template = str_replace('#haricabut#',''.$this->templatehelper->getHari($tglcabut).'',$Template);
    $Template = str_replace('#tglcabut#',''.$this->templatehelper->convertKeTglIndo($tglcabut).'',$Template);
}*/
#DATAPEMBANDING
$pemohonBanding = '';
if($jenisAkta==1 OR $jenisAkta==3 OR $jenisAkta==5 OR $jenisAkta==10 OR $jenisAkta==11 OR $jenisAkta==12 OR $jenisAkta==19 OR $jenisAkta==20 OR $jenisAkta==21 OR $jenisAkta==22 OR $jenisAkta==23 OR $jenisAkta==24){
    if(!empty($infopembanding)){
        foreach ($infopembanding->result() as $row) { 
            $namapembanding = $this->templatehelper->standradnaming($row->pemohon_nama);                      
            $pemohonBanding .= 'nama '.$namapembanding.', umur '.$row->umur.' tahun, agama '.$row->agama.', pekerjaan '.$row->pekerjaan.', pendidik terakhir '.$row->pendidikan.', tempat tinggal / kediaman '.$row->alamat.',';
            $pemohonBanding .= ' dahulu sebagai '.$row->pihak_asal_text.' sekarang '.$row->status_pihak_text;            
        }        
    }    
    $Template = str_replace('#pemohonbanding#',''.$pemohonBanding.'',$Template);    
    $Template = str_replace('#namapembanding#',''.$namapembanding.'',$Template);
}
if($jenisAkta==13 OR $jenisAkta==14 OR $jenisAkta==15 OR $jenisAkta==16 OR $jenisAkta==17 OR $jenisAkta==18){
    if(!empty($infoPihak)){
        foreach ($infoPihak->result() as $row) { 
            $namapembanding = $this->templatehelper->standradnaming($row->nama);                      
            $pemohonBanding .= 'nama '.$namapembanding.', umur '.$row->umur.' tahun, agama '.$row->agama.', pekerjaan '.$row->pekerjaan.', pendidik terakhir '.$row->pendidikan.', tempat tinggal / kediaman '.$row->alamat.',';
            $pemohonBanding .= ' dahulu sebagai '.$row->pihak_asal_text.' sekarang '.$row->status_pihak_text;            
        }        
    }    
    $Template = str_replace('#pemohonbanding#',''.$pemohonBanding.'',$Template);    
    $Template = str_replace('#namapembanding#',''.$namapembanding.'',$Template);
}

#DATAKUASAPENGGUGAT
$pemohonkuasa = '';
$tglkuasa = '...............';
$nomorKuasa = '...............';
if($jenisAkta==2 OR $jenisAkta==4 OR $jenisAkta==6 OR $jenisAkta==7 OR $jenisAkta==8 OR $jenisAkta==9){
    if(!empty($infoKuasaPihak)){
        foreach ($infoKuasaPihak->result() as $kuasa) {
            $namakuasa = $this->templatehelper->standradnaming($kuasa->nama);
            $tglkuasa = $this->templatehelper->convertKeTglIndo($kuasa->tglKuasa);
            $nomorKuasa = $kuasa->nomorKuasa;
            $statusPihak = $kuasa->status_pihak_text;
            $namapihakdiwakili = $this->templatehelper->standradnaming($kuasa->pihakdiwakili);
            $pemohonkuasa = 'Nama '.$namakuasa.' umur '.$kuasa->umur.' tahun, agama '.$kuasa->agama.', pekerjaan Advokat / Pengacara, yang beralamat di '.$kuasa->alamat;
        }                        
    }    
    $Template = str_replace('#namakuasa#',''.$namakuasa.'',$Template);
    $Template = str_replace('#pemohonkuasa#',''.$pemohonkuasa.'',$Template);
    $Template = str_replace('#nomorKuasa#',''.$nomorKuasa.'',$Template);    
    $Template = str_replace('#tglkuasa#',''.$tglkuasa.'',$Template);
    $Template = str_replace('#statuspihak#',''.$statusPihak.'',$Template);
    $Template = str_replace('#namapihakdiwakili#',''.$namapihakdiwakili.'',$Template);
}

#looping pembanding
$dataPihakPembanding = "";
$i = 0;
if(!empty($infoallpembanding)){
        foreach ($infoallpembanding->result() as $rows) {                                   
                $dataPihakPembanding .= " \b ".$this->templatehelper->standradnaming($rows->nama)." \b0  ";                                                    
                $dataPihakPembanding .= " sebagai \b ".$rows->pihak_asal_text." \b0  sekarang \b ".$rows->status_pihak_text." \b0 ; ".($rows->urutan_banding>1 ? ' \\par ':'');
                
        }
        $i++;
}
$Template = str_replace('#pihak_pembanding#',''.$dataPihakPembanding.'',$Template);
#looping terbanding
$dataPihakTerbanding = "";
$i = 0;
if(!empty($infoallterbanding)){
        foreach ($infoallterbanding->result() as $rows) {  
                $namaterbanding = $this->templatehelper->standradnaming($rows->nama);                     
                $dataPihakTerbanding .= " \b ".$this->templatehelper->standradnaming($rows->nama).", \b0 ";                                                      
                $dataPihakTerbanding .= " sebagai \b ".$rows->pihak_asal_text." \b0  sekarang \b ".$rows->status_pihak_text." \b0 ; ".($rows->urutan_banding>1 ? ' \\par ':'');
        }
        $i++;        
}
$Template = str_replace('#pihak_terbanding#',''.$dataPihakTerbanding.'',$Template);
$Template = str_replace('#namaterbanding#',''.$namaterbanding.'',$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;

?>