<?php
	session_start();

	include("auth.inc.php");
	include_once("conn.inc.php");

	if (isset($_POST["tablas"]) || (isset($_SESSION["tablas"]))) {
		if (isset($_POST["tablas"])) {
			$_SESSION["tablas"] = $_POST["tablas"];
			$tabla = $_POST["tablas"];
		} else {
			$tabla = $_SESSION["tablas"];
		}

		if ($tabla == "") {
			$display_tablas = "block";
			$display_titu = "none";
			$display_info_tablas = "none";
		} else {
			$display_tablas = "none";
			$display_titu = "none";
			$display_info_tablas = "block";
		}

		$selected_user = "";
		$selected_matr = "";
		$selected_asig = "";
		$selected_news = "";
		$selected_link = "";
		$selected_tari = "";
		$selected_liqu = "";

		if ($_POST["tablas"] == "usuarios") {
			$selected_user = "selected";
		} else if ($_POST["tablas"] == "matriculas") {
			$selected_matr = "selected";
		} else if ($_POST["tablas"] == "asignaturas") {
			if (isset($_POST["titul_selecc"])) {
				$_SESSION["titul_selecc"] = $_POST["titul_selecc"];
				$titulo = $_SESSION["titul_selecc"];

				$display_info_tablas = "block";
				$display_tablas = "none";
				$display_titu = "none";
			} else {
				$selected_asig = "selected";
				$display_info_tablas = "none";
				$display_tablas = "block";
				$display_titu = "block";
			}

			$query = "SELECT * FROM titulaciones ORDER BY 'id'";
			$r_query = mysql_query($query,$conn);

			$titulos = "<select name=\"titul_selecc\" onchange =\"javascript:f_titulos.submit();\" >\n";
			$titulos .="<option value =\"\" selected>Seleccione una titulaci&oacute;n</option>\n";

			while ($result = mysql_fetch_array($r_query,MYSQL_ASSOC)) {
				$titulos .= "<option value=".$result["id"];
				if ($result["id"] == $titulo) {
					$titulos .=" selected";
				}
				$titulos .=">".$result["codigo"]." - ".$result["descripcion"]."</option>";
			}

			$titulos .= "</select>";

		} else if ($_POST["tablas"] == "noticias") {
			$selected_news = "selected";
		} else if ($_POST["tablas"] == "enlaces") {
			$selected_link = "selected";
		} else if ($_POST["tablas"] == "tarifa") {
			$selected_tari = "selected";
		} else if ($_POST["tablas"] == "liquidacion") {
			$selected_liqu = "selected";
		} else {
			$selected_user = "";
			$selected_matr = "";
			$selected_asig = "";
			$selected_news = "";
			$selected_link = "";
			$selected_tari = "";
			$selected_liqu = "";
		}
	} else {
		$display_tablas = "block";
		$display_info_tablas = "none";
		$display_titu = "none";
	}
?>
<div id="tablas" style="display:<?=$display_tablas?>">
	<div class="msg_admin" align="center">Gesti&oacute;n de la aplicaci&oacute;n<div style="font-size:10px;">Seleccione el &aacute;rea que desee gestionar.</div></div>
	<div id="lista_tablas">
		<form id="f_tablas" method="post" action="inicio.php">
			<select name="tablas" onchange="javascript:f_tablas.submit();" title="tablas administrables">
				<option value ="" selected style="font-weight:bold;">Areas de gesti&oacute;n</option>
				<option value ="usuarios" <?=$selected_user?>>Gesti&oacute;n de usuarios</option>
				<option value ="matriculas" <?=$selected_matr?>>Gesti&oacute;n de matr&iacute;culas</option>
				<option value ="asignaturas" <?=$selected_asig?>>Gesti&oacute;n de asignaturas</option>
				<option value ="noticias" <?=$selected_news?>>Gesti&oacute;n de noticias</option>
				<option value ="enlaces" <?=$selected_link?>>Gesti&oacute;n de enlaces</option>
				<option value ="tarifa" <?=$selected_tari?>>Gesti&oacute;n de tarifas</option>
				<option value ="liquidacion" <?=$selected_liqu?>>Gesti&oacute;n de liquidaciones</option>
			</select>
			<input type="hidden" name="opcion" id="opcion" value="4">
		</form>
	</div>
	<div id="lista_titulos" style="display:<?=$display_titu?>">
		<form id="f_titulos" method="post" action="inicio.php">
			<?=$titulos?>
			<input type="hidden" name="tablas" id="tablas" value="asignaturas">
			<input type="hidden" name="opcion" id="opcion" value="4">
		</form>
	</div>
</div>

<?php if ((isset($_POST["tablas"])) || ((isset($_SESSION["tablas"])))) {?>
<div id="admin_tablas" style="display:<?=$display_info_tablas?>;">
	<div id="msg_gestion" class="msg_gestion" align="center">Gesti&oacute;n de <?=$tabla?></div>
	<?php
	switch ($tabla) {
		case usuarios: include_once("admin_usuarios.php");
			break;
		case matriculas: include_once("admin_matriculas.php");
			break;
		case asignaturas: include_once("admin_asignaturas.php");
			break;
		case noticias: include_once("admin_noticias.php");
			break;
		case enlaces: include_once("admin_enlaces.php");
			break;
		case tarifa: include_once("admin_tarifas.php");
			break;
		case liquidacion: include_once("admin_liquidacion.php");
			break;

		default:
			break;
	}
	?>
</div>
<?php } ?>