9cfb7b94e81698f3fd7aaf9b8332d5a6de92b3ac
[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')) && (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('del')) && (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_del_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_del_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 `{?_MYSQL_PREFIX?}_admin_menu` SET
151 `title`='%s',
152 `action`='%s',
153 `what`='%s',
154 `descr`='%s'
155 WHERE ".$AND." AND `id`=%s LIMIT 1",
156                                 array(
157                                 $menu,
158                                 postRequestParameter('sel_action', $sel),
159                                 postRequestParameter('sel_what', $sel),
160                                 postRequestParameter('sel_desc', $sel),
161                                 $sel,
162                                 ), __FILE__, __LINE__);
163                         }
164
165                         // Load template
166                         loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
167                         break;
168
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__);
173                         } // END - foreach
174
175                         // Load template
176                         loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
177                         break;
178
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')));
182                         break;
183         }
184 } else {
185         if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
186                 // Get ids
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);
197                 } else {
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);
207                 }
208
209                 if ((!empty($tid)) && (!empty($fid))) {
210                         // Sort menu
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__);
215                 } // END - if
216         } // END - if
217
218         // By default list menus
219         if (!empty($SUB)) {
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__);
223         } else {
224                 // Main menus
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__);
226         }
227
228         $max = SQL_NUMROWS($result);
229         if ($max > 0) {
230                 // Remember sub value
231                 $content['sub'] = $SUB;
232
233                 // Init variables
234                 $OUT = ''; $cnt = '0';
235
236                 // Process all entries
237                 while ($data = SQL_FETCHARRAY($result)) {
238                         // Count this entry
239                         $cnt++;
240
241                         // Init navigation variable
242                         $data['navi'] = '';
243                         if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
244                                 // Is highest position
245                                 $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>';
246                         } elseif ($cnt == $max) {
247                                 // Is lowest position
248                                 $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>';
249                         } elseif ($data['sort'] > 0) {
250                                 // Anything else between highest and lowest
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'] . '%}">{--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>';
252                         }
253
254                         // Add more data to $data
255                         $data['mode'] = 'admin';
256
257                         // Load row template and switch colors
258                         $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
259                 } // END - switch
260
261                 // Remember all rows
262                 $content['rows'] = $OUT;
263
264                 // Free memory
265                 SQL_FREERESULT($result);
266
267                 // Load template
268                 loadTemplate('admin_edit_admin_menu', false, $content);
269         } else {
270                 // Menu entries are missing... (???)
271                 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MENUS_FOUND--}');
272         }
273 }
274
275 //
276 ?>