Previous fix fixed, a lot constants rewritten (unfinished)
[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         // Abort adding the menu entry
46         unset($_POST['ok']);
47 }
48
49 if (!isset($_POST['ok'])) {
50         // Create arrays
51         $menus = array(); $titles = array(); $below = array();
52
53         // Get all available main menus
54         $result = SQL_QUERY("SELECT action, title, sort FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE (what='' OR `what` IS NULL) ORDER BY `sort`", __FILE__, __LINE__);
55         if (SQL_NUMROWS($result) > 0) {
56                 // Read menu structure
57                 while (list($act, $title, $sort) = SQL_FETCHROW($result)) {
58                         // Menu actions
59                         $menus[] = $act;
60
61                         // Menu titles
62                         $titles[] = $title;
63
64                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
65                         $below[] = $sort + 1;
66                 }
67
68                 // Free memory
69                 SQL_FREERESULT($result);
70
71                 // Remove double eintries
72                 $prev = ""; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
73                 foreach ($menus as $key => $value) {
74                         if ($value == $prev) {
75                                 unset($dmy[$key]);
76                                 unset($dmy2[$key]);
77                                 unset($dmy3[$key]);
78                         } else {
79                                 $prev = $value;
80                         }
81                 }
82
83                 // Init variables
84                 $menus  = $dmy;
85                 $titles = $dmy2;
86                 $below  = $dmy3;
87
88                 // Load sub menus :)
89                 foreach ($menus as $key_main => $value_main) {
90                         $result = SQL_QUERY_ESC("SELECT what, title, sort
91 FROM `{!_MYSQL_PREFIX!}_guest_menu`
92 WHERE action='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort`",
93  array($value_main), __FILE__, __LINE__);
94                         if (SQL_NUMROWS($result) > 0)
95                         {
96                                 // Initialize arrays
97                                 $menus[$value_main] = array();
98                                 $titles[$value_main] = array();
99                                 $below[$value_main] = array();
100
101                                 // Read menu structure
102                                 while (list($act, $title, $sort) = SQL_FETCHROW($result))
103                                 {
104                                         // Menu actions
105                                         $menus[$value_main][] = $act;
106
107                                         // Menu titles
108                                         $titles[$value_main][] = $title;
109
110                                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
111                                         $below[$value_main][] = $sort + 1;
112                                 }
113
114                                 // Free memory
115                                 SQL_FREERESULT($result);
116
117                                 // Remove double eintries
118                                 $prev = ""; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
119                                 foreach ($menus[$value_main] as $key => $value)
120                                 {
121                                         if ($value == $prev)
122                                         {
123                                                 unset($dmy[$key]);
124                                                 unset($dmy2[$key]);
125                                                 unset($dmy3[$key]);
126                                         }
127                                          else
128                                         {
129                                                 $prev = $value;
130                                         }
131                                 }
132                                 $menus[$value_main] = $dmy; $titles[$value_main] = $dmy2; $below[$value_main] = $dmy3;
133                         }
134                 }
135         }
136
137         $OUT = "    <select class=\"admin_select\" name=\"sort\" size=\"1\">
138       <option value=\"0\">".IS_FIRST_MENU."</option>";
139         foreach ($below as $key => $m)
140         {
141                 if (is_array($m))
142                 {
143                         foreach ($m as $key2 => $m2)
144                         {
145                                 $OUT .= "      <option value=\"".$m2."\">".$titles[$key][$key2];
146                                 foreach ($menus as $k => $v)
147                                 {
148                                         if (($v == $key) && (!is_array($v)))
149                                         {
150                                                 $OUT .= " (".$titles[$k].")";
151                                         }
152                                 }
153                                 $OUT .= "</option>\n";
154                         }
155                 }
156                  else
157                 {
158                         $OUT .= "      <option value=\"".$m."\">".$titles[$key]."</option>\n";
159                 }
160         }
161         $OUT .= "</select>";
162
163         define('__BELOW_SELECTION' , $OUT);
164         define('__WHAT_SELECTION'  , ADMIN_MAKE_MENU_SELECTION("guest", "what", "name"));
165         define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION("guest", "action", "menu"));
166
167         // Display form
168         LOAD_TEMPLATE("admin_guest_add");
169 }
170  elseif (!IS_DEMO())
171 {
172         // Insert new menu entry
173         if (!empty($_POST['menu']))
174         {
175                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_guest_menu` (`action`,`what`,`title`,`sort`,`visible`,`locked`) VALUES ('%s','%s','%s','%s','%s','%s')",
176  array(
177         $_POST['menu'],
178         $_POST['name'],
179         $_POST['title'],
180         bigintval($_POST['sort']),
181         $_POST['visible'],
182         $_POST['active'],
183 ), __FILE__, __LINE__);
184         }
185          else
186         {
187                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_guest_menu` (action, title, sort, visible, locked) VALUES ('%s','%s','%s','%s','%s')",
188  array(
189         $_POST['name'],
190         $_POST['title'],
191         bigintval($_POST['sort']),
192         $_POST['visible'],
193         $_POST['active'],
194 ), __FILE__, __LINE__);
195         }
196         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_SAVED'));
197 }
198  else
199 {
200         // Demo mode!
201         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_NOT_SAVED'));
202 }
203
204 //
205 ?>