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 - 2008 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')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
48 // Do we edit/delete/change main menus or sub menus?
49 $AND = "(`what` = '' OR `what` IS NULL)"; $SUB = '';
50 if (REQUEST_ISSET_GET('sub')) {
51 $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", REQUEST_GET('sub'));
52 $SUB = REQUEST_GET('sub');
55 // Get count of (maybe) selected menu points
57 if (REQUEST_ISSET_POST('sel')) $chk = countPostSelection();
59 // List all menu points and make them editable
60 if ((REQUEST_ISSET_POST('edit')) && ($chk > 0) && (!IS_DEMO())) {
62 // @TODO Kill all constants in this file
63 define('__SUB_VALUE', $SUB);
64 define('__CHK_VALUE', $chk);
66 foreach (REQUEST_POST('sel') as $sel => $confirm) {
69 $result = SQL_QUERY_ESC("SELECT title, action, what, descr FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE ".$AND." AND id=%s LIMIT 1",
70 array(bigintval($sel)), __FILE__, __LINE__);
71 if (SQL_NUMROWS($result) == 1) {
72 // Entry found so we load the stuff...
73 list($menu, $act, $wht, $descr) = SQL_FETCHROW($result);
74 SQL_FREERESULT($result);
76 // Prepare data for the row template
78 'action' => ADMIN_MAKE_MENU_SELECTION('admin', 'action', 'sel_action[' . $sel . ']', $act),
79 'what' => ADMIN_MAKE_MENU_SELECTION('admin', 'what', 'sel_what[' . $sel . ']', $wht),
86 $OUT .= LOAD_TEMPLATE('admin_amenu_edit_row', true, $content);
93 $OUT .= LOAD_TEMPLATE('admin_menu_404_row', true, $content);
99 define('__MENU_ROWS', $OUT);
100 define('__CNT_VALUE', $cnt);
103 LOAD_TEMPLATE('admin_amenu_edit_form');
104 } elseif ((REQUEST_ISSET_POST('del')) && (!IS_DEMO())) {
105 define('__SUB_VALUE', $SUB);
106 define('__CHK_VALUE', $chk);
107 // Del menu entries with or without confirmation
108 $SW = 2; $cnt = 0; $OUT = '';
109 foreach (REQUEST_POST('sel') as $sel => $confirm) {
112 $result = SQL_QUERY_ESC("SELECT title FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE ".$AND." AND id=%s LIMIT 1",
113 array(bigintval($sel)), __FILE__, __LINE__);
114 if (SQL_NUMROWS($result) == 1) {
115 // Entry found so we load the stuff...
116 list($menu) = SQL_FETCHROW($result);
117 SQL_FREERESULT($result);
119 // Prepare data for the row template
126 $OUT .= LOAD_TEMPLATE('admin_amenu_delete_row', true, $content);
133 $OUT .= LOAD_TEMPLATE('admin_menu_404_row', true, $content);
138 define('__MENU_ROWS', $OUT);
139 define('__CNT_VALUE', $cnt);
142 LOAD_TEMPLATE('admin_amenu_delete');
143 } elseif ((isFormSent()) && (!IS_DEMO())) {
144 // An action is done...
145 switch (REQUEST_POST('ok')) {
146 case 'edit': // Edit menu
147 foreach (REQUEST_POST('sel') as $sel => $menu) {
149 $sel = bigintval($sel);
152 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admin_menu` SET
157 WHERE ".$AND." AND id=%s LIMIT 1",
160 REQUEST_POST('sel_action', $sel),
161 REQUEST_POST('sel_what', $sel),
162 REQUEST_POST('sel_desc', $sel),
164 ), __FILE__, __LINE__);
167 // Purge admin menu cache
168 cachePurgeAdminMenu(0, REQUEST_POST('sel_action', $sel), REQUEST_POST('sel_what', $sel));
171 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
174 case 'del': // Delete menu
175 foreach (REQUEST_POST('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__);
178 cachePurgeAdminMenu(0, '', '', $AND);
182 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
185 default: // Unexpected action
186 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", REQUEST_POST('ok')));
187 define('__OK_VALUE', REQUEST_POST('ok'));
188 LOAD_TEMPLATE("admin_menu_unknown_okay");
192 if ((REQUEST_ISSET_GET(('act'))) && (REQUEST_ISSET_GET(('tid'))) && (REQUEST_ISSET_GET(('fid')))) {
194 if (REQUEST_ISSET_GET(('w'))) {
195 // Sub menus selected
196 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
197 array(REQUEST_GET('act'), bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
198 list($tid) = SQL_FETCHROW($result);
199 SQL_FREERESULT($result);
200 $result = SQL_QUERY("SELECT `id` FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
201 array(REQUEST_GET('act'), bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
202 list($fid) = SQL_FETCHROW($result);
203 SQL_FREERESULT($result);
205 // Main menu selected
206 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
207 array(bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
208 list($tid) = SQL_FETCHROW($result);
209 SQL_FREERESULT($result);
210 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
211 array(bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
212 list($fid) = SQL_FETCHROW($result);
213 SQL_FREERESULT($result);
216 if ((!empty($tid)) && (!empty($fid))) {
218 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
219 array(bigintval(REQUEST_GET('tid')), bigintval($fid)), __FILE__, __LINE__);
220 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
221 array(bigintval(REQUEST_GET('fid')), bigintval($tid)), __FILE__, __LINE__);
222 cachePurgeAdminMenu(0, '', '', $AND);
226 // By default list menus
228 // Sub menus of a main menu
229 $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",
230 array($SUB), __FILE__, __LINE__);
233 $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__);
236 $max = SQL_NUMROWS($result);
238 // @TODO Rewrite this constant
239 define('__SUB_VALUE', $SUB);
242 $OUT = ''; $SW = 2; $cnt = 0;
244 // Process all entries
245 while ($content = SQL_FETCHARRAY($result)) {
249 // Init navigation variable
250 $content['navi'] = '';
251 if (($content['sort'] == 0) || (($content['sort'] == 1) && (!empty($SUB)))) {
252 // Is highest position
253 $content['navi'] = "<a href=\"{!URL!}/modules.php?module=admin&what=adminedit&sub={!__SUB_VALUE!}&act=".$content['action']."&w=".$content['what']."&tid=".($content['sort']+1)."&fid=".$content['sort']."\">{--LOWER--}</a>";
254 } elseif ($cnt == $max) {
255 // Is lowest position
256 $content['navi'] = "<a href=\"{!URL!}/modules.php?module=admin&what=adminedit&sub={!__SUB_VALUE!}&act=".$content['action']."&w=".$content['what']."&tid=".($content['sort']-1)."&fid=".$content['sort']."\">{--HIGHER--}</a>";
257 } elseif ($content['sort'] > 0) {
258 // Anything else between highest and lowest
259 $content['navi'] = "<a href=\"{!URL!}/modules.php?module=admin&what=adminedit&sub={!__SUB_VALUE!}&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={!__SUB_VALUE!}&act=".$content['action']."&w=".$content['what']."&tid=".($content['sort']+1)."&fid=".$content['sort']."\">{--LOWER--}</a>";
262 // Fix empty elements for constant (fixes display bugs in Firefox)
263 if (empty($content['action'])) $content['action'] = ' ';
264 if (empty($content['what'])) $content['what'] = ' ';
265 if (empty($content['title'])) $content['title'] = ' ';
267 // Add more data to $content
268 $content['sw'] = $SW;
269 $content['mode'] = 'admin';
271 // Load row template and switch colors
272 $OUT .= LOAD_TEMPLATE('admin_menu_overview_row', true, $content);
277 SQL_FREERESULT($result);
279 // Rewrite this constant
280 define('__MENU_ROWS', $OUT);
283 LOAD_TEMPLATE('admin_amenu_edit');
285 // Menu entries are missing... (???)
286 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));