<?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/perdata_agama/".$filename.".rtf");
$Template = file_get_contents($url);
//=============================================roby======================================================
$perkara = $dataTemplate;
foreach ($perkara->result() as $perkara) {
			$nomorPerkara = $perkara->nomor_perkara;			
			$namaPemohon = $this->templatehelper->standradnaming($perkara->namaPihak);
			$alamatPemohon = $this->templatehelper->standradnaming($perkara->alamatPihak);
			$agamaPemohon = $perkara->agamaPihak;
			$pekerjaanPemohon = $this->templatehelper->standradnaming($perkara->pekerjaanPihak);
			$pendidikanPemohon = $perkara->pendidikanPihak;			
			$umurPemohon = $this->tanggalhelper->getSelisihTahun($perkara->tanggalLahirPihak,date('Y-m-d'));			
			$namaSatker = $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_pk = $this->templatehelper->convertKeTglIndo($perkara->permohonan_pk);
			$memoripk = $this->templatehelper->convertKeTglIndo($perkara->penerimaan_memori_pk);
			$kontrapk = $this->templatehelper->convertKeTglIndo($perkara->penerimaan_kontra_pk);
			$hariPermohonanpk = $this->templatehelper->getHari($perkara->permohonan_pk);
			$statusAsalPemohon = $perkara->pihak_asal_text;
			$statusPemohonpk = $perkara->status_pihak_text;
			$tanggalCabutPK=$this->templatehelper->convertKeTglIndo($perkara->permohonan_pk);
 }
//==============================================================================//
#Insert Into Dokumen#
$Template = str_replace('#nomorPerkara#',''.$nomorPerkara.'',$Template);
$Template = str_replace('#tanggalCabutPK#',''.$tanggalCabutPK.'',$Template);
$Template = str_replace('#namapanitera#',''.$namaPanitera.'',$Template);
$Template = str_replace('#namaSatker#',''.$namaSatker.'',$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('#memoripk#',''.$memoripk.'',$Template);
$Template = str_replace('#kontrapk#',''.$kontrapk.'',$Template);
$Template = str_replace('#haripk#',''.$hariPermohonanpk.'',$Template);

if ($statusPanitera == "Panitera Sekretaris"){
	$Template = str_replace('#jabatanpansek#','Panitera',$Template);
}else{
	$Template = str_replace('#jabatanpansek#','a.n. Panitera',$Template);
}

$Template = str_replace('#namaPemohon#',''.$namaPemohon.'',$Template);
$Template = str_replace('#umurPemohon#',''.$umurPemohon.'',$Template);
$Template = str_replace('#agamaPemohon#',''.$agamaPemohon.'',$Template);
$Template = str_replace('#pekerjaanPemohon#',''.$pekerjaanPemohon.'',$Template);
$Template = str_replace('#pendidikanPemohon#',''.$pendidikanPemohon.'',$Template);
$Template = str_replace('#alamatPemohon#',''.$alamatPemohon.'',$Template);


$statusPemohon='';
$statusPemohon .= 'Nama '.$namaPemohon.', umur '.$umurPemohon.' tahun, agama '.$agamaPemohon.', pekerjaan '.$pekerjaanPemohon.', pendidikan terakhir '.$pendidikanPemohon.', tempat tinggal/kediaman '.$alamatPemohon.', ';
$statusPemohon .= ' dahulu '.$statusAsalPemohon.' sekarang '.$statusPemohonpk;
$Template = str_replace('#statusPemohon#',''.$statusPemohon.'',$Template);

//===============================================================================//
$pemohonpk = '';
$i=0;
if($dataPemohonpk!=''){
	if($dataPemohonpk->num_rows>0){
		foreach ($dataPemohonpk->result() as $pemohon) {
			$pemohonpk .= $pemohon->pihak_nama.' dahulu '.$pemohon->pihak_asal_text.' sekarang '.$pemohon->status_pihak_text.' '.($pemohon->urutan_pk>1 ? $this->templatehelper->converToAngkaRomawi($pemohon->urutan_pk):'').' Peninjauan Kembali; '.($pemohon->urutan_pk>1 ? ' \\par ':'');
			$i++;
		}
		$Template = str_replace('#loopingpemohon#',''.$pemohonpk.'',$Template);
	}
}

$termohonpk = '';
$i=0;
if($dataTermohonpk!=''){
	if($dataTermohonpk->num_rows>0){
		foreach ($dataTermohonpk->result() as $termohon) {
			$termohonpk .= $termohon->pihak_nama.' dahulu '.$termohon->pihak_asal_text.' sekarang '.$termohon->status_pihak_text.' '.($termohon->urutan_pk>1 ? $this->templatehelper->converToAngkaRomawi($termohon->urutan_pk):'').' Peninjauan Kembali; '.($termohon->urutan_pk>1 ? ' \\par ':'');
			$i++;
			$Template = str_replace('#namaTermohon#',''.$termohon->pihak_nama.'',$Template);

		}
		$Template = str_replace('#loopingtermohon#',''.$termohonpk.'',$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;
?>