<?php
//include_once("../../_lib/prod/conffunction.php");
if($this->session->userdata('is_logged_in')===FALSE){
			redirect('login');
}

// $idperkara=$this->encrypt->decode(base64_decode($enc));
// $idperkara = intval($idperkara);
// $pembuat=$this->encrypt->decode(base64_decode($pembuat));
// $pembuat = intval($pembuat);
// $panitera_id=$this->encrypt->decode(base64_decode($panitera_id));
// $panitera_id = intval($panitera_id);

// if(!is_numeric($idperkara) OR !is_numeric($pembuat) OR !is_numeric($panitera_id)){
// 	show_404();
// }
foreach ($template->result() as $template)
{
    $filename=$template->kdtemplate;
    $namafile=str_replace(" ","",$template->namatemplate);
}

$url = base_url("resources/template/penetapan/perdata_umum/".$filename.".rtf");
// $url = base_url("resources/template/PDT_G_02_30_1.rtf");
// $judul = "Penetapan_penunjukan_panitera_pengganti";

$Template = file_get_contents($url);
//=============================================roby======================================================

function in_multiarray($sval, $arr){
	$ret = false;
	foreach ($arr as $value) {
		if (is_array($value)){
			$ret = $ret | in_multiarray($sval, $value);
		}else{
			if ($value == $sval){
				return true;
			}
		}
	}
	return $ret;
}

$dataPenetapan = $data_template;
//echo $data_template;

$tergugat = array();
$penggugat = array();
foreach ($dataPenetapan->result() as $row) {
    if (!in_multiarray($row->namaP, $penggugat)){
    	$penggugatItem = array();
    	$penggugatItem["nama"] = $row->namaP;
    	$penggugatItem["alamat"] = $row->alamatP;
    	$penggugatItem["statusP"] = $row->statusP;
    	$penggugatItem["urutanP"] = $row->urutanP;
    	$penggugat[] = $penggugatItem;
    }
    if (!in_multiarray($row->namaT, $tergugat)){
    	$tergugatItem = array();
    	$tergugatItem["nama"] = $row->namaT;
    	$tergugatItem["alamat"] = $row->alamatT;
    	$tergugatItem["statusT"] = $row->statusT;
    	$tergugatItem["urutanT"] = $row->urutanT;
    	$tergugat[] = $tergugatItem;
    }


	$namaPengadilan     =$this->templatehelper->standradnaming($row->namaPengadilan);
	$kota     =$this->templatehelper->namaKota($row->namaPengadilan);
	$nomorperkara   =$row->nomor_perkara;
	$urutan   =$row->urutan;
	$jabatan   =$row->jabatan;
	$namaPejabat   = $this->templatehelper->standradnaming($row->nama_pejabat);
	$tanggalPendaftaran   =$this->templatehelper->convertKeTglIndo($row->tanggal_pendaftaran);
	$tanggalSurat   =$this->templatehelper->convertKeTglIndo($row->tanggal_surat);
	$nomorSurat   =$row->nomor_surat;
	$tglPenetapan   =$this->templatehelper->convertKeTglIndo($row->tanggal_penetapan);
	$tglPenHakim   =$this->templatehelper->convertKeTglIndo($row->penetapan_majelis_hakim);
	$tglPenPP   =$this->templatehelper->convertKeTglIndo($row->penetapan_panitera_pengganti);
	$namaPP   =$this->templatehelper->standradnaming($row->nama_gelar);

	

}

$cPenggugat = count($penggugat);
$i = 1;
foreach ($penggugat as $item) {
	$naskah ="\b ".$this->templatehelper->standradnaming($item["nama"])." , \b0 ".$item["statusP"]."\b  Penggugat ".$this->templatehelper->converToAngkaRomawi($item["urutanP"])."\b0 ;";
	$brnaskah = (($cPenggugat > 1)?($i):("")).' \tab '.$naskah.' \\par '.PHP_EOL.(($i<$cPenggugat)?("#penggugatParties#"):(""));
	$Template = str_replace("#penggugatParties#",''.$brnaskah.'',$Template);	
	$i++;
}

$cTergugat = count($tergugat);
$i = 1;
foreach ($tergugat as $item) {
	$naskah ="\b ".$this->templatehelper->standradnaming($item["nama"])." , \b0 ".$item["statusT"]."\b  Tergugat ".$this->templatehelper->converToAngkaRomawi($item["urutanT"])."\b0 ;";
	$brnaskah = (($cTergugat > 1)?($i):("")).' \tab '.$naskah.' \\par '.PHP_EOL.(($i<$cTergugat)?("#tergugatParties#"):(""));
	$Template = str_replace("#tergugatParties#",''.$brnaskah.'',$Template);	
	$i++;
}

$Template = str_replace("#namaPengadilan#",''.$namaPengadilan.'',$Template);
$Template = str_replace("#nomorperkara#",''.$nomorperkara.'',$Template);
$Template = str_replace("#tanggalPendaftaran#",''.$tanggalPendaftaran.'',$Template);
$Template = str_replace("#tanggalSurat#",''.$tanggalSurat.'',$Template);
$Template = str_replace("#nomorSurat#",''.$nomorSurat.'',$Template);
$Template = str_replace("#tglPenetapan#",''.$tglPenetapan.'',$Template);
$Template = str_replace("#namaPejabat#",''.$namaPejabat.'',$Template);
$Template = str_replace("#jabatan#",''.$jabatan.'',$Template);
$Template = str_replace("#tglPenHakim#",''.$tglPenHakim.'',$Template);
$Template = str_replace("#tglPenPP#",''.$tglPenPP.'',$Template);
$Template = str_replace("#namaPP#",''.$namaPP.'',$Template);
$Template = str_replace("#kota#",''.$kota.'',$Template);

header("Content-type: application/rtf");
header("Content-disposition: inline; filename=".$namafile."-".$nomorperkara.".rtf");
header("Content-length: ".strlen($Template));
echo $Template;

?>