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