bd4f9c4fd283b22f2af48f405952cbcf91bcfa4e
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 // Check if the admin has entered title and what-php file name...
47 if ((isFormSent()) && ((!isPostRequestElementSet('title')) || (!isPostRequestElementSet('menu')) || (!isPostRequestElementSet('descr')))) {
48         unsetPostRequestElement('ok');
49 } // END - if
50
51 if (!isFormSent()) {
52         // Create arrays
53         $menus = array();
54         $titles = array();
55         $below = array();
56
57         // Get all available main menus
58         $result = sqlQuery("SELECT `action`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
59         if (!ifSqlHasZeroNums($result)) {
60                 // Read menu structure
61                 // @TODO Cant this be rewritten?
62                 while ($content = sqlFetchArray($result)) {
63                         // Menu actions
64                         array_push($menus, $content['action']);
65
66                         // Menu titles
67                         array_push($titles, $content['title']);
68
69                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
70                         array_push($below, $content['sort'] + 1);
71                 } // END - while
72
73                 // Free memory
74                 sqlFreeResult($result);
75
76                 // Remove double eintries
77                 // @TODO This can be somehow rewritten to a function
78                 $prev = ''; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
79                 foreach ($menus as $key => $value) {
80                         if ($value == $prev) {
81                                 unset($dmy[$key]);
82                                 unset($dmy2[$key]);
83                                 unset($dmy3[$key]);
84                         } else {
85                                 $prev = $value;
86                         }
87                 } // END - foreach
88
89                 // Write dummys back to our array
90                 $menus  = $dmy;  unset($dmy);
91                 $titles = $dmy2; unset($dmy2);
92                 $below  = $dmy3; unset($dmy3);
93
94                 // Load sub menus :)
95                 foreach ($menus as $key_main => $value_main) {
96                         $result = sqlQueryEscaped("SELECT `what`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort` ASC",
97                                 array($value_main), __FILE__, __LINE__);
98                         if (!ifSqlHasZeroNums($result)) {
99                                 // Init arrays
100                                 $menus[$value_main] = array();
101                                 $titles[$value_main] = array();
102                                 $below[$value_main] = array();
103
104                                 // Read menu structure
105                                 while ($content = sqlFetchArray($result)) {
106                                         // Menu actions
107                                         array_push($menus[$value_main], $content['what']);
108
109                                         // Menu titles
110                                         array_push($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                                         array_push($below[$value_main], $content['sort'] + 1);
114                                 } // END - while
115
116                                 // Free memory
117                                 sqlFreeResult($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                                 $menus[$value_main] = $dmy;
132                                 $titles[$value_main] = $dmy2;
133                                 $below[$value_main] = $dmy3;
134                         } // END - if
135                 } // END - foreach
136         } // END - if
137
138         $OUT = '    <select class="form_select" name="sort" size="1">
139       <option value="0">{--ADMIN_IS_FIRST_MENU--}</option>';
140         foreach ($below as $key => $m) {
141                 if (is_array($m)) {
142                         foreach ($m as $key2 => $m2) {
143                                 $OUT .= '      <option value="' . $m2 . '">' . $titles[$key][$key2];
144                                 foreach ($menus as $k => $v) {
145                                         if (($v == $key) && (!is_array($v))) {
146                                                 $OUT .= ' (' . $titles[$k] . ')';
147                                         } // END - if
148                                 } // END - foreach
149                                 $OUT .= '</option>';
150                         } // END - foreach
151                 } else {
152                         $OUT .= '      <option value="' . $m . '">' . $titles[$key] . '</option>';
153                 }
154         }
155         $OUT .= '</select>';
156
157         // Prepare selections for template
158         $content['below_selection']  = $OUT;
159         $content['what_selection']   = adminAddMenuSelectionBox('admin', 'what'  , 'name');
160         $content['action_selection'] = adminAddMenuSelectionBox('admin', 'action', 'menu');
161
162         // Display form
163         loadTemplate('admin_add_admin_menu', FALSE, $content);
164 } elseif (!isDemoModeActive()) {
165         // Insert new menu entry
166         if (isPostRequestElementSet('menu')) {
167                 // Add sub menu
168                 sqlQueryEscaped("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                 sqlQueryEscaped("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         displayMessage('{--SETTINGS_SAVED--}');
189 } else {
190         // Is demo login!
191         displayMessage('{--SETTINGS_NOT_SAVED--}');
192 }
193
194 // [EOF]
195 ?>