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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
48 if (isGetRequestParameterSet('rallye')) {
50 if (isFormSent('add')) {
51 if ((isPostRequestParameterSet(('level'))) && ((isPostRequestParameterSet('points')) || (isPostRequestParameterSet(('info'))))) {
52 // Submitted data is valid, but maybe we already have this price level?
53 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s AND `price_level`='%s' LIMIT 1",
54 array(bigintval(getRequestParameter('rallye')), bigintval(postRequestParameter('level'))), __FILE__, __LINE__);
56 if (SQL_HASZERONUMS($result)) {
57 // Ok, new price level entered!
58 SQL_QUERY_ESC("INSERT INTO
59 `{?_MYSQL_PREFIX?}_rallye_prices`
60 (`rallye_id`, `price_level`, `points`, `info`)
62 (%s, %s, '%s', '%s')",
64 bigintval(getRequestParameter('rallye')),
65 bigintval(postRequestParameter('level')),
66 postRequestParameter('points'),
67 postRequestParameter('info')
68 ), __FILE__, __LINE__);
69 loadTemplate('admin_settings_saved', false, '{--RALLYE_PRICE_LEVEL_SAVED--}');
72 SQL_FREERESULT($result);
75 loadTemplate('admin_settings_saved', false, '{--RALLYE_PRICE_ALREADY_FOUND--}');
78 } elseif (isFormSent('remove')) {
79 // Check if at last one line is selected
80 if (countPostSelection() > 0) {
81 // Delete selected entries
82 foreach (postRequestParameter('sel') as $id => $sel) {
83 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
84 array(bigintval($id)), __FILE__, __LINE__);
88 loadTemplate('admin_settings_saved', false, '{--RALLYE_ENTRIES_DELETED--}');
90 loadTemplate('admin_settings_saved', false, '{--RALLYE_ENTRIES_NOT_DELETED--}');
92 } elseif (isFormSent('change')) {
94 foreach (postRequestParameter('level') as $id => $level) {
100 `{?_MYSQL_PREFIX?}_rallye_prices`
110 postRequestParameter('rallye_id', $id),
112 postRequestParameter('points', $id),
113 postRequestParameter('infos', $id),
115 ), __FILE__, __LINE__);
119 loadTemplate('admin_settings_saved', false, '{--RALLYE_ENTRIES_CHANGED--}');
122 if (isFormSent('edit')) {
123 // Check if at last one line is selected
124 if (countPostSelection() > 0) {
125 // Make selected editable
127 foreach (postRequestParameter('sel') as $id => $sel) {
128 // Load data to selected rallye
129 $result = SQL_QUERY_ESC("SELECT `rallye_id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
130 array(bigintval($id)), __FILE__, __LINE__);
131 $content = SQL_FETCHARRAY($result);
132 SQL_FREERESULT($result);
135 $content['sw'] = $SW;
136 $content['rallye_content'] = generateOptionList('rallye_data', 'id', 'title', $content['rallye_id']);
138 // Load row template and switch color
139 $OUT .= loadTemplate('admin_config_rallye_edit_row', true, $content);
143 // Remember row content
144 $content['rows'] = $OUT;
146 // Prepare data for the main template
147 $content['rallye'] = getRequestParameter('rallye');
149 // Load main template
150 loadTemplate('admin_config_rallye_edit', false, $content);
153 $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--}';
154 loadTemplate('admin_settings_saved', false, $content);
156 } elseif (isFormSent('del')) {
157 // Check if at last one line is selected
158 if (countPostSelection() > 0) {
161 foreach (postRequestParameter('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 $content = SQL_FETCHARRAY($result);
166 SQL_FREERESULT($result);
169 $content['sw'] = $SW;
171 // Load row template and switch color
172 $OUT .= loadTemplate('admin_config_rallye_del_row', true, $content);
175 $content['rows'] = $OUT;
177 // Prepare data for the main template
178 $content['rallye'] = getRequestParameter('rallye');
180 // Load main template
181 loadTemplate('admin_config_rallye_del', false, $content);
184 $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--}';
185 loadTemplate('admin_settings_saved', false, $content);
188 // a rallye was selected, so check if there are already prices assigned...
189 $result = SQL_QUERY_ESC("SELECT `id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
190 array(bigintval(getRequestParameter('rallye'))), __FILE__, __LINE__);
192 if (SQL_NUMROWS($result) > 0) {
193 // Load all prices for the selected rallye
195 while ($content = SQL_FETCHARRAY($result)) {
197 $content['sw'] = $SW;
199 // Load row template and switch color
200 $OUT .= loadTemplate('admin_config_rallye_prices_row', true, $content);
205 SQL_FREERESULT($result);
207 // @TODO Rewrite these two constants
208 $content['rows'] = $OUT;
210 // Prepare data for the main template
211 $content['rallye'] = getRequestParameter('rallye');
213 // Load main template
214 loadTemplate('admin_config_rallye_prices', false, $content);
218 // Add form for adding new price level
219 if (!isFormSent('edit')) {
220 loadTemplate('admin_add_rallye_prices', false, getRequestParameter('rallye'));
223 // No rallye selected so display all available without prices
224 $result = SQL_QUERY("SELECT
225 d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
227 `{?_MYSQL_PREFIX?}_rallye_data` AS d
229 `{?_MYSQL_PREFIX?}_admins` AS a
233 d.start_time DESC", __FILE__, __LINE__);
234 if (SQL_NUMROWS($result) > 0) {
235 // List found rallyes
237 while ($content = SQL_FETCHARRAY($result)) {
238 // Prepare data for the row template
241 'id' => $content['id'],
242 'title' => $content['title'],
243 'admin_id' => $content['admin_id'],
244 'login' => $content['login'],
245 'start' => generateDateTime($content['start_time'], 3),
246 'end' => generateDateTime($content['end_time'], 3),
249 // Load row template and switch color
250 $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
255 SQL_FREERESULT($result);
257 // Load main template
258 loadTemplate('admin_list_rallye_prices', false, $OUT);
260 // No rallyes setup so far
261 loadTemplate('admin_settings_saved', false, '{--RALLYE_NO_RALLYES_SETUP--}');