]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-admin_add.php
fe314901936ed66a2e4a11b1f069094dcb9fd4d5
[mailer.git] / inc / modules / admin / what-admin_add.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 // Check if the admin has entered title and what-php file name...
44 if (((!REQUEST_ISSET_POST(('title'))) || (!REQUEST_ISSET_POST(('menu'))) || (!REQUEST_ISSET_POST(('descr')))) && (IS_FORM_SENT())) {
45         REQUEST_UNSET_POST('ok');
46 }
47
48 if (!IS_FORM_SENT())
49 {
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!}_admin_menu` WHERE (what='' OR `what` IS NULL) ORDER BY `sort`", __FILE__, __LINE__);
55         if (SQL_NUMROWS($result) > 0) {
56                 // Read menu structure
57                 while ($content = SQL_FETCHARRAY($result)) {
58                         // Menu actions
59                         $menus[] = $content['action'];
60
61                         // Menu titles
62                         $titles[] = $content['title'];
63
64                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
65                         $below[] = $content['sort'] + 1;
66                 } // END - while
67
68                 // Free memory
69                 SQL_FREERESULT($result);
70
71                 // Remove double eintries
72                 // @TODO This can be somehow rewritten to a function
73                 $prev = ""; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
74                 foreach ($menus as $key => $value)
75                 {
76                         if ($value == $prev)
77                         {
78                                 unset($dmy[$key]);
79                                 unset($dmy2[$key]);
80                                 unset($dmy3[$key]);
81                         }
82                          else
83                         {
84                                 $prev = $value;
85                         }
86                 }
87                 $menus = $dmy; $titles = $dmy2; $below = $dmy3;
88                 // Load sub menus :)
89                 foreach ($menus as $key_main => $value_main) {
90                         $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`",
91                                 array($value_main), __FILE__, __LINE__);
92                         if (SQL_NUMROWS($result) > 0) {
93                                 // Init arrays
94                                 $menus[$value_main] = array();
95                                 $titles[$value_main] = array();
96                                 $below[$value_main] = array();
97
98                                 // Read menu structure
99                                 while ($content = SQL_FETCHROW($result)) {
100                                         // Menu actions
101                                         $menus[$value_main][] = $content['action'];
102
103                                         // Menu titles
104                                         $titles[$value_main][] = $content['title'];
105
106                                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
107                                         $below[$value_main][] = $content['sort'] + 1;
108                                 } // END - while
109
110                                 // Free memory
111                                 SQL_FREERESULT($result);
112
113                                 // Remove double eintries
114                                 // @TODO This can be somehow rewritten to a function
115                                 $prev = ""; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
116                                 foreach ($menus[$value_main] as $key => $value) {
117                                         if ($value == $prev) {
118                                                 unset($dmy[$key]);
119                                                 unset($dmy2[$key]);
120                                                 unset($dmy3[$key]);
121                                         } else {
122                                                 $prev = $value;
123                                         }
124                                 }
125                                 $menus[$value_main] = $dmy;
126                                 $titles[$value_main] = $dmy2;
127                                 $below[$value_main] = $dmy3;
128                         }
129                 }
130         }
131         $OUT = "    <select class=\"admin_select\" name=\"sort\" size=\"1\">
132       <option value=\"0\">".IS_FIRST_MENU."</option>\n";
133         foreach ($below as $key => $m)
134         {
135                 if (is_array($m))
136                 {
137                         foreach ($m as $key2 => $m2)
138                         {
139                                 $OUT .= "      <option value=\"".$m2."\">".$titles[$key][$key2];
140                                 foreach ($menus as $k => $v)
141                                 {
142                                         if (($v == $key) && (!is_array($v)))
143                                         {
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         define('__BELOW_SELECTION' , $OUT);
158         define('__WHAT_SELECTION'  , ADMIN_MAKE_MENU_SELECTION("admin", "what", "name"));
159         define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION("admin", "action", "menu"));
160
161         // Display form
162         LOAD_TEMPLATE("admin_admin_add");
163 } elseif (!IS_DEMO()) {
164         // Insert new menu entry
165         if (REQUEST_ISSET_POST(('menu'))) {
166                 // Add sub menu
167                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s','%s')",
168                         array(
169                                 REQUEST_POST('menu'),
170                                 REQUEST_POST('name'),
171                                 REQUEST_POST('title'),
172                                 REQUEST_POST('descr'),
173                                 bigintval(REQUEST_POST('sort')),
174                         ), __FILE__, __LINE__
175                 );
176                 CACHE_PURGE_ADMIN_MENU(0, REQUEST_POST('menu'), REQUEST_POST('name'));
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                                 REQUEST_POST('name'),
182                                 REQUEST_POST('title'),
183                                 REQUEST_POST('descr'),
184                                 bigintval(REQUEST_POST('sort')),
185                         ), __FILE__, __LINE__
186                 );
187                 CACHE_PURGE_ADMIN_MENU(0, REQUEST_POST('name'));
188         }
189         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_SAVED'));
190 } else {
191         // Is demo login!
192         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_NOT_SAVED'));
193 }
194
195 //
196 ?>