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())) {
63 define('__SUB_VALUE', $SUB);
64 define('__CHK_VALUE', $chk);
66 $cnt = 0; $OUT = ''; $SW = 2;
67 foreach (REQUEST_POST('sel') as $sel => $confirm) {
70 $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
71 array(bigintval($sel)), __FILE__, __LINE__);
72 if (SQL_NUMROWS($result) == 1) {
73 // Entry found so we load the stuff...
74 list($menu, $act, $wht) = SQL_FETCHROW($result);
78 'action' => ADMIN_MAKE_MENU_SELECTION('guest', 'action', 'sel_action[' . $sel . ']', $act),
79 'what' => ADMIN_MAKE_MENU_SELECTION('guest', 'what', 'sel_what[' . $sel . ']', $wht),
83 $OUT .= LOAD_TEMPLATE('admin_gmenu_edit_row', true, $DATA);
90 $OUT .= LOAD_TEMPLATE('admin_menu_404_row', true, $content);
92 SQL_FREERESULT($result);
97 define('__MENU_ROWS', $OUT);
98 define('__CNT_VALUE', $cnt);
101 LOAD_TEMPLATE('admin_gmenu_edit_form');
102 } elseif ((REQUEST_ISSET_POST('del')) && (!IS_DEMO())) {
103 // Del menu entries with or without confirmation
104 define('__SUB_VALUE', $SUB);
105 define('__CHK_VALUE', $chk);
111 foreach (REQUEST_POST('sel') as $sel => $confirm) {
114 $result = SQL_QUERY_ESC("SELECT `title` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
115 array(bigintval($sel)), __FILE__, __LINE__);
116 if (SQL_NUMROWS($result) == 1) {
117 // Entry found so we load the stuff...
118 list($menu) = SQL_FETCHROW($result);
125 $OUT .= LOAD_TEMPLATE('admin_gmenu_delete_row', true, $DATA);
132 $OUT .= LOAD_TEMPLATE('admin_menu_404_row', true, $content);
134 SQL_FREERESULT($result);
138 define('__MENU_ROWS', $OUT);
139 define('__CNT_VALUE', $cnt);
142 LOAD_TEMPLATE('admin_gmenu_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!}_guest_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
153 array($menu, REQUEST_POST('sel_action', $sel), REQUEST_POST('sel_what', $sel), $sel),__FILE__, __LINE__);
155 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
158 case 'del': // Delete menu
159 foreach (REQUEST_POST('sel') as $sel => $menu) {
161 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE ".$AND." AND id=%s LIMIT 1",
162 array(bigintval($sel)), __FILE__, __LINE__);
164 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
167 case 'status': // Change access levels
168 foreach (REQUEST_POST('sel') as $sel => $menu) {
170 $sel = bigintval($sel);
173 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_guest_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
174 array(REQUEST_POST('visible', $sel), REQUEST_POST('locked', $sel), $sel), __FILE__, __LINE__);
176 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
179 default: // Unexpected action
180 define('__OK_VALUE', REQUEST_POST('ok'));
181 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", REQUEST_POST('ok')));
182 LOAD_TEMPLATE('admin_menu_unknown_okay');
185 } elseif ((REQUEST_ISSET_POST('status')) && ($chk > 0) && (!IS_DEMO())) {
186 // Change status (visible / locked)
187 define('__SUB_VALUE', $SUB);
188 define('__CHK_VALUE', $chk);
191 $SW = 2; $cnt = 0; $OUT = '';
192 foreach (REQUEST_POST('sel') as $sel => $confirm) {
195 $result = SQL_QUERY_ESC("SELECT title, visible, locked FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE ".$AND." AND id=%s LIMIT 1",
196 array(bigintval($sel)), __FILE__, __LINE__);
197 if (SQL_NUMROWS($result) == 1) {
198 // Entry found so we load the stuff...
199 list($menu, $vis, $locked) = SQL_FETCHROW($result);
205 'visible' => ADD_SELECTION('yn', $vis , 'visible', $sel),
206 'locked' => ADD_SELECTION('yn', $locked, 'locked' , $sel),
210 $OUT .= LOAD_TEMPLATE('admin_menu_status_row', true, $content);
217 $OUT .= LOAD_TEMPLATE('admin_menu_404_row', true, $content);
220 SQL_FREERESULT($result);
224 define('__CNT_VALUE', $cnt);
225 define('__MENU_ROWS', $OUT);
228 LOAD_TEMPLATE('admin_gmenu_status');
230 if ((REQUEST_ISSET_GET('act')) && (REQUEST_ISSET_GET('tid')) && (REQUEST_ISSET_GET('fid'))) {
232 if (REQUEST_ISSET_GET('w')) {
233 // Sub menus selected
234 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
235 array(REQUEST_GET('act'), bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
236 list($tid) = SQL_FETCHROW($result);
237 SQL_FREERESULT($result);
238 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
239 array(REQUEST_GET('act'), bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
240 list($fid) = SQL_FETCHROW($result);
241 SQL_FREERESULT($result);
243 // Main menu selected
244 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
245 array(bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
246 list($tid) = SQL_FETCHROW($result);
247 SQL_FREERESULT($result);
248 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
249 array(bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
250 list($fid) = SQL_FETCHROW($result);
251 SQL_FREERESULT($result);
254 if ((!empty($tid)) && (!empty($fid))) {
256 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_guest_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
257 array(bigintval(REQUEST_GET('tid')), bigintval($fid)), __FILE__, __LINE__);
258 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_guest_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
259 array(bigintval(REQUEST_GET('fid')), bigintval($tid)), __FILE__, __LINE__);
263 // By default list menus
265 // List only main menus
266 $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__);
269 $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",
270 array($SUB), __FILE__, __LINE__);
273 // Get number of menu entries
274 $max = SQL_NUMROWS($result);
277 // @TODO Rewrite this constant
278 define('__SUB_VALUE', $SUB);
285 // Process all menu entries
286 while ($content = SQL_FETCHARRAY($result)) {
288 if (($content['sort'] == 0) || (($content['sort'] == 1) && (!empty($SUB)))) {
289 // Is highest position
290 $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>";
291 } elseif ($cnt == $max) {
292 // Is lowest position
293 $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>";
294 } elseif ($content['sort'] > 0) {
295 // Anything else between highest and lowest
296 $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>";
299 if (empty($content['action'])) $content['action'] = ' ';
300 if (empty($content['what'])) $content['what'] = ' ';
301 if (empty($content['title'])) $content['title'] = ' ';
306 'id' => $content['id'],
307 'action' => $content['action'],
308 'what' => $content['what'],
309 'title' => $content['title'],
315 $OUT .= LOAD_TEMPLATE('admin_menu_overview_row', true, $content);
320 SQL_FREERESULT($result);
321 define('__MENU_ROWS', $OUT);
324 LOAD_TEMPLATE('admin_gmenu_edit');
326 // Menu entries are missing... (???)
327 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));