ec086086ad2708faa7204d850bf98b7875af87b1
[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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
37 {
38         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
39         require($INC);
40 }
41 // Add desciption as navigation point
42 ADD_DESCR("admin", basename(__FILE__));
43 OUTPUT_HTML ("</FONT><BR>");
44
45 OPEN_TABLE("100%", "admin_content admin_content_align", "");
46
47 // Check if the admin has entered title and what-php file name...
48 if ((empty($_POST['title'])) && (isset($_POST['ok'])))
49 {
50         unset($_POST['ok']);
51 }
52
53 if (!isset($_POST['ok']))
54 {
55         // Create arrays
56         $menus = array(); $titles = array(); $below = array();
57
58         // Get all available main menus
59         $result = SQL_QUERY("SELECT action, title, sort FROM "._MYSQL_PREFIX."_member_menu WHERE what='' ORDER BY sort", __FILE__, __LINE__);
60         if (SQL_NUMROWS($result) > 0)
61         {
62                 // Read menu structure
63                 while (list($act, $title, $sort) = SQL_FETCHROW($result))
64                 {
65                         // Menu actions
66                         $menus[] = $act;
67
68                         // Menu titles
69                         $titles[] = $title;
70
71                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
72                         $below[] = $sort + 1;
73                 }
74
75                 // Free memory
76                 SQL_FREERESULT($result);
77
78                 // Remove double eintries
79                 $prev = ""; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
80                 foreach ($menus as $key=>$value)
81                 {
82                         if ($value == $prev)
83                         {
84                                 // Remove entries
85                                 unset($dmy[$key]);
86                                 unset($dmy2[$key]);
87                                 unset($dmy3[$key]);
88                         }
89                          else
90                         {
91                                 $prev = $value;
92                         }
93                 }
94                 $menus = $dmy; $titles = $dmy2; $below = $dmy3;
95                 // Load sub menus :)
96                 foreach ($menus as $key_main=>$value_main)
97                 {
98                         $result = SQL_QUERY_ESC("SELECT what, title, sort FROM "._MYSQL_PREFIX."_member_menu WHERE action='%s' AND what != '' ORDER BY sort",
99                          array($value_main), __FILE__, __LINE__);
100                         if (SQL_NUMROWS($result) > 0)
101                         {
102                                 // Initialize arrays
103                                 $menus[$value_main] = array();
104                                 $titles[$value_main] = array();
105                                 $below[$value_main] = array();
106
107                                 // Read menu structure
108                                 while (list($act, $title, $sort) = SQL_FETCHROW($result))
109                                 {
110                                         // Menu actions
111                                         $menus[$value_main][] = $act;
112
113                                         // Menu titles
114                                         $titles[$value_main][] = $title;
115
116                                         // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
117                                         $below[$value_main][] = $sort + 1;
118                                 }
119
120                                 // Free memory
121                                 SQL_FREERESULT($result);
122
123                                 // Remove double eintries
124                                 $prev = ""; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
125                                 foreach ($menus[$value_main] as $key=>$value)
126                                 {
127                                         if ($value == $prev)
128                                         {
129                                                 unset($dmy[$key]);
130                                                 unset($dmy2[$key]);
131                                                 unset($dmy3[$key]);
132                                         }
133                                          else
134                                         {
135                                                 $prev = $value;
136                                         }
137                                 }
138                                 $menus[$value_main] = $dmy; $titles[$value_main] = $dmy2; $below[$value_main] = $dmy3;
139                         }
140                 }
141         }
142
143         $OUT = "<SELECT class=\"admin_select\" name=\"sort\" size=\"1\">
144       <OPTION value=\"\">".IS_FIRST_MENU."</OPTION>";
145         foreach ($below as $key=>$m)
146         {
147                 if (is_array($m))
148                 {
149                         foreach ($m as $key2=>$m2)
150                         {
151                                 $OUT .= "      <OPTION value=\"".$m2."\">".$titles[$key][$key2];
152                                 foreach ($menus as $k=>$v)
153                                 {
154                                         if (($v == $key) && (!is_array($v)))
155                                         {
156                                                 $OUT .= " (".$titles[$k].")";
157                                         }
158                                 }
159                                 $OUT .= "</OPTION>\n";
160                         }
161                 }
162                  else
163                 {
164                         $OUT .= "      <OPTION value=\"".$m."\">".$titles[$key]."</OPTION>\n";
165                 }
166         }
167         $OUT .= "</SELECT>";
168
169         define('__BELOW_SELECTION' , $OUT);
170         define('__WHAT_SELECTION'  , ADMIN_MAKE_MENU_SELECTION("member", "what", "name"));
171         define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION("member", "action", "menu"));
172
173         // Display form
174         LOAD_TEMPLATE("admin_member_add");
175 }
176  elseif (!IS_DEMO())
177 {
178         // Insert new menu entry
179         if (!empty($_POST['menu']))
180         {
181                 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_member_menu
182 (action, what, title, visible, locked, sort)
183 VALUES('%s', '%s', '%s', '%s', '%s', '%s')",
184  array(
185         $_POST['menu'],
186         $_POST['name'],
187         $_POST['title'],
188         $_POST['visible'],
189         $_POST['active'],
190         bigintval($_POST['sort']),
191 ), __FILE__, __LINE__);
192         }
193          else
194         {
195                 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_member_menu
196 (action, title, visible, locked, sort)
197 VALUES('%s', '%s', '%s', '%s', '%s')",
198  array(
199         $_POST['name'],
200         $_POST['title'],
201         $_POST['visible'],
202         $_POST['active'],
203         bigintval($_POST['sort']),
204 ), __FILE__, __LINE__);
205         }
206         LOAD_TEMPLATE("admin_settings_saved", false, SAVING_DONE);
207 }
208  else
209 {
210         // Demo mode!
211         LOAD_TEMPLATE("admin_settings_saved", false, SETTINGS_NOT_SAVED);
212 }
213
214 CLOSE_TABLE();
215 //
216 ?>