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

set_time_limit(0);
ini_set('max_execution_time', 3600);
ini_set('memory_limit', '1024M');
ini_set('max_input_time', 3600);

class Putusan extends CI_Controller {
var $a5yu;
	public function __construct()
	{
		parent::__construct();
	}    
        public function antrian_upload(){
            $this->load->model('api/dirput_model');
            $data = $this->dirput_model->range_antrian();
            //echo "antrian sekarang = ".$data['ngantri'];
            foreach($data['antrian'] as $antri){
               $idantrian = $antri['id'];
               $perkara_id = $antri['perkara_id'];
               $this->create($perkara_id,$idantrian);
            }
        }

        public function antrian_upload_to_send(){
            $this->load->model('api/dirput_model');
            $data = $this->dirput_model->range_antrian();
            //echo "antrian sekarang = ".$data['ngantri'];
            foreach($data['antrian'] as $antri){
               $idantrian = $antri['id'];
               $perkara_id = $antri['perkara_id'];
               $this->create($perkara_id,$idantrian);
            }
            $this->load->view("antrian/antrian_dirput/antrian_saat_ini");
        }

        public function antrian_convert(){
            $this->load->model('api/dirput_model');
            $data = $this->dirput_model->antrian_convert();
			
            foreach($data['antrian'] as $antri){
                $instance = explode(" ",php_uname());
                    if($instance[0] == 'Windows'){
			$namafile = str_replace('/','\\',FCPATH.$antri['amar_putusan_dok']);
                    }else{
                        $namafile = FCPATH.$antri['amar_putusan_dok'];
                    }
				if(file_exists($namafile))
				{
					$fileasal = $antri['amar_putusan_dok'];
					$perkara_id = $antri['perkara_id'];
					$dokumen_ref_id = $antri['dokumen_ref_id'];
					$filetarget = $fileasal.'.pdf';
                                        $this->load->helper('wordtopdf_helper');
				   
						$instance = explode(" ",php_uname());
						if($instance[0] == 'Windows')
						{
							convert_pdf_windows($fileasal,$filetarget);								
						} else {	
							convert_pdf($fileasal,$filetarget);
						}
						$this->dirput_model->convert_insert($perkara_id,$filetarget,$dokumen_ref_id);
						$this->dirput_model->insert_antrian_upload($perkara_id);		
				}
				else {
					echo $namafile."<br>";
					//FCPATH.$antri['amar_putusan_dok']."<br>";
				}
			}
			$this->antrian_upload();
		}
        
        public function index(){
	$this->load->view("welcome_message");
		}
		
	public function get_list()
	{
	  $this->load->model('api/dirput_model');
            $coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
                $parameter = array('user_dirput' => $userpwd['user_dirput'],
                                    'pwd_dirput' => $userpwd['pwd_dirput'],
                                    'limit' => 50,
                                    'offset' => 0);
                $field = "idx.guid as putusan_id, idx.sNoPutusan as putusan_no, year(idx.dTglPutusan) as tahun";
                $parameter['field'] = rawurlencode($field);
                $result = $this->rest->get('putusan/list_index', $parameter
		); 
                
                foreach($result->data as $hasil){
                $putusan_id = $hasil->putusan_id; 
                $nomor_perkara = $hasil->putusan_no;
                //$pengajuan_id = 
                $aRemoveChar = array('-', '/', ' ', '.');
		$nomor_perkara_key = str_replace($aRemoveChar, '', $hasil->putusan_no);
                $pengajuan_id = $hasil->tingkat == 'ptm' ? 1 : null;
                //cek di tabel dirput_perkara apa sudah ada atau tidak
                //if(!$this->db->query("select nomor_perkara, putusan_id from dirput_perkara 
                //        where (putusan_id = '$putusan_id' or nomor_perkara = '$putusan_no');")->num_rows()>0){
                    // jika kosong, data result masukkan di tabel dirput_perkara
/*
               $insertdata = $this->dirput_model->ambil_dari_dirput($putusan_id,$nomor_perkara,$pengajuan_id,$nomor_perkara_key);  
                        if($insertdata){
                            echo "Insert success<br>".$putusan_no." dengan id direktori perkara ".$putusan_id."<hr>";
                        }else{
                            echo "insert error<br><hr>";
                        }
*/
                }
                
		echo "<pre>";
		print_r($result);
		echo "</pre>";		
	}
	
