<?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");
$Template = file_get_contents($url);
//=============================================roby======================================================
$perkara = $dataTemplate;
$itunganPerkara = count($perkara);
$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['umurPihak'] = $this->tanggalhelper->getSelisihTahun($perkara->tanggalLahirPihak,date('Y-m-d'));
// 	        $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 = $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);
// 			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($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('#namaterpidana#',''.$itemTerpidana['namaPihak'].'',$Template);
// $Template = str_replace('#pekerjaanterpidana#',''.$itemTerpidana['pekerjaanPihak'].'',$Template);
// $Template = str_replace('#alamatterpidana#',''.$itemTerpidana['alamatPihak'].'',$Template);
// $Template = str_replace('#namajurusita#',''.$namaJurusita.'',$Template);
// //$Template = str_replace('#alamat#',''.$alamatJaksa.'',$Template);
if($itunganPerkara==1){
    $jenisTerpidana = "Terpidana";
    $dkk = "";
} else {
    $jenisTerpidana = "Para Terpidana";
    $dkk = "Dkk";
}

$dataTerpidana = "";
$namaTerdakwaTT = "";
$itungan = 0;
//print_r($terpidana);
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['tempatLahirPihak']." \\par ";
    $dataTerpidana .= "Umur/Tanggal lahir \t:\t ".$rows['umurPihak']." / ".$rows['tanggalLahirPihak']." \\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#',''.$namaTerdakwaTT.'',$Template);
// $Template = str_replace('#terpidana/paraterpidana#',''.$jenisTerpidana.'',$Template);
// $Template = str_replace('#tandatanganterdakwa#',''.$namaTerdakwaTT.'',$Template);
// $Template = str_replace('#namaterpidanadkk#',''.$dkk.'',$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;
?>