d89f0f45660a338cdd2dadeadeb6b78a4aa98db9
[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         // Edit menu entries
58         define('__SUB_VALUE', $SUB);
59         define('__CHK_VALUE', $chk);
60         $SW = 2; $cnt = 0; $OUT = "";
61         foreach ($_POST['sel'] as $sel => $confirm) {
62                 if ($confirm == 1) {
63                         $cnt++;
64                         $result = SQL_QUERY_ESC("SELECT title, action, what FROM `{!_MYSQL_PREFIX!}_member_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                                 list($menu, $act, $wht, $descr) = SQL_FETCHROW($result);
69                                 SQL_FREERESULT($result);
70                                 $content = array(
71                                         'cnt'    => $cnt,
72                                         'sel'    => $sel,
73                                         'menu'   => $menu,
74                                         'sw'     => $SW,
75                                         'act'    => ADMIN_MAKE_MENU_SELECTION("member", "act", "sel_act[".$sel."]", $act),
76                                         'what'   => ADMIN_MAKE_MENU_SELECTION("member", "what", "sel_what[".$sel."]", $wht),
77                                 );
78                                 // Load template
79                                 $OUT .= LOAD_TEMPLATE("admin_mmenu_edit_row", true, $content);
80                         } else {
81                                 // Entry not found?
82                                 $content = array(
83                                         'sw'  => $SW,
84                                         'sel' => $sel
85                                 );
86                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
87                         }
88                         $SW = 3 - $SW;
89                 }
90         }
91         define('__MENU_ROWS', $OUT);
92         define('__CNT_VALUE', $cnt);
93
94         // Load template
95         LOAD_TEMPLATE("admin_mmenu_edit");
96 } elseif ((isset($_POST['del'])) && ($chk > 0) && (!IS_DEMO())) {
97         // Del menu entries with or without confirmation
98         define('__SUB_VALUE', $SUB);
99         define('__CHK_VALUE', $chk);
100         $SW = 2; $cnt = 0; $OUT = "";
101         foreach ($_POST['sel'] as $sel => $confirm) {
102                 if ($confirm == 1) {
103                         $cnt++;
104                         $result = SQL_QUERY_ESC("SELECT title FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE ".$AND." AND id=%s LIMIT 1",
105                          array(bigintval($sel)), __FILE__, __LINE__);
106                         if (SQL_NUMROWS($result) == 1)
107                         {
108                                 // Entry found so we load the stuff...
109                                 list($title) = SQL_FETCHROW($result);
110                                 SQL_FREERESULT($result);
111                                 $content = array(
112                                         'cnt'   => $cnt,
113                                         'sel'   => $sel,
114                                         'title' => $title
115                                 );
116                                 $OUT .= LOAD_TEMPLATE("admin_mmenu_delete_row", true, $content);
117                         }
118                          else
119                         {
120                                 // Entry not found?
121                                 $content = array(
122                                         'sw'  => $SW,
123                                         'sel' => $sel
124                                 );
125                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
126                         }
127                 }
128         }
129         define('__MENU_ROWS', $OUT);
130         define('__CNT_VALUE', $cnt);
131
132         // Load template
133         LOAD_TEMPLATE("admin_mmenu_delete");
134 } elseif ((isset($_POST['status'])) && ($chk > 0) && (!IS_DEMO())) {
135         // Change status (visible / locked)
136         define('__SUB_VALUE', $SUB);
137         define('__CHK_VALUE', $chk);
138         $SW = 2; $cnt = 0; $OUT = "";
139         foreach ($_POST['sel'] as $sel => $confirm) {
140                 if ($confirm == 1) {
141                         $cnt++;
142                         $result = SQL_QUERY_ESC("SELECT title, visible, locked FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE ".$AND." AND id=%s LIMIT 1",
143                                 array(bigintval($sel)), __FILE__, __LINE__);
144                         if (SQL_NUMROWS($result) == 1) {
145                                 // Entry found so we load the stuff...
146                                 list($menu, $vis, $locked) = SQL_FETCHROW($result);
147                                 SQL_FREERESULT($result);
148                                 $content = array(
149                                         'cnt'     => $cnt,
150                                         'menu'    => $menu,
151                                         'sel'     => $sel,
152                                         'sw'      => $SW,
153                                         'visible' => ADD_SELECTION("yn", $vis   , "visible", $sel),
154                                         'locked'  => ADD_SELECTION("yn", $locked, "locked" , $sel),
155                                 );
156
157                                 // Load template
158                                 $OUT .= LOAD_TEMPLATE("admin_menu_status_row", true, $content);
159                         }
160                          else
161                         {
162                                 // Entry not found?
163                                 $content = array(
164                                         'sw'  => $SW,
165                                         'sel' => $sel
166                                 );
167                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
168                         }
169                         $SW = 3 - $SW;
170                 }
171         }
172         define('__MENU_ROWS', $OUT);
173         define('__CNT_VALUE', $cnt);
174         //
175         LOAD_TEMPLATE("admin_mmenu_status");
176 } elseif ((isset($_POST['ok'])) && (!IS_DEMO())) {
177         // An act is done...
178         foreach ($_POST['sel'] as $sel => $menu) {
179                 $AND = "(`what` = '' OR `what` IS NULL)";
180                 $sel = bigintval($sel);
181                 if (!empty($SUB)) $AND = "action='".$SUB."'";
182                 switch ($_POST['ok'])
183                 {
184                 case "edit": // Edit menu
185                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET title='%s', action='%s', what='%s' WHERE ".$AND." AND id=%s LIMIT 1",
186                                 array($menu, $_POST['sel_act'][$sel], $_POST['sel_what'][$sel], $sel), __FILE__, __LINE__);
187                         break;
188
189                 case "del": // Delete menu
190                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE ".$AND." AND id=%s LIMIT 1",
191                                 array($sel), __FILE__, __LINE__);
192                         break;
193
194                 case "status": // Change status of menus
195                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
196                                 array($_POST['visible'][$sel], $_POST['locked'][$sel], $sel), __FILE__, __LINE__);
197                         break;
198                 }
199                 break;
200         }
201
202         // Load template
203         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_SAVED'));
204 } else {
205         if ((!empty($_GET['act'])) && (!empty($_GET['tid'])) && (!empty($_GET['fid']))) {
206                 // Init
207                 $tid = ""; $fid = "";
208
209                 // Get IDs
210                 if (!empty($_GET['w'])) {
211                         // Sub menus selected
212                         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE action='%s' AND sort='%s' LIMIT 1",
213                          array(bigintval($_GET['act']), bigintval($_GET['tid'])), __FILE__, __LINE__);
214                         list($tid) = SQL_FETCHROW($result);
215                         SQL_FREERESULT($result);
216                         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE action='%s' AND sort='%s' LIMIT 1",
217                          array(bigintval($_GET['act']), bigintval($_GET['fid'])), __FILE__, __LINE__);
218                         list($fid) = SQL_FETCHROW($result);
219                         SQL_FREERESULT($result);
220                 } else {
221                         // Main menu selected
222                         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE (what='' OR `what` IS NULL) AND sort='%s' LIMIT 1",
223                          array(bigintval($_GET['tid'])), __FILE__, __LINE__);
224                         list($tid) = SQL_FETCHROW($result);
225                         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE (what='' OR `what` IS NULL) AND sort='%s' LIMIT 1",
226                          array(bigintval($_GET['fid'])), __FILE__, __LINE__);
227                         list($fid) = SQL_FETCHROW($result);
228                 }
229
230                 if ((!empty($tid)) && (!empty($fid))) {
231                         // Sort menu
232                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET sort='%s' WHERE ".$AND." AND id=%s LIMIT 1",
233                                 array(bigintval($_GET['tid']), bigintval($fid)), __FILE__, __LINE__);
234                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET sort='%s' WHERE ".$AND." AND id=%s LIMIT 1",
235                                 array(bigintval($_GET['fid']), bigintval($tid)), __FILE__, __LINE__);
236                 } // END - -fi
237         }
238
239         if (!empty($SUB)) {
240                 // Edit sub menus
241                 $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__);
242         } else {
243                 // Edit main menus
244                 $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__);
245         }
246
247         $max = SQL_NUMROWS($result);
248         if ($max > 0) {
249                 // Set sub value
250                 define('__SUB_VALUE', $SUB);
251
252                 $SW = 2; $cnt = 0; $OUT = "";
253                 while (list($id, $act, $wht, $title, $sort) = SQL_FETCHROW($result)) {
254                         $cnt++;
255                         if (($sort == 0) || (($sort == 1) && (!empty($SUB)))) {
256                                 // Is highest position
257                                 $NAVI = "<a href=\"{!URL!}/modules.php?module=admin&amp;what=memedit&amp;sub={!__SUB_VALUE!}&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort+1)."&amp;fid=".$sort."\">{--LOWER--}</a>";
258                         } elseif ($cnt == $max) {
259                                 // Is lowest position
260                                 $NAVI = "<a href=\"{!URL!}/modules.php?module=admin&amp;what=memedit&amp;sub={!__SUB_VALUE!}&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort-1)."&amp;fid=".$sort."\">{--HIGHER--}</a>";
261                         } elseif ($sort > 0) {
262                                 // Anything else between highest and lowest
263                                 $NAVI = "<a href=\"{!URL!}/modules.php?module=admin&amp;what=memedit&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=memedit&amp;sub={!__SUB_VALUE!}&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort+1)."&amp;fid=".$sort."\">{--LOWER--}</a>";
264                         }
265
266                         if (empty($act))   $act   = "&nbsp;";
267                         if (empty($wht))   $wht   = "&nbsp;";
268                         if (empty($title)) $title = "&nbsp;";
269
270                         $content = array(
271                                 'sw'     => $SW,
272                                 'id'     => $id,
273                                 'action' => $act,
274                                 'what'   => $wht,
275                                 'title'  => $title,
276                                 'navi'   => $NAVI,
277                                 'mode'   => "mem",
278                         );
279                         $OUT .= LOAD_TEMPLATE("admin_menu_overview_row", true, $content);
280                         $SW = 3 - $SW;
281                 }
282
283                 // Free memory
284                 SQL_FREERESULT($result);
285                 define('__MENU_ROWS', $OUT);
286                 LOAD_TEMPLATE("admin_mmenu_overview");
287         } else {
288                 // Menu entries are missing... (???)
289                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_NO_MENUS_FOUND'));
290         }
291 }
292
293 //
294 ?>