branch prepared
[mailer.git] / inc / modules / admin / what-admin_add.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/27/2003 *
4  * ===============                              Last change: 12/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-admin_add.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Add more entries to the admin menu               *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Mehr Menueeintraege zum Admin-Bereich 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
43 OPEN_TABLE("100%", "admin_content admin_content_align", "");
44
45 // Check if the admin has entered title and what-php file name...
46 if (((empty($_POST['title'])) || (empty($_POST['menu'])) || (empty($_POST['descr']))) && (isset($_POST['ok'])))
47 {
48         unset($_POST['ok']);
49 }
50
51 if (!isset($_POST['ok']))
52 {
53         // Create arrays
54         $menus = array(); $titles = array(); $below = array();
55
56         // Get all available main menus
57         $result = SQL_QUERY("SELECT action, title, sort FROM "._MYSQL_PREFIX."_admin_menu WHERE what='' ORDER BY sort", __FILE__, __LINE__);
58         if (SQL_NUMROWS($result) > 0)
59         {
60                 // Read menu structure
61                 while (list($act, $title, $sort) = SQL_FETCHROW($result))
62                 {
63                         // Menu actions
64                         $menus[] = $act;
65
66                         // Menu titles
67                         $titles[] = $title;
68
69                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
70                         $below[] = $sort + 1;
71                 }
72
73                 // Free memory
74                 SQL_FREERESULT($result);
75
76                 // Remove double eintries
77                 $prev = ""; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
78                 foreach ($menus as $key=>$value)
79                 {
80                         if ($value == $prev)
81                         {
82                                 unset($dmy[$key]);
83                                 unset($dmy2[$key]);
84                                 unset($dmy3[$key]);
85                         }
86                          else
87                         {
88                                 $prev = $value;
89                         }
90                 }
91                 $menus = $dmy; $titles = $dmy2; $below = $dmy3;
92                 // Load sub menus :)
93                 foreach ($menus as $key_main=>$value_main)
94                 {
95                         $result = SQL_QUERY_ESC("SELECT what, title, sort FROM "._MYSQL_PREFIX."_admin_menu WHERE action='%s' AND what != '' ORDER BY sort",
96                          array($value_main), __FILE__, __LINE__);
97                         if (SQL_NUMROWS($result) > 0)
98                         {
99                                 $menus[$value_main] = array();
100                                 $titles[$value_main] = array();
101                                 $below[$value_main] = array();
102                                 // Read menu structure
103                                 while (list($act, $title, $sort) = SQL_FETCHROW($result))
104                                 {
105                                         // Menu actions
106                                         $menus[$value_main][] = $act;
107
108                                         // Menu titles
109                                         $titles[$value_main][] = $title;
110
111                                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
112                                         $below[$value_main][] = $sort + 1;
113                                 }
114
115                                 // Free memory
116                                 SQL_FREERESULT($result);
117
118                                 // Remove double eintries
119                                 $prev = ""; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
120                                 foreach ($menus[$value_main] as $key=>$value)
121                                 {
122                                         if ($value == $prev)
123                                         {
124                                                 unset($dmy[$key]);
125                                                 unset($dmy2[$key]);
126                                                 unset($dmy3[$key]);
127                                         }
128                                          else
129                                         {
130                                                 $prev = $value;
131                                         }
132                                 }
133                                 $menus[$value_main] = $dmy; $titles[$value_main] = $dmy2; $below[$value_main] = $dmy3;
134                         }
135                 }
136         }
137         $OUT = "    <SELECT class=\"admin_select\" name=\"sort\" size=\"1\">
138       <OPTION value=\"0\">".IS_FIRST_MENU."</OPTION>\n";
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("admin", "what", "name"));
165         define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION("admin", "action", "menu"));
166
167         // Display form
168         LOAD_TEMPLATE("admin_admin_add");
169 }
170  elseif (!IS_DEMO())
171 {
172         // Insert new menu entry
173         if (!empty($_POST['menu']))
174         {
175                 // Add sub menu
176                 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort)
177 VALUES('%s', '%s', '%s', '%s', '%s')",
178  array(
179         $_POST['menu'],
180         $_POST['name'],
181         $_POST['title'],
182         addslashes($_POST['descr']),
183         bigintval($_POST['sort']),
184 ), __FILE__, __LINE__);
185         }
186          else
187         {
188                 // Add main menu
189                 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, title, descr, sort)
190 VALUES('%s', '%s', '%s', '%s')",
191  array(
192         $_POST['name'],
193         $_POST['title'],
194         addslashes($_POST['descr']),
195         bigintval($_POST['sort']),
196 ), __FILE__, __LINE__);
197         }
198         LOAD_TEMPLATE("admin_settings_saved", false, SAVING_DONE);
199 }
200  else
201 {
202         // Is demo login!
203         LOAD_TEMPLATE("admin_settings_saved", false, SETTINGS_NOT_SAVED);
204 }
205 CLOSE_TABLE();
206
207 //
208 ?>