<?php

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/laporan_dir/business/AppLaporanDir.class.php';

class ViewLaporanDir extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/laporan_dir_barcode/template');
      $this->SetTemplateFile('view_laporan_dir.html');
   }
   
   function ProcessRequest() {
      $Obj = new AppLaporanDir();
		
      //set combo gedung
      $arrComboGedung = $Obj->GetComboGedung();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'gedung', array('gedung', $arrComboGedung, $_POST['gedung'], true, 'onchange=\'setComboPj(this.value);\''), Messenger::CurrentRequest);
      
      $arrPic = $Obj->GetComboPic($_POST['gedung']);
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'pj', array('pj', $arrPic, $_POST['pj'], true, ''), Messenger::CurrentRequest);
      
      if(isset($_POST['cari'])){
         $return['data']= $Obj->getDataDir($_POST['gedung'],$_POST['pj']);
      }
      
      $return['gedung'] = $_POST['gedung'];
      $return['pj']=$_POST['pj'];
     
   	return $return;  
   }
   
   function ParseTemplate($data = NULL) {
   	
      $urlAction = Dispatcher::Instance()->GetUrl('laporan_dir_barcode', 'laporanDir', 'view', 'html');
      $this->mrTemplate->addVar('content','URL_ACTION',$urlAction);
      
      $gedung = Dispatcher::Instance()->Encrypt($data['gedung']);
      $pj = Dispatcher::Instance()->Encrypt($data['pj']);
      $urlPrint = Dispatcher::Instance()->GetUrl('laporan_dir_barcode', 'popupResize', 'view', 'html').'&gedung='.$gedung.'&pj='.$pj;
      $this->mrTemplate->addVar('content','URL_CETAK',$urlPrint);

      if(empty($data['data'])){
      	$this->mrTemplate->AddVar('data','DATA_EMPTY','YES');
      	return;
		}else
			$this->mrTemplate->AddVar('data','DATA_EMPTY','NO');
			
			$dataGrid = $data['data'];
			$no = 1;
			
			for($i=0;$i<count($dataGrid);$i++){
				$dataGrid[$i]['no'] = $no+$i;
				
				$this->mrTemplate->AddVars('data_item',$dataGrid[$i],'DIR_');
				$this->mrTemplate->parseTemplate('data_item','a');
			}

   }
}
?>
