<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
set_time_limit(0);
ini_set('max_execution_time', '36000');
ini_set('memory_limit', '1024M');
ini_set('max_input_time', '36000');
ini_set('post_max_size', '1024M');
ini_set('upload_max_filesize', '1024M');
class Upload_dirput extends CI_Controller {


 function index(){

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

  }

 ///
 function tampil_edit($idupaya,$idpihak_upaya) {

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

			$data['history'] = base_url(uri_string());
			//$this->load->model('perkara/dirput','dirput');
			$this->load->model('api/dirput_model','dirput');
			$perkara_id=$this->session->userdata('perkaraid');
			//$data['id_upaya']=end($this->uri->segments);
                        $alurperdatakhusus=array(3,4,5,6,7,8);
	                if (in_array($this->tanggalhelper->getIDAlurPerkara($perkara_id), $alurperdatakhusus))
			  {
			  $data['alur_perkara_id']=3;
			  } else {
			  $data['alur_perkara_id']=$this->tanggalhelper->getIDAlurPerkara($perkara_id);
			  }
			$data['upayapihak_id']=$idpihak_upaya;
			$data['upaya_id']=$idupaya;
			$data['doc_referensi'] = $this->dirput->doc_ref($this->session->userdata('jenis_pengadilan'),$idupaya,$data['alur_perkara_id']);
			$this->load->vars($data);
			$this->load->view('perkara/direktori_putusan/edit_upload');

 }


function upload(){


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

		$perkara_id = $this->session->userdata('perkaraid');
		$this->load->model('api/dirput_model','dirput');
		//$row=$this->dirput->ambildata_dirput($perkara_id)->row();
		$dataku=$this->dirput->create_dirput($perkara_id);

		foreach ($dataku as $row ) {
		 	$nomor_perkara = $row['nomor_perkara'];
			$tanggal_putus = $row['tanggal_diputus'];
			$jenis_putusan = $row['amar'];
			$klasifikasi   = $row['kata_kunci'];
		 }
		$upayaid = $this->input->post('upaya_id');
    $upayapihak_id = $this->input->post('upayapihak_id');
		switch ($upayaid) {
				case 2:
					$folder = 'banding';
					$url ='perkara_banding_detil';
					break;
				case 3:
					$folder = 'kasasi';
					$url ='perkara_kasasi_detil';
					break;
				case 4:
					$folder = 'pk';
					$url ='perkara_pk_detil';
					break;
				default:
					$folder = 'upaya_apa?';
					$url ='login';
			}


		$files_count=count($_FILES['edoc']['name']);
    //echo"jumlah file :".$files_count."<br>";
    //echo"<pre>";
    //print_r($_FILES);
    for ($i=0;$i<$files_count;$i++) {

			  $_FILES['edocs']['name'] = $_FILES['edoc']['name'][$i];
        $_FILES['edocs']['type'] = $_FILES['edoc']['type'][$i];
        $_FILES['edocs']['tmp_name'] = $_FILES['edoc']['tmp_name'][$i];
        $_FILES['edocs']['error'] = $_FILES['edoc']['error'][$i];
        $_FILES['edocs']['size'] = $_FILES['edoc']['size'][$i];

				$doc_ref		 = $_POST['referensi'][$i];
				$ket			   = $this->dirput->ambil_ketfile($doc_ref)->row();
				$ektensi_ref = $ket->format;
				$ketfile     = str_replace(" ", "_", $ket->keterangan_file);
        $urutan      = $ket->urutan;
				$filetemp		 = $_FILES['edocs']['tmp_name'];
				$nama_file_ori  = $_FILES['edocs']['name'];
				$extension	    = pathinfo($nama_file_ori);
				$ektensi_file	= $extension['extension'];
        $nama_depan_file =basename($nama_file_ori,$ektensi_file);

        $nomor_perkara	= str_replace("/", "_", $nomor_perkara);
				$nomor_perkara	= str_replace(" ", "_", $nomor_perkara);
				$nomor_perkara	= str_replace(".", "_", $nomor_perkara);
				$tanggal_putus	= str_replace("-", "", $tanggal_putus);
				$jenis_putusan	= str_replace(",", "_", $jenis_putusan);
        $jenis_putusan	= str_replace(" ", "_", $jenis_putusan);
        $jenis_putusan	= str_replace(".", "_", $jenis_putusan);
				$klasifikasi	= str_replace(",", "_", $klasifikasi);
				$klasifikasi	= str_replace(" ", "_", $klasifikasi);
				$klasifikasi	= str_replace(".", "_", $klasifikasi);
				$namafile	    = $urutan.'_'.$ketfile.'_'.$this->input->post('upayapihak_id').'_'.$nomor_perkara.'_'.$tanggal_putus.'_'.$jenis_putusan.'_'.$klasifikasi.'.'.$ektensi_file;

				$kataputus = explode("_",strtolower($ketfile));

				if(strpos(strtolower($kataputus[0]),'putusan') !== false) {

					 $direktori="resources/direktori_putusan/".$folder."/".$nomor_perkara."/putusan/";
				     } else {
				     $direktori="resources/direktori_putusan/".$folder."/".$nomor_perkara."/dokumen_pendukung/";
				}
                        $path_namafile=$direktori.$namafile;


			  try {
				//chmod($direktori, 0777);
				@mkdir($direktori,0777,true);
				} catch (Exception $e) {
					echo json_encode(array('st'=>0,'msg'=>'E-Doc TIDAK Berhasil Disimpan.'));
					return;
				}


			 if ((!empty($_FILES['edoc']['name'][$i]) or trim($_FILES['edoc']['name'][$i])!='')) {


					   $upload_config = array(
						'upload_path' => $direktori,
						'allowed_types' => 'pdf|rtf',
						'max_size' => '100240',
						'overwrite' => true,
						'file_name' =>$namafile);


					   $this->upload->initialize($upload_config);
					   $this->load->library('upload', $upload_config);


						if (!$this->upload->do_upload('edocs')){
							echo json_encode(array('st'=>0,'msg'=>'Dokumen Elektronik Tidak Berhasil Disimpan. '.$this->upload->display_errors('<span>', '</span>')));
							return;
						 }
                                                     else {

							  //insert
							  //ambil pihakid
							   $idpihak=$this->dirput->ambil_pihak_kasasi_detil($perkara_id)->row();
							   $pihakid=$idpihak->id;
							   $kasasi_id=$this->input->post('kasasi_id');

							   //ambil_id
							   $ids = $this->dirput->ambil_maxid()->row();
							   $id = $ids->max_id+1;

							   $data_dokumen = array(
											'id' => $id,
											'perkara_id' => $perkara_id,
											'dokumen_ref_id' => $doc_ref,
											'filename' => $namafile,
											'path_filename' => $path_namafile,
											'created_by' => $this->session->userdata('username'),
											'created_date' => date("Y-m-d h:i:s",time()),
											'pihak_detil_id' => $upayapihak_id,
											'pengajuan_id' => $upayaid
										);


								$result=$this->dirput->simpan_doc($data_dokumen);

								if($result===FALSE){
											echo json_encode(array('st'=>0,'msg'=>'GAGAL Menyimpan database'));
											return;
								   }
							}	//berhasil upload







				  }//end ada tidaknya data file

		}

		
    if ($url!='login') { 
	redirect(base_url($url.'/'.base64_encode($this->encrypt->encode($perkara_id))));	
	} else {
		redirect('login');
	}

}