	public function create($perkara_id,$idantrian)
	{
            //$this->load->library('rest', json_decode(base64_decode($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();
                //echo"<pre>";print_r($userpwd);echo"</pre>";exit;
		$dataputusan = $this->dirput_model->create_dirput($perkara_id);
		$file_putusan = file_get_contents($dataputusan[0]['file_putusan']);
                if($dataputusan[0]['urutan'] == 100){
                    switch ($dataputusan[0]['alur_perkara_id']){
                    case '1':
                    $parapihak = "Penggugat melawan Tergugat";
                    break;
                    case '2':
                    $parapihak = "Pemohon melawan Termohon";
                    break;
                    case '9':
                    $parapihak = "Penggugat melawan Tergugat";
                    break;
                    case '16':
                    $parapihak = "Pemohon melawan Termohon";
                    break;
                    case '15':
                    $parapihak = "Penggugat melawan Tergugat";
                    break;
                    case '118':
                    $parapihak = "Terdakwa";
                    break;
					default:
                    $parapihak = $dataputusan[0]['para_pihak'];
                    }
                }else{$parapihak = $dataputusan[0]['para_pihak'];}
		$result = $this->rest->post('putusan/create', 
			array( 'Content-type' => 'application/x-www-form-urlencoded',
				  'user_dirput' => $userpwd['user_dirput'],
				  'pwd_dirput' => $userpwd['pwd_dirput'],
				  'putusan_no'							=> $dataputusan[0]['nomor_perkara']
				, 'tingkat'								=> 'ptm'
				, 'tanggal_register'					=> $dataputusan[0]['tanggal_register']
				, 'kategori_id'							=> $dataputusan[0]['parentguid']
                                , 'kategori_id_2'							=> $dataputusan[0]['guid']
				// , 'kategori_id_4'						=> 'f0db0cd4ccd2c100ee7fd1cc3d980d6d'
				// , 'kategori_id_5'						=> 'f0db0cd4ccd2c100ee7fd1cc3d980d6d'
				, 'tanggal_diputus'						=> $dataputusan[0]['tanggal_diputus']
				, 'tanggal_dibaca'						=> $dataputusan[0]['tanggal_diputus']
				, 'pengadilan_id'						=> $userpwd['pengadilan_id']
				, 'para_pihak'							=> $parapihak
				, 'amar'								=> $dataputusan[0]['amar']
				, 'catatan_amar'						=> $dataputusan[0]['catatan_amar']
				, 'hakim'								=> $dataputusan[0]['hakim']
				, 'hakim_ketua'							=> $dataputusan[0]['hakim_ketua']
				, 'hakim_anggota'						=> $dataputusan[0]['hakim_anggota']
				, 'panitera'							=> $dataputusan[0]['panitera']
				, 'status_tahanan'						=> $dataputusan[0]['status_penahanan']
				, 'bht'									=> $dataputusan[0]['bht']
				, 'publikasi'							=> $dataputusan[0]['published']
				, 'kata_kunci'							=> $dataputusan[0]['kata_kunci']
				, 'file_putusan_nama'					=> $dataputusan[0]['file_putusan_nama']
				, 'file_putusan'						=> base64_encode($file_putusan)
				, 'file_putusan_is_pdf_format'			=> 1
			)
		); 
				
                if($result->response){
                $putusan_id = $result->value->putusan_id;
                $putusan_link = $result->value->putusan_link;
                $status = 1;
                $keterangan = $result->message;
                $perkara_id = intval($perkara_id);
                $nomor_perkara = $dataputusan[0]['nomor_perkara'];
                //echo $idantrian."<br>".$status."<br>".$keterangan;
                $aRemoveChar = array('-', '/', ' ', '.');
		$nomor_perkara_key = str_replace($aRemoveChar, '', $nomor_perkara);  
                if(!empty($putusan_id)){
                    echo "putusan ID ditemukan<br>".$putusan_id;
                $simpan = $this->dirput_model->simpan_dirput_perkara($perkara_id,$putusan_id,$nomor_perkara,$pengajuan_id=1,$nomor_perkara_key,$putusan_link);
                
                if(!$simpan)
                    {
                        $status = -1;
                        $keterangan = "Gagal insert table dirput_perkara";
                        echo "<br>".$keterangan."<hr>";
                    } else {
                        $status = 1;
                        echo "<br>".$keterangan."<hr>";
                    }    
                  }else { echo "<strong>ERROR !!</strong> response Putusan ID tidak ada<hr>";
                  }
                }else{
                    $status = -1;
                    $keterangan = $result->message;
                }
                echo "Nomor Perkara ".$nomor_perkara." berhasil diupload dengan putusan ID : ".$putusan_id."<br>";
                echo "<a href=".$putusan_link." target=_blank>Link putusan</a><br>";
                $this->dirput_model->update_antrian($idantrian,$perkara_id, $status, $keterangan);
		//redirect(base_url('antrian_dirput'));
                
	}
		
