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

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

class ViewInputBidang extends HtmlResponse {
	var $Data;
	var $Pesan;
	
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot') . 'module/golongan_bidang/template');
		$this->SetTemplateFile('input_bidang.html');
	}
	
	function ProcessRequest() {
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']->Integer()->Raw());
		$Obj = new AppGolonganbidang();
      
		$msg = Messenger::Instance()->Receive(__FILE__);
		$this->Pesan = $msg[0][1];
		$this->Data = $msg[0][0];

		$data = $Obj->GetBidangById($idDec);
		if (isset($this->Data['kodegol'])) $gol = $this->Data['kodegol'];
		else $gol = $data[0]['gol_id'];
		Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'kode_golongan', array('kodegol', $Obj->GetComboGolongan(), $gol, false, (isset($_GET['dataId']))?'':'id="cbxGolongan"'), Messenger::CurrentRequest);

		if (!isset($_GET['dataId']))
         $return['lastCode'] = substr(json_encode($Obj->GetKodeBidangLast()), 1, -1);
      
		$return['decDataId'] = $idDec;
		$return['dataGolonganbidang'] = $data;
		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) {
      //set Label
      $this->TemplateLabeling();
      
		if ($this->Pesan) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $this->Pesan);
		}
		$dataGolonganbidang = $data['dataGolonganbidang'];
		
		if (isset($_GET['dataId'])) {
			$url="updateBidang";
			$tambah="Ubah";
		} else {
			$url="addBidang";
			$tambah="Tambah";
		}
      
      if (isset($data['lastCode'])) $this->mrTemplate->SetAttribute('last_code', 'visibility', 'visible');
		$this->mrTemplate->AddVar('content', 'JSON_LAST_CODE', $data['lastCode']);
		$this->mrTemplate->AddVar('content', 'JUDUL', $tambah);
		$this->mrTemplate->AddVar('content', 'KODE', isset($this->Data['kode'])?$this->Data['kode']:$dataGolonganbidang[0]['kode']);
		$this->mrTemplate->AddVar('content', 'NAMA', isset($this->Data['nama'])?$this->Data['nama']:$dataGolonganbidang[0]['nama']);
      
		$this->mrTemplate->AddVar('content', 'URL_ACTION', Dispatcher::Instance()->GetUrl('golongan_bidang', $url, 'do', 'html') . "&dataId=" . Dispatcher::Instance()->Encrypt($data['decDataId'])."&cari=".$_GET['cari']->Raw()."&page=".$_GET['page']->Integer()->Raw());
	}
}
?>
