<?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/akta/pidana_umum/".$filename.".rtf");
$Template = file_get_contents($url);
//=============================================roby======================================================
$perkara = $dataTemplate;
$itunganPerkara = count($perkara);
//print_r($itunganPerkara);
$terpidana = array();
foreach ($perkara->result() as $perkara) {
	        $namapihak = $this->templatehelper->standradnaming($perkara->namaPihak);
	        $tempatlahirpihak = $perkara->tempatLahirPihak;
	        $umurpihak = $this->tanggalhelper->getSelisihTahun($perkara->tanggalLahirPihak,date('Y-m-d'));
	        $tanggallahirpihak = $this->templatehelper->convertKeTglIndo($perkara->tanggalLahirPihak);
	        $kelaminpihak = $perkara->kelaminPihak;
	        $negarapihak = $perkara->negaraPihak;
	        $alamatpihak = $this->templatehelper->standradnaming($perkara->alamatPihak);
	        $agamapihak = $perkara->agamaPihak;
	        $pekerjaanpihak = $this->templatehelper->standradnaming($perkara->pekerjaanPihak);
			$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 = $perkara->Tahapan;
			$noPerkaraTahapan = $this->templatehelper->standradnaming($perkara->nomorPerkaraTahapan);
			$tglPutusTahapan = $this->templatehelper->convertKeTglIndo($perkara->putusan);
			$statusPanitera = $this->templatehelper->standradnaming($perkara->pejabat);
			$tglpermohonan_pk = $this->templatehelper->convertKeTglIndo($perkara->permohonan_pk);
 }

//==============================================================================//
#Insert Into Dokumen#
	$Template = str_replace('#namapihak#',''.$namapihak.'',$Template);
	$Template = str_replace('#tempatlahirpihak#',''.$tempatlahirpihak.'',$Template);
	$Template = str_replace('#umurpihak#',''.$umurpihak.'',$Template);
	$Template = str_replace('#tanggallahirpihak#',''.$tanggallahirpihak.'',$Template);
	$Template = str_replace('#kelaminpihak#',''.$kelaminpihak.'',$Template);
	$Template = str_replace('#negarapihak#',''.$negarapihak.'',$Template);
	$Template = str_replace('#alamatpihak#',''.$alamatpihak.'',$Template);
	$Template = str_replace('#agamapihak#',''.$agamapihak.'',$Template);
	$Template = str_replace('#pekerjaanpihak#',''.$pekerjaanpihak.'',$Template);
	$Template = str_replace('#nomorpermohonan#',''.$nomorPermohonan.'',$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('#tanggalpk#',''.$tglpermohonan_pk.'',$Template);
	$Template = str_replace('#haripk#',''.$this->templatehelper->getHari($perkara->permohonan_pk).'',$Template);
	#$Template = str_replace('#terdakwa#',''.$dataTerpidana.'',$Template);
	#$Template = str_replace('#jenisterdakwa#',''.$jenisTerpidana.'',$Template);
	#$Template = str_replace('#tandatanganterdakwa#',''.$namaTerdakwaTT.'',$Template);


header("Content-type: application/rtf");
header("Content-disposition: inline; filename=".$namafile."-".$nomorPerkara.".rtf");
header("Content-length: ".strlen($Template));
echo $Template;
?>