	//testttt///
	function editpengantar($idupaya){
		//echo "wedusss";exit;

		if($this->session->userdata('is_logged_in')==FALSE){
			redirect('login');
		}
		$data['history'] = base_url(uri_string());
		$data['upaya_id']=$idupaya;
		$perkara_id = $this->session->userdata('perkaraid');
                //echo "perkara _id".$perkara_id."<br>";exit;
                #integrasi 22/04/2017
		$alurperdatakhusus=array(3,4,5,6,7,8);
	        if (in_array($this->tanggalhelper->getIDAlurPerkara($perkara_id), $alurperdatakhusus))
			  {
			  $alur_perkara_id=3;
			  } else {
			  $alur_perkara_id=$this->tanggalhelper->getIDAlurPerkara($perkara_id);
			  }
		//$alur_perkara_id=$this->tanggalhelper->getIDAlurPerkara($perkara_id);
		$this->load->model('perkara/dirput','dirput');
		$data['ref_pengantar']=$this->dirput->doc_ref_pengantar($this->session->userdata('jenis_pengadilan'),$idupaya,$alur_perkara_id)->row();
		//Sdata['pengantar'] = $this->dirput->ambil_pengantar($perkara_id,2);
		$data['upaya_id']=$idupaya;
		$data['history'] = base_url(uri_string());
		$data['current_date'] =date('d/m/Y');
		$this->load->vars($data);
		$this->load->view('perkara/kasasi/edit_pengantar');
	}



