385600b1392f3405a75d4530ef4c8f59e0398afa
[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 // Check if the admin has entered title and what-php file name...
44 if (((empty($_POST['title'])) || (empty($_POST['menu'])) || (empty($_POST['descr']))) && (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."_admin_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 FROM "._MYSQL_PREFIX."_admin_menu WHERE action='%s' AND what != '' AND what IS NOT NULL ORDER BY sort",
94                          array($value_main), __FILE__, __LINE__);
95                         if (SQL_NUMROWS($result) > 0)
96                         {
97                                 $menus[$value_main] = array();
98                                 $titles[$value_main] = array();
99                                 $below[$value_main] = array();
100                                 // Read menu structure
101                                 while (list($act, $title, $sort) = SQL_FETCHROW($result))
102                                 {
103                                         // Menu actions
104                                         $menus[$value_main][] = $act;
105
106                                         // Menu titles
107                                         $titles[$value_main][] = $title;
108
109                                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
110                                         $below[$value_main][] = $sort + 1;
111                                 }
112
113                                 // Free memory
114                                 SQL_FREERESULT($result);
115
116                                 // Remove double eintries
117                                 $prev = ""; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
118                                 foreach ($menus[$value_main] as $key => $value)
119                                 {
120                                         if ($value == $prev)
121                                         {
122                                                 unset($dmy[$key]);
123                                                 unset($dmy2[$key]);
124                                                 unset($dmy3[$key]);
125                                         }
126                                          else
127                                         {
128                                                 $prev = $value;
129                                         }
130                                 }
131                                 $menus[$value_main] = $dmy; $titles[$value_main] = $dmy2; $below[$value_main] = $dmy3;
132                         }
133                 }
134         }
135         $OUT = "    <SELECT class=\"admin_select\" name=\"sort\" size=\"1\">
136       <OPTION value=\"0\">".IS_FIRST_MENU."</OPTION>\n";
137         foreach ($below as $key => $m)
138         {
139                 if (is_array($m))
140                 {
141                         foreach ($m as $key2 => $m2)
142                         {
143                                 $OUT .= "      <OPTION value=\"".$m2."\">".$titles[$key][$key2];
144                                 foreach ($menus as $k => $v)
145                                 {
146                                         if (($v == $key) && (!is_array($v)))
147                                         {
148                                                 $OUT .= " (".$titles[$k].")";
149                                         }
150                                 }
151                                 $OUT .= "</OPTION>\n";
152                         }
153                 }
154                  else
155                 {
156                         $OUT .= "      <OPTION value=\"".$m."\">".$titles[$key]."</OPTION>\n";
157                 }
158         }
159         $OUT .= "</SELECT>";
160
161         define('__BELOW_SELECTION' , $OUT);
162         define('__WHAT_SELECTION'  , ADMIN_MAKE_MENU_SELECTION("admin", "what", "name"));
163         define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION("admin", "action", "menu"));
164
165         // Display form
166         LOAD_TEMPLATE("admin_admin_add");
167 }
168  elseif (!IS_DEMO())
169 {
170         // Insert new menu entry
171         if (!empty($_POST['menu']))
172         {
173                 // Add sub menu
174                 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort)
175 VALUES('%s', '%s', '%s', '%s', '%s')",
176  array(
177         $_POST['menu'],
178         $_POST['name'],
179         $_POST['title'],
180         addslashes($_POST['descr']),
181         bigintval($_POST['sort']),
182 ), __FILE__, __LINE__);
183         }
184          else
185         {
186                 // Add main menu
187                 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, title, descr, sort)
188 VALUES('%s', '%s', '%s', '%s')",
189  array(
190         $_POST['name'],
191         $_POST['title'],
192         addslashes($_POST['descr']),
193         bigintval($_POST['sort']),
194 ), __FILE__, __LINE__);
195         }
196         LOAD_TEMPLATE("admin_settings_saved", false, SAVING_DONE);
197 }
198  else
199 {
200         // Is demo login!
201         LOAD_TEMPLATE("admin_settings_saved", false, SETTINGS_NOT_SAVED);
202 }
203
204 //
205 ?>