Fix in CREATE_EXTENSION_DEACTIVATION_TASK() and coding-style updated
[mailer.git] / inc / modules / admin / what-guest_add.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 // Check if the admin has entered title and what-php file name...
44 if (((empty($_POST['title'])) || (empty($_POST['menu']))) && (isset($_POST['ok'])))
45 {
46         unset($_POST['ok']);
47 }
48
49 if (!isset($_POST['ok']))
50 {
51         // Create arrays
52         $menus = array(); $titles = array(); $below = array();
53
54         // Get all available main menus
55         $result = SQL_QUERY("SELECT action, title, sort FROM `"._MYSQL_PREFIX."_guest_menu` WHERE (what='' OR what IS NULL) ORDER BY sort", __FILE__, __LINE__);
56         if (SQL_NUMROWS($result) > 0)
57         {
58                 // Read menu structure
59                 while (list($act, $title, $sort) = SQL_FETCHROW($result))
60                 {
61                         // Menu actions
62                         $menus[] = $act;
63
64                         // Menu titles
65                         $titles[] = $title;
66
67                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
68                         $below[] = $sort + 1;
69                 }
70
71                 // Free memory
72                 SQL_FREERESULT($result);
73
74                 // Remove double eintries
75                 $prev = ""; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
76                 foreach ($menus as $key => $value)
77                 {
78                         if ($value == $prev)
79                         {
80                                 unset($dmy[$key]);
81                                 unset($dmy2[$key]);
82                                 unset($dmy3[$key]);
83                         }
84                          else
85                         {
86                                 $prev = $value;
87                         }
88                 }
89                 $menus = $dmy; $titles = $dmy2; $below = $dmy3;
90                 // Load sub menus :)
91                 foreach ($menus as $key_main => $value_main)
92                 {
93                         $result = SQL_QUERY_ESC("SELECT what, title, sort
94 FROM "._MYSQL_PREFIX."_guest_menu
95 WHERE action='%s' AND what != '' AND what IS NOT NULL ORDER BY sort",
96  array(bigintval($value_main)), __FILE__, __LINE__);
97                         if (SQL_NUMROWS($result) > 0)
98                         {
99                                 // Initialize arrays
100                                 $menus[$value_main] = array();
101                                 $titles[$value_main] = array();
102                                 $below[$value_main] = array();
103
104                                 // Read menu structure
105                                 while (list($act, $title, $sort) = SQL_FETCHROW($result))
106                                 {
107                                         // Menu actions
108                                         $menus[$value_main][] = $act;
109
110                                         // Menu titles
111                                         $titles[$value_main][] = $title;
112
113                                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
114                                         $below[$value_main][] = $sort + 1;
115                                 }
116
117                                 // Free memory
118                                 SQL_FREERESULT($result);
119
120                                 // Remove double eintries
121                                 $prev = ""; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
122                                 foreach ($menus[$value_main] as $key => $value)
123                                 {
124                                         if ($value == $prev)
125                                         {
126                                                 unset($dmy[$key]);
127                                                 unset($dmy2[$key]);
128                                                 unset($dmy3[$key]);
129                                         }
130                                          else
131                                         {
132                                                 $prev = $value;
133                                         }
134                                 }
135                                 $menus[$value_main] = $dmy; $titles[$value_main] = $dmy2; $below[$value_main] = $dmy3;
136                         }
137                 }
138         }
139
140         $OUT = "    <SELECT class=\"admin_select\" name=\"sort\" size=\"1\">
141       <OPTION value=\"0\">".IS_FIRST_MENU."</OPTION>";
142         foreach ($below as $key => $m)
143         {
144                 if (is_array($m))
145                 {
146                         foreach ($m as $key2 => $m2)
147                         {
148                                 $OUT .= "      <OPTION value=\"".$m2."\">".$titles[$key][$key2];
149                                 foreach ($menus as $k => $v)
150                                 {
151                                         if (($v == $key) && (!is_array($v)))
152                                         {
153                                                 $OUT .= " (".$titles[$k].")";
154                                         }
155                                 }
156                                 $OUT .= "</OPTION>\n";
157                         }
158                 }
159                  else
160                 {
161                         $OUT .= "      <OPTION value=\"".$m."\">".$titles[$key]."</OPTION>\n";
162                 }
163         }
164         $OUT .= "</SELECT>";
165
166         define('__BELOW_SELECTION' , $OUT);
167         define('__WHAT_SELECTION'  , ADMIN_MAKE_MENU_SELECTION("guest", "what", "name"));
168         define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION("guest", "action", "menu"));
169
170         // Display form
171         LOAD_TEMPLATE("admin_guest_add");
172 }
173  elseif (!IS_DEMO())
174 {
175         // Insert new menu entry
176         if (!empty($_POST['menu']))
177         {
178                 SQL_QUERY_ESC("INSERT INTO `"._MYSQL_PREFIX."_guest_menu` (`action`,`what`,`title`,`sort`,`visible`,`locked`) VALUES ('%s','%s','%s','%s','%s','%s')",
179  array(
180         $_POST['menu'],
181         $_POST['name'],
182         $_POST['title'],
183         bigintval($_POST['sort']),
184         $_POST['visible'],
185         $_POST['active'],
186 ), __FILE__, __LINE__);
187         }
188          else
189         {
190                 SQL_QUERY_ESC("INSERT INTO `"._MYSQL_PREFIX."_guest_menu` (action, title, sort, visible, locked) VALUES ('%s','%s','%s','%s','%s')",
191  array(
192         $_POST['name'],
193         $_POST['title'],
194         bigintval($_POST['sort']),
195         $_POST['visible'],
196         $_POST['active'],
197 ), __FILE__, __LINE__);
198         }
199         LOAD_TEMPLATE("admin_settings_saved", false, SAVING_DONE);
200 }
201  else
202 {
203         // Demo mode!
204         LOAD_TEMPLATE("admin_settings_saved", false, SETTINGS_NOT_SAVED);
205 }
206
207 //
208 ?>