bca220d8f9b896f0bb57db6612a2a3e23cb1f49f
[mailer.git] / inc / modules / admin / what-guestedit.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 09/28/2003 *
4  * ===================                          Last change: 12/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-guestedit.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Edit guest's menu                                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Menue fuer die Gaeste editieren                  *
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 - 2012 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
60         $count = '0'; $OUT = '';
61         foreach (postRequestElement('sel') as $sel => $confirm) {
62                 if ($confirm == 1) {
63                         $count++;
64                         $result = SQL_QUERY_ESC("SELECT `title`,`action`,`what` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
65                                 array(bigintval($sel)), __FILE__, __LINE__);
66                         if (SQL_NUMROWS($result) == 1) {
67                                 // Entry found so we load the stuff...
68                                 $content = SQL_FETCHARRAY($result);
69
70                                 // Prepapre content
71                                 $content = array(
72                                         'count'  => $count,
73                                         'sel'    => $sel,
74                                         'action' => adminAddMenuSelectionBox('guest', 'action', 'sel_action[' . $sel . ']', $content['action']),
75                                         'what'   => adminAddMenuSelectionBox('guest', 'what'  , 'sel_what['   . $sel . ']', $content['what']),
76                                         'menu'   => $content['title'],
77                                         'sub'    => $subMenu
78                                 );
79
80                                 // Load row template
81                                 $OUT .= loadTemplate('admin_edit_guest_menu_row', true, $content);
82                         } else {
83                                 // Entry not found
84                                 $content = array(
85                                         'sel' => $sel
86                                 );
87                                 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
88                         }
89
90                         // Free result and switch color
91                         SQL_FREERESULT($result);
92                 } // END - if
93         } // END - foreach
94
95         $content['rows']  = $OUT;
96         $content['chk']   = countPostSelection();
97         $content['sub']   = $subMenu;
98         $content['count'] = $count;
99
100         // Load template
101         loadTemplate('admin_edit_guest_menu_form', false, $content);
102 } elseif ((isFormSent('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
103         // Del menu entries with or without confirmation
104         $content['sub'] = $subMenu;
105         $content['chk'] = countPostSelection();
106
107         $count = '0';
108         $OUT = '';
109
110         foreach (postRequestElement('sel') as $sel => $confirm) {
111                 if ($confirm == 1) {
112                         $count++;
113                         $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
114                                 array(bigintval($sel)), __FILE__, __LINE__);
115                         if (SQL_NUMROWS($result) == 1) {
116                                 // Entry found so we load the stuff...
117                                 $content = SQL_FETCHARRAY($result);
118                                 $content = array(
119                                         'count' => $count,
120                                         'menu'  => $content['title'],
121                                         'sel'   => $sel,
122                                 );
123                                 $OUT .= loadTemplate('admin_delete_guest_menu_row', true, $content);
124                         } else {
125                                 // Entry not found?
126                                 $content = array(
127                                         'sel' => $sel
128                                 );
129                                 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
130                         }
131                         SQL_FREERESULT($result);
132                 } // END - if
133         } // END - foreach
134
135         $content['rows']  = $OUT;
136         $content['chk']   = countPostSelection();
137         $content['sub']   = $subMenu;
138         $content['count'] = $count;
139
140         // Load template
141         loadTemplate('admin_delete_guest_menu', false, $content);
142 } elseif ((isPostRequestElementSet('status')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
143         // Change status (visible / locked)
144         $content['sub'] = $subMenu;
145         $content['chk'] = countPostSelection();
146
147         // Load template
148         $count = '0'; $OUT = '';
149         foreach (postRequestElement('sel') as $sel => $confirm) {
150                 if ($confirm == 1) {
151                         $count++;
152                         $result = SQL_QUERY_ESC("SELECT `title`,`visible`,`locked` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
153                                 array(bigintval($sel)), __FILE__, __LINE__);
154                         if (SQL_NUMROWS($result) == 1) {
155                                 // Entry found so we load the stuff...
156                                 $content = SQL_FETCHARRAY($result);
157                                 $content = array(
158                                         'count'   => $count,
159                                         'menu'    => $content['title'],
160                                         'sel'     => $sel,
161                                         'visible' => addSelectionBox('yn', $content['visible'], 'visible', $sel),
162                                         'locked'  => addSelectionBox('yn', $content['locked'] , 'locked' , $sel),
163                                 );
164
165                                 // Load template
166                                 $OUT .= loadTemplate('admin_menu_status_row', true, $content);
167                         } else {
168                                 // Entry not found?
169                                 $content = array(
170                                         'sel' => $sel
171                                 );
172                                 $OUT .= loadTemplate('admin_menu_404_row', true, $content);
173                         }
174
175                         SQL_FREERESULT($result);
176                 } // END - if
177         } // END - foreach
178
179         $content['rows']  = $OUT;
180         $content['chk']   = countPostSelection();
181         $content['sub']   = $subMenu;
182         $content['count'] = $count;
183
184         // Load template
185         loadTemplate('admin_guest_menu_status', false, $content);
186 } elseif ((isFormSent()) && (!isDemoModeActive())) {
187         // An action is done...
188         adminProcessMenuEditForm('guest', $subMenu);
189 } else {
190         // Handle weightning
191         doAdminProcessMenuWeightning('guest', $AND);
192
193         // By default list menus
194         if (empty($subMenu)) {
195                 // List only main menus
196                 $result = SQL_QUERY("SELECT `id`,`action`,`what`,`title`,`sort` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
197         } else {
198                 // List sub menus
199                 $result = SQL_QUERY_ESC("SELECT `id`,`action`,`what`,`title`,`sort` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort` ASC",
200                         array($subMenu), __FILE__, __LINE__);
201         }
202
203         // Do we have entries?
204         if (!SQL_HASZERONUMS($result)) {
205                 // Init variables
206                 $count = '0';
207                 $OUT = '';
208
209                 // Process all menu entries
210                 while ($content = SQL_FETCHARRAY($result)) {
211                         // Set sub value
212                         $content['sub'] = $subMenu;
213
214                         $count++;
215                         if (($content['sort'] == '0') || (($content['sort'] == 1) && (!empty($subMenu)))) {
216                                 // Is highest position
217                                 $NAVI = '<a href="{%url=modules.php?module=admin&amp;what=guestedit&amp;sub=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']+1) . '&amp;fid=' . $content['sort'] . '%}">{--LOWER--}</a>';
218                         } elseif (SQL_NUMROWS($result) == $count) {
219                                 // Is lowest position
220                                 $NAVI = '<a href="{%url=modules.php?module=admin&amp;what=guestedit&amp;sub=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']-1) . '&amp;fid=' . $content['sort'] . '%}">{--HIGHER--}</a>';
221                         } elseif ($content['sort'] > 0) {
222                                 // Anything else between highest and lowest
223                                 $NAVI = '<a href="{%url=modules.php?module=admin&amp;what=guestedit&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=guestedit&amp;sub=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']+1) . '&amp;fid=' . $content['sort'] . '%}">{--LOWER--}</a>';
224                         }
225
226                         // Prepapre content
227                         $content = array(
228                                 'id'     => $content['id'],
229                                 'action' => $content['action'],
230                                 'what'   => $content['what'],
231                                 'title'  => $content['title'],
232                                 'navi'   => $NAVI,
233                                 'do'     => 'guest'
234                         );
235
236                         // Load row template
237                         $OUT .= loadTemplate('admin_menu_overview_row', true, $content);
238                 } // END - while
239
240                 // Add rows/sub
241                 $content['rows'] = $OUT;
242                 $content['sub']  = $subMenu;
243
244                 // Free memory
245                 SQL_FREERESULT($result);
246
247                 // Load template
248                 loadTemplate('admin_edit_guest_menu', false, $content);
249         } else {
250                 // Menu entries are missing... (???)
251                 displayMessage('{--ADMIN_NO_MENUS_FOUND--}');
252         }
253 }
254
255 // [EOF]
256 ?>