Huge script change, see http://forum.mxchange.org/topic-458.html for details:
[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 - 2009 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')) || (!isAdmin())) {
41         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 // Do we edit/delete/change main menus or sub menus?
48 $AND = "(`what` = '' OR `what` IS NULL)"; $SUB = '';
49
50 if (isGetRequestElementSet('sub')) {
51         $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", getRequestElement('sub'));
52         $SUB = getRequestElement('sub');
53 } // END - if
54
55 // Get count of (maybe) selected menu points
56 $chk = 0;
57 if (isPostRequestElementSet('sel')) $chk = countPostSelection();
58
59 // List all menu points and make them editable
60 if ((isPostRequestElementSet('edit')) && ($chk > 0) && (!isDemoModeActive())) {
61         // Edit menu entries
62         $content['sub'] = $SUB;
63         $content['chk'] = $chk;
64         $SW = 2; $cnt = 0; $OUT = '';
65         foreach (postRequestElement('sel') as $sel => $confirm) {
66                 if ($confirm == 1) {
67                         $cnt++;
68                         $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
69                                 array(bigintval($sel)), __FILE__, __LINE__);
70                         if (SQL_NUMROWS($result) == 1) {
71                                 // Entry found so we load the stuff...
72                                 $data = SQL_FETCHARRAY($result);
73                                 $data = array(
74                                         'cnt'    => $cnt,
75                                         'sel'    => $sel,
76                                         'menu'   => $data['title'],
77                                         'sw'     => $SW,
78                                         'act'    => adminAddMenuSelectionBox('member', 'act' , 'sel_act['  . $sel . ']', $data['action']),
79                                         'what'   => adminAddMenuSelectionBox('member', 'what', 'sel_what[' . $sel . ']', $data['what']),
80                                 );
81
82                                 // Load template
83                                 $OUT .= loadTemplate('admin_mmenu_edit_row', true, $data);
84                         } else {
85                                 // Entry not found?
86                                 $data = array(
87                                         'sw'  => $SW,
88                                         'sel' => $sel
89                                 );
90
91                                 // Load template
92                                 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
93                         }
94                         SQL_FREERESULT($result);
95                         $SW = 3 - $SW;
96                 }
97         }
98         $content['rows'] = $OUT;
99         $content['cnt'] = $cnt;
100
101         // Load template
102         loadTemplate('admin_mmenu_edit', false, $content);
103 } elseif ((isPostRequestElementSet('del')) && ($chk > 0) && (!isDemoModeActive())) {
104         // Del menu entries with or without confirmation
105         $content['sub'] = $SUB;
106         $content['chk'] = $chk;
107         $SW = 2; $cnt = 0; $OUT = '';
108         foreach (postRequestElement('sel') as $sel => $confirm) {
109                 if ($confirm == 1) {
110                         $cnt++;
111                         $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
112                                 array(bigintval($sel)), __FILE__, __LINE__);
113                         if (SQL_NUMROWS($result) == 1) {
114                                 // Entry found so we load the stuff...
115                                 list($title) = SQL_FETCHROW($result);
116                                 $content = array(
117                                         'cnt'   => $cnt,
118                                         'sel'   => $sel,
119                                         'title' => $title
120                                 );
121
122                                 // Load template
123                                 $OUT .= loadTemplate('admin_mmenu_delete_row', true, $content);
124                         } else {
125                                 // Entry not found?
126                                 $content = array(
127                                         'sw'  => $SW,
128                                         'sel' => $sel
129                                 );
130
131                                 // Load template
132                                 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
133                         }
134                         SQL_FREERESULT($result);
135                 } // END - if
136         } // END - foreach
137         $content['rows'] = $OUT;
138         $content['cnt'] = $cnt;
139
140         // Load template
141         loadTemplate('admin_mmenu_delete', false, $content);
142 } elseif ((isPostRequestElementSet('status')) && ($chk > 0) && (!isDemoModeActive())) {
143         // Change status (visible / locked)
144         $content['sub'] = $SUB;
145         $content['chk'] = $chk;
146         $SW = 2; $cnt = 0; $OUT = '';
147         foreach (postRequestElement('sel') as $sel => $confirm) {
148                 if ($confirm == 1) {
149                         $cnt++;
150                         $result = SQL_QUERY_ESC("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
151                                 array(bigintval($sel)), __FILE__, __LINE__);
152                         if (SQL_NUMROWS($result) == 1) {
153                                 // Entry found so we load the stuff...
154                                 $data = SQL_FETCHARRAY($result);
155                                 $data = array(
156                                         'cnt'     => $cnt,
157                                         'menu'    => $data['title'],
158                                         'sel'     => $sel,
159                                         'sw'      => $SW,
160                                         'visible' => addSelectionBox('yn', $data['visible'], 'visible', $sel),
161                                         'locked'  => addSelectionBox('yn', $data['locked'] , 'locked' , $sel),
162                                 );
163
164                                 // Load template
165                                 $OUT .= loadTemplate('admin_menu_status_row', true, $data);
166                         } else {
167                                 // Entry not found?
168                                 $data = array(
169                                         'sw'  => $SW,
170                                         'sel' => $sel
171                                 );
172
173                                 // Load template
174                                 $OUT .= loadTemplate('admin_menu_404_row', true, $data);
175                         }
176                         SQL_FREERESULT($result);
177                         $SW = 3 - $SW;
178                 } // END - if
179         } // END - foreach
180         $content['rows'] = $OUT;
181         $content['cnt'] = $cnt;
182
183         // Load template
184         loadTemplate('admin_mmenu_status', false, $content);
185 } elseif ((isFormSent()) && (!isDemoModeActive())) {
186         // An act is done...
187         foreach (postRequestElement('sel') as $sel => $menu) {
188                 $AND = "(`what` = '' OR `what` IS NULL)";
189                 $sel = bigintval($sel);
190                 if (!empty($SUB)) $AND = "`action`='".$SUB."'";
191                 switch (postRequestElement('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, postRequestElement('sel_act', $sel), postRequestElement('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(postRequestElement('visible', $sel), postRequestElement('locked', $sel), $sel), __FILE__, __LINE__);
205                                 break;
206                 } // END - switch
207                 break;
208         } // END - foreach
209
210         // Load template
211         loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
212 } else {
213         if ((isGetRequestElementSet('act')) && (isGetRequestElementSet('tid')) && (isGetRequestElementSet('fid'))) {
214                 // Init
215                 $tid = ''; $fid = '';
216
217                 // Get IDs
218                 if (isGetRequestElementSet('w')) {
219                         // Sub menus selected
220                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
221                                 array(bigintval(getRequestElement('act')), bigintval(getRequestElement('tid'))), __FILE__, __LINE__);
222                         list($tid) = SQL_FETCHROW($result);
223                         SQL_FREERESULT($result);
224                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
225                                 array(bigintval(getRequestElement('act')), bigintval(getRequestElement('fid'))), __FILE__, __LINE__);
226                         list($fid) = SQL_FETCHROW($result);
227                         SQL_FREERESULT($result);
228                 } else {
229                         // Main menu selected
230                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
231                                 array(bigintval(getRequestElement('tid'))), __FILE__, __LINE__);
232                         list($tid) = SQL_FETCHROW($result);
233                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
234                                 array(bigintval(getRequestElement('fid'))), __FILE__, __LINE__);
235                         list($fid) = SQL_FETCHROW($result);
236                 }
237
238                 if ((!empty($tid)) && (!empty($fid))) {
239                         // Sort menu
240                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
241                                 array(bigintval(getRequestElement('tid')), bigintval($fid)), __FILE__, __LINE__);
242                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
243                                 array(bigintval(getRequestElement('fid')), bigintval($tid)), __FILE__, __LINE__);
244                 } // END - -fi
245         }
246
247         if (!empty($SUB)) {
248                 // Edit sub menus
249                 $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__);
250         } else {
251                 // Edit main menus
252                 $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__);
253         }
254
255         // Get total menu entries
256         $max = SQL_NUMROWS($result);
257
258         // Some are there?
259         if ($max > 0) {
260                 // Set sub value
261                 $content['sub'] = $SUB;
262
263                 $SW = 2; $cnt = 0; $OUT = '';
264                 while ($data = SQL_FETCHARRAY($result)) {
265                         // Init navigation
266                         $data['navi'] = '';
267                         $cnt++;
268                         if (($data['sort'] == 0) || (($data['sort'] == 1) && (!empty($SUB)))) {
269                                 // Is highest position
270                                 $data['navi'] = "<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>";
271                         } elseif ($cnt == $max) {
272                                 // Is lowest position
273                                 $data['navi'] = "<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']."\">{--HIGHER--}</a>";
274                         } elseif ($data['sort'] > 0) {
275                                 // Anything else between highest and lowest
276                                 $data['navi'] = "<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']."\">{--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>";
277                         }
278
279                         // Fix empty values for Firefox
280                         if (empty($data['action'])) $data['action'] = '&nbsp;';
281                         if (empty($data['what']))   $data['what']   = '&nbsp;';
282                         if (empty($data['title']))  $data['title']  = '&nbsp;';
283
284                         // Add more entries
285                         $data['sw']   = $SW;
286                         $data['mode'] = 'mem';
287
288                         // Load row template and switch color
289                         $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
290                         $SW = 3 - $SW;
291                 }
292
293                 // Free memory
294                 SQL_FREERESULT($result);
295
296                 // Remember rows in array
297                 $content['rows'] = $OUT;
298
299                 // Load main template
300                 loadTemplate('admin_mmenu_overview', false, $content);
301         } else {
302                 // Menu entries are missing... (???)
303                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));
304         }
305 }
306
307 // [EOF]
308 ?>