<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Menu
{
	function Menu()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
	}
	
	function infolist()
	{
		//$GLOBALS['Templ'] -> caching = true;
		//$GLOBALS['Templ'] -> cache_lifetime = 86400 ;
		
		$typeval = $GLOBALS['Reque'] -> reqval["type"];
		
		if($typeval !='' ){
			$this -> getinfolist($typeval);
		}else{
			$this -> getinfolist('web');
		}
	}
	
	function getPower( $reArray = array() )
	{

		if( $_SESSION["emplyeeUser"]["use_name"]!= EMPLOYEE_BASEUSER )
		{
				
				$sqlQuery 	= " SELECT * FROM  ".SQL_PREFIX."userpower  WHERE use_id = '".$_SESSION["emplyeeUser"]["use_id"]."' ORDER BY `use_id` ";
					
				$infoclass 	= $GLOBALS['MySql'] -> selectOne( $sqlQuery );
				
				$usp_actionval = base64_decode($infoclass["usp_action"]);
				
				@eval($usp_actionval);
				//eval( $infoclass["usp_action"] );

				$rereArr = array();

				if(isset($companywebArray) )
				{
					$checkinArray = array_keys( $companywebArray );
					
					//var_dump($checkinArray);
					
					if(is_array($reArray))
					{
						//var_dump($reArray);
						
						foreach($reArray as $keykey => $valval)
						{
							//var_dump($reArray);
							
							if(is_array($valval["array"]))
							{
								foreach($valval["array"] as $gkey => $val)
								{
									if(!in_array($val["men_powername"],$checkinArray))
									{
										unset($reArray[$keykey]["array"][$gkey]);
									 }
								}
								if(count($reArray[$keykey]["array"]) < 1 ){  unset($reArray[$keykey]); }
							}
							
	
						}
					
					}			
						
						return $reArray;
					
					}else{
						return false;
					}
		
		}else{
			return $reArray;
		}
		
	}
	

	
	function getinfolist( $type='' )
	{

		if($type!='')
		{
			$sqlQuery = "SELECT men_id, men_name, men_powername, men_file, men_parentid ,men_targetval   FROM ".SQL_PREFIX."menu WHERE men_enabled = 1 and men_type ='".$type."' GROUP BY men_id ORDER BY men_list , men_id  ";
			$menuInfo = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
			//var_dump( $menuInfo );
			$reArray = array();
			 foreach ($menuInfo as $row)
			 {
				if($row["men_parentid"] == 0)
				{
					$reArray[$row["men_id"]]['men_id'] 			= $row["men_id"] ;
					$reArray[$row["men_id"]]['men_powername'] 	= $row["men_powername"] ;
					$reArray[$row["men_id"]]['men_name'] 		= $row["men_name"] ;
					$reArray[$row["men_id"]]['men_file'] 		= $row["men_file"];
					$reArray[$row["men_id"]]['men_parentid'] 	= $row["men_parentid"];

				}else{
					$reArray[$row["men_parentid"]]['array'][] 	= $row;	
				}
			 }
			 
			$powerArray = $this -> getPower( $reArray );
			
			$GLOBALS['Templ']->assign('menuArray',$powerArray);
			$GLOBALS['Templ']->display('menu_tpl.html');
		}else{
			$GLOBALS['Templ']->display('menu_tpl.html');
		}
	}

}


$Menu = new Menu();

?>