<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/pekerjaan/business/AppPekerjaan.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/pekerjaan/business/AppPekerjaanToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/pekerjaan/business/AppPekerjaanToUm.class.php';

class ViewInputPekerjaan extends HtmlResponse {
	
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/pekerjaan/template');
		$this->SetTemplateFile('input_pekerjaan.html');
	}
	
	function ProcessRequest() {
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
      $useUm=GTFWConfiguration::GetValue( 'application', 'use_gtum');
		$msg = Messenger::Instance()->Receive(__FILE__);
		
		$pekerjaanObj = new AppPekerjaan();
		$siaObj = new AppPekerjaanToSia();
		$umObj = new AppPekerjaanToUm();
		
		if(!$siaObj->addConn)
		   $return['siaConn']=false;
      else

		if(!$umObj->addConn && $useUm==true)
		   $return['umConn']=false;
      else
         $return['umConn']=true;
         
		$dataPekerjaan = $pekerjaanObj->GetDataPekerjaanById($idDec);

      $return['Pesan'] = $msg[0][1];
		$return['Data'] = $msg[0][0];

		$return['decDataId'] = $idDec;
		$return['dataPekerjaan'] = $dataPekerjaan;
		return $return;
	}

	function ParseTemplate($data = NULL) {
      $dataPekerjaan = $data['dataPekerjaan'];
      $siaConn = $data['siaConn'];
      $umConn = $data['umConn'];
	     
      if($siaConn==false){
         $this->mrTemplate->AddVar('connection', 'CONNECTION', 'NO');
         $this->mrTemplate->AddVar('warning', 'ISI_PESAN', 'Gagal menghubungi ke database SI Akademik');
         $url_kembali=Dispatcher::Instance()->GetUrl('pekerjaan', 'pekerjaan', 'view', 'html');
         $this->mrTemplate->AddVar('warning', 'URL_KEMBALI', $url_kembali);
      }elseif($siaConn==true){
         $this->mrTemplate->AddVar('connection', 'CONNECTION', 'YES');
      }
      if($umConn==false){
         $this->mrTemplate->AddVar('connection', 'CONNECTION', 'NO');
         $this->mrTemplate->AddVar('warning', 'ISI_PESAN', 'Gagal menghubungi ke database SI Admisi');
         $url_kembali=Dispatcher::Instance()->GetUrl('pekerjaan', 'pekerjaan', 'view', 'html');
         $this->mrTemplate->AddVar('warning', 'URL_KEMBALI', $url_kembali);
      }elseif($umConn==true){
         $this->mrTemplate->AddVar('connection', 'CONNECTION', 'YES');
      }
		if ($data['Pesan']) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['Pesan']);
		}
		
		if ($_REQUEST['dataId']=='') {
			$url="addPekerjaan";
			$tambah="Tambah";
		} else {
			$url="updatePekerjaan";
			$tambah="Ubah";
		}
		$this->mrTemplate->AddVar('connection', 'JUDUL', $tambah);
		$this->mrTemplate->AddVar('connection', 'PEKERJAAN_NAMA', empty($dataPekerjaan[0]['pekerjaan_nama'])?$data['data']['pekerjaan_nama']:$dataPekerjaan[0]['pekerjaan_nama']);
		$this->mrTemplate->AddVar('connection', 'URL_ACTION', Dispatcher::Instance()->GetUrl('pekerjaan', $url, 'do', 'html') . "&dataId=" . Dispatcher::Instance()->Encrypt($data['decDataId']));
		$this->mrTemplate->AddVar('connection', 'DATAID', Dispatcher::Instance()->Decrypt($_GET['dataId']));
		$this->mrTemplate->AddVar('connection', 'PAGE', Dispatcher::Instance()->Decrypt($_GET['page']));
	}
}
?>
