Old config.php is now automatically updated to new config-local.php format, several...
[mailer.git] / inc / modules / admin / what-config_rallye_prices.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 07/03/2004 *
4  * ================                             Last change: 08/22/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-config_rallye_prices.php                    *
8  * -------------------------------------------------------------------- *
9  * Short description : Setup rallye prices                              *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Rallye-Preise einrichten                         *
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 - 2008 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')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
47
48 if (REQUEST_ISSET_GET(('rallye'))) {
49         // Price submitted?
50         if (REQUEST_ISSET_POST(('add'))) {
51                 if ((REQUEST_ISSET_POST(('level'))) && ((REQUEST_ISSET_POST(('points'))) || (REQUEST_ISSET_POST(('info'))))) {
52                         // Submitted data is valid, but maybe we already have this price level?
53                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE rallye_id=%s AND price_level='%s' LIMIT 1",
54                         array(bigintval(REQUEST_GET('rallye')), bigintval(REQUEST_POST('level'))), __FILE__, __LINE__);
55
56                         if (SQL_NUMROWS($result) == 0) {
57                                 // Ok, new price level entered!
58                                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_rallye_prices` (rallye_id, price_level, points, info)
59 VALUES ('%s','%s','%s','%s')",
60                                 array(
61                                 bigintval(REQUEST_GET('rallye')),
62                                 bigintval(REQUEST_POST('level')),
63                                 REQUEST_POST('points'),
64                                 REQUEST_POST('info')
65                                 ), __FILE__, __LINE__);
66                                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_PRICE_LEVEL_SAVED'));
67                         } else {
68                                 // Free memory
69                                 SQL_FREERESULT($result);
70
71                                 // Price level found!
72                                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_PRICE_ALREADY_FOUND'));
73                         }
74                 }
75         } elseif (REQUEST_ISSET_POST('remove')) {
76                 // Check if at last one line is selected
77                 $SEL = countPostSelection();
78                 if ($SEL > 0) {
79                         // Delete selected entries
80                         foreach (REQUEST_POST('sel') as $id => $sel) {
81                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE `id`=%s LIMIT 1",
82                                 array(bigintval($id)), __FILE__, __LINE__);
83                         }
84
85                         // Output message
86                         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_DELETED'));
87                 } else {
88                         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_NOT_DELETED'));
89                 }
90         } elseif (REQUEST_ISSET_POST('change')) {
91                 // Change entries
92                 foreach (REQUEST_POST('level') as $id => $level) {
93                         // Secure ID
94                         $id = bigintval($id);
95
96                         // Update entry
97                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_rallye_prices` SET rallye_id=%s, price_level='%s', points='%s', info='%s' WHERE `id`=%s LIMIT 1",
98                         array(
99                         REQUEST_POST('rallye_id', $id),
100                         bigintval($level),
101                         REQUEST_POST('points', $id),
102                         REQUEST_POST('infos', $id),
103                         $id
104                         ), __FILE__, __LINE__);
105                 }
106
107                 // Output message
108                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_CHANGED'));
109         }
110
111         if (REQUEST_ISSET_POST('edit')) {
112                 // Check if at last one line is selected
113                 $SEL = countPostSelection();
114                 if ($SEL > 0) {
115                         // Make selected editable
116                         $OUT = ''; $SW = 2;
117                         foreach (REQUEST_POST('sel') as $id => $sel) {
118                                 // Load data to selected rallye
119                                 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE `id`=%s LIMIT 1",
120                                 array(bigintval($id)), __FILE__, __LINE__);
121                                 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
122                                 SQL_FREERESULT($result);
123
124                                 // Prepare data for the row template
125                                 $content = array(
126                                         'sw'      => $SW,
127                                         'id'      => $id,
128                                         'rallyes' => generateOptionList("rallye_data", "id", "title", $rallye),
129                                         'level'   => $level,
130                                         'points'  => $points,
131                                         'infos'   => $infos,
132                                 );
133
134                                 // Load row template and switch color
135                                 $OUT .= LOAD_TEMPLATE("admin_config_rallye_edit_row", true, $content);
136                                 $SW = 3 - $SW;
137                         }
138                         define('__PRICE_ROWS', $OUT);
139
140                         // Prepare data for the main template
141                         define('__RALLYE_ID', REQUEST_GET('rallye'));
142
143                         // Load main template
144                         LOAD_TEMPLATE("admin_config_rallye_edit");
145                 } else {
146                         // Nothing selected
147                         $content = sprintf(getMessage('RALLYE_NO_PRICES_SELECTED'), "<a href=\"{!URL!}/modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=".REQUEST_GET('rallye')."\">", "</a>");
148                         LOAD_TEMPLATE('admin_settings_saved', false, $content);
149                 }
150         } elseif (REQUEST_ISSET_POST('del')) {
151                 // Check if at last one line is selected
152                 $SEL = countPostSelection();
153                 if ($SEL > 0) {
154                         // List all prices
155                         $OUT = ''; $SW = 2;
156                         foreach (REQUEST_POST('sel') as $id => $sel) {
157                                 // Load data to selected rallye
158                                 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE `id`=%s LIMIT 1",
159                                 array(bigintval($id)), __FILE__, __LINE__);
160                                 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
161                                 SQL_FREERESULT($result);
162
163                                 if (empty($infos)) $infos = '---';
164
165                                 // Prepare data for the row template
166                                 $content = array(
167                                         'sw'      => $SW,
168                                         'id'      => $id,
169                                         'level'   => $level,
170                                         'points'  => $points,
171                                         'infos'   => $infos,
172                                 );
173
174                                 // Load row template and switch color
175                                 $OUT .= LOAD_TEMPLATE("admin_config_rallye_del_row", true, $content);
176                                 $SW = 3 - $SW;
177                         }
178                         define('__PRICE_ROWS', $OUT);
179
180                         // Prepare data for the main template
181                         define('__RALLYE_ID', REQUEST_GET('rallye'));
182
183                         // Load main template
184                         LOAD_TEMPLATE("admin_config_rallye_del");
185                 } else {
186                         // Nothing selected
187                         $content = RALLYE_NO_PRICES_SELECTED_1."<a href=\"{!URL!}/modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=".REQUEST_GET('rallye')."\">".RALLYE_NO_PRICES_SELECTED_2."</a>".RALLYE_NO_PRICES_SELECTED_3;
188                         LOAD_TEMPLATE('admin_settings_saved', false, $content);
189                 }
190         } else {
191                 // a rallye was selected, so check if there are already prices assigned...
192                 $result = SQL_QUERY_ESC("SELECT id, price_level, points, info FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE rallye_id=%s ORDER BY price_level",
193                 array(bigintval(REQUEST_GET('rallye'))), __FILE__, __LINE__);
194
195                 if (SQL_NUMROWS($result) > 0) {
196                         // Load all prices for the selected rallye
197                         $OUT = ''; $SW = 2;
198                         while ($content = SQL_FETCHARRAY($result)) {
199                                 // Fix empty info
200                                 if (empty($content['info'])) $content['info'] = '---';
201
202                                 // Prepare data for the row template
203                                 // @TODO Rewritings: level->price_level, infos->info in template
204                                 $content = array(
205                                         'sw'      => $SW,
206                                         'id'      => $content['id'],
207                                         'level'   => $content['price_level'],
208                                         'points'  => $content['points'],
209                                         'infos'   => $content['info'],
210                                 );
211
212                                 // Load row template and switch color
213                                 $OUT .= LOAD_TEMPLATE("admin_config_rallye_prices_row", true, $content);
214                                 $SW = 3 - $SW;
215                         } // END - while
216
217                         // Free memory
218                         SQL_FREERESULT($result);
219
220                         // @TODO Rewrite these two constants
221                         define('__PRICE_ROWS', $OUT);
222
223                         // Prepare data for the main template
224                         define('__RALLYE_ID', REQUEST_GET('rallye'));
225
226                         // Load main template
227                         LOAD_TEMPLATE("admin_config_rallye_prices");
228                 }
229         }
230
231         // Add form for adding new price level
232         if (!REQUEST_ISSET_POST('edit')) {
233                 LOAD_TEMPLATE("admin_add_rallye_prices", false, REQUEST_GET('rallye'));
234         }
235 } else {
236         // No rallye selected so display all available without prices
237         $result = SQL_QUERY("SELECT d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
238 FROM `{!_MYSQL_PREFIX!}_rallye_data` AS d, `{!_MYSQL_PREFIX!}_admins` AS a
239 WHERE d.admin_id=a.id ORDER BY start_time DESC", __FILE__, __LINE__);
240         if (SQL_NUMROWS($result) > 0) {
241                 // List found rallyes
242                 $OUT = ''; $SW = 2;
243                 while ($content = SQL_FETCHARRAY($result)) {
244                         $select = "<input type=\"checkbox\" name=\"sel[".$content['id']."]\" class=\"admin_normal\" value=\"1\">";
245                         if ($content['is_active'] == 'Y') $select = "<div class=\"big\">".$content['id']."</div>";
246
247                         // Prepare data for the row template
248                         // @TODO Rewritings: aid->admin_id, alogin->login in template
249                         $content = array(
250                                 'sw'         => $SW,
251                                 'id'         => $content['id'],
252                                 'select'     => $select,
253                                 'title'      => $content['title'],
254                                 'aid'        => $content['admin_id'],
255                                 'email_link' => generateMemberEmailLink($content['admin_id']),
256                                 'alogin'     => $content['login'],
257                                 'start'      => generateDateTime($content['start_time'], '3'),
258                                 'end'        => generateDateTime($content['end_time'], '3'),
259                         );
260
261                         // Load row template and switch color
262                         $OUT .= LOAD_TEMPLATE("admin_list_rallye_prices_row", true, $content);
263                         $SW = 3 - $SW;
264                 }
265
266                 // Free memory
267                 SQL_FREERESULT($result);
268                 define('__RALLYE_ROWS', $OUT);
269
270                 // Load main template
271                 LOAD_TEMPLATE("admin_list_rallye_prices");
272         } else {
273                 // No rallyes setup so far
274                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_NO_RALLYES_SETUP'));
275         }
276 }
277 //
278 ?>