Complete rewrite of and , wrapper functions added, see bug #101
[mailer.git] / inc / modules / admin / what-mem_add.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/28/2003 *
4  * ===============                              Last change: 12/13/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
14  *                                                                      *
15  * -------------------------------------------------------------------- *
16  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
17  * For more information visit: http://www.mxchange.org                  *
18  *                                                                      *
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.                                  *
23  *                                                                      *
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.                         *
28  *                                                                      *
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,               *
32  * MA  02110-1301  USA                                                  *
33  ************************************************************************/
34
35 // Some security stuff...
36 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40
41 // Add desciption as navigation point
42 ADD_DESCR("admin", __FILE__);
43
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');
47 }
48
49 if (!IS_FORM_SENT()) {
50         // Create arrays
51         $menus = array(); $titles = array(); $below = array();
52
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`", __FILE__, __LINE__);
55         if (SQL_NUMROWS($result) > 0) {
56                 // Read menu structure
57                 while (list($act, $title, $sort) = SQL_FETCHROW($result)) {
58                         // Menu actions
59                         $menus[] = $act;
60
61                         // Menu titles
62                         $titles[] = $title;
63
64                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
65                         $below[] = $sort + 1;
66                 }
67
68                 // Free memory
69                 SQL_FREERESULT($result);
70
71                 // Remove double eintries
72                 $prev = ""; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
73                 foreach ($menus as $key => $value) {
74                         if ($value == $prev) {
75                                 // Remove entries
76                                 unset($dmy[$key]);
77                                 unset($dmy2[$key]);
78                                 unset($dmy3[$key]);
79                         } else {
80                                 $prev = $value;
81                         }
82                 }
83
84                 // Prepare variables
85                 $menus = $dmy; $titles = $dmy2; $below = $dmy3;
86
87                 // Load sub menus :)
88                 foreach ($menus as $key_main => $value_main) {
89                         $result = SQL_QUERY_ESC("SELECT what, title, sort FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE `action`='%s' AND `what` != '' ORDER BY `sort`",
90                                 array($value_main), __FILE__, __LINE__);
91                         if (SQL_NUMROWS($result) > 0) {
92                                 // Initialize arrays
93                                 $menus[$value_main] = array();
94                                 $titles[$value_main] = array();
95                                 $below[$value_main] = array();
96
97                                 // Read menu structure
98                                 while (list($act, $title, $sort) = SQL_FETCHROW($result)) {
99                                         // Menu actions
100                                         $menus[$value_main][] = $act;
101
102                                         // Menu titles
103                                         $titles[$value_main][] = $title;
104
105                                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
106                                         $below[$value_main][] = $sort + 1;
107                                 }
108
109                                 // Free memory
110                                 SQL_FREERESULT($result);
111
112                                 // Remove double eintries
113                                 $prev = ""; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
114                                 foreach ($menus[$value_main] as $key => $value) {
115                                         if ($value == $prev) {
116                                                 unset($dmy[$key]);
117                                                 unset($dmy2[$key]);
118                                                 unset($dmy3[$key]);
119                                         } else {
120                                                 $prev = $value;
121                                         }
122                                 }
123                                 $menus[$value_main] = $dmy; $titles[$value_main] = $dmy2; $below[$value_main] = $dmy3;
124                         }
125                 }
126         }
127
128         $OUT = "<select class=\"admin_select\" name=\"sort\" size=\"1\">
129       <option value=\"\">".IS_FIRST_MENU."</option>";
130         foreach ($below as $key => $m) {
131                 if (is_array($m)) {
132                         foreach ($m as $key2 => $m2) {
133                                 $OUT .= "      <option value=\"".$m2."\">".$titles[$key][$key2];
134                                 foreach ($menus as $k => $v) {
135                                         if (($v == $key) && (!is_array($v))) {
136                                                 $OUT .= " (".$titles[$k].")";
137                                         }
138                                 }
139                                 $OUT .= "</option>\n";
140                         }
141                 } else {
142                         $OUT .= "      <option value=\"".$m."\">".$titles[$key]."</option>\n";
143                 }
144         }
145         $OUT .= "</select>";
146
147         define('__BELOW_SELECTION' , $OUT);
148         define('__WHAT_SELECTION'  , ADMIN_MAKE_MENU_SELECTION("member", "what", "name"));
149         define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION("member", "action", "menu"));
150
151         // Display form
152         LOAD_TEMPLATE("admin_member_add");
153 } elseif (!IS_DEMO()) {
154         // Insert new menu entry
155         if (REQUEST_ISSET_POST(('menu')))
156         {
157                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','%s','%s','%s')",
158  array(
159         REQUEST_POST('menu'),
160         REQUEST_POST('name'),
161         REQUEST_POST('title'),
162         REQUEST_POST('visible'),
163         REQUEST_POST('active'),
164         bigintval(REQUEST_POST('sort')),
165 ), __FILE__, __LINE__);
166         } else {
167                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_member_menu` (`action`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','%s','%s')",
168  array(
169         REQUEST_POST('name'),
170         REQUEST_POST('title'),
171         REQUEST_POST('visible'),
172         REQUEST_POST('active'),
173         bigintval(REQUEST_POST('sort')),
174 ), __FILE__, __LINE__);
175         }
176         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_SAVED'));
177 } else {
178         // Demo mode!
179         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_NOT_SAVED'));
180 }
181
182 //
183 ?>