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

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

class PopupBarang extends HtmlResponse
{

	function TemplateBase()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      $this->SetTemplateFile('document-common-popup.html');
      $this->SetTemplateFile('layout-common-popup.html');
   }
   
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/popup/template');
      $this->SetTemplateFile('pop_up_barang.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new Barang;
      
      $cari = $_POST['kode_barang'];
      if(isset($_GET['lokasiId'])) $lokasiId = $_GET['lokasiId']; elseif(isset($_POST['lokasiId']))$lokasiId = $_POST['lokasiId']; 
      if(isset($_GET['unitId'])) $unitId = $_GET['unitId']; elseif(isset($_POST['unitId']))$unitId = $_POST['unitId']; 
      // Inisialisasi komponen paging
      $totalData = $Obj->GetDataBarangCount($cari,$lokasiId,$unitId);
      $itemViewed = 10;
      $currPage = 1;
      if (isset($_GET['page'])) $currPage = $_GET['page']->Integer()->Raw();
      if ($currPage < 1) $currPage = 1;
      $startRec = ($currPage-1) * $itemViewed;
      
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType) . '&cari=' . Dispatcher::Instance()->Encrypt($cari). '&unitId=' . Dispatcher::Instance()->Encrypt($unitId). '&lokasiId=' . Dispatcher::Instance()->Encrypt($lokasiId);
$dest = "popup-subcontent";
      Messenger::Instance()->SendToComponent('paging', 'paging', 'view', 'html', 'paging_top', array($itemViewed, $totalData, $url, $currPage, $dest), Messenger::CurrentRequest);
      $return['start'] = $startRec+1;
      // ---------
      $return['url']['search'] = Dispatcher::Instance()->GetUrl('popup','Barang','popup','html');
      $return['barang'] = $Obj->GetDataBarang($cari,$lokasiId, $unitId, $startRec, $itemViewed);
      $return['cari'] = $cari;
      $return['lokasiId'] = $lokasiId;
      $return['unitId'] = $unitId;
      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();
      
      // Render URL
      $this->mrTemplate->AddVars('content', $data['url'], 'URL_');
      // ---------
      
      // Render filter box
      $this->mrTemplate->AddVar('content','CARI_KODE_BARANG',$data['cari']);
      $this->mrTemplate->AddVar('content','LOKASI_ID',$data['lokasiId']);
      $this->mrTemplate->AddVar('content','UNIT_ID',$data['unitId']);
      // ---------

      // Render tabel data
      
      $gridList = $data['barang'];
      
     if (empty($gridList))
		{
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
			return;
		}
		else $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
     	
		$no = $data['start'];
      for($i=0;$i<count($gridList);$i++){
      	$gridList[$i]['number'] = $no;
			
      	$gridList[$i]['nama_barang'] = addslashes($gridList[$i]['nama_barang']);
      	
			$this->mrTemplate->addVars('data_item',$gridList[$i],'DATA_');
      	$this->mrTemplate->parseTemplate('data_item','a');
      	$no++;
		}
      // ---------
   }
}
?>
