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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
48 // Check if the admin has entered title and what-php file name...
49 if (((!REQUEST_ISSET_POST('title')) || (!REQUEST_ISSET_POST(('menu'))) || (!REQUEST_ISSET_POST(('descr')))) && (isFormSent())) {
50 REQUEST_UNSET_POST('ok');
56 $menus = array(); $titles = array(); $below = array();
58 // Get all available main menus
59 $result = SQL_QUERY("SELECT action, title, sort FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort`", __FILE__, __LINE__);
60 if (SQL_NUMROWS($result) > 0) {
61 // Read menu structure
62 // @TODO Cant this be rewritten?
63 while ($content = SQL_FETCHARRAY($result)) {
65 $menus[] = $content['action'];
68 $titles[] = $content['title'];
70 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
71 $below[] = $content['sort'] + 1;
75 SQL_FREERESULT($result);
77 // Remove double eintries
78 // @TODO This can be somehow rewritten to a function
79 $prev = ''; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
80 foreach ($menus as $key => $value) {
81 if ($value == $prev) {
90 // Write dummys back to our array
91 $menus = $dmy; unset($dmy);
92 $titles = $dmy2; unset($dmy2);
93 $below = $dmy3; unset($dmy3);
96 foreach ($menus as $key_main => $value_main) {
97 $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`",
98 array($value_main), __FILE__, __LINE__);
99 if (SQL_NUMROWS($result) > 0) {
101 $menus[$value_main] = array();
102 $titles[$value_main] = array();
103 $below[$value_main] = array();
105 // Read menu structure
106 while ($content = SQL_FETCHARRAY($result)) {
108 $menus[$value_main][] = $content['what'];
111 $titles[$value_main][] = $content['title'];
113 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
114 $below[$value_main][] = $content['sort'] + 1;
118 SQL_FREERESULT($result);
120 // Remove double eintries
121 // @TODO This can be somehow rewritten to a function
122 $prev = ''; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
123 foreach ($menus[$value_main] as $key => $value) {
124 if ($value == $prev) {
132 $menus[$value_main] = $dmy;
133 $titles[$value_main] = $dmy2;
134 $below[$value_main] = $dmy3;
138 $OUT = " <select class=\"admin_select\" name=\"sort\" size=\"1\">
139 <option value=\"0\">".IS_FIRST_MENU."</option>\n";
140 foreach ($below as $key => $m) {
142 foreach ($m as $key2 => $m2) {
143 $OUT .= " <option value=\"".$m2."\">".$titles[$key][$key2];
144 foreach ($menus as $k => $v) {
145 if (($v == $key) && (!is_array($v))) {
146 $OUT .= " (" . $titles[$k] . ')';
149 $OUT .= "</option>\n";
154 $OUT .= " <option value=\"".$m."\">".$titles[$key]."</option>\n";
159 define('__BELOW_SELECTION' , $OUT);
160 define('__WHAT_SELECTION' , ADMIN_MAKE_MENU_SELECTION('admin', 'what', "name"));
161 define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION('admin', 'action', "menu"));
164 LOAD_TEMPLATE("admin_admin_add");
165 } elseif (!IS_DEMO()) {
166 // Insert new menu entry
167 if (REQUEST_ISSET_POST(('menu'))) {
169 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s','%s')",
171 REQUEST_POST('menu'),
172 REQUEST_POST('name'),
173 REQUEST_POST('title'),
174 REQUEST_POST('descr'),
175 bigintval(REQUEST_POST('sort')),
176 ), __FILE__, __LINE__
178 cachePurgeAdminMenu(0, REQUEST_POST('menu'), REQUEST_POST('name'));
181 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (action, title, descr, sort) VALUES ('%s','%s','%s','%s')",
183 REQUEST_POST('name'),
184 REQUEST_POST('title'),
185 REQUEST_POST('descr'),
186 bigintval(REQUEST_POST('sort')),
187 ), __FILE__, __LINE__
189 cachePurgeAdminMenu(0, REQUEST_POST('name'));
191 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
194 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_NOT_SAVED'));