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

$diwakilkan=intval($diwakilkan);
if(!is_numeric($diwakilkan)){
    show_404();
    exit();
}

if($diwakilkan==1){
    $judulOleh = "KALAPAS";
    $keterangan = "Kepala Lembaga Pemasyarakatan";
} else {
    $judulOleh = "KARUTAN";
    $keterangan = "Kepala Rumah Tahanan Negara";
}

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======================================================
$jaksa = $DataJaksaKasasi;
foreach ($jaksa->result() as $row) {	
		$namaJaksa = $this->templatehelper->standradnaming($row->nama);	
		$nipJaksa = $row->NIP;	
		$pekerjaan = $row->pekerjaan;	
		$kejaksaan = $this->templatehelper->standradnaming($row->kejaksaan);	
}

$perkara = $dataTemplate;
$itunganPerkara = count($perkara);
$terpidana = array();
foreach ($perkara->result() as $perkara) {
			$itemTerpidana= array();
			$itemTerpidana['namaPihak']  = $this->templatehelper->standradnaming($perkara->nama_terdakwa);
	        $itemTerpidana['alamatPihak'] = $this->templatehelper->standradnaming($perkara->alamat);
	        $itemTerpidana['tempatLahirPihak'] = $perkara->tempat_lahir;
	        $itemTerpidana['tanggalLahirPihak'] = $this->templatehelper->convertKeTglIndo($perkara->tanggal_lahir);
	        $itemTerpidana['umurPihak'] = $this->tanggalhelper->getSelisihTahun($perkara->tanggal_lahir,date('Y-m-d'));
	        $itemTerpidana['kelaminPihak'] = $perkara->jenis_kelamin;
	        $itemTerpidana['agamaPihak'] = $perkara->agama_nama;
	        $itemTerpidana['pekerjaanPihak'] = $this->templatehelper->standradnaming($perkara->pekerjaan);
	        $itemTerpidana['negaraPihak'] = $perkara->warga_negara;
	        $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->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_kasasi = $this->templatehelper->convertKeTglIndo($perkara->tglTerimaKas);
			$tgl_penerimaan_kontra_kasasi = $this->templatehelper->convertKeTglIndo($perkara->penerimaan_kontra_kasasi);
			$hari_penerimaan_kontra_kasasi = $this->templatehelper->getHari($perkara->penerimaan_kontra_kasasi);			
			$tglPutusanYangDiPKkan =  $this->templatehelper->convertKeTglIndo($perkara->putusan);
			$namaPemohon =  $this->templatehelper->standradnaming($perkara->pemohon_nama);
			$tglTerimaKas = $this->templatehelper->convertKeTglIndo($perkara->tglTerimaKas);
			$hariTerimaKasasi = $this->templatehelper->getHari($perkara->tglTerimaKas);
			$namaTdkw = $this->templatehelper->standradnaming($perkara->namaTdkw);
			$tglPemberitahuanKas =  $this->templatehelper->convertKeTglIndo($perkara->pemberitahuan_kasasi);

 }


//==============================================================================//
$Template = str_replace("#nomorperkara#",''.$nomorPerkara.'',$Template);
$Template = str_replace("#namaPengadilan#",''.$namaPN.'',$Template);
$Template = str_replace("#nomorAkta#",''.$nomorPermohonan.'',$Template);
$Template = str_replace("#namaTerdakwa#",''.$this->templatehelper->standradnaming($perkara->nama_terdakwa).'',$Template);
$Template = str_replace("#alamatTerdakwa#",''.$this->templatehelper->standradnaming($perkara->alamat).'',$Template);
$Template = str_replace("#tempatLahir#",''.$perkara->tempat_lahir.'',$Template);
$Template = str_replace("#tanggal_lahir#",''.$this->templatehelper->convertKeTglIndo($perkara->tanggal_lahir).'',$Template);
$Template = str_replace("#jenisKelamin#",''.$perkara->jenis_kelamin.'',$Template);
$Template = str_replace("#umur#",''.$this->tanggalhelper->getSelisihTahun($perkara->tanggal_lahir,date('Y-m-d')).'',$Template);
$Template = str_replace("#wargaNegara#",''.$perkara->warga_negara.'',$Template);
$Template = str_replace("#agama#",''.$perkara->agama_nama.'',$Template);
$Template = str_replace("#pekerjaan#",''.$this->templatehelper->standradnaming($perkara->pekerjaan).'',$Template);
$Template = str_replace("#pejabat#",''.$namaPanitera.'',$Template);
$Template = str_replace("#Jabatan#",''.$statusPanitera.'',$Template);
$Template = str_replace("#tahapan#",''.$tahapan.'',$Template);
$Template = str_replace("#nomorYgdDiPK#",''.$noPerkaraTahapan.'',$Template);
$Template = str_replace("#tglPtsDiPKkan#",''.$tglPutusanYangDiPKkan.'',$Template);
$Template = str_replace("#namaPemohon#",''.$namaPemohon.'',$Template);
$Template = str_replace("#tglCetak#",''.$tgl_penerimaan_kontra_kasasi.'',$Template);
$Template = str_replace("#hariCetak#",''.$hari_penerimaan_kontra_kasasi.'',$Template);
$Template = str_replace("#pekerjaan#",''.$this->templatehelper->standradnaming($perkara->pekerjaan).'',$Template);
$Template = str_replace('#juduloleh#',''.$judulOleh.'',$Template);
$Template = str_replace('#keterangan#',''.$keterangan.'',$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('#tglTerimaMK#',''.$tglPemberitahuanKas.'',$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['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('#terdakwa#',''.$namaTdkw.'',$Template);
$Template = str_replace('#jenisterdakwa#',''.$jenisTerpidana.'',$Template);
$Template = str_replace('#tandatanganterdakwa#',''.$namaTerdakwaTT.'',$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\"");
echo $Template;
?>