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 * 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();
61 $SW = 2; $cnt = '0'; $OUT = '';
62 foreach (postRequestParameter('sel') as $sel => $confirm) {
65 $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what` FROM `{?_MYSQL_PREFIX?}_member_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);
73 'menu' => $data['title'],
75 'act' => adminAddMenuSelectionBox('member', 'act' , 'sel_act[' . $sel . ']', $data['action']),
76 'what' => adminAddMenuSelectionBox('member', 'what', 'sel_what[' . $sel . ']', $data['what']),
80 $OUT .= loadTemplate('admin_mmenu_edit_row', true, $data);
89 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
91 SQL_FREERESULT($result);
95 $content['rows'] = $OUT;
96 $content['cnt'] = $cnt;
99 loadTemplate('admin_mmenu_edit', false, $content);
100 } elseif ((isFormSent('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
101 // Del menu entries with or without confirmation
102 $content['sub'] = $SUB;
103 $content['chk'] = countPostSelection();
104 $SW = 2; $cnt = '0'; $OUT = '';
105 foreach (postRequestParameter('sel') as $sel => $confirm) {
108 $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
109 array(bigintval($sel)), __FILE__, __LINE__);
110 if (SQL_NUMROWS($result) == 1) {
111 // Entry found so we load the stuff...
112 list($title) = SQL_FETCHROW($result);
120 $OUT .= loadTemplate('admin_mmenu_delete_row', true, $content);
129 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
131 SQL_FREERESULT($result);
134 $content['rows'] = $OUT;
135 $content['cnt'] = $cnt;
138 loadTemplate('admin_mmenu_delete', false, $content);
139 } elseif ((isPostRequestParameterSet('status')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
140 // Change status (visible / locked)
141 $content['sub'] = $SUB;
142 $content['chk'] = countPostSelection();
143 $SW = 2; $cnt = '0'; $OUT = '';
144 foreach (postRequestParameter('sel') as $sel => $confirm) {
147 $result = SQL_QUERY_ESC("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
148 array(bigintval($sel)), __FILE__, __LINE__);
149 if (SQL_NUMROWS($result) == 1) {
150 // Entry found so we load the stuff...
151 $data = SQL_FETCHARRAY($result);
154 'menu' => $data['title'],
157 'visible' => addSelectionBox('yn', $data['visible'], 'visible', $sel),
158 'locked' => addSelectionBox('yn', $data['locked'] , 'locked' , $sel),
162 $OUT .= loadTemplate('admin_menu_status_row', true, $data);
171 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
173 SQL_FREERESULT($result);
177 $content['rows'] = $OUT;
178 $content['cnt'] = $cnt;
181 loadTemplate('admin_mmenu_status', false, $content);
182 } elseif ((isFormSent()) && (!isDemoModeActive())) {
184 foreach (postRequestParameter('sel') as $sel => $menu) {
185 $AND = "(`what` = '' OR `what` IS NULL)";
186 $sel = bigintval($sel);
187 if (!empty($SUB)) $AND = "`action`='".$SUB."'";
188 switch (postRequestParameter('ok')) {
189 case 'edit': // Edit menu
190 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
191 array($menu, postRequestParameter('sel_act', $sel), postRequestParameter('sel_what', $sel), $sel), __FILE__, __LINE__);
194 case 'del': // Delete menu
195 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
196 array($sel), __FILE__, __LINE__);
199 case 'status': // Change status of menus
200 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
201 array(postRequestParameter('visible', $sel), postRequestParameter('locked', $sel), $sel), __FILE__, __LINE__);
204 default: // Unexpected action
205 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
206 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
212 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
214 if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
216 $tid = ''; $fid = '';
219 if (isGetRequestParameterSet('w')) {
220 // Sub menus selected
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('tid'))), __FILE__, __LINE__);
223 list($tid) = SQL_FETCHROW($result);
224 SQL_FREERESULT($result);
225 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
226 array(bigintval(getRequestParameter('act')), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
227 list($fid) = SQL_FETCHROW($result);
228 SQL_FREERESULT($result);
230 // Main menu selected
231 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
232 array(bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
233 list($tid) = SQL_FETCHROW($result);
234 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
235 array(bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
236 list($fid) = SQL_FETCHROW($result);
239 if ((!empty($tid)) && (!empty($fid))) {
241 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
242 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
243 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
244 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
250 $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__);
253 $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__);
256 // Get total menu entries
257 $max = SQL_NUMROWS($result);
262 $content['sub'] = $SUB;
264 $SW = 2; $cnt = '0'; $OUT = '';
265 while ($data = SQL_FETCHARRAY($result)) {
269 if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
270 // Is highest position
271 $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>';
272 } elseif ($cnt == $max) {
273 // Is lowest position
274 $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>';
275 } elseif ($data['sort'] > 0) {
276 // Anything else between highest and lowest
277 $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>';
280 // Fix empty values for Firefox
281 if (empty($data['action'])) $data['action'] = ' ';
282 if (empty($data['what'])) $data['what'] = ' ';
283 if (empty($data['title'])) $data['title'] = ' ';
287 $data['mode'] = 'mem';
289 // Load row template and switch color
290 $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
295 SQL_FREERESULT($result);
297 // Remember rows in array
298 $content['rows'] = $OUT;
300 // Load main template
301 loadTemplate('admin_mmenu_overview', false, $content);
303 // Menu entries are missing... (???)
304 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));