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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
47 // Do we edit/delete/change main menus or sub menus?
48 $AND = "(`what` = '' OR `what` IS NULL)"; $SUB = '';
49 if (isGetRequestParameterSet('sub')) {
50 $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", getRequestParameter('sub'));
51 $SUB = getRequestParameter('sub');
54 // List all menu points and make them editable
55 if ((isPostRequestParameterSet('edit')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
57 // @TODO Kill all constants in this file
58 $content['sub'] = $SUB;
59 $content['chk'] = countPostSelection();
61 foreach (postRequestParameter('sel') as $sel => $confirm) {
64 $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what`, `descr` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
65 array(bigintval($sel)), __FILE__, __LINE__);
66 if (SQL_NUMROWS($result) == 1) {
67 // Entry found so we load the stuff...
68 $data = SQL_FETCHARRAY($result);
70 // Prepare data for the row template
72 'action' => adminAddMenuSelectionBox('admin', 'action', 'sel_action[' . $sel . ']', $data['action']),
73 'what' => adminAddMenuSelectionBox('admin', 'what' , 'sel_what[' . $sel . ']', $data['what']),
76 'menu' => $data['title'],
77 'descr' => $data['descr'],
82 $OUT .= loadTemplate('admin_amenu_edit_row', true, $data);
91 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
94 // Free result and switch color
95 SQL_FREERESULT($result);
100 $content['rows'] = $OUT;
101 $content['cnt'] = $cnt;
104 loadTemplate('admin_amenu_edit_form', false, $content);
105 } elseif ((isPostRequestParameterSet('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
106 // Prepare misc content
107 $content['sub'] = $SUB;
108 $content['chk'] = countPostSelection();
110 // Del menu entries with or without confirmation
111 $SW = 2; $cnt = '0'; $OUT = '';
112 foreach (postRequestParameter('sel') as $sel => $confirm) {
115 $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
116 array(bigintval($sel)), __FILE__, __LINE__);
117 if (SQL_NUMROWS($result) == 1) {
118 // Entry found so we load the stuff...
119 $data = SQL_FETCHARRAY($result);
121 // Prepare data for the row template
123 'menu' => $data['title'],
128 $OUT .= loadTemplate('admin_amenu_delete_row', true, $data);
135 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
137 SQL_FREERESULT($result);
141 $content['rows'] = $OUT;
142 $content['cnt'] = $cnt;
145 loadTemplate('admin_amenu_delete', false, $content);
146 } elseif ((isFormSent()) && (!isDemoModeActive())) {
147 // An action is done...
148 switch (postRequestParameter('ok')) {
149 case 'edit': // Edit menu
150 foreach (postRequestParameter('sel') as $sel => $menu) {
152 $sel = bigintval($sel);
155 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET
160 WHERE ".$AND." AND `id`=%s LIMIT 1",
163 postRequestParameter('sel_action', $sel),
164 postRequestParameter('sel_what', $sel),
165 postRequestParameter('sel_desc', $sel),
167 ), __FILE__, __LINE__);
171 loadTemplate('admin_settings_saved', false, getMessage('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, getMessage('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 `action`='%s' AND `sort`='%s' LIMIT 1",
195 array(getRequestParameter('act'), bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
196 list($tid) = SQL_FETCHROW($result);
197 SQL_FREERESULT($result);
198 $result = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
199 array(getRequestParameter('act'), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
200 list($fid) = SQL_FETCHROW($result);
201 SQL_FREERESULT($result);
203 // Main menu selected
204 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
205 array(bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
206 list($tid) = SQL_FETCHROW($result);
207 SQL_FREERESULT($result);
208 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
209 array(bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
210 list($fid) = SQL_FETCHROW($result);
211 SQL_FREERESULT($result);
214 if ((!empty($tid)) && (!empty($fid))) {
216 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
217 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
218 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
219 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
223 // By default list menus
225 // Sub menus of a main menu
226 $result = SQL_QUERY_ESC("SELECT id, action, what, title, sort FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort` ASC",
227 array($SUB), __FILE__, __LINE__);
230 $result = SQL_QUERY("SELECT id, action, what, title, sort FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
233 $max = SQL_NUMROWS($result);
235 // Remember sub value
236 $content['sub'] = $SUB;
239 $OUT = ''; $SW = 2; $cnt = '0';
241 // Process all entries
242 while ($data = SQL_FETCHARRAY($result)) {
246 // Init navigation variable
248 if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
249 // Is highest position
250 $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>';
251 } elseif ($cnt == $max) {
252 // Is lowest position
253 $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>';
254 } elseif ($data['sort'] > 0) {
255 // Anything else between highest and lowest
256 $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>';
259 // Fix empty elements for constant (fixes display bugs in Firefox)
260 if (empty($data['action'])) $data['action'] = ' ';
261 if (empty($data['what'])) $data['what'] = ' ';
262 if (empty($data['title'])) $data['title'] = ' ';
264 // Add more data to $data
266 $data['mode'] = 'admin';
268 // Load row template and switch colors
269 $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
274 $content['rows'] = $OUT;
277 SQL_FREERESULT($result);
280 loadTemplate('admin_amenu_edit', false, $content);
282 // Menu entries are missing... (???)
283 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));