<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/agama/business/AppAgama.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/agama/business/AppAgamaToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/agama/business/AppAgamaToUm.class.php';

class ViewInputAgama extends HtmlResponse {
	
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/agama/template');
		$this->SetTemplateFile('input_agama.html');
	}
	
	function ProcessRequest() {
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$useUm=GTFWConfiguration::GetValue( 'application', 'use_gtum');
		$agamaObj = new AppAgama();
		$siaObj = new AppAgamaToSia();
		$umObj = new AppAgamaToUm();
		
		if(!$umObj->addConn && $useUm==true) $return['umConn']=false; else $return['umConn']=true;
		
		if(!$siaObj->addConn) $return['siaConn']=false; else $return['siaConn']=true;
      
		$msg = Messenger::Instance()->Receive(__FILE__);
		$return['Pesan'] = $msg[0][1];
		$return['Data'] = $msg[0][0];
      
		$dataAgama = $agamaObj->GetDataAgamaById($idDec);

		$return['decDataId'] = $idDec;
		$return['dataAgama'] = $dataAgama;

		return $return;
	}

	function ParseTemplate($data = NULL) {
      $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('agama', 'agama', '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('agama', 'agama', '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']);
		}
		$dataAgama = $data['dataAgama'];
		
		if ($_REQUEST['dataId']=='') {
			$url="addAgama";
			$tambah="Tambah";
		} else {
			$url="updateAgama";
			$tambah="Ubah";
		}
		$this->mrTemplate->AddVar('connection', 'JUDUL', $tambah);
		$this->mrTemplate->AddVar('connection', 'AGAMA_NAMA', empty($dataAgama[0]['agama_nama'])?$data['data']['agama_nama']:$dataAgama[0]['agama_nama']);
		$this->mrTemplate->AddVar('connection', 'URL_ACTION', Dispatcher::Instance()->GetUrl('agama', $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']));
	}
}
?>
