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

class ViewPopupInventarisasiTanah extends HtmlResponse {

	function TemplateModule()
   {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/inventarisasi_tanah/template');
		$this->SetTemplateFile('popup_inventarisasi_tanah.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 InventarisasiTanah;
      
      $keyword = '';
		
      if (isset($_POST['keyword']))
      {
         $keyword = $_POST['keyword']->Raw();
      }
      elseif (isset($_GET['cari']))
         list($keyword) = explode('|', Dispatcher::Instance()->Decrypt($_GET['cari']->Raw()));
      $return['cari'] = array
      (
         'keyword' => $keyword
      );
      $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->GetPopupInventarisasiTanah($keyword, $startRec, $itemViewed);
   	$totalData = $Obj->GetPopupInventarisasiTanahCount();

	  	$url = Dispatcher::Instance()->GetUrl(
	  		Dispatcher::Instance()->mModule, 
	  		Dispatcher::Instance()->mSubModule, 
	  		Dispatcher::Instance()->mAction, 
	  		Dispatcher::Instance()->mType . '&cari=' . Dispatcher::Instance()->Encrypt($cari)
	  	);
	  	
		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
      $return['link']['url_search'] = Dispatcher::Instance()->GetUrl('inventarisasi_tanah', 'popupInventarisasiTanah', 'view', 'html');
      return $return;
   }
   
	function ParseTemplate($data = NULL)
   {      
      $link = $data['link'];
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', $link['url_search']);
      
      // 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;
      foreach ($data['data'] as $value)
      {
         $data = $value;
         $data['number'] = $i;
         $data['class_name'] = ($i % 2 == 0) ? '' : 'table-common-even';
         $this->mrTemplate->AddVars('data_item', $data, '');
         $this->mrTemplate->parseTemplate('data_item', 'a');
         $i++;
      }
   }
}
?>
