2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 09/05/2003 *
4 * =================== Last change: 12/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-adminedit.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Edit the admin menu *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Das Admin-Menue 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 = '';
50 if (isGetRequestParameterSet('sub')) {
51 $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", getRequestParameter('sub'));
52 $SUB = getRequestParameter('sub');
55 // List all menu points and make them editable
56 if ((isPostRequestParameterSet('edit')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
58 // @TODO Kill all constants in this file
59 $content['sub'] = $SUB;
60 $content['chk'] = countPostSelection();
62 foreach (postRequestParameter('sel') as $sel => $confirm) {
65 $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what`, `descr` FROM `{?_MYSQL_PREFIX?}_admin_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);
71 // Prepare data for the row template
73 'action' => adminAddMenuSelectionBox('admin', 'action', 'sel_action[' . $sel . ']', $data['action']),
74 'what' => adminAddMenuSelectionBox('admin', 'what' , 'sel_what[' . $sel . ']', $data['what']),
77 'menu' => $data['title'],
78 'descr' => $data['descr'],
83 $OUT .= loadTemplate('admin_amenu_edit_row', true, $data);
92 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
95 // Free result and switch color
96 SQL_FREERESULT($result);
101 $content['rows'] = $OUT;
102 $content['cnt'] = $cnt;
105 loadTemplate('admin_amenu_edit_form', false, $content);
106 } elseif ((isPostRequestParameterSet('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
107 // Prepare misc content
108 $content['sub'] = $SUB;
109 $content['chk'] = countPostSelection();
111 // Del menu entries with or without confirmation
112 $SW = 2; $cnt = '0'; $OUT = '';
113 foreach (postRequestParameter('sel') as $sel => $confirm) {
116 $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_admin_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);
122 // Prepare data for the row template
124 'menu' => $data['title'],
129 $OUT .= loadTemplate('admin_amenu_delete_row', true, $data);
136 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
138 SQL_FREERESULT($result);
142 $content['rows'] = $OUT;
143 $content['cnt'] = $cnt;
146 loadTemplate('admin_amenu_delete', false, $content);
147 } elseif ((isFormSent()) && (!isDemoModeActive())) {
148 // An action is done...
149 switch (postRequestParameter('ok')) {
150 case 'edit': // Edit menu
151 foreach (postRequestParameter('sel') as $sel => $menu) {
153 $sel = bigintval($sel);
156 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET
161 WHERE ".$AND." AND `id`=%s LIMIT 1",
164 postRequestParameter('sel_action', $sel),
165 postRequestParameter('sel_what', $sel),
166 postRequestParameter('sel_desc', $sel),
168 ), __FILE__, __LINE__);
172 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
175 case 'del': // Delete menu
176 foreach (postRequestParameter('sel') as $sel => $menu) {
177 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
178 array(bigintval($sel)), __FILE__, __LINE__);
182 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
185 default: // Unexpected action
186 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
187 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
191 if ((isGetRequestParameterSet(('act'))) && (isGetRequestParameterSet(('tid'))) && (isGetRequestParameterSet(('fid')))) {
193 if (isGetRequestParameterSet(('w'))) {
194 // Sub menus selected
195 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
196 array(getRequestParameter('act'), bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
197 list($tid) = SQL_FETCHROW($result);
198 SQL_FREERESULT($result);
199 $result = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
200 array(getRequestParameter('act'), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
201 list($fid) = SQL_FETCHROW($result);
202 SQL_FREERESULT($result);
204 // Main menu selected
205 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
206 array(bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
207 list($tid) = SQL_FETCHROW($result);
208 SQL_FREERESULT($result);
209 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
210 array(bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
211 list($fid) = SQL_FETCHROW($result);
212 SQL_FREERESULT($result);
215 if ((!empty($tid)) && (!empty($fid))) {
217 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
218 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
219 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
220 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
224 // By default list menus
226 // Sub menus of a main menu
227 $result = SQL_QUERY_ESC("SELECT id, action, what, title, sort FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort` ASC",
228 array($SUB), __FILE__, __LINE__);
231 $result = SQL_QUERY("SELECT id, action, what, title, sort FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
234 $max = SQL_NUMROWS($result);
236 // Remember sub value
237 $content['sub'] = $SUB;
240 $OUT = ''; $SW = 2; $cnt = '0';
242 // Process all entries
243 while ($data = SQL_FETCHARRAY($result)) {
247 // Init navigation variable
249 if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
250 // Is highest position
251 $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>';
252 } elseif ($cnt == $max) {
253 // Is lowest position
254 $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>';
255 } elseif ($data['sort'] > 0) {
256 // Anything else between highest and lowest
257 $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=adminedit&sub=' . $content['sub'] . '&act=' . $data['action'] . '&w=' . $data['what'] . '&tid=' . ($data['sort']+1) . '&fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
260 // Fix empty elements for constant (fixes display bugs in Firefox)
261 if (empty($data['action'])) $data['action'] = ' ';
262 if (empty($data['what'])) $data['what'] = ' ';
263 if (empty($data['title'])) $data['title'] = ' ';
265 // Add more data to $data
267 $data['mode'] = 'admin';
269 // Load row template and switch colors
270 $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
275 $content['rows'] = $OUT;
278 SQL_FREERESULT($result);
281 loadTemplate('admin_amenu_edit', false, $content);
283 // Menu entries are missing... (???)
284 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));