	public function add_file_pendukung($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();
              $file_id = $this->dirput_model->ambil_file_id($perkara_id,$pengajuan_id);
              if(!empty($file_id[0]['keterangan'])){
              foreach($file_id as $file){
                  $param = array(
                    'Content-type' => 'application/x-www-form-urlencoded',
                    'user_dirput'       => $userpwd['user_dirput'],
                    'pwd_dirput'        => $userpwd['pwd_dirput'],
                    'file_id'        => $file['keterangan']);
                $kirim1 = $this->rest->post('putusan/delete_file_pendukung',$param);
		}
              }
                $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 );
                if($result->response){$flag = 1;}else{$flag = -1;}
                $keterangan = $result->value;
                $this->dirput_model->update_file_pendukung($kirim['file_id'],$keterangan,$flag);
		echo "<pre>";
		print_r($result->message);
		echo "</pre>";
                }
                redirect(base_url('dashboard'));
	}
	      
        public function get_satker()
	{
	    $this->load->model('api/dirput_model');
	    $coook = $this->dirput_model->coook();
            	$this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
                $parameter = array('user_dirput' => $userpwd['user_dirput'],
                                    'pwd_dirput' => $userpwd['pwd_dirput']);
                
                $result = $this->rest->get('putusan/satker', $parameter
		);
	print_r($result);
          echo "<h2>Satker ID di direktori Putusan adalah : ".$result->satker_id."</h2><br>";
	  $this->db->query("update sys_config set value = '".$result->satker_id."' where name = 'pengadilan_id';");
          redirect(base_url('configuration'));
     }
	 
    public function cekstatus($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();
                $putusan = $this->dirput_model->ambil_pengajuan($perkara_id,$pengajuan_id);
                $parameter = array('user_dirput' => $userpwd['user_dirput'],
                                    'pwd_dirput' => $userpwd['pwd_dirput'],
                                    'pengajuan_guid' => $putusan[0]['pengajuan_guid']);
                $result = $this->rest->get('putusan/cekstatus', $parameter
		);
//                echo "<pre>";print_r($result);echo "</pre>";exit;
                $data = $result->data;
		switch ($pengajuan_id){
		case "2" :
                    $jenispermohonan = "banding";
                break;
		case "3" : $jenispermohonan = "kasasi"; break;
		case "4" : $jenispermohonan = "pk"; break;
		default: $jenispermohonan = "kasasi";}
//                $jenispermohonan = explode(' ',$data->d_jpName);
//                $jenispermohonan = strtolower($jenispermohonan[0]);
                $tabel = "perkara_".$jenispermohonan;
//                $tanggal_terima = $data->spReceiveDate;
                $no_register = (string)$data->no_perkara;
                $tgl_register = $data->tgl_didaftar;
                $hakim1 = (string)$data->putusan_teraju[0]->ptsKetua;
                $anggota = explode('\r\n',$data->putusan_teraju[0]->ptsAnggota);
		$hakim2 = (string)$anggota[0];
                $hakim3 = (string)$anggota[1];
                $hakim4 = (string)$anggota[2];
                $hakim5 = (string)$anggota[3];
                $panitera = (string)$data->putusan_teraju[0]->ptsPanitera;
                $amar = (string)$data->putusan_teraju[0]->ptsAmar;
                $status = "Status berkas : ".$data->status_pengajuan;
                echo $status."<br>Terdaftar dengan nomor : ".$no_register." pada tanggal ".$tgl_register;
//                echo "<pre>";var_dump($data);echo "</pre>";
                //$putusan_doc = (string)$data->docId;
                $majelis_hakim = $hakim1." ".$hakim2." ".$hakim3;
                $this->dirput_model->update_pengajuan($perkara_id,$pengajuan_id,$status);
                //if($data->d_spStatus=='PUTUS'){
                $datanya = array (
                        'nomor_perkara_'.$jenispermohonan => $no_register,
                        'hakim1_'.$jenispermohonan     => $hakim1,
                        'hakim2_'.$jenispermohonan     => $hakim2,
                        'hakim3_'.$jenispermohonan 	=> $hakim3,
                        'majelis_hakim_'.$jenispermohonan => $majelis_hakim,
                        'panitera_pengganti_'.$jenispermohonan => $panitera,
                        'amar_putusan_'.$jenispermohonan => $amar,
                        'amar_putusan_'.$jenispermohonan.'_dok' => $putusan_doc,
                        'nomor_putusan_'.$jenispermohonan => $no_register);
                        switch ($jenispermohonan){
                            case "kasasi":
                                if($this->dirput_model->update_kasasi($perkara_id,$tabel,$datanya)){
                                    echo "<hr>Update perkara_kasasi berhasil";
                                } else {
                                    echo "<hr>Update perkara_kasasi GAGAL";
                                }
                                break;
                            case "pk":
                                if($this->dirput_model->update_pk($perkara_id,$tabel,$datanya)){
                                    echo "<hr>Update perkara_pk berhasil";
                                } else {
                                    echo "<hr>Update perkara_pk gagal";
                                }
                                break;
                        }
                    //}
//               redirect(base_url('perkara_'.$jenispermohonan.'_detil/'.$this->encrypt->base64_encode($perkara_id)));
         }

    public function download_file($perkara_id,$pengajuan_id){
        switch ($pengajuan_id){
          case 2:
              $tabel = 'perkara_banding';
              $field = 'amar_putusan_banding_dok';
              break;
          case 3:
              $tabel = 'perkara_kasasi';
              $field = 'amar_putusan_kasasi_dok';
              break;
          case 4:
              $tabel = 'perkara_pk';
              $field = 'amar_putusan_pk_dok';
              break;
          default:
              break;
        }
        $this->load->model('api/dirput_model');
        $file_put = $this->dirput_model->putusan_dirput($perkara_id,$tabel,$field);
        if(!empty($file_put[0]['file_id'])){
            $coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
        $userpwd = $this->dirput_model->list_get();
        $parameter = array(
            'user_dirput' => $userpwd['user_dirput'],
            'pwd_dirput' => $userpwd['pwd_dirput'],
            'file_id'   => $file_put[0]['file_id']
        );
        $putusan = $this->rest->get('putusan/download',$parameter);
        header("Content-type: application/pdf");
        header("Content-Disposition: attachment; filename=putusan.pdf");
        print_r($putusan);
        }else{
            echo "putusan ini belum diupload ke direktori putusan<BR>silakan klik tombol back/kembali";
        }
    }     
	 
     public function pengajuan_banding($perkara_id){
	$this->load->model('api/dirput_model');
            $coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
        //    $this->load->library('rest', json_decode(base64_decode($this->config->item('coook'))));
        //        $this->load->model('api/dirput_model');
                $userpwd = $this->dirput_model->list_get();
                $pengantar = $this->dirput_model->pengantar($perkara_id);        
		$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"<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,
			)
		);
                echo json_encode($result);
                $pengajuan_guid = $result->value;
                echo "Pengajuan sukses dibuat dengan pengajuan_guid ".$pengajuan_guid."<br>";
                $this->db->query("update dirput_pengajuan set pengajuan_guid = '$pengajuan_guid' where perkara_id = $perkara_id;");
		$this->pengajuan_detail($pengajuan_guid);
	}	 
	 
	    public function pengajuan_kasasi($perkara_id){
             //$this->load->library('rest', json_decode(base64_decode($this->config->item('coook'))));
             //   $this->load->model('api/dirput_model');
	    $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);        
		$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'];
		$putusan_id = $pengantar[0]['putusan_id'];
                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'				=> '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
			)
		);
                echo json_encode($result);
                $pengajuan_guid = $result->value;
                echo "Pengajuan sukses dibuat dengan pengajuan_guid ".$pengajuan_guid."<br>";
                $this->db->query("update dirput_pengajuan set pengajuan_guid = '$pengajuan_guid' where perkara_id = $perkara_id;");
		$this->pengajuan_detail($pengajuan_guid);
	}
	 

        public function pengajuan_detail($upaya_hukum_id)
	{
		//$this->load->library('rest', json_decode(base64_decode($this->config->item('coook'))));
                //$this->load->model('api/dirput_model');
	    $this->load->model('api/dirput_model');
            $coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
		$result = $this->rest->get('upayahukum/list_detail', 
			array('user_dirput'     => $userpwd['user_dirput'],
                              'pwd_dirput'      => $userpwd['pwd_dirput'],
                              'upaya_hukum_id'  => $upaya_hukum_id)
		); 
		$hasils = (array)$result;
		foreach ($hasils['data'] as $hasil){
                    $filepengantar_id = $hasil->file_pengantar->file_id;
                    $this->print_barcode($filepengantar_id);
                    echo "file id barcode sudah didapat dengan id ".$filepengantar_id."<br>";
                    $this->db->query("update dirput_pengajuan set barcode = '$filepengantar_id' where pengajuan_guid = '$upaya_hukum_id';");
                }
	}
	
        public function print_barcode($filepengantar_id){
            //$this->load->library('rest', json_decode(base64_decode($this->config->item('coook'))));
                //$this->load->model('api/dirput_model');
	    $this->load->model('api/dirput_model');
            $coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
		$barcode = $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.pdf");
		echo $barcode;
        }	
	
	 
                
        public function statusputusan(){
//            $this->load->library('rest', json_decode(base64_decode($this->config->item('coook'))));
//            $this->load->model('api/dirput_model');
	$this->load->model('api/dirput_model');
            $coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
            $userpwd = $this->dirput_model->list_get();
            $parameter = array('user_dirput' => $userpwd['user_dirput'],
                                'pwd_dirput' => $userpwd['pwd_dirput'],
                                'limit' => 50,
                                'offset' => 0);
            $putusan = $this->rest->get('putusan/list_index', $parameter);
            $upayahukum = $this->rest->get('upayahukum/list_detail', $parameter);
            $this->session->set_userdata('statusputusan',$putusan->value->num_rows);
            $this->session->set_userdata('statuspengajuan',$upayahukum->value->num_rows);
            $this->load->view("antrian/antrian_dirput/antrian_saat_ini");
                
    }
    public function ceklink($putusan_id){
            //$this->load->library('rest', json_decode(base64_decode($this->config->item('coook'))));
            //$this->load->model('api/dirput_model');
	$this->load->model('api/dirput_model');
            $coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
                
                $parameter = array('user_dirput' => $userpwd['user_dirput'],
                                    'pwd_dirput' => $userpwd['pwd_dirput'],
                                    'putusan_id' => $putusan_id);
                $putusan = $this->rest->get('putusan/link', $parameter);
                redirect("https://putusan.mahkamahagung.go.id/putusan/".$putusan[0]->catalogGuid);
    }

