<?php

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

class ViewHome extends HtmlResponse {

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

   function ProcessRequest() {
      $menuObj = new Menu();
      $menuObj->LoadSql('module/menu/business/menu.sql.php');
      $menu = $menuObj->ListAllAvailableSubMenuForGroup($_SESSION['username'],$_GET['dmmid']);
      //print_r($menu);exit;
      //return $menu;
		
		// BEGIN : 18 Februari 2013, tampilkan semester aktif
		$appPeriodeObj = new AppPeriode();
		$appPeriode = $appPeriodeObj->GetPeriodeAktif();
		$periodeAktif = $appPeriode[0]['PERIODE'];
		
		$data['menu'] = $menu;
		$data['semester'] = $periodeAktif;
		
		return $data;
		// END
   }
   
   function GetMenuKey ($name, $arrMenu, $len) {
      for ($i=0; $i<$len; $i++) {
         if ($name == $arrMenu[$i]) {
            return  $i;
         }
      }
      return -1;
   }

   function ParseTemplate($data = NULL) {
		
		// BEGIN : 18 Februari 2013, tampilkan semester aktif
		if (!empty($data['semester'])) {
			$this->mrTemplate->addVar('body', 'PERIODE', 'Semester '.$data['semester']);
		}
		// END
		
      if (!empty($data['menu'])) {
		$data = $data['menu'];
         for($i=0;$i<sizeof($data);$i++){
            $url='';
            if($data[$i]['ParentMenuId']=='0'){
               $url = '&dmmid='.$data[$i]['DmMenuId'].'&mid='.$data[$i]['MenuId'];
					$this->mrTemplate->addVar('icon_menu', 'MOUSE_UP', 'onMouseUp="ShowMenu('.$data[$i]['DmMenuId'].')"');
				}
            $this->mrTemplate->addVar('icon_menu', 'LINK_URL', Dispatcher::Instance()->GetUrl($data[$i]['Module'], $data[$i]['SubModule'], $data[$i]['Action'], $data[$i]['Type']).$url);
            $this->mrTemplate->addVar('icon_menu', 'ICON_NAME', $data[$i]['DmIconPath']);
            $this->mrTemplate->addVar('icon_menu', 'LINK_NAME', $data[$i]['MenuName']);
				
            $this->mrTemplate->parseTemplate('icon_menu', 'a');
         }
      }
   }
}
?>
