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) {
96 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 postRequestElement('rallye_id', $id),
100 postRequestElement('points', $id),
101 postRequestElement('infos', $id),
103 ), __FILE__, __LINE__);
107 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_CHANGED'));
110 if (isPostRequestElementSet('edit')) {
111 // Check if at last one line is selected
112 $SEL = countPostSelection();
114 // Make selected editable
116 foreach (postRequestElement('sel') as $id => $sel) {
117 // Load data to selected rallye
118 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
119 array(bigintval($id)), __FILE__, __LINE__);
120 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
121 SQL_FREERESULT($result);
123 // Prepare data for the row template
127 'rallyes' => generateOptionList("rallye_data", 'id', "title", $rallye),
133 // Load row template and switch color
134 $OUT .= loadTemplate('admin_config_rallye_edit_row', true, $content);
137 $content['rows'] = $OUT;
139 // Prepare data for the main template
140 $content['rallye'] = getRequestElement('rallye');
142 // Load main template
143 loadTemplate('admin_config_rallye_edit', false, $content);
146 $content = sprintf(getMessage('RALLYE_NO_PRICES_SELECTED'), "<a href=\"{?URL?}/modules.php?module=admin&what=config_rallye_prices&rallye=".getRequestElement('rallye')."\">", "</a>");
147 loadTemplate('admin_settings_saved', false, $content);
149 } elseif (isPostRequestElementSet('del')) {
150 // Check if at last one line is selected
151 $SEL = countPostSelection();
155 foreach (postRequestElement('sel') as $id => $sel) {
156 // Load data to selected rallye
157 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
158 array(bigintval($id)), __FILE__, __LINE__);
159 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
160 SQL_FREERESULT($result);
162 if (empty($infos)) $infos = '---';
164 // Prepare data for the row template
173 // Load row template and switch color
174 $OUT .= loadTemplate('admin_config_rallye_del_row', true, $content);
177 $content['rows'] = $OUT;
179 // Prepare data for the main template
180 $content['rallye'] = getRequestElement('rallye');
182 // Load main template
183 loadTemplate('admin_config_rallye_del', false, $content);
186 $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--}";
187 loadTemplate('admin_settings_saved', false, $content);
190 // a rallye was selected, so check if there are already prices assigned...
191 $result = SQL_QUERY_ESC("SELECT `id`, `price_level`, points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
192 array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__);
194 if (SQL_NUMROWS($result) > 0) {
195 // Load all prices for the selected rallye
197 while ($content = SQL_FETCHARRAY($result)) {
199 if (empty($content['info'])) $content['info'] = '---';
201 // Prepare data for the row template
202 // @TODO Rewritings: level->price_level, infos->info in template
205 'id' => $content['id'],
206 'level' => $content['price_level'],
207 'points' => $content['points'],
208 'infos' => $content['info'],
211 // Load row template and switch color
212 $OUT .= loadTemplate('admin_config_rallye_prices_row', true, $content);
217 SQL_FREERESULT($result);
219 // @TODO Rewrite these two constants
220 $content['rows'] = $OUT;
222 // Prepare data for the main template
223 $content['rallye'] = getRequestElement('rallye');
225 // Load main template
226 loadTemplate('admin_config_rallye_prices', false, $content);
230 // Add form for adding new price level
231 if (!isPostRequestElementSet('edit')) {
232 loadTemplate('admin_add_rallye_prices', false, getRequestElement('rallye'));
235 // No rallye selected so display all available without prices
236 $result = SQL_QUERY("SELECT
237 d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
239 `{?_MYSQL_PREFIX?}_rallye_data` AS d
241 `{?_MYSQL_PREFIX?}_admins` AS a
245 d.start_time DESC", __FILE__, __LINE__);
246 if (SQL_NUMROWS($result) > 0) {
247 // List found rallyes
249 while ($content = SQL_FETCHARRAY($result)) {
250 $select = "<input type=\"checkbox\" name=\"sel[".$content['id']."]\" class=\"admin_normal\" value=\"1\">";
251 if ($content['is_active'] == 'Y') $select = "<div class=\"big\">".$content['id']."</div>";
253 // Prepare data for the row template
256 'id' => $content['id'],
258 'title' => $content['title'],
259 'admin_id' => $content['admin_id'],
260 'email_link' => generateEmailLink($content['admin_id']),
261 'login' => $content['login'],
262 'start' => generateDateTime($content['start_time'], 3),
263 'end' => generateDateTime($content['end_time'], 3),
266 // Load row template and switch color
267 $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
272 SQL_FREERESULT($result);
274 // Load main template
275 loadTemplate('admin_list_rallye_prices', false, $OUT);
277 // No rallyes setup so far
278 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_NO_RALLYES_SETUP'));