New extension added, more EL-rewrites, naming-convention applied:
[mailer.git] / inc / modules / admin / what-adminedit.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 09/05/2003 *
4  * ===================                          Last change: 12/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-adminedit.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Edit the admin menu                              *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Das Admin-Menue editieren                        *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
23  *                                                                      *
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.                                  *
28  *                                                                      *
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.                         *
33  *                                                                      *
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,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 }
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
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');
53 } // END - if
54
55 // List all menu points and make them editable
56 if ((isFormSent('edit')l) && (countPostSelection() > 0) && (!isDemoModeActive())) {
57         // Edit menu entries
58         // @TODO Kill all constants in this file
59         $content['sub'] = $SUB;
60         $content['chk'] = countPostSelection();
61         $cnt = '0'; $SW = 2;
62         foreach (postRequestParameter('sel') as $sel => $confirm) {
63                 if ($confirm == 1) {
64                         $cnt++;
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);
70
71                                 // Prepare data for the row template
72                                 $data = array(
73                                         'action' => adminAddMenuSelectionBox('admin', 'action', 'sel_action[' . $sel . ']', $data['action']),
74                                         'what'   => adminAddMenuSelectionBox('admin', 'what'  , 'sel_what['   . $sel . ']', $data['what']),
75                                         'sw'     => $SW,
76                                         'sel'    => $sel,
77                                         'menu'   => $data['title'],
78                                         'descr'  => $data['descr'],
79                                         'cnt'    => $cnt,
80                                 );
81
82                                 // Load row template
83                                 $OUT .= loadTemplate('admin_amenu_edit_row', true, $data);
84                         } else {
85                                 // Entry not found?
86                                 $data = array(
87                                         'sw'  => $SW,
88                                         'sel' => $sel
89                                 );
90
91                                 // Load row template
92                                 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
93                         }
94
95                         // Free result and switch color
96                         SQL_FREERESULT($result);
97                         $SW = 3 - $SW;
98                 } // END - if
99         } // END - foreach
100
101         $content['rows'] = $OUT;
102         $content['cnt'] = $cnt;
103
104         // Load template
105         loadTemplate('admin_amenu_edit_form', false, $content);
106 } elseif ((isFormSent('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
107         // Prepare misc content
108         $content['sub'] = $SUB;
109         $content['chk'] = countPostSelection();
110
111         // Del menu entries with or without confirmation
112         $SW = 2; $cnt = '0'; $OUT = '';
113         foreach (postRequestParameter('sel') as $sel => $confirm) {
114                 if ($confirm == 1) {
115                         $cnt++;
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);
121
122                                 // Prepare data for the row template
123                                 $data = array(
124                                         'menu' => $data['title'],
125                                         'cnt'  => $cnt,
126                                         'sel'  => $sel,
127                                         'sw'   => $SW
128                                 );
129                                 $OUT .= loadTemplate('admin_amenu_delete_row', true, $data);
130                         } else {
131                                 // Entry not found?
132                                 $data = array(
133                                         'sw'  => $SW,
134                                         'sel' => $sel
135                                 );
136                                 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
137                         }
138                         SQL_FREERESULT($result);
139                         $SW = 3 - $SW;
140                 }
141         }
142         $content['rows'] = $OUT;
143         $content['cnt'] = $cnt;
144
145         // Load template
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) {
152                                 // Secure id
153                                 $sel = bigintval($sel);
154
155                                 // Update entry
156                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET
157 `title`='%s',
158 `action`='%s',
159 `what`='%s',
160 `descr`='%s'
161 WHERE ".$AND." AND `id`=%s LIMIT 1",
162                                 array(
163                                 $menu,
164                                 postRequestParameter('sel_action', $sel),
165                                 postRequestParameter('sel_what', $sel),
166                                 postRequestParameter('sel_desc', $sel),
167                                 $sel,
168                                 ), __FILE__, __LINE__);
169                         }
170
171                         // Load template
172                         loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
173                         break;
174
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__);
179                         } // END - foreach
180
181                         // Load template
182                         loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
183                         break;
184
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')));
188                         break;
189         }
190 } else {
191         if ((isGetRequestParameterSet(('act'))) && (isGetRequestParameterSet(('tid'))) && (isGetRequestParameterSet(('fid')))) {
192                 // Get ids
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);
203                 } else {
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);
213                 }
214
215                 if ((!empty($tid)) && (!empty($fid))) {
216                         // Sort menu
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__);
221                 }
222         }
223
224         // By default list menus
225         if (!empty($SUB)) {
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__);
229         } else {
230                 // Main menus
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__);
232         }
233
234         $max = SQL_NUMROWS($result);
235         if ($max > 0) {
236                 // Remember sub value
237                 $content['sub'] = $SUB;
238
239                 // Init variables
240                 $OUT = ''; $SW  = 2; $cnt = '0';
241
242                 // Process all entries
243                 while ($data = SQL_FETCHARRAY($result)) {
244                         // Count this entry
245                         $cnt++;
246
247                         // Init navigation variable
248                         $data['navi'] = '';
249                         if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
250                                 // Is highest position
251                                 $data['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']+1) . '&amp;fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
252                         } elseif ($cnt == $max) {
253                                 // Is lowest position
254                                 $data['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']-1) . '&amp;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&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']-1) . '&amp;fid=' . $data['sort'] . '%}">{--HIGHER--}</a>/<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']+1) . '&amp;fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
258                         }
259
260                         // Fix empty elements for constant (fixes display bugs in Firefox)
261                         if (empty($data['action'])) $data['action'] = '&nbsp;';
262                         if (empty($data['what']))   $data['what']   = '&nbsp;';
263                         if (empty($data['title']))  $data['title']  = '&nbsp;';
264
265                         // Add more data to $data
266                         $data['sw']   = $SW;
267                         $data['mode'] = 'admin';
268
269                         // Load row template and switch colors
270                         $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
271                         $SW = 3 - $SW;
272                 } // END - switch
273
274                 // Remember all rows
275                 $content['rows'] = $OUT;
276
277                 // Free memory
278                 SQL_FREERESULT($result);
279
280                 // Load template
281                 loadTemplate('admin_amenu_edit', false, $content);
282         } else {
283                 // Menu entries are missing... (???)
284                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));
285         }
286 }
287
288 //
289 ?>