81ce2c312f12e2f2b2cefc647692040381166691
[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 - 2015 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 = sqlQueryEscaped("SELECT `title`, `action`, `what` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
64                                 array(bigintval($sel)), __FILE__, __LINE__);
65                         if (sqlNumRows($result) == 1) {
66                                 // Entry found so we load the stuff...
67                                 $content = sqlFetchArray($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                         sqlFreeResult($result);
88                 } // END - if
89         } // END - foreach
90
91         // Add row content and current counter
92         $content['rows']  = $OUT;
93         $content['chk']   = countPostSelection();
94         $content['sub']   = $subMenu;
95         $content['count'] = $count;
96
97         // Load template
98         loadTemplate('admin_edit_member_menu', FALSE, $content);
99 } elseif ((isFormSent('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
100         // Del menu entries with or without confirmation
101         $content['sub'] = $subMenu;
102         $content['chk'] = countPostSelection();
103         $count = '0'; $OUT = '';
104         foreach (postRequestElement('sel') as $sel => $confirm) {
105                 if ($confirm == 1) {
106                         $count++;
107                         $result = sqlQueryEscaped("SELECT `title` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
108                                 array(bigintval($sel)), __FILE__, __LINE__);
109                         if (sqlNumRows($result) == 1) {
110                                 // Entry found so we load the stuff...
111                                 list($title) = sqlFetchRow($result);
112                                 $content = array(
113                                         'count' => $count,
114                                         'sel'   => $sel,
115                                         'title' => $title
116                                 );
117
118                                 // Load template
119                                 $OUT .= loadTemplate('admin_delete_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                         sqlFreeResult($result);
130                 } // END - if
131         } // END - foreach
132
133         $content['rows']  = $OUT;
134         $content['chk']   = countPostSelection();
135         $content['sub']   = $subMenu;
136         $content['count'] = $count;
137
138         // Load template
139         loadTemplate('admin_delete_member_menu', FALSE, $content);
140 } elseif ((isPostRequestElementSet('status')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
141         // Change status (visible / locked)
142         $content['sub'] = $subMenu;
143         $content['chk'] = countPostSelection();
144         $count = '0'; $OUT = '';
145         foreach (postRequestElement('sel') as $sel => $confirm) {
146                 if ($confirm == 1) {
147                         $count++;
148                         $result = sqlQueryEscaped("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
149                                 array(bigintval($sel)), __FILE__, __LINE__);
150                         if (sqlNumRows($result) == 1) {
151                                 // Entry found so we load the stuff...
152                                 $content = sqlFetchArray($result);
153                                 $content = array(
154                                         'count'   => $count,
155                                         'menu'    => $content['title'],
156                                         'sel'     => $sel,
157                                         'visible' => addSelectionBox('yn', $content['visible'], 'visible', $sel),
158                                         'locked'  => addSelectionBox('yn', $content['locked'] , 'locked' , $sel),
159                                 );
160
161                                 // Load template
162                                 $OUT .= loadTemplate('admin_menu_status_row', TRUE, $content);
163                         } else {
164                                 // Entry not found?
165                                 $content = array(
166                                         'sel' => $sel
167                                 );
168
169                                 // Load template
170                                 $OUT .= loadTemplate('admin_menu_404_row', TRUE, $content);
171                         }
172                         sqlFreeResult($result);
173                 } // END - if
174         } // END - foreach
175
176         $content['rows']  = $OUT;
177         $content['chk']   = countPostSelection();
178         $content['sub']   = $subMenu;
179         $content['count'] = $count;
180
181         // Load template
182         loadTemplate('admin_member_menu_status', FALSE, $content);
183 } elseif ((isFormSent()) && (!isDemoModeActive())) {
184         // Process menu editing form
185         adminProcessMenuEditForm('member', $subMenu);
186 } else {
187         // Handle weightning
188         doAdminProcessMenuWeightning('member', $AND);
189
190         if (!empty($subMenu)) {
191                 // Edit sub menus
192                 $result = sqlQuery("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__);
193         } else {
194                 // Edit main menus
195                 $result = sqlQuery("SELECT `id`, `action`, `what`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
196         }
197
198         // Some are there?
199         if (!ifSqlHasZeroNums($result)) {
200                 $count = '0'; $OUT = '';
201                 while ($content = sqlFetchArray($result)) {
202                         // Set sub value
203                         $content['sub'] = $subMenu;
204
205                         // Init navigation
206                         $content['navi'] = '';
207                         $count++;
208                         if (($content['sort'] == '0') || (($content['sort'] == 1) && (!empty($subMenu)))) {
209                                 // Is highest position
210                                 $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>';
211                         } elseif ($count == sqlNumRows($result)) {
212                                 // Is lowest position
213                                 $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>';
214                         } elseif ($content['sort'] > 0) {
215                                 // Anything else between highest and lowest
216                                 $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>';
217                         }
218
219                         // Add more entries
220                         $content['do'] = 'mem';
221
222                         // Load row template and switch color
223                         $OUT .= loadTemplate('admin_menu_overview_row', TRUE, $content);
224                 } // END - while
225
226                 // Free memory
227                 sqlFreeResult($result);
228
229                 // Remember rows/sub in array
230                 $content['rows'] = $OUT;
231                 $content['sub']  = $subMenu;
232
233                 // Load main template
234                 loadTemplate('admin_member_menu_overview', FALSE, $content);
235         } else {
236                 // Menu entries are missing... (???)
237                 displayMessage('{--ADMIN_NO_MENUS_FOUND--}');
238         }
239 }
240
241 // [EOF]
242 ?>