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