2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
46 // Check if the admin has entered title and what-php file name...
47 if (((!isPostRequestParameterSet('title')) || (!isPostRequestParameterSet('menu'))) && (isFormSent())) {
48 // Abort adding the menu entry
49 unsetPostRequestParameter('ok');
54 $menus = array(); $titles = array(); $below = array();
56 // Get all available main menus
57 $result_menu = SQL_QUERY("SELECT
58 `action`,`title`,`sort`
60 `{?_MYSQL_PREFIX?}_guest_menu`
62 (`what`='' OR `what` IS NULL)
64 `sort` ASC", __FILE__, __LINE__);
65 if (!SQL_HASZERONUMS($result_menu)) {
66 // Read menu structure
67 // @TODO Cant this be rewritten?
68 while ($content = SQL_FETCHARRAY($result_menu)) {
70 $menus[] = $content['action'];
73 $titles[] = $content['title'];
75 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
76 $below[] = $content['sort'] + 1;
79 // Remove double eintries
80 // @TODO This can be somehow rewritten to a function
81 $prev = ''; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
82 foreach ($menus as $key => $value) {
83 if ($value == $prev) {
98 foreach ($menus as $key_main => $value_main) {
99 // Query for sub menus
100 $result = SQL_QUERY_ESC("SELECT
101 `what`,`title`,`sort`
103 `{?_MYSQL_PREFIX?}_guest_menu`
108 ORDER BY `sort` ASC",
109 array($value_main), __FILE__, __LINE__);
110 if (!SQL_HASZERONUMS($result)) {
112 $menus[$value_main] = array();
113 $titles[$value_main] = array();
114 $below[$value_main] = array();
116 // Read menu structure
117 while ($content = SQL_FETCHARRAY($result)) {
119 $menus[$value_main][] = $content['what'];
122 $titles[$value_main][] = $content['title'];
124 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
125 $below[$value_main][] = $content['sort'] + 1;
128 // Remove double eintries
129 // @TODO This can be somehow rewritten to a function
130 $prev = ''; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
131 foreach ($menus[$value_main] as $key => $value) {
132 if ($value == $prev) {
141 // Transfer dummy array
142 $menus[$value_main] = $dmy;
143 $titles[$value_main] = $dmy2;
144 $below[$value_main] = $dmy3;
148 SQL_FREERESULT($result);
153 SQL_FREERESULT($result_menu);
155 $OUT = '<select class="form_select" name="sort" size="1">
156 <option value="0">{--ADMIN_IS_FIRST_MENU--}</option>';
157 foreach ($below as $key => $m) {
159 foreach ($m as $key2 => $m2) {
160 $OUT .= '<option value="' . $m2 . '">' . $titles[$key][$key2];
161 foreach ($menus as $k => $v) {
162 if (($v == $key) && (!is_array($v))) {
163 $OUT .= ' (' . $titles[$k] . ')';
169 $OUT .= '<option value="' . $m . '">' . $titles[$key] . '</option>';
174 // Prepare selections for template
175 $content['below_selection'] = $OUT;
176 $content['what_selection'] = adminAddMenuSelectionBox('guest', 'what' , 'name');
177 $content['action_selection'] = adminAddMenuSelectionBox('guest', 'action', 'menu');
180 loadTemplate('admin_add_guest_menu', false, $content);
181 } elseif (!isDemoModeActive()) {
182 // Insert new menu entry
183 if (isPostRequestParameterSet('menu')) {
184 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`sort`,`visible`,`locked`) VALUES ('%s','%s','%s','%s','%s','%s')",
186 postRequestParameter('menu'),
187 postRequestParameter('name'),
188 postRequestParameter('title'),
189 bigintval(postRequestParameter('sort')),
190 postRequestParameter('visible'),
191 postRequestParameter('active'),
192 ), __FILE__, __LINE__);
194 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`title`,`sort`,`visible`,`locked`) VALUES ('%s','%s','%s','%s','%s')",
196 postRequestParameter('name'),
197 postRequestParameter('title'),
198 bigintval(postRequestParameter('sort')),
199 postRequestParameter('visible'),
200 postRequestParameter('active'),
201 ), __FILE__, __LINE__);
203 displayMessage('{--SETTINGS_SAVED--}');
206 displayMessage('{--SETTINGS_NOT_SAVED--}');