More rewrites to make use of (cached) wrapper functions
[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 }
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 = 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)) {
68                 // Read menu structure
69                 // @TODO Cant this be rewritten?
70                 while ($content = SQL_FETCHARRAY($result)) {
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                 // Free memory
82                 SQL_FREERESULT($result);
83
84                 // Remove double eintries
85                 // @TODO This can be somehow rewritten to a function
86                 $prev = ''; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
87                 foreach ($menus as $key => $value) {
88                         if ($value == $prev) {
89                                 unset($dmy[$key]);
90                                 unset($dmy2[$key]);
91                                 unset($dmy3[$key]);
92                         } else {
93                                 $prev = $value;
94                         }
95                 }
96
97                 // Init variables
98                 $menus  = $dmy;
99                 $titles = $dmy2;
100                 $below  = $dmy3;
101
102                 // Load sub menus :)
103                 foreach ($menus as $key_main => $value_main) {
104                         // Query for sub menus
105                         $result = SQL_QUERY_ESC("SELECT
106         `what`, `title`, `sort`
107 FROM
108         `{?_MYSQL_PREFIX?}_guest_menu`
109 WHERE
110         `action`='%s' AND
111         `what` != '' AND
112         `what` IS NOT NULL
113 ORDER BY `sort` ASC",
114                                 array($value_main), __FILE__, __LINE__);
115                         if (!SQL_HASZERONUMS($result)) {
116                                 // Initialize arrays
117                                 $menus[$value_main] = array();
118                                 $titles[$value_main] = array();
119                                 $below[$value_main] = array();
120
121                                 // Read menu structure
122                                 while ($content = SQL_FETCHARRAY($result)) {
123                                         // Menu actions
124                                         $menus[$value_main][] = $content['what'];
125
126                                         // Menu titles
127                                         $titles[$value_main][] = $content['title'];
128
129                                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
130                                         $below[$value_main][] = $content['sort'] + 1;
131                                 }
132
133                                 // Free memory
134                                 SQL_FREERESULT($result);
135
136                                 // Remove double eintries
137                                 // @TODO This can be somehow rewritten to a function
138                                 $prev = ''; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
139                                 foreach ($menus[$value_main] as $key => $value) {
140                                         if ($value == $prev) {
141                                                 unset($dmy[$key]);
142                                                 unset($dmy2[$key]);
143                                                 unset($dmy3[$key]);
144                                         } else {
145                                                 $prev = $value;
146                                         }
147                                 }
148
149                                 // Transfer dummy array
150                                 $menus[$value_main] = $dmy;
151                                 $titles[$value_main] = $dmy2;
152                                 $below[$value_main] = $dmy3;
153                         }
154                 }
155         }
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>\n";
169                         }
170                 } else {
171                         $OUT .= "      <option value=\"".$m."\">".$titles[$key]."</option>\n";
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_guest_add', 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 ?>