<?php
	session_start();

	if (isset($_SESSION["pendiente"]) && (($_SESSION["pendiente"] != "") && ($_SESSION["perfil"] == "E") && ($_SESSION["opcion"] == "3")) || (($_SESSION["alumno"] == "11111111a") && (($_SESSION["opcion"] == "2") || ($_SESSION["opcion"] == "3")))){

	} else {
		if (isset($_SESSION["opcion"]) && ($_SESSION["opcion"] != "")) {
			$opcion = $_SESSION["opcion"];
		} else {
			$opcion = "1";
		}

		$query = "SELECT * FROM opciones WHERE flagver = '1' AND id_padre = '".$opcion."'";

		if($_SESSION["user_logged"] == "1"){
			if($_SESSION["perfil"] == "E"){
				$query .= " AND nivel <= '1'";
			} elseif ($_SESSION["perfil"] == "A"){
				$query .= " AND nivel <= '2'";
			} else {
				$query .= " AND nivel = '0'";
			}
		}

		$query .= " ORDER BY `id`";

		$result = mysql_query($query,$conn) or die(mysql_error());

		$patron = "javascript";

	?>
	    <ul class="menu_lateral">
	<?php
	    while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

	    	$q_subopcion = "SELECT * FROM opciones WHERE flagver = '1' AND id_padre = '".$row["id"]."'";
	    	$r_subopcion = mysql_query($q_subopcion,$conn) or die(mysql_error());

	    	$jsfunction = stripos($row["accion"],$patron);

	    	if ($_SESSION["opcion"] == "1" and $_SESSION["pestanya"] == $row["accion"]) {
	    		$accion = "";
	    	} else if ($jsfunction !== false){
	    		$accion = $row["accion"];
	    	} else {
	    		$accion = $row["accion"].".php";
	    	}


	    	if ((($_SESSION["perfil"] == "A") && (($row["id"] == 15) || ($_SESSION["opcion"] != "3") || ($_SESSION["pendiente"] == ""))) || ($_SESSION["perfil"] != "A")){

	?>
		    	<li><a href='<?=$accion?>' title='<?=$row['titulo']?>'><?=$row['titulo']?></a></li>
				<ul class="menu_lateral submenu">
	<?php
		    	while($res_subopcion = mysql_fetch_array($r_subopcion,MYSQL_ASSOC)){
		    		$jsfunction2 = stripos($res_subopcion["accion"],$patron);

		    		if ($_SESSION["opcion"] == "1" and $_SESSION["pestanya"] == $res_subopcion["accion"]) {
		    			$accion = "";
		    		} else if ($jsfunction2 !== false){
		    			$accion = $res_subopcion["accion"];
		    		} else {
		    			$accion = $res_subopcion["accion"].".php";
		    		}
		    		echo "<li><a href='".$accion."' title='" . $res_subopcion['titulo'] . "'>" . $res_subopcion['titulo'] . "</a></li>";
		    	}
		    	echo "</ul>";
	    	}
	    }
	?>
	    </ul>
<?php } ?>