]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-mem_add.php
We need a solution for this...
[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 } // END - if
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`",
55                 __FILE__, __LINE__);
56         if (SQL_NUMROWS($result) > 0) {
57                 // Read menu structure
58                 while ($content = SQL_FETCHARRAY($result)) {
59                         // Menu actions
60                         $menus[] = $content['action'];
61
62                         // Menu titles
63                         $titles[] = $content['title'];
64
65                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
66                         $below[] = $content['sort'] + 1;
67                 }
68
69                 // Free memory
70                 SQL_FREERESULT($result);
71
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) {
77                                 // Remove entries
78                                 unset($dmy[$key]);
79                                 unset($dmy2[$key]);
80                                 unset($dmy3[$key]);
81                         } else {
82                                 $prev = $value;
83                         }
84                 } // END - foreach
85
86                 // Prepare variables
87                 $menus = $dmy; $titles = $dmy2; $below = $dmy3;
88
89                 // Load sub menus :)
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) {
94                                 // Initialize arrays
95                                 $menus[$value_main] = array();
96                                 $titles[$value_main] = array();
97                                 $below[$value_main] = array();
98
99                                 // Read menu structure
100                                 while ($content = SQL_FETCHARRAY($result)) {
101                                         // Menu actions
102                                         $menus[$value_main][] = $content['action'];
103
104                                         // Menu titles
105                                         $titles[$value_main][] = $content['title'];
106
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;
109                                 } // END - while
110
111                                 // Free memory
112                                 SQL_FREERESULT($result);
113
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) {
119                                                 unset($dmy[$key]);
120                                                 unset($dmy2[$key]);
121                                                 unset($dmy3[$key]);
122                                         } else {
123                                                 $prev = $value;
124                                         }
125                                 } // END - foreach
126
127                                 // Transfer variables into array
128                                 $menus[$value_main]  = $dmy;
129                                 $titles[$value_main] = $dmy2;
130                                 $below[$value_main]  = $dmy3;
131                         } // END - if
132                 } // END - foreach
133         } // END - if
134
135         $OUT = "<select class=\"admin_select\" name=\"sort\" size=\"1\">
136       <option value=\"\">{--IS_FIRST_MENU--}</option>\n";
137         foreach ($below as $key => $m) {
138                 if (is_array($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].")";
144                                         }
145                                 }
146                                 $OUT .= "</option>\n";
147                         }
148                 } else {
149                         $OUT .= "      <option value=\"".$m."\">".$titles[$key]."</option>\n";
150                 }
151         }
152         $OUT .= "</select>";
153
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"));
157
158         // Display form
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')",
164                         array(
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__);
172         } else {
173                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_member_menu` (`action`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','%s','%s')",
174                         array(
175                                 REQUEST_POST('name'),
176                                 REQUEST_POST('title'),
177                                 REQUEST_POST('visible'),
178                                 REQUEST_POST('active'),
179                                 bigintval(REQUEST_POST('sort')),
180                         ), __FILE__, __LINE__);
181         }
182         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_SAVED'));
183 } else {
184         // Demo mode!
185         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_NOT_SAVED'));
186 }
187
188 //
189 ?>