2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.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 (isGetRequestParameterSet('rallye')) {
48 if (isFormSent('add')) {
49 if ((isPostRequestParameterSet('level')) && ((isPostRequestParameterSet('points')) || (isPostRequestParameterSet('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(getRequestParameter('rallye')), bigintval(postRequestParameter('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(getRequestParameter('rallye')),
63 bigintval(postRequestParameter('level')),
64 postRequestParameter('points'),
65 postRequestParameter('info')
66 ), __FILE__, __LINE__);
67 displayMessage('{--RALLYE_PRICE_LEVEL_SAVED--}');
70 SQL_FREERESULT($result);
73 displayMessage('{--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 (postRequestParameter('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('{--RALLYE_ENTRIES_DELETED--}');
88 displayMessage('{--RALLYE_ENTRIES_NOT_DELETED--}');
90 } elseif (isFormSent('do_edit')) {
92 foreach (postRequestParameter('level') as $id => $level) {
98 `{?_MYSQL_PREFIX?}_rallye_prices`
108 postRequestParameter('rallye_id', $id),
110 postRequestParameter('points', $id),
111 postRequestParameter('infos', $id),
113 ), __FILE__, __LINE__);
117 displayMessage('{--RALLYE_ENTRIES_CHANGED--}');
120 if (isFormSent('edit')) {
121 // Check if at last one line is selected
122 if (ifPostContainsSelections()) {
123 // Make selected editable
125 foreach (postRequestParameter('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 $content = SQL_FETCHARRAY($result);
130 SQL_FREERESULT($result);
133 $content['rallye_content'] = generateOptionList('rallye_data', 'id', 'title', $content['rallye_id']);
135 // Load row template and switch color
136 $OUT .= loadTemplate('admin_config_rallye_edit_row', true, $content);
139 // Remember row content
140 $content['rows'] = $OUT;
142 // Prepare data for the main template
143 $content['rallye'] = getRequestParameter('rallye');
145 // Load main template
146 loadTemplate('admin_config_rallye_edit', false, $content);
149 $content = '{--RALLYE_NO_PRICES_SELECTED_1--}<a href="{%url=modules.php?module=admin&what=config_rallye_prices&rallye=' . getRequestParameter('rallye') . '%}">{--RALLYE_NO_PRICES_SELECTED_2--}</a>{--RALLYE_NO_PRICES_SELECTED_3--}';
150 displayMessage($content);
152 } elseif (isFormSent('delete')) {
153 // Check if at last one line is selected
154 if (ifPostContainsSelections()) {
157 foreach (postRequestParameter('sel') as $id => $sel) {
158 // Load data to selected rallye
159 $result = SQL_QUERY_ESC("SELECT `rallye_id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
160 array(bigintval($id)), __FILE__, __LINE__);
161 $content = SQL_FETCHARRAY($result);
162 SQL_FREERESULT($result);
164 // Load row template and switch color
165 $OUT .= loadTemplate('admin_config_rallye_del_row', true, $content);
167 $content['rows'] = $OUT;
169 // Prepare data for the main template
170 $content['rallye'] = getRequestParameter('rallye');
172 // Load main template
173 loadTemplate('admin_config_rallye_del', false, $content);
176 $content = '{--RALLYE_NO_PRICES_SELECTED_1--}<a href="{%url=modules.php?module=admin&what=config_rallye_prices&rallye=' . getRequestParameter('rallye') . '%}">{--RALLYE_NO_PRICES_SELECTED_2--}</a>{--RALLYE_NO_PRICES_SELECTED_3--}';
177 displayMessage($content);
180 // a rallye was selected, so check if there are already prices assigned...
181 $result = SQL_QUERY_ESC("SELECT `id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
182 array(bigintval(getRequestParameter('rallye'))), __FILE__, __LINE__);
184 if (!SQL_HASZERONUMS($result)) {
185 // Load all prices for the selected rallye
187 while ($content = SQL_FETCHARRAY($result)) {
188 // Load row template and switch color
189 $OUT .= loadTemplate('admin_config_rallye_prices_row', true, $content);
193 SQL_FREERESULT($result);
195 // @TODO Rewrite these two constants
196 $content['rows'] = $OUT;
198 // Prepare data for the main template
199 $content['rallye'] = getRequestParameter('rallye');
201 // Load main template
202 loadTemplate('admin_config_rallye_prices', false, $content);
206 // Add form for adding new price level
207 if (!isFormSent('edit')) {
208 loadTemplate('admin_add_rallye_prices', false, getRequestParameter('rallye'));
211 // No rallye selected so display all available without prices
212 $result = SQL_QUERY("SELECT
213 d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
215 `{?_MYSQL_PREFIX?}_rallye_data` AS d
217 `{?_MYSQL_PREFIX?}_admins` AS a
221 d.start_time DESC", __FILE__, __LINE__);
222 if (!SQL_HASZERONUMS($result)) {
223 // List found rallyes
225 while ($content = SQL_FETCHARRAY($result)) {
226 // Prepare data for the row template
227 // @TODO rename: start->start_time, end->end_time
228 $content['start'] = generateDateTime($content['start_time'], '3');
229 $content['end'] = generateDateTime($content['end_time'] , '3');
231 // Load row template and switch color
232 $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
236 SQL_FREERESULT($result);
238 // Load main template
239 loadTemplate('admin_list_rallye_prices', false, $OUT);
241 // No rallyes setup so far
242 displayMessage('{--RALLYE_NO_RALLYES_SETUP--}');