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 - 2015 by Mailer Developer Team *
20 * For more information visit: http://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 (((!isPostRequestElementSet('title')) || (!isPostRequestElementSet('menu'))) && (isFormSent())) {
48 // Abort adding the menu entry
49 unsetPostRequestElement('ok');
54 $menus = array(); $titles = array(); $below = array();
56 // Get all available main menus
57 $result_menu = sqlQuery("SELECT
58 `action`, `title`, `sort`
60 `{?_MYSQL_PREFIX?}_guest_menu`
62 (`what`='' OR `what` IS NULL)
64 `sort` ASC", __FILE__, __LINE__);
66 if (!ifSqlHasZeroNumRows($result_menu)) {
67 // Read menu structure
68 // @TODO Cant this be rewritten?
69 while ($content = sqlFetchArray($result_menu)) {
71 array_push($menus, $content['action']);
74 array_push($titles, $content['title']);
76 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
77 array_push($below, $content['sort'] + 1);
80 // Remove double eintries
81 // @TODO This can be somehow rewritten to a function
82 $prev = ''; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
83 foreach ($menus as $key => $value) {
84 if ($value == $prev) {
99 foreach ($menus as $key_main => $value_main) {
100 // Query for sub menus
101 $result = sqlQueryEscaped("SELECT
102 `what`, `title`, `sort`
104 `{?_MYSQL_PREFIX?}_guest_menu`
109 ORDER BY `sort` ASC",
110 array($value_main), __FILE__, __LINE__);
112 if (!ifSqlHasZeroNumRows($result)) {
114 $menus[$value_main] = array();
115 $titles[$value_main] = array();
116 $below[$value_main] = array();
118 // Read menu structure
119 while ($content = sqlFetchArray($result)) {
121 array_push($menus[$value_main], $content['what']);
124 array_push($titles[$value_main], $content['title']);
126 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
127 array_push($below[$value_main], $content['sort'] + 1);
130 // Remove double eintries
131 // @TODO This can be somehow rewritten to a function
132 $prev = ''; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
133 foreach ($menus[$value_main] as $key => $value) {
134 if ($value == $prev) {
143 // Transfer dummy array
144 $menus[$value_main] = $dmy;
145 $titles[$value_main] = $dmy2;
146 $below[$value_main] = $dmy3;
150 sqlFreeResult($result);
155 sqlFreeResult($result_menu);
157 $OUT = '<select class="form_select" name="sort" size="1">
158 <option value="0">{--ADMIN_IS_FIRST_MENU--}</option>';
159 foreach ($below as $key => $m) {
161 foreach ($m as $key2 => $m2) {
162 $OUT .= '<option value="' . $m2 . '">' . $titles[$key][$key2];
163 foreach ($menus as $k => $v) {
164 if (($v == $key) && (!is_array($v))) {
165 $OUT .= ' (' . $titles[$k] . ')';
171 $OUT .= '<option value="' . $m . '">' . $titles[$key] . '</option>';
176 // Prepare selections for template
177 $content['below_selection'] = $OUT;
178 $content['what_selection'] = adminAddMenuSelectionBox('guest', 'what' , 'name');
179 $content['action_selection'] = adminAddMenuSelectionBox('guest', 'action', 'menu');
182 loadTemplate('admin_add_guest_menu', FALSE, $content);
183 } elseif (!isDemoModeActive()) {
184 // Insert new menu entry
185 if (isPostRequestElementSet('menu')) {
186 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`, `what`, `title`, `sort`, `visible`, `locked`) VALUES ('%s','%s','%s','%s','%s','%s')",
188 postRequestElement('menu'),
189 postRequestElement('name'),
190 postRequestElement('title'),
191 bigintval(postRequestElement('sort')),
192 postRequestElement('visible'),
193 postRequestElement('active'),
194 ), __FILE__, __LINE__);
196 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`, `title`, `sort`, `visible`, `locked`) VALUES ('%s','%s','%s','%s','%s')",
198 postRequestElement('name'),
199 postRequestElement('title'),
200 bigintval(postRequestElement('sort')),
201 postRequestElement('visible'),
202 postRequestElement('active'),
203 ), __FILE__, __LINE__);
205 displayMessage('{--SETTINGS_SAVED--}');
208 displayMessage('{--SETTINGS_NOT_SAVED--}');