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

//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .
'module/label/response/Label.proc.class.php';

class ViewInventarisRuang extends HtmlResponse {
	function TemplateModule()
   {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/gedung/template');
		$this->SetTemplateFile('view_inventaris_ruang.html');
	}
   
   function ProcessRequest()
   {
      $Obj = new Ruang;
      $gId = $Obj->gId;
      
      if ($gId !== false AND isset($_GET['id']))
      {
         $result = $Obj->GetDataRuangById($_GET['id']->Integer()->Raw());
         if ($result)
         {
            $result['inventaris'] = $Obj->GetInventarisByRuangId($_GET['id']->Integer()->Raw());
            $return['data'] = $result;
            $return['list_inventaris'] = $Obj->GetListInventarisByRuangId($_GET['id']->Integer()->Raw());
         }
         else $gId = false;
      }
      
      if ($gId === false OR !isset($_GET['id']))
      {
         $urlRedirect = Dispatcher::Instance()->GetUrl('gedung','gedung','view','html');
         if (isset($_GET['ascomponent']) AND $_GET['ascomponent']->Raw())
            $urlRedirect .= '&ascomponent=1';
         $this->RedirectTo($urlRedirect);
         return null;
      }
      
      // inisialisasi messaging
		$msg = Messenger::Instance()->Receive(__FILE__);
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
      // ---------
      
      // inisialisasi link address
      $return['link']['url_back'] = Dispatcher::Instance()->GetUrl('gedung', 'listRuang', 'view', 'html').'&lantaiId='.$_GET['lantaiId'];
      // ---------
      
      // inisialisasi data lain
      #$return['konstruksiRuangList'] = $Obj->GetKonstruksiRuangList();
      #$return['comboJnsKonstruksi'] = $Obj->ComboJnsKonstruksi();
      // ---------
      
      return $return;
   }
   
   
   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 ParseTemplate($data = NULL)
   {
      if ($data === null) return;
      //set Label
      $this->TemplateLabeling();
      // render message box
      if($this->Pesan)
      {
         $msg = '';
         if (count($this->Pesan) > 1) foreach ($this->Pesan as $value)
            $msg .= "\t$value<br/>\n";
         else $msg .= $this->Pesan[0];
         
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $msg);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $this->css);
		}
      // ---------
      
      // render link
      $this->mrTemplate->AddVar('content', 'URL_BACK', $data['link']['url_back']);
      // ---------
      
      // render informasi
      $this->mrTemplate->AddVar('content', 'NAMA', $data['data']['nama']);
      // ---------
      #print_r($data['data']);
      // render list kontruksi ruang
      if (!empty($data['data']['inventaris'])) {
         $this->mrTemplate->AddVar('content', 'GEDUNG_KODE', $data['data']['inventaris']['gedung_kode']);
         $this->mrTemplate->AddVar('content', 'GEDUNG_NAMA', $data['data']['inventaris']['gedung_nama']);
         $this->mrTemplate->AddVar('content', 'RUANG_KODE', $data['data']['inventaris']['ruang_kode']);
         $this->mrTemplate->AddVar('content', 'RUANG_NAMA', $data['data']['inventaris']['ruang_nama']);
         $this->mrTemplate->AddVar('content', 'RUANG_JENIS', $data['data']['inventaris']['ruang_jenis']);
         $this->mrTemplate->AddVar('content', 'RUANG_KAPASITAS', $data['data']['inventaris']['ruang_kapasitas']);
         $this->mrTemplate->AddVar('content', 'RUANG_LUAS', $data['data']['inventaris']['ruang_luas']);
         $this->mrTemplate->AddVar('content', 'RUANG_TIPE', $data['data']['inventaris']['ruang_tipe']);
      }
      // ---------
      
      #print_r($data['list_inventaris']);
      if (!empty($data['list_inventaris'])) {
         $this->mrTemplate->AddVar('inventaris', 'INVENTARIS_EMPTY', 'NO');
         $no = 1; 
         for($i=0; $i<sizeof($data['list_inventaris']); $i++) {
            $this->mrTemplate->AddVar("inventaris_item", "NO", $no++);
            $this->mrTemplate->AddVar("inventaris_item", "ASET_KODE", $data['list_inventaris'][$i]['aset_kode']);
            $this->mrTemplate->AddVar("inventaris_item", "ASET_LABEL", $data['list_inventaris'][$i]['aset_label']);
            $this->mrTemplate->AddVar("inventaris_item", "KONDISI", $data['list_inventaris'][$i]['kondisi']);
            if($no % 2 != 0)
               $this->mrTemplate->AddVar("inventaris_item", "CLASS_NAME", 'table-common-even');
            else
               $this->mrTemplate->AddVar("inventaris_item", "CLASS_NAME", '');          
            $this->mrTemplate->parseTemplate("inventaris_item", "a");
         }
      }
      else $this->mrTemplate->AddVar('inventaris', 'INVENTARIS_EMPTY', 'YES');
   }
}
?>