]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-memedit.php
ac894ac23a9de0c5ddfe6b30ef639de221d4825c
[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                 $sel = bigintval($sel);
187                 if (!empty($SUB)) $AND = "`action`='".$SUB."'";
188                 switch (postRequestParameter('ok')) {
189                         case 'edit': // Edit menu
190                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
191                                         array($menu, postRequestParameter('sel_act', $sel), postRequestParameter('sel_what', $sel), $sel), __FILE__, __LINE__);
192                                 break;
193
194                         case 'del': // Delete menu
195                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
196                                         array($sel), __FILE__, __LINE__);
197                                 break;
198
199                         case 'status': // Change status of menus
200                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
201                                         array(postRequestParameter('visible', $sel), postRequestParameter('locked', $sel), $sel), __FILE__, __LINE__);
202                                 break;
203
204                         default: // Unexpected action
205                                 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
206                                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
207                                 break;
208                 } // END - switch
209         } // END - foreach
210
211         // Load template
212         loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
213 } else {
214         if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
215                 // Init
216                 $tid = ''; $fid = '';
217
218                 // Get ids
219                 if (isGetRequestParameterSet('w')) {
220                         // Sub menus selected
221                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
222                                 array(bigintval(getRequestParameter('act')), bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
223                         list($tid) = SQL_FETCHROW($result);
224                         SQL_FREERESULT($result);
225                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
226                                 array(bigintval(getRequestParameter('act')), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
227                         list($fid) = SQL_FETCHROW($result);
228                         SQL_FREERESULT($result);
229                 } else {
230                         // Main menu selected
231                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
232                                 array(bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
233                         list($tid) = SQL_FETCHROW($result);
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('fid'))), __FILE__, __LINE__);
236                         list($fid) = SQL_FETCHROW($result);
237                 }
238
239                 if ((!empty($tid)) && (!empty($fid))) {
240                         // Sort menu
241                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
242                                 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
243                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
244                                 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
245                 } // END - -fi
246         } // END - if
247
248         if (!empty($SUB)) {
249                 // Edit sub menus
250                 $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__);
251         } else {
252                 // Edit main menus
253                 $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__);
254         }
255
256         // Get total menu entries
257         $max = SQL_NUMROWS($result);
258
259         // Some are there?
260         if ($max > 0) {
261                 // Set sub value
262                 $content['sub'] = $SUB;
263
264                 $SW = 2; $cnt = '0'; $OUT = '';
265                 while ($data = SQL_FETCHARRAY($result)) {
266                         // Init navigation
267                         $data['navi'] = '';
268                         $cnt++;
269                         if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
270                                 // Is highest position
271                                 $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>';
272                         } elseif ($cnt == $max) {
273                                 // Is lowest 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'] . '%}">{--HIGHER--}</a>';
275                         } elseif ($data['sort'] > 0) {
276                                 // Anything else between highest and lowest
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>/<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>';
278                         }
279
280                         // Fix empty values for Firefox
281                         if (empty($data['action'])) $data['action'] = '&nbsp;';
282                         if (empty($data['what']))   $data['what']   = '&nbsp;';
283                         if (empty($data['title']))  $data['title']  = '&nbsp;';
284
285                         // Add more entries
286                         $data['sw']   = $SW;
287                         $data['mode'] = 'mem';
288
289                         // Load row template and switch color
290                         $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
291                         $SW = 3 - $SW;
292                 } // END - while
293
294                 // Free memory
295                 SQL_FREERESULT($result);
296
297                 // Remember rows in array
298                 $content['rows'] = $OUT;
299
300                 // Load main template
301                 loadTemplate('admin_mmenu_overview', false, $content);
302         } else {
303                 // Menu entries are missing... (???)
304                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));
305         }
306 }
307
308 // [EOF]
309 ?>