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

class CT_operator_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');
        }
		
		$this->load->model("production/mdl_production", 'mdl_production');
		
    }
    
    
    function index()
    {
        $this->load->view('pasi_operator/view_operator');
    }


    function save_operator(){  
        $nama_operator        = isset($_POST['nama_operator'])?$_POST['nama_operator']:'-1'; // get the requested page 
  


        $xmldoc =  XMLbasic('json'); 
         AddField($xmldoc ,'nama_operator',$nama_operator ); 
        AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

        $str = $xmldoc->saveXML();
        //  print_r($str);die();
        exec_sp_array($xmldoc, 'dbo.SPX_OPERATOR_ADD',$sts,$des,$rows,$detail); 
        echo json_encode(array('valid'=>($sts=='00'?true:false)
        ,'stsno' => $sts
        , 'stsmsg' => $des
        , 'detail' => $detail)
        ); 
}


function edit_operator(){  
    $id_operator       = isset($_POST['id_operator'])?$_POST['id_operator']:''; // get the requested page 
     $nama_operator        = isset($_POST['nama_operator'])?$_POST['nama_operator']:''; // get the requested page 
  


    $xmldoc =  XMLbasic('json'); 
    AddField($xmldoc ,'id_operator',$id_operator ); 
     AddField($xmldoc ,'nama_operator',$nama_operator ); 
  
    AddField($xmldoc,'data_by',$this->session->userdata('DX_user_id'));

    $str = $xmldoc->saveXML();
     // print_r($str);die();
    exec_sp_array($xmldoc, 'dbo.SPX_OPERATOR_EDIT',$sts,$des,$rows,$detail); 
    echo json_encode(array('valid'=>($sts=='00'?true:false)
    ,'stsno' => $sts
    , 'stsmsg' => $des
    , 'detail' => $detail)
    ); 
}


function delete_operator(){  
$id_operator = isset($_POST['id_operator'])?$_POST['id_operator']:'-1'; // get the requested page 

$xmldoc =  XMLbasic('json'); 
 AddField($xmldoc ,'id_operator',$id_operator ); 
     
$str = $xmldoc->saveXML();
 // print_r($str);die();
 exec_sp_array($xmldoc, 'dbo.SPX_OPERATOR_DELETE',$sts,$des,$rows,$detail); 
echo json_encode(array('valid'=>($sts=='00'?true:false)
,'stsno' => $sts
, 'stsmsg' => $des
, 'detail' => $detail)
); 
}  




}


?>