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

class ViewLaporanInvTanah extends HtmlResponse {

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

   function ProcessRequest() {
		
		$Obj = new LaporanInventarisasiTanah;
      
      $filter = array();
		if (isset($_POST['keyword'])) $filter = $_POST->AsArray();
		
		if (!empty($filter))
      {
         $filter['tahun'] = $filter['tahun'];
         $filter['keyword'] = $filter['keyword'];
      } else {	
			$filter['tahun'] = date('Y');
			$filter['keyword'] = '';
		}
		
		for($i=0; $i <= 20; $i++){
			$tanggal[] = array(
				'id' => date('Y')-$i,
				'name' => date('Y')-$i
			);
		}
		
      
      //PAGING
   	$itemViewed = 10000;
   	$currPage = 1;
   	$startRec = 0;
   	
   	if(isset ($_GET['page'])){
   		$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
   		$startRec = ($currPage - 1) * $itemViewed;
   	}
   	
   	$return['data'] = $Obj->GetInventarisasiTanah($filter, $startRec, $itemViewed);
   	//$totalData = $Obj->GetInventarisasiTanahCount();
	  
	  	Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'tahun', array('tahun', $tanggal, $filter['tahun'], "false", ''), Messenger::CurrentRequest);
	  
		$return['startRec'] = $startRec;
   	$return['cari'] = $filter;
      $return['link']['url_search'] = Dispatcher::Instance()->GetUrl('laporan_inventarisasi_tanah', 'laporanInvTanah', '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']);
		$urlCetak = Dispatcher::Instance()->GetUrl('laporan_inventarisasi_tanah', 'printLaporanInvTanah', 'view', 'html').'&keyword='.$data['cari']['keyword'].'&tahun='.$data['cari']['tahun'];
		
		$this->mrTemplate->AddVar('content','URL_CETAK', $urlCetak);
      
      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',',','.');
         $this->mrTemplate->AddVars('data_item', $data, '');
         $this->mrTemplate->parseTemplate('data_item', 'a');
         $i++;
      }
   }
}
?>
