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