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