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

$jenistemplate=intval($jenistemplate);
if(!is_numeric($jenistemplate)){
    show_404();
    exit();
}

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


if ($jenistemplate==1){
$url = base_url("resources/template/putusan/pidana_militer/".$filename.".rtf");			
}elseif ($jenistemplate==2){
$url = base_url("resources/template/putusan/pidana_militer/".$filename.".rtf");		
}elseif ($jenistemplate==3){
$url = base_url("resources/template/berita_acara/pidana_militer/".$filename.".rtf");           
}

$Template = file_get_contents($url);
//--------------MULAI--------------------------------------------//
if (!empty($dataputusan->row()->nomor_perkara)){
	$nomorperkara=$dataputusan->row()->nomor_perkara;
	$nomorperkarasplit=explode("/",$nomorperkara);
	$noreg=$nomorperkarasplit[0]; 
	$matra=$nomorperkarasplit[2]; 
	$bulan=$nomorperkarasplit[3]; 
	$tahun=$nomorperkarasplit[4]; 

}else{
	$nomorperkara="..........";
	$noreg="..........";
	$matra="..........";
	$bulan="..........";
	$tahun="..........";

}

//nomor putusan banding stive 

if (!empty($databandingter->row()->nomor_putusan_banding)){
	$nomorputusanbanding=$databandingter->row()->nomor_putusan_banding; 
	//$nomorputusanbandingsplit=explode("/",$nomorputusanbanding);
	//$noreg_pts_banding=$nomorputusanbandingsplit[0]; 
	//$kode_pt_pts_banding=$nomorputusanbandingsplit[1]; 	
	//$matra_pts_banding=$nomorputusanbandingsplit[2]; 
	//$bulan_pts_banding=$nomorputusanbandingsplit[3]; 
	//$tahun_pts_banding=$nomorputusanbandingsplit[4]; 

    $noreg_pts_banding=$databandingter->row()->nomor_register; 
    $kode_pt_pts_banding=$databandingter->row()->kode_pt; 
    $kodepn=$databandingter->row()->kodee_pn; 
    $matra_pts_banding=$databandingter->row()->matra; 
    $bulan_pts_banding=$this->templatehelper->converToAngkaRomawi($databandingter->row()->bulan);
    $tahun_pts_banding=$databandingter->row()->tahun;

    

}else{
	$nomorputusanbanding="..........";
	$noreg_pts_banding=".........."; 
	$kode_pt_pts_banding=".........."; 
	$matra_pts_banding="..........";
	$bulan_pts_banding="..........";
	$tahun_pts_banding="..........";

}

//end of nomor putusan banding stiven

// if (!empty($dataputusan->row()->tanggal_bht)){
	// $tglbht=$dataputusan->row()->tanggal_bht;
	// $tglbhtsplit=explode("-",$tglbht);
	// $thnbht=$tglbhtsplit[0];
	// $blnbht=$this->templatehelper->converToAngkaRomawi($tglbhtsplit[1]);
	// $haribht=$this->templatehelper->getHari($tglbht);
	// $tglbht=$this->templatehelper->convertKeTglIndo($tglbht);
// }else{
	// $tglbht="..........";
	// $thnbht="..........";
	// $blnbht="..........";	
	// $haribht="..........";	
// }

// if (!empty($dataputusan->row()->namaOditur)){
	// $namaOditur=$this->templatehelper->standradnaming($this->templatehelper->ucname($dataputusan->row()->namaOditur));
	// $pangkatOditur=$dataputusan->row()->pangkatOditur;
	// $namapangkatoditur="$pangkatOditur $namaOditur";
// }else{
	// $namapangkatoditur="..........";
// }
// if (!empty($dataputusan->row()->nrpOditur)){	
	// $nrpOditur=$dataputusan->row()->nrpOditur;
// }else{
	// $nrpOditur="..........";
// }
// if (!empty($dataputusan->row()->tanggal_putusan)){	
	// $tglputusan=$this->templatehelper->convertKeTglIndo($dataputusan->row()->tanggal_putusan);
// }else{
	// $tglputusan="..........";
