2bf60d34fdcbe9284113576f28390ce8c8d36088
[mailer.git] / inc / modules / admin / what-memedit.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/28/2003 *
4  * ===============                              Last change: 05/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-memedit.php                                 *
8  * -------------------------------------------------------------------- *
9  * Short description : Edit member's menu                               *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Editieren Sie das Menue fuer Ihre Mitglieder     *
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", __FILE__);
42
43 // Do we edit/delete/change main menus or sub menus?
44 $AND = "(what = '' OR what IS NULL)"; $SUB = "";
45
46 if (!empty($_GET['sub'])) {
47         $AND = sprintf("action='%s' AND what IS NOT NULL", 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         $SW = 2; $cnt = 0; $OUT = "";
62         foreach ($_POST['sel'] as $sel => $confirm)
63         {
64                 if ($confirm == 1)
65                 {
66                         $cnt++;
67                         $result = SQL_QUERY_ESC("SELECT title, action, what FROM `"._MYSQL_PREFIX."_member_menu` WHERE ".$AND." AND id=%s LIMIT 1",
68                          array(bigintval($sel)), __FILE__, __LINE__);
69                         if (SQL_NUMROWS($result) == 1)
70                         {
71                                 // Entry found so we load the stuff...
72                                 list($menu, $act, $wht, $descr) = SQL_FETCHROW($result);
73                                 SQL_FREERESULT($result);
74                                 $content = array(
75                                         'cnt'    => $cnt,
76                                         'sel'    => $sel,
77                                         'menu'   => $menu,
78                                         'sw'     => $SW,
79                                         'act'    => ADMIN_MAKE_MENU_SELECTION("member", "act", "sel_act[".$sel."]", $act),
80                                         'what'   => ADMIN_MAKE_MENU_SELECTION("member", "what", "sel_what[".$sel."]", $wht),
81                                 );
82                                 // Load template
83                                 $OUT .= LOAD_TEMPLATE("admin_mmenu_edit_row", true, $content);
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_mmenu_edit");
102 }
103  elseif ((isset($_POST['del'])) && ($chk > 0) && (!IS_DEMO()))
104 {
105         // Del menu entries with or without confirmation
106         define('__SUB_VALUE', $SUB);
107         define('__CHK_VALUE', $chk);
108         $SW = 2; $cnt = 0; $OUT = "";
109         foreach ($_POST['sel'] as $sel => $confirm)
110         {
111                 if ($confirm == 1)
112                 {
113                         $cnt++;
114                         $result = SQL_QUERY_ESC("SELECT title FROM `"._MYSQL_PREFIX."_member_menu` WHERE ".$AND." AND id=%s LIMIT 1",
115                          array(bigintval($sel)), __FILE__, __LINE__);
116                         if (SQL_NUMROWS($result) == 1)
117                         {
118                                 // Entry found so we load the stuff...
119                                 list($title) = SQL_FETCHROW($result);
120                                 SQL_FREERESULT($result);
121                                 $content = array(
122                                         'cnt'   => $cnt,
123                                         'sel'   => $sel,
124                                         'title' => $title
125                                 );
126                                 $OUT .= LOAD_TEMPLATE("admin_mmenu_delete_row", true, $content);
127                         }
128                          else
129                         {
130                                 // Entry not found?
131                                 $content = array(
132                                         'sw'  => $SW,
133                                         'sel' => $sel
134                                 );
135                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
136                         }
137                 }
138         }
139         define('__MENU_ROWS', $OUT);
140         define('__CNT_VALUE', $cnt);
141
142         // Load template
143         LOAD_TEMPLATE("admin_mmenu_delete");
144 }
145  elseif ((isset($_POST['status'])) && ($chk > 0) && (!IS_DEMO()))
146 {
147         // Change status (visible / locked)
148         define('__SUB_VALUE', $SUB);
149         define('__CHK_VALUE', $chk);
150         $SW = 2; $cnt = 0; $OUT = "";
151         foreach ($_POST['sel'] as $sel => $confirm)
152         {
153                 if ($confirm == 1)
154                 {
155                         $cnt++;
156                         $result = SQL_QUERY_ESC("SELECT title, visible, locked FROM `"._MYSQL_PREFIX."_member_menu` WHERE ".$AND." AND id=%s LIMIT 1",
157                          array(bigintval($sel)), __FILE__, __LINE__);
158                         if (SQL_NUMROWS($result) == 1)
159                         {
160                                 // Entry found so we load the stuff...
161                                 list($menu, $vis, $locked) = SQL_FETCHROW($result);
162                                 SQL_FREERESULT($result);
163                                 $content = array(
164                                         'cnt'     => $cnt,
165                                         'menu'    => $menu,
166                                         'sel'     => $sel,
167                                         'sw'      => $SW,
168                                         'visible' => ADD_SELECTION("yn", $vis   , "visible", $sel),
169                                         'locked'  => ADD_SELECTION("yn", $locked, "locked" , $sel),
170                                 );
171
172                                 // Load template
173                                 $OUT .= LOAD_TEMPLATE("admin_menu_status_row", true, $content);
174                         }
175                          else
176                         {
177                                 // Entry not found?
178                                 $content = array(
179                                         'sw'  => $SW,
180                                         'sel' => $sel
181                                 );
182                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
183                         }
184                         $SW = 3 - $SW;
185                 }
186         }
187         define('__MENU_ROWS', $OUT);
188         define('__CNT_VALUE', $cnt);
189         //
190         LOAD_TEMPLATE("admin_mmenu_status");
191 }
192  elseif ((isset($_POST['ok'])) && (!IS_DEMO()))
193 {
194         // An act is done...
195         foreach ($_POST['sel'] as $sel => $menu)
196         {
197                 $AND = "(what = '' OR what IS NULL)";
198                 $sel = bigintval($sel);
199                 if (!empty($SUB)) $AND = "action='".$SUB."'";
200                 switch ($_POST['ok'])
201                 {
202                 case "edit": // Edit menu
203                         $result = SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_member_menu` SET title='%s', action='%s', what='%s' WHERE ".$AND." AND id=%s LIMIT 1",
204                          array($menu, $_POST['sel_act'][$sel], $_POST['sel_what'][$sel], $sel), __FILE__, __LINE__);
205                         break;
206
207                 case "del": // Delete menu
208                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_member_menu` WHERE ".$AND." AND id=%s LIMIT 1",
209                          array($sel), __FILE__, __LINE__);
210                         break;
211
212                 case "status": // Change status of menus
213                         $result = SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_member_menu` SET visible='%s', locked='%s' WHERE ".$AND." AND id=%s LIMIT 1",
214                          array($_POST['visible'][$sel], $_POST['locked'][$sel], $sel), __FILE__, __LINE__);
215                         break;
216                 }
217                 break;
218         }
219
220         // Load template
221         LOAD_TEMPLATE("admin_settings_saved", false, SAVING_DONE);
222 } else {
223         if ((!empty($_GET['act'])) && (!empty($_GET['tid'])) && (!empty($_GET['fid']))) {
224                 // Init
225                 $tid = ""; $fid = "";
226
227                 // Get IDs
228                 if (!empty($_GET['w'])) {
229                         // Sub menus selected
230                         $result = SQL_QUERY_ESC("SELECT id FROM `"._MYSQL_PREFIX."_member_menu` WHERE action='%s' AND sort='%s' LIMIT 1",
231                          array(bigintval($_GET['act']), bigintval($_GET['tid'])), __FILE__, __LINE__);
232                         list($tid) = SQL_FETCHROW($result);
233                         SQL_FREERESULT($result);
234                         $result = SQL_QUERY_ESC("SELECT id FROM `"._MYSQL_PREFIX."_member_menu` WHERE action='%s' AND sort='%s' LIMIT 1",
235                          array(bigintval($_GET['act']), bigintval($_GET['fid'])), __FILE__, __LINE__);
236                         list($fid) = SQL_FETCHROW($result);
237                         SQL_FREERESULT($result);
238                 } else {
239                         // Main menu selected
240                         $result = SQL_QUERY_ESC("SELECT id FROM `"._MYSQL_PREFIX."_member_menu` WHERE (what='' OR what IS NULL) AND sort='%s' LIMIT 1",
241                          array(bigintval($_GET['tid'])), __FILE__, __LINE__);
242                         list($tid) = SQL_FETCHROW($result);
243                         $result = SQL_QUERY_ESC("SELECT id FROM `"._MYSQL_PREFIX."_member_menu` WHERE (what='' OR what IS NULL) AND sort='%s' LIMIT 1",
244                          array(bigintval($_GET['fid'])), __FILE__, __LINE__);
245                         list($fid) = SQL_FETCHROW($result);
246                 }
247
248                 if ((!empty($tid)) && (!empty($fid))) {
249                         // Sort menu
250                         $result_sort = SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_member_menu` SET sort='%s' WHERE ".$AND." AND id=%s LIMIT 1",
251                          array(bigintval($_GET['tid']), bigintval($fid)), __FILE__, __LINE__);
252                         $result_sort = SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_member_menu` SET sort='%s' WHERE ".$AND." AND id=%s LIMIT 1",
253                          array(bigintval($_GET['fid']), bigintval($tid)), __FILE__, __LINE__);
254                 } // END - -fi
255         }
256
257         if (!empty($SUB))
258         {
259                 // Edit sub menus
260                 $result = SQL_QUERY("SELECT id, action, what, title, sort FROM `"._MYSQL_PREFIX."_member_menu` WHERE ".$AND." AND what != '' AND what IS NOT NULL ORDER BY sort ASC", __FILE__, __LINE__);
261         }
262          else
263         {
264                 // Edit main menus
265                 $result = SQL_QUERY("SELECT id, action, what, title, sort FROM `"._MYSQL_PREFIX."_member_menu` WHERE (what='' OR what IS NULL) ORDER BY sort ASC", __FILE__, __LINE__);
266         }
267         $max = SQL_NUMROWS($result);
268         if ($max > 0)
269         {
270                 // Set sub value
271                 define('__SUB_VALUE', $SUB);
272
273                 $SW = 2; $cnt = 0; $OUT = "";
274                 while (list($id, $act, $wht, $title, $sort) = SQL_FETCHROW($result))
275                 {
276                         $cnt++;
277                         if (($sort == 0) || (($sort == 1) && (!empty($SUB))))
278                         {
279                                 // Is highest position
280                                 $NAVI = "<A href=\"".URL."/modules.php?module=admin&amp;what=memedit&amp;sub=".$SUB."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort+1)."&amp;fid=".$sort."\">".LOWER."</A>";
281                         }
282                          elseif ($cnt == $max)
283                         {
284                                 // Is lowest position
285                                 $NAVI = "<A href=\"".URL."/modules.php?module=admin&amp;what=memedit&amp;sub=".$SUB."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort-1)."&amp;fid=".$sort."\">".HIGHER."</A>";
286                         }
287                          elseif ($sort > 0)
288                         {
289                                 // Anything else between highest and lowest
290                                 $NAVI = "<A href=\"".URL."/modules.php?module=admin&amp;what=memedit&amp;sub=".$SUB."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort-1)."&amp;fid=".$sort."\">".HIGHER."</A>/<A href=\"".URL."/modules.php?module=admin&amp;what=memedit&amp;sub=".$SUB."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort+1)."&amp;fid=".$sort."\">".LOWER."</A>";
291                         }
292                         if (empty($act))   $act   = "&nbsp;";
293                         if (empty($wht))   $wht   = "&nbsp;";
294                         if (empty($title)) $title = "&nbsp;";
295                         $content = array(
296                                 'sw'     => $SW,
297                                 'id'     => $id,
298                                 'action' => $act,
299                                 'what'   => $wht,
300                                 'title'  => $title,
301                                 'navi'   => $NAVI,
302                                 'mode'   => "mem",
303                         );
304                         $OUT .= LOAD_TEMPLATE("admin_menu_overview_row", true, $content);
305                         $SW = 3 - $SW;
306                 }
307
308                 // Free memory
309                 SQL_FREERESULT($result);
310                 define('__MENU_ROWS', $OUT);
311                 LOAD_TEMPLATE("admin_mmenu_overview");
312         }
313          else
314         {
315                 // Menu entries are missing... (???)
316                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_MENUS_FOUND);
317         }
318 }
319
320 //
321 ?>