Next wave of lesser getMessage() usage and more EL
[mailer.git] / inc / modules / admin / what-mem_add.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 2009 by Roland Haeder                           *
22  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
23  * For more information visit: http://www.mxchange.org                  *
24  *                                                                      *
25  * This program is free software; you can redistribute it and/or modify *
26  * it under the terms of the GNU General Public License as published by *
27  * the Free Software Foundation; either version 2 of the License, or    *
28  * (at your option) any later version.                                  *
29  *                                                                      *
30  * This program is distributed in the hope that it will be useful,      *
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
33  * GNU General Public License for more details.                         *
34  *                                                                      *
35  * You should have received a copy of the GNU General Public License    *
36  * along with this program; if not, write to the Free Software          *
37  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
38  * MA  02110-1301  USA                                                  *
39  ************************************************************************/
40
41 // Some security stuff...
42 if ((!defined('__SECURITY')) || (!isAdmin())) {
43         die();
44 }
45
46 // Add desciption as navigation point
47 addMenuDescription('admin', __FILE__);
48
49 // Check if the admin has entered title and what-php file name...
50 if ((!isPostRequestParameterSet('title')) && (isFormSent())) {
51         unsetPostRequestParameter('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['what'];
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         // Prepare selection boxes for template
166         $content['below_selection']  = $OUT;
167         $content['what_selection']   = adminAddMenuSelectionBox('member', 'what'  , 'name');
168         $content['action_selection'] = adminAddMenuSelectionBox('member', 'action', 'menu');
169
170         // Display form
171         loadTemplate('admin_member_add', false, $content);
172 } elseif (!isDemoModeActive()) {
173         // Insert new menu entry
174         if (isPostRequestParameterSet('menu')) {
175                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','%s','%s','%s')",
176                         array(
177                                 postRequestParameter('menu'),
178                                 postRequestParameter('name'),
179                                 postRequestParameter('title'),
180                                 postRequestParameter('visible'),
181                                 postRequestParameter('active'),
182                                 bigintval(postRequestParameter('sort')),
183                         ), __FILE__, __LINE__);
184         } else {
185                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','%s','%s')",
186                         array(
187                                 postRequestParameter('name'),
188                                 postRequestParameter('title'),
189                                 postRequestParameter('visible'),
190                                 postRequestParameter('active'),
191                                 bigintval(postRequestParameter('sort')),
192                         ), __FILE__, __LINE__);
193         }
194         loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED');
195 } else {
196         // Demo mode!
197         loadTemplate('admin_settings_saved', false, '{--SETTINGS_NOT_SAVED--}');
198 }
199
200 // [EOF]
201 ?>