// }


	
if (!empty($datapengadilan->row()->PansekPNNip)){
	$nrppanitera=$datapengadilan->row()->PansekPNNip;
}else{
	$nrppanitera="..........";
}
if (!empty($datapengadilan->row()->PansekPNNama) && !empty($datapengadilan->row()->PansekPNPangkat)){
	$namapanitera=$this->templatehelper->standradnaming($this->templatehelper->ucname($datapengadilan->row()->PansekPNNama));
	$pangkatpanitera=$datapengadilan->row()->PansekPNPangkat;
	$namapangkatpanitera="$pangkatpanitera $namapanitera";
}else{
	$namapanitera="..........";
	$pangkatpanitera="..........";
	$namapangkatpanitera="..........";
}
if (!empty($datapengadilan->row()->KodePN) && !empty($datapengadilan->row()->NamaPN)){
	$kodepengadilan=$datapengadilan->row()->KodePN;
	$kodepengadilansplit=explode(".",$kodepengadilan);
	$kodepengadilan=$kodepengadilansplit[1];
	$namapengadilan=$datapengadilan->row()->NamaPN;
	$namapengadilansplit=explode($kodepengadilan,$namapengadilan);
	$kotapengadilan=trim($namapengadilansplit[1]);
	$kotapengadilan1=$this->templatehelper->ucname($kotapengadilan); 
}else{
	$kodepengadilan="..........";
	$kotapengadilan="..........";
	$kotapengadilan1="..........";
}

if (!empty($databanding->row()->nrp)){
	$nrpterdakwa=$databanding->row()->nrp;
}else{
	$nrpterdakwa="..........";
}
//if (!empty($dataterdakwa->row()->nama)){
//	$namaterdakwa=$this->templatehelper->standradnaming($this->templatehelper->ucname($dataterdakwa->row()->nama)); 
//	$kode_pt=$dataterdakwa->row()->kode_pt; 



//	$kota_pt=$dataterdakwa->row()->kota_pt; 
//	if (!empty($dataterdakwa->row()->pangkat)){
//		$pangkatterdakwa=$dataterdakwa->row()->pangkat;
//		$namapangkatterdakwa="$pangkatterdakwa $namaterdakwa";
//	}
//	$namapangkatterdakwa="$namaterdakwa";
// }else{
//	$namapangkatterdakwa="..........";
// }

if (!empty($databanding->row()->nama)){
	$namaterdakwa=$this->templatehelper->standradnaming($this->templatehelper->ucname($databanding->row()->nama)); 
	$kode_pt=$databanding->row()->kode_pt; 

	

	$kota_pt=$databanding->row()->kota_pt; 
	if (!empty($databanding->row()->pangkat)){
		$pangkatterdakwa=$databanding->row()->pangkat;
		$namapangkatterdakwa="$pangkatterdakwa $namaterdakwa";
	}
	$namapangkatterdakwa="$namaterdakwa";
}else{
	$namapangkatterdakwa="..........";
}

//stiven 
$nomor_perkara_banding = $databandingter->row()->nomor_perkara_banding; 
$nomor_putusan_banding = $databandingter->row()->nomor_putusan_banding;  
$tgl_putusan_banding = $this->templatehelper->convertKeTglIndo($databandingter->row()->tgl_putusan_banding); 
$amar_putusan_banding = $databandingter->row()->amar_putusan_banding;
$today = date("Y-m-d"); 
$tgl_sekarang = $this->templatehelper->convertKeTglIndo($today); 
$hari_ini = $this->templatehelper->getHari($today); 
$tgl_ke_empat_belas = date("Y-m-d", strtotime("+14 days", strtotime($today)));
$tgl_paling_lambat = $this->templatehelper->convertKeTglIndo($tgl_ke_empat_belas); 

if (empty($kode_pt)){$kode_pt="..........";} 
if (empty($kota_pt)){$kota_pt="..........";}
if (empty($nomor_perkara_banding)){$nomor_perkara_banding="..........";}
if (empty($tgl_putusan_banding)){$tgl_putusan_banding="..........";} 
if (empty($amar_putusan_banding)){$amar_putusan_banding="..........";} 
if (empty($tgl_ke_empat_belas)){$tgl_ke_empat_belas="..........";} 
if (empty($tgl_paling_lambat)){$tgl_paling_lambat="..........";}

// if ($tanggapan==1){
	// $redaksi="haknya dalam tenggang waktu 7 (tujuh) hari dihitung mulai hari berikutnya setelah Putusan diucapkan/diberitahukan untuk mencabut pernyataan menerima";
