3269df0ff71dc331767fb95db3b0937ad3bb9e69
[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  * $Revision::                                                        $ *
15  * $Date::                                                            $ *
16  * $Tag:: 0.2.1-FINAL                                                 $ *
17  * $Author::                                                          $ *
18  * Needs to be in all Files and every File needs "svn propset           *
19  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
20  * -------------------------------------------------------------------- *
21  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
42         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
43         require($INC);
44 }
45
46 // Add desciption as navigation point
47 ADD_DESCR('admin', __FILE__);
48
49 // Check if the admin has entered title and what-php file name...
50 if ((!REQUEST_ISSET_POST(('title'))) && (isFormSent())) {
51         REQUEST_UNSET_POST('ok');
52 } // END - if
53
54 if (!isFormSent()) {
55         // Create arrays
56         $menus = array(); $titles = array(); $below = array();
57
58         // Get all available main menus
59         $result = SQL_QUERY("SELECT action, title, sort FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort`",
60         __FILE__, __LINE__);
61         if (SQL_NUMROWS($result) > 0) {
62                 // Read menu structure
63                 while ($content = SQL_FETCHARRAY($result)) {
64                         // Menu actions
65                         $menus[] = $content['action'];
66
67                         // Menu titles
68                         $titles[] = $content['title'];
69
70                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
71                         $below[] = $content['sort'] + 1;
72                 }
73
74                 // Free memory
75                 SQL_FREERESULT($result);
76
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) {
82                                 // Remove entries
83                                 unset($dmy[$key]);
84                                 unset($dmy2[$key]);
85                                 unset($dmy3[$key]);
86                         } else {
87                                 $prev = $value;
88                         }
89                 } // END - foreach
90
91                 // Prepare variables
92                 $menus = $dmy; $titles = $dmy2; $below = $dmy3;
93
94                 // Load sub menus :)
95                 foreach ($menus as $key_main => $value_main) {
96                         $result = SQL_QUERY_ESC("SELECT what, title, sort FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE `action`='%s' AND `what` != '' ORDER BY `sort`",
97                         array($value_main), __FILE__, __LINE__);
98                         if (SQL_NUMROWS($result) > 0) {
99                                 // Initialize arrays
100                                 $menus[$value_main] = array();
101                                 $titles[$value_main] = array();
102                                 $below[$value_main] = array();
103
104                                 // Read menu structure
105                                 while ($content = SQL_FETCHARRAY($result)) {
106                                         // Menu actions
107                                         $menus[$value_main][] = $content['action'];
108
109                                         // Menu titles
110                                         $titles[$value_main][] = $content['title'];
111
112                                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
113                                         $below[$value_main][] = $content['sort'] + 1;
114                                 } // END - while
115
116                                 // Free memory
117                                 SQL_FREERESULT($result);
118
119                                 // Remove double eintries
120                                 // @TODO This can be somehow rewritten to a function
121                                 $prev = ''; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
122                                 foreach ($menus[$value_main] as $key => $value) {
123                                         if ($value == $prev) {
124                                                 unset($dmy[$key]);
125                                                 unset($dmy2[$key]);
126                                                 unset($dmy3[$key]);
127                                         } else {
128                                                 $prev = $value;
129                                         }
130                                 } // END - foreach
131
132                                 // Transfer variables into array
133                                 $menus[$value_main]  = $dmy;
134                                 $titles[$value_main] = $dmy2;
135                                 $below[$value_main]  = $dmy3;
136                         } // END - if
137                 } // END - foreach
138         } // END - if
139
140         $OUT = "<select class=\"admin_select\" name=\"sort\" size=\"1\">
141       <option value=\"\">{--IS_FIRST_MENU--}</option>\n";
142         foreach ($below as $key => $m) {
143                 if (is_array($m)) {
144                         foreach ($m as $key2 => $m2) {
145                                 $OUT .= "      <option value=\"".$m2."\">".$titles[$key][$key2];
146                                 foreach ($menus as $k => $v) {
147                                         if (($v == $key) && (!is_array($v))) {
148                                                 $OUT .= " (" . $titles[$k] . ')';
149                                         }
150                                 }
151                                 $OUT .= "</option>\n";
152                         }
153                 } else {
154                         $OUT .= "      <option value=\"".$m."\">".$titles[$key]."</option>\n";
155                 }
156         }
157         $OUT .= "</select>";
158
159         define('__BELOW_SELECTION' , $OUT);
160         define('__WHAT_SELECTION'  , ADMIN_MAKE_MENU_SELECTION('member', "what", "name"));
161         define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION('member', "action", "menu"));
162
163         // Display form
164         LOAD_TEMPLATE("admin_member_add");
165 } elseif (!IS_DEMO()) {
166         // Insert new menu entry
167         if (REQUEST_ISSET_POST(('menu'))) {
168                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','%s','%s','%s')",
169                 array(
170                 REQUEST_POST('menu'),
171                 REQUEST_POST('name'),
172                 REQUEST_POST('title'),
173                 REQUEST_POST('visible'),
174                 REQUEST_POST('active'),
175                 bigintval(REQUEST_POST('sort')),
176                 ), __FILE__, __LINE__);
177         } else {
178                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_member_menu` (`action`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','%s','%s')",
179                 array(
180                 REQUEST_POST('name'),
181                 REQUEST_POST('title'),
182                 REQUEST_POST('visible'),
183                 REQUEST_POST('active'),
184                 bigintval(REQUEST_POST('sort')),
185                 ), __FILE__, __LINE__);
186         }
187         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
188 } else {
189         // Demo mode!
190         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_NOT_SAVED'));
191 }
192
193 //
194 ?>