2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 09/28/2003 *
4 * =================== Last change: 05/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-memedit.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Edit member's menu *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Editieren Sie das Menue fuer Ihre Mitglieder *
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();
59 $cnt = '0'; $OUT = '';
60 foreach (postRequestParameter('sel') as $sel => $confirm) {
63 $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
64 array(bigintval($sel)), __FILE__, __LINE__);
65 if (SQL_NUMROWS($result) == 1) {
66 // Entry found so we load the stuff...
67 $data = SQL_FETCHARRAY($result);
71 'menu' => $data['title'],
72 'act' => adminAddMenuSelectionBox('member', 'act' , 'sel_act[' . $sel . ']', $data['action']),
73 'what' => adminAddMenuSelectionBox('member', 'what', 'sel_what[' . $sel . ']', $data['what']),
77 $OUT .= loadTemplate('admin_edit_member_menu_row', true, $data);
85 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
87 SQL_FREERESULT($result);
91 // Add row content and current counter
92 $content['rows'] = $OUT;
93 $content['cnt'] = $cnt;
96 loadTemplate('admin_edit_member_menu', false, $content);
97 } elseif ((isFormSent('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
98 // Del menu entries with or without confirmation
99 $content['sub'] = $SUB;
100 $content['chk'] = countPostSelection();
101 $cnt = '0'; $OUT = '';
102 foreach (postRequestParameter('sel') as $sel => $confirm) {
105 $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
106 array(bigintval($sel)), __FILE__, __LINE__);
107 if (SQL_NUMROWS($result) == 1) {
108 // Entry found so we load the stuff...
109 list($title) = SQL_FETCHROW($result);
117 $OUT .= loadTemplate('admin_delete_member_menu_row', true, $content);
125 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
127 SQL_FREERESULT($result);
130 $content['rows'] = $OUT;
131 $content['cnt'] = $cnt;
134 loadTemplate('admin_delete_member_menu', false, $content);
135 } elseif ((isPostRequestParameterSet('status')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
136 // Change status (visible / locked)
137 $content['sub'] = $SUB;
138 $content['chk'] = countPostSelection();
139 $cnt = '0'; $OUT = '';
140 foreach (postRequestParameter('sel') as $sel => $confirm) {
143 $result = SQL_QUERY_ESC("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
144 array(bigintval($sel)), __FILE__, __LINE__);
145 if (SQL_NUMROWS($result) == 1) {
146 // Entry found so we load the stuff...
147 $data = SQL_FETCHARRAY($result);
150 'menu' => $data['title'],
152 'visible' => addSelectionBox('yn', $data['visible'], 'visible', $sel),
153 'locked' => addSelectionBox('yn', $data['locked'] , 'locked' , $sel),
157 $OUT .= loadTemplate('admin_menu_status_row', true, $data);
165 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
167 SQL_FREERESULT($result);
170 $content['rows'] = $OUT;
171 $content['cnt'] = $cnt;
174 loadTemplate('admin_member_menu_status', false, $content);
175 } elseif ((isFormSent()) && (!isDemoModeActive())) {
177 foreach (postRequestParameter('sel') as $sel => $menu) {
178 $AND = "(`what` = '' OR `what` IS NULL)";
180 $sel = bigintval($sel);
182 if (!empty($SUB)) $AND = "`action`='" . $SUB . "'";
184 switch (postRequestParameter('ok')) {
185 case 'edit': // Edit menu
186 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
187 array($menu, postRequestParameter('sel_act', $sel), postRequestParameter('sel_what', $sel), $sel), __FILE__, __LINE__);
190 case 'delete': // Delete menu
191 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
192 array($sel), __FILE__, __LINE__);
195 case 'status': // Change status of menus
196 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
197 array(postRequestParameter('visible', $sel), postRequestParameter('locked', $sel), $sel), __FILE__, __LINE__);
200 default: // Unexpected action
201 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
202 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
208 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
210 if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
212 $tid = ''; $fid = '';
215 if (isGetRequestParameterSet('w')) {
216 // Sub menus selected
217 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`=%s LIMIT 1",
218 array(bigintval(getRequestParameter('act')), bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
219 list($tid) = SQL_FETCHROW($result);
220 SQL_FREERESULT($result);
221 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`=%s LIMIT 1",
222 array(bigintval(getRequestParameter('act')), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
223 list($fid) = SQL_FETCHROW($result);
224 SQL_FREERESULT($result);
226 // Main menu selected
227 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`=%s LIMIT 1",
228 array(bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
229 list($tid) = SQL_FETCHROW($result);
230 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`=%s LIMIT 1",
231 array(bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
232 list($fid) = SQL_FETCHROW($result);
235 if ((!empty($tid)) && (!empty($fid))) {
237 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
238 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
239 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
240 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
246 $result = SQL_QUERY("SELECT `id`, `action`, `what`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort` ASC", __FILE__, __LINE__);
249 $result = SQL_QUERY("SELECT `id`, `action`, `what`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
253 if (SQL_NUMROWS($result) > 0) {
255 $content['sub'] = $SUB;
257 $cnt = '0'; $OUT = '';
258 while ($data = SQL_FETCHARRAY($result)) {
262 if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
263 // Is highest position
264 $data['navi'] = '<a href="{%url=modules.php?module=admin&what=adminedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']+1) . '&fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
265 } elseif ($cnt == SQL_NUMROWS($result)) {
266 // Is lowest position
267 $data['navi'] = '<a href="{%url=modules.php?module=admin&what=adminedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']-1) . '&fid=' . $data['sort'] . '%}">{--HIGHER--}</a>';
268 } elseif ($data['sort'] > 0) {
269 // Anything else between highest and lowest
270 $data['navi'] = '<a href="{%url=modules.php?module=admin&what=adminedit&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=memedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']+1) . '&fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
273 // Fix empty values for Firefox
274 if (empty($data['action'])) $data['action'] = ' ';
275 if (empty($data['what'])) $data['what'] = ' ';
276 if (empty($data['title'])) $data['title'] = ' ';
279 $data['mode'] = 'mem';
281 // Load row template and switch color
282 $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
286 SQL_FREERESULT($result);
288 // Remember rows in array
289 $content['rows'] = $OUT;
291 // Load main template
292 loadTemplate('admin_member_menu_overview', false, $content);
294 // Menu entries are missing... (???)
295 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MENUS_FOUND--}');