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 * 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 if (countPostSelection() > 0) {
77 // Delete selected entries
78 foreach (postRequestElement('sel') as $id => $sel) {
79 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
80 array(bigintval($id)), __FILE__, __LINE__);
84 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_DELETED'));
86 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_NOT_DELETED'));
88 } elseif (isPostRequestElementSet('change')) {
90 foreach (postRequestElement('level') as $id => $level) {
96 `{?_MYSQL_PREFIX?}_rallye_prices`
106 postRequestElement('rallye_id', $id),
108 postRequestElement('points', $id),
109 postRequestElement('infos', $id),
111 ), __FILE__, __LINE__);
115 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_CHANGED'));
118 if (isPostRequestElementSet('edit')) {
119 // Check if at last one line is selected
120 if (countPostSelection() > 0) {
121 // Make selected editable
123 foreach (postRequestElement('sel') as $id => $sel) {
124 // Load data to selected rallye
125 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
126 array(bigintval($id)), __FILE__, __LINE__);
127 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
128 SQL_FREERESULT($result);
130 // Prepare data for the row template
134 'rallyes' => generateOptionList('rallye_data', 'id', 'title', $rallye),
140 // Load row template and switch color
141 $OUT .= loadTemplate('admin_config_rallye_edit_row', true, $content);
144 $content['rows'] = $OUT;
146 // Prepare data for the main template
147 $content['rallye'] = getRequestElement('rallye');
149 // Load main template
150 loadTemplate('admin_config_rallye_edit', false, $content);
153 $content = sprintf(getMessage('RALLYE_NO_PRICES_SELECTED'), "<a href=\"{%url=modules.php?module=admin&what=config_rallye_prices&rallye=".getRequestElement('rallye')."%}\">", "</a>");
154 loadTemplate('admin_settings_saved', false, $content);
156 } elseif (isPostRequestElementSet('del')) {
157 // Check if at last one line is selected
158 if (countPostSelection() > 0) {
161 foreach (postRequestElement('sel') as $id => $sel) {
162 // Load data to selected rallye
163 $result = SQL_QUERY_ESC("SELECT `rallye_id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
164 array(bigintval($id)), __FILE__, __LINE__);
165 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
166 SQL_FREERESULT($result);
168 if (empty($infos)) $infos = '---';
170 // Prepare data for the row template
179 // Load row template and switch color
180 $OUT .= loadTemplate('admin_config_rallye_del_row', true, $content);
183 $content['rows'] = $OUT;
185 // Prepare data for the main template
186 $content['rallye'] = getRequestElement('rallye');
188 // Load main template
189 loadTemplate('admin_config_rallye_del', false, $content);
192 $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--}";
193 loadTemplate('admin_settings_saved', false, $content);
196 // a rallye was selected, so check if there are already prices assigned...
197 $result = SQL_QUERY_ESC("SELECT `id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
198 array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__);
200 if (SQL_NUMROWS($result) > 0) {
201 // Load all prices for the selected rallye
203 while ($content = SQL_FETCHARRAY($result)) {
205 if (empty($content['info'])) $content['info'] = '---';
207 // Prepare data for the row template
208 // @TODO Rewritings: level->price_level, infos->info in template
211 'id' => $content['id'],
212 'level' => $content['price_level'],
213 'points' => $content['points'],
214 'infos' => $content['info'],
217 // Load row template and switch color
218 $OUT .= loadTemplate('admin_config_rallye_prices_row', true, $content);
223 SQL_FREERESULT($result);
225 // @TODO Rewrite these two constants
226 $content['rows'] = $OUT;
228 // Prepare data for the main template
229 $content['rallye'] = getRequestElement('rallye');
231 // Load main template
232 loadTemplate('admin_config_rallye_prices', false, $content);
236 // Add form for adding new price level
237 if (!isPostRequestElementSet('edit')) {
238 loadTemplate('admin_add_rallye_prices', false, getRequestElement('rallye'));
241 // No rallye selected so display all available without prices
242 $result = SQL_QUERY("SELECT
243 d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
245 `{?_MYSQL_PREFIX?}_rallye_data` AS d
247 `{?_MYSQL_PREFIX?}_admins` AS a
251 d.start_time DESC", __FILE__, __LINE__);
252 if (SQL_NUMROWS($result) > 0) {
253 // List found rallyes
255 while ($content = SQL_FETCHARRAY($result)) {
256 // Prepare data for the row template
259 'id' => $content['id'],
260 'title' => $content['title'],
261 'admin_id' => $content['admin_id'],
262 'admin_link' => generateAdminLink($content['admin_id']),
263 'login' => $content['login'],
264 'start' => generateDateTime($content['start_time'], 3),
265 'end' => generateDateTime($content['end_time'], 3),
268 // Load row template and switch color
269 $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
274 SQL_FREERESULT($result);
276 // Load main template
277 loadTemplate('admin_list_rallye_prices', false, $OUT);
279 // No rallyes setup so far
280 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_NO_RALLYES_SETUP'));