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