<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/penghasilan/business/AppPenghasilan.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/penghasilan/business/AppPenghasilanToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/penghasilan/business/AppPenghasilanToUm.class.php';

class ViewInputPenghasilan extends HtmlResponse {
	
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/penghasilan/template');
		$this->SetTemplateFile('input_penghasilan.html');
	}
	
	function ProcessRequest() {
	   $useUm=GTFWConfiguration::GetValue( 'application', 'use_gtum');
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$msg = Messenger::Instance()->Receive(__FILE__);
		
		$penghasilanObj = new AppPenghasilan();
		$siaObj = new AppPenghasilanToSia();
		$umObj = new AppPenghasilanToUm();
		
      if(!$siaObj->addConn)
		   $return['siaConn']=false;
      else
         $return['siaConn']=true;		
      
      if(!$umObj->addConn && $useUm==true)
         $return['umConn']=false;
      else
         $return['umConn']=true;
         
      //print($returl['umConn']);
		$dataPenghasilan = $penghasilanObj->GetDataPenghasilanById($idDec);

      $return['Pesan'] = $msg[0][1];
		$return['Data'] = $msg[0][0];

		$return['decDataId'] = $idDec;
		$return['dataPenghasilan'] = $dataPenghasilan;
		return $return;
	}

	function ParseTemplate($data = NULL) {
		$dataPenghasilan = $data['dataPenghasilan'];
		$siaConn = $data['siaConn'];
		$umConn = $data['umConn'];
		
		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('penghasilan', 'penghasilan', 'view', 'html');
         $this->mrTemplate->AddVar('warning', 'URL_KEMBALI', $url_kembali);
      }elseif($siaConn==true){
         $this->mrTemplate->AddVar('connection', 'CONNECTION', 'YES');
      }
      
		if($umConn==false){
         $this->mrTemplate->AddVar('connection', 'CONNECTION', 'NO');
         $this->mrTemplate->AddVar('warning', 'ISI_PESAN', 'Gagal menghubungi ke database SI Admisi');
         $url_kembali=Dispatcher::Instance()->GetUrl('penghasilan', 'penghasilan', 'view', 'html');
         $this->mrTemplate->AddVar('warning', 'URL_KEMBALI', $url_kembali);
      }elseif($umConn==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']);
		}

		if ($_REQUEST['dataId']=='') {
			$url="addPenghasilan";
			$tambah="Tambah";
		} else {
			$url="updatePenghasilan";
			$tambah="Ubah";
		}
		$this->mrTemplate->AddVar('connection', 'JUDUL', $tambah);
		$this->mrTemplate->AddVar('connection', 'PENGHASILAN_BESAR', empty($dataPenghasilan[0]['penghasilan_besar'])?$data['Data']['penghasilan_besar']:$dataPenghasilan[0]['penghasilan_besar']);
		$this->mrTemplate->AddVar('connection', 'PENGHASILAN_URUTAN',empty($dataPenghasilan[0]['penghasilan_urutan'])?$data['Data']['penghasilan_urutan']:$dataPenghasilan[0]['penghasilan_urutan']);
		$this->mrTemplate->AddVar('connection', 'URL_ACTION', Dispatcher::Instance()->GetUrl('penghasilan', $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']));
	}
}
?>
