Location: PHPKode > projects > Monyet > classes/navigation.php
<?php

//this class get array of allowed access from privileges
//invoked in controllerbase

Class Navigation {

	private $menu;
	private $submenu;
	private $allowed_access;

	public function __construct($allowed_access){
		$this->allowed_access = $allowed_access;
	}
	public function getMenu($type){

		//menu[0] for GUEST
		//menu[1] to build public page for authenticated user
		//menu[2] for administrator private page

		$this->menu = array();
		if(array_key_exists('index',$this->allowed_access)){
			$this->menu[0]['index/index']='home';
			$this->menu[1]['index/index']='home';
			$this->menu[2]['index/index']='monyet!';
		}
		if(array_key_exists('admin',$this->allowed_access)){
			$this->menu[2]['admin/index']='admin';
		}
		if(array_key_exists('managecontent',$this->allowed_access)){
			$this->menu[2]['managecontent/index']='content';
		}
		
		if(array_key_exists('reports',$this->allowed_access)){
			$this->menu[0]['reporst/index']='reports';
			$this->menu[1]['index/index']='home';
		}
		if(array_key_exists('authentication',$this->allowed_access)){
			$this->menu[0]['authentication/login']='maintenance';
			$this->menu[1]['admin/index']='maintenance';
		}
		if(array_key_exists('systemstat',$this->allowed_access)){
			$this->menu[0]['systemstat/summary']='status';
			$this->menu[1]['systemstat/summary']='status';
			$this->menu[1]['systemstat/buildmarquee']='refresh';
		}
		if(array_key_exists('feedback',$this->allowed_access)){
			$this->menu[0]['feedback/index']='feedback';
			$this->menu[1]['index/index']='home';
		}
		
		//menu administrator
		if(array_key_exists('manageagent',$this->allowed_access)){
			$this->menu[2]['manageagent/index']='agent';
		}
		if(array_key_exists('manageautomate',$this->allowed_access)){
			$this->menu[2]['manageautomate/index']='automate';
		}
		if(array_key_exists('manageping',$this->allowed_access)){
			$this->menu[2]['manageping/index']='ping';
		}
		if((array_key_exists('manageservice',$this->allowed_access))&&(array_key_exists('manageservicemon',$this->allowed_access))){
			$this->menu[2]['manageservice/index']='service';
		}else
		if(array_key_exists('manageservice',$this->allowed_access)){
			$this->menu[2]['manageservice/index']='service';
		}
		else
		if(array_key_exists('manageservicemon',$this->allowed_access)){
			$this->menu[2]['manageservicemon/index']='service';
		}
		if(array_key_exists('managesnmpdef',$this->allowed_access)){
			$this->menu[2]['managesnmpdef/index']='snmp';
		}
		
		if(array_key_exists('manageservice',$this->allowed_access)){
			$this->menu[2]['manageservice/index']='service';
		}
		if(array_key_exists('manageuser',$this->allowed_access)){
			$this->menu[2]['manageuser/index']='user';
		}
		if((array_key_exists('managegroup',$this->allowed_access))&&(array_key_exists('manageprivileges',$this->allowed_access))){
			$this->menu[2]['managegroup/index']='group';
		}else
		if(array_key_exists('manageprivileges',$this->allowed_access)){
			$this->menu[2]['manageprivileges/index']='group';
		}
		else
		if(array_key_exists('managegroup',$this->allowed_access)){
			$this->menu[2]['managegroup/index']='group';
		}
		if(array_key_exists('managenews',$this->allowed_access)){
			$this->menu[2]['managenews/index']='news';
		}
		if(array_key_exists('managesms',$this->allowed_access)){
			$this->menu[2]['managesms/index']='sms';
		}
		return $this->menu[$type];
	}
	public function getSubMenu($obj){
		$this->submenu = array();	  
		if(($obj instanceof ManageGroup)||($obj instanceof ManagePrivileges)){
			if(isset($this->allowed_access['managegroup'])){
				$this->submenu['javascript:sndReq(\'managegroup/show\')'] = 'browse group';
				if($this->allowed_access['managegroup']=='Write'){
					$this->submenu['javascript:sndReq(\'managegroup/add\')'] = 'add group';
				}
			}
			if(isset($this->allowed_access['manageprivileges'])){
				$this->submenu['javascript:sndReq(\'manageprivileges/show\')'] = 'show privileges';
				if($this->allowed_access['manageprivileges']=='Write'){
					$this->submenu['javascript:sndReq(\'manageprivileges/add\')'] = 'add privileges';
				}
			}
			$this->submenu[] = 'break';
			if(array_key_exists('manageuser',$this->allowed_access)){
				$this->submenu['javascript:sndReq(\'manageuser/index\')'] = 'user management';
			}
		
		}
		else
		if($obj instanceof ManageContent){
			$this->submenu['javascript:sndReq(\'managecontent/show\')'] = 'browse content';
			if($this->allowed_access['managecontent']=='Write'){
				$this->submenu['javascript:sndReq(\'managecontent/add\')'] = 'add content';
			}
		}
		else
		if($obj instanceof ManageNetworkMap){
			$this->submenu['javascript:sndReq(\'managenetworkmap/index\')'] = 'show current map';
			if($this->allowed_access['networkmapagent']=='Write'){
				$this->submenu['javascript:sndReq(\'networkmapagent/add\')'] = 'add agent to draw';
			}
			$this->submenu['javascript:sndReq(\'networkmapnet/add\')'] = 'add net';
			$this->submenu['javascript:sndReq(\'managenetrelation/add\')'] = 'add relationship';
		}
		else
		if($obj instanceof ManagePing){
			$this->submenu['javascript:sndReq(\'manageping/show\')'] = 'browse ping';
			if($this->allowed_access['manageping']=='Write'){
				$this->submenu['javascript:sndReq(\'manageping/add\')'] = 'add ping';
			}
			$this->submenu[] = 'break';
			if(array_key_exists('manageagent',$this->allowed_access)){
				$this->submenu['javascript:sndReq(\'manageagent/index\')'] = 'agent management';
			}
		}
		else
		if($obj instanceof ManageSNMPDef){
			$this->submenu['javascript:sndReq(\'managesnmpdef/show\')'] = 'browse definition';
			if($this->allowed_access['managesnmpdef']=='Write'){
				$this->submenu['javascript:sndReq(\'managesnmpdef/add\')'] = 'add definition';
			}
			if(isset($this->allowed_access['managesnmpmon'])){
				$this->submenu['javascript:sndReq(\'managesnmpmon/show\')'] = 'show monitoring';
				if($this->allowed_access['managesnmpmon']=='Write'){
					$this->submenu['javascript:sndReq(\'managesnmpmon/add\')'] = 'add monitoring';
				}
			}
			$this->submenu[] = 'break';
			if(array_key_exists('manageagent',$this->allowed_access)){
				$this->submenu['javascript:sndReq(\'manageagent/index\')'] = 'agent management';
			}
		}
		else
		if($obj instanceof ManageAgent){
			$this->submenu['javascript:sndReq(\'manageagent/show\')'] = 'browse agent';
			if($this->allowed_access['manageagent']=='Write'){
				$this->submenu['javascript:sndReq(\'manageagent/add\')'] = 'add agent';
			}
			$this->submenu[] = 'break';
			//FIXME: lil bit rough.. please clean it when you have a time
			$this->submenu['javascript:sndReq(\'managenetworkmap/index\')'] = 'manage network map';
			$this->submenu[] = 'break';
			if(array_key_exists('manageping',$this->allowed_access)){
				$this->submenu['javascript:sndReq(\'manageping/index\')'] = 'ping monitoring';
			}
			if(array_key_exists('manageservicemon',$this->allowed_access)){
				$this->submenu['javascript:sndReq(\'manageservicemon/index\')'] = 'service monitoring';
			}
		}
		else
		if(($obj instanceof ManageService)||($obj instanceof ManageServiceMon)){
			if(isset($this->allowed_access['manageservice'])){
				$this->submenu['javascript:sndReq(\'manageservice/show\')'] = 'browse definition';
				if($this->allowed_access['manageservice']=='Write'){
					$this->submenu['javascript:sndReq(\'manageservice/add\')'] = 'add definition';
				}
			}
			if(isset($this->allowed_access['manageservicemon'])){
				$this->submenu['javascript:sndReq(\'manageservicemon/show\')'] = 'show monitoring';
				if($this->allowed_access['manageservicemon']=='Write'){
					$this->submenu['javascript:sndReq(\'manageservicemon/add\')'] = 'add monitoring';
				}
			}
			$this->submenu[] = 'break';
			if(array_key_exists('manageagent',$this->allowed_access)){
				$this->submenu['javascript:sndReq(\'manageagent/index\')'] = 'agent management';
			}
		

		}
		else
		if($obj instanceof ManageUser){
			$this->submenu['javascript:sndReq(\'manageuser/show\')'] = 'browse user';
			if($this->allowed_access['manageuser']=='Write'){
				$this->submenu['javascript:sndReq(\'manageuser/add\')'] = 'add user';
				$this->submenu['javascript:sndReq(\'manageuser/changepass\')'] = 'change password';
			}
			$this->submenu[] = 'break';
			if(array_key_exists('managegroup',$this->allowed_access)){
				$this->submenu['javascript:sndReq(\'managegroup/index\')'] = 'group management';
			}

		}else
		if($obj instanceof ManageNews){
			$this->submenu['javascript:sndReq(\'managenews/show\')'] = 'browse news';
			if($this->allowed_access['managenews']=='Write'){
				$this->submenu['javascript:sndReq(\'managenews/add\')'] = 'add news';
			}
		}
		else
		if($obj instanceof ManageAutomate){
			$this->submenu['javascript:sndReq(\'manageautomate/show\')'] = 'browse definition';
			if($this->allowed_access['manageautomate']=='Write'){
				$this->submenu['javascript:sndReq(\'manageautomate/add\')'] = 'add definition';
			}
		}
		else
		if($obj instanceof Admin){
			$this->submenu['javascript:sndReq(\'doc/index\')'] = 'Documentation';
			$this->submenu['javascript:sndReq(\'doc/changelogs\')'] = 'Changelogs';
			$this->submenu['javascript:sndReq(\'doc/howto\')'] = 'Quick How To';
		}
		else
		if($obj instanceof SystemStat){
			$this->submenu['javascript:sndReq(\'systemstat/netmapstatus\')'] = 'Network Map';
			$this->submenu['javascript:sndReq(\'systemstat/summary\')'] = 'Status Summary';
			$this->submenu[] = 'break';
		}
		else
		if($obj instanceof ManageSMS){
			$this->submenu['javascript:sndReq(\'managesms/show\')'] = 'Show SMS Buffer';
			$this->submenu['javascript:sndReq(\'managesms/truncate\')'] = 'Truncate Old SMS';
		}
		return $this->submenu;	
	}
	public function getAccess($obj){
		$result = '';
		$r = new ReflectionClass($obj);
		$classname = strtolower($r->getName());
		if($this->allowed_access[$classname]=='Write'){
			return $classname;
		}
		return $result;
	}	
}
?>
Return current item: Monyet