<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/kota/business/AppKota.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/kota/business/AppKotaToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/kota/business/AppKotaToUm.class.php';

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

   function ProcessRequest() {
		$msg = Messenger::Instance()->Receive(__FILE__);
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
      $useUm=GTFWConfiguration::GetValue( 'application', 'use_gtum');
		$kotaObj = new AppKota();
		$siaObj = new AppKotaToSia();
		$umObj = new AppKotaToUm();
		
		if(!$siaObj->addConn)
		   $return['siaConn']=false;
      else
         $return['siaConn']=true;
		
		if(!$umObj->addConn && $useUm==true)
		   $return['umConn']=false;
		else
		   $return['umConn']=true;
		
		
		
		$dataKota = $kotaObj->GetDataKotaById($idDec);
		$dataPropinsi = $kotaObj->GetDataPropinsi();

      if($msg[0][0]){
         $idProp=$msg[0][0]['propinsi'];
      }else{
         $idProp=$dataKota[0]['kota_propinsi_kode'];
      }

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'propinsi', 
         array('propinsi',$dataPropinsi,$idProp,'false'), Messenger::CurrentRequest);
      
      $return['pesan']=$msg[0][1];
      $return['data']=$msg[0][0];
      
		$return['decDataId'] = $idDec;
		$return['dataKota'] = $dataKota;
		return $return;
	}

   function ParseTemplate($data = NULL) {
      $dataKota = $data['dataKota'];
      $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('kota', 'kota', '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('kota', 'kota', '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="addKota";
			$tambah="Tambah";
		} else {
			$url="updateKota";
			$tambah="Ubah";
		}

		$this->mrTemplate->AddVar('connection', 'JUDUL', $tambah);
      $this->mrTemplate->AddVar('connection', 'KOTA_KODE', empty($dataKota[0]['kota_kode'])?$data['data']['kota_kode']:$dataKota[0]['kota_kode']);
      $this->mrTemplate->AddVar('connection', 'KOTA_NAMA', empty($dataKota[0]['kota_nama'])?$data['data']['kota_nama']:$dataKota[0]['kota_nama']);
		$this->mrTemplate->AddVar('connection', 'URL_ACTION', Dispatcher::Instance()->GetUrl('kota', $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']));
	}
}
?>
