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