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)"; $SUB = '';
48 if (isGetRequestParameterSet('sub')) {
49 $AND = sprintf("`action`='%s' AND `what` != '' AND `what` IS NOT NULL", getRequestParameter('sub'));
50 $SUB = 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'] = $SUB;
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 $data = SQL_FETCHARRAY($result);
69 // Prepare data for the row template
71 'action' => adminAddMenuSelectionBox('admin', 'action', 'sel_action[' . $sel . ']', $data['action']),
72 'what' => adminAddMenuSelectionBox('admin', 'what' , 'sel_what[' . $sel . ']', $data['what']),
74 'menu' => $data['title'],
75 'descr' => $data['descr'],
80 $OUT .= loadTemplate('admin_edit_admin_menu_row', true, $data);
88 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
91 // Free result and switch color
92 SQL_FREERESULT($result);
96 $content['rows'] = $OUT;
97 $content['cnt'] = $count;
100 loadTemplate('admin_edit_admin_menu_form', false, $content);
101 } elseif ((isFormSent('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
102 // Prepare misc content
103 $content['sub'] = $SUB;
104 $content['chk'] = countPostSelection();
106 // Del menu entries with or without confirmation
107 $count = '0'; $OUT = '';
108 foreach (postRequestParameter('sel') as $sel => $confirm) {
111 $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
112 array(bigintval($sel)), __FILE__, __LINE__);
113 if (SQL_NUMROWS($result) == 1) {
114 // Entry found so we load the stuff...
115 $data = SQL_FETCHARRAY($result);
117 // Prepare data for the row template
119 'menu' => $data['title'],
123 $OUT .= loadTemplate('admin_delete_admin_menu_row', true, $data);
129 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
131 SQL_FREERESULT($result);
134 $content['rows'] = $OUT;
135 $content['cnt'] = $count;
138 loadTemplate('admin_delete_admin_menu', false, $content);
139 } elseif ((isFormSent()) && (!isDemoModeActive())) {
140 // An action is done...
141 switch (postRequestParameter('ok')) {
142 case 'edit': // Edit menu
143 foreach (postRequestParameter('sel') as $sel => $menu) {
145 $sel = bigintval($sel);
148 SQL_QUERY_ESC("UPDATE
149 `{?_MYSQL_PREFIX?}_admin_menu`
161 postRequestParameter('sel_action', $sel),
162 postRequestParameter('sel_what', $sel),
163 postRequestParameter('sel_desc', $sel),
165 ), __FILE__, __LINE__);
169 displayMessage('{--SETTINGS_SAVED--}');
172 case 'delete': // Delete menu
173 foreach (postRequestParameter('sel') as $sel => $menu) {
174 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
175 array(bigintval($sel)), __FILE__, __LINE__);
179 displayMessage('{--SETTINGS_SAVED--}');
182 default: // Unexpected action
183 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
184 displayMessage(getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
189 doAdminProcessMenuWeightning('admin', $AND);
192 $result = SQL_QUERY("SELECT `id`, `action`, `what`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." ORDER BY `sort` ASC", __FILE__, __LINE__);
194 // Do we have entries?
195 if (!SQL_HASZERONUMS($result)) {
196 // Remember sub value
197 $content['sub'] = $SUB;
200 $OUT = ''; $count = '0';
202 // Process all entries
203 while ($data = SQL_FETCHARRAY($result)) {
207 // Init navigation variable
209 if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
210 // Is highest position
211 $data['navi'] = '<a href="{%url=modules.php?module=admin&what=adminedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']+1) . '&fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
212 } elseif ($count == SQL_NUMROWS($result)) {
213 // Is lowest position
214 $data['navi'] = '<a href="{%url=modules.php?module=admin&what=adminedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']-1) . '&fid=' . $data['sort'] . '%}">{--HIGHER--}</a>';
215 } elseif ($data['sort'] > 0) {
216 // Anything else between highest and lowest
217 $data['navi'] = '<a href="{%url=modules.php?module=admin&what=adminedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']-1) . '&fid=' . $data['sort'] . '%}">{--HIGHER--}</a>|<a href="{%url=modules.php?module=admin&what=adminedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']+1) . '&fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
220 // Add more data to $data
221 $data['mode'] = 'admin';
223 // Load row template and switch colors
224 $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
228 $content['rows'] = $OUT;
231 SQL_FREERESULT($result);
234 loadTemplate('admin_edit_admin_menu', false, $content);
236 // Menu entries are missing... (???)
237 displayMessage('{--ADMIN_NO_MENUS_FOUND--}');