<?php 
defined('BASEPATH') OR exit('No direct script access allowed');

class c_template_putusan_mil extends CI_Controller {

    function index(){
        if($this->session->userdata('is_logged_in')==FALSE){
        redirect('login');
        }       
        $this->load->view('dashboard', FALSE);
    }

    function popup_putusan_mil(){
        if($this->session->userdata('is_logged_in')==FALSE){
        redirect('login');
        }       
        

        $data['enc']=$this->uri->segment('3');
        $data['jPut']=$this->uri->segment('4');

        $idperkara = $this->encrypt->decode(base64_decode($data['enc']));
        $idalurperkara = $this->tanggalhelper->getIDAlurPerkara($idperkara);

        if(!is_numeric($idperkara) OR !intval($idperkara)>0){
            show_404();
            exit();
        }

        if($idalurperkara==120){
            if($data['jPut']==1){
                $jdlHead = "Putusan Akhir";
            }elseif($data['jPut']==2){
                $jdlHead = "Petikan Putusan";
            }elseif($data['jPut']==3){
                $jdlHead = "Info Pengumuman Putusan";
            }
        }else{
            if($data['jPut']==1){
                $jdlHead = "Putusan Akhir Pelanggaran";            
            }elseif($data['jPut']==2){
                $jdlHead = "Info Pengumuman Putusan";
            }
        }


        $data['jdl']=$jdlHead;
        


        $this->load->model('generate_template/m_template_mil','template');
        $this->load->model('penetapan/add_majelis_m');
        $data['infoPutus']=$this->template->getTglPts($idperkara);
        $data['penandatangan']=$this->template->getDataPN();

        $this->load->model('generate_template/m_template_ambil_identitas_template','template2'); 
        $template=$this->template2->getDataDocumentTemplate('1','12','20','1','');
        $i=0;
        $jumdata=count($template->result());
        foreach ($template->result() as $template){
            if ($jumdata=='1'){
                $judul['0']=$template->namatemplate;
                $jnsperkara=$template->jnsperkara;
            }else{
                if ($i=='0'){
                    $judul=$template->namatemplate;
                    $judul=explode("Voluntair",$judul);
                    $jnsperkara=$template->jnsperkara;
                }
            }
        }

        $perkara_id=$this->encrypt->decode(base64_decode($data['enc']));
        $data['perkara'] = $this->add_majelis_m->get_no_perkara($perkara_id);
        $data['idalurperkara'] = $this->tanggalhelper->getIDAlurPerkara($perkara_id);
        $data['tanggal_pelimpahan'] = $this->add_majelis_m->get_tanggal_pelimpahan($perkara_id);
        $data['idperkara']=$this->encrypt->decode(base64_decode($data['enc']));
        $data['judul']=$judul['0'];
        $data['jnsperkara']=$jnsperkara;
        $this->load->view('generate_template/popup_put_mil', $data, FALSE);
    }

