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

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

$url = base_url("resources/template/putusan/pidana_pra/".$filename.".rtf");
$Template = file_get_contents($url);

foreach ($data_pn->result() as $row) {
    $namaPengadilan=$row->NamaPN;
}
foreach ($data_pp->result() as $row) {
    $namaPP=$row->nama_gelar;
}

foreach ($data_putusan->result() as $row) {
    $tgl_putusan=$row->tanggal_putusan;
}
if (empty($tgl_putusan)||($tgl_putusan==NULL))
{
	$tgl_putusan='';
}

foreach ($data_penetapan_hakim->result() as $row) {
    $tanggal_penetapan_hakim=$row->tanggal_penetapan;
    $hakim_nama=$row->hakim_nama;
}
foreach ($data_pp->result() as $row) {
    $namaPP=$row->nama_gelar;
}

foreach ($data_perkara->result() as $row) {
	$nomorperkara=$row->nomor_perkara;
    $statusPemohon=$row->statusP;
    $statusTermohon=$row->statusT;
    $tgl_pendaftaran=$row->tanggal_pendaftaran;
    $nomor_perkara=$row->nomor_perkara;
    $tgl_gugatan=$row->tgl_gugatan;
    $nomor_surat=$row->nomor_surat;
    $nama_pemohon=$row->namaP;
    $alamat_pemohon=$row->alamatP;
    $status_pemohon=$row->statusP;
    $nama_termohon=$row->namaT;
    $status_termohon=$row->statusT;
    $tgl_lahir_pemohon=$row->tglLahirP;
    $tempat_lahir_pemohon=$row->tempatlahirP;
    $umur_pemohon=$this->tanggalhelper->getSelisihTahun($row->tglLahirP,date('Y-m-d'));
    $pekerjaan_pemohon=$row->pekerjaanP;
    $jenis_kelamin_pemohon=$row->jenis_kelaminP;
    $agama_pemohon=$row->agamaP;
    $kebangsaan_pemohon=$row->wargaNegaraP;
    $agama_pemohon=$row->agamaP;


}

$Template = str_replace("#nama_pemohon#".'',$nama_pemohon,$Template);
$Template = str_replace("#nama_termohon#".'',$nama_termohon,$Template);
$Template = str_replace("#tgl_lahir_pemohon#".'',$tgl_lahir_pemohon,$Template);
$Template = str_replace("#tempat_lahir_pemohon#".'',$tempat_lahir_pemohon,$Template);
$Template = str_replace("#umur_pemohon#".'',$umur_pemohon,$Template);
    if ($jenis_kelamin_pemohon=="L") {
        $Template = str_replace("#jenis_kelamin_pemohon#".'',"Laki-laki",$Template);
    } else {
        $Template = str_replace("#jenis_kelamin_pemohon#".'',"Perempuan",$Template);
    }
$Template = str_replace("#kebangsaan_pemohon#".'',$kebangsaan_pemohon,$Template);
$Template = str_replace("#alamat_pemohon#".'',$alamat_pemohon,$Template);
$Template = str_replace("#agama_pemohon#".'',$agama_pemohon,$Template);
$Template = str_replace("#pekerjaan_pemohon#".'',$pekerjaan_pemohon,$Template);


$Template = str_replace("#nomor_perkara#",$nomorperkara.'',$Template);
$Template = str_replace("#status_pemohon",$statusPemohon.'',$Template);
$Template = str_replace("#status_termohon#",$statusTermohon.'',$Template);
$Template = str_replace("#tgl_surat#",$tgl_gugatan.'',$Template);
$Template = str_replace("#tgl_pendaftaran#",$this->templatehelper->convertKeTglIndo($tgl_pendaftaran).'',$Template);
$Template = str_replace("#tgl_penetapan_hakim#",$this->templatehelper->convertKeTglIndo($tanggal_penetapan_hakim).'',$Template);
$Template = str_replace("#nama_pn#",$this->templatehelper->standradnaming($namaPengadilan).'',$Template);
$Template = str_replace("#nama_pp#",$this->templatehelper->standradnaming($namaPP).'',$Template);
$Template = str_replace("#hakim_nama#",$this->templatehelper->standradnaming($hakim_nama).'',$Template);
$Template = str_replace("#tgl_putusan#".'',$this->templatehelper->convertKeTglIndo($tgl_putusan),$Template);
$Template = str_replace("#hari_putusan#".'',$this->templatehelper->gethari($tgl_putusan),$Template);
$Template = str_replace("#tgl_sidang#".'',$this->templatehelper->convertKeTglIndo($tgl_putusan),$Template);
$Template = str_replace("#hari_sidang#".'',$this->templatehelper->gethari($tgl_putusan),$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."-".$nomorperkara.".rtf\"");
header("Content-length: ".strlen($Template));
echo $Template;
?>