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 * 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 // Do we edit/delete/change main menus or sub menus?
49 $AND = "(`what` = '' OR `what` IS NULL)"; $SUB = '';
50 if (isGetRequestParameterSet('sub')) {
51 $AND = sprintf("`action`='%s' AND `what` != '' AND `what` IS NOT NULL", getRequestParameter('sub'));
52 $SUB = getRequestParameter('sub');
55 // List all menu points and make them editable
56 if ((isFormSent('edit')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
58 // @TODO Kill all constants in this file
59 $content['sub'] = $SUB;
60 $content['chk'] = countPostSelection();
62 foreach (postRequestParameter('sel') as $sel => $confirm) {
65 $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what`, `descr` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
66 array(bigintval($sel)), __FILE__, __LINE__);
67 if (SQL_NUMROWS($result) == 1) {
68 // Entry found so we load the stuff...
69 $data = SQL_FETCHARRAY($result);
71 // Prepare data for the row template
73 'action' => adminAddMenuSelectionBox('admin', 'action', 'sel_action[' . $sel . ']', $data['action']),
74 'what' => adminAddMenuSelectionBox('admin', 'what' , 'sel_what[' . $sel . ']', $data['what']),
76 'menu' => $data['title'],
77 'descr' => $data['descr'],
82 $OUT .= loadTemplate('admin_edit_admin_menu_row', true, $data);
90 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
93 // Free result and switch color
94 SQL_FREERESULT($result);
98 $content['rows'] = $OUT;
99 $content['cnt'] = $cnt;
102 loadTemplate('admin_edit_admin_menu_form', false, $content);
103 } elseif ((isFormSent('del')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
104 // Prepare misc content
105 $content['sub'] = $SUB;
106 $content['chk'] = countPostSelection();
108 // Del menu entries with or without confirmation
109 $cnt = '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 $data = SQL_FETCHARRAY($result);
119 // Prepare data for the row template
121 'menu' => $data['title'],
125 $OUT .= loadTemplate('admin_del_admin_menu_row', true, $data);
131 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
133 SQL_FREERESULT($result);
136 $content['rows'] = $OUT;
137 $content['cnt'] = $cnt;
140 loadTemplate('admin_del_admin_menu', false, $content);
141 } elseif ((isFormSent()) && (!isDemoModeActive())) {
142 // An action is done...
143 switch (postRequestParameter('ok')) {
144 case 'edit': // Edit menu
145 foreach (postRequestParameter('sel') as $sel => $menu) {
147 $sel = bigintval($sel);
150 SQL_QUERY_ESC("UPDATE
151 `{?_MYSQL_PREFIX?}_admin_menu`
163 postRequestParameter('sel_action', $sel),
164 postRequestParameter('sel_what', $sel),
165 postRequestParameter('sel_desc', $sel),
167 ), __FILE__, __LINE__);
171 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
174 case 'del': // Delete menu
175 foreach (postRequestParameter('sel') as $sel => $menu) {
176 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
177 array(bigintval($sel)), __FILE__, __LINE__);
181 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
184 default: // Unexpected action
185 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
186 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
190 if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
192 if (isGetRequestParameterSet('w')) {
193 // Sub menus selected
194 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `what` != '%s' AND `sort`=%s LIMIT 1",
196 getRequestParameter('w'),
197 bigintval(getRequestParameter('tid'))
198 ), __FILE__, __LINE__);
199 list($tid) = SQL_FETCHROW($result);
200 SQL_FREERESULT($result);
201 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `what`='%s' AND `sort`=%s LIMIT 1",
203 getRequestParameter('w'),
204 bigintval(getRequestParameter('fid'))
205 ), __FILE__, __LINE__);
206 list($fid) = SQL_FETCHROW($result);
207 SQL_FREERESULT($result);
209 // Main menu selected
210 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action` != %s AND ".$AND." AND `sort`=%s LIMIT 1",
212 getRequestParameter('act'),
213 bigintval(getRequestParameter('tid'))
214 ), __FILE__, __LINE__);
215 list($tid) = SQL_FETCHROW($result);
216 SQL_FREERESULT($result);
217 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`=%s AND ".$AND." AND `sort`=%s LIMIT 1",
219 getRequestParameter('act'),
220 bigintval(getRequestParameter('fid'))
221 ), __FILE__, __LINE__);
222 list($fid) = SQL_FETCHROW($result);
223 SQL_FREERESULT($result);
226 // Do we have entries found?
227 if ((!empty($tid)) && (!empty($fid))) {
229 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
231 bigintval(getRequestParameter('tid')),
233 ), __FILE__, __LINE__);
234 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
236 bigintval(getRequestParameter('fid')),
238 ), __FILE__, __LINE__);
243 $result = SQL_QUERY("SELECT id, action, what, title, sort FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." ORDER BY `sort` ASC", __FILE__, __LINE__);
245 // Do we have entries?
246 if (SQL_NUMROWS($result) > 0) {
247 // Remember sub value
248 $content['sub'] = $SUB;
251 $OUT = ''; $cnt = '0';
253 // Process all entries
254 while ($data = SQL_FETCHARRAY($result)) {
258 // Init navigation variable
260 if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
261 // Is highest position
262 $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>';
263 } elseif ($cnt == SQL_NUMROWS($result)) {
264 // Is lowest position
265 $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>';
266 } elseif ($data['sort'] > 0) {
267 // Anything else between highest and lowest
268 $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>';
271 // Add more data to $data
272 $data['mode'] = 'admin';
274 // Load row template and switch colors
275 $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
279 $content['rows'] = $OUT;
282 SQL_FREERESULT($result);
285 loadTemplate('admin_edit_admin_menu', false, $content);
287 // Menu entries are missing... (???)
288 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MENUS_FOUND--}');