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

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

$tglPenyerahanKontraM=$tglpenyerahan;
$tglPenerimaanKontraM=$tglpenerimaan;

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

$url = base_url("resources/template/relaas/pidana_umum/".$filename.".rtf");

$Template = file_get_contents($url);

//---------------Mulai--------------------------------------//
function cetakPihak(&$strbuf, $tmp_label, $arrDef, $hasilFetch, $cetakLabel = true){
    $tblcnt = 1;
    $jmlphk = count($hasilFetch);
    foreach($hasilFetch as $baris){
        $idxKolom = 1;
        foreach($arrDef as $kolomTabel => $label){
            $counter = (($jmlphk > 1)?($tblcnt.'.'):(''));
            $strbuf = str_replace($tmp_label,
                    (($idxKolom == 1)?($counter):('')).
                        ' \tab '.(($cetakLabel)?$label:('')).(($cetakLabel)?(' \tab : \tab '):('')).$baris[$kolomTabel].'; \\par'.
                        PHP_EOL.
                        //$tmp_label,
                        (($idxKolom < count($arrDef)) ? 
                            ($tmp_label) 
                            :  
                            (($tblcnt<$jmlphk)?($tmp_label):('')) 
                        ),
                    $strbuf);
            $idxKolom++;
        }
        $tblcnt++;
    }
}

//-------------Nomor Perkara & Tanggal Pemerbitahuan----------------------//
$data_perkara = $dataPerkara;
$nomorperkara = '';
foreach ($data_perkara->result() as $row) {
        $nomorperkara = $row->nomor_perkara;
    }
if(empty($nomorperkara)){ $nomorperkara = '........'; }
$akta="Akta ";
$nomorperkarabaru=substr_replace($nomorperkara, $akta, 
    strpos($nomorperkara,'/')+1, 
    0);
$Template = str_replace("#nomorperkarabaru#",''.$nomorperkarabaru.'',$Template);
$Template = str_replace("#nomorperkara#",''.$nomorperkara.'',$Template);


//-------------Data Tanggal Putusan-------------------//
$tanggalPutusan=$tanggalPutus;
foreach ($tanggalPutusan->result() as $row) {
    $tglputus=$this->templatehelper->convertKeTglIndo($row->tanggal_putusan);
}
$Template = str_replace('#tgl_putus#',''.$tglputus.'',$Template);

//---------------Data Pengadilan--------------------//
$datapengadilan = $dataPN;
$namapn = '';
foreach ($datapengadilan->result() as $row) {
    $namapn = $this->templatehelper->standradnaming($row->NamaPN);
    $namakota =str_replace("Pengadilan Negeri ",'',$namapn);
    $nama_pt = $this->templatehelper->standradnaming($row->NamaPT);     
}

$Template = str_replace('#nama_pn#',''.$namapn.'',$Template);
$Template = str_replace('#namakota#',''.$namakota.'',$Template);
$Template = str_replace('#namapt#',''.$nama_pt.'',$Template);

//----------------Data Jurusita--------------------//
$namajurusita=$cetakJurusita;
foreach ($namajurusita->result() as $row) {
	$namajurusita = $this->templatehelper->standradnaming($row->nama_gelar);
}
$Template = str_replace('#namajurusita#',''.$namajurusita.'',$Template);


//-----------------Data Jaksa---------------------//
$databanding = $cetakDataJPU;
$jpu = '';
$nip = '';
foreach ($databanding->result() as $row) {        
        $jpu = $this->templatehelper->standradnaming($row->nama);
        $nip = $row->NIP;
}
if(empty($jpu)){
        $jpu = '..................';
    }
if(empty($nip)){
        $nip = '..................';
    }    
$Template = str_replace("#nip#",''.$nip.'',$Template);
$Template = str_replace("#namajaksa#",''.$jpu.'',$Template);      

