b7ee2ea99a71f0ecc50dbd00f3c40558318889cf
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
42
43 // Do we edit/delete/change main menus or sub menus?
44 $AND = "what = ''"; $SUB = "";
45
46 if (!empty($_GET['sub'])) {
47         $AND = sprintf("action='%s'", SQL_ESCAPE($_GET['sub']));
48         $SUB = SQL_ESCAPE($_GET['sub']);
49 }
50
51 // Get count of (maybe) selected menu points
52 $chk = 0;
53 if (!empty($_POST['sel'])) $chk = SELECTION_COUNT($_POST['sel']);
54
55 // List all menu points and make them editable
56 if ((isset($_POST['edit'])) && ($chk > 0) && (!IS_DEMO()))
57 {
58         // Edit menu entries
59         define('__SUB_VALUE', $SUB);
60         define('__CHK_VALUE', $chk);
61
62         $cnt = 0; $SW = 2; $OUT = "";
63         foreach ($_POST['sel'] as $sel => $confirm)
64         {
65                 if ($confirm == 1)
66                 {
67                         $cnt++;
68                         $query = SQL_QUERY_ESC("SELECT title, action, what FROM "._MYSQL_PREFIX."_guest_menu WHERE ".$AND." AND id=%s LIMIT 1",
69                          array(bigintval($sel)), __FILE__, __LINE__);
70                         if (SQL_NUMROWS($query) == 1)
71                         {
72                                 // Entry found so we load the stuff...
73                                 list($menu, $act, $wht) = SQL_FETCHROW($query);
74                                 SQL_FREERESULT($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                         }
85                          else
86                         {
87                                 // Entry not found?
88                                 $content = array(
89                                         'sw'  => $SW,
90                                         'sel' => $sel
91                                 );
92                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
93                         }
94                         $SW = 3 - $SW;
95                 }
96         }
97         define('__MENU_ROWS', $OUT);
98         define('__CNT_VALUE', $cnt);
99
100         // Load template
101         LOAD_TEMPLATE("admin_gmenu_edit_form");
102 }
103  elseif ((isset($_POST['del'])) && (!IS_DEMO()))
104 {
105         // Del menu entries with or without confirmation
106         define('__SUB_VALUE', $SUB);
107         define('__CHK_VALUE', $chk);
108
109         $cnt = 0; $OUT = ""; $SW = 2;
110         foreach ($_POST['sel'] as $sel => $confirm)
111         {
112                 if ($confirm == 1)
113                 {
114                         $cnt++;
115                         $query = 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($query) == 1)
118                         {
119                                 // Entry found so we load the stuff...
120                                 list($menu) = SQL_FETCHROW($query);
121                                 SQL_FREERESULT($result);
122                                 $DATA = array(
123                                         'cnt'  => $cnt,
124                                         'menu' => $menu,
125                                         'sel'  => $sel,
126                                         'sw'   => $SW,
127                                 );
128                                 $OUT .= LOAD_TEMPLATE("admin_gmenu_delete_row", true, $DATA);
129                         }
130                          else
131                         {
132                                 // Entry not found?
133                                 $content = array(
134                                         'sw'  => $SW,
135                                         'sel' => $sel
136                                 );
137                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
138                         }
139                         $SW = 3 - $SW;
140                 }
141         }
142         define('__MENU_ROWS', $OUT);
143         define('__CNT_VALUE', $cnt);
144
145         // Load template
146         LOAD_TEMPLATE("admin_gmenu_delete");
147 }
148  elseif ((isset($_POST['ok'])) && (!IS_DEMO()))
149 {
150         // An action is done...
151         switch ($_POST['ok'])
152         {
153         case "edit": // Edit menu
154                 foreach ($_POST['sel'] as $sel => $menu)
155                 {
156                         // Secure selector
157                         $sel = bigintval($sel);
158
159                         // Update entry
160                         $query = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_guest_menu SET title='%s', action='%s', what='%s' WHERE ".$AND." AND id=%s LIMIT 1",
161                          array($menu, $_POST['sel_action'][$sel], $_POST['sel_what'][$sel], $sel),__FILE__, __LINE__);
162                 }
163                 LOAD_TEMPLATE("admin_data_saved");
164                 break;
165
166         case "del": // Delete menu
167                 foreach ($_POST['sel'] as $sel => $menu)
168                 {
169                         // Delete enty
170                         $query = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_guest_menu WHERE ".$AND." AND id=%s LIMIT 1",
171                          array(bigintval($sel)), __FILE__, __LINE__);
172                 }
173                 LOAD_TEMPLATE("admin_data_saved");
174                 break;
175
176         case "status": // Change access levels
177                 foreach ($_POST['sel'] as $sel => $menu)
178                 {
179                         // Secure selector
180                         $sel = bigintval($sel);
181
182                         // Update entry
183                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_guest_menu SET visible='%s', locked='%s' WHERE ".$AND." AND id=%s LIMIT 1",
184                          array($_POST['visible'][$sel], $_POST['locked'][$sel], $sel), __FILE__, __LINE__);
185                 }
186                 LOAD_TEMPLATE("admin_data_saved");
187                 break;
188
189         default: // Unexpected action
190                 define('__OK_VALUE', $_POST['ok']);
191                 LOAD_TEMPLATE("admin_menu_unknown_okay");
192                 break;
193         }
194 }
195  elseif ((isset($_POST['status'])) && ($chk > 0) && (!IS_DEMO()))
196 {
197         // Change status (visible / locked)
198         define('__SUB_VALUE', $SUB);
199         define('__CHK_VALUE', $chk);
200
201         // Load template
202         $SW = 2; $cnt = 0; $OUT = "";
203         foreach ($_POST['sel'] as $sel => $confirm)
204         {
205                 if ($confirm == 1)
206                 {
207                         $cnt++;
208                         $result = SQL_QUERY_ESC("SELECT title, visible, locked FROM "._MYSQL_PREFIX."_guest_menu WHERE ".$AND." AND id=%s LIMIT 1",
209                          array(bigintval($sel)), __FILE__, __LINE__);
210                         if (SQL_NUMROWS($result) == 1)
211                         {
212                                 // Entry found so we load the stuff...
213                                 list($menu, $vis, $locked) = SQL_FETCHROW($result);
214                                 SQL_FREERESULT($result);
215                                 $content = array(
216                                         'cnt'     => $cnt,
217                                         'menu'    => $menu,
218                                         'sel'     => $sel,
219                                         'sw'      => $SW,
220                                         'visible' => ADD_SELECTION("yn", $vis   , "visible", $sel),
221                                         'locked'  => ADD_SELECTION("yn", $locked, "locked" , $sel),
222                                 );
223
224                                 // Load template
225                                 $OUT .= LOAD_TEMPLATE("admin_menu_status_row", true, $content);
226                         }
227                          else
228                         {
229                                 // Entry not found?
230                                 $content = array(
231                                         'sw'  => $SW,
232                                         'sel' => $sel
233                                 );
234                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
235                         }
236                         $SW = 3 - $SW;
237                 }
238         }
239         define('__CNT_VALUE', $cnt);
240         define('__MENU_ROWS', $OUT);
241
242         // Load template
243         LOAD_TEMPLATE("admin_gmenu_status");
244 }
245  else
246 {
247         if ((!empty($_GET['act'])) && (!empty($_GET['tid'])) && (!empty($_GET['fid'])))
248         {
249                 // Get IDs
250                 if (!empty($_GET['w']))
251                 {
252                         // Sub menus selected
253                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_guest_menu WHERE action='%s' AND sort='%s' LIMIT 1",
254                          array($_GET['act'], bigintval($_GET['tid'])), __FILE__, __LINE__);
255                         list($tid) = SQL_FETCHROW($result);
256                         SQL_FREERESULT($result);
257                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_guest_menu WHERE action='%s' AND sort='%s' LIMIT 1",
258                          array($_GET['act'], bigintval($_GET['fid'])), __FILE__, __LINE__);
259                         list($fid) = SQL_FETCHROW($result);
260                         SQL_FREERESULT($result);
261                 }
262                  else
263                 {
264                         // Main menu selected
265                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_guest_menu WHERE (what='' OR what IS NULL) AND sort='%s' LIMIT 1",
266                          array(bigintval($_GET['tid'])), __FILE__, __LINE__);
267                         list($tid) = SQL_FETCHROW($result);
268                         SQL_FREERESULT($result);
269                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_guest_menu WHERE (what='' OR what IS NULL) AND sort='%s' LIMIT 1",
270                          array(bigintval($_GET['fid'])), __FILE__, __LINE__);
271                         list($fid) = SQL_FETCHROW($result);
272                         SQL_FREERESULT($result);
273                 }
274
275                 if ((!empty($tid)) && (!empty($fid)))
276                 {
277                         // Sort menu
278                         $result_sort = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_guest_menu SET sort='%s' WHERE ".$AND." AND id=%s LIMIT 1",
279                          array(bigintval($_GET['tid']), bigintval($fid)), __FILE__, __LINE__);
280                         $result_sort = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_guest_menu SET sort='%s' WHERE ".$AND." AND id=%s LIMIT 1",
281                          array(bigintval($_GET['fid']), bigintval($tid)), __FILE__, __LINE__);
282                 }
283         }
284
285         // By default list menus
286         if (empty($SUB))
287         {
288                 // List only main menus
289                 $query = 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__);
290         }
291          else
292         {
293                 // List sub menus
294                 $query = 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",
295                  array($SUB), __FILE__, __LINE__);
296         }
297
298         // Get number of menu entries
299         $max = SQL_NUMROWS($query);
300         if ($max > 0)
301         {
302                 // Some entties does exist!
303                 if (!empty($SUB))
304                 {
305                         // Set sub value
306                         define('__SUB_VALUE', $SUB);
307                 }
308                  else
309                 {
310                         // No sub menu selected
311                         define('__SUB_VALUE', "");
312                 }
313
314                 $SW = 2; $cnt = 0; $OUT = "";
315                 while (list($id, $act, $wht, $title, $sort) = SQL_FETCHROW($query))
316                 {
317                         $cnt++;
318                         if (($sort == 0) || (($sort == 1) && (!empty($SUB))))
319                         {
320                                 // Is highest position
321                                 $NAVI = "<A href=\"".URL."/modules.php?module=admin&amp;what=guestedit&amp;sub=".__SUB_VALUE."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort+1)."&amp;fid=".$sort."\">".LOWER."</A>";
322                         }
323                          elseif ($cnt == $max)
324                         {
325                                 // Is lowest position
326                                 $NAVI = "<A href=\"".URL."/modules.php?module=admin&amp;what=guestedit&amp;sub=".__SUB_VALUE."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort-1)."&amp;fid=".$sort."\">".HIGHER."</A>";
327                         }
328                          elseif ($sort > 0)
329                         {
330                                 // Anything else between highest and lowest
331                                 $NAVI = "<A href=\"".URL."/modules.php?module=admin&amp;what=guestedit&amp;sub=".__SUB_VALUE."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort-1)."&amp;fid=".$sort."\">".HIGHER."</A>/<A href=\"".URL."/modules.php?module=admin&amp;what=guestedit&amp;sub=".__SUB_VALUE."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort+1)."&amp;fid=".$sort."\">".LOWER."</A>";
332                         }
333                         if (empty($act)) $act = "&nbsp;";
334                         if (empty($wht))   $wht   = "&nbsp;";
335                         if (empty($title))  $title  = "&nbsp;";
336                         $content = array(
337                                 'sw'     => $SW,
338                                 'id'     => $id,
339                                 'action' => $act,
340                                 'what'   => $wht,
341                                 'title'  => $title,
342                                 'navi'   => $NAVI,
343                                 'mode'   => "guest"
344                         );
345                         $OUT .= LOAD_TEMPLATE("admin_menu_overview_row", true, $content);
346                         $SW = 3 - $SW;
347                 }
348
349                 // Free memory
350                 SQL_FREERESULT($query);
351                 define('__MENU_ROWS', $OUT);
352
353                 // Load template
354                 LOAD_TEMPLATE("admin_gmenu_edit");
355         }
356          else
357         {
358                 // Menu entries are missing... (???)
359                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_MENUS_FOUND);
360         }
361 }
362
363 //
364 ?>