########[------- menus.php -----------]#######
<html>
<head>
<title>Menus beheren</title>
</head>
<body>
<?php
include("config.php");
//Actions
if(isset($_POST['action'])) {
//activate in zone 1
if($_POST['action'] == "act_zone_1") {
$sql = mysql_query("SELECT * FROM menus WHERE menu_zone=1 ORDER BY menu_order ASC"); $naam = $_POST['naam'];
$sql = mysql_query("SELECT * FROM menus WHERE menu_naam='".$naam."'"); rendertable("Fout!", "Het menu is al geactiveerd!", "", "die");
}
$order = $aantalmenus+1;
$insert = mysql_query("INSERT INTO menus (menu_naam, menu_zone, menu_order) VALUES ('".$naam."', 1, '".$order."')") or
die(mysql_error()); }
//activate in zone 2
if($_POST['action'] == "act_zone_2") {
$sql = mysql_query("SELECT * FROM menus WHERE menu_zone=2 ORDER BY menu_order ASC"); $naam = $_POST['naam'];
$sql = mysql_query("SELECT * FROM menus WHERE menu_naam='".$naam."'"); rendertable("Fout!", "Het menu is al geactiveerd!", "", "die");
}
$order = $aantalmenus+1;
$insert = mysql_query("INSERT INTO menus (menu_naam, menu_zone, menu_order) VALUES ('".$naam."', 2, '".$order."')") or
die(mysql_error()); }
//deactivate
if($_POST['action'] == "deac") {
$id = $_POST['menu_id'];
$sql = mysql_query("SELECT * FROM menus WHERE menu_id=".$id); $move_up = mysql_query("UPDATE menus SET menu_order=menu_order-1 WHERE menu_order > ".$menuinfo['menu_order']." AND menu_zone='".$_POST['menu_zone']."'"); }
//move up
if($_POST['action'] == "move_up") {
$id = $_POST['menu_id'];
$sql = mysql_query("SELECT * FROM menus WHERE menu_id=".$id); if($menuinfo['menu_order'] == 1) {
rendertable("Fout!", "Het menu staat al op de hoogste plaats", "", "die");
}
$move_down = mysql_query("UPDATE menus SET menu_order=menu_order+1 WHERE menu_order=".($menuinfo['menu_order']-1)." AND menu_zone='".$_POST['menu_zone']."'");
}
//move down
if($_POST['action'] == "move_down") {
$id = $_POST['menu_id'];
$sql = mysql_query("SELECT * FROM menus WHERE menu_id=".$id); $sql = mysql_query("SELECT * FROM menus WHERE menu_zone='".$_POST['menu_zone']."'"); if($menuinfo['menu_order'] == $aantalmenus) {
rendertable("Fout!", "Het menu staat al op de laagste plaats", "", "die");
}
$move_up = mysql_query("UPDATE menus SET menu_order=menu_order-1 WHERE menu_order=".($menuinfo['menu_order']+1)." AND menu_zone='".$_POST['menu_zone']."'"); }
//move to menu zone 1
if($_POST['action'] == "to_menu_zone_1") {
$id = $_POST['menu_id'];
$sql = mysql_query("SELECT * FROM menus WHERE menu_id=".$id); $sql = mysql_query("SELECT * FROM menus WHERE menu_zone=1"); $to_menu_zone1 = mysql_query("UPDATE menus SET menu_order='".($menuszone1+1)."', menu_zone=1 WHERE menu_id=".$id); $move_up = mysql_query("UPDATE menus SET menu_order=menu_order-1 WHERE menu_order > ".$menuinfo['menu_order']." AND menu_zone='".$_POST['menu_zone']."'"); }
//move to menu zone 2
if($_POST['action'] == "to_menu_zone_2") {
$id = $_POST['menu_id'];
$sql = mysql_query("SELECT * FROM menus WHERE menu_id=".$id); $sql = mysql_query("SELECT * FROM menus WHERE menu_zone=2"); $to_menu_zone2 = mysql_query("UPDATE menus SET menu_order='".($menuszone2+1)."', menu_zone=2 WHERE menu_id=".$id); $move_up = mysql_query("UPDATE menus SET menu_order=menu_order-1 WHERE menu_order > ".$menuinfo['menu_order']." AND menu_zone='".$_POST['menu_zone']."'"); }
}
//get inactive menus
$inactivemenus = "";
while(false !== ($menu = readdir($directory))) { if ($menu != '.' && $menu != '..' && $menu != '') {
$sql = mysql_query("SELECT * FROM menus WHERE menu_naam='".$menu."'"); $inactivemenus .= "
<form action='menus.php' method='post' onchange='this.form.submit()'>
<TABLE bordercolor='#000' cellpadding='0' cellspacing='0' width='100%' class='tablebrdr'>
<tr bgcolor='#0000FF'>
<td class='12px'>".$menu."</td>
</tr>
<tr>
<td class='12px'>
<center><select name='action' onchange='this.form.submit()'>
<option>Activeer - Selecteer zone</option>
<option value='act_zone_1'>Activeer in menu zone 1</option>
<option value='act_zone_2'>Activeer in menu zone 2</option>
</select>
<input type='hidden' name='naam' value='".$menu."'>
</center>
</td>
</tr>
</table><br>
</form>";
}
}
}
if($inactivemenus == "") {
$inactivemenus .= "Geen inactieve menu's";
}
//get active menus in zone 1
$sql = mysql_query("SELECT * FROM menus WHERE menu_zone=1 ORDER BY menu_order ASC"); $activemenus1 = "";
if($aantalmenus == 0) {
$activemenus1 = "Geen menus in deze zone.";
}
$activemenus1 .= "
<form action='menus.php' method='post' onchange='this.form.submit()'>
<TABLE class='tablebrdr' bordercolor='#000' cellpadding='0' cellspacing='0' width='100%'>
<tr bgcolor='#0000FF'>
<td class='12px'>".$menuinfo['menu_naam']."</td>
</tr>
<tr>
<td class='12px'>
<select name='action' onchange='this.form.submit()'>
<option>Optie's...</option>
<option value='deac'>Deactiveer</option>
".($menuinfo['menu_order'] != 1 ? "<option value='move_up'>Omhoog</option>" : "")."
".($aantalmenus != $menuinfo['menu_order'] ? "<option value='move_down'>Omlaag</option>" : "")."
<option value='to_menu_zone_2'>Naar menuzone 2</option>
</select>
<input type='hidden' name='menu_id' value='".$menuinfo['menu_id']."'>
<input type='hidden' name='menu_zone' value='".$menuinfo['menu_zone']."'>
</td>
</tr>
</table><br>
</form>";
}
//get active menus in zone 2
$sql = mysql_query("SELECT * FROM menus WHERE menu_zone=2 ORDER BY menu_order ASC"); $activemenus2 = "";
if($aantalmenus == 0) {
$activemenus2 = "Geen menus in deze zone.";
}
$activemenus2 .= "
<form action='menus.php' method='post' onchange='this.form.submit()'>
<TABLE class='tablebrdr' bordercolor='#000' cellpadding='0' cellspacing='0' width='100%'>
<tr bgcolor='#0000FF'>
<td class='12px'>".$menuinfo['menu_naam']."</td>
</tr>
<tr>
<td class='12px'>
<select name='action' onchange='this.form.submit()'>
<option>Optie's...</option>
<option value='deac'>Deactiveer</option>
".($menuinfo['menu_order'] != 1 ? "<option value='move_up'>Omhoog</option>" : "")."
".($aantalmenus != $menuinfo['menu_order'] ? "<option value='move_down'>Omlaag</option>" : "")."
<option value='to_menu_zone_1'>Naar menuzone 1</option>
</select>
<input type='hidden' name='menu_id' value='".$menuinfo['menu_id']."'>
<input type='hidden' name='menu_zone' value='".$menuinfo['menu_zone']."'>
</td>
</tr>
</table>
<br>
</form>";
}
$text = "
<TABLE border='0' bordercolor='#000' cellpadding='2' cellspacing='2' width='100%'>
<tr bgcolor='#0000FF'>
<td width='20%' bgcolor='#0000FF'>
Zone 1
</td>
<td width='60%' bgcolor='#0000FF'>
In active menu's
</td>
<td width='20%' bgcolor='#0000FF'>
Zone 2
</td>
</tr>
<tr>
<td width='20%' bgcolor='#FFFF00'>
".$activemenus1."
</td>
<td width='60%'>
".$inactivemenus."
</td>
<td width='20%' bgcolor='#FFFF00'>
".$activemenus2."
</td>
</tr>
</table>";
rendertable("Configureer menus", $text);
//-----Functions-------//
function rendertable($caption, $body, $bottom="", $mode="normal") {
$table = "<center><TABLE width='90%' border='1' cellspacing='0' cellpadding='0'></center>";
$table .= "
<TR>
<TD bgcolor='#FF0000'><font class='12px'>".$caption."</font></TD>
</TR>";
}
$table .= "
<TR border='0'>
<TD bgcolor='#F7FDB1'><font class='12px'>".$body."</font></TD>
</TR>";
}
$table .= "
<TR>
<TD bgcolor='#FF0000'><font class='12px'>".$bottom."</font></TD>
</TR>";
}
$table .= "
</TABLE>";
if($mode == "die") {
include("footer.php");
}
}
?>
</body>
</html>
############[----------- config.php --------------]############
<?php
/*
voer deze query uit in phpMyAdmin
CREATE TABLE `menus` (
`menu_id` INT NOT NULL AUTO_INCREMENT ,
`menu_naam` VARCHAR( 100 ) NOT NULL ,
`menu_order` INT NOT NULL ,
`menu_zone` INT NOT NULL ,
PRIMARY KEY ( `menu_id` )
);
*/
//hier de database gegevens
$host = "127.0.0.1";
$user = "root";
$pass = "";
$db = "menus";
/*
Om de menus te laten zien op je pagina moet je de volgende code ergens zetten om de menus
uit zone 1 te krijgen:
deze code haalt de menus van zone 1 uit de DB, deze zet je bijv. in je header file
$menus = mysql_query("SELECT * FROM menus WHERE menu_zone=1 ORDER BY menu_order ASC");
while($menuinfo = mysql_fetch_array($menus)) {
if(file_exists("menus/".$menuinfo['menu_naam']."/".$menuinfo['menu_naam'].".php")) {
include("menus/".$menuinfo['menu_naam']."/".$menuinfo['menu_naam'].".php");
echo "<br>";
}
}
deze code haalt de menus van zone 2 uit de DB, deze zet je bijv. in je footer file
$menus = mysql_query("SELECT * FROM menus WHERE menu_zone=2 ORDER BY menu_order ASC");
while($menuinfo = mysql_fetch_array($menus)) {
if(file_exists("menus/".$menuinfo['menu_naam']."/".$menuinfo['menu_naam'].".php")) {
include("menus/".$menuinfo['menu_naam']."/".$menuinfo['menu_naam'].".php");
echo "<br>";
}
}
*/
?>