<?php
if($this->session->userdata('is_logged_in')===FALSE){
            redirect('login');
}
$url = base_url("resources/template/delegasi/pengantar_delegasi_keluar_pertama.rtf");
$Template = file_get_contents($url);
$tanggal_kirim = $this->templatehelper->convertKeTglIndo($tgl_pengiriman);
$tanggal_sidang = $this->templatehelper->convertKeTglIndo($tgl_sidang);
$hari_sidang = $this->templatehelper->getHari($tgl_sidang);
foreach ($datapengadilan as $row) {
	$Template = str_replace("#panitera#",''.$row->PansekPNNama.'',$Template);
	$Template = str_replace("#alamat_satker#",''.$row->AlamatPN.'',$Template);
}
foreach ($perkara_detil as $rows) {
	$Template = str_replace("#pihak1_text#",''.$rows->pihak1_text.'',$Template);
	$Template = str_replace("#pihak2_text#",''.$rows->pihak2_text.'',$Template);
	$Template = str_replace("#jenis_perkara_text#",''.$rows->jenis_perkara_text.'',$Template);
}
if ($idalurperkara=='15') {
    $Template = str_replace("#jenisperkara#",''."Gugatan".'',$Template);
    if ($jenisPerkaraID==346) {
        $Template = str_replace("#jenis_pihak1#",''."Pemohon".'',$Template);
        $Template = str_replace("#jenis_pihak2#",''."Termohon".'',$Template);
		$Template = str_replace("#sebagai_p#","Pemohon",$Template);
		$Template = str_replace("#sebagai_t#","Termohon",$Template);
    
    }else{
        $Template = str_replace("#jenis_pihak1#",''."Penggugat".'',$Template);
        $Template = str_replace("#jenis_pihak2#",''."Tergugat".'',$Template);
        $Template = str_replace("#sebagai_p#","Penggugat",$Template);
        $Template = str_replace("#sebagai_t#","Tergugat",$Template);
    }
}else{
    $Template = str_replace("#jenisperkara#",''." Permohonan ".'',$Template);   
    $Template = str_replace("#jenis_pihak1#",''." Pemohon ".'',$Template);
    $Template = str_replace("#jenis_pihak2#",''." Termohon ".'',$Template);
    $Template = str_replace("#sebagai_p#","Pemohon",$Template);
    $Template = str_replace("#sebagai_t#","Termohon",$Template);
}
$pisahnama = explode('<br>',$para_pihak);
$nama = $pisahnama[0];
$alamat = $pisahnama[1];
$pekerjaan = $pisahnama[2];

$Template = str_replace("#namapapengaju#",''.ucwords(strtolower($pn_asal_text)).'',$Template);
$Template = str_replace("#namapatujuan#",''.ucwords(strtolower($pn_tujuan_text)).'',$Template);
$Template = str_replace('#namakota#',''.ucwords(strtolower($namakota)).'',$Template);
$Template = str_replace("#nomorsurat#",''.$nomor_surat.'',$Template);
$Template = str_replace("#tanggaldaftar#",''.$tanggal_pendaftaran_perkara.'',$Template);
$Template = str_replace("#tanggalsurat#",''.$tanggal_kirim.'',$Template);
$Template = str_replace("#tanggalpenetapan#",''.$tanggal_phs.'',$Template);
$Template = str_replace("#tanggalsidang#",''.$tgl_sidang.'',$Template);
$Template = str_replace("#harisidang#",''.$hari_sidang.'',$Template);
$Template = str_replace("#nomorperkara#",''.$nomor_perkara.'',$Template);
$Template = str_replace("#biaya#",''.$biaya.'',$Template);
$Template = str_replace("#biayaterbilang#",''.$terbilang.'',$Template);
$Template = str_replace("#namapihak#",''.$nama.'',$Template);
$Template = str_replace("#alamat#",''.$alamat.'',$Template);
$Template = str_replace("#pekerjaan#",''.$pekerjaan.'',$Template);
$Template = str_replace("#parapihak1#",''.$pihak1_text.'',$Template);
$Template = str_replace("#parapihak2#",''.$pihak2_text.'',$Template);
$Template = str_replace("#tanggal_sekarang#",''.$this->templatehelper->convertKeTglIndo(date('Y-m-d')).'',$Template);
$nomorperkara = $nomor_perkara;
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=\"Cetak-pengantar-delegasi-keluar-Nomor-$nomorperkara.rtf\"");
echo $Template;
?>