<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/status_mahasiswa/business/AppStatusMahasiswa.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/status_mahasiswa/business/AppStatusMahasiswaToSia.class.php';

class ViewInputStatusMahasiswa extends HtmlResponse {
	
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/status_mahasiswa/template');
		$this->SetTemplateFile('input_status_mahasiswa.html');
	}
	
	function ProcessRequest() {
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$msg = Messenger::Instance()->Receive(__FILE__);
		$statusMahasiswaObj = new AppStatusMahasiswa();
		$siaObj = new AppStatusMahasiswaToSia();
		
		if(!$siaObj->addConn)
         $return['siaConn'] = false;
      else
         $return['siaConn'] = true;

		$dataStatusMahasiswa = $statusMahasiswaObj->GetDataStatusMahasiswaById($idDec);
		$return['Pesan'] = $msg[0][1];
		$return['data'] = $msg[0][0];
		$return['decDataId'] = $idDec;
      $return['dataStatusMahasiswa'] = $dataStatusMahasiswa;

		return $return;
	}

	function ParseTemplate($data = NULL) {
      $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('status_mahasiswa', 'statusMahasiswa', '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']);
		}
		$dataStatusMahasiswa = $data['dataStatusMahasiswa'];
		
		if ($_REQUEST['dataId']=='') {
			$url="addStatusMahasiswa";
			$tambah="Tambah";
		} else {
			$url="updateStatusMahasiswa";
			$tambah="Ubah";
		}
		$this->mrTemplate->AddVar('connection', 'JUDUL', $tambah);
      $this->mrTemplate->AddVar('connection', 'STATUS_MAHASISWA_KODE', empty($dataStatusMahasiswa[0]['status_mahasiswa_kode'])?$data['data']['status_mahasiswa_kode']:$dataStatusMahasiswa[0]['status_mahasiswa_kode']);
      $this->mrTemplate->AddVar('connection', 'STATUS_MAHASISWA_NAMA', empty($dataStatusMahasiswa[0]['status_mahasiswa_nama'])?$data['data']['status_mahasiswa_nama']:$dataStatusMahasiswa[0]['status_mahasiswa_nama']);
		$this->mrTemplate->AddVar('connection', 'URL_ACTION', Dispatcher::Instance()->GetUrl('status_mahasiswa', $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']));
	}
}
?>
