2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 09/05/2003 *
4 * =================== Last change: 12/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-adminedit.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Edit the admin menu *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Das Admin-Menue editieren *
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 // Do we edit/delete/change main menus or sub menus?
47 $AND = "(`what` = '' OR `what` IS NULL)"; $subMenu = '';
48 if (isGetRequestParameterSet('sub')) {
49 $AND = sprintf("`action`='%s' AND `what` != '' AND `what` IS NOT NULL", getRequestParameter('sub'));
50 $subMenu = getRequestParameter('sub');
53 // List all menu points and make them editable
54 if ((isFormSent('edit')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
56 // @TODO Kill all constants in this file
57 $content['sub'] = $subMenu;
58 $content['chk'] = countPostSelection();
59 $count = '0'; $OUT = '';
60 foreach (postRequestParameter('sel') as $sel => $confirm) {
63 $result = SQL_QUERY_ESC("SELECT `title`,`action`,`what`,`descr` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
64 array(bigintval($sel)), __FILE__, __LINE__);
65 if (SQL_NUMROWS($result) == 1) {
66 // Entry found so we load the stuff...
67 $content = SQL_FETCHARRAY($result);
69 // Prepare data for the row template
71 'action' => adminAddMenuSelectionBox('admin', 'action', 'sel_action[' . $sel . ']', $content['action']),
72 'what' => adminAddMenuSelectionBox('admin', 'what' , 'sel_what[' . $sel . ']', $content['what']),
74 'menu' => $content['title'],
75 'descr' => $content['descr'],
80 $OUT .= loadTemplate('admin_edit_admin_menu_row', true, $content);
88 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
91 // Free result and switch color
92 SQL_FREERESULT($result);
96 $content['rows'] = $OUT;
97 $content['sub'] = $subMenu;
98 $content['chk'] = countPostSelection();
99 $content['count'] = $count;
102 loadTemplate('admin_edit_admin_menu_form', false, $content);
103 } elseif ((isFormSent('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
104 // Prepare misc content
105 $content['sub'] = $subMenu;
106 $content['chk'] = countPostSelection();
108 // Del menu entries with or without confirmation
109 $count = '0'; $OUT = '';
110 foreach (postRequestParameter('sel') as $sel => $confirm) {
113 $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
114 array(bigintval($sel)), __FILE__, __LINE__);
115 if (SQL_NUMROWS($result) == 1) {
116 // Entry found so we load the stuff...
117 $content = SQL_FETCHARRAY($result);
119 // Prepare data for the row template
121 'menu' => $content['title'],
125 $OUT .= loadTemplate('admin_delete_admin_menu_row', true, $content);
131 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
133 SQL_FREERESULT($result);
137 $content['rows'] = $OUT;
138 $content['sub'] = $subMenu;
139 $content['chk'] = countPostSelection();
140 $content['count'] = $count;
143 loadTemplate('admin_delete_admin_menu', false, $content);
144 } elseif ((isFormSent()) && (!isDemoModeActive())) {
145 // An action is done...
146 switch (postRequestParameter('ok')) {
147 case 'edit': // Edit menu
148 foreach (postRequestParameter('sel') as $sel => $menu) {
150 $sel = bigintval($sel);
153 SQL_QUERY_ESC("UPDATE
154 `{?_MYSQL_PREFIX?}_admin_menu`
166 postRequestParameter('sel_action', $sel),
167 postRequestParameter('sel_what', $sel),
168 postRequestParameter('sel_desc', $sel),
170 ), __FILE__, __LINE__);
174 displayMessage('{--SETTINGS_SAVED--}');
177 case 'delete': // Delete menu
178 foreach (postRequestParameter('sel') as $sel => $menu) {
179 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
180 array(bigintval($sel)), __FILE__, __LINE__);
184 displayMessage('{--SETTINGS_SAVED--}');
187 default: // Unexpected action
188 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
189 displayMessage('{%message,ADMIN_UNKNOWN_OKAY=' . postRequestParameter('ok') . '%}');
194 doAdminProcessMenuWeightning('admin', $AND);
197 $result = SQL_QUERY("SELECT `id`,`action`,`what`,`title`,`sort` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." ORDER BY `sort` ASC", __FILE__, __LINE__);
199 // Do we have entries?
200 if (!SQL_HASZERONUMS($result)) {
205 // Process all entries
206 while ($content = SQL_FETCHARRAY($result)) {
207 // Remember sub value
208 $content['sub'] = $subMenu;
213 // Init navigation variable
214 $content['navi'] = '';
215 if (($content['sort'] == '0') || (($content['sort'] == 1) && (!empty($subMenu)))) {
216 // Is highest position
217 $content['navi'] = '<a href="{%url=modules.php?module=admin&what=adminedit&sub=' . $content['sub'] . '&act=' . $content['action'] . '&w=' . $content['what'] . '&tid=' . ($content['sort']+1) . '&fid=' . $content['sort'] . '%}">{--LOWER--}</a>';
218 } elseif ($count == SQL_NUMROWS($result)) {
219 // Is lowest position
220 $content['navi'] = '<a href="{%url=modules.php?module=admin&what=adminedit&sub=' . $content['sub'] . '&act=' . $content['action'] . '&w=' . $content['what'] . '&tid=' . ($content['sort']-1) . '&fid=' . $content['sort'] . '%}">{--HIGHER--}</a>';
221 } elseif ($content['sort'] > 0) {
222 // Anything else between highest and lowest
223 $content['navi'] = '<a href="{%url=modules.php?module=admin&what=adminedit&sub=' . $content['sub'] . '&act=' . $content['action'] . '&w=' . $content['what'] . '&tid=' . ($content['sort']-1) . '&fid=' . $content['sort'] . '%}">{--HIGHER--}</a>|<a href="{%url=modules.php?module=admin&what=adminedit&sub=' . $content['sub'] . '&act=' . $content['action'] . '&w=' . $content['what'] . '&tid=' . ($content['sort']+1) . '&fid=' . $content['sort'] . '%}">{--LOWER--}</a>';
226 // Add more data to $content
227 $content['mode'] = 'admin';
229 // Load row template and switch colors
230 $OUT .= loadTemplate('admin_menu_overview_row', true, $content);
234 $content['rows'] = $OUT;
235 $content['sub'] = $subMenu;
238 SQL_FREERESULT($result);
241 loadTemplate('admin_edit_admin_menu', false, $content);
243 // Menu entries are missing... (???)
244 displayMessage('{--ADMIN_NO_MENUS_FOUND--}');