2 /************************************************************************
3 * MXChange v0.2.1 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 (isGetRequestElementSet('sub')) {
50 $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", getRequestElement('sub'));
51 $SUB = getRequestElement('sub');
54 // Get count of (maybe) selected menu points
56 if (isPostRequestElementSet('sel')) $chk = countPostSelection();
58 // List all menu points and make them editable
59 if ((isPostRequestElementSet('edit')) && ($chk > 0) && (!isDemoModeActive())) {
61 // @TODO Kill all constants in this file
62 $content['sub'] = $SUB;
63 $content['chk'] = $chk;
65 foreach (postRequestElement('sel') as $sel => $confirm) {
68 $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what`, `descr` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
69 array(bigintval($sel)), __FILE__, __LINE__);
70 if (SQL_NUMROWS($result) == 1) {
71 // Entry found so we load the stuff...
72 $data = SQL_FETCHARRAY($result);
74 // Prepare data for the row template
76 'action' => adminAddMenuSelectionBox('admin', 'action', 'sel_action[' . $sel . ']', $data['action']),
77 'what' => adminAddMenuSelectionBox('admin', 'what' , 'sel_what[' . $sel . ']', $data['what']),
80 'menu' => $data['title'],
81 'descr' => $data['descr'],
86 $OUT .= loadTemplate('admin_amenu_edit_row', true, $data);
95 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
98 // Free result and switch color
99 SQL_FREERESULT($result);
104 $content['rows'] = $OUT;
105 $content['cnt'] = $cnt;
108 loadTemplate('admin_amenu_edit_form', false, $content);
109 } elseif ((isPostRequestElementSet('del')) && (!isDemoModeActive())) {
110 // Prepare misc content
111 $content['sub'] = $SUB;
112 $content['chk'] = $chk;
114 // Del menu entries with or without confirmation
115 $SW = 2; $cnt = 0; $OUT = '';
116 foreach (postRequestElement('sel') as $sel => $confirm) {
119 $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
120 array(bigintval($sel)), __FILE__, __LINE__);
121 if (SQL_NUMROWS($result) == 1) {
122 // Entry found so we load the stuff...
123 $data = SQL_FETCHARRAY($result);
125 // Prepare data for the row template
127 'menu' => $data['title'],
132 $OUT .= loadTemplate('admin_amenu_delete_row', true, $data);
139 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
141 SQL_FREERESULT($result);
145 $content['rows'] = $OUT;
146 $content['cnt'] = $cnt;
149 loadTemplate('admin_amenu_delete', false, $content);
150 } elseif ((isFormSent()) && (!isDemoModeActive())) {
151 // An action is done...
152 switch (postRequestElement('ok')) {
153 case 'edit': // Edit menu
154 foreach (postRequestElement('sel') as $sel => $menu) {
156 $sel = bigintval($sel);
159 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET
164 WHERE ".$AND." AND id=%s LIMIT 1",
167 postRequestElement('sel_action', $sel),
168 postRequestElement('sel_what', $sel),
169 postRequestElement('sel_desc', $sel),
171 ), __FILE__, __LINE__);
175 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
178 case 'del': // Delete menu
179 foreach (postRequestElement('sel') as $sel => $menu) {
180 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
181 array(bigintval($sel)), __FILE__, __LINE__);
185 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
188 default: // Unexpected action
189 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestElement('ok')));
190 loadTemplate('admin_menu_unknown_okay', false, postRequestElement('ok'));
194 if ((isGetRequestElementSet(('act'))) && (isGetRequestElementSet(('tid'))) && (isGetRequestElementSet(('fid')))) {
196 if (isGetRequestElementSet(('w'))) {
197 // Sub menus selected
198 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
199 array(getRequestElement('act'), bigintval(getRequestElement('tid'))), __FILE__, __LINE__);
200 list($tid) = SQL_FETCHROW($result);
201 SQL_FREERESULT($result);
202 $result = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
203 array(getRequestElement('act'), bigintval(getRequestElement('fid'))), __FILE__, __LINE__);
204 list($fid) = SQL_FETCHROW($result);
205 SQL_FREERESULT($result);
207 // Main menu selected
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(getRequestElement('tid'))), __FILE__, __LINE__);
210 list($tid) = SQL_FETCHROW($result);
211 SQL_FREERESULT($result);
212 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
213 array(bigintval(getRequestElement('fid'))), __FILE__, __LINE__);
214 list($fid) = SQL_FETCHROW($result);
215 SQL_FREERESULT($result);
218 if ((!empty($tid)) && (!empty($fid))) {
220 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
221 array(bigintval(getRequestElement('tid')), bigintval($fid)), __FILE__, __LINE__);
222 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
223 array(bigintval(getRequestElement('fid')), bigintval($tid)), __FILE__, __LINE__);
227 // By default list menus
229 // Sub menus of a main menu
230 $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",
231 array($SUB), __FILE__, __LINE__);
234 $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__);
237 $max = SQL_NUMROWS($result);
239 // Remember sub value
240 $content['sub'] = $SUB;
243 $OUT = ''; $SW = 2; $cnt = 0;
245 // Process all entries
246 while ($data = SQL_FETCHARRAY($result)) {
250 // Init navigation variable
252 if (($data['sort'] == 0) || (($data['sort'] == 1) && (!empty($SUB)))) {
253 // Is highest position
254 $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>";
255 } elseif ($cnt == $max) {
256 // Is lowest position
257 $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>";
258 } elseif ($data['sort'] > 0) {
259 // Anything else between highest and lowest
260 $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>";
263 // Fix empty elements for constant (fixes display bugs in Firefox)
264 if (empty($data['action'])) $data['action'] = ' ';
265 if (empty($data['what'])) $data['what'] = ' ';
266 if (empty($data['title'])) $data['title'] = ' ';
268 // Add more data to $data
270 $data['mode'] = 'admin';
272 // Load row template and switch colors
273 $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
278 $content['rows'] = $OUT;
281 SQL_FREERESULT($result);
284 loadTemplate('admin_amenu_edit', false, $content);
286 // Menu entries are missing... (???)
287 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));