www is out-dated
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 // Do we edit/delete/change main menus or sub menus?
47 $AND = "(`what` = '' OR `what` IS NULL)"; $subMenu = '';
48
49 if (isGetRequestElementSet('sub')) {
50         $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", getRequestElement('sub'));
51         $subMenu = getRequestElement('sub');
52 } // END - if
53
54 // List all menu points and make them editable
55 if ((isFormSent('edit')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
56         // Edit menu entries
57         $content['sub'] = $subMenu;
58         $content['chk'] = countPostSelection();
59         $count = '0'; $OUT = '';
60         foreach (postRequestElement('sel') as $sel => $confirm) {
61                 if ($confirm == 1) {
62                         $count++;
63                         $result = SQL_QUERY_ESC("SELECT `title`,`action`,`what` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
64                                 array(bigintval($sel)), __FILE__, __LINE__);
65                         if (SQL_NUMROWS($result) == 1) {
66                                 // Entry found so we load the stuff...
67                                 $content = SQL_FETCHARRAY($result);
68                                 $content = array(
69                                         'count'  => $count,
70                                         'sel'    => $sel,
71                                         'menu'   => $content['title'],
72                                         'action' => adminAddMenuSelectionBox('member', 'action', 'sel_action[' . $sel . ']', $content['action']),
73                                         'what'   => adminAddMenuSelectionBox('member', 'what'  , 'sel_what[' . $sel . ']', $content['what']),
74                                 );
75
76                                 // Load template
77                                 $OUT .= loadTemplate('admin_edit_member_menu_row', true, $content);
78                         } else {
79                                 // Entry not found?
80                                 $content = array(
81                                         'sel' => $sel
82                                 );
83
84                                 // Load template
85                                 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
86                         }
87                         SQL_FREERESULT($result);
88                 } // END - if
89         } // END - foreach
90
91         // Add row content and current counter
92         $content['rows'] = $OUT;
93         $content['count'] = $count;
94
95         // Load template
96         loadTemplate('admin_edit_member_menu', false, $content);
97 } elseif ((isFormSent('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
98         // Del menu entries with or without confirmation
99         $content['sub'] = $subMenu;
100         $content['chk'] = countPostSelection();
101         $count = '0'; $OUT = '';
102         foreach (postRequestElement('sel') as $sel => $confirm) {
103                 if ($confirm == 1) {
104                         $count++;
105                         $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
106                                 array(bigintval($sel)), __FILE__, __LINE__);
107                         if (SQL_NUMROWS($result) == 1) {
108                                 // Entry found so we load the stuff...
109                                 list($title) = SQL_FETCHROW($result);
110                                 $content = array(
111                                         'count' => $count,
112                                         'sel'   => $sel,
113                                         'title' => $title
114                                 );
115
116                                 // Load template
117                                 $OUT .= loadTemplate('admin_delete_member_menu_row', true, $content);
118                         } else {
119                                 // Entry not found?
120                                 $content = array(
121                                         'sel' => $sel
122                                 );
123
124                                 // Load template
125                                 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
126                         }
127                         SQL_FREERESULT($result);
128                 } // END - if
129         } // END - foreach
130
131         $content['rows']  = $OUT;
132         $content['chk']   = countPostSelection();
133         $content['sub']   = $subMenu;
134         $content['count'] = $count;
135
136         // Load template
137         loadTemplate('admin_delete_member_menu', false, $content);
138 } elseif ((isPostRequestElementSet('status')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
139         // Change status (visible / locked)
140         $content['sub'] = $subMenu;
141         $content['chk'] = countPostSelection();
142         $count = '0'; $OUT = '';
143         foreach (postRequestElement('sel') as $sel => $confirm) {
144                 if ($confirm == 1) {
145                         $count++;
146                         $result = SQL_QUERY_ESC("SELECT `title`,`visible`,`locked` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
147                                 array(bigintval($sel)), __FILE__, __LINE__);
148                         if (SQL_NUMROWS($result) == 1) {
149                                 // Entry found so we load the stuff...
150                                 $content = SQL_FETCHARRAY($result);
151                                 $content = array(
152                                         'count'   => $count,
153                                         'menu'    => $content['title'],
154                                         'sel'     => $sel,
155                                         'visible' => addSelectionBox('yn', $content['visible'], 'visible', $sel),
156                                         'locked'  => addSelectionBox('yn', $content['locked'] , 'locked' , $sel),
157                                 );
158
159                                 // Load template
160                                 $OUT .= loadTemplate('admin_menu_status_row', true, $content);
161                         } else {
162                                 // Entry not found?
163                                 $content = array(
164                                         'sel' => $sel
165                                 );
166
167                                 // Load template
168                                 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
169                         }
170                         SQL_FREERESULT($result);
171                 } // END - if
172         } // END - foreach
173
174         $content['rows']  = $OUT;
175         $content['chk']   = countPostSelection();
176         $content['sub']   = $subMenu;
177         $content['count'] = $count;
178
179         // Load template
180         loadTemplate('admin_member_menu_status', false, $content);
181 } elseif ((isFormSent()) && (!isDemoModeActive())) {
182         // Process menu editing form
183         adminProcessMenuEditForm('member', $subMenu);
184 } else {
185         // Handle weightning
186         doAdminProcessMenuWeightning('member', $AND);
187
188         if (!empty($subMenu)) {
189                 // Edit sub menus
190                 $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__);
191         } else {
192                 // Edit main menus
193                 $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__);
194         }
195
196         // Some are there?
197         if (!SQL_HASZERONUMS($result)) {
198                 $count = '0'; $OUT = '';
199                 while ($content = SQL_FETCHARRAY($result)) {
200                         // Set sub value
201                         $content['sub'] = $subMenu;
202
203                         // Init navigation
204                         $content['navi'] = '';
205                         $count++;
206                         if (($content['sort'] == '0') || (($content['sort'] == 1) && (!empty($subMenu)))) {
207                                 // Is highest position
208                                 $content['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=memedit&amp;sub=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']+1) . '&amp;fid=' . $content['sort'] . '%}">{--LOWER--}</a>';
209                         } elseif ($count == SQL_NUMROWS($result)) {
210                                 // Is lowest position
211                                 $content['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=memedit&amp;sub=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']-1) . '&amp;fid=' . $content['sort'] . '%}">{--HIGHER--}</a>';
212                         } elseif ($content['sort'] > 0) {
213                                 // Anything else between highest and lowest
214                                 $content['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=memedit&amp;sub=' . $content['sub'] . '&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=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']+1) . '&amp;fid=' . $content['sort'] . '%}">{--LOWER--}</a>';
215                         }
216
217                         // Add more entries
218                         $content['mode'] = 'mem';
219
220                         // Load row template and switch color
221                         $OUT .= loadTemplate('admin_menu_overview_row', true, $content);
222                 } // END - while
223
224                 // Free memory
225                 SQL_FREERESULT($result);
226
227                 // Remember rows/sub in array
228                 $content['rows'] = $OUT;
229                 $content['sub']  = $subMenu;
230
231                 // Load main template
232                 loadTemplate('admin_member_menu_overview', false, $content);
233         } else {
234                 // Menu entries are missing... (???)
235                 displayMessage('{--ADMIN_NO_MENUS_FOUND--}');
236         }
237 }
238
239 // [EOF]
240 ?>