<?php
class SableDashboard
{
	var  $dashboardTitle, $menuItems = array();
	
	// constructor method
	public function __construct(){}
	
	private function getMenuSection($module, $type, $minAccessLevel)
	{		
		$ttl = SableGeneralFunctions::getFormattedModuleName($module);		
		$typ = strtolower($type);
		$tp	 = (empty($type)||$typ==="index")?'Manage':ucfirst($type); //can be blank for index.html
		
		$itm = strtolower($module).'/'.$typ.'.php';
		if (($ttl==='User')&&($tp==='Edit'))
		{
			$ttl	= 'My Profile';
			$itm 	.= '+'.$_SESSION['user']['user_code'].'+'.session_id();
			$href = SABLE_URL_ROOT.'index.php?'.SableSystem::sableEncode($itm);
		}	
		else 
		{
			$param = '';
			$href = SableSystem::getSableLinkPath($itm); 
		}
		$html	= 
		'<a href="'.$href.'">'.$tp.' '.$ttl.'</a><br />';
		$val = $_SESSION['user']['access_level']>=$minAccessLevel?$html:'';
		return $val;
	}
	
	protected function getListItemSection($module, $minAccessLevel)
	{					
		$ttl = SableGeneralFunctions::getFormattedModuleName($module);
			
		$menuItems = $this->getMenuSection($module, 'add',	9).$this->getMenuSection($module, 'index',	1);
		if ($ttl==='User') $menuItems .= $this->getMenuSection($module, 'edit', 6);		
		$html = '<li>
					<div class="ch-item ch-img-dash-users"">
						<div class="ch-info">
							<h3 class="pointer">'.$ttl.'</h3>
							<p>'.$menuItems.'</p>
						</div>
					</div>
				</li>';
		$val = $_SESSION['user']['access_level']>=$minAccessLevel?$html:'';
		return $val;				
	}
	
	private function getMenuSections()
	{
		$html = '';
		for($i=0; $i<sizeof($this->menuItems); $i++)
		{
			/*
			$this->menuItems will be a mutli-dimensional array with the instance [0] being the module name
			and instance [1] being the min access level.
			*/
			$html .= $this->getListItemSection(strtolower($this->menuItems[$i][0]), $this->menuItems[$i][1]);
		}
		return $html;
	}
	
	public function printMenu()
	{
		/*
		This is a standard menu layout for Sable. 
		To have your own menu, extend the class and create an override version of printMenu()
		*/
		$html ='
		<!-- // MENU -->
		<div class="loginContent">
			<div class="container">
				<h1 class="title"><i class="fa fa-tachometer-alt" aria-hidden="true"></i>&nbsp;'.$this->dashboardTitle.'</h1>
				<div class="forms-grids">
					<section class="main">
						<ul class="ch-grid">
							<li>
								<div class="ch-item ch-img-dash-users"">
									<div class="ch-info">
										<h3 class="pointer"><a href="'.SableSystem::getCallPageLink('login/logout.php').'">Log Out</a></h3>
									</div>
								</div>
							</li>'.
							$this->getMenuSections().
						'</ul>
					</section>
				</div>
			</div>
		</div>
		<!-- MENU //-->';
		echo($html);
	}
	
	// destructor method
	public function __destruct(){}	
}
?>