// }else{
	// $redaksi="kesempatan berpikir dalam tenggang waktu 7 (tujuh) hari dihitung mulai hari berikutnya setelah Putusan diucapkan/diberitahukan untuk menyatakan menolak";
// }

// $Template = str_replace('#nomor_perkara#',''.$nomorperkara.'',$Template);
// $Template = str_replace('#no_register#',''.$noreg.'',$Template);
// $Template = str_replace('#matra#',''.$matra.'',$Template);
// $Template = str_replace('#bulan#',''.$blnbht.'',$Template);
// $Template = str_replace('#tahun#',''.$thnbht.'',$Template);
// $Template = str_replace('#nama_pangkat_korp_oditur#',''.$namapangkatoditur.'',$Template);
// $Template = str_replace('#nrp_oditur#',''.$nrpOditur.'',$Template);
// $Template = str_replace('#tanggal_putusan#',''.$tglputusan.'',$Template);
// $Template = str_replace('#hari_bht#',''.$haribht.'',$Template);
// $Template = str_replace('#tgl_bht#',''.$tglbht.'',$Template);

$Template = str_replace('#nrp_panitera#',''.$nrppanitera.'',$Template);
$Template = str_replace('#nama_panitera#',''.$namapanitera.'',$Template);
$Template = str_replace('#pangkat_korp#',''.$pangkatpanitera.'',$Template);
$Template = str_replace('#nama_pangkat_korp_katera#',''.$namapangkatpanitera.'',$Template);
$Template = str_replace('#kode_pn1#',''.$kodepengadilan.'',$Template);
$Template = str_replace('#kota_pn1#',''.$kotapengadilan.'',$Template);
$Template = str_replace('#kota_pn#',''.$kotapengadilan1.'',$Template);

$Template = str_replace('#no_register#',''.$noreg.'',$Template);
$Template = str_replace('#kode_pn#',''.$kodepengadilan.'',$Template);
$Template = str_replace('#matra#',''.$matra.'',$Template);
$Template = str_replace('#bulan#',''.$bulan.'',$Template);
$Template = str_replace('#tahun#',''.$tahun.'',$Template);

$Template = str_replace('#kode_pt#',''.$kode_pt.'',$Template);
$Template = str_replace('#kota_pt#',''.$kota_pt.'',$Template);
$Template = str_replace('#tanggal_sekarang#',''.$tgl_sekarang.'',$Template);
$Template = str_replace('#tgl_ke_14_sejak_surat_ini_terbit#',''.$tgl_paling_lambat.'',$Template);
$Template = str_replace('#hari#',''.$hari_ini.'',$Template); 
$Template = str_replace('#tanggal#',''.$tgl_sekarang.'',$Template);

$Template = str_replace('#no_reg#',''.$noreg_pts_banding.'',$Template); 
$Template = str_replace('#kd_pt#',''.$kode_pt_pts_banding.'',$Template);
$Template = str_replace('#kd_matra#',''.$matra_pts_banding.'',$Template);
$Template = str_replace('#bln#',''.$bulan_pts_banding.'',$Template);
$Template = str_replace('#thn#',''.$tahun_pts_banding.'',$Template);

$Template = str_replace('#nama_katera#',''.$namapanitera.'',$Template);
$Template = str_replace('#nrp_katera#',''.$nrppanitera.'',$Template);

$Template = str_replace('#nomor_register_banding#',''.$nomor_perkara_banding.'',$Template); 
$Template = str_replace('#nomor_putusan_banding#',''.$nomor_putusan_banding.'',$Template);

$Template = str_replace('#tanggal_putusan_banding#',''.$tgl_putusan_banding.'',$Template); 
$Template = str_replace('#tanggal_putus#',''.$tgl_putusan_banding.'',$Template);

$Template = str_replace('#pidanaTerdakwa#',''.$amar_putusan_banding.'',$Template);

$Template = str_replace('#nama_pangkat_korp_terdakwa#',''.$namapangkatterdakwa.'',$Template);
$Template = str_replace('#nama_pangkat_terdakwa#',''.$namapangkatterdakwa.'',$Template);
$Template = str_replace('#nrp_terdakwa#',''.$nrpterdakwa.'',$Template);
// $Template = str_replace('#redaksi#',''.$redaksi.'',$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\"");
echo $Template;
?>