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

/*$idperkara=$this->encrypt->decode(base64_decode($enc));
$idperkara = intval($idperkara);
if(!is_numeric($idperkara)){
    show_404();
	exit();
}*/
/*$idpembuatakta=$this->encrypt->decode(base64_decode($idpembuatakta));
$idpembuatakta = intval($idpembuatakta);
if(!is_numeric($idpembuatakta)){
    show_404();
	exit();
}*/
/*$idput=$this->encrypt->decode(base64_decode($idput));
$idput = intval($idput);
if(!is_numeric($idput)){
    show_404();
	exit();
}*/
//$diwakilkan=intval($diwakilkan);

//$idperkara = intval($idperkara);
//$idpembuatakta = intval($idpembuatakta);
//$idput = intval($idput);
foreach ($template->result() as $template)
{
    $filename=$template->kdtemplate;
    $namafile=str_replace(" ","",$template->namatemplate);
}
$url = base_url("resources/template/akta/pidana_umum/".$filename.".rtf");

// $url = base_url("resources/template/PID_20_510_639.rtf");
// $judul = "AktaPencabutanPermintaanPeninjauanKembaliPenasihatHukumTerdakwa_";


$Template = file_get_contents($url);
//=============================================roby======================================================


$perkara = $dataTemplate;
$itunganPerkara = count($perkara);
//print_r($perkara->result());
$terpidana = array();
foreach ($perkara->result() as $perkara) {
//echo ("halo");

	        $namapihak = $this->templatehelper->standradnaming($perkara->nama_terdakwa);
	        $tempatlahirpihak = $perkara->tempat_lahir;
	        #$umurpihak = $perkara->umurPihak;
	        $tanggallahirpihak = $this->templatehelper->convertKeTglIndo($perkara->tanggal_lahir);
	        $kelaminpihak = $perkara->jenis_kelamin;
	        $negarapihak = $perkara->warga_negara;
	        $alamatpihak = $this->templatehelper->standradnaming($perkara->alamat);
	        $agamapihak = $perkara->agama_nama;
	        $pekerjaanpihak = $this->templatehelper->standradnaming($perkara->pekerjaan_terdakwa);

	        $tglCabut = $perkara->tglCabut;
			$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->nama_pengadilan);
			$namaPanitera = $this->templatehelper->standradnaming($perkara->pw);
			$tahapan = $perkara->tahapan;
			$noPerkaraTahapan = $this->templatehelper->standradnaming($perkara->nomorPerkara);
			$tglPutusTahapan = $this->templatehelper->convertKeTglIndo($perkara->putusan);
			$statusPanitera = $this->templatehelper->standradnaming($perkara->jabatan);
			$tglpermohonan_pk = $this->templatehelper->convertKeTglIndo($perkara->permohonan_pk);
			$tanggalPK = $this->templatehelper->convertKeTglIndo($perkara->tglPk);
			$pemohon_nama = $this->templatehelper->standradnaming($perkara->pemohon_nama);
 }

//$nomorAkta = $nomor."/Akta ".$kodePerkara."/".$tahunPerkara."/".$kodePN;
$tCabut = explode("^",$tglCabut);

if (!empty($tCabut['1']))
	{
		$TglCabutCet = " tanggal ".$this->templatehelper->convertKeTglIndo($tCabut['1']);
		$hariCabutCet = $this->templatehelper->getHari($tCabut['1']);	
	}
	else
	{
		$TglCabutCet="#isi tanggal cabut di aplikasi#";
		$hariCabutCet="#isi tanggal cabut di aplikasi#";
	}

//==============================================================================//
#Insert Into Dokumen#
	$Template = str_replace('#namaTerdakwa#',''.$namapihak.'',$Template);
	$Template = str_replace('#tempatLahir#',''.$tempatlahirpihak.'',$Template);
	$Template = str_replace('#wargaNegara#',''.$negarapihak.'',$Template);
	$Template = str_replace('#tanggal_lahir#',''.$tanggallahirpihak.'',$Template);
	$Template = str_replace('#umur#',''.$this->tanggalhelper->getSelisihTahun($tanggallahirpihak,date('Y-m-d')).'',$Template);
	$Template = str_replace('#jenisKelamin#',''.$kelaminpihak.'',$Template);
	$Template = str_replace('#negarapihak#',''.$negarapihak.'',$Template);
	$Template = str_replace('#alamatTerdakwa#',''.$alamatpihak.'',$Template);
	$Template = str_replace('#agama#',''.$agamapihak.'',$Template);
	$Template = str_replace('#pekerjaan#',''.$pekerjaanpihak.'',$Template);
	$Template = str_replace('#nomorAkta#',''.$nomorPermohonan.'',$Template);
	$Template = str_replace('#Jabatan#',''.$namaPanitera.'',$Template);
	$Template = str_replace('#namaPengadilan#',''.$namaPN.'',$Template);
	$Template = str_replace('#tahapan#',''.$tahapan.'',$Template);
	$Template = str_replace('#nomorYgdDiPK#',''.$noPerkaraTahapan.'',$Template);
	$Template = str_replace('#tglPtsDiPKkan#',''.$tglPutusTahapan.'',$Template);
	$Template = str_replace('#pejabat#',''.$statusPanitera.'',$Template);
	// $Template = str_replace('#tglCetak#',''.$tglpermohonan_pk.'',$Template);
	$Template = str_replace('#tglCetak#',''.$TglCabutCet.'',$Template);
	$Template = str_replace('#hariCetak#',''.$hariCabutCet.'',$Template);
	$Template = str_replace('#pejabat#',''.$statusPanitera.'',$Template);
	$Template = str_replace('#tglPK#',''.$tanggalPK.'',$Template);
	$Template = str_replace('#namaPemohon#',''.$pemohon_nama.'',$Template);
	//$Template = str_replace('#hariCetak#',''.$TglCabutCet.'',$Template);
	$Template = str_replace('#tglCetak#',''.$TglCabutCet.'',$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;
?>
