<?php class CT_ms_setting_report_car_line 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('ms_master/view_ms_setting_report_car_line');
	} 
	
	function view_new_item(){	
 		$this->load->view('ms_master/view_ms_setting_report_car_line_new');
	} 
	
	function view_edit_item(){
		$row_data=isset($_POST['row_data'])?$_POST['row_data']:null; 
		$data['x'] ='';
		if   (empty($row_data)==false ) {
			$data['row_data'] =$row_data;
		 
		}  
 		$this->load->view('ms_master/view_ms_setting_report_car_line_new',$data);
	}  
	function view_base_part_import(){
		$row_data=isset($_POST['row_data'])?$_POST['row_data']:null; 
		$data['x'] ='';
		if   (empty($row_data)==false ) {
			$data['row_data'] =$row_data;
		 
		}  
 		$this->load->view('ms_master/view_ms_setting_report_car_line_import_base_part',$data);
	} 
	 	 
			 
    function loaddata(){; 
		$def_col= array();    
		
		$spt='dbo.MG_MS_SETTING_REPORT_CAR_LINE'; 
		$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2i']=array("db" => "r2i" ,"sc" => "r2i","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"-100");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
		
 		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
	 	 
        $page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rID'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 
  	  
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		  
		$xmldoc =  XMLbasic($spt); 
		paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
  	//	AddField($xmldoc ,'ms_type_id',$ms_type_id); 
		 
        if ($search == 'true'){ 
            if (!empty($filters)){ 
				$array = json_decode($filters); 
                foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
	 					if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue'])  
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1');  
			 					  
							} 
							elseif ($fcr['ctype']=='text'){ 
					        	$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
							     addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
                 } 
             } 
	   }  
  
  
		$str = $xmldoc->saveXML();   
		// print_r($str);die();
		 wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		
			 
    function loaddata_base_part(){; 
		$def_col= array();    
		
		$spt='dbo.MG_MS_SETTING_REPORT_CAR_LINE_LIST_BASE_PART'; 
		$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"int", "bypassvalue"=>"");
		
 		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
	 	 
        $page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rID'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 
  	  
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		
		$ms_report_car_line_sum_id =  isset($_POST['ms_report_car_line_sum_id'])?$_POST['ms_report_car_line_sum_id']:'-1'; 
	    
		$xmldoc =  XMLbasic($spt); 
		paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
  	 	AddField($xmldoc ,'ms_report_car_line_sum_id',$ms_report_car_line_sum_id); 
		 
        if ($search == 'true'){ 
            if (!empty($filters)){ 
				$array = json_decode($filters); 
                foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
	 					if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue'])  
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1');  
			 					  
							} 
							elseif ($fcr['ctype']=='text'){ 
					        	$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
							     addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
                 } 
             } 
	   }  
  
  
		$str = $xmldoc->saveXML();   
		// print_r($str);die();
		 wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
			
    function loaddata_base_part_for_import(){; 
		$def_col= array();    
		
		$spt='dbo.MG_MS_BASE_PART_FOR_IMPORT_REPORT_CAR_LINE'; 
		$def_col['rID']=array("db" => "rID" ,"sc" => "rID","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r1']=array("db" => "r1" ,"sc" => "r1","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r2']=array("db" => "r2" ,"sc" => "r2","ctype"=>"int", "bypassvalue"=>"-100");
		$def_col['r3']=array("db" => "r3" ,"sc" => "r3","ctype"=>"int", "bypassvalue"=>"");
		$def_col['r4']=array("db" => "r4" ,"sc" => "r4","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r5']=array("db" => "r5" ,"sc" => "r5","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r6']=array("db" => "r6" ,"sc" => "r6","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r7']=array("db" => "r7" ,"sc" => "r7","ctype"=>"text", "bypassvalue"=>"");
		$def_col['r8']=array("db" => "r8" ,"sc" => "r8","ctype"=>"date", "bypassvalue"=>"");
		$def_col['r9']=array("db" => "r9" ,"sc" => "r9","ctype"=>"text", "bypassvalue"=>"");
 
 		$search = isset($_POST['_search'])?$_POST['_search']:false; 
		$searchField = isset($_POST['searchField'])?$_POST['searchField']:''; 
		$searchString = isset($_POST['searchString'])?$_POST['searchString']:''; 
		$filters =  isset($_POST['filters'])?$_POST['filters']:''; 
	 	 
        $page = isset($_POST['page'])?$_POST['page']:1; // get the requested page 
		$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid 
		$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rID'; // get index row - i.e. user click to sort 
		$sord = isset($_POST['sord'])?$_POST['sord']:'0'; // get the direction 
  	  
		if ($sord == 'asc') { $sord = '0'; } else if ($sord == 'desc') { $sord = '1'; } 
 		 
		if (array_key_exists($sidx, $def_col)) {  
				$fsidx=$def_col[$sidx];
				$sidx=$fsidx['db'];
		}else{
				$sidx='rID'; //DEFAULT SORT KALU GA ADA
		}
        $sidx=$sidx.'='. $sord;
		$ms_report_car_line_sum_id = isset($_POST['ms_report_car_line_sum_id'])?$_POST['ms_report_car_line_sum_id']:'-1'; // get the direction 
  	  
		  
		$xmldoc =  XMLbasic($spt); 
		paramViewJSON($xmldoc, $limit, $page,  $sidx, $sord); 
		AddField($xmldoc ,'ms_report_car_line_sum_id',$ms_report_car_line_sum_id); 
		//	AddField($xmldoc ,'ms_type_id',$ms_type_id); 
		 
        if ($search == 'true'){ 
            if (!empty($filters)){ 
				$array = json_decode($filters); 
                foreach($array->rules as $arr=>$k){ 
						$fcr=$def_col[$k->field]; 
	 					if ($fcr != null) 
						{ 
							if ($fcr['ctype']=='int'){ 
								$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue'])  
									addSearchNum($xmldoc,$fcr['sc'],$searchString,'2','1');  
			 					  
							} 
							elseif ($fcr['ctype']=='text'){ 
					        	$searchString = $k->data; 
								if ($searchString!=$fcr['bypassvalue']) 
							     addSearchText($xmldoc,$fcr['sc'],'1','1',$searchString); 
							}  
							elseif ($fcr['ctype']=='date'){ 
								$searchString = $k->data; 
								if (trim($searchString) != '' ){ 
									$dateArray=explode('/',$searchString);  
									$searchString = $dateArray[2].$dateArray[1].$dateArray[0]; 
								} 
								 addSearchDate($xmldoc,$fcr['sc'],$searchString,'1','1'); 
							}  
						} 
                 } 
             } 
	   }  
  
  
		$str = $xmldoc->saveXML();   
		// print_r($str);die();
		 wh_exec_sp_json($xmldoc, $spt,$sts,$des,$rows,$detail);  
  		echo $rows; 
		}
		
		
	    function new_item(){  
	 	       $ms_report_car_line_sum_name = isset($_POST['ms_report_car_line_sum_name'])?$_POST['ms_report_car_line_sum_name']:''; // get the requested page 
	  	       $ms_report_car_line_sum_color = isset($_POST['ms_report_car_line_sum_color'])?$_POST['ms_report_car_line_sum_color']:''; // get the requested page 
	  	        $code_sheet = isset($_POST['code_sheet'])?$_POST['code_sheet']:''; // get the requested page 
	  	       $show_on_report = isset($_POST['show_on_report'])?$_POST['show_on_report']:'0'; // get the requested page 
	  	       $order_column = isset($_POST['order_column'])?$_POST['order_column']:'-1'; // get the requested page 
	  	   	     
				
				$xmldoc =  XMLbasic('json'); 
		 		AddField($xmldoc ,'ms_report_car_line_sum_name',$ms_report_car_line_sum_name );
		 		AddField($xmldoc ,'ms_report_car_line_sum_color',$ms_report_car_line_sum_color );
		 		AddField($xmldoc ,'show_on_report',$show_on_report ); 
				AddField($xmldoc ,'order_column',$order_column ); 
				AddField($xmldoc ,'code_sheet',$code_sheet ); 
				
				
				$str = $xmldoc->saveXML();
			 	// print_r($str);die();
				 wh_exec_sp_array($xmldoc, 'dbo.MG_MS_SETTING_REPORT_CAR_LINE_ADD',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false)
				,'stsno' => $sts
				, 'stsmsg' => $des
				, 'detail' => $detail)
				); 
		}  
		
	    function edit_item(){  
	 	       $ms_report_car_line_sum_id = isset($_POST['ms_report_car_line_sum_id'])?$_POST['ms_report_car_line_sum_id']:''; // get the requested page 
				$ms_report_car_line_sum_name = isset($_POST['ms_report_car_line_sum_name'])?$_POST['ms_report_car_line_sum_name']:''; // get the requested page 
	  	       $ms_report_car_line_sum_color = isset($_POST['ms_report_car_line_sum_color'])?$_POST['ms_report_car_line_sum_color']:''; // get the requested page 
	  	       $show_on_report = isset($_POST['show_on_report'])?$_POST['show_on_report']:'0'; // get the requested page 
	  	       $order_column = isset($_POST['order_column'])?$_POST['order_column']:'-1'; // get the requested page 
			   $code_sheet = isset($_POST['code_sheet'])?$_POST['code_sheet']:''; // get the requested page 
	  	    
				$xmldoc =  XMLbasic('json'); 
		 		AddField($xmldoc ,'ms_report_car_line_sum_id',$ms_report_car_line_sum_id );
		 		AddField($xmldoc ,'ms_report_car_line_sum_name',$ms_report_car_line_sum_name );
		 		AddField($xmldoc ,'ms_report_car_line_sum_color',$ms_report_car_line_sum_color );
		 		AddField($xmldoc ,'show_on_report',$show_on_report ); 
				AddField($xmldoc ,'order_column',$order_column ); 
				AddField($xmldoc ,'code_sheet',$code_sheet ); 
				
						$str = $xmldoc->saveXML();
			 	// print_r($str);die();
				 wh_exec_sp_array($xmldoc, 'dbo.MG_MS_SETTING_REPORT_CAR_LINE_EDIT',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false)
				,'stsno' => $sts
				, 'stsmsg' => $des
				, 'detail' => $detail)
				); 
		}  
		
				
	    function delete_item(){  
 	 	       $ms_report_car_line_sum_id = isset($_POST['ms_report_car_line_sum_id'])?$_POST['ms_report_car_line_sum_id']:''; // get the requested page 
 	  	 
				$xmldoc =  XMLbasic('json'); 
 		 		AddField($xmldoc ,'ms_setting_report_car_line_no',$ms_setting_report_car_line_no );
 				$str = $xmldoc->saveXML();
			 	// print_r($str);die();
				 wh_exec_sp_array($xmldoc, 'dbo.MG_MS_SETTING_REPORT_CAR_LINE_DELETE',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false)
				,'stsno' => $sts
				, 'stsmsg' => $des
				, 'detail' => $detail)
				); 
		}  
		
		function import_data_base_part(){
	 	       $ms_report_car_line_sum_id = isset($_POST['ms_report_car_line_sum_id'])?$_POST['ms_report_car_line_sum_id']:'-1'; // get the requested page 
 	  	       $lst = isset($_POST['lst'])?$_POST['lst']:die('pilih Basepart ');; // get the requested page 
	 	 
				$xmldoc =  XMLbasic('json'); 
			 	AddField($xmldoc ,'ms_report_car_line_sum_id',$ms_report_car_line_sum_id); 
			 	
				for ($i = 0; $i <  count($lst); $i++) {
				    $this->_insert_id_to_field($xmldoc,$lst[$i]);
				} 
				$str = $xmldoc->saveXML();  
				 wh_exec_sp_array($xmldoc, 'dbo.MG_MS_SETTING_REPORT_CAR_LINE_LIST_BASE_PART_IMPORT',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
		function move_data_base_part(){
	 	       $ms_report_car_line_sum_id = isset($_POST['ms_report_car_line_sum_id'])?$_POST['ms_report_car_line_sum_id']:'-1'; // get the requested page 
 	  	       $lst = isset($_POST['lst'])?$_POST['lst']:die('pilih Basepart ');; // get the requested page 
	 	 
				$xmldoc =  XMLbasic('json'); 
			 	AddField($xmldoc ,'ms_report_car_line_sum_id',$ms_report_car_line_sum_id); 
			 	
				for ($i = 0; $i <  count($lst); $i++) {
				    $this->_insert_id_to_field($xmldoc,$lst[$i]);
				} 
				$str = $xmldoc->saveXML();  
				 wh_exec_sp_array($xmldoc, 'dbo.MG_MS_SETTING_REPORT_CAR_LINE_LIST_BASE_PART_MOVE_TO',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
		function remove_data_base_part(){
	 	        $lst = isset($_POST['lst'])?$_POST['lst']:die('pilih Basepart ');; // get the requested page 
	 	 
				$xmldoc =  XMLbasic('json'); 
				AddField($xmldoc ,'ms_report_car_line_sum_id','-1'); 
			 	
				for ($i = 0; $i <  count($lst); $i++) {
				    $this->_insert_id_to_field($xmldoc,$lst[$i]);
				} 
				$str = $xmldoc->saveXML();  
				// print_r($str);die();
				 wh_exec_sp_array($xmldoc, 'dbo.MG_MS_SETTING_REPORT_CAR_LINE_LIST_BASE_PART_REMOVE',$sts,$des,$rows,$detail); 
				echo json_encode(array('valid'=>($sts=='00'?true:false),'stsno' => $sts, 'stsmsg' => $des)); 
		}
		
		function _insert_id_to_field($doc,$id){
			$param = $doc->getElementsByTagName('param')->item(0);
			$field = $param->getElementsByTagName('field')->item(0);
			$lst = $doc->createElement("lst","");
			$field->appendChild($lst); 
			$tmp = $doc->createElement("id",$id);
			$lst->appendChild($tmp); 
		}
				
				
		
 }