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

foreach ($template->result() as $template){
    $filename=$template->kdtemplate;
    $namafile=str_replace(" ","",$template->namatemplate);
}

$url = base_url("resources/template/penetapan/perdata_agama/".$filename.".rtf");

$Template = file_get_contents($url);
$namakota = $datapengadilan->row(0)->NamaPN;
if ($pembuat==1) {
	$Template = str_replace('#JABATAN#','Panitera',$Template);
	$Template = str_replace('#atasnama#','',$Template);
	$Template = str_replace("#NAMA#",$datapengadilan->row(0)->PansekPNNama,$Template);
} else {
	$Template = str_replace('#JABATAN#','Panitera',$Template);
	$Template = str_replace('#atasnama#','a.n ',$Template);
	$Template = str_replace("#NAMA#",$datapengadilan->row(0)->WaPanNama,$Template);
}
foreach ($datapaniterapengganti ->result() as $row) {
		//$tanggalpenetapanjurusita = $this->templatehelper->convertKeTglIndo($row->tanggal_surat);
	$Template = str_replace("#tanggalpenetapanjurusita#",$this->templatehelper->convertKeTglIndo($row->tanggal_penetapan),$Template);
}
foreach ($datapenetapanhakim ->result() as $row) {
	//$tanggalpenetapanhakim = $this->templatehelper->convertKeTglIndo($row->tanggal_penetapan);
	$Template = str_replace("#tanggalpenetapanhakim#",$this->templatehelper->convertKeTglIndo($row->tanggal_penetapan),$Template);
}
$nomorperkara = $dataperkara->row(0)->nomor_perkara;

$i=0;
$nama_pp='';
foreach ($datapaniterapengganti->result() as $row) {
	$i++;
	if ($i>1){
		$nama_pp.=' dan ';
	}
	$nama_pp .= $row->nama_gelar;
}
	
$Template = str_replace("#nama_pp#",$nama_pp,$Template);
$Template = str_replace("#nomorperkara#",$dataperkara->row(0)->nomor_perkara,$Template);
//$Template = str_replace("#namakota#",ucwords(strtolower($datapengadilan->row(0)->NamaPN)),$Template);
//$Template = str_replace("#tanggalpenetapanjurusita#",''.$tanggalpenetapanjurusita.'',$Template);
foreach ($datapengadilan->result() as $row) {
	$namapn = ucwords(strtolower($this->templatehelper->standradnaming($row->NamaPN)));
	$namaketuapn = $this->templatehelper->standradnaming($row->KetuaPNNama);
	$namawakilpn = $this->templatehelper->standradnaming($row->WakilKetuaPNNama);
	$namakota =str_replace("Pengadilan Agama ",'',$namapn);
	$namakota =str_replace("Mahkamah Syar'Iyah ",'',$namakota);
	}
$Template = str_replace('#namakota#',''.$namakota.'',$Template);
$Template = str_replace('#namapa#',''.$namapn.'',$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=\"Penetapan PPPP - $nomorperkara.rtf\"");
echo $Template;
?>