    function cetak_putusan_mil(){
        if($this->session->userdata('is_logged_in')==FALSE){
        redirect('login');
        }       


        $data['enc']=$this->input->post('enc',TRUE);
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));
        if(!is_numeric($idperkara) OR !intval($idperkara)>0){
            show_404();
            exit();
        }  
        $idalurperkara = $this->tanggalhelper->getIDAlurPerkara($idperkara);
        $jns_template=$this->input->post('jns_template',TRUE);
        if ($jns_template==3){
            $jenis_no=$this->input->post('jenis_no',TRUE);
        }else{
            $jenis_no="";
        }
        if(!is_numeric($jns_template) OR !intval($jns_template)>0){
            show_404();
            exit();
        }   

        $data['ket_oditur']=$this->input->post('ket_oditur_text',TRUE);
        $data['ket_terdakwa']=$this->input->post('ket_terdakwa',TRUE);

        $this->load->model('generate_template/m_template_mil','template');
        $this->load->model('putusan/data_putusan_akhir','putusan');
        $data['status_putusan'] = $this->putusan->getPutusanTerdakwa($idperkara);
        $data['oditur'] = $this->template->getDataOditur($idperkara);

        $data['pengacara'] = $this->template->getDataPengacara($idperkara);
        $data['dataTemplate'] = $this->template->getDataPutusan($idperkara);

        // $this->load->model('generate_template/m_template_ambil_identitas_template','template2');        
        if($idalurperkara=='120'){
            if($jns_template==1){
                $filenya="peradilan_militer/PUTUSAN/54 PUTUSAN.rtf";
                $prosesid=210;
                // $data['template']=$this->template2->getDataDocumentTemplate('120','15','210','6','');        
            }elseif($jns_template==2){
                $filenya="peradilan_militer/PUTUSAN/PUTUSAN (TERDAKWA TDK HADIR).rtf";
                // $data['template']=$this->template2->getDataDocumentTemplate('120','15','210','2','');        
            }elseif($jns_template==3){
                switch ($jenis_no) {
                    case '1':
                       $filenya="peradilan_militer/PUTUSAN/61 PUTUSAN(NO TERDAKWA TDK HADIR).rtf";
                        break;
                    case '2':
                       $filenya="peradilan_militer/PUTUSAN/62 PUTUSAN (NO TERDAKWA MENINGGAL).rtf";
                        break;
                    case '3':
                       $filenya="peradilan_militer/PUTUSAN/63 PUTUSAN (NO DALUWARSA).rtf";
                       $prosesid=210;
                        break;
                    case '4':
                       $filenya="peradilan_militer/PUTUSAN/64 PUTUSAN(NO PENCABUTAN PENGADUAN).rtf";
                        break;
                    case '5':
                       $filenya="peradilan_militer/PUTUSAN/65 PUTUSAN(NO NEBIS IN IDEM).rtf";
                        break;
                }
            }elseif($jns_template==4){
                $filenya="peradilan_militer/PUTUSAN/PUTUSAN (TERDAKWA MENINGGAL DUNIA).rtf";
                // $data['template']=$this->template2->getDataDocumentTemplate('120','15','210','4','');        
            }elseif($jns_template==5){
                $filenya="peradilan_militer/PUTUSAN/";
                // $data['template']=$this->template2->getDataDocumentTemplate('120','15','210','5','');        
            }elseif($jns_template==6){
                $filenya="peradilan_militer/PUTUSAN/17 PETIKAN PUTUSAN.rtf";
                $prosesid=210;
                // $data['template']=$this->template2->getDataDocumentTemplate('120','15','210','7','');        
            }elseif($jns_template==7){
                $filenya="peradilan_militer/PUTUSAN/";
                // $data['template']=$this->template2->getDataDocumentTemplate('120','15','210','9','');        
            }elseif($jns_template==8){
                $filenya="peradilan_militer/PUTUSAN/";
                // $data['template']=$this->template2->getDataDocumentTemplate('120','15','210','10','');        
            }
        }else{
            if($jns_template==1){
                $filenya="peradilan_militer/PUTUSAN/PUTUSAN PELANGGARAN LALIN.rtf";
                // $data['template']=$this->template2->getDataDocumentTemplate('121','15','210','1','');        
            }else{
                $filenya="peradilan_militer/PUTUSAN/PUTUSAN PELANGGARAN LALIN.rtf";
                // $data['template']=$this->template2->getDataDocumentTemplate('121','15','210','1','');        
            }
        }

        $jPut = $this->uri->segment('3');
        if($jPut==9){
            $filenya="peradilan_militer/PUTUSAN";
            // $data['template']=$this->template2->getDataDocumentTemplate('120','15','210','1',''); 
        }
        
        $data['penandatangan']=$this->template->getDataPN();
        $data['dataterdakwa']=$this->template->getDataTerdakwaMil($idperkara);
        $data['getTglPts']=$this->template->getTglPts($idperkara);
        $data['datapenahanan'] = $this->template->getDataPenahananTerdakwaMil($idperkara);
        //$this->load->view('generate_template/cetak_putusan_mil',$data,FALSE);
