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 * 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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
48 // Check if the admin has entered title and what-php file name...
49 if (((!isPostRequestParameterSet('title')) || (!isPostRequestParameterSet('menu'))) && (isFormSent())) {
50 // Abort adding the menu entry
51 unsetPostRequestParameter('ok');
56 $menus = array(); $titles = array(); $below = array();
58 // Get all available main menus
59 $result_menu = SQL_QUERY("SELECT
60 `action`, `title`, `sort`
62 `{?_MYSQL_PREFIX?}_guest_menu`
64 (`what`='' OR `what` IS NULL)
66 `sort` ASC", __FILE__, __LINE__);
67 if (!SQL_HASZERONUMS($result_menu)) {
68 // Read menu structure
69 // @TODO Cant this be rewritten?
70 while ($content = SQL_FETCHARRAY($result_menu)) {
72 $menus[] = $content['action'];
75 $titles[] = $content['title'];
77 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
78 $below[] = $content['sort'] + 1;
81 // Remove double eintries
82 // @TODO This can be somehow rewritten to a function
83 $prev = ''; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
84 foreach ($menus as $key => $value) {
85 if ($value == $prev) {
100 foreach ($menus as $key_main => $value_main) {
101 // Query for sub menus
102 $result = SQL_QUERY_ESC("SELECT
103 `what`, `title`, `sort`
105 `{?_MYSQL_PREFIX?}_guest_menu`
110 ORDER BY `sort` ASC",
111 array($value_main), __FILE__, __LINE__);
112 if (!SQL_HASZERONUMS($result)) {
114 $menus[$value_main] = array();
115 $titles[$value_main] = array();
116 $below[$value_main] = array();
118 // Read menu structure
119 while ($content = SQL_FETCHARRAY($result)) {
121 $menus[$value_main][] = $content['what'];
124 $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 $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 SQL_FREERESULT($result);
155 SQL_FREERESULT($result_menu);
157 $OUT = '<select class="admin_select" name="sort" size="1">
158 <option value="0">{--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_guest_add', false, $content);
183 } elseif (!isDemoModeActive()) {
184 // Insert new menu entry
185 if (isPostRequestParameterSet('menu')) {
186 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`sort`,`visible`,`locked`) VALUES ('%s','%s','%s','%s','%s','%s')",
188 postRequestParameter('menu'),
189 postRequestParameter('name'),
190 postRequestParameter('title'),
191 bigintval(postRequestParameter('sort')),
192 postRequestParameter('visible'),
193 postRequestParameter('active'),
194 ), __FILE__, __LINE__);
196 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`, `title`, `sort`, `visible`, `locked`) VALUES ('%s','%s','%s','%s','%s')",
198 postRequestParameter('name'),
199 postRequestParameter('title'),
200 bigintval(postRequestParameter('sort')),
201 postRequestParameter('visible'),
202 postRequestParameter('active'),
203 ), __FILE__, __LINE__);
205 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
208 loadTemplate('admin_settings_saved', false, '{--SETTINGS_NOT_SAVED--}');