2 /************************************************************************
3 * MXChange v0.2.1 Start: 09/28/2003 *
4 * =============== Last change: 12/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-mem_add.php *
8 * -------------------------------------------------------------------- *
9 * Short desciption : Add new menu for your members *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Fuegen Sie einen weiteren Menuepunkt zum Mit- *
12 * Mitgliedsmenue hinzu *
13 * -------------------------------------------------------------------- *
15 * -------------------------------------------------------------------- *
16 * Copyright (c) 2003 - 2008 by Roland Haeder *
17 * For more information visit: http://www.mxchange.org *
19 * This program is free software; you can redistribute it and/or modify *
20 * it under the terms of the GNU General Public License as published by *
21 * the Free Software Foundation; either version 2 of the License, or *
22 * (at your option) any later version. *
24 * This program is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU General Public License for more details. *
29 * You should have received a copy of the GNU General Public License *
30 * along with this program; if not, write to the Free Software *
31 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
33 ************************************************************************/
35 // Some security stuff...
36 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
41 // Add desciption as navigation point
42 ADD_DESCR("admin", __FILE__);
44 // Check if the admin has entered title and what-php file name...
45 if ((!REQUEST_ISSET_POST(('title'))) && (IS_FORM_SENT())) {
46 REQUEST_UNSET_POST('ok');
49 if (!IS_FORM_SENT()) {
51 $menus = array(); $titles = array(); $below = array();
53 // Get all available main menus
54 $result = SQL_QUERY("SELECT action, title, sort FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE (what='' OR `what` IS NULL) ORDER BY `sort`",
56 if (SQL_NUMROWS($result) > 0) {
57 // Read menu structure
58 while ($content = SQL_FETCHARRAY($result)) {
60 $menus[] = $content['action'];
63 $titles[] = $content['title'];
65 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
66 $below[] = $content['sort'] + 1;
70 SQL_FREERESULT($result);
72 // Remove double eintries
73 // @TODO This can be somehow rewritten to a function
74 $prev = ""; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
75 foreach ($menus as $key => $value) {
76 if ($value == $prev) {
87 $menus = $dmy; $titles = $dmy2; $below = $dmy3;
90 foreach ($menus as $key_main => $value_main) {
91 $result = SQL_QUERY_ESC("SELECT what, title, sort FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE `action`='%s' AND `what` != '' ORDER BY `sort`",
92 array($value_main), __FILE__, __LINE__);
93 if (SQL_NUMROWS($result) > 0) {
95 $menus[$value_main] = array();
96 $titles[$value_main] = array();
97 $below[$value_main] = array();
99 // Read menu structure
100 while ($content = SQL_FETCHARRAY($result)) {
102 $menus[$value_main][] = $content['action'];
105 $titles[$value_main][] = $content['title'];
107 // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
108 $below[$value_main][] = $content['sort'] + 1;
112 SQL_FREERESULT($result);
114 // Remove double eintries
115 // @TODO This can be somehow rewritten to a function
116 $prev = ""; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
117 foreach ($menus[$value_main] as $key => $value) {
118 if ($value == $prev) {
127 // Transfer variables into array
128 $menus[$value_main] = $dmy;
129 $titles[$value_main] = $dmy2;
130 $below[$value_main] = $dmy3;
135 $OUT = "<select class=\"admin_select\" name=\"sort\" size=\"1\">
136 <option value=\"\">{--IS_FIRST_MENU--}</option>\n";
137 foreach ($below as $key => $m) {
139 foreach ($m as $key2 => $m2) {
140 $OUT .= " <option value=\"".$m2."\">".$titles[$key][$key2];
141 foreach ($menus as $k => $v) {
142 if (($v == $key) && (!is_array($v))) {
143 $OUT .= " (".$titles[$k].")";
146 $OUT .= "</option>\n";
149 $OUT .= " <option value=\"".$m."\">".$titles[$key]."</option>\n";
154 define('__BELOW_SELECTION' , $OUT);
155 define('__WHAT_SELECTION' , ADMIN_MAKE_MENU_SELECTION("member", "what", "name"));
156 define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION("member", "action", "menu"));
159 LOAD_TEMPLATE("admin_member_add");
160 } elseif (!IS_DEMO()) {
161 // Insert new menu entry
162 if (REQUEST_ISSET_POST(('menu'))) {
163 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','%s','%s','%s')",
165 REQUEST_POST('menu'),
166 REQUEST_POST('name'),
167 REQUEST_POST('title'),
168 REQUEST_POST('visible'),
169 REQUEST_POST('active'),
170 bigintval(REQUEST_POST('sort')),
171 ), __FILE__, __LINE__);
173 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_member_menu` (`action`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','%s','%s')",
175 REQUEST_POST('name'),
176 REQUEST_POST('title'),
177 REQUEST_POST('visible'),
178 REQUEST_POST('active'),
179 bigintval(REQUEST_POST('sort')),
180 ), __FILE__, __LINE__);
182 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_SAVED'));
185 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_NOT_SAVED'));