	function simpan_katapengantar() {

		if($this->session->userdata('is_logged_in')==FALSE){
			echo json_encode(array('st'=>0,'msg'=>'Waktu Login Anda telah Berakhir, Silahkan Login Kembali.'));
			return;
		}

		$perkara_id = $this->session->userdata('perkaraid');
		$upayaid = $this->input->post('upaya_id');
		$this->form_validation->set_rules('tanggal_surat', 'Tanggal surat pengantar', 'trim|required|xss_clean|exact_length[10]');
		$this->form_validation->set_rules('nomor_surat', 'Nomor surat pengantar', 'trim|required|xss_clean|min_length[5]');
                $this->form_validation->set_rules('nomer_resi', 'Nomor resi PT.Pos', 'trim|required|xss_clean');

		if ($this->form_validation->run() === FALSE){
			echo json_encode(array('st'=>0,'msg'=>'<strong>Peringatan:</strong><br /> Tidak Berhasil'.validation_errors()));
			return;
		} else {

			$nomor_surat=$this->input->post('nomor_surat');
			$tanggal_surat=$this->input->post('tanggal_surat');
			$no_resi=$this->input->post('nomer_resi');
			$this->load->model('perkara/dirput','dirput');

			//get nomor perkara
                         $upayaid = $this->input->post('upaya_id');

			switch ($upayaid) {
					case 2:
						$tabel = 'perkara_banding';
						break;
					case 3:
						$tabel = 'perkara_kasasi';
						break;
					case 4:
						$tabel = 'perkara_pk';
						break;
					default:
						$tabel = 'perkara';
				}

			//echo 'tabellll '.$tabel;exit;
			$noperk=$this->dirput->ambil_nomor_perkara($perkara_id,$tabel)->row();
			//$noperk=$this->dirput->ambil_nomor_perkara($perkara_id)->row();
			$nomor_perkara=$noperk->nomor_perkara;
			$id =$this->dirput->ambil_maxid_pengantar()->row();
			$id=$id->max_id+1;
			///insert data
			$data_pengantar = array(
						'id' => $id,
						'perkara_id' => $perkara_id,
						'nomor_perkara' => $nomor_perkara,
						'nomor_surat_pengantar' => $nomor_surat,
						'tgl_surat_pengantar' => $this->tanggalhelper->convertToMysqlDate($tanggal_surat),
						'no_resi_pos' => $no_resi,
						'pengajuan_id'=> $upayaid

					);


			$result0=$this->dirput->simpan_pengantar($data_pengantar);

                                   if ($result0==TRUE) {
					echo json_encode(array('st'=>1,'msg'=>'Data Berhasil Disimpan'));
					}else{
						echo json_encode(array('st'=>0,'msg'=>'Data Tidak Tersimpan'));
					}

		return;

         }
     }


