<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/status_smta/business/AppStatusSmta.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/status_smta/business/AppStatusSmtaToSia.class.php';

class ViewInputStatusSmta extends HtmlResponse {
	
	function TemplateModule() {
		$this->SetTemplateBasedir($this->mrConfig->mApplication['docroot'] . 'module/status_smta/template');
		$this->SetTemplateFile('input_status_smta.html');
	}

	function ProcessRequest() {
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$statusObj = new AppStatusSmta();
		$statusObjToSia = new AppStatusSmtaToSia();
      
      if(!$statusObjToSia->addConn)
         $return['siaConn']=false;
      else
         $return['siaConn']=true;
      
      $msg = Messenger::Instance()->Receive(__FILE__);

		$dataStatusSmta = $statusObj->GetDataStatusSmtaById($idDec);
      $return['pesan']=$msg[0][1];
      $return['data']=$msg[0][0];
		$return['decDataId'] = $idDec;
		$return['dataStatusSmta'] = $dataStatusSmta;
		return $return;
	}
	function ParseTemplate($data = NULL) {
      $siaConn=$data['siaConn'];
      
		if ($data['pesan']) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan']);
		}
      
      if($siaConn==false){
      	$this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
			$this->mrTemplate->AddVar('warning', 'ISI_PESAN_SIA', 'Gagal Menghubungi SI Akademik');
         $url_kembali=Dispatcher::Instance()->GetUrl('status_smta', 'statusSmta', 'view', 'html');
         $this->mrTemplate->AddVar('warning', 'URL_KEMBALI_SIA',$url_kembali );
      }elseif($siaConn==true){
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      }
      
		$dataStatusSmta = $data['dataStatusSmta'];
		
		if ($_REQUEST['dataId']=='') {
			$url="addStatusSmta";
			$tambah="Tambah";
		} else {
			$url="updateStatusSmta";
			$tambah="Ubah";
		}

		$this->mrTemplate->AddVar('status_koneksi', 'JUDUL', $tambah);
      $this->mrTemplate->AddVar('status_koneksi', 'STATUS_SMTA', empty($dataStatusSmta[0]['status_smta'])?$data['data']['status_smta']:$dataStatusSmta[0]['status_smta']);
		$this->mrTemplate->AddVar('status_koneksi', 'URL_ACTION', Dispatcher::Instance()->GetUrl('status_smta', $url, 'do', 'html') . "&dataId=" . Dispatcher::Instance()->Encrypt($data['decDataId']));
		$this->mrTemplate->AddVar('status_koneksi', 'DATAID', Dispatcher::Instance()->Decrypt($_GET['dataId']));
		$this->mrTemplate->AddVar('status_koneksi', 'PAGE', Dispatcher::Instance()->Decrypt($_GET['page']));
	}
}
?>
