2 /************************************************************************
3 * MXChange v0.2.1 Start: 09/28/2003 *
4 * =============== Last change: 12/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-guestedit.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Edit guest's menu *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Menue fuer die Gaeste 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 = '';
51 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 = countPostSelection();
60 // List all menu points and make them editable
61 if ((REQUEST_ISSET_POST('edit')) && ($chk > 0) && (!IS_DEMO()))
64 define('__SUB_VALUE', $SUB);
65 define('__CHK_VALUE', $chk);
67 $cnt = 0; $OUT = ''; $SW = 2;
68 foreach (REQUEST_POST('sel') as $sel => $confirm)
73 $result = SQL_QUERY_ESC("SELECT title, action, what FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE ".$AND." AND id=%s LIMIT 1",
74 array(bigintval($sel)), __FILE__, __LINE__);
75 if (SQL_NUMROWS($result) == 1)
77 // Entry found so we load the stuff...
78 list($menu, $act, $wht) = SQL_FETCHROW($result);
79 SQL_FREERESULT($result);
83 'action' => ADMIN_MAKE_MENU_SELECTION('guest', 'action', 'sel_action[' . $sel . ']', $act),
84 'what' => ADMIN_MAKE_MENU_SELECTION('guest', 'what', 'sel_what[' . $sel . ']', $wht),
88 $OUT .= LOAD_TEMPLATE("admin_gmenu_edit_row", true, $DATA);
97 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
102 define('__MENU_ROWS', $OUT);
103 define('__CNT_VALUE', $cnt);
106 LOAD_TEMPLATE("admin_gmenu_edit_form");
107 } elseif ((REQUEST_ISSET_POST('del')) && (!IS_DEMO())) {
108 // Del menu entries with or without confirmation
109 define('__SUB_VALUE', $SUB);
110 define('__CHK_VALUE', $chk);
112 $cnt = 0; $OUT = ''; $SW = 2;
113 foreach (REQUEST_POST('sel') as $sel => $confirm) {
116 $result = SQL_QUERY_ESC("SELECT title FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE ".$AND." AND id=%s LIMIT 1",
117 array(bigintval($sel)), __FILE__, __LINE__);
118 if (SQL_NUMROWS($result) == 1) {
119 // Entry found so we load the stuff...
120 list($menu) = SQL_FETCHROW($result);
121 SQL_FREERESULT($result);
128 $OUT .= LOAD_TEMPLATE("admin_gmenu_delete_row", true, $DATA);
135 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
140 define('__MENU_ROWS', $OUT);
141 define('__CNT_VALUE', $cnt);
144 LOAD_TEMPLATE("admin_gmenu_delete");
145 } elseif ((isFormSent()) && (!IS_DEMO())) {
146 // An action is done...
147 switch (REQUEST_POST('ok'))
149 case 'edit': // Edit menu
150 foreach (REQUEST_POST('sel') as $sel => $menu) {
152 $sel = bigintval($sel);
155 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_guest_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
156 array($menu, REQUEST_POST('sel_action', $sel), REQUEST_POST('sel_what', $sel), $sel),__FILE__, __LINE__);
158 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
161 case 'del': // Delete menu
162 foreach (REQUEST_POST('sel') as $sel => $menu) {
164 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE ".$AND." AND id=%s LIMIT 1",
165 array(bigintval($sel)), __FILE__, __LINE__);
167 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
170 case 'status': // Change access levels
171 foreach (REQUEST_POST('sel') as $sel => $menu) {
173 $sel = bigintval($sel);
176 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_guest_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
177 array(REQUEST_POST('visible', $sel), REQUEST_POST('locked', $sel), $sel), __FILE__, __LINE__);
179 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
182 default: // Unexpected action
183 define('__OK_VALUE', REQUEST_POST('ok'));
184 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", REQUEST_POST('ok')));
185 LOAD_TEMPLATE("admin_menu_unknown_okay");
188 } elseif ((REQUEST_ISSET_POST(('status'))) && ($chk > 0) && (!IS_DEMO())) {
189 // Change status (visible / locked)
190 define('__SUB_VALUE', $SUB);
191 define('__CHK_VALUE', $chk);
194 $SW = 2; $cnt = 0; $OUT = '';
195 foreach (REQUEST_POST('sel') as $sel => $confirm)
200 $result = SQL_QUERY_ESC("SELECT title, visible, locked FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE ".$AND." AND id=%s LIMIT 1",
201 array(bigintval($sel)), __FILE__, __LINE__);
202 if (SQL_NUMROWS($result) == 1)
204 // Entry found so we load the stuff...
205 list($menu, $vis, $locked) = SQL_FETCHROW($result);
206 SQL_FREERESULT($result);
212 'visible' => ADD_SELECTION('yn', $vis , 'visible', $sel),
213 'locked' => ADD_SELECTION('yn', $locked, 'locked' , $sel),
217 $OUT .= LOAD_TEMPLATE('admin_menu_status_row', true, $content);
226 $OUT .= LOAD_TEMPLATE('admin_menu_404_row', true, $content);
231 define('__CNT_VALUE', $cnt);
232 define('__MENU_ROWS', $OUT);
235 LOAD_TEMPLATE('admin_gmenu_status');
237 if ((REQUEST_ISSET_GET(('act'))) && (REQUEST_ISSET_GET(('tid'))) && (REQUEST_ISSET_GET(('fid')))) {
239 if (REQUEST_ISSET_GET(('w'))) {
240 // Sub menus selected
241 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
242 array(REQUEST_GET('act'), bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
243 list($tid) = SQL_FETCHROW($result);
244 SQL_FREERESULT($result);
245 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
246 array(REQUEST_GET('act'), bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
247 list($fid) = SQL_FETCHROW($result);
248 SQL_FREERESULT($result);
250 // Main menu selected
251 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
252 array(bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
253 list($tid) = SQL_FETCHROW($result);
254 SQL_FREERESULT($result);
255 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
256 array(bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
257 list($fid) = SQL_FETCHROW($result);
258 SQL_FREERESULT($result);
261 if ((!empty($tid)) && (!empty($fid))) {
263 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_guest_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
264 array(bigintval(REQUEST_GET('tid')), bigintval($fid)), __FILE__, __LINE__);
265 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_guest_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
266 array(bigintval(REQUEST_GET('fid')), bigintval($tid)), __FILE__, __LINE__);
270 // By default list menus
272 // List only main menus
273 $result = SQL_QUERY("SELECT `id`,`action`,`what`,`title`,`sort` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
276 $result = SQL_QUERY_ESC("SELECT `id`,`action`,`what`,`title`,`sort` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort` ASC",
277 array($SUB), __FILE__, __LINE__);
280 // Get number of menu entries
281 $max = SQL_NUMROWS($result);
284 // @TODO Rewrite this constant
285 define('__SUB_VALUE', $SUB);
292 // Process all menu entries
293 while ($content = SQL_FETCHARRAY($result)) {
295 if (($content['sort'] == 0) || (($content['sort'] == 1) && (!empty($SUB)))) {
296 // Is highest position
297 $NAVI = "<a href=\"{!URL!}/modules.php?module=admin&what=guestedit&sub={!__SUB_VALUE!}&act=".$content['action']."&w=".$content['what']."&tid=".($content['sort']+1)."&fid=".$content['sort']."\">{--LOWER--}</a>";
298 } elseif ($cnt == $max) {
299 // Is lowest position
300 $NAVI = "<a href=\"{!URL!}/modules.php?module=admin&what=guestedit&sub={!__SUB_VALUE!}&act=".$content['action']."&w=".$content['what']."&tid=".($content['sort']-1)."&fid=".$content['sort']."\">{--HIGHER--}</a>";
301 } elseif ($content['sort'] > 0) {
302 // Anything else between highest and lowest
303 $NAVI = "<a href=\"{!URL!}/modules.php?module=admin&what=guestedit&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=guestedit&sub={!__SUB_VALUE!}&act=".$content['action']."&w=".$content['what']."&tid=".($content['sort']+1)."&fid=".$content['sort']."\">{--LOWER--}</a>";
306 if (empty($content['action'])) $content['action'] = ' ';
307 if (empty($content['what'])) $content['what'] = ' ';
308 if (empty($content['title'])) $content['title'] = ' ';
312 'id' => $content['id'],
313 'action' => $content['action'],
314 'what' => $content['what'],
315 'title' => $content['title'],
319 $OUT .= LOAD_TEMPLATE('admin_menu_overview_row', true, $content);
324 SQL_FREERESULT($result);
325 define('__MENU_ROWS', $OUT);
328 LOAD_TEMPLATE('admin_gmenu_edit');
330 // Menu entries are missing... (???)
331 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));