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