<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/smta/business/AppSmta.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/smta/business/AppSmtaToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/smta/business/AppSmtaToUm.class.php';

class ViewInputSmta extends HtmlResponse {

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/smta/template');
		$this->SetTemplateFile('input_smta.html');
	}
	
	function ProcessRequest() {
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$useUm=GTFWConfiguration::GetValue( 'application', 'use_gtum');
		$smtaObj = new AppSmta();
		$smtaObjToSia = new AppSmtaToSia();
		$smtaObjToUm = new AppSmtaToUm();
      
      if(!$smtaObjToSia->addConn)
         $return['siaConn']=false;
      else
         $return['siaConn']=true;
         
      if(!$smtaObjToUm->addConn && $useUm==true)
         $return['umConn']=false;
      else
         $return['umConn']=true;
         
		$msg = Messenger::Instance()->Receive(__FILE__);

		$dataSmta = $smtaObj->GetDataSmtaById($idDec);

      $dataKota=$smtaObj->GetDataKota();

      if($msg[0][0]){
         $idKota=$msg[0][0]['kota'];
      }else{
         $idKota=$dataSmta[0]['smta_kotaKode'];
      }

            Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'kota',
            array('kota',$dataKota,$idKota,'false',''), Messenger::CurrentRequest);


      $return['data']=$msg[0][0];
      $return['pesan']=$msg[0][1];;
		$return['decDataId'] = $idDec;
		$return['dataSmta'] = $dataSmta;
		return $return;
	}

	function ParseTemplate($data = NULL) {
      $siaConn=$data['siaConn'];
      $umConn=$data['umConn'];
      
		if ($data['pesan']) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan']);
		}
      
      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('smta', 'smta', '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('smta', 'smta', 'view', 'html');
         $this->mrTemplate->AddVar('warning', 'URL_KEMBALI_SIA',$url_kembali );
      }elseif($umConn==true){
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      }     
		$dataSmta = $data['dataSmta'];


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

		$this->mrTemplate->AddVar('status_koneksi', 'JUDUL', $tambah);
		$this->mrTemplate->AddVar('status_koneksi', 'SMTA_KODE', empty($dataSmta[0]['smta_kode'])?$data['data']['smta_kode']:$dataSmta[0]['smta_kode']);
      $this->mrTemplate->AddVar('status_koneksi', 'SMTA_NAMA', empty($dataSmta[0]['smta_nama'])?$data['data']['smta_nama']:$dataSmta[0]['smta_nama']);
		$this->mrTemplate->AddVar('status_koneksi', 'URL_ACTION', Dispatcher::Instance()->GetUrl('smta', $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']));
	}
}
?>
