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

class c_template_pen_mil extends CI_Controller {

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

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

        $data['enc']=$this->uri->segment('3');
        $data['jpen']=$this->uri->segment('5');
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));
        if(!is_numeric($idperkara) OR !intval($idperkara)>0){
            show_404();
            exit();
        }   

        $this->load->model('generate_template/m_template_mil','template');
        $this->load->model('penetapan/add_majelis_m');
        $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);
        $list = array('0'=>'Pilih Nama Hakim');
        $res = $this->add_majelis_m->get_data_hakim_aktif();
        foreach ($res as $row){
            $list[$row['id']] = $row['nama_gelar'];
        };
        $data['data_hakim']=$list;
        $data['tanggal_pelimpahan'] = $this->add_majelis_m->get_tanggal_pelimpahan($perkara_id);
        //$data['data_majelis'] = $this->add_majelis_m->get_data_majelis($perkara_id);
        $data['data_majelis'] = $this->add_majelis_m->get_data_hakim_separator($perkara_id);
        $data['data_majelis_detail'] = $this->add_majelis_m->get_data_majelis_detail($perkara_id);
        $data['idperkara']=$this->encrypt->decode(base64_decode($data['enc']));


        $data['judul']=$judul['0'];
        $data['jnsperkara']=$jnsperkara;
        $this->load->view('generate_template/popup_penetapan_mil', $data, FALSE);
    }

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

        $jpen = $this->uri->segment('3');
        $data['enc']=$this->input->post('enc',TRUE);
        $jenisTemplate = $this->input->post('jenisTemplate',TRUE);
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));
        if(!is_numeric($idperkara) OR !intval($idperkara)>0){
            show_404();
            exit();
        }  

        $pembuat=$this->input->post('ditetapkanoleh',TRUE);
        if(!is_numeric($pembuat) OR !intval($pembuat)>0){
            show_404();
            exit();
        }   

        $this->load->model('generate_template/m_template_mil','template');
        $data['dataTemplate'] = $this->template->getDataPenetapanHakimMil($idperkara,$pembuat);
        $data['dataTemplate'] = $this->template->getDataPN();

        $this->load->model('generate_template/m_template_ambil_identitas_template','template2');

        if($jpen==1){
            $data['template']=$this->template2->getDataDocumentTemplate('120','12','20','1','');    
            //$filenya=".rtf";
        }elseif($jpen==2) {
            $data['template']=$this->template2->getDataDocumentTemplate('120','12','30','1','');    
            //$filenya=".rtf";
        }else{
            $data['template']=$this->template2->getDataDocumentTemplate('120','12','80','1','');    
        }              
        $jtem_apb = $this->input->post('jenisTemplate',TRUE);
        if($jtem_apb==1){
            $data['template']=$this->template2->getDataDocumentTemplate('120','10','10','1','');    
        }elseif($jtem_apb==2){
            $data['template']=$this->template2->getDataDocumentTemplate('120','10','10','2','');    
        }elseif($jtem_apb==3){
            $data['template']=$this->template2->getDataDocumentTemplate('120','10','10','3','');    
        }elseif($jtem_apb==4){
            $data['template']=$this->template2->getDataDocumentTemplate('120','10','10','4','');    
        }elseif($jtem_apb==5){
            $data['template']=$this->template2->getDataDocumentTemplate('120','10','10','5','');    
        }elseif($jtem_apb==6){
            $data['template']=$this->template2->getDataDocumentTemplate('120','10','10','6','');    
        }

       // $data_id= array(
       //             'source_file'=>$filenya,
       //             'perkara_id'=>$idperkara,
       //             'pembuat'=>$pembuat);   
                            
        //$this->load->model('generate_template/var_template_mil','var_template');
        //$this->var_template->kirim_variabel($data_id);

        $data['template_apb'];

        $this->load->view('generate_template/cetak_penetapan_mil',$data,FALSE);
    }

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

        $jpen = $this->uri->segment('3');
        $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();
        }  

        $pembuat=$this->input->post('ditetapkanoleh',TRUE);
        if(!is_numeric($pembuat) OR !intval($pembuat)>0){
            show_404();
            exit();
        }   

        $this->load->model('generate_template/m_template_mil','template');
        $data['dataTemplate'] = $this->template->getDataPenetapanHakimMil($idperkara,$pembuat);
        $this->load->model('generate_template/m_template_ambil_identitas_template','template2');

        if($jpen==1){
            //$data['template']=$this->template2->getDataDocumentTemplate('120','12','20','1','');
            $filenya="peradilan_militer/PENETAPAN/PENETAPAN_MAJELIS_HAKIM.rtf";  
            $prosesid=20;  
        }elseif($jpen==2) {
            //$data['template']=$this->template2->getDataDocumentTemplate('120','12','30','1','');
            $filenya="peradilan_militer/PENETAPAN/41_PENUNJUKAN_PANITERA_PENGGANTI.rtf"; 
            $prosesid=30;   
        }else{
            //$data['template']=$this->template2->getDataDocumentTemplate('120','12','80','1','');
            $filenya="peradilan_militer/PENETAPAN/42_PENETAPAN_HARI_SIDANG.rtf"; 
            $prosesid=80;   
        }              

        //$data['template_apb'];
        $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);
        //$this->load->view('generate_template/cetak_penetapan_hakim_pp_militer',$data,FALSE);
    }

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

        $data['enc']=$this->input->post('enc',TRUE);
        $jenisTemplate = $this->input->post('jenisTemplate',TRUE);
        $data['pertimbangan1'] = $this->input->post('pertimbangan1',TRUE);
        $data['pertimbangan2'] = $this->input->post('pertimbangan2',TRUE);
        $data['tglpenetapan'] = $this->input->post('tgl_penetapan',TRUE);
        $idOditur = $this->input->post('oditur',TRUE);
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));
        if(!is_numeric($idperkara) OR !intval($idperkara)>0){
            show_404();
            exit();
        }  
        if($jenisTemplate==4 ||$jenisTemplate==5){
            $pembuat=$this->input->post('ditetapkanoleh2',TRUE);
        }else{
            $pembuat=$this->input->post('ditetapkanoleh1',TRUE);    
        }

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

        $this->load->model('generate_template/m_template_mil','template');
        $data['dataTemplate'] = $this->template->getDataPenetapanHakimMil($idperkara,$pembuat);
        $data['dataOditur'] = $this->template->pihak_Oditur($idperkara,$idOditur); 
        $data['namaKota']=$this->template->getDataPN();
        $this->load->model('generate_template/m_template_ambil_identitas_template','template2');
        $data['jenisTemplate'] = $this->input->post('jenisTemplate',TRUE);
        $jtem_apb = $this->input->post('jenisTemplate',TRUE);
        if($jtem_apb==1){
            //$data['template']=$this->template2->getDataDocumentTemplate('120','10','10','1',''); 
            $filenya="peradilan_militer/PENETAPAN/2_PEN_PENGEMBALIAN_BERKAS_YUSTIABEL.rtf"; 
            $prosesid=215;  
        }elseif($jtem_apb==2){
            //$data['template']=$this->template2->getDataDocumentTemplate('120','10','10','2',''); 
            $filenya="peradilan_militer/PENETAPAN/3 PENETAPAN PENGEMBALIAN BERKAS TKP DILUAR SATKER.rtf";
            $prosesid=215;   
        }elseif($jtem_apb==3){
            //$data['template']=$this->template2->getDataDocumentTemplate('120','10','10','3','');
             $filenya="peradilan_militer/PENETAPAN/43 PENETAPAN PENGEMBALIAN BERKAS BAP TIDAK LENGKAP.rtf";
             $prosesid=215;   
        }elseif($jtem_apb==4){
            //$data['template']=$this->template2->getDataDocumentTemplate('120','10','10','4','');
            $filenya="peradilan_militer/BERITA ACARA/45 BERITA  ACARA  PERUBAHAN  SURAT DAKWAAN.rtf"; 
             $prosesid=215;   
        }elseif($jtem_apb==5){
            //$data['template']=$this->template2->getDataDocumentTemplate('120','10','10','5','');
            $filenya="peradilan_militer/AKTA/AKTA MENERIMA PERUBAHAN DAKWAAN.rtf";
            $prosesid=215;    
        }elseif($jtem_apb==6){
            //$data['template']=$this->template2->getDataDocumentTemplate('120','10','10','6','');
            $filenya="peradilan_militer/PENETAPAN/52 PENETAPAN PENGGABUNGAN GUGATAN GANTI RUGI .rtf";

        }
       // $this->load->view('generate_template/cetak_penetapan_mil',$data,FALSE);
    $data_id= array(
                    'source_file'=>$filenya,
                    'perkara_id'=>$idperkara,
                    'ditetapkan_oleh'=>$pembuat,
                    'pertimbangan1_mil'=>$data['pertimbangan1'],
                    'pertimbangan2_mil'=>$data['pertimbangan2'],
                    'tanggal'=>$data['tglpenetapan'],
                    'proses_id'=>$prosesid);

     $this->load->model('generate_template/var_template_mil','var_template');
     $this->var_template->kirim_variabel($data_id);

                    
    }

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

        $segment = $this->uri->segment_array();
        $data['enc']=$this->uri->segment('3');
        $data['jpen']=$this->uri->segment('5');
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));
        if(!is_numeric($idperkara) OR !intval($idperkara)>0){
            show_404();
            exit();
        }

        $this->load->model('generate_template/m_template_mil','template');
        $this->load->model('penetapan/add_majelis_m');
        $data['penandatangan']=$this->template->getDataPN();
        $this->load->model('generate_template/m_template_ambil_identitas_template','template2');        
        $template=$this->template2->getDataDocumentTemplate('120','12','30','1','');
        $i=0;
        foreach ($template->result() as $template){
            if (count($template)=='1'){
                $judul['0']=$template->namatemplate;
                $jnsperkara=$template->jnsperkara;
            }else{
                if ($i=='0'){
                    $judul=$template->namatemplate;
                    $judul=explode("",$judul);
                    $jnsperkara=$template->jnsperkara;
                }
            }
        }

        if($data['jpen']==1){
            $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['data_majelis'] = $this->add_majelis_m->get_data_majelis($perkara_id);
            $data['data_majelis_detail'] = $this->add_majelis_m->get_data_majelis_detail($perkara_id);            
        }elseif($data['jpen']==2){
            $this->load->model('penetapan/add_panitera_m');
            $perkara_id=$this->encrypt->decode(base64_decode($data['enc']));
            //$data['enc'] = $this->nativesession->get_flash_session('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['data_penetapan'] = $this->add_panitera_m->get_data_penetapan($perkara_id);
            $data['data_panitera_detail'] = $this->add_panitera_m->get_data_panitera_detail($perkara_id);
        }

        $data['judul']=$judul['0'];
        $data['jnsperkara']=$jnsperkara;
        $this->load->view('generate_template/popup_penetapan_mil', $data, FALSE);
    }


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

        $data['enc']=$this->uri->segment('3');
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));
        if(!is_numeric($idperkara) OR !intval($idperkara)>0){
            show_404();
            exit();
        }   
        
        $this->load->model('generate_template/m_template_mil','template');
        $data['dataTemplate'] = $this->template->getDataPenetapanHakimMil($idperkara,'64');
        $this->load->model('generate_template/m_template_ambil_identitas_template','template2');        
        //$data['template']=$this->template2->getDataDocumentTemplate('120','12','80','1','');
        //$this->load->view('generate_template/cetak_penetapan_hakim_pp_militer',$data,FALSE);
        $filenya="peradilan_militer/PENETAPAN/42_PENETAPAN_HARI_SIDANG.rtf";
        $prosesid=80;
        $data_id= array(
                    'source_file'=>$filenya,
                    'perkara_id'=>$idperkara,
                    'pembuat'=>$pembuat,
                    'proses_id'=>$prosesid);   
                            
        $this->load->model('generate_template/var_template_mil','var_template');
        $this->var_template->kirim_variabel($data_id);
    }

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

        $data['enc']=$this->uri->segment('3');
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));
        if(!is_numeric($idperkara) OR !intval($idperkara)>0){
            show_404();
            exit();
        }   

        $this->load->model('generate_template/m_template_mil','template');
        $this->load->model('penetapan/add_majelis_m');
        $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);
        $list = array('0'=>'Pilih Nama Hakim');
        $res = $this->add_majelis_m->get_data_hakim_aktif();
        foreach ($res as $row){
            $list[$row['id']] = $row['nama_gelar'];
        };
        $data['data_hakim']=$list;
        $data['tanggal_pelimpahan'] = $this->add_majelis_m->get_tanggal_pelimpahan($perkara_id);
        $data['data_majelis'] = $this->add_majelis_m->get_data_majelis($perkara_id);
        $data['data_majelis_detail'] = $this->add_majelis_m->get_data_majelis_detail($perkara_id);
        $data['idperkara']=$this->encrypt->decode(base64_decode($data['enc']));
        $data['oditur']=$this->template->getDataOditur($perkara_id);

        $data['judul']=$judul['0'];
        $data['jnsperkara']=$jnsperkara;
        $this->load->view('generate_template/popup_akta_pengembalian_berkas', $data, FALSE);
    }


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

        $data['enc']=$this->uri->segment('3');
        $data['enctahan']=$this->uri->segment('4');
        $data['encpihak']=$this->uri->segment('5');
        $data['typePen']=$this->uri->segment('6');
      
        $idperkara=$this->encrypt->decode(base64_decode($data['enc']));
        $idpenahanan=$this->encrypt->decode(base64_decode($data['enctahan']));
        $idpihak=$this->encrypt->decode(base64_decode($data['encpihak']));
        
        if(!is_numeric($idperkara) OR !intval($idperkara)>0){
            show_404();
            exit();
        }   
       
        //  $data['idpenahanan']=$idpenahanan;
        //  $data['idpihak']=$idpihak;
        //  $this->load->model('generate_template/m_template_mil','template');
        //  $this->load->model('generate_template/m_template_penetapan','template3');
        //  $data['tgl_sejak']=$this->template3->getDataPenahanan($idpenahanan)->row()->mulai;
        //  $data['tgl_sampai']=$this->template3->getDataPenahanan($idpenahanan)->row()->sampai;
        //  $data['tanggal_surat']=$this->template3->getDataPenahanan($idpenahanan)->row()->tanggal_surat;
        //  $data['lama_penahanan_nya']=$this->template3->getDataPenahanan($idpenahanan)->row()->lama_penahanan;
        // $data['dataterdakwa'] = $this->template3->getDataPihakTerdakwa1($idperkara,$idpihak);
        // $data['datapenahanan'] = $this->template3->getDataPenahananTerdakwa($idperkara,$idpihak);
        // $data['dataTemplate'] = $this->template->getDataPenetapanHakimMil($idperkara,'64');
        // $this->load->model('generate_template/m_template_ambil_identitas_template','template2');

        // $data['mulaiBef']='';
        // $tglMulaiBef = $this->template3->getDataPenahanan($idpenahanan)->row()->mulai;
        // if ($this->template->getDataPenahananBef($idperkara,$tglMulaiBef)->num_rows()){
        //     $data['mulaiBef'] = $this->template->getDataPenahananBef($idperkara,$tglMulaiBef)->row()->mulai;
        //     $data['sampaiBef'] = $this->template->getDataPenahananBef($idperkara,$tglMulaiBef)->row()->sampai;
        //     $data['lama_penahananBef'] = $this->template->getDataPenahananBef($idperkara,$tglMulaiBef)->row()->lama_penahanan;
        //     $data['tanggal_suratBef'] = $this->template->getDataPenahananBef($idperkara,$tglMulaiBef)->row()->tanggal_surat;
        //     $data['nomor_suratBef'] = $this->template->getDataPenahananBef($idperkara,$tglMulaiBef)->row()->nomor_surat;
        // }else{
        //     $data['mulaiBef']='.......';
        //     $data['sampaiBef']='.......';
        //     $data['lama_penahananBef']='0';
        //     $data['tanggal_suratBef']='.......';
        //     $data['nomor_suratBef']='.......';
        // }


        if($data['typePen']==1){
            //$data['template']=$this->template2->getDataDocumentTemplate('120','12','200','2',''); 
            $filenya="peradilan_militer/PENETAPAN/46 PENETAPAN PENAHANAN .rtf"; 

        }elseif($data['typePen']==2){
            //$data['template']=$this->template2->getDataDocumentTemplate('120','12','200','3','');
            $filenya="peradilan_militer/PENETAPAN/47 PENETAPAN PERPANJANGAN PENAHANAN .rtf";    
        }elseif($data['typePen']==3){
            //$data['template']=$this->template2->getDataDocumentTemplate('120','12','200','4','');    
        }         
        
        // $this->load->view('generate_template/cetak_penahanan_mil',$data,FALSE);
        $data_id= array(
                     'source_file'=>$filenya,
                     'perkara_id'=>$idperkara,
                     'pembuat'=>$pembuat,
                     'penahanan_id'=>$idpenahanan,
                     'pihak_id'=>$idpihak,
                     'proses_id'=>$prosesid);   
                            
         $this->load->model('generate_template/var_template_mil','var_template');
         $this->var_template->kirim_variabel($data_id);
    }

}
?>