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')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
59 $content['sub'] = $SUB;
60 $content['chk'] = countPostSelection();
62 $cnt = '0'; $OUT = '';
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'],
82 $OUT .= loadTemplate('admin_gmenu_edit_row', true, $DATA);
88 $OUT .= loadTemplate('admin_menu_404_row', true, $DATA);
91 // Free result and switch color
92 SQL_FREERESULT($result);
96 $content['rows'] = $OUT;
97 $content['cnt'] = $cnt;
100 loadTemplate('admin_gmenu_edit_form', false, $content);
101 } elseif ((isFormSent('del')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
102 // Del menu entries with or without confirmation
103 $content['sub'] = $SUB;
104 $content['chk'] = countPostSelection();
109 foreach (postRequestParameter('sel') as $sel => $confirm) {
112 $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
113 array(bigintval($sel)), __FILE__, __LINE__);
114 if (SQL_NUMROWS($result) == 1) {
115 // Entry found so we load the stuff...
116 $DATA = SQL_FETCHARRAY($result);
119 'menu' => $DATA['title'],
122 $OUT .= loadTemplate('admin_gmenu_delete_row', true, $DATA);
128 $OUT .= loadTemplate('admin_menu_404_row', true, $DATA);
130 SQL_FREERESULT($result);
133 $content['rows'] = $OUT;
134 $content['cnt'] = $cnt;
137 loadTemplate('admin_gmenu_delete', false, $content);
138 } elseif ((isFormSent()) && (!isDemoModeActive())) {
139 // An action is done...
140 switch (postRequestParameter('ok')) {
141 case 'edit': // Edit menu
142 foreach (postRequestParameter('sel') as $sel => $menu) {
144 $sel = bigintval($sel);
147 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
148 array($menu, postRequestParameter('sel_action', $sel), postRequestParameter('sel_what', $sel), $sel),__FILE__, __LINE__);
150 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
153 case 'del': // Delete menu
154 foreach (postRequestParameter('sel') as $sel => $menu) {
156 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
157 array(bigintval($sel)), __FILE__, __LINE__);
159 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
162 case 'status': // Change access levels
163 foreach (postRequestParameter('sel') as $sel => $menu) {
165 $sel = bigintval($sel);
168 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
169 array(postRequestParameter('visible', $sel), postRequestParameter('locked', $sel), $sel), __FILE__, __LINE__);
171 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
174 default: // Unexpected action
175 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
176 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
179 } elseif ((isPostRequestParameterSet('status')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
180 // Change status (visible / locked)
181 $content['sub'] = $SUB;
182 $content['chk'] = countPostSelection();
185 $cnt = '0'; $OUT = '';
186 foreach (postRequestParameter('sel') as $sel => $confirm) {
189 $result = SQL_QUERY_ESC("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
190 array(bigintval($sel)), __FILE__, __LINE__);
191 if (SQL_NUMROWS($result) == 1) {
192 // Entry found so we load the stuff...
193 $data = SQL_FETCHARRAY($result);
196 'menu' => $data['title'],
198 'visible' => addSelectionBox('yn', $data['visible'], 'visible', $sel),
199 'locked' => addSelectionBox('yn', $data['locked'] , 'locked' , $sel),
203 $OUT .= loadTemplate('admin_menu_status_row', true, $data);
209 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
212 SQL_FREERESULT($result);
215 $content['cnt'] = $cnt;
216 $content['rows'] = $OUT;
219 loadTemplate('admin_gmenu_status', false, $content);
221 if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
223 if (isGetRequestParameterSet('w')) {
224 // Sub menus selected
225 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
226 array(getRequestParameter('act'), bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
227 list($tid) = SQL_FETCHROW($result);
228 SQL_FREERESULT($result);
229 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
230 array(getRequestParameter('act'), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
231 list($fid) = SQL_FETCHROW($result);
232 SQL_FREERESULT($result);
234 // Main menu selected
235 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
236 array(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 (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
240 array(bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
241 list($fid) = SQL_FETCHROW($result);
242 SQL_FREERESULT($result);
245 if ((!empty($tid)) && (!empty($fid))) {
247 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
248 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
249 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
250 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
254 // By default list menus
256 // List only main menus
257 $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__);
260 $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",
261 array($SUB), __FILE__, __LINE__);
264 // Get number of menu entries
265 $max = SQL_NUMROWS($result);
268 $content['sub'] = $SUB;
274 // Process all menu entries
275 while ($data = SQL_FETCHARRAY($result)) {
277 if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
278 // Is highest 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'] . '%}">{--LOWER--}</a>';
280 } elseif ($cnt == $max) {
281 // Is lowest position
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>';
283 } elseif ($data['sort'] > 0) {
284 // Anything else between highest and lowest
285 $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>';
288 if (empty($data['action'])) $data['action'] = ' ';
289 if (empty($data['what'])) $data['what'] = ' ';
290 if (empty($data['title'])) $data['title'] = ' ';
295 'action' => $data['action'],
296 'what' => $data['what'],
297 'title' => $data['title'],
303 $OUT .= loadTemplate('admin_menu_overview_row', true, $row);
307 $content['rows'] = $OUT;
310 SQL_FREERESULT($result);
313 loadTemplate('admin_gmenu_edit', false, $content);
315 // Menu entries are missing... (???)
316 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MENUS_FOUND--}');