Naming convention further applied, TODOs.txt updated
[mailer.git] / inc / modules / admin / what-guest_add.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-guest_add.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Add a new guest menu                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Einen neuen Gastmenuepunkt einfuegen             *
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 // Check if the admin has entered title and what-php file name...
49 if (((!isPostRequestParameterSet('title')) || (!isPostRequestParameterSet('menu'))) && (isFormSent())) {
50         // Abort adding the menu entry
51         unsetPostRequestParameter('ok');
52 } // END - if
53
54 if (!isFormSent()) {
55         // Create arrays
56         $menus = array(); $titles = array(); $below = array();
57
58         // Get all available main menus
59         $result_menu = SQL_QUERY("SELECT
60         `action`, `title`, `sort`
61 FROM
62         `{?_MYSQL_PREFIX?}_guest_menu`
63 WHERE
64         (`what`='' OR `what` IS NULL)
65 ORDER BY
66         `sort` ASC", __FILE__, __LINE__);
67         if (!SQL_HASZERONUMS($result_menu)) {
68                 // Read menu structure
69                 // @TODO Cant this be rewritten?
70                 while ($content = SQL_FETCHARRAY($result_menu)) {
71                         // Menu actions
72                         $menus[] = $content['action'];
73
74                         // Menu titles
75                         $titles[] = $content['title'];
76
77                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
78                         $below[] = $content['sort'] + 1;
79                 } // END - while
80
81                 // Remove double eintries
82                 // @TODO This can be somehow rewritten to a function
83                 $prev = ''; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
84                 foreach ($menus as $key => $value) {
85                         if ($value == $prev) {
86                                 unset($dmy[$key]);
87                                 unset($dmy2[$key]);
88                                 unset($dmy3[$key]);
89                         } else {
90                                 $prev = $value;
91                         }
92                 }
93
94                 // Init variables
95                 $menus  = $dmy;
96                 $titles = $dmy2;
97                 $below  = $dmy3;
98
99                 // Load sub menus :)
100                 foreach ($menus as $key_main => $value_main) {
101                         // Query for sub menus
102                         $result = SQL_QUERY_ESC("SELECT
103         `what`, `title`, `sort`
104 FROM
105         `{?_MYSQL_PREFIX?}_guest_menu`
106 WHERE
107         `action`='%s' AND
108         `what` != '' AND
109         `what` IS NOT NULL
110 ORDER BY `sort` ASC",
111                                 array($value_main), __FILE__, __LINE__);
112                         if (!SQL_HASZERONUMS($result)) {
113                                 // Initialize arrays
114                                 $menus[$value_main] = array();
115                                 $titles[$value_main] = array();
116                                 $below[$value_main] = array();
117
118                                 // Read menu structure
119                                 while ($content = SQL_FETCHARRAY($result)) {
120                                         // Menu actions
121                                         $menus[$value_main][] = $content['what'];
122
123                                         // Menu titles
124                                         $titles[$value_main][] = $content['title'];
125
126                                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
127                                         $below[$value_main][] = $content['sort'] + 1;
128                                 } // END - while
129
130                                 // Remove double eintries
131                                 // @TODO This can be somehow rewritten to a function
132                                 $prev = ''; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
133                                 foreach ($menus[$value_main] as $key => $value) {
134                                         if ($value == $prev) {
135                                                 unset($dmy[$key]);
136                                                 unset($dmy2[$key]);
137                                                 unset($dmy3[$key]);
138                                         } else {
139                                                 $prev = $value;
140                                         }
141                                 } // END - foreach
142
143                                 // Transfer dummy array
144                                 $menus[$value_main] = $dmy;
145                                 $titles[$value_main] = $dmy2;
146                                 $below[$value_main] = $dmy3;
147                         } // END - if
148
149                         // Free memory
150                         SQL_FREERESULT($result);
151                 } // END - foreach
152         } // END - if
153
154         // Free memory
155         SQL_FREERESULT($result_menu);
156
157         $OUT = '<select class="admin_select" name="sort" size="1">
158       <option value="0">{--IS_FIRST_MENU--}</option>';
159         foreach ($below as $key => $m) {
160                 if (is_array($m)) {
161                         foreach ($m as $key2 => $m2) {
162                                 $OUT .= '<option value="' . $m2 . '">' . $titles[$key][$key2];
163                                 foreach ($menus as $k => $v) {
164                                         if (($v == $key) && (!is_array($v))) {
165                                                 $OUT .= ' (' . $titles[$k] . ')';
166                                         }
167                                 }
168                                 $OUT .= '</option>';
169                         }
170                 } else {
171                         $OUT .= '<option value="' . $m . '">' . $titles[$key] . '</option>';
172                 }
173         }
174         $OUT .= '</select>';
175
176         // Prepare selections for template
177         $content['below_selection']  = $OUT;
178         $content['what_selection']   = adminAddMenuSelectionBox('guest', 'what'  , 'name');
179         $content['action_selection'] = adminAddMenuSelectionBox('guest', 'action', 'menu');
180
181         // Display form
182         loadTemplate('admin_add_guest_menu', false, $content);
183 } elseif (!isDemoModeActive()) {
184         // Insert new menu entry
185         if (isPostRequestParameterSet('menu')) {
186                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`sort`,`visible`,`locked`) VALUES ('%s','%s','%s','%s','%s','%s')",
187                         array(
188                                 postRequestParameter('menu'),
189                                 postRequestParameter('name'),
190                                 postRequestParameter('title'),
191                                 bigintval(postRequestParameter('sort')),
192                                 postRequestParameter('visible'),
193                                 postRequestParameter('active'),
194                         ), __FILE__, __LINE__);
195         } else {
196                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`, `title`, `sort`, `visible`, `locked`) VALUES ('%s','%s','%s','%s','%s')",
197                         array(
198                                 postRequestParameter('name'),
199                                 postRequestParameter('title'),
200                                 bigintval(postRequestParameter('sort')),
201                                 postRequestParameter('visible'),
202                                 postRequestParameter('active'),
203                         ), __FILE__, __LINE__);
204         }
205         loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}');
206 } else {
207         // Demo mode!
208         loadTemplate('admin_settings_saved', false, '{--SETTINGS_NOT_SAVED--}');
209 }
210
211 // [EOF]
212 ?>