//print_r('blabla');exit();
        $data_id= array(
                    'source_file'=>$filenya,
                    'perkara_id'=>$idperkara,
                    'ditetapkan_oleh'=>$pembuat,
                    'pernyataan_thd_petikan_terdakwa'=>$data['ket_terdakwa'],
                    'pernyataan_thd_petikan_oditur'=>$data['ket_oditur'],
                   // 'penahanan_id'=>$data['datapenahanan'],
                    'proses_id'=>$prosesid);   
        $this->load->model('generate_template/var_template_mil','var_template');
        $this->var_template->kirim_variabel($data_id);
    }

    function cetak_akta_menerima_putusan($enc, $pihak_id, $pihak_ke){
        if($this->session->userdata('is_logged_in')==FALSE){
            redirect('login');
        }       
        
        $segment = $this->uri->segment_array(); 
        $perkara_id=$this->encrypt->decode(base64_decode($enc));       
        $data['perkara_id'] = $perkara_id;
        if(!is_numeric($perkara_id) OR !intval($perkara_id)>0){            
            show_404();
            exit();
        }   
        
        $pihak_id=$this->encrypt->decode(base64_decode($pihak_id));
        $data['pihak_id'] = $pihak_id;
        if(!is_numeric($pihak_id) OR !intval($pihak_id)>0){            
            show_404();
            exit();
        }   
        $data['pihak_ke'] = $pihak_ke;
        if ($pihak_ke=='1'){
           // $var='7';
            $var="peradilan_militer/AKTA/55 AKTA MENERIMA PUTUSAN(ODITUR).rtf";
            $prosesid=218;
        }elseif($pihak_ke=='2'){
            //$var='6';
            $var="peradilan_militer/AKTA/55 AKTA MENERIMA PUTUSAN(TERDAKWA).rtf";
            $prosesid=218;
        }
       //  $this->load->model('generate_template/m_template_mil','template');
       //  $this->load->model('generate_template/m_template_ambil_identitas_template','template2');        
        
        // $PN=$this->template->getDataPN()->result();
        // $id_pn=$PN[0]->IDPN;
        // $info_pn=$this->template->get_pn($id_pn)->result();
        // $info_pn=$info_pn[0];
        // $data['info_pn']=$info_pn;
        // $info_putusan=$this->template2->getDataPutusanPerkara($perkara_id)->result();
        // $data['tgl_putusan']=$info_putusan[0]->tanggal_putusan;
        // $data['info_panitera']=$this->template->get_perkara_panitera($perkara_id)->result();
        // $data['ls_pemberitahuan_putusan']= $this->template->getDataPemberitahuanPutusanMil($perkara_id, $pihak_ke, $pihak_id);
        //$data['template']=$this->template2->getDataDocumentTemplate('120','16','240',$var,'');    
       // $this->load->view('generate_template/cetak_pemberitahuan_putusan_mil',$data,FALSE);
        $filenya=$var;
        $data_id= array(
                    'source_file'=>$filenya,
                    'perkara_id'=>$perkara_id,
                    'ditetapkan_oleh'=>$pembuat,
                    'pihak_id'=>$data['pihak_id'],
                    'proses_id'=>$prosesid);   
        //print_r($data_id);exit();
        $this->load->model('generate_template/var_template_mil','var_template');
        $this->var_template->kirim_variabel($data_id);

    }
    

    function cetak_putusan_sela_mil(){
        if($this->session->userdata('is_logged_in')==FALSE){
        redirect('login');
        }       

        $enc = $this->uri->segment('3');
        $idperkara=$this->encrypt->decode(base64_decode($enc));
         $this->load->model('generate_template/m_template_mil','template');
         $this->load->model('generate_template/m_template_ambil_identitas_template','template2');   
        $data['enc']=$enc;
        //$data['template']=$this->template2->getDataDocumentTemplate('120','15','210','1',''); 
        $filenya="peradilan_militer/PUTUSAN/59 PUTUSAN SELA.rtf";
        $prosesid=210;

        $this->load->model('putusan/data_putusan_akhir','putusan');
        $idalurperkara = $this->tanggalhelper->getIDAlurPerkara($idperkara);
        $data['status_putusan'] = $this->putusan->getPutusanTerdakwa($idperkara);
        $data['dataTemplate'] = $this->template->getDataPutusan($idperkara);
        $data['penandatangan']=$this->template->getDataPN();
        $data['dataterdakwa']=$this->template->getDataTerdakwaMil($idperkara);
        $data['getTglPts']=$this->template->getTglPts($idperkara);
        $data['datapenahanan'] = $this->template->getDataPenahananTerdakwaMil($idperkara);
        $data['oditur'] = $this->template->getDataOditur($idperkara);
        $data['pengacara'] = $this->template->getDataPengacara($idperkara);
       // $this->load->view('generate_template/cetak_putusan_mil',$data,FALSE);
   
         $data_id= array(
                    'source_file'=>$filenya,
                    'perkara_id'=>$idperkara,
                    'ditetapkan_oleh'=>$pembuat,
                    'proses_id'=>$prosesid);   
                           
        $this->load->model('generate_template/var_template_mil','var_template');
        $this->var_template->kirim_variabel($data_id);

    }
}
?>