]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-adminedit.php
Fixes for old-lost code
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 // Do we edit/delete/change main menus or sub menus?
47 $AND = "(`what` = '' OR `what` IS NULL)"; $subMenu = '';
48 if (isGetRequestParameterSet('sub')) {
49         $AND = sprintf("`action`='%s' AND `what` != '' AND `what` IS NOT NULL", getRequestParameter('sub'));
50         $subMenu = getRequestParameter('sub');
51 } // END - if
52
53 // List all menu points and make them editable
54 if ((isFormSent('edit')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
55         // Edit menu entries
56         // @TODO Kill all constants in this file
57         $content['sub'] = $subMenu;
58         $content['chk'] = countPostSelection();
59         $count = '0'; $OUT = '';
60         foreach (postRequestParameter('sel') as $sel => $confirm) {
61                 if ($confirm == 1) {
62                         $count++;
63                         $result = SQL_QUERY_ESC("SELECT `title`,`action`,`what`,`descr` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
64                                 array(bigintval($sel)), __FILE__, __LINE__);
65                         if (SQL_NUMROWS($result) == 1) {
66                                 // Entry found so we load the stuff...
67                                 $content = SQL_FETCHARRAY($result);
68
69                                 // Prepare data for the row template
70                                 $content = array(
71                                         'action' => adminAddMenuSelectionBox('admin', 'action', 'sel_action[' . $sel . ']', $content['action']),
72                                         'what'   => adminAddMenuSelectionBox('admin', 'what'  , 'sel_what['   . $sel . ']', $content['what']),
73                                         'sel'    => $sel,
74                                         'menu'   => $content['title'],
75                                         'descr'  => $content['descr'],
76                                         'count'  => $count,
77                                 );
78
79                                 // Load row template
80                                 $OUT .= loadTemplate('admin_edit_admin_menu_row', true, $content);
81                         } else {
82                                 // Entry not found?
83                                 $content = array(
84                                         'sel' => $sel
85                                 );
86
87                                 // Load row template
88                                 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
89                         }
90
91                         // Free result and switch color
92                         SQL_FREERESULT($result);
93                 } // END - if
94         } // END - foreach
95
96         $content['rows']  = $OUT;
97         $content['sub']   = $subMenu;
98         $content['chk']   = countPostSelection();
99         $content['count'] = $count;
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'] = $subMenu;
106         $content['chk'] = countPostSelection();
107
108         // Del menu entries with or without confirmation
109         $count = '0'; $OUT = '';
110         foreach (postRequestParameter('sel') as $sel => $confirm) {
111                 if ($confirm == 1) {
112                         $count++;
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                                 $content = SQL_FETCHARRAY($result);
118
119                                 // Prepare data for the row template
120                                 $content = array(
121                                         'menu'  => $content['title'],
122                                         'count' => $count,
123                                         'sel'   => $sel,
124                                 );
125                                 $OUT .= loadTemplate('admin_delete_admin_menu_row', true, $content);
126                         } else {
127                                 // Entry not found?
128                                 $content = array(
129                                         'sel' => $sel
130                                 );
131                                 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
132                         }
133                         SQL_FREERESULT($result);
134                 } // END - if
135         } // END - switch
136
137         $content['rows']  = $OUT;
138         $content['sub']   = $subMenu;
139         $content['chk']   = countPostSelection();
140         $content['count'] = $count;
141
142         // Load template
143         loadTemplate('admin_delete_admin_menu', false, $content);
144 } elseif ((isFormSent()) && (!isDemoModeActive())) {
145         // An action is done...
146         switch (postRequestParameter('ok')) {
147                 case 'edit': // Edit menu
148                         foreach (postRequestParameter('sel') as $sel => $menu) {
149                                 // Secure id
150                                 $sel = bigintval($sel);
151
152                                 // Update entry
153                                 SQL_QUERY_ESC("UPDATE
154         `{?_MYSQL_PREFIX?}_admin_menu`
155 SET
156         `title`='%s',
157         `action`='%s',
158         `what`='%s',
159         `descr`='%s'
160 WHERE
161         ".$AND." AND
162         `id`=%s
163 LIMIT 1",
164                                 array(
165                                         $menu,
166                                         postRequestParameter('sel_action', $sel),
167                                         postRequestParameter('sel_what', $sel),
168                                         postRequestParameter('sel_desc', $sel),
169                                         $sel,
170                                 ), __FILE__, __LINE__);
171                         }
172
173                         // Load template
174                         displayMessage('{--SETTINGS_SAVED--}');
175                         break;
176
177                 case 'delete': // Delete menu
178                         foreach (postRequestParameter('sel') as $sel => $menu) {
179                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
180                                         array(bigintval($sel)), __FILE__, __LINE__);
181                         } // END - foreach
182
183                         // Load template
184                         displayMessage('{--SETTINGS_SAVED--}');
185                         break;
186
187                 default: // Unexpected action
188                         logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
189                         displayMessage('{%message,ADMIN_UNKNOWN_OKAY=' . postRequestParameter('ok') . '%}');
190                         break;
191         } // END - switch
192 } else {
193         // Handle weightning
194         doAdminProcessMenuWeightning('admin', $AND);
195
196         // Run SQL
197         $result = SQL_QUERY("SELECT `id`,`action`,`what`,`title`,`sort` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$AND." ORDER BY `sort` ASC", __FILE__, __LINE__);
198
199         // Do we have entries?
200         if (!SQL_HASZERONUMS($result)) {
201                 // Init variables
202                 $OUT = '';
203                 $count = '0';
204
205                 // Process all entries
206                 while ($content = SQL_FETCHARRAY($result)) {
207                         // Remember sub value
208                         $content['sub'] = $subMenu;
209
210                         // Count this entry
211                         $count++;
212
213                         // Init navigation variable
214                         $content['navi'] = '';
215                         if (($content['sort'] == '0') || (($content['sort'] == 1) && (!empty($subMenu)))) {
216                                 // Is highest position
217                                 $content['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']+1) . '&amp;fid=' . $content['sort'] . '%}">{--LOWER--}</a>';
218                         } elseif ($count == SQL_NUMROWS($result)) {
219                                 // Is lowest position
220                                 $content['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']-1) . '&amp;fid=' . $content['sort'] . '%}">{--HIGHER--}</a>';
221                         } elseif ($content['sort'] > 0) {
222                                 // Anything else between highest and lowest
223                                 $content['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&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=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']+1) . '&amp;fid=' . $content['sort'] . '%}">{--LOWER--}</a>';
224                         }
225
226                         // Add more data to $content
227                         $content['mode'] = 'admin';
228
229                         // Load row template and switch colors
230                         $OUT .= loadTemplate('admin_menu_overview_row', true, $content);
231                 } // END - switch
232
233                 // Remember all rows
234                 $content['rows'] = $OUT;
235                 $content['sub']  = $subMenu;
236
237                 // Free memory
238                 SQL_FREERESULT($result);
239
240                 // Load template
241                 loadTemplate('admin_edit_admin_menu', false, $content);
242         } else {
243                 // Menu entries are missing... (???)
244                 displayMessage('{--ADMIN_NO_MENUS_FOUND--}');
245         }
246 }
247
248 //
249 ?>