 function upload_pengantar() {

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

		$perkara_id = $this->session->userdata('perkaraid');
		$this->load->model('perkara/dirput','dirput');

		$upayaid = $this->input->post('upaya_id');
		$pihakid = $this->input->post('upayapihak_id');

		switch ($upayaid) {
				case 2:
					$folder = 'banding';
					break;
				case 3:
					$folder = 'kasasi';
					break;
				case 4:
					$folder = 'pk';
					break;
				default:
					$folder = 'upaya_apa?';
			}

		 echo "upaya id :".$upayaid." nama folder :".$folder;
		//upload file_surat_pengantar
			$perkara_id = $this->session->userdata('perkaraid');
			$noperk=$this->dirput->ambildata_dirput($perkara_id)->row();
			$nomor_perkara	= trim($noperk->nomor_perkara);
			$nomor_perkara	= str_replace("/", "_", $nomor_perkara);
			$nomor_perkara	= str_replace(" ", "_", $nomor_perkara);
			$nomor_perkara	= str_replace(".", "_", $nomor_perkara);
			$direktori      ="resources/direktori_putusan/".$folder."/".$nomor_perkara."/surat_pengantar/";
		   	$nama_file_ori  = $_FILES['edoc_pengantar']['name'];
			$extension	    = pathinfo($nama_file_ori);
			$ektensi_file	= $extension['extension'];
			$namafile	    = "surat_pengantar"."_".$folder."_".$nomor_perkara.".".$ektensi_file;
			$path_namafile	= $direktori.$namafile;

			try {
			//chmod($direktori, 0777);
			@mkdir($direktori,0777,true);

			} catch (Exception $e) {
				echo json_encode(array('st'=>0,'msg'=>'E-Doc TIDAK Berhasil Disimpan.'));
				return;
			}
		  if ((!empty($_FILES['edoc_pengantar']['name'][$i]) or trim($_FILES['edoc_pengantar']['name'][$i])!='')) {

			$upload_config = array(
			'upload_path' => $direktori,
			'allowed_types' => 'pdf|zip|rar',
			'max_size' => '10240',
			'overwrite' => true,
			'file_name' =>$namafile);

			$this->upload->initialize($upload_config);
			$this->load->library('upload', $upload_config);

			if (!$this->upload->do_upload('edoc_pengantar')){

				echo json_encode(array('st'=>0,'msg'=>'E-Doc Tidak Berhasil Disimpan. '.$this->upload->display_errors('<span>', '</span>')));
				return;
			 } else {

			   //ambil pihakid
			   //$idpihak=$this->dirput->ambil_pihak_kasasi_detil($perkara_id)->row();
			  // $pihakid=$idpihak->id;

			   //ambil_id
			   $ids = $this->dirput->ambil_maxid()->row();
			   $id = $ids->max_id+1;
				///////update path file ke database
			    $ref_pengantar=$this->input->post('ref_pengantar');
				 $data_dokumen = array(
						'id' => $id,
						'perkara_id' => $perkara_id,
						'dokumen_ref_id' => $ref_pengantar, //doc_ref surat pengatar kaasasi
						'filename' => $namafile,
						'path_filename' => $path_namafile,
						'created_by' => $this->session->userdata('username'),
						'created_date' => date("Y-m-d h:i:s",time()),
						'pihak_detil_id' => 0,
						'pengajuan_id' => $upayaid
						);



                $this->dirput->simpan_doc($data_dokumen);
                $keteranganstatus = "DATA selesai diupload";
		//echo json_encode(array('st'=>1,'msg'=>'DATA Berhasil Disimpan. '.$keteranganstatus));
                //$this->pengajuan_kasasi($perkara_id);
		//return;
	}


    }
 }



 function upload_direktori_putusan($perkara_id,$pengajuan_id) {
	$this->load->model('api/dirput_model');
            $coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
                $datapendukung = $this->dirput_model->file_pendukung($perkara_id,$pengajuan_id);
                foreach($datapendukung as $kirim){
                $parameter = array(
                    'Content-type' => 'application/x-www-form-urlencoded',
                    'user_dirput'       => $userpwd['user_dirput'],
                    'pwd_dirput'        => $userpwd['pwd_dirput'],
                    'putusan_id'        => $kirim['putusan_id'],
                    'file_nama'         => $kirim['file_nama'],
                    'file'              => base64_encode(file_get_contents($kirim['file'])),
                    'file_keterangan'   => $kirim['keterangan_file']
                );


		           $result = $this->rest->post('putusan/add_file_pendukung',$parameter );

                }


     }


	 public function pengajuan_banding($perkara_id){
                //$perkara_id = $this->session->userdata('perkaraid');
		$this->load->model('api/dirput_model');
            	$coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
                $pengantar[0] = $this->dirput_model->pengantar($perkara_id,2);
                $datadukung = $this->dirput_model->pengajuan($perkara_id,2);
		$file = $pengantar[0]['path_filename'];
		$file_pengantar = file_get_contents(base_url().$file);
                $file_pengantar_nama = $pengantar[0]['filename'];
		$no_surat_pengantar = $pengantar[0]['nomor_surat_pengantar'];
		$tgl_surat_pengantar = $pengantar[0]['tgl_surat_pengantar'];
		$putusan_id = $pengantar[0]['putusan_id'];
		//echo "file pengantar nama : ".$file_pengantar_nama." no surat : ".$no_surat_pengantar." tanggal surat : ".$tgl_surat_pengantar." putusan id : ".$putusan_id; exit();
                //echo"<pre>";print_r($pengantar);echo"</pre>";
		$result = $this->rest->post('upayahukum/create',
			array( 'Content-type' => 'application/x-www-form-urlencoded',
				  'user_dirput' => $userpwd['user_dirput'],
				  'pwd_dirput' => $userpwd['pwd_dirput'],
				'putusan_id'				=> $putusan_id,
				'upaya_hukum'				=> 'banding',
				'tanggal_surat_pengantar'	=> $tgl_surat_pengantar,
				'no_surat_pengantar'		=> $no_surat_pengantar,
				'file_pengantar_nama'		=> $file_pengantar_nama,
				'file_pengantar'			=> base64_encode($file_pengantar),
				'no_perkara_teraju'			=> NULL,
                                'amar_tingkat_1'        => $datadukung[0]['amar_tingkat_1'],
                                'posita'                => $datadukung[0]['posita'],
                                'petitum'               => $datadukung[0]['petitum'],
                                'dakwaan'               => $datadukung[0]['dakwaan'],
                                'tuntutan_jpu'          => $datadukung[0]['tuntutan_jpu'],
                                'rekonvensi'            => $datadukung[0]['rekonvensi'],
                                'no_resi_pt_pos'        => $pengantar[0]['no_resi_pos'],
                                'tanggal_pengiriman_kurir' => $tgl_surat_pengantar
			)
		);

                $pengajuan_guid = $result->value;
                echo "Pengajuan sukses dibuat dengan pengajuan_guid ".$pengajuan_guid."<br>";
                $this->db->where('perkara_id',$perkara_id);
                $this->db->where('pengajuan_id',2);
                $this->db->set('pengajuan_guid',$pengajuan_guid);
                $this->db->update('dirput_pengajuan');
				redirect(base_url('banding'));
	}


