<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/warga_negara/business/AppWargaNegara.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/warga_negara/business/AppWargaNegaraToSia.class.php';

class ViewInputWargaNegara extends HtmlResponse {
	
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/warga_negara/template');
		$this->SetTemplateFile('input_warga_negara.html');
	}
	
	function ProcessRequest() {
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$wargaNegaraObj = new AppWargaNegara();
		$siaObj = new AppWargaNegaraToSia();
		
      if(!$siaObj->addConn){
         $return['siaConn']=false;
      }else{
         $return['siaConn']=true;
      }
      
      $msg = Messenger::Instance()->Receive(__FILE__);
		$return['Pesan'] = $msg[0][1];
      
		$dataWargaNegara = $wargaNegaraObj->GetDataWargaNegaraById($idDec);

		$return['decDataId'] = $idDec;
		$return['css'] = $msg[0][2];
		$return['dataWargaNegara'] = $dataWargaNegara;
		$return['start'] = $startRec+1;
		
		return $return;
	}

	function ParseTemplate($data = NULL) {
      $dataWargaNegara = $data['dataWargaNegara'];
      $siaConn = $data['siaConn'];
      
      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('warga_negara', 'wargaNegara', 'view', 'html');
         $this->mrTemplate->AddVar('warning', 'URL_KEMBALI', $url_kembali);
      }elseif($siaConn==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="addWargaNegara";
			$tambah="Tambah";
		} else {
			$url="updateWargaNegara";
			$tambah="Ubah";
		}
		$this->mrTemplate->AddVar('connection', 'JUDUL', $tambah);
		$this->mrTemplate->AddVar('connection', 'WARGA_NEGARA_NAMA', empty($dataWargaNegara[0]['warga_negara_nama'])?$data['data']['warga_negara_nama']:$dataWargaNegara[0]['warga_negara_nama']);
		$this->mrTemplate->AddVar('connection', 'URL_ACTION', Dispatcher::Instance()->GetUrl('warga_negara', $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']));
	}
}
?>
