Heavy rewrite:
[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();
57         $titles = array();
58         $below  = array();
59
60         // Get all available main menus
61         $result = SQL_QUERY("SELECT `action`, `title`, `sort` FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC",
62                 __FILE__, __LINE__);
63         if (SQL_NUMROWS($result) > 0) {
64                 // Read menu structure
65                 // @TODO Cant this be rewritten?
66                 while ($content = SQL_FETCHARRAY($result)) {
67                         // Menu actions
68                         $menus[] = $content['action'];
69
70                         // Menu titles
71                         $titles[] = $content['title'];
72
73                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
74                         $below[] = $content['sort'] + 1;
75                 } // END - if
76
77                 // Free memory
78                 SQL_FREERESULT($result);
79
80                 // Remove double eintries
81                 // @TODO This can be somehow rewritten to a function
82                 $prev = '';
83                 $dmy  = $menus;
84                 $dmy2 = $titles;
85                 $dmy3 = $below;
86                 foreach ($menus as $key => $value) {
87                         if ($value == $prev) {
88                                 // Remove entries
89                                 unset($dmy[$key]);
90                                 unset($dmy2[$key]);
91                                 unset($dmy3[$key]);
92                         } else {
93                                 $prev = $value;
94                         }
95                 } // END - foreach
96
97                 // Prepare variables
98                 $menus = $dmy; $titles = $dmy2; $below = $dmy3;
99
100                 // Load sub menus :)
101                 foreach ($menus as $key_main => $value_main) {
102                         $result = SQL_QUERY_ESC("SELECT what, title, sort FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE `action`='%s' AND `what` != '' ORDER BY `sort`",
103                         array($value_main), __FILE__, __LINE__);
104                         if (SQL_NUMROWS($result) > 0) {
105                                 // Initialize arrays
106                                 $menus[$value_main] = array();
107                                 $titles[$value_main] = array();
108                                 $below[$value_main] = array();
109
110                                 // Read menu structure
111                                 while ($content = SQL_FETCHARRAY($result)) {
112                                         // Menu actions
113                                         $menus[$value_main][] = $content['action'];
114
115                                         // Menu titles
116                                         $titles[$value_main][] = $content['title'];
117
118                                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
119                                         $below[$value_main][] = $content['sort'] + 1;
120                                 } // END - while
121
122                                 // Free memory
123                                 SQL_FREERESULT($result);
124
125                                 // Remove double eintries
126                                 // @TODO This can be somehow rewritten to a function
127                                 $prev = ''; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
128                                 foreach ($menus[$value_main] as $key => $value) {
129                                         if ($value == $prev) {
130                                                 unset($dmy[$key]);
131                                                 unset($dmy2[$key]);
132                                                 unset($dmy3[$key]);
133                                         } else {
134                                                 $prev = $value;
135                                         }
136                                 } // END - foreach
137
138                                 // Transfer variables into array
139                                 $menus[$value_main]  = $dmy;
140                                 $titles[$value_main] = $dmy2;
141                                 $below[$value_main]  = $dmy3;
142                         } // END - if
143                 } // END - foreach
144         } // END - if
145
146         $OUT = "<select class=\"admin_select\" name=\"sort\" size=\"1\">
147       <option value=\"\">{--IS_FIRST_MENU--}</option>\n";
148         foreach ($below as $key => $m) {
149                 if (is_array($m)) {
150                         foreach ($m as $key2 => $m2) {
151                                 $OUT .= "      <option value=\"" . $m2 . "\">" . $titles[$key][$key2];
152                                 foreach ($menus as $k => $v) {
153                                         if (($v == $key) && (!is_array($v))) {
154                                                 $OUT .= " (" . $titles[$k] . ')';
155                                         } // END - if
156                                 } // END - foreach
157                                 $OUT .= "</option>\n";
158                         } // END - foreach
159                 } else {
160                         $OUT .= "      <option value=\"" . $m . "\">" . $titles[$key] . "</option>\n";
161                 }
162         }
163         $OUT .= "</select>";
164
165         define('__BELOW_SELECTION' , $OUT);
166         define('__WHAT_SELECTION'  , ADMIN_MAKE_MENU_SELECTION('member', 'what'  , 'name'));
167         define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION('member', 'action', 'menu'));
168
169         // Display form
170         LOAD_TEMPLATE('admin_member_add');
171 } elseif (!IS_DEMO()) {
172         // Insert new menu entry
173         if (REQUEST_ISSET_POST('menu')) {
174                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','%s','%s','%s')",
175                         array(
176                                 REQUEST_POST('menu'),
177                                 REQUEST_POST('name'),
178                                 REQUEST_POST('title'),
179                                 REQUEST_POST('visible'),
180                                 REQUEST_POST('active'),
181                                 bigintval(REQUEST_POST('sort')),
182                         ), __FILE__, __LINE__);
183         } else {
184                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_member_menu` (`action`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','%s','%s')",
185                         array(
186                                 REQUEST_POST('name'),
187                                 REQUEST_POST('title'),
188                                 REQUEST_POST('visible'),
189                                 REQUEST_POST('active'),
190                                 bigintval(REQUEST_POST('sort')),
191                         ), __FILE__, __LINE__);
192         }
193         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
194 } else {
195         // Demo mode!
196         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_NOT_SAVED'));
197 }
198
199 //
200 ?>