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 - 2008 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')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
48 if (REQUEST_ISSET_GET(('rallye'))) {
50 if (REQUEST_ISSET_POST(('add'))) {
51 if ((REQUEST_ISSET_POST(('level'))) && ((REQUEST_ISSET_POST(('points'))) || (REQUEST_ISSET_POST(('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(REQUEST_GET('rallye')), bigintval(REQUEST_POST('level'))), __FILE__, __LINE__);
56 if (SQL_NUMROWS($result) == 0) {
57 // Ok, new price level entered!
58 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_rallye_prices` (rallye_id, price_level, points, info)
59 VALUES ('%s','%s','%s','%s')",
61 bigintval(REQUEST_GET('rallye')),
62 bigintval(REQUEST_POST('level')),
63 REQUEST_POST('points'),
65 ), __FILE__, __LINE__);
66 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_PRICE_LEVEL_SAVED'));
69 SQL_FREERESULT($result);
72 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_PRICE_ALREADY_FOUND'));
75 } elseif (REQUEST_ISSET_POST('remove')) {
76 // Check if at last one line is selected
77 $SEL = countPostSelection();
79 // Delete selected entries
80 foreach (REQUEST_POST('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 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_DELETED'));
88 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_NOT_DELETED'));
90 } elseif (REQUEST_ISSET_POST('change')) {
92 foreach (REQUEST_POST('level') as $id => $level) {
97 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_rallye_prices` SET rallye_id=%s, price_level='%s', points='%s', info='%s' WHERE `id`=%s LIMIT 1",
99 REQUEST_POST('rallye_id', $id),
101 REQUEST_POST('points', $id]),
102 REQUEST_POST('infos', $id),
104 ), __FILE__, __LINE__);
108 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_CHANGED'));
111 if (REQUEST_ISSET_POST('edit')) {
112 // Check if at last one line is selected
113 $SEL = countPostSelection();
115 // Make selected editable
117 foreach (REQUEST_POST('sel') as $id => $sel) {
118 // Load data to selected rallye
119 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE `id`=%s LIMIT 1",
120 array(bigintval($id)), __FILE__, __LINE__);
121 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
122 SQL_FREERESULT($result);
124 // Prepare data for the row template
128 'rallyes' => generateOptionList("rallye_data", "id", "title", $rallye),
134 // Load row template and switch color
135 $OUT .= LOAD_TEMPLATE("admin_config_rallye_edit_row", true, $content);
138 define('__PRICE_ROWS', $OUT);
140 // Prepare data for the main template
141 define('__RALLYE_ID', REQUEST_GET('rallye'));
143 // Load main template
144 LOAD_TEMPLATE("admin_config_rallye_edit");
147 $content = sprintf(getMessage('RALLYE_NO_PRICES_SELECTED'), "<a href=\"{!URL!}/modules.php?module=admin&what=config_rallye_prices&rallye=".REQUEST_GET('rallye')."\">", "</a>");
148 LOAD_TEMPLATE('admin_settings_saved', false, $content);
150 } elseif (REQUEST_ISSET_POST('del')) {
151 // Check if at last one line is selected
152 $SEL = countPostSelection();
156 foreach (REQUEST_POST('sel') as $id => $sel) {
157 // Load data to selected rallye
158 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE `id`=%s LIMIT 1",
159 array(bigintval($id)), __FILE__, __LINE__);
160 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
161 SQL_FREERESULT($result);
163 if (empty($infos)) $infos = '---';
165 // Prepare data for the row template
174 // Load row template and switch color
175 $OUT .= LOAD_TEMPLATE("admin_config_rallye_del_row", true, $content);
178 define('__PRICE_ROWS', $OUT);
180 // Prepare data for the main template
181 define('__RALLYE_ID', REQUEST_GET('rallye'));
183 // Load main template
184 LOAD_TEMPLATE("admin_config_rallye_del");
187 $content = RALLYE_NO_PRICES_SELECTED_1."<a href=\"{!URL!}/modules.php?module=admin&what=config_rallye_prices&rallye=".REQUEST_GET('rallye')."\">".RALLYE_NO_PRICES_SELECTED_2."</a>".RALLYE_NO_PRICES_SELECTED_3;
188 LOAD_TEMPLATE('admin_settings_saved', false, $content);
191 // a rallye was selected, so check if there are already prices assigned...
192 $result = SQL_QUERY_ESC("SELECT id, price_level, points, info FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE rallye_id=%s ORDER BY price_level",
193 array(bigintval(REQUEST_GET('rallye'))), __FILE__, __LINE__);
195 if (SQL_NUMROWS($result) > 0) {
196 // Load all prices for the selected rallye
198 while ($content = SQL_FETCHARRAY($result)) {
200 if (empty($content['info'])) $content['info'] = '---';
202 // Prepare data for the row template
203 // @TODO Rewritings: level->price_level, infos->info in template
206 'id' => $content['id'],
207 'level' => $content['price_level'],
208 'points' => $content['points'],
209 'infos' => $content['info'],
212 // Load row template and switch color
213 $OUT .= LOAD_TEMPLATE("admin_config_rallye_prices_row", true, $content);
218 SQL_FREERESULT($result);
220 // @TODO Rewrite these two constants
221 define('__PRICE_ROWS', $OUT);
223 // Prepare data for the main template
224 define('__RALLYE_ID', REQUEST_GET('rallye'));
226 // Load main template
227 LOAD_TEMPLATE("admin_config_rallye_prices");
231 // Add form for adding new price level
232 if (!REQUEST_ISSET_POST('edit')) {
233 LOAD_TEMPLATE("admin_add_rallye_prices", false, REQUEST_GET('rallye'));
236 // No rallye selected so display all available without prices
237 $result = SQL_QUERY("SELECT d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
238 FROM `{!_MYSQL_PREFIX!}_rallye_data` AS d, `{!_MYSQL_PREFIX!}_admins` AS a
239 WHERE d.admin_id=a.id ORDER BY start_time DESC", __FILE__, __LINE__);
240 if (SQL_NUMROWS($result) > 0) {
241 // List found rallyes
243 while ($content = SQL_FETCHARRAY($result)) {
244 $select = "<input type=\"checkbox\" name=\"sel[".$content['id']."]\" class=\"admin_normal\" value=\"1\">";
245 if ($content['is_active'] == 'Y') $select = "<div class=\"big\">".$content['id']."</div>";
247 // Prepare data for the row template
248 // @TODO Rewritings: aid->admin_id, alogin->login in template
251 'id' => $content['id'],
253 'title' => $content['title'],
254 'aid' => $content['admin_id'],
255 'email_link' => generateMemberEmailLink($content['admin_id']),
256 'alogin' => $content['login'],
257 'start' => generateDateTime($content['start_time'], '3'),
258 'end' => generateDateTime($content['end_time'], '3'),
261 // Load row template and switch color
262 $OUT .= LOAD_TEMPLATE("admin_list_rallye_prices_row", true, $content);
267 SQL_FREERESULT($result);
268 define('__RALLYE_ROWS', $OUT);
270 // Load main template
271 LOAD_TEMPLATE("admin_list_rallye_prices");
273 // No rallyes setup so far
274 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_NO_RALLYES_SETUP'));