<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/sumber_dana/business/AppSumberDana.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/sumber_dana/business/AppSumberDanaToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/sumber_dana/business/AppSumberDanaToUm.class.php';

class ViewInputSumberDana extends HtmlResponse {
	
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/sumber_dana/template');
		$this->SetTemplateFile('input_sumber_dana.html');
	}
	
	function ProcessRequest() {
		$msg = Messenger::Instance()->Receive(__FILE__);
      $idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$useUm=GTFWConfiguration::GetValue( 'application', 'use_gtum');
		$sumberDanaObj = new AppSumberDana();
		$siaObj = new AppSumberDanaToSia();
		$umObj = new AppSumberDanaToUm();
		
		if(!$siaObj->addConn)
		   $return['siaConn']=false;
      else
         $return['siaConn']=true;
         
      if(!$umObj->addConn && $useUm==true)
		   $return['umConn']=false;
      else
         $return['umConn']=true;
		$dataSumberDana = $sumberDanaObj->GetDataSumberDanaById($idDec);

		$return['Pesan'] = $msg[0][1];
		$return['css'] = $msg[0][2];
		
      $return['decDataId'] = $idDec;
		$return['dataSumberDana'] = $dataSumberDana;
		$return['start'] = $startRec+1;
		return $return;
	}

	function ParseTemplate($data = NULL) {
      $siaConn = $data['siaConn'];
      $dataSumberDana = $data['dataSumberDana'];
      
      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('sumber_dana', 'sumberDana', '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('status_nikah', 'statusNikah', '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="addSumberDana";
			$tambah="Tambah";
		} else {
			$url="updateSumberDana";
			$tambah="Ubah";
		}
		
		$this->mrTemplate->AddVar('connection', 'JUDUL', $tambah);
		$this->mrTemplate->AddVar('connection', 'SUMBER_DANA_NAMA', empty($dataSumberDana[0]['sumber_dana_nama'])?$data['data']['sumber_dana_nama']:$dataSumberDana[0]['sumber_dana_nama']);
		$this->mrTemplate->AddVar('connection', 'URL_ACTION', Dispatcher::Instance()->GetUrl('sumber_dana', $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']));
	}
}
?>
