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

class Sinkron_file extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
	}    
	
	public function upload_putusan($perkara_id)
	{
		$this->load->library('rest', 
			array(  
				'server' 	=> 'http://119.82.224.91/api/',
				'http_user'	=> 'sipp',
				'http_pass'	=> 'SIPP2016!',
				'http_auth'	=> 'digest'
			)
		); 
                $this->load->model('api/dirput_model');
                $fileputusan = $this->dirput_model->ambil_fileputusan($perkara_id);
                $putusan_publish = $fileputusan[0]['path_publish'];
                $putusan_anonim = $fileputusan[0]['path_anonim'];
                $putusan_rtf = $fileputusan[0]['path_rtf'];
                $result = $this->rest->post('upload/putusan_akhir', 
                        array(
                            'Content-type' => 'application/x-www-form-urlencoded',
                            'user_admin'        => $user_admin,
                            'pwd_admin'         => $pwd_admin,
                            'satker_id'         => $satker_id,
                            'perkara_id'        =>$perkara_id,
                            'putusan_anonim'    => base64_encode(file_get_contents($putusan_anonim)),
                            'putusan_rtf'       => base64_encode(file_get_contents($putusan_rtf)),
                            'putusan_publish'       => base64_encode(file_get_contents($putusan_publish))
                        )
		); 
		echo "<pre>";
		print_r($result);
		echo "</pre>";		
	}
        
        public function upload_pendukung($perkara_id)
	{
		$this->load->library('rest', 
			array(  
				'server' 	=> 'http://sipp-ma.mahkamahagung.go.id/api/',
				'http_user'	=> 'sipp',
				'http_pass'	=> 'SIPP2016!',
				'http_auth'	=> 'digest'
			)
		); 
                $this->load->model('api/dirput_model');
                $pendukung = $this->dirput_model->ambil_filependukung($perkara_id);
                foreach ($pendukung as $file){
                $filename = $file['filename'];
                $file = $file['path_filename'];
                $satker_id = $userpwd['kode_satker'];
                
                $result = $this->rest->post('upload/file_pendukung', 
                        array(
                            'Content-type' => 'application/x-www-form-urlencoded',
                            'user_admin'            => $user_admin,
                            'pwd_admin'             => $pwd_admin,
                            'satker_id'             => $satker_id,
                            'perkara_id'            => $perkara_id,
                            'filename'              => $filename,
                            'file'                  => base64_encode(file_get_contents($file)),
                            'path_filename'         => $file
                        )
		); 
		echo "<pre>";
		print_r($result);
		echo "</pre>";		
            }
        }

        public function upload_pengantar($perkara_id)
	{
		$this->load->library('rest', 
			array(  
				'server' 	=> 'http://sipp-ma.mahkamahagung.go.id/api/',
				'http_user'	=> 'sipp',
				'http_pass'	=> 'SIPP2016!',
				'http_auth'	=> 'digest'
			)
		); 
                $this->load->model('api/dirput_model');
                $pendukung = $this->dirput_model->ambil_filependukung($perkara_id);
                foreach ($pendukung as $file){
                $filename = $file['filename'];
                $file = $file['path_filename'];
                $satker_id = $userpwd['kode_satker'];
                
                $result = $this->rest->post('upload/pengantar', 
                        array(
                            'Content-type' => 'application/x-www-form-urlencoded',
                            'user_admin'            => $user_admin,
                            'pwd_admin'             => $pwd_admin,
                            'satker_id'             => $satker_id,
                            'perkara_id'            => $perkara_id,
                            'filename'              => $filename,
                            'file'                  => base64_encode(file_get_contents($file))
                        )
		); 
		echo "<pre>";
		print_r($result);
		echo "</pre>";		
            }
        }
}