<?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_40_510_635.rtf");
// $judul = "AktaPermintaanPeninjauanKembaliOlehKuasaHukumTerpidana_";


$Template = file_get_contents($url);
//=============================================roby======================================================
$perkara = $dataTemplate;
$itunganPerkara = count($perkara);
//print_r($itunganPerkara);
$terpidana = array();
foreach ($perkara->result() as $perkara) {
		$itemTerpidana= array();
			$itemTerpidana['namaPihak']  = $this->templatehelper->standradnaming($perkara->namaPihak);
	        $itemTerpidana['alamatPihak'] = $this->templatehelper->standradnaming($perkara->alamatPihak);
	        $itemTerpidana['tempatLahirPihak'] = $perkara->tempatLahirPihak;
	        $itemTerpidana['tanggalLahirPihak'] = $this->templatehelper->convertKeTglIndo($perkara->tanggalLahirPihak);
	        $itemTerpidana['kelaminPihak'] = $perkara->kelaminPihak;
	        $itemTerpidana['agamaPihak'] = $perkara->agamaPihak;
	        $itemTerpidana['pekerjaanPihak'] = $this->templatehelper->standradnaming($perkara->pekerjaanPihak);
	        $itemTerpidana['negaraPihak'] = $perkara->negaraPihak;
	        $terpidana[]= $itemTerpidana;

			$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);
			$pengacara = $this->templatehelper->convertKeTglIndo($perkara->pihak_nama);
			//pihak_nama
 }

//==============================================================================//
#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('#pengacara#',''.$pengacara.'',$Template);
	#$Template = str_replace('#terdakwa#',''.$dataTerpidana.'',$Template);
	#$Template = str_replace('#jenisterdakwa#',''.$jenisTerpidana.'',$Template);
	#$Template = str_replace('#tandatanganterdakwa#',''.$namaTerdakwaTT.'',$Template);

if($itunganPerkara==1){
    $jenisTerpidana = "Terpidana";
} else {
    $jenisTerpidana = "Para Terpidana";
}

$dataTerpidana = "";
$namaTerdakwaTT = "";
$itungan = 0;
foreach($terpidana as $rows){$itungan++;
	$namaTerdakwaTT .= "\\line \\line ".$rows['namaPihak']."";
    if($itunganPerkara >= 1){
        $dataTerpidana .= "Terpidana ".$this->templatehelper->converToAngkaRomawi($itungan)." \\par ";
    }
    $dataTerpidana .= "Nama \t:\t ".$rows['namaPihak']." \\par ";
    $dataTerpidana .= "Tempat Lahir \t:\t ".$rows['tanggalLahirPihak']." \\par ";
   # $dataTerpidana .= "Umur/tanggal lahir \t:\t ".$rows['umurPihak']." / ".$rows['dinoLairPihak']." \\par ";
    $dataTerpidana .= "Jenis Kelamin \t:\t ".$rows['kelaminPihak']." \\par ";
    $dataTerpidana .= "Kebangsaan \t:\t ".$rows['negaraPihak']." \\par ";
    $dataTerpidana .= "Tempat tinggal \t:\t ".$rows['alamatPihak']." \\par ";
    $dataTerpidana .= "Agama \t:\t ".$rows['agamaPihak']." \\par ";
    $dataTerpidana .= "Pekerjaan \t:\t ".$rows['pekerjaanPihak']." \\par ";
}
$Template = str_replace('#terpidana#',''.$dataTerpidana.'',$Template);
$Template = str_replace('#jenisterpidana#',''.$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;
?>