<?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======================================================


//===securing
$nipJaksa='..........';					$jabatan='............';				$kejaksaan='............';
$nomorPermohonan='............';		$namaPanitera='............';			$namaPN='............';
$tahapan='............';				$noPerkaraTahapan='............';		$tglPutusTahapan='............';
$statusPanitera='............';			$tglpermohonan_kasasi='............';	$judulOleh='............';
$keterangan='............';				$namaJaksa='............';				$nipJaksa='............';
$jabatan='............';				$kejaksaan='............';				$dataTerpidana='............';
$jenisTerpidana='............';			$namaTerdakwaTT='............';			$haricabut = '.............';
$tanggalcabut = '............';

//=== begin
$jaksaKasasi=$DataJaksaKasasi;
if(!empty($jaksaKasasi)){
	foreach ($jaksaKasasi->result() as $row){
		$namaJaksa = $this->templatehelper->standradnaming($row->nama);
		$nipJaksa = $row->NIP;
		$jabatan = $row->pemohon_pekerjaan." pada ".$this->templatehelper->standradnaming($row->alamat);
		$kejaksaan = $this->templatehelper->standradnaming($row->alamat);
	}
}

$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'] = $perkara->umurPihak;
	        $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);
			$tglpermohonan_kasasi = $this->templatehelper->convertKeTglIndo($perkara->permohonan_kasasi);
 }

//==============================================================================//
#Insert Into Dokumen#

$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('#permohonankasasi#',''.$tglpermohonan_kasasi.'',$Template);
$Template = str_replace('#harikasasi#',''.$this->templatehelper->getHari($tglpermohonan_kasasi).'',$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('#pekerjaanJaksa#',''.$jabatan.'',$Template);
$Template = str_replace('#kejaksaan#',''.$kejaksaan.'',$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#',''.$dataTerpidana.'',$Template);
$Template = str_replace('#jenisterdakwa#',''.$jenisTerpidana.'',$Template);
$Template = str_replace('#tandatanganterdakwa#',''.$namaTerdakwaTT.'',$Template);

if(!empty($tglcabut)){
	$haricabut = $this->templatehelper->getHari($tglcabut);
	$tanggalcabut = $this->templatehelper->convertKeTglIndo($tglcabut);
}

$Template = str_replace('#haricabut#',''.$haricabut.'',$Template);
$Template = str_replace('#tanggalcabut#',''.$tanggalcabut.'',$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;
?>