<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/periode/business/AppPeriode.class.php';

class ViewInputPeriode extends HtmlResponse {
	
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/periode/template');
		$this->SetTemplateFile('input_periode.html');
	}
	
	function ProcessRequest() {
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$prdObj = new AppPeriode();
		
		$msg = Messenger::Instance()->Receive(__FILE__);
		$return['Pesan'] = $msg[0][1];
		$return['Data'] = $msg[0][0];

		$dataPeriode = $prdObj->GetDataPeriodeById($idDec);
      $dataNamaPeriode = $prdObj->GetComboNamaPeriode();
      $dataTahun=$prdObj->GetTahun();
      
      if ($_REQUEST['dataId']=='') {
         $tahunAkademik = $_SESSION['tahun'];
         $periode = $_SESSION['semester'];
      }else{
         if($msg[0][0]){
            $periode=$msg[0][0]['semester'];
         }else{
            $periode=$dataPeriode[0]['sem_id'];
         }
         
         if(($idDec=='') and (empty($msg[0][0]['tahun']))){
         $tahunAkademik='';
         }else{
         $tahunAkademik=empty($dataPeriode[0]['tahun'])?$msg[0][0]['tahun']:$dataPeriode[0]['tahun'];     
         } 
      }
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'semester', 
         array('semester',$dataNamaPeriode,$periode,'false',''), Messenger::CurrentRequest);
      
      //combo tahun Akademik    
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'tahun',
         array('tahun',$dataTahun,$tahunAkademik,'false',''), 
            Messenger::CurrentRequest);
		
      $periodeAkhir = $prdObj->GetPeriodeAkhir();

		$return['decDataId'] = $idDec;
		$return['dataPeriode'] = $dataPeriode;
      $return['tahun'] = $tahunAkademik;
      $return['semester'] = $periode;
		return $return;
	}

	function ParseTemplate($data = NULL) {
      $tahun = $_SESSION['tahun'];
      $periode = $_SESSION['semester'];
      #print_r($_SESSION['tahun']);
      
		if ($data['Pesan']) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['Pesan']);
		}
		$dataPeriode = $data['dataPeriode'];

		if ($_REQUEST['dataId']=='') {
			$url="addPeriode";
			$tambah="Tambah";
		} else {
			$url="updatePeriode";
			$tambah="Ubah";
		}
		
		$this->mrTemplate->AddVar('content', 'JUDUL', $tambah);
      $this->mrTemplate->AddVar('content', 'URL_ACTION', Dispatcher::Instance()->GetUrl('periode', $url, 'do', 'html') . "&dataId=" . Dispatcher::Instance()->Encrypt($data['decDataId']));
		$this->mrTemplate->AddVar('content', 'DATAID', Dispatcher::Instance()->Decrypt($_GET['dataId']));
		$this->mrTemplate->AddVar('content', 'PAGE', Dispatcher::Instance()->Decrypt($_GET['page']));
	}
}
?>
