<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot').
   'module/'.Dispatcher::Instance()->mModule.'/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/'.Dispatcher::Instance()->mModule.'/template');
      $this->SetTemplateFile('pop_up_barang.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new Barang;
      
      if($_POST || isset($_GET['cari'])) {
			if(isset($_POST['kodeBarang'])) {
				$kodeBarang = $_POST['kodeBarang'];
				$namaBarang =$_POST['namaBarang'];
			} elseif(isset($_GET['kodeBarang'])) {
				$kodeBarang = Dispatcher::Instance()->Decrypt($_GET['kodeBarang']);
				$namaBarang = Dispatcher::Instance()->Decrypt($_GET['namaBarang']);
			} else {
				$kodeBarang = '';
				$namaBarang = '';
			}
		}
         
      // Inisialisasi komponen paging
      //$totalData = $Obj->GetDataBarangCount($kodeBarang, $namaBarang);
      $itemViewed = 10;
      $currPage = 1;
      if (isset($_GET['page'])) $currPage = $_GET['page']->Integer()->Raw();
      if ($currPage < 1) $currPage = 1;
      $startRec = ($currPage-1) * $itemViewed;
      
      $return['barang'] = $Obj->GetDataBarang($kodeBarang,$namaBarang,  $startRec, $itemViewed);
      $totalData = $Obj->GetCount();
      
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . '&cari=' . Dispatcher::Instance()->Encrypt(1). '&kodeBarang=' . Dispatcher::Instance()->Encrypt($kodeBarang). '&namaBarang=' . Dispatcher::Instance()->Encrypt($namaBarang));
	  Messenger::Instance()->SendToComponent('paging', 'paging', 'view', 'html', 'paging_top', array($itemViewed, $totalData, $url, array($currPage, $filter['keyword']), 'popup-subcontent'), Messenger::CurrentRequest);
	  
      $return['start'] = $startRec+1;
      // ---------
      
      $return['kodeBarang'] = $kodeBarang;
	  $return['namaBarang'] = $namaBarang;
      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();
      
      // url search
      $this->mrTemplate->AddVar('content', 'URL_SEARCH',  Dispatcher::Instance()->GetUrl('perbaikan_barang', 'barang', 'popup', 'html'));
      // ---------
      
      // Render filter box
      $this->mrTemplate->AddVar('content','KODEBARANG',$data['kodeBarang']);
	  $this->mrTemplate->AddVar('content','NAMABARANG',$data['namaBarang']);
      // ---------

      // 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++;
		}
      // ---------
   }
}
?>
