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

class Detil_delegasi extends CI_Controller {
	function index(){
		if($this->nativesession->get_flash_session('security')===FALSE){
			redirect('main');
		}
		$sec = $this->nativesession->get_flash_session('security');

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

	function show_data(){
		$enc_idalur = $this->nativesession->get_flash_session('idalur');
		$idalur=$this->encrypt->decode(base64_decode($enc_idalur,TRUE));
		$enc=$this->encrypt->decode(base64_decode($this->nativesession->get_flash_session('encDelegasi'),TRUE));
		$idpnasal=$this->encrypt->decode(base64_decode($this->nativesession->get_flash_session('idpnasal'),TRUE));
		$idpntujuan=$this->encrypt->decode(base64_decode($this->nativesession->get_flash_session('idpntujuan'),TRUE));

		$this->load->model('perkara/delegasi','delegasi');
		$jenis_pengadilan = $this->session->userdata('jenis_pengadilan');

		$data['delegasi_detil'] = $this->delegasi->get_detil_delegasi($idalur,$enc,$idpnasal,$idpntujuan);
		$data['delegasi_proses'] = $this->delegasi->get_detil_proses($idalur,$enc,$idpnasal,$idpntujuan);
		//$data['delegasi_proses'] = $this->delegasi->getDelegasiProses($enc,"masuk");

		if ($data['delegasi_detil']->num_rows>=1) {
				foreach ($data['delegasi_detil']->result() as $row) {
						$data['delegasi_id']=$row->id;	
						$data['perkara_id']=$row->perkara_id;
						$data['nomor_perkara']=$row->nomor_perkara;
						$data['id_pn_asal']=$row->id_pn_asal;
						$data['kode_satker_asal']=$row->kode_satker_asal;
						$data['pn_asal_text']=$row->pn_asal_text;
						$data['id_pn_tujuan']=$row->id_pn_tujuan;
						$data['kode_satker_tujuan']=$row->kode_satker_tujuan;
						$data['pn_tujuan_text']=$row->pn_tujuan_text;
						$data['tgl_delegasi']=$this->tanggalhelper->convertDayDate($row->tgl_delegasi);
						$data['id_jenis_delegasi']=$row->id_jenis_delegasi;
						$data['tgl_sidang']=$this->tanggalhelper->convertDayDate($row->tgl_sidang);
						$data['jenis_delegasi_text']=$row->jenis_delegasi_text;
						$data['tgl_surat']=$this->tanggalhelper->convertDayDate($row->tgl_surat);
						$data['tgl_pengiriman']=$this->tanggalhelper->convertDayDate($row->tgl_pengiriman);
						$data['nomor_surat']=$row->nomor_surat;
						$data['namadokumen']=$row->namadokumen;
						$data['document']=$row->document;
						$data['document_size']=$row->document_size;
						$data['document_mime']=$row->document_mime;
						$data['tgl_resi']=$this->tanggalhelper->convertDayDate($row->tgl_resi);
						$data['nomor_resi']=$row->nomor_resi;
						$data['biaya']=$row->biaya;
						$data['para_pihak']=$row->pihak;
						$data['catatan']=$row->catatan;
				}
			}else{
						$data['delegasi_id']='';
						$data['perkara_id']='';
						$data['nomor_perkara']='';
						$data['id_pn_asal']='';
						$data['kode_satker_asal']='';
						$data['pn_asal_text']='';
						$data['id_pn_tujuan']='';
						$data['kode_satker_tujuan']='';
						$data['pn_tujuan_text']='';
						$data['tgl_delegasi']='';
						$data['id_jenis_delegasi']='';
						$data['tgl_sidang']='';
						$data['jenis_delegasi_text']='';
						$data['tgl_surat']='';
						$data['tgl_pengiriman']='';
						$data['nomor_surat']='';
						$data['namadokumen']='';
						$data['document']='';
						$data['document_size']='';
						$data['document_mime']='';
						$data['tgl_resi']='';
						$data['nomor_resi']='';
						$data['biaya']='';
						$data['para_pihak']='';
						$data['catatan']='';
			}
			if ($data['delegasi_proses']->num_rows>=1) {
				foreach ($data['delegasi_proses']->result() as $row) {
						$data['p_delegasi_id']=$row->delegasi_id;
						$data['p_tgl_surat_diterima']=$this->tanggalhelper->convertDayDate($row->tgl_surat_diterima);
						$data['p_perkara_id']=$row->perkara_id;
						$data['p_jurusita_id']=$row->jurusita_id;
						$data['p_tgl_penunjukan_jurusita']=$this->tanggalhelper->convertDayDate($row->tgl_penunjukan_jurusita);
						$data['p_jurusita_nama']=$row->jurusita_nama;
						$data['p_id_pn_asal']=$row->id_pn_asal;
						$data['p_pn_asal_text']=$row->pn_asal_text;
						$data['p_kode_satker_asal']=$row->kode_satker_asal;
						$data['p_id_pn_tujuan']=$row->id_pn_tujuan;
						$data['p_pn_tujuan_text']=$row->pn_tujuan_text;
						$data['p_kode_satker_tujuan']=$row->kode_satker_tujuan;
						$data['p_tgl_relaas']=$this->tanggalhelper->convertDayDate($row->tgl_relaas);
						$data['p_nomor_relaas']=$row->nomor_relaas;
						$data['p_tgl_pengiriman_relaas']=$this->tanggalhelper->convertDayDate($row->tgl_pengiriman_relaas);
						$data['p_nomor_surat_pengantar_relaas']=$row->nomor_surat_pengantar_relaas;
						$data['p_id_status_delegasi']=$row->id_status_delegasi;
						$data['p_status_delegasi']=$row->status_delegasi;
						$data['p_namadokumen']=$row->namadokumen;
						$data['p_document']=$row->document;
						$data['p_document_size']=$row->document_size;
						$data['p_document_mime']=$row->document_mime;
						$data['p_tgl_resi']=$this->tanggalhelper->convertDayDate($row->tgl_resi);
						$data['p_nomor_resi']=$row->nomor_resi;
						$data['p_biaya']=$row->biaya;
						$data['p_catatan']=$row->catatan;
					}
			}else{
						$data['p_delegasi_id']='';
						$data['p_tgl_surat_diterima']='';
						$data['p_perkara_id']='';
						$data['p_jurusita_id']='';
						$data['p_tgl_penunjukan_jurusita']='';
						$data['p_jurusita_nama']='';
						$data['p_id_pn_asal']='';
						$data['p_pn_asal_text']='';
						$data['p_kode_satker_asal']='';
						$data['p_id_pn_tujuan']='';
						$data['p_pn_tujuan_text']='';
						$data['p_kode_satker_tujuan']='';
						$data['p_tgl_relaas']='';
						$data['p_nomor_relaas']='';
						$data['p_tgl_pengiriman_relaas']='';
						$data['p_nomor_surat_pengantar_relaas']='';
						$data['p_id_status_delegasi']='';
						if (empty($data['p_status_delegasi'])) {
							$data['p_status_delegasi']='Belum dilaksanakan';
						}
						$data['p_namadokumen']='';
						$data['p_document']='';
						$data['p_document_size']='';
						$data['p_document_mime']='';
						$data['p_tgl_resi']='';
						$data['p_nomor_resi']='';
						$data['p_biaya']='';
						$data['p_catatan']='';
			}

		if ($idalur==1) {
			$data['page_title'] = 'INFORMASI DETIL DELEGASI MASUK';
		}else{
			$data['page_title'] = 'INFORMASI DETIL DELEGASI KELUAR';
		}

		foreach ($data['delegasi_detil']->result() as $key => $valdetil) {
			$$key=$valdetil;
		}

		$data['main_body'] = 'delegasi/detil_delegasi';
		$data['main_history'] = $this->nativesession->get_flash_session('main_url_requested');
		$this->nativesession->set('main_url_requested', $data['main_history']);
		
		$data['idalur']=$idalur;
		$data['iddelegasi']=$enc;
		$data['idpnasal']=$idpnasal;
		$data['idpntujuan']=$idpntujuan;
		$this->load->vars($data);
		$this->load->view('header');
		$this->load->view('body/body_new');
	}
	function downloadFile(){
			$segment = $this->uri->segment_array();
			$encDelegasi=$this->encrypt->decode(base64_decode($segment[3]));
			$this->load->model('perkara/delegasi','delegasi');
			//1 = delegasi masuk
			//2 = delegasi keluar
			$datautama=$this->delegasi->get_detil_delegasi('2',$encDelegasi,'','');
  			
			foreach ($datautama->result() as $row)
			{
				$data['namafile']=$row->namadokumen;
				$data['content']=$row->document;
	       		$data['type']=$row->document_mime;
	       		$data['size']=$row->document_size;

				//tampil dihalaman yang sama
				//$this->output->set_header('Content-type: '.$row->document_mime);
				//$this->output->set_output($row->document);
			}
			//----------- tampil di halaman lain
	       	$this->load->vars($data);
			$this->load->view('delegasi/downloadfile',$data,FALSE);
	}
}