<?php

/*
 @ClassName : View Laporan DIRs
 @Copyright : PT Gamatechno Indosnesia
 @Analyzed By : Nanang Ruswianto <nanang@gamatechno.com>
 @Designed By : Rosyid <rosyid@gamatechno.com>
 @Author By : Dyan Galih <galih@gamatechno.com>
 @Version : 1.0
 @StartDate : Nov 11, 2008
 @LastUpdate : Nov 11, 2008
 @Description :
*/

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/laporan_dir/business/AppLaporanDir.class.php';
//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .
'module/label/response/Label.proc.class.php';
class ViewLaporanDir extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/laporan_dir/template');
      $this->SetTemplateFile('view_laporan_dir.html');
   }
   
   function TemplateLabeling(){
      $ObjLabel = new GetModuleLabel();
      $arrLabel = $ObjLabel->GetLabel();
      
      //patTemplate name yang memiliki label2 dinamic
      $arrContent=array("content");
      
      for($i=0;$i<count($arrContent);$i++){
         for($j=0;$j<count($arrLabel);$j++){
            $this->mrTemplate->AddVar($arrContent[$i],$arrLabel[$j]['labelCode'],$arrLabel[$j]['labelName']);
         }
      }
   }
   
   function ProcessRequest() {
      $Obj = new AppLaporanDir();
      $User = $Obj->GetDataUserByUsername($_SESSION['username']);
		
      //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', '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', 'laporanDir', 'print', 'html').'&gedung='.$gedung.'&pj='.$pj;
      $this->mrTemplate->addVar('content','URL_CETAK',$urlPrint);
      $urlExcel = Dispatcher::Instance()->GetUrl('laporan_dir', 'ExcelLaporanDir', 'view', 'xls').'&gedung='.$gedung.'&pj='.$pj;
      $this->mrTemplate->addVar('content','URL_EXCEL',$urlExcel);
      
      //set Label
      $this->TemplateLabeling();
      
      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');
			}

   }
}
?>
