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

class ViewPopupPenempatanAset extends HtmlResponse {

	function TemplateModule()
   {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/gedung/template');
		$this->SetTemplateFile('popup_penempatan_aset.html');
	}
	
	function TemplateBase() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      $this->SetTemplateFile('document-common.html');
      $this->SetTemplateFile('layout-common-popup.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new AppInventarisasi();
  
      $keyword = '';
      $lokasi = '2';
		
      if (!empty($_POST['keyword']) || !empty($_POST['lokasi']))
      {
         $keyword = $_POST['keyword']->Raw();
         $lokasi = $_POST['lokasi']->Raw();
      }
      elseif (isset($_GET['cari']))
         list($keyword, $lokasi) = explode('|', Dispatcher::Instance()->Decrypt($_GET['cari']->Raw()));
      $return['cari'] = array
      (
         'keyword' => $keyword,
         'lokasi' => $lokasi
      );
      $cari = Dispatcher::Instance()->Encrypt(implode('|',$return['cari']));
      
      //PAGING
   	$itemViewed = 20;
   	$currPage = 1;
   	$startRec = 0;
   	
   	if(isset ($_GET['page'])){
   		$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
   		$startRec = ($currPage - 1) * $itemViewed;
   	}

   	$return['data'] = $Obj->GetDataPenempatanAset($keyword, $lokasi, $startRec, $itemViewed);
   	$totalData = $Obj->GetDataPenempatanAsetCount();

	  	$url = Dispatcher::Instance()->GetUrl(
	  		Dispatcher::Instance()->mModule, 
	  		Dispatcher::Instance()->mSubModule, 
	  		Dispatcher::Instance()->mAction, 
	  		Dispatcher::Instance()->mType . '&cari=' . Dispatcher::Instance()->Encrypt($cari)
	  	);
	  	
	  	Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'lokasi', array('lokasi', $Obj->GetComboIsIsi(), $lokasi, 'true', ''), Messenger::CurrentRequest);
	  	
		Messenger::Instance()->SendToComponent('paging', 'paging', 'view', 'html', 'paging_top', array($itemViewed, $totalData, $url, array($currPage, $filter['keyword']), 'popup-subcontent'), Messenger::CurrentRequest);
	  
		$return['startRec'] = $startRec;
   	$return['cari']['keyword'] = $keyword;

      // inisialisasi link address
      $_GET = $_GET->AsArray();
      if($_GET['ruangId']){
      	$_GET['id'] = $_GET['ruangId'];
      }
      $return['link']['url_search'] = Dispatcher::Instance()->GetUrl('gedung', 'popupPenempatanAset', 'view', 'html')."&ruangId=".$_GET['id']."&gedungId=".$_GET['gedungId']."&lantaiId=".$_GET['lantaiId']."&kampusId=".$_GET['kampusId'];
      $return['link']['url_add'] = Dispatcher::Instance()->GetUrl('gedung', 'addPenempatanAset', 'do', 'html')."&ruangId=".$_GET['id']."&gedungId=".$_GET['gedungId']."&lantaiId=".$_GET['lantaiId']."&kampusId=".$_GET['kampusId'];
      return $return;
   }
   
	function ParseTemplate($data = NULL)
   {      
      $link = $data['link'];
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', $link['url_search']);
      $this->mrTemplate->AddVar('content', 'URL_ADD', $link['url_add']);
      
      // Render filter box
      $this->mrTemplate->AddVars('content', $data['cari'], '');
      
      if (!is_array($data['data']) OR count($data['data']) == 0)
         return $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
      else $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
      
      // render data sheet
      $i = $data['startRec'] + 1;
      $len = sizeof($data['data']);
      foreach ($data['data'] as $key => $value)
      {
         $data = $value;
         $data['number'] = $i;
         
         if($key == 0) $this->mrTemplate->AddVar('content','FIRST_NUMBER',$i); //untuk keperluan checkedall
			if($key == ($len - 1)) $this->mrTemplate->AddVar('content','LAST_NUMBER',$i);
				
         $data['class_name'] = ($i % 2 == 0) ? '' : 'table-common-even';
  			$data['lokasi'] = str_replace(array(' ','@@'),array('&nbsp;', ' &raquo;&nbsp;'),$data['lokasi']);       
         $this->mrTemplate->AddVars('data_item', $data, '');
         $this->mrTemplate->parseTemplate('data_item', 'a');
         $i++;
      }
   }
}
?>
