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 * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. March 2009) $ *
15 * $Tag:: 0.2.1-FINAL $ *
16 * $Author:: stelzi $ *
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')))
52 $AND = sprintf("action='%s' AND `what` IS NOT NULL", REQUEST_GET(('sub')));
53 $SUB = REQUEST_GET(('sub'));
56 // Get count of (maybe) selected menu points
58 if (REQUEST_ISSET_POST('sel')) $chk = SELECTION_COUNT(REQUEST_POST('sel'));
60 // List all menu points and make them editable
61 if ((REQUEST_ISSET_POST('edit')) && ($chk > 0) && (!IS_DEMO())) {
63 define('__SUB_VALUE', $SUB);
64 define('__CHK_VALUE', $chk);
66 foreach (REQUEST_POST('sel') as $sel => $confirm)
71 $result = SQL_QUERY_ESC("SELECT title, action, what, descr FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE ".$AND." AND id=%s LIMIT 1",
72 array(bigintval($sel)), __FILE__, __LINE__);
73 if (SQL_NUMROWS($result) == 1)
75 // Entry found so we load the stuff...
76 list($menu, $act, $wht, $descr) = SQL_FETCHROW($result);
77 SQL_FREERESULT($result);
79 // Prepare data for the row template
81 'action' => ADMIN_MAKE_MENU_SELECTION("admin", "action", "sel_action[".$sel."]", $act),
82 'what' => ADMIN_MAKE_MENU_SELECTION("admin", "what", "sel_what[".$sel."]", $wht),
89 $OUT .= LOAD_TEMPLATE("admin_amenu_edit_row", true, $content);
98 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
103 define('__MENU_ROWS', $OUT);
104 define('__CNT_VALUE', $cnt);
107 LOAD_TEMPLATE("admin_amenu_edit_form");
109 elseif ((REQUEST_ISSET_POST('del')) && (!IS_DEMO()))
111 define('__SUB_VALUE', $SUB);
112 define('__CHK_VALUE', $chk);
113 // Del menu entries with or without confirmation
114 $SW = 2; $cnt = 0; $OUT = "";
115 foreach (REQUEST_POST('sel') as $sel => $confirm)
120 $result = SQL_QUERY_ESC("SELECT title FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE ".$AND." AND id=%s LIMIT 1",
121 array(bigintval($sel)), __FILE__, __LINE__);
122 if (SQL_NUMROWS($result) == 1)
124 // Entry found so we load the stuff...
125 list($menu) = SQL_FETCHROW($result);
126 SQL_FREERESULT($result);
128 // Prepare data for the row template
135 $OUT .= LOAD_TEMPLATE("admin_amenu_delete_row", true, $content);
144 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
149 define('__MENU_ROWS', $OUT);
150 define('__CNT_VALUE', $cnt);
153 LOAD_TEMPLATE("admin_amenu_delete");
154 } elseif ((IS_FORM_SENT()) && (!IS_DEMO())) {
155 // An action is done...
156 switch (REQUEST_POST('ok'))
158 case "edit": // Edit menu
159 foreach (REQUEST_POST('sel') as $sel => $menu) {
161 $sel = bigintval($sel);
164 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admin_menu` SET
169 WHERE ".$AND." AND id=%s LIMIT 1",
172 REQUEST_POST('sel_action', $sel),
173 REQUEST_POST('sel_what', $sel),
174 REQUEST_POST('sel_desc', $sel),
176 ), __FILE__, __LINE__);
179 // Purge admin menu cache
180 CACHE_PURGE_ADMIN_MENU(0, REQUEST_POST('sel_action', $sel), REQUEST_POST('sel_what', $sel));
183 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_SAVED'));
186 case "del": // Delete menu
187 foreach (REQUEST_POST('sel') as $sel => $menu) {
188 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE ".$AND." AND id=%s LIMIT 1",
189 array(bigintval($sel)), __FILE__, __LINE__);
190 CACHE_PURGE_ADMIN_MENU(0, "", "", $AND);
194 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_SAVED'));
197 default: // Unexpected action
198 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", REQUEST_POST('ok')));
199 define('__OK_VALUE', REQUEST_POST('ok'));
200 LOAD_TEMPLATE("admin_menu_unknown_okay");
204 if ((REQUEST_ISSET_GET(('act'))) && (REQUEST_ISSET_GET(('tid'))) && (REQUEST_ISSET_GET(('fid')))) {
206 if (REQUEST_ISSET_GET(('w'))) {
207 // Sub menus selected
208 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
209 array(REQUEST_GET('act'), bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
210 list($tid) = SQL_FETCHROW($result);
211 SQL_FREERESULT($result);
212 $result = SQL_QUERY("SELECT id FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
213 array(REQUEST_GET('act'), bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
214 list($fid) = SQL_FETCHROW($result);
215 SQL_FREERESULT($result);
217 // Main menu selected
218 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE (what='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
219 array(bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
220 list($tid) = SQL_FETCHROW($result);
221 SQL_FREERESULT($result);
222 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE (what='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
223 array(bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
224 list($fid) = SQL_FETCHROW($result);
225 SQL_FREERESULT($result);
228 if ((!empty($tid)) && (!empty($fid))) {
230 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
231 array(bigintval(REQUEST_GET('tid')), bigintval($fid)), __FILE__, __LINE__);
232 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
233 array(bigintval(REQUEST_GET('fid')), bigintval($tid)), __FILE__, __LINE__);
234 CACHE_PURGE_ADMIN_MENU(0, "", "", $AND);
238 // By default list menus
240 // Sub menus of a main menu
241 $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",
242 array($SUB), __FILE__, __LINE__);
245 $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);
250 // @TODO Rewrite this constant
251 define('__SUB_VALUE', $SUB);
254 $OUT = ""; $SW = 2; $cnt = 0;
256 // Process all entries
257 while ($content = SQL_FETCHARRAY($result)) {
261 // Init navigation variable
262 $content['navi'] = "";
263 if (($content['sort'] == 0) || (($content['sort'] == 1) && (!empty($SUB)))) {
264 // Is highest position
265 $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>";
266 } elseif ($cnt == $max) {
267 // Is lowest position
268 $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>";
269 } elseif ($content['sort'] > 0) {
270 // Anything else between highest and lowest
271 $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>";
274 // Fix empty elements for constant (fixes display bugs in Firefox)
275 if (empty($content['action'])) $content['action'] = " ";
276 if (empty($content['what'])) $content['what'] = " ";
277 if (empty($content['title'])) $content['title'] = " ";
279 // Add more data to $content
280 $content['sw'] = $SW;
281 $content['mode'] = "admin";
283 // Load row template and switch colors
284 $OUT .= LOAD_TEMPLATE("admin_menu_overview_row", true, $content);
289 SQL_FREERESULT($result);
291 // Rewrite this constant
292 define('__MENU_ROWS', $OUT);
295 LOAD_TEMPLATE("admin_amenu_edit");
297 // Menu entries are missing... (???)
298 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_NO_MENUS_FOUND'));