<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/jalur_masuk/business/AppJalurMasukToAdmisi.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/jalur_masuk/business/AppJalurMasukToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/jalur_masuk/business/AppJalurMasukToFinansi.class.php';

class ViewInputJalurMasuk extends HtmlResponse {

	
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/jalur_masuk/template');
		$this->SetTemplateFile('input_jalur_masuk.html');
	}
	
	function ProcessRequest() {
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
      
		$jalurObjAdmisi = new AppJalurMasukToAdmisi();
		$jalurObjSia = new AppJalurMasukToSia();
		$jalurObjFinansi = new AppJalurMasukToFinansi();
      
      if(!$jalurObjSia->addConn)
         $return['siaConn']=false;
      else
         $return['siaConn']=true;              
      
      if(!$jalurObjFinansi->addConn)
         $return['finansiConn']=false;
      else
         $return['finansiConn']=true;
         
		$msg = Messenger::Instance()->Receive(__FILE__);

		$dataJalur= $jalurObjAdmisi->GetDataJalurMasukById($idDec);
      $return['pesan']=$msg[0][1];
      $return['data']=$msg[0][0];
		$return['decDataId'] = $idDec;
		$return['dataJalur'] = $dataJalur;
		return $return;
	}

	function ParseTemplate($data = NULL) {
      $siaConn=$data['siaConn'];
      $finansiConn=$data['finansiConn'];
      
      if($siaConn==false){
      	$this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
         $this->mrTemplate->SetAttribute('sia_conn', 'visibility', 'visible');
			$this->mrTemplate->AddVar('sia_conn', 'ISI_PESAN_SIA', 'Gagal Menghubungi SI Akademik');
      }
      
      if($finansiConn==false){
      	$this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
         $this->mrTemplate->SetAttribute('finansi_conn', 'visibility', 'visible');
			$this->mrTemplate->AddVar('finansi_conn', 'ISI_PESAN_FINANSI', 'Gagal Menghubungi SI Finansi');
      }
      
      if(($finansiConn==true) and ($siaConn==true) ){
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      }
      
      
      $url_kembali=Dispatcher::Instance()->GetUrl('jalur_masuk', 'jalurMasuk', 'view', 'html');
      $this->mrTemplate->AddVar('warning', 'URL_KEMBALI',$url_kembali );
      
		if ($data['pesan']) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan']);
		}
      
		$dataJalur = $data['dataJalur'];

		if ($_REQUEST['dataId']=='') {
			$url="addJalurMasuk";
			$tambah="Tambah";
		} else {
			$url="updateJalurMasuk";
			$tambah="Ubah";
		}

		$this->mrTemplate->AddVar('status_koneksi', 'JUDUL', $tambah);
      $this->mrTemplate->AddVar('status_koneksi', 'KODE_JALUR', empty($dataJalur[0]['kode_jalur'])?$data['data']['kode_jalur']:$dataJalur[0]['kode_jalur']);
      $this->mrTemplate->AddVar('status_koneksi', 'NAMA_JALUR', empty($dataJalur[0]['nama_jalur'])?$data['data']['nama_jalur']:$dataJalur[0]['nama_jalur']);
		$this->mrTemplate->AddVar('status_koneksi', 'URL_ACTION', Dispatcher::Instance()->GetUrl('jalur_masuk', $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']));
	}
}
?>
