<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/propinsi/business/AppPropinsi.class.php';

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/propinsi/business/AppPropinsiToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/propinsi/business/AppPropinsiToUm.class.php';


class ViewInputPropinsi extends HtmlResponse{
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/propinsi/template');
		$this->SetTemplateFile('input_propinsi.html');
	}

   function ProcessRequest() {
		$propObj = new AppPropinsi();
		$propObjToSia = new AppPropinsiToSia();
		$propObjToUm = new AppPropinsiToUm();
		
      $idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$dataPropinsi = $propObj->GetDataPropinsiById($idDec);
		$msg = Messenger::Instance()->Receive(__FILE__);
		$useUm=GTFWConfiguration::GetValue( 'application', 'use_gtum');
      
      if(!$propObjToSia->addConn) $return['siaConn']=false; else $return['siaConn']=true;
      if(!$propObjToUm->addConn && $useUm==true) $return['umConn']=false; else $return['umConn']=true;
		
      $return['pesan']=$msg[0][1];
      $return['data']=$msg[0][0];
      $return['decDataId'] = $idDec;
		$return['dataPropinsi'] = $dataPropinsi;
		return $return;
	}

   function ParseTemplate($data = NULL) {
      $dataPropinsi=$data['dataPropinsi'];
      $siaConn=$data['siaConn'];
      $umConn=$data['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('propinsi', 'propinsi', '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('propinsi', 'propinsi', '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('warningb', 'ISI_PESAN', $data['pesan']);
		}else{
      			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'hidden');
      }

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


		$this->mrTemplate->AddVar('status_koneksi', 'JUDUL', $tambah);
      $this->mrTemplate->AddVar('status_koneksi', 'PROPINSI_KODE', empty($dataPropinsi[0]['propinsi_kode'])?$data['data']['propinsi_kode']:$dataPropinsi[0]['propinsi_kode']);
      $this->mrTemplate->AddVar('status_koneksi', 'PROPINSI_NAMA', empty($dataPropinsi[0]['propinsi_nama'])?$data['data']['propinsi_nama']:$dataPropinsi[0]['propinsi_nama']);
      $this->mrTemplate->AddVar('status_koneksi', 'PROPINSI_NAMA_SINGKAT', empty($dataPropinsi[0]['propinsi_nama_singkat'])?$data['data']['propinsi_nama_singkat']:$dataPropinsi[0]['propinsi_nama_singkat']);
		$this->mrTemplate->AddVar('status_koneksi', 'URL_ACTION', Dispatcher::Instance()->GetUrl('propinsi', $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']));

	}
}
?>
