2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 09/27/2003 *
4 * =================== Last change: 12/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-admin_add.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Add more entries to the admin menu *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Mehr Menueeintraege zum Admin-Bereich 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 ((isFormSent()) && ((!isPostRequestParameterSet('title')) || (!isPostRequestParameterSet('menu')) || (!isPostRequestParameterSet('descr')))) {
48 unsetPostRequestParameter('ok');
53 $menus = array(); $titles = array(); $below = array();
55 // Get all available main menus
56 $result = SQL_QUERY("SELECT `action`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
57 if (!SQL_HASZERONUMS($result)) {
58 // Read menu structure
59 // @TODO Cant this be rewritten?
60 while ($content = SQL_FETCHARRAY($result)) {
62 $menus[] = $content['action'];
65 $titles[] = $content['title'];
67 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
68 $below[] = $content['sort'] + 1;
72 SQL_FREERESULT($result);
74 // Remove double eintries
75 // @TODO This can be somehow rewritten to a function
76 $prev = ''; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
77 foreach ($menus as $key => $value) {
78 if ($value == $prev) {
87 // Write dummys back to our array
88 $menus = $dmy; unset($dmy);
89 $titles = $dmy2; unset($dmy2);
90 $below = $dmy3; unset($dmy3);
93 foreach ($menus as $key_main => $value_main) {
94 $result = SQL_QUERY_ESC("SELECT `what`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort` ASC",
95 array($value_main), __FILE__, __LINE__);
96 if (!SQL_HASZERONUMS($result)) {
98 $menus[$value_main] = array();
99 $titles[$value_main] = array();
100 $below[$value_main] = array();
102 // Read menu structure
103 while ($content = SQL_FETCHARRAY($result)) {
105 $menus[$value_main][] = $content['what'];
108 $titles[$value_main][] = $content['title'];
110 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
111 $below[$value_main][] = $content['sort'] + 1;
115 SQL_FREERESULT($result);
117 // Remove double eintries
118 // @TODO This can be somehow rewritten to a function
119 $prev = ''; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
120 foreach ($menus[$value_main] as $key => $value) {
121 if ($value == $prev) {
129 $menus[$value_main] = $dmy;
130 $titles[$value_main] = $dmy2;
131 $below[$value_main] = $dmy3;
136 $OUT = ' <select class="form_select" name="sort" size="1">
137 <option value="0">{--ADMIN_IS_FIRST_MENU--}</option>';
138 foreach ($below as $key => $m) {
140 foreach ($m as $key2 => $m2) {
141 $OUT .= ' <option value="' . $m2 . '">' . $titles[$key][$key2];
142 foreach ($menus as $k => $v) {
143 if (($v == $key) && (!is_array($v))) {
144 $OUT .= ' (' . $titles[$k] . ')';
150 $OUT .= ' <option value="' . $m . '">' . $titles[$key] . '</option>';
155 // Prepare selections for template
156 $content['below_selection'] = $OUT;
157 $content['what_selection'] = adminAddMenuSelectionBox('admin', 'what' , 'name');
158 $content['action_selection'] = adminAddMenuSelectionBox('admin', 'action', 'menu');
161 loadTemplate('admin_add_admin_menu', false, $content);
162 } elseif (!isDemoModeActive()) {
163 // Insert new menu entry
164 if (isPostRequestParameterSet('menu')) {
166 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s','%s')",
168 postRequestParameter('menu'),
169 postRequestParameter('name'),
170 postRequestParameter('title'),
171 postRequestParameter('descr'),
172 bigintval(postRequestParameter('sort')),
173 ), __FILE__, __LINE__
177 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (action, title, descr, sort) VALUES ('%s','%s','%s','%s')",
179 postRequestParameter('name'),
180 postRequestParameter('title'),
181 postRequestParameter('descr'),
182 bigintval(postRequestParameter('sort')),
183 ), __FILE__, __LINE__
186 displayMessage('{--SETTINGS_SAVED--}');
189 displayMessage('{--SETTINGS_NOT_SAVED--}');