<?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);
$nama_js = $datajurusita->row(0)->nama_gelar;
//$jabatan_js = $datajurusita->row(0)->jabatan;
$namasatker = $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 ($datajurusita ->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);
}

$Template = str_replace("Pengadilan Agama ",'',str_replace("#namakota#",ucwords(strtolower($namasatker)),$Template));
$Template = str_replace("Mahkamah Syar'iyah ",'',str_replace("#namakota#",ucwords(strtolower($namasatker)),$Template));

$i=0;
$nama_js='';
foreach ($datajurusita->result() as $row) {
	$i++;
	if ($i>1){
		$nama_js.=' dan ';
		if ($jabatan_js!=$row->jabatan){
			$Template = str_replace('#JABATAN_JS#','Jurusita dan Jurusita Pengganti',$Template);
		}
	}
	$nama_js .= $row->nama_gelar;
	$jabatan_js=$row->jabatan;
}

if($jabatan_js==1){
	$Template = str_replace('#JABATAN_JS#','Jurusita',$Template);
}else{
	$Template = str_replace('#JABATAN_JS#','Jurusita Pengganti',$Template);
}

$Template = str_replace("#namajurusita#",$nama_js,$Template);
$Template = str_replace("#nomorperkara#",$dataperkara->row(0)->nomor_perkara,$Template);
$Template = str_replace("#namasatker#",ucwords(strtolower($datapengadilan->row(0)->NamaPN)),$Template);


//$Template = str_replace("#tanggalpenetapanjurusita#",''.$tanggalpenetapanjurusita.'',$Template);

$temp = explode(' ', $namasatker);
$Template = str_replace("#pa/ms#",''.$temp[0].' '.$temp[1].'',$Template);
$Template = str_replace("#namakota#",''.$temp[0].' '.$temp[1].'',$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."-ttt.rtf\"");
echo $Template;
?>