<?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);
//=============================================roby======================================================
$perkara = $dataTemplate;
$itunganPerkara = count($perkara);
$terpidana = array();
foreach ($perkara->result() as $perkara) {
			/*$itemPihak2= array();
			$itemPihak2['namaPihak']  = $this->templatehelper->standradnaming($perkara->namaPihak);
	        $itemPihak2['alamatPihak'] = $this->templatehelper->standradnaming($perkara->alamatPihak);
	        $itemPihak2['tempatLahirPihak'] = $perkara->tempatLahirPihak;
	        $itemPihak2['tanggalLahirPihak'] = $this->templatehelper->convertKeTglIndo($perkara->tanggalLahirPihak);
	        $itemPihak2['umurPihak'] = $this->tanggalhelper->getSelisihTahun($perkara->tanggalLahirPihak,date('Y-m-d'));
	        $itemPihak2['kelaminPihak'] = $perkara->kelaminPihak;
	        $itemPihak2['agamaPihak'] = $perkara->agamaPihak;
	        $itemPihak2['pekerjaanPihak'] = $this->templatehelper->standradnaming($perkara->pekerjaanPihak);
	        $itemPihak2['negaraPihak'] = $perkara->negaraPihak;
	        $pihak2[]= $itemPihak2; */

			$nomorPerkara = $perkara->nomor_perkara;
			$no = explode("/",$perkara->nomor_perkara);
			$nomor = $no[0];
			$kodePerkara = $no[1];
			$tahunPerkara = $no[2];
			$kodePN = $no[3];
			$nomorPermohonan = $nomor."/Akta ".$kodePerkara."/".$tahunPerkara."/".$kodePN;
			$namaPN = $this->templatehelper->standradnaming($perkara->namaPengadilan);
			$namaPanitera = $this->templatehelper->standradnaming($perkara->pw);
			$tahapan = $this->templatehelper->standradnaming($perkara->Tahapan);
			$noPerkaraTahapan = $this->templatehelper->standradnaming($perkara->nomorPerkaraTahapan);
			$tglPutusTahapan = $this->templatehelper->convertKeTglIndo($perkara->putusan);
			$statusPanitera = $this->templatehelper->standradnaming($perkara->pejabat);			
			//$namajaksa = $this->templatehelper->standradnaming($perkara->namaPihak);
			$nomorPerkaraKasasi = $this->templatehelper->standradnaming($perkara->nomor_perkara_kasasi);
			$tglPutusKasasi = $this->templatehelper->convertKeTglIndo($perkara->putusan_kasasi);
			$amarPutPK = $this->templatehelper->cleanHtmlTag($perkara->amar_putusan_pk);
			//$alamatJaksa = $this->templatehelper->standradnaming($perkara->alamat_kantor);
			$namaPihak = $perkara->namaPihak;
			$pekerjaanPihak = $perkara->pekerjaanPihak;
			$alamatPihak = $perkara->alamatPihak;
			$penerimanMemoriPK = $this->templatehelper->convertKeTglIndo($perkara->penerimaan_memori_pk);
			$penyerahanMemoriPK = $this->templatehelper->convertKeTglIndo($perkara->penyerahan_memori_pk);
			if(!empty($perkara->pemberitahuan_putusan_pk)){
				$tglPemberitahuan_pk = $this->templatehelper->convertKeTglIndo($perkara->pemberitahuan_putusan_pk);
				$hariPemberitahuanPK = $this->templatehelper->getHari($perkara->pemberitahuan_putusan_pk);
			}else{
				$tglPemberitahuan_pk = '.............';
				$hariPemberitahuanPK = '.............';
			}
 }

	if (!empty($datapihaktergugat)){
	$pihak2 = $datapihaktergugat;
	foreach ($pihak2->result() as $rows) {
		$namaPihak2 = $this->templatehelper->standradnaming($rows->nama);
		$pekerjaanPihak2 = $this->templatehelper->standradnaming($rows->pekerjaan);
		$alamatPihak2 = $this->templatehelper->standradnaming($rows->alamat);
		}
	}
	$Template = str_replace('#namaPihak2#',''.$namaPihak2.'',$Template);
	$Template = str_replace('#pekerjaanPihak2#',''.$pekerjaanPihak2.'',$Template);
	$Template = str_replace('#alamatPihak2#',''.$alamatPihak2.'',$Template);

	if(empty($namaPihak2)){ $namaPihak2 = '....................'; }
	if(empty($pekerjaanPihak2)){ $pekerjaanPihak2 = '....................'; }
	if(empty($alamatPihak2)){ $alamatPihak2 = '....................'; }

	//$infoIntervensi='';
	//$jmlPihakIntervensi=$datapihaktergugat->num_rows;
	//$i=0;
	if (!empty($datapihakintervensi)){
	$pihak4 = $datapihakintervensi;
	foreach ($pihak4->result() as $rows) {
		//$infoIntervensi.=', Dan' 
		$namaPihak4 = $this->templatehelper->standradnaming($rows->nama);
		$pekerjaanPihak4 = $this->templatehelper->standradnaming($rows->pekerjaan); 
		$alamatPihak4 = $this->templatehelper->standradnaming($rows->alamat);
		}
	}

	/*$infoTergugat='';
	$jmlPihak2=$datapihaktergugat->num_rows;
	$i=0;
	if (!empty($datapihaktergugat)) {
		foreach ($datapihaktergugat->result() as $row) {
			$infoTergugat .= $this->templatehelper->standradnaming($row->nama).' Warga negara Indonesia, pekerjaan '.$row->pekerjaan;
			$infoTergugat .= ', Tempat tinggal di '.$row->alamat;
			$infoTergugat .= ', untuk selanjutnya disebut sebagai Tergugat '.$jmlPihak2>1?$this->templatehelper->converToAngkaRomawi($row->urutan):'';
		}
	}
	$Template = str_replace('#infoTergugat#',''.$infoTergugat.'',$Template);
	if(empty($infoTergugat)){ $infoTergugat = '....................'; }
	*/

	if(empty($namaPihak4)){ $namaPihak4 = '....................'; }
	if(empty($pekerjaanPihak4)){ $pekerjaanPihak4 = '....................'; }
	if(empty($alamatPihak4)){ $alamatPihak4 = '....................'; }

	if(empty($nomorPerkara)){ $nomorPerkara = '....................'; }
	if(empty($no)){ $no = '....................'; }
	if(empty($nomor)){ $nomor = '....................'; }
	if(empty($kodePerkara)){ $kodePerkara = '....................'; }
	if(empty($tahunPerkara)){ $tahunPerkara = '....................'; }
	if(empty($kodePN)){ $kodePN = '....................'; }
	if(empty($nomorPermohonan)){ $nomorPermohonan = '....................'; }
	if(empty($namaPN)){ $namaPN = '........'; }
	if(empty($namaPanitera)){ $namaPanitera = '....................'; }
	if(empty($tahapan)){ $tahapan = '....................'; }
	if(empty($noPerkaraTahapan)){ $noPerkaraTahapan = '....................'; }
	if(empty($tglPutusTahapan)){ $tglPutusTahapan = '....................'; }
	if(empty($statusPanitera)){ $statusPanitera = '....................'; }
	if(empty($nomorPerkaraKasasi)){ $nomorPerkaraKasasi = '....................'; }
	if(empty($tglPutusKasasi)){ $tglPutusKasasi = '....................'; }
	if(empty($amarPutPK)){ $amarPutPK = '....................'; }
	if(empty($namaPihak)){ $namaPihak = '....................'; }
	if(empty($pekerjaanPihak)){ $pekerjaanPihak = '....................'; }
	if(empty($alamatPihak)){ $alamatPihak = '....................'; }
	if(empty($penerimanMemoriPK)){ $penerimanMemoriPK = '....................'; }
	if(empty($penyerahanMemoriPK)){ $penyerahanMemoriPK = '....................'; }

