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

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

class ViewPopupAset 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/gedung/template');
      $this->SetTemplateFile('popup_aset.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new AppGedungPopUpAset;
      $msg = Messenger::Instance()->Receive(__FILE__);
      $post = $_POST->AsArray();

      if(!empty($post['key']))
         $key = $post['key'];
      else
         $key = '';
         
      if(isset($_GET['cari'])) {
         $get_data = $_GET->AsArray();
         $key = $get_data['key'];
      }
      $itemViewed = 20;
      $currPage = 1;
      $startRec = 0 ;
      if(isset($_GET['page'])) {
         $currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();  
         $startRec =($currPage-1) * $itemViewed;
      }
      
      $totalData = $Obj->GetCount($key);
      $data_list = $Obj->GetData($key, $startRec,$itemViewed);
      
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . 	
	 '&key=' . Dispatcher::Instance()->Encrypt($key) . 
      '&cari=' . Dispatcher::Instance()->Encrypt(1));
	  $dest = "popup-subcontent";
      Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed,$totalData, $url, $currPage, $dest), Messenger::CurrentRequest);
      
      
      $return['aset'] = $data_list;
      $return['start'] = $startRec+1;
      $return['key'] = $key;
      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 filter($string){
		return addslashes($string);
	}
	
   function ParseTemplate($data = NULL)
   {
      //set Label
      $this->TemplateLabeling();
	  
      $search = $data['search'];
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('gedung', 'PopUpAset', 'view', 'html'));
		
      $this->mrTemplate->AddVar('content', 'CARI_NAMA_BARANG', $data['key']);
      if (empty($data['aset'])) {
         $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
      } else {
         $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
         for($i=0; $i<count($data['aset']); $i++) {
            $no = $i+$data['start'];
            if($no % 2 != 0)
               $this->mrTemplate->AddVar("data_item", "CLASS_NAME", 'table-common-even');
            else
				
				$data['aset'][$i]['nama'] = $this->filter($data['aset'][$i]['nama']);
				
               $this->mrTemplate->AddVar("data_item", "CLASS_NAME", '');
            $this->mrTemplate->AddVar("data_item", "NOMOR", $no);
            $this->mrTemplate->AddVar("data_item", "KODE", $data['aset'][$i]['kode']);
            $this->mrTemplate->AddVar("data_item", "NAMA", $data['aset'][$i]['nama']);
            $this->mrTemplate->AddVar("data_item", "BARANG_ID", $data['aset'][$i]['barang_id']);
            $this->mrTemplate->parseTemplate("data_item", "a");
         }
      }
   }
}
?>