<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/jurusan/business/AppJurusanToAdmisi.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/jurusan/business/AppJurusanToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/jurusan/business/AppJurusanToPortal.class.php';
class ViewInputJurusan extends HtmlResponse {
   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/jurusan/template');
      $this->SetTemplateFile('input_jurusan.html');
   }
   
   function ProcessRequest(){
      $jurObj=new AppJurusanToAdmisi();
      $jurObjSia=new AppJurusanToSia();
      $jurObjPortal=new AppJurusanToPortal();
      
      if(!$jurObjSia->addConn)
         $return['siaConn']=false;
      else
         $return['siaConn']=true;      
      
      if(!$jurObjPortal->addConn)
         $return['portalConn']=false;
      else
         $return['portalConn']=true;
         
      $idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
      
      $dataJurusan= $jurObj->GetDataJurusanById($idDec);
      
      $dataFakultas=$jurObj->GetDataFakultas();        
      
      $msg = Messenger::Instance()->Receive(__FILE__);  
      
      $jurFakKode=empty($dataJurusan[0]['jur_fak_kode'])?$msg[0][0]['jur_fak_kode']:$dataJurusan[0]['jur_fak_kode'];

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'fakultas',
            array('jur_fak_kode',$dataFakultas,$jurFakKode,'false',''), Messenger::CurrentRequest);

      
      $return['Pesan'] = $msg[0][1];
      $return['Data'] = $msg[0][0];
      $return['decDataId'] = $idDec;
      $return['dataJurusan'] = $dataJurusan;
      return $return;
   }
   
   function ParseTemplate($data=null){
      $siaConn=$data['siaConn'];
      $portalConn=$data['portalConn'];

      $dataJurusan=$data['dataJurusan'];
      
      if ($data['Pesan']) {
         $this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['Pesan']);
      }
      
      if ($_REQUEST['dataId']=='') {
         $url="addJurusan";
         $tambah="Tambah";
      } else {
         $url="updateJurusan";
         $tambah="Ubah";
      }
      
      if($siaConn==false){
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
         $this->mrTemplate->SetAttribute('sia_conn', 'visibility', 'visible');
         $this->mrTemplate->AddVar('sia_conn', 'ISI_PESAN_SIA', 'Gagal Menghubungi SI Akademik');
      }
      
      if($portalConn==false){
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
         $this->mrTemplate->SetAttribute('portal_conn', 'visibility', 'visible');
         $this->mrTemplate->AddVar('portal_conn', 'ISI_PESAN_PORTAL', 'Gagal Menghubungi SI Portal');
      }
      
      
      if( ($portalConn==true) and ($siaConn==true) ){
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      }
      
      $this->mrTemplate->AddVar('status_koneksi', 'JUDUL', $tambah);
      $this->mrTemplate->AddVar('status_koneksi', 'JUR_KODE', empty($dataJurusan[0]['jur_kode'])?$data['Data']['jur_kode']:$dataJurusan[0]['jur_kode']);
      $this->mrTemplate->AddVar('status_koneksi', 'JUR_NAMA_RESMI',empty($dataJurusan[0]['jur_nama_resmi'])?$data['Data']['jur_nama_resmi']:$dataJurusan[0]['jur_nama_resmi']);
      $this->mrTemplate->AddVar('status_koneksi', 'JUR_NAMA_SINGKAT',empty($dataJurusan[0]['jur_nama_singkat'])?$data['Data']['jur_nama_singkat']:$dataJurusan[0]['jur_nama_singkat']);
      $this->mrTemplate->AddVar('status_koneksi', 'URL_ACTION', Dispatcher::Instance()->GetUrl('jurusan', $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']));

   }
}
?>