login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Navigatie systemen > Menu Systeem

Menu Systeem

Auteur: LuckyLuke - 23 november 2004 - 20:45 - Gekeurd door: Dennisvb - Hits: 11522 - Aantal punten: 1.13 (15 stemmen)




Een menu systeem, hiemree kan je heel gemakkelijk menuutjes beheren. 

Je kan menuutjes deactiveren, activeren, omhoog en omlaag verplaatsen, naar een andere zone verplaatsen.

Het script heeft 2 menu zones. Ook heb ik niks aan de lay-out gedaan.

Instructies:
-Maak een map in de map waar het bestand menus.php in staat. Noem die map menus.

-Voer de volgende query uit in je DB:
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` )
);

-Verander de variablen in config.php
-om een menu toe te voegen maak je een map in de map menus.
Noem die map naar de titel van jou menu.
In die map die je net hebt gemaakt maak je een PHP bestand aan met precies de zelfde naam als de map.

Ga naar menus.php en activeer hem in de zone die jij wil.

Om de menus uit de DB te halen doe je het volgende:
Voor menus uit zone 1 zet je bijv. in je header dit:
$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>";
}

voor zone 2, bijv. in je footer:
$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>";
}

Nou dat het was het denk ik wel, voor vragen/bugs opmerkingen kun je altijd een comment plaatsen

Code:
  1. ########[------- menus.php -----------]#######
  2. <html>
  3. <head>
  4. <title>Menus beheren</title>
  5. </head>
  6. <body>
  7. <?php
  8. include("config.php");
  9.  
  10. //Actions
  11. if(isset($_POST['action'])) {
  12.  
  13. //activate in zone 1
  14. if($_POST['action'] == "act_zone_1") {
  15. $sql = mysql_query("SELECT * FROM menus WHERE menu_zone=1 ORDER BY menu_order ASC");
  16. $aantalmenus = mysql_num_rows($sql);
  17. $naam = $_POST['naam'];
  18. $sql = mysql_query("SELECT * FROM menus WHERE menu_naam='".$naam."'");
  19. if(mysql_num_rows($sql) > 0) {
  20. rendertable("Fout!", "Het menu is al geactiveerd!", "", "die");
  21. }
  22. $order = $aantalmenus+1;
  23. $insert = mysql_query("INSERT INTO menus (menu_naam, menu_zone, menu_order) VALUES ('".$naam."', 1, '".$order."')") or die(mysql_error());
  24. }
  25.  
  26. //activate in zone 2
  27. if($_POST['action'] == "act_zone_2") {
  28. $sql = mysql_query("SELECT * FROM menus WHERE menu_zone=2 ORDER BY menu_order ASC");
  29. $aantalmenus = mysql_num_rows($sql);
  30. $naam = $_POST['naam'];
  31. $sql = mysql_query("SELECT * FROM menus WHERE menu_naam='".$naam."'");
  32. if(mysql_num_rows($sql) > 0) {
  33. rendertable("Fout!", "Het menu is al geactiveerd!", "", "die");
  34. }
  35. $order = $aantalmenus+1;
  36. $insert = mysql_query("INSERT INTO menus (menu_naam, menu_zone, menu_order) VALUES ('".$naam."', 2, '".$order."')") or die(mysql_error());
  37. }
  38.  
  39. //deactivate
  40. if($_POST['action'] == "deac") {
  41. $id = $_POST['menu_id'];
  42. $sql = mysql_query("SELECT * FROM menus WHERE menu_id=".$id);
  43. $menuinfo = mysql_fetch_array($sql);
  44. $delete = mysql_query("DELETE FROM menus WHERE menu_id='".$_POST['menu_id']."'") or die(mysql_error());
  45. $move_up = mysql_query("UPDATE menus SET menu_order=menu_order-1 WHERE menu_order > ".$menuinfo['menu_order']." AND menu_zone='".$_POST['menu_zone']."'");
  46. }
  47.  
  48. //move up
  49. if($_POST['action'] == "move_up") {
  50. $id = $_POST['menu_id'];
  51. $sql = mysql_query("SELECT * FROM menus WHERE menu_id=".$id);
  52. $menuinfo = mysql_fetch_array($sql);
  53. if($menuinfo['menu_order'] == 1) {
  54. rendertable("Fout!", "Het menu staat al op de hoogste plaats", "", "die");
  55. }
  56. $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']."'");
  57. $move_up = mysql_query("UPDATE menus SET menu_order=menu_order-1 WHERE menu_id=".$id) or die(mysql_error());
  58.  
  59. }
  60.  
  61. //move down
  62. if($_POST['action'] == "move_down") {
  63. $id = $_POST['menu_id'];
  64. $sql = mysql_query("SELECT * FROM menus WHERE menu_id=".$id);
  65. $menuinfo = mysql_fetch_array($sql);
  66. $sql = mysql_query("SELECT * FROM menus WHERE menu_zone='".$_POST['menu_zone']."'");
  67. $aantalmenus = mysql_num_rows($sql);
  68. if($menuinfo['menu_order'] == $aantalmenus) {
  69. rendertable("Fout!", "Het menu staat al op de laagste plaats", "", "die");
  70. }
  71. $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']."'");
  72. $move_down = mysql_query("UPDATE menus SET menu_order=menu_order+1 WHERE menu_id=".$id) or die(mysql_error());
  73. }
  74.  
  75. //move to menu zone 1
  76. if($_POST['action'] == "to_menu_zone_1") {
  77. $id = $_POST['menu_id'];
  78. $sql = mysql_query("SELECT * FROM menus WHERE menu_id=".$id);
  79. $menuinfo = mysql_fetch_array($sql);
  80. $sql = mysql_query("SELECT * FROM menus WHERE menu_zone=1");
  81. $menuszone1 = mysql_num_rows($sql);
  82. $to_menu_zone1 = mysql_query("UPDATE menus SET menu_order='".($menuszone1+1)."', menu_zone=1 WHERE menu_id=".$id);
  83. $move_up = mysql_query("UPDATE menus SET menu_order=menu_order-1 WHERE menu_order > ".$menuinfo['menu_order']." AND menu_zone='".$_POST['menu_zone']."'");
  84. }
  85.  
  86. //move to menu zone 2
  87. if($_POST['action'] == "to_menu_zone_2") {
  88. $id = $_POST['menu_id'];
  89. $sql = mysql_query("SELECT * FROM menus WHERE menu_id=".$id);
  90. $menuinfo = mysql_fetch_array($sql);
  91. $sql = mysql_query("SELECT * FROM menus WHERE menu_zone=2");
  92. $menuszone2 = mysql_num_rows($sql);
  93. $to_menu_zone2 = mysql_query("UPDATE menus SET menu_order='".($menuszone2+1)."', menu_zone=2 WHERE menu_id=".$id);
  94. $move_up = mysql_query("UPDATE menus SET menu_order=menu_order-1 WHERE menu_order > ".$menuinfo['menu_order']." AND menu_zone='".$_POST['menu_zone']."'");
  95. }
  96. }
  97.  
  98.  
  99.  
  100. //get inactive menus
  101. $inactivemenus = "";
  102. $directory = opendir('menus');
  103. while(false !== ($menu = readdir($directory))) {
  104. if ($menu != '.' && $menu != '..' && $menu != '') {
  105. $sql = mysql_query("SELECT * FROM menus WHERE menu_naam='".$menu."'");
  106. if(mysql_num_rows($sql) == 0) {
  107. $menuinfo = mysql_fetch_array($sql);
  108. $inactivemenus .= "
  109. <form action='menus.php' method='post' onchange='this.form.submit()'>
  110. <TABLE bordercolor='#000' cellpadding='0' cellspacing='0' width='100%' class='tablebrdr'>
  111. <tr bgcolor='#0000FF'>
  112. <td class='12px'>".$menu."</td>
  113. </tr>
  114. <tr>
  115. <td class='12px'>
  116. <center><select name='action' onchange='this.form.submit()'>
  117. <option>Activeer - Selecteer zone</option>
  118. <option value='act_zone_1'>Activeer in menu zone 1</option>
  119. <option value='act_zone_2'>Activeer in menu zone 2</option>
  120. </select>
  121. <input type='hidden' name='naam' value='".$menu."'>
  122. </center>
  123. </td>
  124. </tr>
  125. </table><br>
  126. </form>";
  127.  
  128. }
  129. }
  130. }
  131. if($inactivemenus == "") {
  132. $inactivemenus .= "Geen inactieve menu's";
  133. }
  134. closedir($directory);
  135.  
  136.  
  137.  
  138. //get active menus in zone 1
  139. $sql = mysql_query("SELECT * FROM menus WHERE menu_zone=1 ORDER BY menu_order ASC");
  140. $aantalmenus = mysql_num_rows($sql);
  141. $activemenus1 = "";
  142. if($aantalmenus == 0) {
  143. $activemenus1 = "Geen menus in deze zone.";
  144. }
  145. while($menuinfo = mysql_fetch_array($sql)) {
  146. $activemenus1 .= "
  147. <form action='menus.php' method='post' onchange='this.form.submit()'>
  148. <TABLE class='tablebrdr' bordercolor='#000' cellpadding='0' cellspacing='0' width='100%'>
  149. <tr bgcolor='#0000FF'>
  150. <td class='12px'>".$menuinfo['menu_naam']."</td>
  151. </tr>
  152. <tr>
  153. <td class='12px'>
  154. <select name='action' onchange='this.form.submit()'>
  155. <option>Optie's...</option>
  156. <option value='deac'>Deactiveer</option>
  157. ".($menuinfo['menu_order'] != 1 ? "<option value='move_up'>Omhoog</option>" : "")."
  158. ".($aantalmenus != $menuinfo['menu_order'] ? "<option value='move_down'>Omlaag</option>" : "")."
  159. <option value='to_menu_zone_2'>Naar menuzone 2</option>
  160. </select>
  161. <input type='hidden' name='menu_id' value='".$menuinfo['menu_id']."'>
  162. <input type='hidden' name='menu_zone' value='".$menuinfo['menu_zone']."'>
  163. </td>
  164. </tr>
  165. </table><br>
  166. </form>";
  167. }
  168.  
  169. //get active menus in zone 2
  170. $sql = mysql_query("SELECT * FROM menus WHERE menu_zone=2 ORDER BY menu_order ASC");
  171. $aantalmenus = mysql_num_rows($sql);
  172. $activemenus2 = "";
  173. if($aantalmenus == 0) {
  174. $activemenus2 = "Geen menus in deze zone.";
  175. }
  176. while($menuinfo = mysql_fetch_array($sql)) {
  177. $activemenus2 .= "
  178. <form action='menus.php' method='post' onchange='this.form.submit()'>
  179. <TABLE class='tablebrdr' bordercolor='#000' cellpadding='0' cellspacing='0' width='100%'>
  180. <tr bgcolor='#0000FF'>
  181. <td class='12px'>".$menuinfo['menu_naam']."</td>
  182. </tr>
  183. <tr>
  184. <td class='12px'>
  185. <select name='action' onchange='this.form.submit()'>
  186. <option>Optie's...</option>
  187. <option value='deac'>Deactiveer</option>
  188. ".($menuinfo['menu_order'] != 1 ? "<option value='move_up'>Omhoog</option>" : "")."
  189. ".($aantalmenus != $menuinfo['menu_order'] ? "<option value='move_down'>Omlaag</option>" : "")."
  190. <option value='to_menu_zone_1'>Naar menuzone 1</option>
  191. </select>
  192. <input type='hidden' name='menu_id' value='".$menuinfo['menu_id']."'>
  193. <input type='hidden' name='menu_zone' value='".$menuinfo['menu_zone']."'>
  194. </td>
  195. </tr>
  196. </table>
  197. <br>
  198. </form>";
  199. }
  200.  
  201. $text = "
  202. <TABLE border='0' bordercolor='#000' cellpadding='2' cellspacing='2' width='100%'>
  203. <tr bgcolor='#0000FF'>
  204. <td width='20%' bgcolor='#0000FF'>
  205. Zone 1
  206. </td>
  207. <td width='60%' bgcolor='#0000FF'>
  208. In active menu's
  209. </td>
  210. <td width='20%' bgcolor='#0000FF'>
  211. Zone 2
  212. </td>
  213. </tr>
  214. <tr>
  215. <td width='20%' bgcolor='#FFFF00'>
  216. ".$activemenus1."
  217. </td>
  218. <td width='60%'>
  219. ".$inactivemenus."
  220. </td>
  221. <td width='20%' bgcolor='#FFFF00'>
  222. ".$activemenus2."
  223. </td>
  224. </tr>
  225. </table>";
  226. rendertable("Configureer menus", $text);
  227.  
  228. //-----Functions-------//
  229. function rendertable($caption, $body, $bottom="", $mode="normal") {
  230. $table = "<center><TABLE width='90%' border='1' cellspacing='0' cellpadding='0'></center>";
  231. if(strlen($caption) != 0) {
  232. $table .= "
  233. <TR>
  234. <TD bgcolor='#FF0000'><font class='12px'>".$caption."</font></TD>
  235. </TR>";
  236. }
  237. if(strlen($body) != 0) {
  238. $table .= "
  239. <TR border='0'>
  240. <TD bgcolor='#F7FDB1'><font class='12px'>".$body."</font></TD>
  241. </TR>";
  242. }
  243. if(strlen($bottom) != 0) {
  244. $table .= "
  245. <TR>
  246. <TD bgcolor='#FF0000'><font class='12px'>".$bottom."</font></TD>
  247. </TR>";
  248. }
  249. $table .= "
  250. </TABLE>";
  251. echo $table;
  252. if($mode == "die") {
  253. include("footer.php");
  254. die();
  255. }
  256. }
  257. ?>
  258. </body>
  259.  
  260. </html>
  261.  
  262.  
  263.  
  264. ############[----------- config.php --------------]############
  265.  
  266. <?php
  267. /*
  268. voer deze query uit in phpMyAdmin
  269. CREATE TABLE `menus` (
  270. `menu_id` INT NOT NULL AUTO_INCREMENT ,
  271. `menu_naam` VARCHAR( 100 ) NOT NULL ,
  272. `menu_order` INT NOT NULL ,
  273. `menu_zone` INT NOT NULL ,
  274. PRIMARY KEY ( `menu_id` )
  275. );
  276. */
  277.  
  278. //hier de database gegevens
  279. $host = "127.0.0.1";
  280. $user = "root";
  281. $pass = "";
  282. $db = "menus";
  283.  
  284. mysql_connect($host, $user, $pass);
  285.  
  286.  
  287. /*
  288. Om de menus te laten zien op je pagina moet je de volgende code ergens zetten om de menus
  289. uit zone 1 te krijgen:
  290.  
  291. deze code haalt de menus van zone 1 uit de DB, deze zet je bijv. in je header file
  292. $menus = mysql_query("SELECT * FROM menus WHERE menu_zone=1 ORDER BY menu_order ASC");
  293. while($menuinfo = mysql_fetch_array($menus)) {
  294.   if(file_exists("menus/".$menuinfo['menu_naam']."/".$menuinfo['menu_naam'].".php")) {
  295.   include("menus/".$menuinfo['menu_naam']."/".$menuinfo['menu_naam'].".php");
  296.   echo "<br>";
  297.   }
  298. }
  299.  
  300. deze code haalt de menus van zone 2 uit de DB, deze zet je bijv. in je footer file
  301. $menus = mysql_query("SELECT * FROM menus WHERE menu_zone=2 ORDER BY menu_order ASC");
  302. while($menuinfo = mysql_fetch_array($menus)) {
  303.   if(file_exists("menus/".$menuinfo['menu_naam']."/".$menuinfo['menu_naam'].".php")) {
  304.   include("menus/".$menuinfo['menu_naam']."/".$menuinfo['menu_naam'].".php");
  305.   echo "<br>";
  306.   }
  307. }
  308. */
  309. ?>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Geen reacties (0)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.048s