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

	class ViewInventarisasiTanah extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/inventarisasi_tanah/template');
      $this->SetTemplateFile('view_inventarisasi_tanah.html');
   }

   function ProcessRequest() {
		$Obj = new InventarisasiTanah;
      
		$msg = Messenger::Instance()->Receive(__FILE__);
      $this->Data = $msg[0][0];
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
      
      $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->GetInventarisasiTanah($keyword, $startRec, $itemViewed);
   	$totalData = $Obj->GetInventarisasiTanahCount();

	  	$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']), 'subcontent'), Messenger::CurrentRequest);
	  
		$return['startRec'] = $startRec;
   	$return['cari']['keyword'] = $keyword;
      $return['link']['url_search'] = Dispatcher::Instance()->GetUrl('inventarisasi_tanah', 'inventarisasiTanah', 'view', 'html');
      return $return;
   }

   function ParseTemplate($data = NULL) {
   	if($this->Pesan)
      {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $this->Pesan);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $this->css);
		}
   
   	$link = $data['link'];
   	$this->mrTemplate->AddVars('content', $data['cari'], '');
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', $link['url_search']);
		
		$urlInput = Dispatcher::Instance()->GetUrl('inventarisasi_tanah', 'inputInventarisasiTanah', 'view', 'html');
		$urlDelete = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').
         "&urlDelete=".Dispatcher::Instance()->Encrypt('inventarisasi_tanah|deleteInventarisasiTanah|do|html').
         "&urlReturn=".Dispatcher::Instance()->Encrypt('inventarisasi_tanah|inventarisasiTanah|view|html').
         "&label=".Dispatcher::Instance()->Encrypt('Inventarisasi Tanah');
		
		$this->mrTemplate->AddVar('content','URL_INPUT', $urlInput);
      
      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');
      
      $i = $data['startRec'] + 1;
      foreach ($data['data'] as $value)
      {
         $data = $value;
         $data['number'] = $i;
         $data['class_name'] = ($i % 2 == 0) ? '' : 'table-common-even';
         $data['luas'] = number_format($data['luas'],'2',',','.');
         $data['url_edit'] = $urlInput.'&id='.$data['idTanah'];
         $data['url_delete'] = $urlDelete."&id=".Dispatcher::Instance()->Encrypt($data['idTanah']).
            "&dataName=".Dispatcher::Instance()->Encrypt($data['nama_aset']);
         $this->mrTemplate->AddVars('data_item', $data, '');
         $this->mrTemplate->parseTemplate('data_item', 'a');
         $i++;
      }
   }
}
?>
