<?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 ViewKonstruksiRuang extends HtmlResponse {
	function TemplateModule()
   {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/gedung/template');
		$this->SetTemplateFile('view_konstruksi_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['konstruksi'] = $Obj->GetKonstruksiByRuangId($_GET['id']->Integer()->Raw());
            $return['data'] = $result;
         }
         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']);
      // ---------
      
      // render list kontruksi ruang
      if (count($data['konstruksiRuangList']) > 0)
      {
         $this->mrTemplate->AddVar('konstruksi', 'KONSTRUKSI_EMPTY', 'NO');
         
         foreach ($data['comboJnsKonstruksi'] as $value)
            $jnsKonstruksi[$value['id']] = $value['name'];
         
         $form = array();
         foreach ($data['konstruksiRuangList'] as $value)
         {
            $form['konstruksiRuangNama'] = $value['name'];
            if (!isset($data['data']['konstruksi']/*$value['id']*/)) 
               $form['jenisKonstruksiNama'] = 'Belum didata!';
            else $form['jenisKonstruksiNama'] = $jnsKonstruksi[$data['data']['konstruksi'][$value['id']]];
            
            $this->mrTemplate->AddVars('konstruksi_item', $form, '');
            $this->mrTemplate->parseTemplate('konstruksi_item', 'a');
         }
      }
      else $this->mrTemplate->AddVar('konstruksi', 'KONSTRUKSI_EMPTY', 'YES');
      // ---------
   }
}
?>