2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 - 2009 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')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
47 // Do we edit/delete/change main menus or sub menus?
48 $AND = "(`what` = '' OR `what` IS NULL)"; $SUB = '';
50 if (isGetRequestParameterSet('sub')) {
51 $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", getRequestParameter('sub'));
52 $SUB = getRequestParameter('sub');
55 // List all menu points and make them editable
56 if ((isPostRequestParameterSet('edit')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
58 $content['sub'] = $SUB;
59 $content['chk'] = countPostSelection();
61 $cnt = '0'; $OUT = ''; $SW = 2;
62 foreach (postRequestParameter('sel') as $sel => $confirm) {
65 $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
66 array(bigintval($sel)), __FILE__, __LINE__);
67 if (SQL_NUMROWS($result) == 1) {
68 // Entry found so we load the stuff...
69 $DATA = SQL_FETCHARRAY($result);
75 'action' => adminAddMenuSelectionBox('guest', 'action', 'sel_action[' . $sel . ']', $DATA['action']),
76 'what' => adminAddMenuSelectionBox('guest', 'what' , 'sel_what[' . $sel . ']', $DATA['what']),
77 'menu' => $DATA['title'],
82 $OUT .= loadTemplate('admin_gmenu_edit_row', true, $DATA);
89 $OUT .= loadTemplate('admin_menu_404_row', true, $DATA);
92 // Free result and switch color
93 SQL_FREERESULT($result);
98 $content['rows'] = $OUT;
99 $content['cnt'] = $cnt;
102 loadTemplate('admin_gmenu_edit_form', false, $content);
103 } elseif ((isPostRequestParameterSet('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
104 // Del menu entries with or without confirmation
105 $content['sub'] = $SUB;
106 $content['chk'] = countPostSelection();
112 foreach (postRequestParameter('sel') as $sel => $confirm) {
115 $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
116 array(bigintval($sel)), __FILE__, __LINE__);
117 if (SQL_NUMROWS($result) == 1) {
118 // Entry found so we load the stuff...
119 $DATA = SQL_FETCHARRAY($result);
122 'menu' => $DATA['title'],
126 $OUT .= loadTemplate('admin_gmenu_delete_row', true, $DATA);
133 $OUT .= loadTemplate('admin_menu_404_row', true, $DATA);
135 SQL_FREERESULT($result);
139 $content['rows'] = $OUT;
140 $content['cnt'] = $cnt;
143 loadTemplate('admin_gmenu_delete', false, $content);
144 } elseif ((isFormSent()) && (!isDemoModeActive())) {
145 // An action is done...
146 switch (postRequestParameter('ok')) {
147 case 'edit': // Edit menu
148 foreach (postRequestParameter('sel') as $sel => $menu) {
150 $sel = bigintval($sel);
153 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
154 array($menu, postRequestParameter('sel_action', $sel), postRequestParameter('sel_what', $sel), $sel),__FILE__, __LINE__);
156 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
159 case 'del': // Delete menu
160 foreach (postRequestParameter('sel') as $sel => $menu) {
162 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
163 array(bigintval($sel)), __FILE__, __LINE__);
165 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
168 case 'status': // Change access levels
169 foreach (postRequestParameter('sel') as $sel => $menu) {
171 $sel = bigintval($sel);
174 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
175 array(postRequestParameter('visible', $sel), postRequestParameter('locked', $sel), $sel), __FILE__, __LINE__);
177 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
180 default: // Unexpected action
181 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
182 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
185 } elseif ((isPostRequestParameterSet('status')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
186 // Change status (visible / locked)
187 $content['sub'] = $SUB;
188 $content['chk'] = countPostSelection();
191 $SW = 2; $cnt = '0'; $OUT = '';
192 foreach (postRequestParameter('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 $data = SQL_FETCHARRAY($result);
202 'menu' => $data['title'],
205 'visible' => addSelectionBox('yn', $data['visible'], 'visible', $sel),
206 'locked' => addSelectionBox('yn', $data['locked'] , 'locked' , $sel),
210 $OUT .= loadTemplate('admin_menu_status_row', true, $data);
217 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
220 SQL_FREERESULT($result);
224 $content['cnt'] = $cnt;
225 $content['rows'] = $OUT;
228 loadTemplate('admin_gmenu_status', false, $content);
230 if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
232 if (isGetRequestParameterSet('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(getRequestParameter('act'), bigintval(getRequestParameter('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(getRequestParameter('act'), bigintval(getRequestParameter('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(getRequestParameter('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(getRequestParameter('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(getRequestParameter('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(getRequestParameter('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 $content['sub'] = $SUB;
284 // Process all menu entries
285 while ($data = SQL_FETCHARRAY($result)) {
287 if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
288 // Is highest position
289 $NAVI = '<a href="{%url=modules.php?module=admin&what=guestedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']+1) . '&fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
290 } elseif ($cnt == $max) {
291 // Is lowest position
292 $NAVI = '<a href="{%url=modules.php?module=admin&what=guestedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']-1) . '&fid=' . $data['sort'] . '%}">{--HIGHER--}</a>';
293 } elseif ($data['sort'] > 0) {
294 // Anything else between highest and lowest
295 $NAVI = '<a href="{%url=modules.php?module=admin&what=guestedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']-1) . '&fid=' . $data['sort'] . '%}">{--HIGHER--}</a>/<a href=\"{%url=modules.php?module=admin&what=guestedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']+1) . '&fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
298 if (empty($data['action'])) $data['action'] = ' ';
299 if (empty($data['what'])) $data['what'] = ' ';
300 if (empty($data['title'])) $data['title'] = ' ';
306 'action' => $data['action'],
307 'what' => $data['what'],
308 'title' => $data['title'],
314 $OUT .= loadTemplate('admin_menu_overview_row', true, $row);
319 $content['rows'] = $OUT;
322 SQL_FREERESULT($result);
325 loadTemplate('admin_gmenu_edit', false, $content);
327 // Menu entries are missing... (???)
328 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));