2 /************************************************************************
3 * MXChange v0.2.1 Start: 09/27/2003 *
4 * =============== Last change: 12/13/2004 *
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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
32 ************************************************************************/
34 // Some security stuff...
35 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
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'])))
49 if (!isset($_POST['ok']))
52 $menus = array(); $titles = array(); $below = array();
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)
58 // Read menu structure
59 while (list($act, $title, $sort) = SQL_FETCHROW($result))
67 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
72 SQL_FREERESULT($result);
74 // Remove double eintries
75 $prev = ""; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
76 foreach ($menus as $key => $value)
89 $menus = $dmy; $titles = $dmy2; $below = $dmy3;
91 foreach ($menus as $key_main => $value_main)
93 $result = SQL_QUERY_ESC("SELECT what, title, sort FROM "._MYSQL_PREFIX."_admin_menu WHERE action='%s' AND what != '' ORDER BY sort",
94 array($value_main), __FILE__, __LINE__);
95 if (SQL_NUMROWS($result) > 0)
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))
104 $menus[$value_main][] = $act;
107 $titles[$value_main][] = $title;
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;
114 SQL_FREERESULT($result);
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)
131 $menus[$value_main] = $dmy; $titles[$value_main] = $dmy2; $below[$value_main] = $dmy3;
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)
141 foreach ($m as $key2 => $m2)
143 $OUT .= " <OPTION value=\"".$m2."\">".$titles[$key][$key2];
144 foreach ($menus as $k => $v)
146 if (($v == $key) && (!is_array($v)))
148 $OUT .= " (".$titles[$k].")";
151 $OUT .= "</OPTION>\n";
156 $OUT .= " <OPTION value=\"".$m."\">".$titles[$key]."</OPTION>\n";
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"));
166 LOAD_TEMPLATE("admin_admin_add");
170 // Insert new menu entry
171 if (!empty($_POST['menu']))
174 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort)
175 VALUES('%s', '%s', '%s', '%s', '%s')",
180 addslashes($_POST['descr']),
181 bigintval($_POST['sort']),
182 ), __FILE__, __LINE__);
187 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, title, descr, sort)
188 VALUES('%s', '%s', '%s', '%s')",
192 addslashes($_POST['descr']),
193 bigintval($_POST['sort']),
194 ), __FILE__, __LINE__);
196 LOAD_TEMPLATE("admin_settings_saved", false, SAVING_DONE);
201 LOAD_TEMPLATE("admin_settings_saved", false, SETTINGS_NOT_SAVED);