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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009, 2010 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addMenuDescription('admin', __FILE__);
46 // Do we edit/delete/change main menus or sub menus?
47 $AND = "(`what` = '' OR `what` IS NULL)"; $SUB = '';
49 if (isGetRequestParameterSet('sub')) {
50 $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", getRequestParameter('sub'));
51 $SUB = getRequestParameter('sub');
54 // List all menu points and make them editable
55 if ((isFormSent('edit')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
57 $content['sub'] = $SUB;
58 $content['chk'] = countPostSelection();
60 $cnt = '0'; $OUT = '';
61 foreach (postRequestParameter('sel') as $sel => $confirm) {
64 $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
65 array(bigintval($sel)), __FILE__, __LINE__);
66 if (SQL_NUMROWS($result) == 1) {
67 // Entry found so we load the stuff...
68 $DATA = SQL_FETCHARRAY($result);
74 'action' => adminAddMenuSelectionBox('guest', 'action', 'sel_action[' . $sel . ']', $DATA['action']),
75 'what' => adminAddMenuSelectionBox('guest', 'what' , 'sel_what[' . $sel . ']', $DATA['what']),
76 'menu' => $DATA['title'],
80 $OUT .= loadTemplate('admin_edit_guest_menu_row', true, $DATA);
86 $OUT .= loadTemplate('admin_menu_404_row', true, $DATA);
89 // Free result and switch color
90 SQL_FREERESULT($result);
94 $content['rows'] = $OUT;
95 $content['cnt'] = $cnt;
98 loadTemplate('admin_edit_guest_menu_form', false, $content);
99 } elseif ((isFormSent('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
100 // Del menu entries with or without confirmation
101 $content['sub'] = $SUB;
102 $content['chk'] = countPostSelection();
107 foreach (postRequestParameter('sel') as $sel => $confirm) {
110 $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
111 array(bigintval($sel)), __FILE__, __LINE__);
112 if (SQL_NUMROWS($result) == 1) {
113 // Entry found so we load the stuff...
114 $DATA = SQL_FETCHARRAY($result);
117 'menu' => $DATA['title'],
120 $OUT .= loadTemplate('admin_delete_guest_menu_row', true, $DATA);
126 $OUT .= loadTemplate('admin_menu_404_row', true, $DATA);
128 SQL_FREERESULT($result);
131 $content['rows'] = $OUT;
132 $content['cnt'] = $cnt;
135 loadTemplate('admin_delete_guest_menu', false, $content);
136 } elseif ((isFormSent()) && (!isDemoModeActive())) {
137 // An action is done...
138 switch (postRequestParameter('ok')) {
139 case 'edit': // Edit menu
140 foreach (postRequestParameter('sel') as $sel => $menu) {
142 $sel = bigintval($sel);
145 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
146 array($menu, postRequestParameter('sel_action', $sel), postRequestParameter('sel_what', $sel), $sel),__FILE__, __LINE__);
148 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
151 case 'delete': // Delete menu
152 foreach (postRequestParameter('sel') as $sel => $menu) {
154 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
155 array(bigintval($sel)), __FILE__, __LINE__);
157 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
160 case 'status': // Change access levels
161 foreach (postRequestParameter('sel') as $sel => $menu) {
163 $sel = bigintval($sel);
166 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
167 array(postRequestParameter('visible', $sel), postRequestParameter('locked', $sel), $sel), __FILE__, __LINE__);
169 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
172 default: // Unexpected action
173 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
174 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
177 } elseif ((isPostRequestParameterSet('status')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
178 // Change status (visible / locked)
179 $content['sub'] = $SUB;
180 $content['chk'] = countPostSelection();
183 $cnt = '0'; $OUT = '';
184 foreach (postRequestParameter('sel') as $sel => $confirm) {
187 $result = SQL_QUERY_ESC("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
188 array(bigintval($sel)), __FILE__, __LINE__);
189 if (SQL_NUMROWS($result) == 1) {
190 // Entry found so we load the stuff...
191 $data = SQL_FETCHARRAY($result);
194 'menu' => $data['title'],
196 'visible' => addSelectionBox('yn', $data['visible'], 'visible', $sel),
197 'locked' => addSelectionBox('yn', $data['locked'] , 'locked' , $sel),
201 $OUT .= loadTemplate('admin_menu_status_row', true, $data);
207 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
210 SQL_FREERESULT($result);
213 $content['cnt'] = $cnt;
214 $content['rows'] = $OUT;
217 loadTemplate('admin_guest_menu_status', false, $content);
219 if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
221 if (isGetRequestParameterSet('w')) {
222 // Sub menus selected
223 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='%s' AND `sort`=%s LIMIT 1",
224 array(getRequestParameter('act'), bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
225 list($tid) = SQL_FETCHROW($result);
226 SQL_FREERESULT($result);
227 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='%s' AND `sort`=%s LIMIT 1",
228 array(getRequestParameter('act'), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
229 list($fid) = SQL_FETCHROW($result);
230 SQL_FREERESULT($result);
232 // Main menu selected
233 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`=%s LIMIT 1",
234 array(bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
235 list($tid) = SQL_FETCHROW($result);
236 SQL_FREERESULT($result);
237 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`=%s LIMIT 1",
238 array(bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
239 list($fid) = SQL_FETCHROW($result);
240 SQL_FREERESULT($result);
243 if ((!empty($tid)) && (!empty($fid))) {
245 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
246 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
247 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
248 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
252 // By default list menus
254 // List only main menus
255 $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__);
258 $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",
259 array($SUB), __FILE__, __LINE__);
262 // Do we have entries?
263 if (SQL_NUMROWS($result) > 0) {
265 $content['sub'] = $SUB;
271 // Process all menu entries
272 while ($data = SQL_FETCHARRAY($result)) {
274 if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
275 // Is highest position
276 $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>';
277 } elseif ($cnt == SQL_NUMROWS($result)) {
278 // Is lowest position
279 $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>';
280 } elseif ($data['sort'] > 0) {
281 // Anything else between highest and lowest
282 $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>';
285 if (empty($data['action'])) $data['action'] = ' ';
286 if (empty($data['what'])) $data['what'] = ' ';
287 if (empty($data['title'])) $data['title'] = ' ';
292 'action' => $data['action'],
293 'what' => $data['what'],
294 'title' => $data['title'],
300 $OUT .= loadTemplate('admin_menu_overview_row', true, $row);
304 $content['rows'] = $OUT;
307 SQL_FREERESULT($result);
310 loadTemplate('admin_edit_guest_menu', false, $content);
312 // Menu entries are missing... (???)
313 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MENUS_FOUND--}');