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