<?php
class CT_pasi_sa_save extends CI_Controller{
	function __construct()
	{
	  parent::__construct();
		if (!$this->dx_auth->is_logged_in()) {
			header('HTTP/1.1 401 Unauthorize');die('expire');  
		}
		
		$uid = $this->session->userdata('DX_user_id');
		
		if(!permissionAuth(2) && $uid != RID){ 
			header('HTTP/1.1 401 Unauthorize');die('noaccess');
		} 
	}
	
	function index(){	
		$this->load->view('pasi_ceisa_master_new/view_pasi_file_sa'); 
	} 

		
 
	
  
		
		function prosses_file_bc25(){
		        $file_data_id = isset($_POST['file_data_id'])?$_POST['file_data_id']:die('Pilih file yang akan di prosses');; // get the requested page 
		  		$xmldoc =  XMLbasic('json');  
				AddField($xmldoc ,'file_data_id',$file_data_id);
				$str = $xmldoc->saveXML();   
				exec_sp_array($xmldoc, 'dbo.SPX_FILE_SA_BC25_PROSSES',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}

		function prosses_file_bc27(){
			$file_data_id = isset($_POST['file_data_id'])?$_POST['file_data_id']:die('Pilih file yang akan di prosses');; // get the requested page 
			  $xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'file_data_id',$file_data_id);
			$str = $xmldoc->saveXML();   
			exec_sp_array($xmldoc, 'dbo.SPX_FILE_SA_BC27_PROSSES',$sts,$des,$rows,$detail); 
			echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}

	function prosses_file_bc41(){
		$file_data_id = isset($_POST['file_data_id'])?$_POST['file_data_id']:die('Pilih file yang akan di prosses');; // get the requested page 
		  $xmldoc =  XMLbasic('json');  
		AddField($xmldoc ,'file_data_id',$file_data_id);
		$str = $xmldoc->saveXML();   
		exec_sp_array($xmldoc, 'dbo.SPX_FILE_SA_BC41_PROSSES',$sts,$des,$rows,$detail); 
		echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
}
		function delete_file_bc25(){
		        $file_data_id = isset($_POST['file_data_id'])?$_POST['file_data_id']:die('Pilih file yang akan di prosses');; // get the requested page 
		  		$xmldoc =  XMLbasic('json');  
				AddField($xmldoc ,'file_data_id',$file_data_id);
				$str = $xmldoc->saveXML();   
				exec_sp_array($xmldoc, 'dbo.SP_T_FILE_SA_BC25_DELETE',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}

		function delete_file_bc27(){
			$file_data_id = isset($_POST['file_data_id'])?$_POST['file_data_id']:die('Pilih file yang akan di prosses');; // get the requested page 
			  $xmldoc =  XMLbasic('json');  
			AddField($xmldoc ,'file_data_id',$file_data_id);
			$str = $xmldoc->saveXML();   
			exec_sp_array($xmldoc, 'dbo.SP_T_FILE_SA_BC27_DELETE',$sts,$des,$rows,$detail); 
			echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
	}
		
	   function upload_file(){
	   
		$config['overwrite'] = false;
		$config['upload_path'] = './loaderfiles/masterdata/';
		$config['allowed_types'] = '*'; 
		$this->load->library('upload', $config); 
		$this->upload->initialize($config);   
		if ($this->upload->do_upload('file')) { 
			$uploaded = $this->upload->data();   
			$xmldoc =XMLbasic('SP_T_FILE_SA_ADD');  
			$testarr_keys = array_keys($uploaded);
			$testarr_values = array_values($uploaded); 
			$namafile='';
			for ($i = 0; $i <= count($uploaded) - 1; $i++) {
				AddField($xmldoc ,'i_'.$testarr_keys[$i],$testarr_values[$i]);  
				if ($testarr_keys[$i]=='full_path')
					$namafile=$testarr_values[$i];
			}  
			exec_sp_array($xmldoc,'SP_T_FILE_SA_ADD',$stsno,$stsmsg,$rows,$detail);  
			echo json_encode(array('valid'=>($stsno=='00'?true:false),'stsno' => $stsno, 'stsmsg' => $stsmsg));
			@unlink($namafile);
		} else {  
			echo json_encode(array('valid'=>false,'stsno'=>'99','stsmsg'=>$this->upload->display_errors()));
		}	
		   
	    
		//  @unlink($_FILES[$file_element_name]);
	   
	} 
 }