<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/mahasiswa/business/AppMahasiswa.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/mahasiswa/business/AppMahasiswaToFinansi.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/mahasiswa/business/AppMahasiswaUm.class.php';

class ViewImportMahasiswaFromUm extends HtmlResponse{

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/mahasiswa/template');
		$this->SetTemplateFile('import_mahasiswa_from_um.html');
	}

   function ProcessRequest() {
      $siregObj = new AppMahasiswa();
      $finansiObj = new AppMahasiswaToFinansi();
      $umObj = new AppMahasiswaUm();
      
      $msg = Messenger::Instance()->Receive(__FILE__);
      $dataTahun=$siregObj->GetTahun(1990);
      $tahunMasukDefault=$siregObj->GetTahunPeriodeAktif();
      
      $pesan = $msg[0][1];
      $data = $msg[0][0];   
      $tahunMasuk = empty($data['tahun_masuk'])?$tahunMasukDefault:$data['tahun_masuk'];
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'tahun_masuk',array('tahun_masuk',$dataTahun,$tahunMasuk,'false',''), Messenger::CurrentRequest);
      
      $semsMasukDefault = $siregObj->GetPeriodeAktif();
      $dataSemester = $siregObj->GetSemesterMasuk();
      $semesterMasuk = empty($data['sems_masuk'])?$semsMasukDefault:$data['sems_masuk'];
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'sems_masuk',array('sems_masuk',$dataSemester,$semesterMasuk,'false',''),Messenger::CurrentRequest); 
      
      $useUm = GTFWConfiguration::GetValue( 'application', 'use_gtum');
      if(!$finansiObj->addConn)$return['finansiConn'] = false; elseif($finansiObj->addConn)$return['finansiConn'] = true;  
      if(!$umObj->addConn && $useUm==true) $return['umConn'] = false; elseif($umObj->addConn) $return['umConn'] = true;  
      $return['data']=$data;
      $return['pesan']=$pesan;
      return $return;
	}

   function ParseTemplate($data = NULL) {
      $finansiConn=$data['finansiConn'];
      $umConn=$data['umConn'];
      
      if($finansiConn==false){
        $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
        $this->mrTemplate->SetAttribute('finansi_conn', 'visibility', 'visible');
        $this->mrTemplate->AddVar('finansi_conn', 'ISI_PESAN_FINANSI', 'Gagal Menghubungi SI Finansi');
      }else{
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      }
      
      if($umConn==false){
        $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
        $this->mrTemplate->SetAttribute('finansi_conn', 'visibility', 'visible');
        $this->mrTemplate->AddVar('finansi_conn', 'ISI_PESAN_FINANSI', 'Gagal Menghubungi SI Admisi');
      }else{
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      }

		if ($data['pesan']) {
         $this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan']);
      }
      
      $this->mrTemplate->AddVar('status_koneksi', 'URL_ACTION', Dispatcher::Instance()->GetUrl('mahasiswa', 'importMahasiswaFromUm', 'do', 'html') );
	}
}
?>
