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

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

class ViewSetting extends HtmlResponse {
   
   protected $data;
   
   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 TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/setting/template');
      $this->SetTemplateFile('setting.html');
   }
   
   function ProcessRequest() {  
   
		$Obj = new Setting();
		$arrSetting = $Obj->GetSetting();
		
		$unit = $Obj->GetUnitKerjaById($arrSetting['0']['settingValue']);
		$arrSetting['0']['viewValue'] = $unit['0']['unitKerjaNama'];
		
		$arrUnitKerja = $Obj->GetUnitKerja();
		Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'unit_kerja', 
         array('setting[0]',$arrUnitKerja,$arrSetting['0']['settingValue'],'false','style="width:320px;"'), Messenger::CurrentRequest);
		
      	$gudangList = $Obj->GetGudangList();
      	Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'gudang', 
         array('setting[1]',$gudangList,$arrSetting['1']['settingValue'],false,'style="width:320px;"'), Messenger::CurrentRequest);
		
      	$ruangList = $Obj->GetRuangList();
      	Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'ruang', 
         array('setting[2]',$ruangList,$arrSetting['2']['settingValue'],false,'style="width:320px;"'), Messenger::CurrentRequest);

      	$gudangMaintenance = $Obj->GetGudangList($arrSetting['1']['settingValue']);
		Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'gudang_penyimpanan', 
         array('setting[3]',$gudangMaintenance,$arrSetting['3']['settingValue'],false,'style="width:320px;"'), Messenger::CurrentRequest);
		
		$arrGet = $_GET->AsArray();
      	@$return['msg'] = $arrGet['msg'];
		@$return['arrSetting'] = $arrSetting;
		return $return;
   }
   
   function ParseTemplate($data = NULL) {
		
		if (isset($data['msg'])) {	     
         $this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', 'Update Data Berhasil Dilaksanakan');
		 if($data['msg']=='sukses') 
		   $class='notebox-done';
		 else
		   $class = 'notebox-warning';
         $this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $class);
		 
      }
		
      //set Label
      $this->TemplateLabeling();
		$arrSetting = $data['arrSetting'];
		
		$this->mrTemplate->AddVar('content', 'URL_ACTION', Dispatcher::Instance()->GetUrl('setting', 'updateSetting', 'do', 'html'));
		$this->mrTemplate->addVar("content","SETTING_NAMA",$arrSetting[0]['settingNama']);
		$this->mrTemplate->addVar("content","SETTING_GUDANG",$arrSetting[1]['settingNama']);
		$this->mrTemplate->addVar("content","SETTING_PENYIMPANAN",$arrSetting[3]['settingNama']);
		$this->mrTemplate->addVar("content","SETTING_RUANG",$arrSetting[2]['settingNama']);
	}
}
?>