          public function pengajuan_kasasi($perkara_id){
                //$perkara_id = $this->session->userdata('perkaraid');
                //$this->load->library('rest',$this->config->item('coook'));
		$this->load->model('api/dirput_model');
            	$coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
                $pengantar = $this->dirput_model->pengantar($perkara_id,3);
                $datadukung = $this->dirput_model->pengajuan($perkara_id,3);
                $ambilpihak = $this->dirput_model->ambil_pihak($perkara_id);
		$file = $pengantar['path_filename'];
		$file_pengantar = file_get_contents(base_url().$file);
                $file_pengantar_nama = $pengantar['filename'];
		$no_surat_pengantar = $pengantar['nomor_surat_pengantar'];
		$tgl_surat_pengantar = $pengantar['tgl_surat_pengantar'];
		$no_putusan_banding = $pengantar['nomor_putusan_banding'];
		$putusan_id = $pengantar['putusan_id'];
//echo "<pre>";print_r($datadukung);echo"</pre>";
  //              echo"<pre>";print_r($pengantar);echo"</pre>";exit;
		$params=array( 'Content-type' => 'application/json',
				  'user_dirput' => $userpwd['user_dirput'],
				  'pwd_dirput' => $userpwd['pwd_dirput'],
				'putusan_id'				=> $putusan_id,
				'upaya_hukum'				=> 'Kasasi',
				'tanggal_surat_pengantar'	=> $tgl_surat_pengantar,
				'no_surat_pengantar'		=> $no_surat_pengantar,
				'file_pengantar_nama'		=> $file_pengantar_nama,
				'file_pengantar'			=> base64_encode($file_pengantar),
				'no_perkara_teraju'			=> NULL,
				'no_putusan_banding_ref'	=> $no_putusan_banding,
                                'amar_tingkat_1'        => $datadukung['amar_tingkat_1'],
                                'amar_tingkat_banding'        => $datadukung['amar_tingkat_banding'],
                                'posita'                => $datadukung['posita'],
                                'petitum'               => $datadukung['petitum'],
                                'dakwaan'               => $datadukung['dakwaan'],
                                'tuntutan_jpu'          => $datadukung['tuntutan_jpu'],
                                'rekonvensi'            => $datadukung['rekonvensi'],
                                'no_resi_pt_pos'        => $pengantar['no_resi_pos'],
                                'tanggal_pengiriman_kurir' => $tgl_surat_pengantar,
                                'json_pihak'            => json_encode($ambilpihak)
			);
//echo "<pre>";print_r($params);echo"</pre>";exit;
		$results = $this->rest->post('upayahukum/create', $params);
echo "<pre>";print_r($results);echo "</pre>";
                $pengajuan_guid = $results->value;
                //echo "Pengajuan sukses dibuat dengan pengajuan_guid ".$pengajuan_guid."<br>";
                $this->db->where('perkara_id',$perkara_id);
                $this->db->where('pengajuan_id',3);
                $this->db->set('pengajuan_guid',$pengajuan_guid);
                $this->db->update('dirput_pengajuan');
		//redirect(base_url('kasasi'));
                //print_r($result);
	}