//------------------Data Terdakwa Parties Banding-----------//
if(($jenisAkta==1)||($jenisAkta==4)||($jenisAkta==6)||($jenisAkta==8)||($jenisAkta==10)){
	$dataterdakwa = $cetakpartiesbanding;
    $tblcnt = 1;
    $dataterdakwa->num_rows>0;
    //$jmltdkw = count($dataterdakwa);
    $p = array();
    $gkolom = array(
        'nama' => 'Nama Lengkap',
        'tempat_lahir' => 'Tempat Lahir',
        'umur' => 'Umur / Tgl. Lahir',
        'jenis_kelamin' => 'Jenis Kelamin',
        'warga_negara' => 'Kebangsaan',
        'alamat' => 'Tempat Tinggal',
        'agama' => 'Agama',
        'pekerjaan' => 'Pekerjaan'
        );
    foreach ($dataterdakwa->result() as $row){   
        $tglBanding = $this->templatehelper->convertKeTglIndo($row->permohonan_banding);
        $inpass = array();

        if(empty($row->nama)){
            $row->nama = '......'; 
        }

        $namaterdakwa = $this->templatehelper->standradnaming($row->nama);
        $inpass['nama'] = $namaterdakwa;

        if(empty($row->tempat_lahir)){
            $row->tempat_lahir = '......'; 
        }

        $tempatlahir = $row->tempat_lahir;
        $inpass['tempat_lahir'] = $this->templatehelper->standradnaming($tempatlahir);

        if(empty($row->umur)){
            $tgllahir = '......'; 
        }else{
            $tgllahir = $this->templatehelper->convertKeTglIndo($row->tanggal_lahir);
        }

        if(empty($row->umur)){
            $row->umur = '......'; 
        }
        $umur = $row->umur;
        $inpass['umur'] = $umur.' Tahun / '.$tgllahir;

        if(empty($row->warga_negara)){
            $row->warga_negara = '......'; 
        }

        $kebangsaan = $this->templatehelper->standradnaming($row->warga_negara);
        $inpass['warga_negara'] = $kebangsaan;

        if(empty($row->alamat)){
            $row['alamat'] = '......'; 
        }
        $alamat = $row->alamat;
        $inpass['alamat'] = $this->templatehelper->standradnaming($alamat);

        if(empty($row->agama_nama)){
            $row->agama_nama = '......'; 
        }
        $agama = $this->templatehelper->standradnaming($row->agama_nama);
        $inpass['agama'] = $agama;
        
        if(empty($row->pekerjaan)){
            $row->pekerjaan = '......'; 
        }
        $pekerjaan = $this->templatehelper->standradnaming($row->pekerjaan);     
        $inpass['pekerjaan'] = $pekerjaan;

        if($row->jenis_kelamin=='L'){
            $row->jenis_kelamin = 'Laki - Laki';
        }elseif($row->jenis_kelamin=='P'){
            $row->jenis_kelamin = 'Perempuan';
        }
        $sex = $row->jenis_kelamin;
        $inpass['jenis_kelamin'] = $sex;
        
        $tblcnt++;

        $p[] = $inpass;
    }
    cetakPihak($Template, '#terdakwaparties#', $gkolom, $p);
    if ($dataterdakwa->num_rows>1) {
        $Template = str_replace('#jmlTerdakwa#','Para Terdakwa',$Template);
    } else {
        $Template = str_replace('#jmlTerdakwa#','Terdakwa',$Template);
    }
       
	if(empty($tglpemberitahuan)){
    	$tglPemberitahuan = '..................';
    	$haripengajuan = '.................';
	}else{
    	$haripengajuan = $this->templatehelper->getHari($tglpemberitahuan);
        $tglPemberitahuan = $this->templatehelper->convertKeTglIndo($tglpemberitahuan);
	}
	$Template = str_replace("#tglpermohonan#",''.$tglPemberitahuan.'',$Template);
	$Template = str_replace("#haripermohonan#",''.$haripengajuan.'',$Template);

	$penyerahanM = $cetakTglRelaasPU;
	foreach ($penyerahanM->result() as $row) {
    	$tglPenyerahanM=$row->penyerahan_memori_banding;    	
	}
	if(empty($tglPenyerahanM)){
	    $tglPenyerahanM = '..................';
	    $hariPenyerahanM = '.................';
	}else{
	    $hariPenyerahanM = $this->templatehelper->getHari($tglPenyerahanM);
	}
    if($jenisAkta==8){
        $tglbandingterdakwa = $infotglbandingterdakwa;
        if(!empty($tglbandingterdakwa)) {
            foreach ($tglbandingterdakwa->result() as $row) {
               $tglBanding=$this->templatehelper->convertKeTglIndo($row->permohonan_banding);
            }
        }
    }
	if(empty($tglBanding)){$tglBanding='...............';}
    $tglPenyerahanM = $this->templatehelper->convertKeTglIndo($tglPenyerahanM);
	$Template = str_replace('#tglpenyerahanmemori#',''.$tglPenyerahanM.'',$Template);
	$Template = str_replace('#haripenyerahanmemori#',''.$hariPenyerahanM.'',$Template);
	$Template = str_replace('#tgl_akta_banding#',$tglBanding,$Template);

	$dataPUBanding = $cetakPUBanding;
	foreach ($dataPUBanding->result() as $row) {
    	$tglPenyerahanKontra = $row->penyerahan_kontra_banding;
    	$tglPenerimaanMemori=$this->templatehelper->convertKeTglIndo($row->penerimaan_memori_banding);
    	$statusPU=($row->status_pihak_text);
    	$tglPemberitahuanInzag = $row->pemberitahuan_inzage;
    	$tanggalPtsPT = $row->pemberitahuan_putusan_banding;
	}
	if(empty($tglPenyerahanKontraM)){
	    $tglPenyerahanKontra = '..................';
	    $hariPenyerahanKontra = '.................';
	}else{
	    $hariPenyerahanKontra = $this->templatehelper->getHari($tglPenyerahanKontraM);
        $tglPenyerahanKontra = $this->templatehelper->convertKeTglIndo($tglPenyerahanKontraM);
	}
	if(empty($tglPenerimaanMemori)){$tglPenerimaanMemori='................';}
	if(empty($statusPU)){$statusPU='................';}
	if(empty($tglPemberitahuanInzag)){
	    $tglPemberitahuanInzag = '..................';
	    $hariPemberitahuanInzag = '.................';
	}else{
	    $hariPemberitahuanInzag = $this->templatehelper->getHari($tglPemberitahuanInzag);
        $tglPemberitahuanInzag = $this->templatehelper->convertKeTglIndo($tglPemberitahuanInzag);
	}
	if(empty($tanggalPtsPT)){
	    $tanggalPtsPT = '..................';
	    $hariPtsPT = '.................';
	}else{
	    $hariPtsPT = $this->templatehelper->getHari($tanggalPtsPT);
        $tanggalPtsPT = $this->templatehelper->convertKeTglIndo($tanggalPtsPT);
	}
	$Template = str_replace('#tglpenyerahankontramemori#',''.$tglPenyerahanKontra.'',$Template);
	$Template = str_replace('#haripenyerahankontramemori#',''.$hariPenyerahanKontra.'',$Template);
	$Template = str_replace('#tglpenerimaanmemori#',''.$tglPenerimaanMemori.'',$Template);
	$Template = str_replace('#statuspihak#',''.$statusPU.'',$Template);
	$Template = str_replace('#tglpemberitahuaninzage#',''.$tglPemberitahuanInzag.'',$Template);
	$Template = str_replace('#haripemberitahuaninzage#',''.$hariPemberitahuanInzag.'',$Template);
	$Template = str_replace('#tglptspt#',''.$tanggalPtsPT.'',$Template);
	$Template = str_replace('#hariptspt#',''.$hariPtsPT.'',$Template);
	//----------------Data Banding di PT------------------//
	$dataPT=$cetakBandingPT;
    foreach ($dataPT->result() as $row) {
			$nomorPerkaraPT=($row->nomor_perkara_banding);
			$tglPutusPT=$this->templatehelper->convertKeTglIndo($row->tglPutusanBanding);
			$amarPutusanPT=$this->templatehelper->cleanHtmlTag($row->amar_putusan_banding);	
	}
	if(empty($nomorPerkaraPT)){$nomorPerkaraPT = '..................';}
	if(empty($tglPutusPT)){$tglPutusPT = '..................';}
	if(empty($amarPutusanPT)){$amarPutusanPT = '-Isi Amar Putusan Banding PT-';}
	$Template = str_replace("#nomorpt#",''.$nomorPerkaraPT.'',$Template);
	$Template = str_replace("#tglputuspt#",''.$tglPutusPT.'',$Template);
	$Template = str_replace("#amarpt#",''.$amarPutusanPT.'',$Template);

	$tampilAllTerdakwa=$cetakAllTerdakwa;
	$cnt = $tampilAllTerdakwa->num_rows;
	$pihak_nama ='';
	$T=0;
	foreach ($tampilAllTerdakwa->result() as $row){
		$T++;
		$pihak_nama .=$row->nama;
		if($T!=$cnt){
			$pihak_nama .= ', ';
		}
	}
	$Template = str_replace('#pihakterdakwa#',''.$this->templatehelper->standradnaming($pihak_nama).'',$Template);
	if($cnt>1){
		$Template = str_replace('#jmlterdakwa#','Para Terdakwa',$Template);
	}else{
		$Template = str_replace('#jmlterdakwa#','Terdakwa',$Template);
	}

}
//-------------Data Terdakwa 1-------------------------//
if(($jenisAkta==2)||($jenisAkta==3)||($jenisAkta==5)||($jenisAkta==9)||($jenisAkta==11)){
    $dataterdakwa = $cetakDataTerdakwa;
    foreach ($dataterdakwa->result() as $row){
        if(empty($row->nama)){
            $row->nama = '......'; 
        }

        $namaterdakwa = '\listid1 '.$this->templatehelper->standradnaming($row->nama);

        if(empty($row->tempat_lahir)){
            $row->tempat_lahir = '......'; 
        }

        $tempatlahir = '\listid1 '.$this->templatehelper->standradnaming($row->tempat_lahir);

        if(empty($row->umur)){
            $tgllahir = '......'; 
        }else{
            $tgllahir = '\listid1 '.$this->templatehelper->convertKeTglIndo($row->tanggal_lahir);
        }

        if(empty($row->umur)){
            $row->umur = '......'; 
        }
        $umur = '\listid1 '.$row->umur.' Tahun';

        if(empty($row->warga_negara)){
            $row->warga_negara = '......'; 
        }

        $kebangsaan = '\listid1 '.$this->templatehelper->standradnaming($row->warga_negara);

        if(empty($row->alamat)){
            $row->alamat = '......'; 
        }
        $alamat = '\listid1 '.$this->templatehelper->standradnaming($row->alamat);

        if(empty($row->agama_nama)){
            $row->agama_nama = '......'; 
        }
        $agama = '\listid1 '.$this->templatehelper->standradnaming($row->agama_nama);
        
        if(empty($row->pekerjaan)){
            $row->pekerjaan = '......'; 
        }

        $pekerjaan = '\listid1 '.$this->templatehelper->standradnaming($row->pekerjaan);
        
        if($row->jenis_kelamin=='L'){
            $row->jenis_kelamin = 'Laki - Laki';
        }elseif($row->jenis_kelamin=='P'){
            $row->jenis_kelamin = 'Perempuan';
        }
        $sex = '\listid1 '.$row->jenis_kelamin;
    }

    $Template = str_replace('#namaterdakwa#',''.$namaterdakwa.'',$Template);
    $Template = str_replace('#tempatlahir#',''.$tempatlahir.'',$Template);
    $Template = str_replace('#umur#',''.$umur.'',$Template);
    $Template = str_replace('#tgllahir#',''.$tgllahir.'',$Template);
    $Template = str_replace('#kebangsaan#',''.$kebangsaan.'',$Template);
    $Template = str_replace('#alamat#',''.$alamat.'',$Template);
    $Template = str_replace('#agama#',''.$agama.'',$Template);
    $Template = str_replace('#pekerjaan#',''.$pekerjaan.'',$Template);
    $Template = str_replace('#jeniskelamin#',''.$sex.'',$Template);

    //-------------Data Parties Jaksa----------------//
    $dataJaksa = $cetakPartiesJaksa;
    $tblcnt2 = 1;
    $dataJaksa->num_rows>0;    
    $p2 = array();
    $gkolom2 = array(
        'nama' => 'Nama lengkap',
		'nip' => 'NIP',
		'jabatan' => 'Jabatan'
        );
    foreach ($dataJaksa->result() as $row){
    	$tglBandingPenuntut=$this->templatehelper->convertKeTglIndo($row->tglbandingPu);      	
        $inpass = array();
        if(empty($row->nama)){
            $row->nama = '..................'; 
        }
        $namajaksa = $this->templatehelper->standradnaming($row->nama);
        $inpass['nama'] = $namajaksa;        

        if(empty($row->NIP)){
            $row->NIP = '..................'; 
        }
        $nip = $row->NIP;
        $inpass['nip'] = $nip;        
        
        if(empty($row->pekerjaan)){
            $row->pekerjaan = '......'; 
        }
        $pekerjaan = $this->templatehelper->standradnaming($row->pekerjaan);     
        $inpass['jabatan'] = $pekerjaan;        
        
        $tblcnt2++;

        $p2[] = $inpass;
    }
    cetakPihak($Template, '#jaksaparties#', $gkolom2, $p2);
    if (empty($tglBandingPenuntut)) {$tglBandingPenuntut="#isi dulu di aplikasi#";}
    $Template = str_replace('#tgl_akta_banding#',$tglBandingPenuntut,$Template);

    //---------------Data Penyerahan Memori Banding------------//
	$penyerahanM = $cetakTanggalMemori;
	foreach ($penyerahanM->result() as $row) {
    	$tgl_penyerahan=$row->penyerahan_memori_banding;
	}
	if(empty($tgl_penyerahan)){
	    $tglPenyerahanM = '..................';
	    $hariPenyerahanM = '.................';
	}else{
	    $hariPenyerahanM = $this->templatehelper->getHari($tgl_penyerahan);
	}
    $tglPenyerahanM=$this->templatehelper->convertKeTglIndo($tgl_penyerahan);
	$Template = str_replace('#tglpenyerahanmemori#',''.$tglPenyerahanM.'',$Template);
	$Template = str_replace('#haripenyerahanmemori#',''.$hariPenyerahanM.'',$Template);

	$terimaMemori = $cetakTglTerdakwaPembanding;
	foreach ($terimaMemori->result() as $row) {
    	$tglTerimaMemoriTerdakwa=$this->templatehelper->convertKeTglIndo($row->penerimaan_memori_banding);
    	$tglKontraMemoriTerdakwa=$row->penyerahan_kontra_banding;
    	$statusTerdakwa=($row->status_pihak_text);
    	$tglInzageTerdakwa=$row->pemberitahuan_inzage;  
    	$tglPemberitahuanPtsPT=$row->pemberitahuan_putusan_banding;  	
	}	
	if(empty($tglTerimaMemoriTerdakwa)){$tglTerimaMemoriTerdakwa = '..................';}
	if(empty($statusTerdakwa)){$statusTerdakwa = '..................';}
	if(empty($tglKontraMemoriTerdakwa)){
	    $tglKontraMemoriTerdakwa = '..................';
	    $hariKontraMemoriTerdakwa = '.................';
	}else{
	    $hariKontraMemoriTerdakwa = $this->templatehelper->getHari($tglKontraMemoriTerdakwa);
        $tglKontraMemoriTerdakwa = $this->templatehelper->convertKeTglIndo($tglKontraMemoriTerdakwa);
	}
	if(empty($tglInzageTerdakwa)){
	    $tglInzageTerdakwa = '..................';
	    $hariInzageTerdakwa = '.................';
	}else{
	    $hariInzageTerdakwa = $this->templatehelper->getHari($tglInzageTerdakwa);
        $tglInzageTerdakwa = $this->templatehelper->convertKeTglIndo($tglInzageTerdakwa);
	}	
	if(empty($tglPemberitahuanPtsPT)){
	    $tglPemberitahuanPtsPT = '..................';
	    $hariPemberitahuanPtsPT = '.................';
	}else{
	    $hariPemberitahuanPtsPT = $this->templatehelper->getHari($tglPemberitahuanPtsPT);
        $tglPemberitahuanPtsPT = $this->templatehelper->convertKeTglIndo($tglPemberitahuanPtsPT);
	}
              
	$Template = str_replace('#tglterimamemori#',''.$tglTerimaMemoriTerdakwa.'',$Template);
	$Template = str_replace('#tglserahkontramemori#',''.$tglKontraMemoriTerdakwa.'',$Template);
	$Template = str_replace('#haripenyerahankontramemori#',''.$hariKontraMemoriTerdakwa.'',$Template);
	$Template = str_replace('#tglpemberitahuaninzage#',''.$tglInzageTerdakwa.'',$Template);
	$Template = str_replace('#haripemberitahuaninzage#',''.$hariInzageTerdakwa.'',$Template);
	$Template = str_replace('#statuspihak#',''.$statusTerdakwa.'',$Template);
	$Template = str_replace('#tglpemberitahuanputusanpt#',''.$tglPemberitahuanPtsPT.'',$Template);
	$Template = str_replace('#haripemberitahuanputusanpt#',''.$hariPemberitahuanPtsPT.'',$Template);	

	/*$tglPemberitahuanPU=$tanggalPemberitahuan;
    foreach ($tglPemberitahuanPU->result() as $row) {
			$tglPemberitahuan=$this->templatehelper->convertKeTglIndo($row->pemberitahuan);	
	}*/
	if(empty($tglpemberitahuan)){
    	$tglpemberitahuan = '..................';
    	$haripermohonan = '.................';
	}else{
    	$haripermohonan = $this->templatehelper->getHari($tglpemberitahuan);
        $tglpemberitahuan = $this->templatehelper->convertKeTglIndo($tglpemberitahuan);
	}
	$Template = str_replace("#tglpermohonan#",''.$tglpemberitahuan.'',$Template);
    $Template = str_replace("#tglpemberitahuan#",''.$tglpemberitahuan.'',$Template);
	$Template = str_replace("#haripermohonan#",''.$haripermohonan.'',$Template);

	//----------------Data Banding di PT------------------//
	$dataPT=$cetakBandingPT;
    foreach ($dataPT->result() as $row) {
			$nomorPerkaraPT=($row->nomor_perkara_banding);
			$tglPutusPT=$this->templatehelper->convertKeTglIndo($row->tglPutusanBanding);
			$amarPutusanPT=$this->templatehelper->cleanHtmlTag($row->amar_putusan_banding);	
	}
	if(empty($nomorPerkaraPT)){$nomorPerkaraPT = '..................';}
	if(empty($tglPutusPT)){$tglPutusPT = '..................';}
	if(empty($amarPutusanPT)){$amarPutusanPT = '-Isi Amar Putusan Banding PT-';}
	$Template = str_replace("#nomorpt#",''.$nomorPerkaraPT.'',$Template);
	$Template = str_replace("#tglputuspt#",''.$tglPutusPT.'',$Template);
	$Template = str_replace("#amarpt#",''.$amarPutusanPT.'',$Template);

}
if($jenisAkta==7){
	//-----------Data Pembanding------------------//
	$dataPembanding = $cetakAllPembanding;
    if(!empty($dataPembanding)){
        foreach ($dataPembanding->result() as $row){
            $namapembanding = $this->templatehelper->standradnaming($row->nama);
            $alamatpembanding = $this->templatehelper->standradnaming($row->alamat);
            $pekerjaanpembanding = $this->templatehelper->standradnaming($row->pekerjaan);
        }
    }
	$Template = str_replace('#namapembanding#',''.$namapembanding.'',$Template);
	$Template = str_replace('#alamatpembanding#',''.$alamatpembanding.'',$Template);
	$Template = str_replace('#pekerjaanpembanding#',''.$pekerjaanpembanding.'',$Template); 

	//-----------Data Terbanding-----------------//
	$dataTerbanding = $cetakAllTerbanding;	
	if(!empty($dataTerbanding)){
        foreach($dataTerbanding->result() as $row){
            $namaterbanding = $this->templatehelper->standradnaming($row->nama);
            $alamatterbanding = $this->templatehelper->standradnaming($row->alamat);
            $pekerjaanterbanding = $this->templatehelper->standradnaming($row->pekerjaan);
        }
    }
	$Template = str_replace('#namaterbanding#',''.$namaterbanding.'',$Template);
	$Template = str_replace('#alamatterbanding#',''.$alamatterbanding.'',$Template);
	$Template = str_replace('#pekerjaanterbanding#',''.$pekerjaanterbanding.'',$Template);          
    
    #Data Terdakwa
	$tampilAllTerdakwa=$cetakAllTerdakwa;
	$cnt = $tampilAllTerdakwa->num_rows;
	$pihak_nama ='';
	$T=0;
	foreach ($tampilAllTerdakwa->result() as $row){
		$T++;
		$pihak_nama .=$row->nama;
		if($T!=$cnt){
			$pihak_nama .= ', ';
		}
	}
	$Template = str_replace('#pihakterdakwa#',''.$this->templatehelper->standradnaming($pihak_nama).'',$Template);
	if($cnt>1){
		$Template = str_replace('#jmlterdakwa#','Para Terdakwa',$Template);
	}else{
		$Template = str_replace('#jmlterdakwa#','Terdakwa',$Template);
	}
    if(!empty($tglPenyerahanKontraM)){
    	$Template = str_replace("#tglpenyerahankontramemori#",''.$this->templatehelper->convertKeTglIndo($tglPenyerahanKontraM).'',$Template);
    	$Template = str_replace("#haripenyerahankontramemori#",''.$this->templatehelper->getHari($tglPenyerahanKontraM).'',$Template);
	}
    if(!empty($tglPenerimaanKontraM)){
        $Template = str_replace("#tglpenerimaankontramemori#",''.$this->templatehelper->convertKeTglIndo($tglPenerimaanKontraM).'',$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;
?>