<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/jenis_semester/business/AppJenisSemesterToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/jenis_semester/business/AppJenisSemesterToFinansi.class.php';
class ViewInputJenisSemester extends HtmlResponse {
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/jenis_semester/template');
		$this->SetTemplateFile('input_jenis_semester.html');
	}
   
   function ProcessRequest(){
      $jSemsObj=new AppJenisSemesterToSia();
      $jSemsObjFinansi=new AppJenisSemesterToFinansi();
      $idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
      $dataJSems=$jSemsObj->GetJenisSemesterById($idDec);
      $msg = Messenger::Instance()->Receive(__FILE__);  
     
     if(!$jSemsObjFinansi->addConn)
         $return['finansiConn']=false;
      else
         $return['finansiConn']=true;

      $dataKategori[0]['id']="R";
      $dataKategori[0]['name']="Reguler";      
      $dataKategori[1]['id']="N";
      $dataKategori[1]['name']="Non Reguler";      
      
      $dataPeriode[0]['id']="1";
      $dataPeriode[0]['name']="Semester I";      
      $dataPeriode[1]['id']="2";
      $dataPeriode[1]['name']="Semester II";
      

      $kategori=empty($dataJSems[0]['sems_kategori'])?$msg[0][0]['kategori]']:$dataJSems[0]['sems_kategori'];
      $periode=empty($dataJSems[0]['sems_periode'])?$msg[0][0]['periode]']:$dataJSems[0]['sems_periode'];

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'kategori',
         array('kategori',$dataKategori,$kategori,'false',''), Messenger::CurrentRequest) ;     
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'periode',
         array('periode',$dataPeriode,$periode,'false',''), Messenger::CurrentRequest) ;  
         
      $return['Pesan'] = $msg[0][1];
		$return['Data'] = $msg[0][0];
      $return['decDataId'] = $idDec;
		$return['dataJSems'] = $dataJSems;
      return $return;
   }
   function ParseTemplate($data=null){
      $dataJSems=$data['dataJSems'];
      $finansiConn=$data['finansiConn'];

      if($finansiConn==false){
      	$this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
			$this->mrTemplate->AddVar('warning', 'ISI_PESAN_SIA', 'Gagal Menghubungi SI Finansi');
         $url_kembali=Dispatcher::Instance()->GetUrl('jenis_semester', 'jenisSemester', 'view', 'html');
         $this->mrTemplate->AddVar('warning', 'URL_KEMBALI_SIA',$url_kembali );
      }elseif($finansiConn==true){
         $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']);
		}
      
      if ($_REQUEST['dataId']=='') {
			$url="addJenisSemester";
			$tambah="Tambah";
		} else {
			$url="updateJenisSemester";
			$tambah="Ubah";
		}
      $this->mrTemplate->AddVar('status_koneksi', 'JUDUL', $tambah);
      $this->mrTemplate->AddVar('status_koneksi', 'DATAID', Dispatcher::Instance()->Decrypt($_GET['dataId']));
		$this->mrTemplate->AddVar('status_koneksi', 'PAGE', Dispatcher::Instance()->Decrypt($_GET['page']));
      $this->mrTemplate->AddVar('status_koneksi', 'SEMS_LABEL', empty($dataJSems[0]['sems_label'])?$data['Data']['label']:$dataJSems[0]['sems_label']);
		$this->mrTemplate->AddVar('status_koneksi', 'SEMS_LABEL_SINGKAT',empty($dataJSems[0]['sems_label_singkat'])?$data['Data']['label_singkat']:$dataJSems[0]['sems_label_singkat']);
		$this->mrTemplate->AddVar('status_koneksi', 'URL_ACTION', Dispatcher::Instance()->GetUrl('jenis_semester', $url, 'do', 'html') . "&dataId=" . Dispatcher::Instance()->Encrypt($data['decDataId']));

   }
}
?>