Deprecated variables for templates removed, mor EL-rewrites, getMessage() rewritten:
[mailer.git] / inc / modules / admin / what-memedit.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('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 (isGetRequestParameterSet('sub')) {
52         $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", getRequestParameter('sub'));
53         $SUB = getRequestParameter('sub');
54 } // END - if
55
56 // List all menu points and make them editable
57 if ((isFormSent('edit')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
58         // Edit menu entries
59         $content['sub'] = $SUB;
60         $content['chk'] = countPostSelection();
61         $SW = 2; $cnt = '0'; $OUT = '';
62         foreach (postRequestParameter('sel') as $sel => $confirm) {
63                 if ($confirm == 1) {
64                         $cnt++;
65                         $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
66                                 array(bigintval($sel)), __FILE__, __LINE__);
67                         if (SQL_NUMROWS($result) == 1) {
68                                 // Entry found so we load the stuff...
69                                 $data = SQL_FETCHARRAY($result);
70                                 $data = array(
71                                         'cnt'    => $cnt,
72                                         'sel'    => $sel,
73                                         'menu'   => $data['title'],
74                                         'sw'     => $SW,
75                                         'act'    => adminAddMenuSelectionBox('member', 'act' , 'sel_act['  . $sel . ']', $data['action']),
76                                         'what'   => adminAddMenuSelectionBox('member', 'what', 'sel_what[' . $sel . ']', $data['what']),
77                                 );
78
79                                 // Load template
80                                 $OUT .= loadTemplate('admin_mmenu_edit_row', true, $data);
81                         } else {
82                                 // Entry not found?
83                                 $data = array(
84                                         'sw'  => $SW,
85                                         'sel' => $sel
86                                 );
87
88                                 // Load template
89                                 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
90                         }
91                         SQL_FREERESULT($result);
92                         $SW = 3 - $SW;
93                 }
94         }
95         $content['rows'] = $OUT;
96         $content['cnt'] = $cnt;
97
98         // Load template
99         loadTemplate('admin_mmenu_edit', false, $content);
100 } elseif ((isFormSent('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
101         // Del menu entries with or without confirmation
102         $content['sub'] = $SUB;
103         $content['chk'] = countPostSelection();
104         $SW = 2; $cnt = '0'; $OUT = '';
105         foreach (postRequestParameter('sel') as $sel => $confirm) {
106                 if ($confirm == 1) {
107                         $cnt++;
108                         $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
109                                 array(bigintval($sel)), __FILE__, __LINE__);
110                         if (SQL_NUMROWS($result) == 1) {
111                                 // Entry found so we load the stuff...
112                                 list($title) = SQL_FETCHROW($result);
113                                 $content = array(
114                                         'cnt'   => $cnt,
115                                         'sel'   => $sel,
116                                         'title' => $title
117                                 );
118
119                                 // Load template
120                                 $OUT .= loadTemplate('admin_mmenu_delete_row', true, $content);
121                         } else {
122                                 // Entry not found?
123                                 $content = array(
124                                         'sw'  => $SW,
125                                         'sel' => $sel
126                                 );
127
128                                 // Load template
129                                 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
130                         }
131                         SQL_FREERESULT($result);
132                 } // END - if
133         } // END - foreach
134         $content['rows'] = $OUT;
135         $content['cnt'] = $cnt;
136
137         // Load template
138         loadTemplate('admin_mmenu_delete', false, $content);
139 } elseif ((isPostRequestParameterSet('status')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
140         // Change status (visible / locked)
141         $content['sub'] = $SUB;
142         $content['chk'] = countPostSelection();
143         $SW = 2; $cnt = '0'; $OUT = '';
144         foreach (postRequestParameter('sel') as $sel => $confirm) {
145                 if ($confirm == 1) {
146                         $cnt++;
147                         $result = SQL_QUERY_ESC("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
148                                 array(bigintval($sel)), __FILE__, __LINE__);
149                         if (SQL_NUMROWS($result) == 1) {
150                                 // Entry found so we load the stuff...
151                                 $data = SQL_FETCHARRAY($result);
152                                 $data = array(
153                                         'cnt'     => $cnt,
154                                         'menu'    => $data['title'],
155                                         'sel'     => $sel,
156                                         'sw'      => $SW,
157                                         'visible' => addSelectionBox('yn', $data['visible'], 'visible', $sel),
158                                         'locked'  => addSelectionBox('yn', $data['locked'] , 'locked' , $sel),
159                                 );
160
161                                 // Load template
162                                 $OUT .= loadTemplate('admin_menu_status_row', true, $data);
163                         } else {
164                                 // Entry not found?
165                                 $data = array(
166                                         'sw'  => $SW,
167                                         'sel' => $sel
168                                 );
169
170                                 // Load template
171                                 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
172                         }
173                         SQL_FREERESULT($result);
174                         $SW = 3 - $SW;
175                 } // END - if
176         } // END - foreach
177         $content['rows'] = $OUT;
178         $content['cnt'] = $cnt;
179
180         // Load template
181         loadTemplate('admin_mmenu_status', false, $content);
182 } elseif ((isFormSent()) && (!isDemoModeActive())) {
183         // An act is done...
184         foreach (postRequestParameter('sel') as $sel => $menu) {
185                 $AND = "(`what` = '' OR `what` IS NULL)";
186
187                 $sel = bigintval($sel);
188
189                 if (!empty($SUB)) $AND = "`action`='" . $SUB . "'";
190
191                 switch (postRequestParameter('ok')) {
192                         case 'edit': // Edit menu
193                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
194                                         array($menu, postRequestParameter('sel_act', $sel), postRequestParameter('sel_what', $sel), $sel), __FILE__, __LINE__);
195                                 break;
196
197                         case 'del': // Delete menu
198                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
199                                         array($sel), __FILE__, __LINE__);
200                                 break;
201
202                         case 'status': // Change status of menus
203                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
204                                         array(postRequestParameter('visible', $sel), postRequestParameter('locked', $sel), $sel), __FILE__, __LINE__);
205                                 break;
206
207                         default: // Unexpected action
208                                 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
209                                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
210                                 break;
211                 } // END - switch
212         } // END - foreach
213
214         // Load template
215         loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
216 } else {
217         if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
218                 // Init
219                 $tid = ''; $fid = '';
220
221                 // Get ids
222                 if (isGetRequestParameterSet('w')) {
223                         // Sub menus selected
224                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
225                                 array(bigintval(getRequestParameter('act')), bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
226                         list($tid) = SQL_FETCHROW($result);
227                         SQL_FREERESULT($result);
228                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
229                                 array(bigintval(getRequestParameter('act')), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
230                         list($fid) = SQL_FETCHROW($result);
231                         SQL_FREERESULT($result);
232                 } else {
233                         // Main menu selected
234                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
235                                 array(bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
236                         list($tid) = SQL_FETCHROW($result);
237                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
238                                 array(bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
239                         list($fid) = SQL_FETCHROW($result);
240                 }
241
242                 if ((!empty($tid)) && (!empty($fid))) {
243                         // Sort menu
244                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
245                                 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
246                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
247                                 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
248                 } // END - -fi
249         } // END - if
250
251         if (!empty($SUB)) {
252                 // Edit sub menus
253                 $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__);
254         } else {
255                 // Edit main menus
256                 $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__);
257         }
258
259         // Get total menu entries
260         $max = SQL_NUMROWS($result);
261
262         // Some are there?
263         if ($max > 0) {
264                 // Set sub value
265                 $content['sub'] = $SUB;
266
267                 $SW = 2; $cnt = '0'; $OUT = '';
268                 while ($data = SQL_FETCHARRAY($result)) {
269                         // Init navigation
270                         $data['navi'] = '';
271                         $cnt++;
272                         if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
273                                 // Is highest position
274                                 $data['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']+1) . '&amp;fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
275                         } elseif ($cnt == $max) {
276                                 // Is lowest position
277                                 $data['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']-1) . '&amp;fid=' . $data['sort'] . '%}">{--HIGHER--}</a>';
278                         } elseif ($data['sort'] > 0) {
279                                 // Anything else between highest and lowest
280                                 $data['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']-1) . '&amp;fid=' . $data['sort'] . '%}">{--HIGHER--}</a>/<a href="{%url=modules.php?module=admin&amp;what=memedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']+1) . '&amp;fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
281                         }
282
283                         // Fix empty values for Firefox
284                         if (empty($data['action'])) $data['action'] = '&nbsp;';
285                         if (empty($data['what']))   $data['what']   = '&nbsp;';
286                         if (empty($data['title']))  $data['title']  = '&nbsp;';
287
288                         // Add more entries
289                         $data['sw']   = $SW;
290                         $data['mode'] = 'mem';
291
292                         // Load row template and switch color
293                         $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
294                         $SW = 3 - $SW;
295                 } // END - while
296
297                 // Free memory
298                 SQL_FREERESULT($result);
299
300                 // Remember rows in array
301                 $content['rows'] = $OUT;
302
303                 // Load main template
304                 loadTemplate('admin_mmenu_overview', false, $content);
305         } else {
306                 // Menu entries are missing... (???)
307                 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MENUS_FOUND--}');
308         }
309 }
310
311 // [EOF]
312 ?>