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

$url = base_url("resources/template/berita_acara/perdata_umum/".$nama_file.".rtf");
$judulTemplate = preg_replace('/\s/','',$judul_cetak);
$Template = file_get_contents($url);

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;
$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;
    	$penggugat[] = $penggugatItem;
    }
    if (!in_multiarray($row->namaT, $tergugat)){
    	$tergugatItem = array();
    	$tergugatItem["nama"] = $row->namaT;
    	$tergugatItem["alamat"] = $row->alamatT;
    	$tergugatItem["statusT"] = $row->statusT;
    	$tergugat[] = $tergugatItem;
    }

	$nomorPerkara   =$row->nomorPerkara;
	$jenisPerkara = $row->jenisPerkara;
	$tanggalPenetapanHakim = $this->templatehelper->convertKeTglIndo($row->tanggalPenetapanHakim);
	$tanggalPendaftaran = $this->templatehelper->convertKeTglIndo($row->tanggalPendaftaran);
	$petitum = $this->templatehelper->cleanHtmlTag($row->petitum);
	$namaPN =$this->templatehelper->standradnaming($row->namaPN);
	$alamatPN = $this->templatehelper->standradnaming($row->alamatPN);
	$zonaWaktu = $this->templatehelper->standradnaming($row->zonaWaktu);
	$kota     =$this->templatehelper->namaKota($row->namaPN);
	$namaHakimTT   =$this->templatehelper->standradnaming($row->namaHakim1);
	$paniteraTT	= $this->templatehelper->standradnaming($row->namaPanitera1);
	$tanggalSurat  = $this->templatehelper->convertKeTglIndo($row->tanggalSurat);
	$tanggalSidangNow = $this->templatehelper->convertKeTglIndo($row->tanggalSidang1);
	$hariSidangNow = $this->templatehelper->getHari($row->tanggalSidang1);
	$jamSidangNow = $row->jamSidang1;
	$zonaWaktu = $row->zonaWaktu;
	$namaMediator = $this->templatehelper->standradnaming($row->namaMediator);
	$tanggalLaporanMediasi = $this->templatehelper->convertKeTglIndo($row->tanggalLaporanMediasi);
	$tanggalSidangNext = $this->templatehelper->convertKeTglIndo($row->tanggalSidang2);
	$hariSidangNext = $this->templatehelper->getHari($row->tanggalSidang2);
	$jamSidangNext = $row->jamSidang2;
	$agendaSidangNext = $row->agendaSidang2;
	$jenisHakim1 = $row->jenisHakim1;
	$jenisHakim2 = $row->jenisHakim2;
	$amarPutusan = $this->templatehelper->cleanHtmlTag($row->amarPutusan);
	$hariPutusan = $this->templatehelper->getHari($row->tanggalPutusan);
	$tanggalPutusan = $this->templatehelper->convertKeTglIndo($row->tanggalPutusan);
	$namaPansek = $this->templatehelper->standradnaming($row->PanSekNama);
	$nipPansek = $row->PanSekNIP;
	$namaWapan = $this->templatehelper->standradnaming($row->WaPanNama);
	$nipWapan = $row->WaPanNIP;
}

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


if($nama_file=='PDT_1_14_200_373'){
	if($petugas_sita=='1'){
		$namaPetugasx = $namaPansek;
		$jenisPetugasx = "Panitera";
	} else if ($petugas_sita=='2'){
		$namaPetugasx = $namaWapan;
		$jenisPetugasx = "Wakil Panitera";
	}
	$Template = str_replace('#petugassita#',''.$namaPetugasx.'',$Template);
	$Template = str_replace('#jenispetugas#',''.$jenisPetugasx.'',$Template);
	$Template = str_replace('#namatergugat#',''.$namaTergugatx.'',$Template);
	$Template = str_replace('#pekerjaantergugat#',''.$pekerjaanTergugatx.'',$Template);
	$Template = str_replace('#alamattergugat#',''.$alamatTergugatx.'',$Template);
	$Template = str_replace('#namapenggugat#',''.$namaPenggugatx.'',$Template);
	$Template = str_replace('#pekerjaanpenggugat#',''.$pekerjaanPenggugatx.'',$Template);
	$Template = str_replace('#alamatpenggugat#',''.$alamatTergugatx.'',$Template);
}

if(($nama_file=='PDT_3_14_200_307')||($nama_file=='PDT_3_14_200_2')){
	$Template = str_replace('#namakurator#',''.$nama_kurator.'',$Template);
	$Template = str_replace('#alamatkurator#',''.$alamat_kurator.'',$Template);
}

$Template = str_replace('#nomorperkara#',''.$nomorPerkara.'',$Template);
$Template = str_replace('#jenisperkara#',''.$jenisPerkara.'',$Template);
$Template = str_replace('#tanggalpendaftaran#',''.$tanggalPendaftaran.'',$Template);
$Template = str_replace('#amarpetitum#',''.$petitum.'',$Template);
$Template = str_replace('#namapn#',''.$namaPN.'',$Template);
$Template = str_replace('#alamatpn#',''.$alamatPN.'',$Template);
$Template = str_replace('#tanggalsurat#',''.$tanggalSurat.'',$Template);
$Template = str_replace('#harisidang#',''.$hariSidangNow.'',$Template);
$Template = str_replace('#tanggalsidang#',''.$tanggalSidangNow.'',$Template);
$Template = str_replace('#jamsidang#',''.$jamSidangNow.'',$Template);
$Template = str_replace('#zonawaktu#',''.$zonaWaktu.'',$Template);
$Template = str_replace('#hakim#',''.$hakim.'',$Template);
$Template = str_replace('#panitera#',''.$panitera.'',$Template);
$Template = str_replace('#namamediator#',''.	$namaMediator.'',$Template);
$Template = str_replace('#tanggallaporanmediasi#',''.$tanggalLaporanMediasi.'',$Template);
$Template = str_replace('#paniteraTT#',''.$paniteraTT.'',$Template);
$Template = str_replace('#hakimTT#',''.$namaHakimTT.'',$Template);
$Template = str_replace('#tanggalsidangnew#',''.$tanggalSidangNext.'',$Template);
$Template = str_replace('#harisidangnew#',''.$hariSidangNext.'',$Template);
$Template = str_replace('#jamsidangnew#',''.$jamSidangNext.'',$Template);
$Template = str_replace('#agendasidangnew#',''.$agendaSidangNext.'',$Template);
$Template = str_replace('#amarputusan#',''.$amarPutusan.'',$Template);
$Template = str_replace('#tanggalputusan#',''.$tanggalPutusan.'',$Template);
$Template = str_replace('#hariputusan#',''.$hariPutusan.'',$Template);
$Template = str_replace('#jenishakim1#',''.$jenisHakim1.'',$Template);
$Template = str_replace('#jenishakim2#',''.$jenisHakim2.'',$Template);
$Template = str_replace('#hakimanggotaTT#',''.$hakimAnggotaTT.'',$Template);
$Template = str_replace('#hakimanggota#',''.$hakim_anggota.'',$Template);
$Template = str_replace('#penetapanhakim#',''.$tanggalPenetapanHakim.'',$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=\"".$judulTemplate."-".$nomorPerkara.".rtf\"");
header("Content-length: ".strlen($Template));
echo $Template;
?>