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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
48 // Do we edit/delete/change main menus or sub menus?
49 $AND = "(`what` = '' OR `what` IS NULL)"; $SUB = '';
51 if (isGetRequestParameterSet('sub')) {
52 $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", getRequestParameter('sub'));
53 $SUB = getRequestParameter('sub');
56 // List all menu points and make them editable
57 if ((isFormSent('edit')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
59 $content['sub'] = $SUB;
60 $content['chk'] = countPostSelection();
62 $cnt = '0'; $OUT = ''; $SW = 2;
63 foreach (postRequestParameter('sel') as $sel => $confirm) {
66 $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
67 array(bigintval($sel)), __FILE__, __LINE__);
68 if (SQL_NUMROWS($result) == 1) {
69 // Entry found so we load the stuff...
70 $DATA = SQL_FETCHARRAY($result);
76 'action' => adminAddMenuSelectionBox('guest', 'action', 'sel_action[' . $sel . ']', $DATA['action']),
77 'what' => adminAddMenuSelectionBox('guest', 'what' , 'sel_what[' . $sel . ']', $DATA['what']),
78 'menu' => $DATA['title'],
83 $OUT .= loadTemplate('admin_gmenu_edit_row', true, $DATA);
90 $OUT .= loadTemplate('admin_menu_404_row', true, $DATA);
93 // Free result and switch color
94 SQL_FREERESULT($result);
99 $content['rows'] = $OUT;
100 $content['cnt'] = $cnt;
103 loadTemplate('admin_gmenu_edit_form', false, $content);
104 } elseif ((isFormSent('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
105 // Del menu entries with or without confirmation
106 $content['sub'] = $SUB;
107 $content['chk'] = countPostSelection();
113 foreach (postRequestParameter('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 $DATA = SQL_FETCHARRAY($result);
123 'menu' => $DATA['title'],
127 $OUT .= loadTemplate('admin_gmenu_delete_row', true, $DATA);
134 $OUT .= loadTemplate('admin_menu_404_row', true, $DATA);
136 SQL_FREERESULT($result);
140 $content['rows'] = $OUT;
141 $content['cnt'] = $cnt;
144 loadTemplate('admin_gmenu_delete', false, $content);
145 } elseif ((isFormSent()) && (!isDemoModeActive())) {
146 // An action is done...
147 switch (postRequestParameter('ok')) {
148 case 'edit': // Edit menu
149 foreach (postRequestParameter('sel') as $sel => $menu) {
151 $sel = bigintval($sel);
154 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
155 array($menu, postRequestParameter('sel_action', $sel), postRequestParameter('sel_what', $sel), $sel),__FILE__, __LINE__);
157 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
160 case 'del': // Delete menu
161 foreach (postRequestParameter('sel') as $sel => $menu) {
163 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
164 array(bigintval($sel)), __FILE__, __LINE__);
166 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
169 case 'status': // Change access levels
170 foreach (postRequestParameter('sel') as $sel => $menu) {
172 $sel = bigintval($sel);
175 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
176 array(postRequestParameter('visible', $sel), postRequestParameter('locked', $sel), $sel), __FILE__, __LINE__);
178 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
181 default: // Unexpected action
182 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
183 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
186 } elseif ((isPostRequestParameterSet('status')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
187 // Change status (visible / locked)
188 $content['sub'] = $SUB;
189 $content['chk'] = countPostSelection();
192 $SW = 2; $cnt = '0'; $OUT = '';
193 foreach (postRequestParameter('sel') as $sel => $confirm) {
196 $result = SQL_QUERY_ESC("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
197 array(bigintval($sel)), __FILE__, __LINE__);
198 if (SQL_NUMROWS($result) == 1) {
199 // Entry found so we load the stuff...
200 $data = SQL_FETCHARRAY($result);
203 'menu' => $data['title'],
206 'visible' => addSelectionBox('yn', $data['visible'], 'visible', $sel),
207 'locked' => addSelectionBox('yn', $data['locked'] , 'locked' , $sel),
211 $OUT .= loadTemplate('admin_menu_status_row', true, $data);
218 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
221 SQL_FREERESULT($result);
225 $content['cnt'] = $cnt;
226 $content['rows'] = $OUT;
229 loadTemplate('admin_gmenu_status', false, $content);
231 if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
233 if (isGetRequestParameterSet('w')) {
234 // Sub menus selected
235 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
236 array(getRequestParameter('act'), bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
237 list($tid) = SQL_FETCHROW($result);
238 SQL_FREERESULT($result);
239 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
240 array(getRequestParameter('act'), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
241 list($fid) = SQL_FETCHROW($result);
242 SQL_FREERESULT($result);
244 // Main menu selected
245 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
246 array(bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
247 list($tid) = SQL_FETCHROW($result);
248 SQL_FREERESULT($result);
249 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
250 array(bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
251 list($fid) = SQL_FETCHROW($result);
252 SQL_FREERESULT($result);
255 if ((!empty($tid)) && (!empty($fid))) {
257 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
258 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
259 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
260 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
264 // By default list menus
266 // List only main menus
267 $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__);
270 $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",
271 array($SUB), __FILE__, __LINE__);
274 // Get number of menu entries
275 $max = SQL_NUMROWS($result);
278 $content['sub'] = $SUB;
285 // Process all menu entries
286 while ($data = SQL_FETCHARRAY($result)) {
288 if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
289 // Is highest position
290 $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>';
291 } elseif ($cnt == $max) {
292 // Is lowest position
293 $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>';
294 } elseif ($data['sort'] > 0) {
295 // Anything else between highest and lowest
296 $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>';
299 if (empty($data['action'])) $data['action'] = ' ';
300 if (empty($data['what'])) $data['what'] = ' ';
301 if (empty($data['title'])) $data['title'] = ' ';
307 'action' => $data['action'],
308 'what' => $data['what'],
309 'title' => $data['title'],
315 $OUT .= loadTemplate('admin_menu_overview_row', true, $row);
320 $content['rows'] = $OUT;
323 SQL_FREERESULT($result);
326 loadTemplate('admin_gmenu_edit', false, $content);
328 // Menu entries are missing... (???)
329 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));