public function cekdatadirput()
	{
	//	$this->load->library('rest', json_decode(base64_decode($this->config->item('coook'))));
        //        $this->load->model('api/dirput_model');
	$this->load->model('api/dirput_model');
            $coook = $this->dirput_model->coook();
                $this->load->library('rest',$coook);
                $userpwd = $this->dirput_model->list_get();
                $parameter = array('user_dirput' => $userpwd['user_dirput'],
                                    'pwd_dirput' => $userpwd['pwd_dirput']);
                $result = $this->rest->get('putusan/list_baru', $parameter);
                $totalrow = $result->value->num_rows;

                $parameter['limit'] = $totalrow;
//                $totalpage = (int)($totalrow/$parameter['limit']);
                $field = "idx.guid as putusan_id, idx.sNoPutusan as putusan_no, idx.sNoPutusanKey as nomor_perkara_key";
                $parameter['field'] = rawurlencode($field);
                $ambilcepek = $this->rest->get('putusan/list_baru', $parameter);
                    echo"<pre>";print_r($ambilcepek);echo"</pre>";
                    foreach($ambilcepek->data[0] as $hasil){
                        $putusan_id = $hasil->putusan_id; 
                        $nomor_perkara = $hasil->putusan_no;
                        $nomor_perkara_key = $hasil->nomor_perkara_key;
                        $arr=explode('/',$nomor_perkara);
                        $arr[0]=intval($arr[0]);
                        $nomor_perkara = implode('/',$arr);
                        //$aRemoveChar = array('-', '/', ' ', '.');
                        //$nomor_perkara_key = strtoupper(str_replace($aRemoveChar, '', $nomor_perkara));
                        //$pengajuan_id = $hasil->tingkat == 'ptm' ? 1 : null;
                        $pengajuan_id = 1;
                        $insertdata = $this->dirput_model->ambil_dari_dirput($putusan_id,$nomor_perkara,$pengajuan_id,$nomor_perkara_key);  
                        if($insertdata){
                            echo "Insert success<br>".$nomor_perkara." dengan id direktori perkara ".$putusan_id."<hr>";
                        }else{
                            echo "insert error<br><hr>";
                        }
                    }
        }
    
}