                  public function pengajuan_pk($perkara_id){
                //$perkara_id = $this->session->userdata('perkaraid');
		$this->load->model('api/dirput_model');
            	$coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
                $pengantar[0] = $this->dirput_model->pengantar($perkara_id,$pengajuan_id=4);
                $datadukung = $this->dirput_model->pengajuan($perkara_id,4);
		$file = $pengantar[0]['path_filename'];
		$file_pengantar = file_get_contents(base_url().$file);
                $file_pengantar_nama = $pengantar[0]['filename'];
		$no_surat_pengantar = $pengantar[0]['nomor_surat_pengantar'];
		$tgl_surat_pengantar = $pengantar[0]['tgl_surat_pengantar'];
		$no_putusan_banding = $pengantar[0]['nomor_putusan_banding'];
                $no_putusan_kasasi = $pengantar[0]['nomor_putusan_banding'];
		$putusan_id = $pengantar[0]['putusan_id'];
		$result = $this->rest->post('upayahukum/create',
			array( 'Content-type' => 'application/x-www-form-urlencoded',
				  'user_dirput' => $userpwd['user_dirput'],
				  'pwd_dirput' => $userpwd['pwd_dirput'],
				'putusan_id'				=> $putusan_id,
				'upaya_hukum'				=> 'pk',
				'tanggal_surat_pengantar'	=> $tgl_surat_pengantar,
				'no_surat_pengantar'		=> $no_surat_pengantar,
				'file_pengantar_nama'		=> $file_pengantar_nama,
				'file_pengantar'			=> base64_encode($file_pengantar),
				'no_perkara_teraju'			=> NULL,
                                'no_putusan_kasasi_ref'         => $no_putusan_kasasi,
                                'amar_kasasi'        => $datadukung[0]['amar_kasasi'],
                                'amar_tingkat_1'        => $datadukung[0]['amar_tingkat_1'],
                                'amar_tingkat_banding'        => $datadukung[0]['amar_tingkat_banding'],
                                'posita'                => $datadukung[0]['posita'],
                                'petitum'               => $datadukung[0]['petitum'],
                                'dakwaan'               => $datadukung[0]['dakwaan'],
                                'tuntutan_jpu'          => $datadukung[0]['tuntutan_jpu'],
                                'rekonvensi'            => $datadukung[0]['rekonvensi'],
                                'no_resi_pt_pos'        => $pengantar[0]['no_resi_pos'],
                                'tanggal_pengiriman_kurir' => $tgl_surat_pengantar
			)
		);
                echo json_encode($result);
                $pengajuan_guid = $result->value;
                //echo "Pengajuan sukses dibuat dengan pengajuan_guid ".$pengajuan_guid."<br>";
                $this->db->where('perkara_id',$perkara_id);
                $this->db->where('pengajuan_id',4);
                $this->db->set('pengajuan_guid',$pengajuan_guid);
                $this->db->update('dirput_pengajuan');
		//		redirect(base_url('pk'));
		//$this->pengajuan_detail($pengajuan_guid);
	}




        public function pengajuan_detail($upaya_hukum_id)
	{
		$this->load->model('api/dirput_model');
            	$coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
		$hasils = $this->rest->get('upayahukum/list_detail',
			array('user_dirput'     => $userpwd['user_dirput'],
                              'pwd_dirput'      => $userpwd['pwd_dirput'],
                              'upaya_hukum_id'  => $upaya_hukum_id)
		);
                //echo "<pre>";print_r($hasils);echo "</pre>";
		$hasilnya = (array)$hasils;
		foreach ($hasilnya['data'] as $hasil){
                    $filepengantar_id = $hasil->file_pengantar->file_id;

                    //echo "file id barcode sudah didapat dengan id ".$filepengantar_id."<br>";
                    try {
                        $this->db->where('pengajuan_guid',$upaya_hukum_id)
                            ->set('barcode',$filepengantar_id)
                            ->update('dirput_pengajuan');
                        } catch (Exception $e) {
                                return FALSE;
                        }
                    }
            $this->print_barcode($filepengantar_id);
	}

        public function print_barcode($filepengantar_id){
		$this->load->model('api/dirput_model');
            	$coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
		$resultnya = $this->rest->get('upayahukum/print_barcode',
			array('user_dirput'     => $userpwd['user_dirput'],
                              'pwd_dirput'      => $userpwd['pwd_dirput'],
                              'file_id'  => $filepengantar_id)
		);
               header("Content-type: application/pdf");
               header("Content-Disposition: attachment; filename=barcode_".$filepengantar_id.".pdf");
            echo $resultnya;
        }
}
