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 ((isFormSent('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']),
76 'menu' => $data['title'],
77 'descr' => $data['descr'],
82 $OUT .= loadTemplate('admin_amenu_edit_row', true, $data);
90 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
93 // Free result and switch color
94 SQL_FREERESULT($result);
98 $content['rows'] = $OUT;
99 $content['cnt'] = $cnt;
102 loadTemplate('admin_amenu_edit_form', false, $content);
103 } elseif ((isFormSent('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
104 // Prepare misc content
105 $content['sub'] = $SUB;
106 $content['chk'] = countPostSelection();
108 // Del menu entries with or without confirmation
109 $cnt = '0'; $OUT = '';
110 foreach (postRequestParameter('sel') as $sel => $confirm) {
113 $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
114 array(bigintval($sel)), __FILE__, __LINE__);
115 if (SQL_NUMROWS($result) == 1) {
116 // Entry found so we load the stuff...
117 $data = SQL_FETCHARRAY($result);
119 // Prepare data for the row template
121 'menu' => $data['title'],
125 $OUT .= loadTemplate('admin_amenu_delete_row', true, $data);
131 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
133 SQL_FREERESULT($result);
136 $content['rows'] = $OUT;
137 $content['cnt'] = $cnt;
140 loadTemplate('admin_amenu_delete', false, $content);
141 } elseif ((isFormSent()) && (!isDemoModeActive())) {
142 // An action is done...
143 switch (postRequestParameter('ok')) {
144 case 'edit': // Edit menu
145 foreach (postRequestParameter('sel') as $sel => $menu) {
147 $sel = bigintval($sel);
150 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET
155 WHERE ".$AND." AND `id`=%s LIMIT 1",
158 postRequestParameter('sel_action', $sel),
159 postRequestParameter('sel_what', $sel),
160 postRequestParameter('sel_desc', $sel),
162 ), __FILE__, __LINE__);
166 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
169 case 'del': // Delete menu
170 foreach (postRequestParameter('sel') as $sel => $menu) {
171 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
172 array(bigintval($sel)), __FILE__, __LINE__);
176 loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
179 default: // Unexpected action
180 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
181 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
185 if ((isGetRequestParameterSet(('act'))) && (isGetRequestParameterSet(('tid'))) && (isGetRequestParameterSet(('fid')))) {
187 if (isGetRequestParameterSet(('w'))) {
188 // Sub menus selected
189 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
190 array(getRequestParameter('act'), bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
191 list($tid) = SQL_FETCHROW($result);
192 SQL_FREERESULT($result);
193 $result = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
194 array(getRequestParameter('act'), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
195 list($fid) = SQL_FETCHROW($result);
196 SQL_FREERESULT($result);
198 // Main menu selected
199 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
200 array(bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
201 list($tid) = SQL_FETCHROW($result);
202 SQL_FREERESULT($result);
203 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
204 array(bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
205 list($fid) = SQL_FETCHROW($result);
206 SQL_FREERESULT($result);
209 if ((!empty($tid)) && (!empty($fid))) {
211 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
212 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
213 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
214 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
218 // By default list menus
220 // Sub menus of a main menu
221 $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",
222 array($SUB), __FILE__, __LINE__);
225 $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__);
228 $max = SQL_NUMROWS($result);
230 // Remember sub value
231 $content['sub'] = $SUB;
234 $OUT = ''; $SW = 2; $cnt = '0';
236 // Process all entries
237 while ($data = SQL_FETCHARRAY($result)) {
241 // Init navigation variable
243 if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
244 // Is highest position
245 $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>';
246 } elseif ($cnt == $max) {
247 // Is lowest position
248 $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>';
249 } elseif ($data['sort'] > 0) {
250 // Anything else between highest and lowest
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'] . '%}">{--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>';
254 // Fix empty elements for constant (fixes display bugs in Firefox)
255 if (empty($data['action'])) $data['action'] = ' ';
256 if (empty($data['what'])) $data['what'] = ' ';
257 if (empty($data['title'])) $data['title'] = ' ';
259 // Add more data to $data
261 $data['mode'] = 'admin';
263 // Load row template and switch colors
264 $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
269 $content['rows'] = $OUT;
272 SQL_FREERESULT($result);
275 loadTemplate('admin_amenu_edit', false, $content);
277 // Menu entries are missing... (???)
278 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MENUS_FOUND--}');