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 * 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 ((isFormSent()) && ((!isPostRequestParameterSet('title')) || (!isPostRequestParameterSet('menu')) || (!isPostRequestParameterSet('descr')))) {
50 unsetPostRequestParameter('ok');
55 $menus = array(); $titles = array(); $below = array();
57 // Get all available main menus
58 $result = SQL_QUERY("SELECT action, title, sort FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort`", __FILE__, __LINE__);
59 if (!SQL_HASZERONUMS($result)) {
60 // Read menu structure
61 // @TODO Cant this be rewritten?
62 while ($content = SQL_FETCHARRAY($result)) {
64 $menus[] = $content['action'];
67 $titles[] = $content['title'];
69 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
70 $below[] = $content['sort'] + 1;
74 SQL_FREERESULT($result);
76 // Remove double eintries
77 // @TODO This can be somehow rewritten to a function
78 $prev = ''; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
79 foreach ($menus as $key => $value) {
80 if ($value == $prev) {
89 // Write dummys back to our array
90 $menus = $dmy; unset($dmy);
91 $titles = $dmy2; unset($dmy2);
92 $below = $dmy3; unset($dmy3);
95 foreach ($menus as $key_main => $value_main) {
96 $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`",
97 array($value_main), __FILE__, __LINE__);
98 if (!SQL_HASZERONUMS($result)) {
100 $menus[$value_main] = array();
101 $titles[$value_main] = array();
102 $below[$value_main] = array();
104 // Read menu structure
105 while ($content = SQL_FETCHARRAY($result)) {
107 $menus[$value_main][] = $content['what'];
110 $titles[$value_main][] = $content['title'];
112 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
113 $below[$value_main][] = $content['sort'] + 1;
117 SQL_FREERESULT($result);
119 // Remove double eintries
120 // @TODO This can be somehow rewritten to a function
121 $prev = ''; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
122 foreach ($menus[$value_main] as $key => $value) {
123 if ($value == $prev) {
131 $menus[$value_main] = $dmy;
132 $titles[$value_main] = $dmy2;
133 $below[$value_main] = $dmy3;
138 $OUT = ' <select class="admin_select" name="sort" size="1">
139 <option value="0">{--IS_FIRST_MENU--}</option>';
140 foreach ($below as $key => $m) {
142 foreach ($m as $key2 => $m2) {
143 $OUT .= ' <option value="' . $m2 . '">' . $titles[$key][$key2];
144 foreach ($menus as $k => $v) {
145 if (($v == $key) && (!is_array($v))) {
146 $OUT .= ' (' . $titles[$k] . ')';
152 $OUT .= ' <option value="' . $m . '">' . $titles[$key] . '</option>';
157 // Prepare selections for template
158 $content['below_selection'] = $OUT;
159 $content['what_selection'] = adminAddMenuSelectionBox('admin', 'what' , 'name');
160 $content['action_selection'] = adminAddMenuSelectionBox('admin', 'action', 'menu');
163 loadTemplate('admin_add_admin_menu', false, $content);
164 } elseif (!isDemoModeActive()) {
165 // Insert new menu entry
166 if (isPostRequestParameterSet('menu')) {
168 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s','%s')",
170 postRequestParameter('menu'),
171 postRequestParameter('name'),
172 postRequestParameter('title'),
173 postRequestParameter('descr'),
174 bigintval(postRequestParameter('sort')),
175 ), __FILE__, __LINE__
179 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (action, title, descr, sort) VALUES ('%s','%s','%s','%s')",
181 postRequestParameter('name'),
182 postRequestParameter('title'),
183 postRequestParameter('descr'),
184 bigintval(postRequestParameter('sort')),
185 ), __FILE__, __LINE__
188 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
191 loadTemplate('admin_settings_saved', false, '{--SETTINGS_NOT_SAVED--}');