<?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_militer/".$filename.".rtf");
//echo "string ".$filename;
//exit();
$Template = file_get_contents($url);
//=============================================roby======================================================


$perkara = $dataTemplate;
$itunganPerkara = count($perkara);
$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];
			$kodePN = $no[1];
			$matra = $no[2];
			$bulan = $no[3];
			$tahunPerkara = $no[4];
			$kodePerkara = '';

			$tglpermohonan_pk = $this->templatehelper->convertKeTglIndo($perkara->permohonan_pk);

			$nomorPermohonan = 'APPK/'.$nomor."/".$kodePN.'/'.$matra."/".$bulan.'/'.$tahunPerkara;
			$namaPN = $perkara->namaPengadilan;
			$namaPanitera = $this->templatehelper->standradnaming($perkara->pw);
			$nrppanitera = $perkara->nrppejabat;
			$pangkatpanitera = $perkara->pangkatpejabat;
			$alamatpn = $perkara->alamatpn;

			$tahapan = $perkara->Tahapan;
			$noPerkaraTahapan = $this->templatehelper->standradnaming($perkara->nomorPerkaraTahapan);
			$tglPutusTahapan = $this->templatehelper->convertKeTglIndo($perkara->putusan);
			$statusPanitera = $this->templatehelper->standradnaming($perkara->pejabat);
			$nrp = $perkara->nrp;
			$pangkat = $perkara->pangkat;
			$tempatlahirpihak = $perkara->tempatLahirPihak;
			$namapengadilan = $perkara->namaPengadilan;
			$jabatan = $perkara->jabatan;
			$kesatuan = $perkara->kesatuan;

			$namaoditur 	= $perkara->oditur;
			$nrpoditur 		= $perkara->oditur_nrp;
			$pangkatoditur 	= $perkara->oditur_pangkat;
			$jabatanoditur 	= $perkara->oditur_jabatan;
			$kantoroditur = $perkara->oditur_kantor;
 }


	$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('#alamatpn#',''.$alamatpn.'',$Template);
	$Template = str_replace('#nrppejabat#',''.$nrppanitera.'',$Template);
	$Template = str_replace('#pangkatpejabat#',''.$pangkatpanitera.'',$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('#nrp_pemohon#',''.$nrp.'',$Template);
	$Template = str_replace('#pangkat_korp#',''.$pangkat.'',$Template);
	$Template = str_replace('#kodepn1#',''.$kodePN.'',$Template);
	$Template = str_replace('#tempat_lahir#',''.$tempatlahirpihak.'',$Template);
	$Template = str_replace('#nama_pengadilan#',''.$namapengadilan.'',$Template);
	$Template = str_replace('#jabatan#',''.$jabatan.'',$Template);
	$Template = str_replace('#kesatuan#',''.$kesatuan.'',$Template);
	$Template = str_replace('#namaoditur#',''.$namaoditur.'',$Template);	
	$Template = str_replace('#nrpoditur#',''.$nrpoditur.'',$Template);		
	$Template = str_replace('#pangkatoditur#',''.$pangkatoditur.'',$Template);
	$Template = str_replace('#jabatanoditur#',''.$jabatanoditur.'',$Template);
	$Template = str_replace('#kantoroditur#',''.$kantoroditur.'',$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;
?>