f5743113d5bb30a99e885bb65a90cacafb7d7466
[mailer.git] / inc / modules / admin / what-adminedit.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
47
48 // Do we edit/delete/change main menus or sub menus?
49 $AND = "(`what` = '' OR `what` IS NULL)"; $SUB = '';
50 if (REQUEST_ISSET_GET('sub'))
51 {
52         $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", REQUEST_GET('sub'));
53         $SUB = REQUEST_GET('sub');
54 }
55
56 // Get count of (maybe) selected menu points
57 $chk = 0;
58 if (REQUEST_ISSET_POST('sel')) $chk = countPostSelection();
59
60 // List all menu points and make them editable
61 if ((REQUEST_ISSET_POST('edit')) && ($chk > 0) && (!IS_DEMO())) {
62         // Edit menu entries
63         define('__SUB_VALUE', $SUB);
64         define('__CHK_VALUE', $chk);
65         $cnt = 0; $SW = 2;
66         foreach (REQUEST_POST('sel') as $sel => $confirm)
67         {
68                 if ($confirm == 1)
69                 {
70                         $cnt++;
71                         $result = SQL_QUERY_ESC("SELECT title, action, what, descr FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE ".$AND." AND id=%s LIMIT 1",
72                         array(bigintval($sel)), __FILE__, __LINE__);
73                         if (SQL_NUMROWS($result) == 1)
74                         {
75                                 // Entry found so we load the stuff...
76                                 list($menu, $act, $wht, $descr) = SQL_FETCHROW($result);
77                                 SQL_FREERESULT($result);
78
79                                 // Prepare data for the row template
80                                 $content = array(
81                                         'action' => ADMIN_MAKE_MENU_SELECTION('admin', "action", "sel_action[".$sel."]", $act),
82                                         'what'   => ADMIN_MAKE_MENU_SELECTION('admin', "what", "sel_what[".$sel."]", $wht),
83                                         'sw'     => $SW,
84                                         'sel'    => $sel,
85                                         'menu'   => $menu,
86                                         'descr'  => $descr,
87                                         'cnt'    => $cnt,
88                                 );
89                                 $OUT .= LOAD_TEMPLATE("admin_amenu_edit_row", true, $content);
90                         }
91                         else
92                         {
93                                 // Entry not found?
94                                 $content = array(
95                                         'sw'  => $SW,
96                                         'sel' => $sel
97                                 );
98                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
99                         }
100                         $SW = 3 - $SW;
101                 }
102         }
103         define('__MENU_ROWS', $OUT);
104         define('__CNT_VALUE', $cnt);
105
106         // Load template
107         LOAD_TEMPLATE("admin_amenu_edit_form");
108 }
109 elseif ((REQUEST_ISSET_POST('del')) && (!IS_DEMO()))
110 {
111         define('__SUB_VALUE', $SUB);
112         define('__CHK_VALUE', $chk);
113         // Del menu entries with or without confirmation
114         $SW = 2; $cnt = 0; $OUT = '';
115         foreach (REQUEST_POST('sel') as $sel => $confirm)
116         {
117                 if ($confirm == 1)
118                 {
119                         $cnt++;
120                         $result = SQL_QUERY_ESC("SELECT title FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE ".$AND." AND id=%s LIMIT 1",
121                         array(bigintval($sel)), __FILE__, __LINE__);
122                         if (SQL_NUMROWS($result) == 1)
123                         {
124                                 // Entry found so we load the stuff...
125                                 list($menu) = SQL_FETCHROW($result);
126                                 SQL_FREERESULT($result);
127
128                                 // Prepare data for the row template
129                                 $content = array(
130                                         'menu' => $menu,
131                                         'cnt'  => $cnt,
132                                         'sel'  => $sel,
133                                         'sw'   => $SW
134                                 );
135                                 $OUT .= LOAD_TEMPLATE("admin_amenu_delete_row", true, $content);
136                         }
137                         else
138                         {
139                                 // Entry not found?
140                                 $content = array(
141                                         'sw'  => $SW,
142                                         'sel' => $sel
143                                 );
144                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
145                         }
146                         $SW = 3 - $SW;
147                 }
148         }
149         define('__MENU_ROWS', $OUT);
150         define('__CNT_VALUE', $cnt);
151
152         // Load template
153         LOAD_TEMPLATE("admin_amenu_delete");
154 } elseif ((isFormSent()) && (!IS_DEMO())) {
155         // An action is done...
156         switch (REQUEST_POST('ok'))
157         {
158                 case 'edit': // Edit menu
159                         foreach (REQUEST_POST('sel') as $sel => $menu) {
160                                 // Secure ID
161                                 $sel = bigintval($sel);
162
163                                 // Update entry
164                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admin_menu` SET
165 title='%s',
166 `action`='%s',
167 `what`='%s',
168 descr='%s'
169 WHERE ".$AND." AND id=%s LIMIT 1",
170                                 array(
171                                 $menu,
172                                 REQUEST_POST('sel_action', $sel),
173                                 REQUEST_POST('sel_what', $sel),
174                                 REQUEST_POST('sel_desc', $sel),
175                                 $sel,
176                                 ), __FILE__, __LINE__);
177                         }
178
179                         // Purge admin menu cache
180                         cachePurgeAdminMenu(0, REQUEST_POST('sel_action', $sel), REQUEST_POST('sel_what', $sel));
181
182                         // Load template
183                         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
184                         break;
185
186                 case 'del': // Delete menu
187                         foreach (REQUEST_POST('sel') as $sel => $menu) {
188                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE ".$AND." AND id=%s LIMIT 1",
189                                 array(bigintval($sel)), __FILE__, __LINE__);
190                                 cachePurgeAdminMenu(0, '', '', $AND);
191                         } // END - foreach
192
193                         // Load template
194                         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
195                         break;
196
197                 default: // Unexpected action
198                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", REQUEST_POST('ok')));
199                         define('__OK_VALUE', REQUEST_POST('ok'));
200                         LOAD_TEMPLATE("admin_menu_unknown_okay");
201                         break;
202         }
203 } else {
204         if ((REQUEST_ISSET_GET(('act'))) && (REQUEST_ISSET_GET(('tid'))) && (REQUEST_ISSET_GET(('fid')))) {
205                 // Get IDs
206                 if (REQUEST_ISSET_GET(('w'))) {
207                         // Sub menus selected
208                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
209                         array(REQUEST_GET('act'), bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
210                         list($tid) = SQL_FETCHROW($result);
211                         SQL_FREERESULT($result);
212                         $result = SQL_QUERY("SELECT `id` FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
213                         array(REQUEST_GET('act'), bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
214                         list($fid) = SQL_FETCHROW($result);
215                         SQL_FREERESULT($result);
216                 } else {
217                         // Main menu selected
218                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
219                         array(bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
220                         list($tid) = SQL_FETCHROW($result);
221                         SQL_FREERESULT($result);
222                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
223                         array(bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
224                         list($fid) = SQL_FETCHROW($result);
225                         SQL_FREERESULT($result);
226                 }
227
228                 if ((!empty($tid)) && (!empty($fid))) {
229                         // Sort menu
230                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
231                         array(bigintval(REQUEST_GET('tid')), bigintval($fid)), __FILE__, __LINE__);
232                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admin_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
233                         array(bigintval(REQUEST_GET('fid')), bigintval($tid)), __FILE__, __LINE__);
234                         cachePurgeAdminMenu(0, '', '', $AND);
235                 }
236         }
237
238         // By default list menus
239         if (!empty($SUB)) {
240                 // Sub menus of a main menu
241                 $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",
242                 array($SUB), __FILE__, __LINE__);
243         } else {
244                 // Main menus
245                 $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__);
246         }
247
248         $max = SQL_NUMROWS($result);
249         if ($max > 0) {
250                 // @TODO Rewrite this constant
251                 define('__SUB_VALUE', $SUB);
252
253                 // Init variables
254                 $OUT = ''; $SW  = 2; $cnt = 0;
255
256                 // Process all entries
257                 while ($content = SQL_FETCHARRAY($result)) {
258                         // Count this entry
259                         $cnt++;
260
261                         // Init navigation variable
262                         $content['navi'] = '';
263                         if (($content['sort'] == 0) || (($content['sort'] == 1) && (!empty($SUB)))) {
264                                 // Is highest position
265                                 $content['navi'] = "<a href=\"{!URL!}/modules.php?module=admin&amp;what=adminedit&amp;sub={!__SUB_VALUE!}&amp;act=".$content['action']."&amp;w=".$content['what']."&amp;tid=".($content['sort']+1)."&amp;fid=".$content['sort']."\">{--LOWER--}</a>";
266                         } elseif ($cnt == $max) {
267                                 // Is lowest position
268                                 $content['navi'] = "<a href=\"{!URL!}/modules.php?module=admin&amp;what=adminedit&amp;sub={!__SUB_VALUE!}&amp;act=".$content['action']."&amp;w=".$content['what']."&amp;tid=".($content['sort']-1)."&amp;fid=".$content['sort']."\">{--HIGHER--}</a>";
269                         } elseif ($content['sort'] > 0) {
270                                 // Anything else between highest and lowest
271                                 $content['navi'] = "<a href=\"{!URL!}/modules.php?module=admin&amp;what=adminedit&amp;sub={!__SUB_VALUE!}&amp;act=".$content['action']."&amp;w=".$content['what']."&amp;tid=".($content['sort']-1)."&amp;fid=".$content['sort']."\">{--HIGHER--}</a>/<a href=\"{!URL!}/modules.php?module=admin&amp;what=adminedit&amp;sub={!__SUB_VALUE!}&amp;act=".$content['action']."&amp;w=".$content['what']."&amp;tid=".($content['sort']+1)."&amp;fid=".$content['sort']."\">{--LOWER--}</a>";
272                         }
273
274                         // Fix empty elements for constant (fixes display bugs in Firefox)
275                         if (empty($content['action'])) $content['action'] = "&nbsp;";
276                         if (empty($content['what']))   $content['what']   = "&nbsp;";
277                         if (empty($content['title']))  $content['title']  = "&nbsp;";
278
279                         // Add more data to $content
280                         $content['sw']   = $SW;
281                         $content['mode'] = 'admin';
282
283                         // Load row template and switch colors
284                         $OUT .= LOAD_TEMPLATE("admin_menu_overview_row", true, $content);
285                         $SW = 3 - $SW;
286                 } // END - switch
287
288                 // Free memory
289                 SQL_FREERESULT($result);
290
291                 // Rewrite this constant
292                 define('__MENU_ROWS', $OUT);
293
294                 // Load template
295                 LOAD_TEMPLATE("admin_amenu_edit");
296         } else {
297                 // Menu entries are missing... (???)
298                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));
299         }
300 }
301
302 //
303 ?>