/*if (!empty($DataJaksaKasasi)){
	$jaksa = $DataJaksaKasasi;
	foreach ($jaksa->result() as $rows) {
		$namaJaksa = $this->templatehelper->standradnaming($rows->nama);
		$nipJaksa = $rows->NIP;
		$pekerjaan = $this->templatehelper->standradnaming($rows->pekerjaan);
		$kejaksaan = $this->templatehelper->standradnaming($rows->kejaksaan);
		$alamatJaksa = $this->templatehelper->standradnaming($rows->alamat_kantor);
	}
}
if(!empty($cetakJurusita)){
	$juru = $cetakJurusita;
	foreach ($juru->result() as $sita) {
		$namaJurusita = $this->templatehelper->standradnaming($sita->nama_gelar);
	}
} */
//==============================================================================//
$Template = str_replace('#nomorperkara#',''.$nomorPerkara.'',$Template);
$Template = str_replace('#namapanitera#',''.$namaPanitera.'',$Template);
$Template = str_replace('#namapn#',''.$namaPN.'',$Template);
$Template = str_replace('#jenisputusan#',''.$tahapan.'',$Template);
$Template = str_replace('#nomorputusan#',''.$noPerkaraTahapan.'',$Template);
$Template = str_replace('#tanggalputusan#',''.$tglPutusTahapan.'',$Template);
$Template = str_replace('#statuspanitera#',''.$statusPanitera.'',$Template);
$Template = str_replace('#tglpemberitahuan#',''.$tglPemberitahuan_pk.'',$Template);
$Template = str_replace('#haripemberitahuan#',''.$hariPemberitahuanPK.'',$Template);
//$Template = str_replace('#namajaksa#',''.$namaJaksa.'',$Template);
//$Template = str_replace('#nipjaksa#',''.$nipJaksa.'',$Template);
//$Template = str_replace('#pekerjaan#',''.$pekerjaan.'',$Template);
//$Template = str_replace('#kejaksaan#',''.$kejaksaan.'',$Template);
//$Template = str_replace('#alamat#',''.$alamatJaksa.'',$Template);

$Template = str_replace('#nomorpk#',''.$nomorPerkaraKasasi.'',$Template);
$Template = str_replace('#tglputuspk#',''.$tglPutusKasasi.'',$Template);
$Template = str_replace('#amarpk#',''.$amarPutPK.'',$Template);
$Template = str_replace('#namaPihak#',''.$namaPihak.'',$Template);
$Template = str_replace('#pekerjaanPihak#',''.$pekerjaanPihak.'',$Template);
$Template = str_replace('#alamatPihak#',''.$alamatPihak.'',$Template);
$Template = str_replace('#penerimanMemoriPK#',''.$penerimanMemoriPK.'',$Template);
$Template = str_replace('#penyerahanMemoriPK#',''.$penyerahanMemoriPK.'',$Template);

$Template = str_replace('#namaPihak4#',''.$namaPihak4.'',$Template);
$Template = str_replace('#pekerjaanPihak4#',''.$pekerjaanPihak4.'',$Template);
$Template = str_replace('#alamatPihak4#',''.$alamatPihak4.'',$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\"");
header("Content-length: ".strlen($Template));
echo $Template;
?>