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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
47 // Check if the admin has entered title and what-php file name...
48 if (((!isPostRequestElementSet('title')) || (!isPostRequestElementSet('menu'))) && (isFormSent())) {
49 // Abort adding the menu entry
50 unsetPostRequestElement('ok');
55 $menus = array(); $titles = array(); $below = array();
57 // Get all available main menus
58 $result = SQL_QUERY("SELECT
59 `action`, `title`, `sort`
61 `{?_MYSQL_PREFIX?}_guest_menu`
63 (`what`='' OR `what` IS NULL)
65 `sort` ASC", __FILE__, __LINE__);
66 if (SQL_NUMROWS($result) > 0) {
67 // Read menu structure
68 // @TODO Cant this be rewritten?
69 while ($content = SQL_FETCHARRAY($result)) {
71 $menus[] = $content['action'];
74 $titles[] = $content['title'];
76 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
77 $below[] = $content['sort'] + 1;
81 SQL_FREERESULT($result);
83 // Remove double eintries
84 // @TODO This can be somehow rewritten to a function
85 $prev = ''; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
86 foreach ($menus as $key => $value) {
87 if ($value == $prev) {
102 foreach ($menus as $key_main => $value_main) {
103 // Query for sub menus
104 $result = SQL_QUERY_ESC("SELECT
105 `what`, `title`, `sort`
107 `{?_MYSQL_PREFIX?}_guest_menu`
112 ORDER BY `sort` ASC",
113 array($value_main), __FILE__, __LINE__);
114 if (SQL_NUMROWS($result) > 0) {
116 $menus[$value_main] = array();
117 $titles[$value_main] = array();
118 $below[$value_main] = array();
120 // Read menu structure
121 while ($content = SQL_FETCHARRAY($result)) {
123 $menus[$value_main][] = $content['what'];
126 $titles[$value_main][] = $content['title'];
128 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
129 $below[$value_main][] = $content['sort'] + 1;
133 SQL_FREERESULT($result);
135 // Remove double eintries
136 // @TODO This can be somehow rewritten to a function
137 $prev = ''; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
138 foreach ($menus[$value_main] as $key => $value) {
139 if ($value == $prev) {
148 // Transfer dummy array
149 $menus[$value_main] = $dmy;
150 $titles[$value_main] = $dmy2;
151 $below[$value_main] = $dmy3;
156 $OUT = " <select class=\"admin_select\" name=\"sort\" size=\"1\">
157 <option value=\"0\">{--IS_FIRST_MENU--}</option>";
158 foreach ($below as $key => $m) {
160 foreach ($m as $key2 => $m2) {
161 $OUT .= " <option value=\"".$m2."\">".$titles[$key][$key2];
162 foreach ($menus as $k => $v) {
163 if (($v == $key) && (!is_array($v))) {
164 $OUT .= " (" . $titles[$k] . ')';
167 $OUT .= "</option>\n";
170 $OUT .= " <option value=\"".$m."\">".$titles[$key]."</option>\n";
175 // Prepare selections for template
176 $content['below_selection'] = $OUT;
177 $content['what_selection'] = adminAddMenuSelectionBox('member', 'what' , 'name');
178 $content['action_selection'] = adminAddMenuSelectionBox('member', 'action', 'menu');
181 loadTemplate('admin_guest_add', false, $content);
182 } elseif (!isDemoModeActive()) {
183 // Insert new menu entry
184 if (isPostRequestElementSet('menu')) {
185 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`sort`,`visible`,`locked`) VALUES ('%s','%s','%s','%s','%s','%s')",
187 postRequestElement('menu'),
188 postRequestElement('name'),
189 postRequestElement('title'),
190 bigintval(postRequestElement('sort')),
191 postRequestElement('visible'),
192 postRequestElement('active'),
193 ), __FILE__, __LINE__);
195 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`, `title`, `sort`, `visible`, `locked`) VALUES ('%s','%s','%s','%s','%s')",
197 postRequestElement('name'),
198 postRequestElement('title'),
199 bigintval(postRequestElement('sort')),
200 postRequestElement('visible'),
201 postRequestElement('active'),
202 ), __FILE__, __LINE__);
204 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
207 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_NOT_SAVED'));