<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/pendidikan/business/AppPendidikan.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/pendidikan/business/AppPendidikanToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/pendidikan/business/AppPendidikanToUm.class.php';

class ViewInputPendidikan extends HtmlResponse{

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/pendidikan/template');
		$this->SetTemplateFile('input_pendidikan.html');
	}
	
	function ProcessRequest() {
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
      $useUm=GTFWConfiguration::GetValue( 'application', 'use_gtum');
		$pendObj = new AppPendidikan();
		$pendObjSia = new AppPendidikanToSia();
		$pendObjUm = new AppPendidikanToUm();
		
      if(!$pendObjSia->addConn)
         $return['siaConn']=false;
      else
         $return['siaConn']=true;

      if(!$pendObjUm->addConn && $useUm==true)
         $return['umConn']=false;
      else
         $return['umConn']=true;
              
              

		$msg = Messenger::Instance()->Receive(__FILE__);
      $return['pesan']=$msg[0][1];
      $return['data']=$msg[0][0];
      
		$dataPendidikan = $pendObj->GetDataPendidikanById($idDec);
		$return['decDataId'] = $idDec;
		$return['dataPendidikan'] = $dataPendidikan;
		//$return['umConn'] = $umConn;
		
		return $return;
	}
	function ParseTemplate($data = NULL) {
      $siaConn=$data['siaConn'];
      $umConn=$data['umConn'];
      //print($umConn);
      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('pendidikan', 'pendidikan', 'view', 'html');
         $this->mrTemplate->AddVar('warning', 'URL_KEMBALI_SIA',$url_kembali );
      }elseif($siaConn==true){
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      }
      
      if($umConn==false){
      	$this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
			$this->mrTemplate->AddVar('warning', 'ISI_PESAN_SIA', 'Gagal Menghubungi SI Admisi');
         $url_kembali=Dispatcher::Instance()->GetUrl('pendidikan', 'pendidikan', 'view', 'html');
         $this->mrTemplate->AddVar('warning', 'URL_KEMBALI_SIA',$url_kembali );
      }elseif($umConn==true){
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      } 
      
		if ($data['pesan']) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan']);
		}
		$dataPendidikan = $data['dataPendidikan'];
		
		if ($_REQUEST['dataId']=='') {
			$url="addPendidikan";
			$tambah="Tambah";
		} else {
			$url="updatePendidikan";
			$tambah="Ubah";
		}
		$this->mrTemplate->AddVar('status_koneksi', 'JUDUL', $tambah);
      $this->mrTemplate->AddVar('status_koneksi', 'NAMA_PENDIDIKAN', empty($dataPendidikan[0]['nama_pendidikan'])?$data['data']['nama_pendidikan']:$dataPendidikan[0]['nama_pendidikan']);
      $this->mrTemplate->AddVar('status_koneksi', 'ID_PENDIDIKAN', empty($dataPendidikan[0]['nama_pendidikan'])?$data['data']['id_pendidikan']:$dataPendidikan[0]['id_pendidikan']);
		$this->mrTemplate->AddVar('status_koneksi', 'URL_ACTION', Dispatcher::Instance()->GetUrl('pendidikan', $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']));
	}

}

?>
