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

foreach ($template->result() as $template){
    $filename=$template->kdtemplate;
    $namafile=str_replace(" ","",$template->namatemplate);
}

$url = base_url("resources/template/relaas/perdata_tun/".$filename.".rtf");

$Template = file_get_contents($url);
//-------Data PN--------------------------------------//
if(!empty($datapenetapan)){
    if($datapenetapan->num_rows>0){
        foreach ($datapenetapan->result() as $row) {
            $nomorperkara = $row->nomor_perkara;
            if(!empty($row->tanggal_surat)){
                $tanggal_surat = $this->templatehelper->convertKeTglIndo($row->tanggal_surat);
            }else{
                $tanggal_surat = '.........';
            }
            $tgl_pendaftaran = $this->templatehelper->convertKeTglIndo($row->tanggal_pendaftaran);
            $tanggal_penetapan = $this->templatehelper->convertKeTglIndo($row->tanggal_penetapan);
            $tgl_musyawarah = $this->templatehelper->convertKeTglIndo($row->tanggal_musyawarah);
            $hari_musyawarah = $this->templatehelper->getHari($row->tanggal_musyawarah);                                       
            $jam_panggilan = substr($row->waktu_musyawarah, 0, 5);
            $tanggal_penetapan_persiapan = $this->templatehelper->convertKeTglIndo($row->tanggal_penetapan_persiapan);
            $hakim_nama = $this->templatehelper->standradnaming($row->hakim_nama);
        }
    }
}

$datapengadilan = $datapn;
if(!empty($datapengadilan)){
    if($datapengadilan->num_rows>0){
        foreach ($datapengadilan->result() as $row) {
            $namapn = $this->templatehelper->standradnaming($row->NamaPN);
            $namakota = str_replace("Pengadilan Tata Usaha Negara ",'',$namapn);   
            $alamatpn = $row->AlamatPN;
        }
    }
}
    
if(empty($namapn)){ $namapn = '........'; }
if(empty($alamatpn)){ $alamatpn = '........'; }

$nomorpkrbaru = str_replace('G', 'PEN-PP', $nomorperkara);
$nomormajelis = str_replace('G', 'PEN-MH', $nomorperkara);

$Template = str_replace('#nomor_perkara#',''.$nomorperkara.'',$Template);
$Template = str_replace('#nomorpkrbaru#',''.$nomorpkrbaru.'',$Template);
$Template = str_replace('#nomormajelis#',''.$nomormajelis.'',$Template);
$Template = str_replace('#tanggal_surat#',''.$tanggal_surat.'',$Template);
$Template = str_replace('#tgl_pendaftaran#',''.$tgl_pendaftaran.'',$Template);
$Template = str_replace('#tanggal_penetapan#',''.$tanggal_penetapan.'',$Template);
$Template = str_replace('#tgl_musyawarah#',''.$tgl_musyawarah.'',$Template);
$Template = str_replace('#hari_musyawarah#',''.$hari_musyawarah.'',$Template);
$Template = str_replace('#jam_panggilan#',''.$jam_panggilan.'',$Template);
$Template = str_replace('#tanggal_penetapan_persiapan#',''.$tanggal_penetapan_persiapan.'',$Template);
$Template = str_replace('#nama_pn#',''.$namapn.'',$Template);
$Template = str_replace('#namakota#',''.$namakota.'',$Template);
$Template = str_replace('#alamatpn#',''.$alamatpn.'',$Template);
$Template = str_replace('#hakim_nama#',''.$hakim_nama.'',$Template);

$dataPihakP = "";
$i = 0;
$jmlpihak = $datapihakpenggugat->num_rows;
if(!empty($datapihakpenggugat)){
        foreach ($datapihakpenggugat->result() as $rows) {  
            $dataPihakP .= " \b ".$this->templatehelper->standradnaming($rows->nama).", \b0 kewarganegaraan Indonesia, pekerjaan ".$rows->pekerjaan.", beralamat di ".$rows->alamat;
            $dataPihakP .= " selanjutnya disebut sebagai \b PENGGUGAT ".($jmlpihak>1 ? $this->templatehelper->converToAngkaRomawi($rows->urutan) : '')."; \b0 \\par ";
            $i++;           
        }                        
}
$Template = str_replace('#pihak_penggugat#',''.$dataPihakP.'',$Template);

$dataPihakT = "";
$i = 0;
$jmlpihak = $datapihaktergugat->num_rows;
if(!empty($datapihaktergugat)){
        foreach ($datapihaktergugat->result() as $rows) {            
            $dataPihakT .= " \b ".$this->templatehelper->standradnaming($rows->nama).", \b0 kewarganegaraan Indonesia, pekerjaan ".$rows->pekerjaan.", beralamat di ".$rows->alamat;
            $dataPihakT .= " selanjutnya disebut sebagai \b TERGUGAT ".($jmlpihak>1 ? $this->templatehelper->converToAngkaRomawi($rows->urutan) : '')."; \b0 \\par ";   
            $i++;                      
        }
}
$Template = str_replace('#pihak_tergugat#',''.$dataPihakT.'',$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;
?>