2 /************************************************************************
3 * MXChange v0.2.1 Start: 07/03/2004 *
4 * ================ Last change: 08/22/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-config_rallye_prices.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Setup rallye prices *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Rallye-Preise einrichten *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
47 if (isGetRequestElementSet('rallye')) {
49 if (isPostRequestElementSet('add')) {
50 if ((isPostRequestElementSet(('level'))) && ((isPostRequestElementSet(('points'))) || (isPostRequestElementSet(('info'))))) {
51 // Submitted data is valid, but maybe we already have this price level?
52 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s AND `price_level`='%s' LIMIT 1",
53 array(bigintval(getRequestElement('rallye')), bigintval(postRequestElement('level'))), __FILE__, __LINE__);
55 if (SQL_NUMROWS($result) == 0) {
56 // Ok, new price level entered!
57 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_rallye_prices` (rallye_id, price_level, points, info)
58 VALUES ('%s','%s','%s','%s')",
60 bigintval(getRequestElement('rallye')),
61 bigintval(postRequestElement('level')),
62 postRequestElement('points'),
63 postRequestElement('info')
64 ), __FILE__, __LINE__);
65 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_PRICE_LEVEL_SAVED'));
68 SQL_FREERESULT($result);
71 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_PRICE_ALREADY_FOUND'));
74 } elseif (isPostRequestElementSet('remove')) {
75 // Check if at last one line is selected
76 $SEL = countPostSelection();
78 // Delete selected entries
79 foreach (postRequestElement('sel') as $id => $sel) {
80 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
81 array(bigintval($id)), __FILE__, __LINE__);
85 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_DELETED'));
87 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_NOT_DELETED'));
89 } elseif (isPostRequestElementSet('change')) {
91 foreach (postRequestElement('level') as $id => $level) {
97 `{?_MYSQL_PREFIX?}_rallye_prices`
107 postRequestElement('rallye_id', $id),
109 postRequestElement('points', $id),
110 postRequestElement('infos', $id),
112 ), __FILE__, __LINE__);
116 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_CHANGED'));
119 if (isPostRequestElementSet('edit')) {
120 // Check if at last one line is selected
121 $SEL = countPostSelection();
123 // Make selected editable
125 foreach (postRequestElement('sel') as $id => $sel) {
126 // Load data to selected rallye
127 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
128 array(bigintval($id)), __FILE__, __LINE__);
129 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
130 SQL_FREERESULT($result);
132 // Prepare data for the row template
136 'rallyes' => generateOptionList('rallye_data', 'id', 'title', $rallye),
142 // Load row template and switch color
143 $OUT .= loadTemplate('admin_config_rallye_edit_row', true, $content);
146 $content['rows'] = $OUT;
148 // Prepare data for the main template
149 $content['rallye'] = getRequestElement('rallye');
151 // Load main template
152 loadTemplate('admin_config_rallye_edit', false, $content);
155 $content = sprintf(getMessage('RALLYE_NO_PRICES_SELECTED'), "<a href=\"{?URL?}/modules.php?module=admin&what=config_rallye_prices&rallye=".getRequestElement('rallye')."\">", "</a>");
156 loadTemplate('admin_settings_saved', false, $content);
158 } elseif (isPostRequestElementSet('del')) {
159 // Check if at last one line is selected
160 $SEL = countPostSelection();
164 foreach (postRequestElement('sel') as $id => $sel) {
165 // Load data to selected rallye
166 $result = SQL_QUERY_ESC("SELECT `rallye_id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
167 array(bigintval($id)), __FILE__, __LINE__);
168 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
169 SQL_FREERESULT($result);
171 if (empty($infos)) $infos = '---';
173 // Prepare data for the row template
182 // Load row template and switch color
183 $OUT .= loadTemplate('admin_config_rallye_del_row', true, $content);
186 $content['rows'] = $OUT;
188 // Prepare data for the main template
189 $content['rallye'] = getRequestElement('rallye');
191 // Load main template
192 loadTemplate('admin_config_rallye_del', false, $content);
195 $content = "{--RALLYE_NO_PRICES_SELECTED_1--}<a href=\"{?URL?}/modules.php?module=admin&what=config_rallye_prices&rallye=".getRequestElement('rallye')."\">{--RALLYE_NO_PRICES_SELECTED_2--}</a>{--RALLYE_NO_PRICES_SELECTED_3--}";
196 loadTemplate('admin_settings_saved', false, $content);
199 // a rallye was selected, so check if there are already prices assigned...
200 $result = SQL_QUERY_ESC("SELECT `id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
201 array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__);
203 if (SQL_NUMROWS($result) > 0) {
204 // Load all prices for the selected rallye
206 while ($content = SQL_FETCHARRAY($result)) {
208 if (empty($content['info'])) $content['info'] = '---';
210 // Prepare data for the row template
211 // @TODO Rewritings: level->price_level, infos->info in template
214 'id' => $content['id'],
215 'level' => $content['price_level'],
216 'points' => $content['points'],
217 'infos' => $content['info'],
220 // Load row template and switch color
221 $OUT .= loadTemplate('admin_config_rallye_prices_row', true, $content);
226 SQL_FREERESULT($result);
228 // @TODO Rewrite these two constants
229 $content['rows'] = $OUT;
231 // Prepare data for the main template
232 $content['rallye'] = getRequestElement('rallye');
234 // Load main template
235 loadTemplate('admin_config_rallye_prices', false, $content);
239 // Add form for adding new price level
240 if (!isPostRequestElementSet('edit')) {
241 loadTemplate('admin_add_rallye_prices', false, getRequestElement('rallye'));
244 // No rallye selected so display all available without prices
245 $result = SQL_QUERY("SELECT
246 d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
248 `{?_MYSQL_PREFIX?}_rallye_data` AS d
250 `{?_MYSQL_PREFIX?}_admins` AS a
254 d.start_time DESC", __FILE__, __LINE__);
255 if (SQL_NUMROWS($result) > 0) {
256 // List found rallyes
258 while ($content = SQL_FETCHARRAY($result)) {
259 // Prepare data for the row template
262 'id' => $content['id'],
263 'title' => $content['title'],
264 'admin_id' => $content['admin_id'],
265 'admin_link' => generateAdminLink($content['admin_id']),
266 'login' => $content['login'],
267 'start' => generateDateTime($content['start_time'], 3),
268 'end' => generateDateTime($content['end_time'], 3),
271 // Load row template and switch color
272 $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
277 SQL_FREERESULT($result);
279 // Load main template
280 loadTemplate('admin_list_rallye_prices', false, $OUT);
282 // No rallyes setup so far
283 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_NO_RALLYES_SETUP'));