]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-memedit.php
d3c27d7c0fc949cca03d7c055df3f8542eab5242
[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')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
58         // Edit menu entries
59         $content['sub'] = $SUB;
60         $content['chk'] = countPostSelection();
61         $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                                         'act'    => adminAddMenuSelectionBox('member', 'act' , 'sel_act['  . $sel . ']', $data['action']),
75                                         'what'   => adminAddMenuSelectionBox('member', 'what', 'sel_what[' . $sel . ']', $data['what']),
76                                 );
77
78                                 // Load template
79                                 $OUT .= loadTemplate('form_submit_member_menu_row', true, $data);
80                         } else {
81                                 // Entry not found?
82                                 $data = array(
83                                         'sel' => $sel
84                                 );
85
86                                 // Load template
87                                 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
88                         }
89                         SQL_FREERESULT($result);
90                 } // END - if
91         } // END - foreach
92
93         // Add row content and current counter
94         $content['rows'] = $OUT;
95         $content['cnt'] = $cnt;
96
97         // Load template
98         loadTemplate('form_submit_member_menu', false, $content);
99 } elseif ((isFormSent('del')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
100         // Del menu entries with or without confirmation
101         $content['sub'] = $SUB;
102         $content['chk'] = countPostSelection();
103         $cnt = '0'; $OUT = '';
104         foreach (postRequestParameter('sel') as $sel => $confirm) {
105                 if ($confirm == 1) {
106                         $cnt++;
107                         $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
108                                 array(bigintval($sel)), __FILE__, __LINE__);
109                         if (SQL_NUMROWS($result) == 1) {
110                                 // Entry found so we load the stuff...
111                                 list($title) = SQL_FETCHROW($result);
112                                 $content = array(
113                                         'cnt'   => $cnt,
114                                         'sel'   => $sel,
115                                         'title' => $title
116                                 );
117
118                                 // Load template
119                                 $OUT .= loadTemplate('admin_del_member_menu_row', true, $content);
120                         } else {
121                                 // Entry not found?
122                                 $content = array(
123                                         'sel' => $sel
124                                 );
125
126                                 // Load template
127                                 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
128                         }
129                         SQL_FREERESULT($result);
130                 } // END - if
131         } // END - foreach
132         $content['rows'] = $OUT;
133         $content['cnt'] = $cnt;
134
135         // Load template
136         loadTemplate('admin_del_member_menu', false, $content);
137 } elseif ((isPostRequestParameterSet('status')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
138         // Change status (visible / locked)
139         $content['sub'] = $SUB;
140         $content['chk'] = countPostSelection();
141         $cnt = '0'; $OUT = '';
142         foreach (postRequestParameter('sel') as $sel => $confirm) {
143                 if ($confirm == 1) {
144                         $cnt++;
145                         $result = SQL_QUERY_ESC("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
146                                 array(bigintval($sel)), __FILE__, __LINE__);
147                         if (SQL_NUMROWS($result) == 1) {
148                                 // Entry found so we load the stuff...
149                                 $data = SQL_FETCHARRAY($result);
150                                 $data = array(
151                                         'cnt'     => $cnt,
152                                         'menu'    => $data['title'],
153                                         'sel'     => $sel,
154                                         'visible' => addSelectionBox('yn', $data['visible'], 'visible', $sel),
155                                         'locked'  => addSelectionBox('yn', $data['locked'] , 'locked' , $sel),
156                                 );
157
158                                 // Load template
159                                 $OUT .= loadTemplate('admin_menu_status_row', true, $data);
160                         } else {
161                                 // Entry not found?
162                                 $data = array(
163                                         'sel' => $sel
164                                 );
165
166                                 // Load template
167                                 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
168                         }
169                         SQL_FREERESULT($result);
170                 } // END - if
171         } // END - foreach
172         $content['rows'] = $OUT;
173         $content['cnt'] = $cnt;
174
175         // Load template
176         loadTemplate('admin_member_menu_status', false, $content);
177 } elseif ((isFormSent()) && (!isDemoModeActive())) {
178         // An act is done...
179         foreach (postRequestParameter('sel') as $sel => $menu) {
180                 $AND = "(`what` = '' OR `what` IS NULL)";
181
182                 $sel = bigintval($sel);
183
184                 if (!empty($SUB)) $AND = "`action`='" . $SUB . "'";
185
186                 switch (postRequestParameter('ok')) {
187                         case 'edit': // Edit menu
188                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
189                                         array($menu, postRequestParameter('sel_act', $sel), postRequestParameter('sel_what', $sel), $sel), __FILE__, __LINE__);
190                                 break;
191
192                         case 'del': // Delete menu
193                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
194                                         array($sel), __FILE__, __LINE__);
195                                 break;
196
197                         case 'status': // Change status of menus
198                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
199                                         array(postRequestParameter('visible', $sel), postRequestParameter('locked', $sel), $sel), __FILE__, __LINE__);
200                                 break;
201
202                         default: // Unexpected action
203                                 logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestParameter('ok')));
204                                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_UNKNOWN_OKAY', postRequestParameter('ok')));
205                                 break;
206                 } // END - switch
207         } // END - foreach
208
209         // Load template
210         loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
211 } else {
212         if ((isGetRequestParameterSet('act')) && (isGetRequestParameterSet('tid')) && (isGetRequestParameterSet('fid'))) {
213                 // Init
214                 $tid = ''; $fid = '';
215
216                 // Get ids
217                 if (isGetRequestParameterSet('w')) {
218                         // Sub menus selected
219                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`=%s LIMIT 1",
220                                 array(bigintval(getRequestParameter('act')), bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
221                         list($tid) = SQL_FETCHROW($result);
222                         SQL_FREERESULT($result);
223                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`=%s LIMIT 1",
224                                 array(bigintval(getRequestParameter('act')), bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
225                         list($fid) = SQL_FETCHROW($result);
226                         SQL_FREERESULT($result);
227                 } else {
228                         // Main menu selected
229                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`=%s LIMIT 1",
230                                 array(bigintval(getRequestParameter('tid'))), __FILE__, __LINE__);
231                         list($tid) = SQL_FETCHROW($result);
232                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`=%s LIMIT 1",
233                                 array(bigintval(getRequestParameter('fid'))), __FILE__, __LINE__);
234                         list($fid) = SQL_FETCHROW($result);
235                 }
236
237                 if ((!empty($tid)) && (!empty($fid))) {
238                         // Sort menu
239                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
240                                 array(bigintval(getRequestParameter('tid')), bigintval($fid)), __FILE__, __LINE__);
241                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
242                                 array(bigintval(getRequestParameter('fid')), bigintval($tid)), __FILE__, __LINE__);
243                 } // END - -fi
244         } // END - if
245
246         if (!empty($SUB)) {
247                 // Edit sub menus
248                 $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__);
249         } else {
250                 // Edit main menus
251                 $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__);
252         }
253
254         // Some are there?
255         if (SQL_NUMROWS($result) > 0) {
256                 // Set sub value
257                 $content['sub'] = $SUB;
258
259                 $cnt = '0'; $OUT = '';
260                 while ($data = SQL_FETCHARRAY($result)) {
261                         // Init navigation
262                         $data['navi'] = '';
263                         $cnt++;
264                         if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
265                                 // Is highest position
266                                 $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>';
267                         } elseif ($cnt == SQL_NUMROWS($result)) {
268                                 // Is lowest position
269                                 $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>';
270                         } elseif ($data['sort'] > 0) {
271                                 // Anything else between highest and lowest
272                                 $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>';
273                         }
274
275                         // Fix empty values for Firefox
276                         if (empty($data['action'])) $data['action'] = '&nbsp;';
277                         if (empty($data['what']))   $data['what']   = '&nbsp;';
278                         if (empty($data['title']))  $data['title']  = '&nbsp;';
279
280                         // Add more entries
281                         $data['mode'] = 'mem';
282
283                         // Load row template and switch color
284                         $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
285                 } // END - while
286
287                 // Free memory
288                 SQL_FREERESULT($result);
289
290                 // Remember rows in array
291                 $content['rows'] = $OUT;
292
293                 // Load main template
294                 loadTemplate('admin_member_menu_overview', false, $content);
295         } else {
296                 // Menu entries are missing... (???)
297                 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MENUS_FOUND--}');
298         }
299 }
300
301 // [EOF]
302 ?>