Configuration of advertisement networks prepared, CSS cleaned up, HTML rewritten:
[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` != '' 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')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
57         // Edit menu entries
58         // @TODO Kill all constants in this file
59         $content['sub'] = $SUB;
60         $content['chk'] = countPostSelection();
61         $cnt = '0';
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                                         'sel'    => $sel,
76                                         'menu'   => $data['title'],
77                                         'descr'  => $data['descr'],
78                                         'cnt'    => $cnt,
79                                 );
80
81                                 // Load row template
82                                 $OUT .= loadTemplate('admin_edit_admin_menu_row', true, $data);
83                         } else {
84                                 // Entry not found?
85                                 $data = array(
86                                         'sel' => $sel
87                                 );
88
89                                 // Load row template
90                                 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
91                         }
92
93                         // Free result and switch color
94                         SQL_FREERESULT($result);
95                 } // END - if
96         } // END - foreach
97
98         $content['rows'] = $OUT;
99         $content['cnt'] = $cnt;
100
101         // Load template
102         loadTemplate('admin_edit_admin_menu_form', false, $content);
103 } elseif ((isFormSent('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
104         // Prepare misc content
105         $content['sub'] = $SUB;
106         $content['chk'] = countPostSelection();
107
108         // Del menu entries with or without confirmation
109         $cnt = '0'; $OUT = '';
110         foreach (postRequestParameter('sel') as $sel => $confirm) {
111                 if ($confirm == 1) {
112                         $cnt++;
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);
118
119                                 // Prepare data for the row template
120                                 $data = array(
121                                         'menu' => $data['title'],
122                                         'cnt'  => $cnt,
123                                         'sel'  => $sel,
124                                 );
125                                 $OUT .= loadTemplate('admin_delete_admin_menu_row', true, $data);
126                         } else {
127                                 // Entry not found?
128                                 $data = array(
129                                         'sel' => $sel
130                                 );
131                                 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
132                         }
133                         SQL_FREERESULT($result);
134                 } // END - if
135         } // END - switch
136         $content['rows'] = $OUT;
137         $content['cnt'] = $cnt;
138
139         // Load template
140         loadTemplate('admin_delete_admin_menu', 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) {
146                                 // Secure id
147                                 $sel = bigintval($sel);
148
149                                 // Update entry
150                                 SQL_QUERY_ESC("UPDATE
151         `{?_MYSQL_PREFIX?}_admin_menu`
152 SET
153         `title`='%s',
154         `action`='%s',
155         `what`='%s',
156         `descr`='%s'
157 WHERE
158         ".$AND." AND
159         `id`=%s
160 LIMIT 1",
161                                 array(
162                                         $menu,
163                                         postRequestParameter('sel_action', $sel),
164                                         postRequestParameter('sel_what', $sel),
165                                         postRequestParameter('sel_desc', $sel),
166                                         $sel,
167                                 ), __FILE__, __LINE__);
168                         }
169
170                         // Load template
171                         loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
172                         break;
173
174                 case 'delete': // Delete menu
175                         foreach (postRequestParameter('sel') as $sel => $menu) {
176                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
177                                         array(bigintval($sel)), __FILE__, __LINE__);
178                         } // END - foreach
179
180                         // Load template
181                         loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
182                         break;
183
184                 default: // Unexpected action
185                         logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
186                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
187                         break;
188         }
189 } else {
190         if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
191                 // Get ids
192                 if (isGetRequestParameterSet('w')) {
193                         // Sub menus selected
194                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `what` != '%s' AND `sort`=%s LIMIT 1",
195                                 array(
196                                         getRequestParameter('w'),
197                                         bigintval(getRequestParameter('tid'))
198                                 ), __FILE__, __LINE__);
199                         list($tid) = SQL_FETCHROW($result);
200                         SQL_FREERESULT($result);
201                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `what`='%s' AND `sort`=%s LIMIT 1",
202                                 array(
203                                         getRequestParameter('w'),
204                                         bigintval(getRequestParameter('fid'))
205                                 ), __FILE__, __LINE__);
206                         list($fid) = SQL_FETCHROW($result);
207                         SQL_FREERESULT($result);
208                 } else {
209                         // Main menu selected
210                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action` != %s AND ".$AND." AND `sort`=%s LIMIT 1",
211                                 array(
212                                         getRequestParameter('act'),
213                                         bigintval(getRequestParameter('tid'))
214                                 ), __FILE__, __LINE__);
215                         list($tid) = SQL_FETCHROW($result);
216                         SQL_FREERESULT($result);
217                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`=%s AND ".$AND." AND `sort`=%s LIMIT 1",
218                                 array(
219                                         getRequestParameter('act'),
220                                         bigintval(getRequestParameter('fid'))
221                                 ), __FILE__, __LINE__);
222                         list($fid) = SQL_FETCHROW($result);
223                         SQL_FREERESULT($result);
224                 }
225
226                 // Do we have entries found?
227                 if ((!empty($tid)) && (!empty($fid))) {
228                         // Sort menu
229                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
230                                 array(
231                                         bigintval(getRequestParameter('tid')),
232                                         bigintval($fid)
233                                 ), __FILE__, __LINE__);
234                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
235                                 array(
236                                         bigintval(getRequestParameter('fid')),
237                                         bigintval($tid)
238                                 ), __FILE__, __LINE__);
239                 } // END - if
240         } // END - if
241
242         // Run SQL
243         $result = SQL_QUERY("SELECT id, action, what, title, sort FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." ORDER BY `sort` ASC", __FILE__, __LINE__);
244
245         // Do we have entries?
246         if (SQL_NUMROWS($result) > 0) {
247                 // Remember sub value
248                 $content['sub'] = $SUB;
249
250                 // Init variables
251                 $OUT = ''; $cnt = '0';
252
253                 // Process all entries
254                 while ($data = SQL_FETCHARRAY($result)) {
255                         // Count this entry
256                         $cnt++;
257
258                         // Init navigation variable
259                         $data['navi'] = '';
260                         if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
261                                 // Is highest position
262                                 $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>';
263                         } elseif ($cnt == SQL_NUMROWS($result)) {
264                                 // Is lowest position
265                                 $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>';
266                         } elseif ($data['sort'] > 0) {
267                                 // Anything else between highest and lowest
268                                 $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>';
269                         }
270
271                         // Add more data to $data
272                         $data['mode'] = 'admin';
273
274                         // Load row template and switch colors
275                         $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
276                 } // END - switch
277
278                 // Remember all rows
279                 $content['rows'] = $OUT;
280
281                 // Free memory
282                 SQL_FREERESULT($result);
283
284                 // Load template
285                 loadTemplate('admin_edit_admin_menu', false, $content);
286         } else {
287                 // Menu entries are missing... (???)
288                 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MENUS_FOUND--}');
289         }
290 }
291
292 //
293 ?>