<?PHP

class menu extends engine{

	var $call_sql_class = array('menus');
	var $clone_class = array(
		array('menus' => 'parent_menus'),
		array('menus' => 'parent_menus_2')
	);

	function get_sitemap_data(){

		$this->recursive_menu('', 0);
		return $this;
	}
	function adminmenu(){

		$this->menus->useMethod(array($this, 'parent_menus'));
		$this->menus->admin_menus();

		return $this;
	}

	function get_public_menus($position){

		$this->menu_list = array();
		$this->recursive_menu($position, 0);

		return $this;
	}

	function recursive_menu($position, $id, $counter = 1){

		$this->menus->public_menu($position, "p1.parent_id = ".$id, "ASC");
		$result = $this->menus->Result;
		while($row = mysqli_fetch_Assoc($result)){

			$row['counter'] = $counter;
			$this->menu_list[] = $row;
			$this->recursive_menu($position, $row['id'], $counter+1);
		}
	}

	function parent_menus($row){

		$this->parent_menus->useMethod(array($this, 'parent_menus_2'));
		$this->parent_menus->parent_menu("p1.parent_id = ".$row['id']." AND p3.role_id = ".($_SESSION['UserData']['role_id'])." ");

		if(!$row['url'])
			$row['url'] = '?model='.$row['model'].'&page='.$row['page'];

		return $row;
	}

	function parent_menus_2($row){

		$this->parent_menus_2->parent_menu("p1.parent_id = ".$row['id']." AND p3.role_id = ".($_SESSION['UserData']['role_id'])." ");

		if(!$row['url'])
			$row['url'] = '?model='.$row['model'].'&page='.$row['page'];

		return $row;
	}
}

?>