More use of EL, fix for admin links
[mailer.git] / inc / modules / admin / what-guestedit.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 09/28/2003 *
4  * ===================                          Last change: 12/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-guestedit.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Edit guest's menu                                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Menue fuer die Gaeste 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
51 if (isGetRequestParameterSet('sub')) {
52         $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", getRequestParameter('sub'));
53         $SUB = getRequestParameter('sub');
54 } // END - if
55
56 // List all menu points and make them editable
57 if ((isFormSent('edit')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
58         // Edit menu entries
59         $content['sub'] = $SUB;
60         $content['chk'] = countPostSelection();
61
62         $cnt = '0'; $OUT = ''; $SW = 2;
63         foreach (postRequestParameter('sel') as $sel => $confirm) {
64                 if ($confirm == 1) {
65                         $cnt++;
66                         $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
67                                 array(bigintval($sel)), __FILE__, __LINE__);
68                         if (SQL_NUMROWS($result) == 1) {
69                                 // Entry found so we load the stuff...
70                                 $DATA = SQL_FETCHARRAY($result);
71
72                                 // Prepapre content
73                                 $DATA = array(
74                                         'cnt'    => $cnt,
75                                         'sel'    => $sel,
76                                         'action' => adminAddMenuSelectionBox('guest', 'action', 'sel_action[' . $sel . ']', $DATA['action']),
77                                         'what'   => adminAddMenuSelectionBox('guest', 'what'  , 'sel_what['   . $sel . ']', $DATA['what']),
78                                         'menu'   => $DATA['title'],
79                                         'sw'     => $SW,
80                                 );
81
82                                 // Load row template
83                                 $OUT .= loadTemplate('admin_gmenu_edit_row', true, $DATA);
84                         } else {
85                                 // Entry not found
86                                 $DATA = array(
87                                         'sw'  => $SW,
88                                         'sel' => $sel
89                                 );
90                                 $OUT .= loadTemplate('admin_menu_404_row', true, $DATA);
91                         }
92
93                         // Free result and switch color
94                         SQL_FREERESULT($result);
95                         $SW = 3 - $SW;
96                 } // END - if
97         } // END - foreach
98
99         $content['rows'] = $OUT;
100         $content['cnt']  = $cnt;
101
102         // Load template
103         loadTemplate('admin_gmenu_edit_form', false, $content);
104 } elseif ((isFormSent('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
105         // Del menu entries with or without confirmation
106         $content['sub'] = $SUB;
107         $content['chk'] = countPostSelection();
108
109         $cnt = '0';
110         $OUT = '';
111         $SW  = 2;
112
113         foreach (postRequestParameter('sel') as $sel => $confirm) {
114                 if ($confirm == 1) {
115                         $cnt++;
116                         $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_guest_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                                 $DATA = array(
122                                         'cnt'  => $cnt,
123                                         'menu' => $DATA['title'],
124                                         'sel'  => $sel,
125                                         'sw'   => $SW,
126                                 );
127                                 $OUT .= loadTemplate('admin_gmenu_delete_row', true, $DATA);
128                         } else {
129                                 // Entry not found?
130                                 $DATA = array(
131                                         'sw'  => $SW,
132                                         'sel' => $sel
133                                 );
134                                 $OUT .= loadTemplate('admin_menu_404_row', true, $DATA);
135                         }
136                         SQL_FREERESULT($result);
137                         $SW = 3 - $SW;
138                 }
139         }
140         $content['rows'] = $OUT;
141         $content['cnt']  = $cnt;
142
143         // Load template
144         loadTemplate('admin_gmenu_delete', false, $content);
145 } elseif ((isFormSent()) && (!isDemoModeActive())) {
146         // An action is done...
147         switch (postRequestParameter('ok')) {
148                 case 'edit': // Edit menu
149                         foreach (postRequestParameter('sel') as $sel => $menu) {
150                                 // Secure selector
151                                 $sel = bigintval($sel);
152
153                                 // Update entry
154                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
155                                         array($menu, postRequestParameter('sel_action', $sel), postRequestParameter('sel_what', $sel), $sel),__FILE__, __LINE__);
156                         } // END - foreach
157                         loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
158                         break;
159
160                 case 'del': // Delete menu
161                         foreach (postRequestParameter('sel') as $sel => $menu) {
162                                 // Delete enty
163                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
164                                         array(bigintval($sel)), __FILE__, __LINE__);
165                         } // END - foreach
166                         loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
167                         break;
168
169                 case 'status': // Change access levels
170                         foreach (postRequestParameter('sel') as $sel => $menu) {
171                                 // Secure selector
172                                 $sel = bigintval($sel);
173
174                                 // Update entry
175                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
176                                         array(postRequestParameter('visible', $sel), postRequestParameter('locked', $sel), $sel), __FILE__, __LINE__);
177                         } // END - foreach
178                         loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
179                         break;
180
181                 default: // Unexpected action
182                         logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
183                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
184                         break;
185         } // END - switch
186 } elseif ((isPostRequestParameterSet('status')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
187         // Change status (visible / locked)
188         $content['sub'] = $SUB;
189         $content['chk'] = countPostSelection();
190
191         // Load template
192         $SW = 2; $cnt = '0'; $OUT = '';
193         foreach (postRequestParameter('sel') as $sel => $confirm) {
194                 if ($confirm == 1) {
195                         $cnt++;
196                         $result = SQL_QUERY_ESC("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
197                                 array(bigintval($sel)), __FILE__, __LINE__);
198                         if (SQL_NUMROWS($result) == 1) {
199                                 // Entry found so we load the stuff...
200                                 $data = SQL_FETCHARRAY($result);
201                                 $data = array(
202                                         'cnt'     => $cnt,
203                                         'menu'    => $data['title'],
204                                         'sel'     => $sel,
205                                         'sw'      => $SW,
206                                         'visible' => addSelectionBox('yn', $data['visible'], 'visible', $sel),
207                                         'locked'  => addSelectionBox('yn', $data['locked'] , 'locked' , $sel),
208                                 );
209
210                                 // Load template
211                                 $OUT .= loadTemplate('admin_menu_status_row', true, $data);
212                         } else {
213                                 // Entry not found?
214                                 $data = array(
215                                         'sw'  => $SW,
216                                         'sel' => $sel
217                                 );
218                                 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
219                         }
220
221                         SQL_FREERESULT($result);
222                         $SW = 3 - $SW;
223                 } // END - if
224         } // END - foreach
225         $content['cnt']  = $cnt;
226         $content['rows'] = $OUT;
227
228         // Load template
229         loadTemplate('admin_gmenu_status', false, $content);
230 } else {
231         if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
232                 // Get ids
233                 if (isGetRequestParameterSet('w')) {
234                         // Sub menus selected
235                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
236                                 array(getRequestParameter('act'), bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
237                         list($tid) = SQL_FETCHROW($result);
238                         SQL_FREERESULT($result);
239                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
240                                 array(getRequestParameter('act'), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
241                         list($fid) = SQL_FETCHROW($result);
242                         SQL_FREERESULT($result);
243                 } else {
244                         // Main menu selected
245                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
246                                 array(bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
247                         list($tid) = SQL_FETCHROW($result);
248                         SQL_FREERESULT($result);
249                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
250                                 array(bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
251                         list($fid) = SQL_FETCHROW($result);
252                         SQL_FREERESULT($result);
253                 }
254
255                 if ((!empty($tid)) && (!empty($fid))) {
256                         // Sort menu
257                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
258                                 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
259                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
260                                 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
261                 } // END - if
262         } // END - if
263
264         // By default list menus
265         if (empty($SUB)) {
266                 // List only main menus
267                 $result = SQL_QUERY("SELECT `id`,`action`,`what`,`title`,`sort` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
268         } else {
269                 // List sub menus
270                 $result = SQL_QUERY_ESC("SELECT `id`,`action`,`what`,`title`,`sort` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort` ASC",
271                         array($SUB), __FILE__, __LINE__);
272         }
273
274         // Get number of menu entries
275         $max = SQL_NUMROWS($result);
276         if ($max > 0) {
277                 // Set sub value
278                 $content['sub'] = $SUB;
279
280                 // Init variables
281                 $SW = 2;
282                 $cnt = '0';
283                 $OUT = '';
284
285                 // Process all menu entries
286                 while ($data = SQL_FETCHARRAY($result)) {
287                         $cnt++;
288                         if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
289                                 // Is highest position
290                                 $NAVI = '<a href="{%url=modules.php?module=admin&amp;what=guestedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']+1) . '&amp;fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
291                         } elseif ($cnt == $max) {
292                                 // Is lowest position
293                                 $NAVI = '<a href="{%url=modules.php?module=admin&amp;what=guestedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']-1) . '&amp;fid=' . $data['sort'] . '%}">{--HIGHER--}</a>';
294                         } elseif ($data['sort'] > 0) {
295                                 // Anything else between highest and lowest
296                                 $NAVI = '<a href="{%url=modules.php?module=admin&amp;what=guestedit&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=guestedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']+1) . '&amp;fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
297                         }
298
299                         if (empty($data['action'])) $data['action'] = '&nbsp;';
300                         if (empty($data['what']))   $data['what']   = '&nbsp;';
301                         if (empty($data['title']))  $data['title']  = '&nbsp;';
302
303                         // Prepapre content
304                         $row = array(
305                                 'sw'     => $SW,
306                                 'id'     => $data['id'],
307                                 'action' => $data['action'],
308                                 'what'   => $data['what'],
309                                 'title'  => $data['title'],
310                                 'navi'   => $NAVI,
311                                 'mode'   => 'guest'
312                         );
313
314                         // Load row template
315                         $OUT .= loadTemplate('admin_menu_overview_row', true, $row);
316                         $SW = 3 - $SW;
317                 } // END - while
318
319                 // Add rows
320                 $content['rows'] = $OUT;
321
322                 // Free memory
323                 SQL_FREERESULT($result);
324
325                 // Load template
326                 loadTemplate('admin_gmenu_edit', false, $content);
327         } else {
328                 // Menu entries are missing... (???)
329                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));
330         }
331 }
332
333 // [EOF]
334 ?>