<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/penguasaan_barang/business/PenguasaanBarang.class.php';

//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .
'module/label/response/Label.proc.class.php';

class ViewPenguasaanBarang extends HtmlResponse {
   
   protected $PenguasaanBarang;
   protected $data;
   
   function ViewPenguasaanBarang() {
     $this->PenguasaanBarang = new PenguasaanBarang();   
   }
   
   
   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/penguasaan_barang/template');
      $this->SetTemplateFile('view_penguasaan_barang.html');
   }
   
   function ProcessRequest() {  
	  
	        
      $itemViewed = 20;
      $currPage = 1;
      $startRec = 0 ;
	  
      if(isset($_GET['page'])) {
         $currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();  
         $startRec =($currPage-1) * $itemViewed;
      }
	  
	  
	  $totalData = $this->PenguasaanBarang->GetCount($this->data['search']);
	  $dataList = $this->PenguasaanBarang->GetData($startRec,$itemViewed, $this->data['search']);	  
	  
	
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
               Dispatcher::Instance()->mSubModule, 
               Dispatcher::Instance()->mAction, 
               Dispatcher::Instance()->mType
               );
			   
      Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', 
         array($itemViewed,$totalData, $url, $currPage), 
         Messenger::CurrentRequest); 
       
      $return['data'] = $dataList;
      $return['start'] = $startRec+1;	
	
      
	return $return;
   }
   
   function TemplateLabeling(){
      $ObjLabel = new GetModuleLabel();
      $arrLabel = $ObjLabel->GetLabel();
      
      //patTemplate name yang memiliki label2 dinamic
      $arrContent=array("content");
      
      for($i=0;$i<count($arrContent);$i++){
         for($j=0;$j<count($arrLabel);$j++){
            $this->mrTemplate->AddVar($arrContent[$i],$arrLabel[$j]['labelCode'],$arrLabel[$j]['labelName']);
         }
      }
   }
   
	function ParseTemplate($data = NULL)
   {
      //set Label
      $this->TemplateLabeling();
      
      if (empty($data['data'])) {
         $this->mrTemplate->AddVar('data_grid', 'IS_DATA_EMPTY', 'YES');
      } else {
         $this->mrTemplate->AddVar('data_grid', 'IS_DATA_EMPTY', 'NO');
         $dataGrid = $data['data'];		 
		 $nomor= $data['start'] ;
		//data sudah siap ditampilkan... kirim ke pat-template
		for($j=0;$j < sizeof($dataGrid);$j++) {	
           $dataGrid[$j]['nomor'] = $nomor;
		   $nomor++;
		   if(($j % 2) != 0)
		     $dataGrid[$j]['class_name']='';
		   else
		     $dataGrid[$j]['class_name']='table-common-even';			 
		  
		   $this->mrTemplate->AddVars('data_item', $dataGrid[$j], 'DATA_');
           $this->mrTemplate->parseTemplate('data_item', 'a');			   
		}
		
		
	}
	
   }
   
   
  
}
?>
