2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 07/03/2004 *
4 * =================== Last change: 08/22/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-list_rallye_prices.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Setup rallye prices *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Rallye-Preise einrichten *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
46 if (isGetRequestElementSet('rallye_id')) {
48 if (isFormSent('add')) {
49 if ((isPostRequestElementSet('level')) && ((isPostRequestElementSet('points')) || (isPostRequestElementSet('info')))) {
50 // Submitted data is valid, but maybe we already have this price level?
51 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s AND `price_level`='%s' LIMIT 1",
52 array(bigintval(getRequestElement('rallye_id')), bigintval(postRequestElement('level'))), __FILE__, __LINE__);
54 if (SQL_HASZERONUMS($result)) {
55 // Ok, new price level entered!
56 SQL_QUERY_ESC("INSERT INTO
57 `{?_MYSQL_PREFIX?}_rallye_prices`
58 (`rallye_id`, `price_level`, `points`, `info`)
60 (%s, %s, '%s', '%s')",
62 bigintval(getRequestElement('rallye_id')),
63 bigintval(postRequestElement('level')),
64 convertCommaToDot(postRequestElement('points')),
65 postRequestElement('info')
66 ), __FILE__, __LINE__);
67 displayMessage('{--ADMIN_RALLYE_PRICE_LEVEL_SAVED--}');
70 SQL_FREERESULT($result);
73 displayMessage('{--ADMIN_RALLYE_PRICE_ALREADY_FOUND--}');
76 } elseif (isFormSent('do_delete')) {
77 // Check if at last one line is selected
78 if (ifPostContainsSelections()) {
79 // Delete selected entries
80 foreach (postRequestElement('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__);
86 displayMessage('{--ADMIN_RALLYE_PRICES_DELETED--}');
88 displayMessage('{--ADMIN_RALLYE_PRICES_NOT_DELETED--}');
90 } elseif (isFormSent('do_edit')) {
92 foreach (postRequestElement('level') as $id => $level) {
98 `{?_MYSQL_PREFIX?}_rallye_prices`
108 postRequestElement('rallye_id', $id),
110 convertCommaToDot(postRequestElement('points', $id)),
111 postRequestElement('info', $id),
113 ), __FILE__, __LINE__);
117 displayMessage('{--ADMIN_RALLYE_PRICES_CHANGED--}');
120 if (isFormSent('edit')) {
121 // Check if at last one line is selected
122 if (ifPostContainsSelections()) {
123 // Make selected editable
125 foreach (postRequestElement('sel') as $id => $sel) {
126 // Load data to selected rallye
127 $result = SQL_QUERY_ESC("SELECT
134 `{?_MYSQL_PREFIX?}_rallye_prices`
138 array(bigintval($id)), __FILE__, __LINE__);
141 $content = SQL_FETCHARRAY($result);
144 SQL_FREERESULT($result);
147 $content['rallye_content'] = generateOptions('rallye_data', 'id', 'title', $content['rallye_id']);
149 // Load row template and switch color
150 $OUT .= loadTemplate('admin_edit_rallye_prices_row', TRUE, $content);
153 // Remember row content
154 $content['rows'] = $OUT;
156 // Prepare data for the main template
157 $content['rallye_id'] = bigintval(getRequestElement('rallye_id'));
159 // Load main template
160 loadTemplate('admin_edit_rallye_prices', FALSE, $content);
163 displayMessage('{%message,ADMIN_RALLYE_NO_PRICES_SELECTED=' . getRequestElement('rallye_id') . '%}');
165 } elseif (isFormSent('delete')) {
166 // Check if at last one line is selected
167 if (ifPostContainsSelections()) {
170 foreach (postRequestElement('sel') as $id => $sel) {
171 // Load data to selected rallye
172 $result = SQL_QUERY_ESC("SELECT
179 `{?_MYSQL_PREFIX?}_rallye_prices`
183 array(bigintval($id)), __FILE__, __LINE__);
186 $content = SQL_FETCHARRAY($result);
189 SQL_FREERESULT($result);
191 // Load row template and switch color
192 $OUT .= loadTemplate('admin_delete_rallye_prices_row', TRUE, $content);
194 $content['rows'] = $OUT;
196 // Prepare data for the main template
197 $content['rallye_id'] = bigintval(getRequestElement('rallye_id'));
199 // Load main template
200 loadTemplate('admin_delete_rallye_prices', FALSE, $content);
203 $content = '{--RALLYE_NO_PRICES_SELECTED_1--}<a href="{%url=modules.php?module=admin&what=list_rallye_prices&rallye_id=' . getRequestElement('rallye_id') . '%}">{--RALLYE_NO_PRICES_SELECTED_2--}</a>{--RALLYE_NO_PRICES_SELECTED_3--}';
204 displayMessage($content);
207 // A rallye was selected, so check if there are already prices assigned...
208 $result = SQL_QUERY_ESC("SELECT `id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
209 array(bigintval(getRequestElement('rallye_id'))), __FILE__, __LINE__);
211 if (!SQL_HASZERONUMS($result)) {
212 // Load all prices for the selected rallye
214 while ($content = SQL_FETCHARRAY($result)) {
215 // Load row template and switch color
216 $OUT .= loadTemplate('admin_list_rallye_prices_simple_row', TRUE, $content);
220 SQL_FREERESULT($result);
222 // @TODO Rewrite these two constants
223 $content['rows'] = $OUT;
225 // Prepare data for the main template
226 $content['rallye_id'] = bigintval(getRequestElement('rallye_id'));
228 // Load main template
229 loadTemplate('admin_list_rallye_prices_simple', FALSE, $content);
233 // Add form for adding new price level
234 if ((!isFormSent('edit')) && (!isFormSent('delete'))) {
235 loadTemplate('admin_add_rallye_prices', FALSE, getRequestElement('rallye_id'));
238 // No rallye selected so display all available without prices
239 $result = SQL_QUERY("SELECT
248 `{?_MYSQL_PREFIX?}_rallye_data` AS d
250 `{?_MYSQL_PREFIX?}_admins` AS a
254 d.start_time DESC", __FILE__, __LINE__);
255 if (!SQL_HASZERONUMS($result)) {
256 // List found rallyes
258 while ($content = SQL_FETCHARRAY($result)) {
259 // Prepare data for the row template
260 $content['start_time'] = generateDateTime($content['start_time'], '3');
261 $content['end_time'] = generateDateTime($content['end_time'] , '3');
263 // Load row template and switch color
264 $OUT .= loadTemplate('admin_list_rallye_prices_row', TRUE, $content);
268 SQL_FREERESULT($result);
270 // Load main template
271 loadTemplate('admin_list_rallye_prices', FALSE, $OUT);
273 // No rallyes setup so far
274 displayMessage('{--ADMIN_RALLYE_NO_RALLYES_SETUP--}');