]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-guestedit.php
Several more constants rewritten to getConfig()
[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 - 2008 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')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('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 (REQUEST_ISSET_GET('sub')) {
52         $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", REQUEST_GET('sub'));
53         $SUB = REQUEST_GET('sub');
54 } // END - if
55
56 // Get count of (maybe) selected menu points
57 $chk = 0;
58 if (REQUEST_ISSET_POST('sel')) $chk = countPostSelection();
59
60 // List all menu points and make them editable
61 if ((REQUEST_ISSET_POST('edit')) && ($chk > 0) && (!IS_DEMO())) {
62         // Edit menu entries
63         define('__SUB_VALUE', $SUB);
64         define('__CHK_VALUE', $chk);
65
66         $cnt = 0; $OUT = ''; $SW = 2;
67         foreach (REQUEST_POST('sel') as $sel => $confirm) {
68                 if ($confirm == 1) {
69                         $cnt++;
70                         $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
71                                 array(bigintval($sel)), __FILE__, __LINE__);
72                         if (SQL_NUMROWS($result) == 1) {
73                                 // Entry found so we load the stuff...
74                                 list($menu, $act, $wht) = SQL_FETCHROW($result);
75                                 $DATA = array(
76                                         'cnt'    => $cnt,
77                                         'sel'    => $sel,
78                                         'action' => ADMIN_MAKE_MENU_SELECTION('guest', 'action', 'sel_action[' . $sel . ']', $act),
79                                         'what'   => ADMIN_MAKE_MENU_SELECTION('guest', 'what', 'sel_what[' . $sel . ']', $wht),
80                                         'menu'   => $menu,
81                                         'sw'     => $SW,
82                                 );
83                                 $OUT .= LOAD_TEMPLATE('admin_gmenu_edit_row', true, $DATA);
84                         } else {
85                                 // Entry not found?
86                                 $content = array(
87                                         'sw'  => $SW,
88                                         'sel' => $sel
89                                 );
90                                 $OUT .= LOAD_TEMPLATE('admin_menu_404_row', true, $content);
91                         }
92                         SQL_FREERESULT($result);
93                         $SW = 3 - $SW;
94                 } // END - if
95         } // END - foreach
96
97         define('__MENU_ROWS', $OUT);
98         define('__CNT_VALUE', $cnt);
99
100         // Load template
101         LOAD_TEMPLATE('admin_gmenu_edit_form');
102 } elseif ((REQUEST_ISSET_POST('del')) && (!IS_DEMO())) {
103         // Del menu entries with or without confirmation
104         define('__SUB_VALUE', $SUB);
105         define('__CHK_VALUE', $chk);
106
107         $cnt = 0;
108         $OUT = '';
109         $SW  = 2;
110
111         foreach (REQUEST_POST('sel') as $sel => $confirm) {
112                 if ($confirm == 1) {
113                         $cnt++;
114                         $result = SQL_QUERY_ESC("SELECT `title` FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
115                                 array(bigintval($sel)), __FILE__, __LINE__);
116                         if (SQL_NUMROWS($result) == 1) {
117                                 // Entry found so we load the stuff...
118                                 list($menu) = SQL_FETCHROW($result);
119                                 $DATA = array(
120                                         'cnt'  => $cnt,
121                                         'menu' => $menu,
122                                         'sel'  => $sel,
123                                         'sw'   => $SW,
124                                 );
125                                 $OUT .= LOAD_TEMPLATE('admin_gmenu_delete_row', true, $DATA);
126                         } else {
127                                 // Entry not found?
128                                 $content = array(
129                                         'sw'  => $SW,
130                                         'sel' => $sel
131                                 );
132                                 $OUT .= LOAD_TEMPLATE('admin_menu_404_row', true, $content);
133                         }
134                         SQL_FREERESULT($result);
135                         $SW = 3 - $SW;
136                 }
137         }
138         define('__MENU_ROWS', $OUT);
139         define('__CNT_VALUE', $cnt);
140
141         // Load template
142         LOAD_TEMPLATE('admin_gmenu_delete');
143 } elseif ((isFormSent()) && (!IS_DEMO())) {
144         // An action is done...
145         switch (REQUEST_POST('ok')) {
146                 case 'edit': // Edit menu
147                         foreach (REQUEST_POST('sel') as $sel => $menu) {
148                                 // Secure selector
149                                 $sel = bigintval($sel);
150
151                                 // Update entry
152                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_guest_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
153                                         array($menu, REQUEST_POST('sel_action', $sel), REQUEST_POST('sel_what', $sel), $sel),__FILE__, __LINE__);
154                         } // END - foreach
155                         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
156                         break;
157
158                 case 'del': // Delete menu
159                         foreach (REQUEST_POST('sel') as $sel => $menu) {
160                                 // Delete enty
161                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE ".$AND." AND id=%s LIMIT 1",
162                                         array(bigintval($sel)), __FILE__, __LINE__);
163                         } // END - foreach
164                         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
165                         break;
166
167                 case 'status': // Change access levels
168                         foreach (REQUEST_POST('sel') as $sel => $menu) {
169                                 // Secure selector
170                                 $sel = bigintval($sel);
171
172                                 // Update entry
173                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_guest_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
174                                         array(REQUEST_POST('visible', $sel), REQUEST_POST('locked', $sel), $sel), __FILE__, __LINE__);
175                         } // END - foreach
176                         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
177                         break;
178
179                 default: // Unexpected action
180                         define('__OK_VALUE', REQUEST_POST('ok'));
181                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", REQUEST_POST('ok')));
182                         LOAD_TEMPLATE('admin_menu_unknown_okay');
183                         break;
184         } // END - switch
185 } elseif ((REQUEST_ISSET_POST('status')) && ($chk > 0) && (!IS_DEMO())) {
186         // Change status (visible / locked)
187         define('__SUB_VALUE', $SUB);
188         define('__CHK_VALUE', $chk);
189
190         // Load template
191         $SW = 2; $cnt = 0; $OUT = '';
192         foreach (REQUEST_POST('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                                 list($menu, $vis, $locked) = SQL_FETCHROW($result);
200                                 $content = array(
201                                         'cnt'     => $cnt,
202                                         'menu'    => $menu,
203                                         'sel'     => $sel,
204                                         'sw'      => $SW,
205                                         'visible' => ADD_SELECTION('yn', $vis   , 'visible', $sel),
206                                         'locked'  => ADD_SELECTION('yn', $locked, 'locked' , $sel),
207                                 );
208
209                                 // Load template
210                                 $OUT .= LOAD_TEMPLATE('admin_menu_status_row', true, $content);
211                         } else {
212                                 // Entry not found?
213                                 $content = array(
214                                         'sw'  => $SW,
215                                         'sel' => $sel
216                                 );
217                                 $OUT .= LOAD_TEMPLATE('admin_menu_404_row', true, $content);
218                         }
219
220                         SQL_FREERESULT($result);
221                         $SW = 3 - $SW;
222                 } // END - if
223         } // END - foreach
224         define('__CNT_VALUE', $cnt);
225         define('__MENU_ROWS', $OUT);
226
227         // Load template
228         LOAD_TEMPLATE('admin_gmenu_status');
229 } else {
230         if ((REQUEST_ISSET_GET('act')) && (REQUEST_ISSET_GET('tid')) && (REQUEST_ISSET_GET('fid'))) {
231                 // Get IDs
232                 if (REQUEST_ISSET_GET('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(REQUEST_GET('act'), bigintval(REQUEST_GET('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(REQUEST_GET('act'), bigintval(REQUEST_GET('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(REQUEST_GET('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(REQUEST_GET('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(REQUEST_GET('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(REQUEST_GET('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                 // @TODO Rewrite this constant
278                 define('__SUB_VALUE', $SUB);
279
280                 // Init variables
281                 $SW = 2;
282                 $cnt = 0;
283                 $OUT = '';
284
285                 // Process all menu entries
286                 while ($content = SQL_FETCHARRAY($result)) {
287                         $cnt++;
288                         if (($content['sort'] == 0) || (($content['sort'] == 1) && (!empty($SUB)))) {
289                                 // Is highest position
290                                 $NAVI = "<a href=\"{?URL?}/modules.php?module=admin&amp;what=guestedit&amp;sub={!__SUB_VALUE!}&amp;act=".$content['action']."&amp;w=".$content['what']."&amp;tid=".($content['sort']+1)."&amp;fid=".$content['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={!__SUB_VALUE!}&amp;act=".$content['action']."&amp;w=".$content['what']."&amp;tid=".($content['sort']-1)."&amp;fid=".$content['sort']."\">{--HIGHER--}</a>";
294                         } elseif ($content['sort'] > 0) {
295                                 // Anything else between highest and lowest
296                                 $NAVI = "<a href=\"{?URL?}/modules.php?module=admin&amp;what=guestedit&amp;sub={!__SUB_VALUE!}&amp;act=".$content['action']."&amp;w=".$content['what']."&amp;tid=".($content['sort']-1)."&amp;fid=".$content['sort']."\">{--HIGHER--}</a>/<a href=\"{?URL?}/modules.php?module=admin&amp;what=guestedit&amp;sub={!__SUB_VALUE!}&amp;act=".$content['action']."&amp;w=".$content['what']."&amp;tid=".($content['sort']+1)."&amp;fid=".$content['sort']."\">{--LOWER--}</a>";
297                         }
298
299                         if (empty($content['action'])) $content['action'] = '&nbsp;';
300                         if (empty($content['what']))   $content['what']   = '&nbsp;';
301                         if (empty($content['title']))  $content['title']  = '&nbsp;';
302
303                         // Prepapre content
304                         $content = array(
305                                 'sw'     => $SW,
306                                 'id'     => $content['id'],
307                                 'action' => $content['action'],
308                                 'what'   => $content['what'],
309                                 'title'  => $content['title'],
310                                 'navi'   => $NAVI,
311                                 'mode'   => 'guest'
312                         );
313
314                         // Load row template
315                         $OUT .= LOAD_TEMPLATE('admin_menu_overview_row', true, $content);
316                         $SW = 3 - $SW;
317                 } // END - while
318
319                 // Free memory
320                 SQL_FREERESULT($result);
321                 define('__MENU_ROWS', $OUT);
322
323                 // Load template
324                 LOAD_TEMPLATE('admin_gmenu_edit');
325         } else {
326                 // Menu entries are missing... (???)
327                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));
328         }
329 }
330
331 //
332 ?>