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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
43 // Do we edit/delete/change main menus or sub menus?
44 $AND = "(`what` = '' OR `what` IS NULL)"; $SUB = "";
45 if (!empty($_GET['sub']))
47 $AND = sprintf("action='%s' AND `what` IS NOT NULL", SQL_ESCAPE($_GET['sub']));
48 $SUB = SQL_ESCAPE($_GET['sub']);
51 // Get count of (maybe) selected menu points
53 if (!empty($_POST['sel'])) $chk = SELECTION_COUNT($_POST['sel']);
55 // List all menu points and make them editable
56 if ((isset($_POST['edit'])) && ($chk > 0) && (!IS_DEMO())) {
58 define('__SUB_VALUE', $SUB);
59 define('__CHK_VALUE', $chk);
61 foreach ($_POST['sel'] as $sel => $confirm)
66 $result = SQL_QUERY_ESC("SELECT title, action, what, descr FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE ".$AND." AND id=%s LIMIT 1",
67 array(bigintval($sel)), __FILE__, __LINE__);
68 if (SQL_NUMROWS($result) == 1)
70 // Entry found so we load the stuff...
71 list($menu, $act, $wht, $descr) = SQL_FETCHROW($result);
72 SQL_FREERESULT($result);
74 // Prepare data for the row template
76 'action' => ADMIN_MAKE_MENU_SELECTION("admin", "action", "sel_action[".$sel."]", $act),
77 'what' => ADMIN_MAKE_MENU_SELECTION("admin", "what", "sel_what[".$sel."]", $wht),
84 $OUT .= LOAD_TEMPLATE("admin_amenu_edit_row", true, $content);
93 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
98 define('__MENU_ROWS', $OUT);
99 define('__CNT_VALUE', $cnt);
102 LOAD_TEMPLATE("admin_amenu_edit_form");
104 elseif ((isset($_POST['del'])) && (!IS_DEMO()))
106 define('__SUB_VALUE', $SUB);
107 define('__CHK_VALUE', $chk);
108 // Del menu entries with or without confirmation
109 $SW = 2; $cnt = 0; $OUT = "";
110 foreach ($_POST['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)
119 // Entry found so we load the stuff...
120 list($menu) = SQL_FETCHROW($result);
121 SQL_FREERESULT($result);
123 // Prepare data for the row template
130 $OUT .= LOAD_TEMPLATE("admin_amenu_delete_row", true, $content);
139 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
144 define('__MENU_ROWS', $OUT);
145 define('__CNT_VALUE', $cnt);
148 LOAD_TEMPLATE("admin_amenu_delete");
149 } elseif ((isset($_POST['ok'])) && (!IS_DEMO())) {
150 // An action is done...
151 switch ($_POST['ok'])
153 case "edit": // Edit menu
154 foreach ($_POST['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 $_POST['sel_action'][$sel],
168 $_POST['sel_what'][$sel],
169 $_POST['sel_desc'][$sel],
171 ), __FILE__, __LINE__);
174 // Purge admin menu cache
175 CACHE_PURGE_ADMIN_MENU(0, $_POST['sel_action'][$sel], $_POST['sel_what'][$sel]);
178 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_SAVED'));
181 case "del": // Delete menu
182 foreach ($_POST['sel'] as $sel => $menu) {
183 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE ".$AND." AND id=%s LIMIT 1",
184 array(bigintval($sel)), __FILE__, __LINE__);
185 CACHE_PURGE_ADMIN_MENU(0, "", "", $AND);
189 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_SAVED'));
192 default: // Unexpected action
193 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", $_POST['ok']));
194 define('__OK_VALUE', $_POST['ok']);
195 LOAD_TEMPLATE("admin_menu_unknown_okay");
199 if ((!empty($_GET['act'])) && (!empty($_GET['tid'])) && (!empty($_GET['fid']))) {
201 if (!empty($_GET['w'])) {
202 // Sub menus selected
203 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE action='%s' AND sort='%s' LIMIT 1",
204 array($_GET['act'], bigintval($_GET['tid'])), __FILE__, __LINE__);
205 list($tid) = SQL_FETCHROW($result);
206 SQL_FREERESULT($result);
207 $result = SQL_QUERY("SELECT id FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE action='%s' AND sort='%s' LIMIT 1",
208 array($_GET['act'], bigintval($_GET['fid'])), __FILE__, __LINE__);
209 list($fid) = SQL_FETCHROW($result);
210 SQL_FREERESULT($result);
214 // Main menu selected
215 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE (what='' OR `what` IS NULL) AND sort='%s' LIMIT 1",
216 array(bigintval($_GET['tid'])), __FILE__, __LINE__);
217 list($tid) = SQL_FETCHROW($result);
218 SQL_FREERESULT($result);
219 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE (what='' OR `what` IS NULL) AND sort='%s' LIMIT 1",
220 array(bigintval($_GET['fid'])), __FILE__, __LINE__);
221 list($fid) = SQL_FETCHROW($result);
222 SQL_FREERESULT($result);
225 if ((!empty($tid)) && (!empty($fid)))
228 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admin_menu` SET sort='%s' WHERE ".$AND." AND id=%s LIMIT 1",
229 array(bigintval($_GET['tid']), bigintval($fid)), __FILE__, __LINE__);
230 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admin_menu` SET sort='%s' WHERE ".$AND." AND id=%s LIMIT 1",
231 array(bigintval($_GET['fid']), bigintval($tid)), __FILE__, __LINE__);
232 CACHE_PURGE_ADMIN_MENU(0, "", "", $AND);
236 // By default list menus
239 // Sub menus of a main menu
240 $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",
241 array($SUB), __FILE__, __LINE__);
246 $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__);
248 $max = SQL_NUMROWS($result);
251 define('__SUB_VALUE', $SUB);
252 $SW = 2; $cnt = 0; $OUT = "";
253 while (list($id, $act, $wht, $title, $sort) = SQL_FETCHROW($result))
256 if (($sort == 0) || (($sort == 1) && (!empty($SUB))))
258 // Is highest position
259 $NAVI = "<a href=\"{!URL!}/modules.php?module=admin&what=adminedit&sub=".$SUB."&act=".$act."&w=".$wht."&tid=".($sort+1)."&fid=".$sort."\">{!LOWER!}</a>";
261 elseif ($cnt == $max)
263 // Is lowest position
264 $NAVI = "<a href=\"{!URL!}/modules.php?module=admin&what=adminedit&sub=".$SUB."&act=".$act."&w=".$wht."&tid=".($sort-1)."&fid=".$sort."\">{!HIGHER!}</a>";
268 // Anything else between highest and lowest
269 $NAVI = "<a href=\"{!URL!}/modules.php?module=admin&what=adminedit&sub=".$SUB."&act=".$act."&w=".$wht."&tid=".($sort-1)."&fid=".$sort."\">{!HIGHER!}</a>/<a href=\"{!URL!}/modules.php?module=admin&what=adminedit&sub=".$SUB."&act=".$act."&w=".$wht."&tid=".($sort+1)."&fid=".$sort."\">{!LOWER!}</a>";
272 if (empty($act)) $act = " ";
273 if (empty($wht)) $wht = " ";
274 if (empty($title)) $title = " ";
285 $OUT .= LOAD_TEMPLATE("admin_menu_overview_row", true, $content);
290 SQL_FREERESULT($result);
291 define('__MENU_ROWS', $OUT);
294 LOAD_TEMPLATE("admin_amenu_edit");
298 // Menu entries are missing... (???)
299 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_NO_MENUS_FOUND'));