2 /************************************************************************
3 * MXChange v0.2.1 Start: 09/28/2003 *
4 * =============== Last change: 12/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-guest_add.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Add a new guest menu *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Einen neuen Gastmenuepunkt einfuegen *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
43 // Check if the admin has entered title and what-php file name...
44 if (((empty($_POST['title'])) || (empty($_POST['menu']))) && (isset($_POST['ok']))) {
45 // Abort adding the menu entry
49 if (!isset($_POST['ok'])) {
51 $menus = array(); $titles = array(); $below = array();
53 // Get all available main menus
54 $result = SQL_QUERY("SELECT action, title, sort FROM `"._MYSQL_PREFIX."_guest_menu` WHERE (what='' OR what IS NULL) ORDER BY sort", __FILE__, __LINE__);
55 if (SQL_NUMROWS($result) > 0) {
56 // Read menu structure
57 while (list($act, $title, $sort) = SQL_FETCHROW($result)) {
64 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
69 SQL_FREERESULT($result);
71 // Remove double eintries
72 $prev = ""; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
73 foreach ($menus as $key => $value) {
74 if ($value == $prev) {
89 foreach ($menus as $key_main => $value_main) {
90 $result = SQL_QUERY_ESC("SELECT what, title, sort
91 FROM "._MYSQL_PREFIX."_guest_menu
92 WHERE action='%s' AND what != '' AND what IS NOT NULL ORDER BY sort",
93 array($value_main), __FILE__, __LINE__);
94 if (SQL_NUMROWS($result) > 0)
97 $menus[$value_main] = array();
98 $titles[$value_main] = array();
99 $below[$value_main] = array();
101 // Read menu structure
102 while (list($act, $title, $sort) = SQL_FETCHROW($result))
105 $menus[$value_main][] = $act;
108 $titles[$value_main][] = $title;
110 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
111 $below[$value_main][] = $sort + 1;
115 SQL_FREERESULT($result);
117 // Remove double eintries
118 $prev = ""; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
119 foreach ($menus[$value_main] as $key => $value)
132 $menus[$value_main] = $dmy; $titles[$value_main] = $dmy2; $below[$value_main] = $dmy3;
137 $OUT = " <select class=\"admin_select\" name=\"sort\" size=\"1\">
138 <option value=\"0\">".IS_FIRST_MENU."</option>";
139 foreach ($below as $key => $m)
143 foreach ($m as $key2 => $m2)
145 $OUT .= " <option value=\"".$m2."\">".$titles[$key][$key2];
146 foreach ($menus as $k => $v)
148 if (($v == $key) && (!is_array($v)))
150 $OUT .= " (".$titles[$k].")";
153 $OUT .= "</option>\n";
158 $OUT .= " <option value=\"".$m."\">".$titles[$key]."</option>\n";
163 define('__BELOW_SELECTION' , $OUT);
164 define('__WHAT_SELECTION' , ADMIN_MAKE_MENU_SELECTION("guest", "what", "name"));
165 define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION("guest", "action", "menu"));
168 LOAD_TEMPLATE("admin_guest_add");
172 // Insert new menu entry
173 if (!empty($_POST['menu']))
175 SQL_QUERY_ESC("INSERT INTO `"._MYSQL_PREFIX."_guest_menu` (`action`,`what`,`title`,`sort`,`visible`,`locked`) VALUES ('%s','%s','%s','%s','%s','%s')",
180 bigintval($_POST['sort']),
183 ), __FILE__, __LINE__);
187 SQL_QUERY_ESC("INSERT INTO `"._MYSQL_PREFIX."_guest_menu` (action, title, sort, visible, locked) VALUES ('%s','%s','%s','%s','%s')",
191 bigintval($_POST['sort']),
194 ), __FILE__, __LINE__);
196 LOAD_TEMPLATE("admin_settings_saved", false, SAVING_DONE);
201 LOAD_TEMPLATE("admin_settings_saved", false, SETTINGS_NOT_SAVED);