2 /************************************************************************
\r
3 * MXChange v0.2.1 Start: 07/03/2004 *
\r
4 * ================ Last change: 08/22/2004 *
\r
6 * -------------------------------------------------------------------- *
\r
7 * File : what-config_rallye_prices.php *
\r
8 * -------------------------------------------------------------------- *
\r
9 * Short description : Setup rallye prices *
\r
10 * -------------------------------------------------------------------- *
\r
11 * Kurzbeschreibung : Rallye-Preise einrichten *
\r
12 * -------------------------------------------------------------------- *
\r
14 * -------------------------------------------------------------------- *
\r
15 * Copyright (c) 2003 - 2007 by Roland Haeder *
\r
16 * For more information visit: http://www.mxchange.org *
\r
18 * This program is free software; you can redistribute it and/or modify *
\r
19 * it under the terms of the GNU General Public License as published by *
\r
20 * the Free Software Foundation; either version 2 of the License, or *
\r
21 * (at your option) any later version. *
\r
23 * This program is distributed in the hope that it will be useful, *
\r
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
\r
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
\r
26 * GNU General Public License for more details. *
\r
28 * You should have received a copy of the GNU General Public License *
\r
29 * along with this program; if not, write to the Free Software *
\r
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
\r
31 * MA 02110-1301 USA *
\r
32 ************************************************************************/
\r
34 // Some security stuff...
\r
35 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
\r
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
\r
40 // Add description as navigation point
\r
41 ADD_DESCR("admin", basename(__FILE__));
\r
43 if (!empty($_GET['rallye']))
\r
46 if (isset($_POST['add']))
\r
48 if ((!empty($_POST['level'])) && ((!empty($_POST['points'])) || (!empty($_POST['info']))))
\r
50 // Submitted data is valid, but maybe we already have this price level?
\r
51 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id=%d AND price_level='%s' LIMIT 1",
\r
52 array(bigintval($_GET['rallye']), bigintval($_POST['level'])), __FILE__, __LINE__);
\r
54 if (SQL_NUMROWS($result) == 0)
\r
56 // Ok, new price level entered!
\r
57 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_rallye_prices (rallye_id, price_level, points, info)
\r
58 VALUES ('%s', '%s', '%s', '%s')",
\r
60 bigintval($_GET['rallye']),
\r
61 bigintval($_POST['level']),
\r
64 ), __FILE__, __LINE__);
\r
65 LOAD_TEMPLATE ("admin_settings_saved", false, RALLYE_PRICE_LEVEL_SAVED);
\r
70 SQL_FREERESULT($result);
\r
72 // Price level found!
\r
73 LOAD_TEMPLATE ("admin_settings_saved", false, RALLYE_PRICE_ALREADY_FOUND);
\r
77 elseif (isset($_POST['remove']))
\r
79 // Check if at last one line is selected
\r
80 $SEL = SELECTION_COUNT($_POST['sel']);
\r
83 // Delete selected entries
\r
84 foreach ($_POST['sel'] as $id=>$sel)
\r
86 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_rallye_prices WHERE id=%d LIMIT 1",
\r
87 array(bigintval($id)), __FILE__, __LINE__);
\r
91 LOAD_TEMPLATE ("admin_settings_saved", false, RALLYE_ENTRIES_DELETED);
\r
95 LOAD_TEMPLATE ("admin_settings_saved", false, RALLYE_ENTRIES_NOT_DELETED);
\r
98 elseif (isset($_POST['change']))
\r
101 foreach ($_POST['level'] as $id=>$level)
\r
104 $id = bigintval($id);
\r
107 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_rallye_prices SET rallye_id=%d, price_level='%s', points='%s', info='%s' WHERE id=%d LIMIT 1",
\r
108 array($_POST['rallye_id'][$id], bigintval($level), $_POST['points'][$id], $_POST['infos'][$id], $id), __FILE__, __LINE__);
\r
112 LOAD_TEMPLATE ("admin_settings_saved", false, RALLYE_ENTRIES_CHANGED);
\r
115 if (isset($_POST['edit']))
\r
117 // Check if at last one line is selected
\r
118 $SEL = SELECTION_COUNT($_POST['sel']);
\r
121 // Make selected editable
\r
122 $SW = 2; $OUT = "";
\r
123 foreach ($_POST['sel'] as $id=>$sel)
\r
125 // Load data to selected rallye
\r
126 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM "._MYSQL_PREFIX."_rallye_prices WHERE id=%d LIMIT 1",
\r
127 array(bigintval($id)), __FILE__, __LINE__);
\r
128 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
\r
129 SQL_FREERESULT($result);
\r
131 // Prepare data for the row template
\r
135 'rallyes' => ADD_OPTION_LINES("rallye_data", "id", "title", $rallye),
\r
137 'points' => $points,
\r
141 // Load row template and switch color
\r
142 $OUT .= LOAD_TEMPLATE("admin_config_rallye_edit_row", true, $content);
\r
145 define('__PRICE_ROWS', $OUT);
\r
147 // Prepare data for the main template
\r
148 define('__RALLYE_ID', $_GET['rallye']);
\r
150 // Load main template
\r
151 LOAD_TEMPLATE("admin_config_rallye_edit");
\r
155 // Nothing selected
\r
156 $content = RALLYE_NO_PRICES_SELECTED_1."<A href=\"".URL."/modules.php?module=admin&what=config_rallye_prices&rallye=".$_GET['rallye']."\">".RALLYE_NO_PRICES_SELECTED_2."</A>".RALLYE_NO_PRICES_SELECTED_3;
\r
157 LOAD_TEMPLATE("admin_settings_saved", false, $content);
\r
160 elseif (isset($_POST['del']))
\r
162 // Check if at last one line is selected
\r
163 $SEL = SELECTION_COUNT($_POST['sel']);
\r
167 $SW = 2; $OUT = "";
\r
168 foreach ($_POST['sel'] as $id=>$sel)
\r
170 // Load data to selected rallye
\r
171 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM "._MYSQL_PREFIX."_rallye_prices WHERE id=%d LIMIT 1",
\r
172 array(bigintval($id)), __FILE__, __LINE__);
\r
173 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
\r
174 SQL_FREERESULT($result);
\r
176 if (empty($infos)) $infos = "---";
\r
178 // Prepare data for the row template
\r
183 'points' => $points,
\r
187 // Load row template and switch color
\r
188 $OUT .= LOAD_TEMPLATE("admin_config_rallye_del_row", true, $content);
\r
191 define('__PRICE_ROWS', $OUT);
\r
193 // Prepare data for the main template
\r
194 define('__RALLYE_ID', $_GET['rallye']);
\r
196 // Load main template
\r
197 LOAD_TEMPLATE("admin_config_rallye_del");
\r
201 // Nothing selected
\r
202 $content = RALLYE_NO_PRICES_SELECTED_1."<A href=\"".URL."/modules.php?module=admin&what=config_rallye_prices&rallye=".$_GET['rallye']."\">".RALLYE_NO_PRICES_SELECTED_2."</A>".RALLYE_NO_PRICES_SELECTED_3;
\r
203 LOAD_TEMPLATE("admin_settings_saved", false, $content);
\r
208 // A rallye was selected, so check if there are already prices assigned...
\r
209 $result = SQL_QUERY_ESC("SELECT id, price_level, points, info FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id=%d ORDER BY price_level",
\r
210 array(bigintval($_GET['rallye'])), __FILE__, __LINE__);
\r
212 if (SQL_NUMROWS($result) > 0)
\r
214 // Load all prices for the selected rallye
\r
215 $SW = 2; $OUT = "";
\r
216 while(list($id, $level, $points, $infos) = SQL_FETCHROW($result))
\r
218 if (empty($infos)) $infos = "---";
\r
220 // Prepare data for the row template
\r
225 'points' => $points,
\r
229 // Load row template and switch color
\r
230 $OUT .= LOAD_TEMPLATE("admin_config_rallye_prices_row", true, $content);
\r
235 SQL_FREERESULT($result);
\r
236 define('__PRICE_ROWS', $OUT);
\r
238 // Prepare data for the main template
\r
239 define('__RALLYE_ID', $_GET['rallye']);
\r
241 // Load main template
\r
242 LOAD_TEMPLATE("admin_config_rallye_prices");
\r
246 // Add form for adding new price level
\r
247 if (empty($_POST['edit']))
\r
249 LOAD_TEMPLATE("admin_add_rallye_prices", false, $_GET['rallye']);
\r
254 // No rallye selected so display all available without prices
\r
255 $result = SQL_QUERY("SELECT d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
\r
256 FROM "._MYSQL_PREFIX."_rallye_data AS d, "._MYSQL_PREFIX."_admins AS a
\r
257 WHERE d.admin_id=a.id ORDER BY start_time DESC", __FILE__, __LINE__);
\r
258 if (SQL_NUMROWS($result) > 0)
\r
260 // List found rallyes
\r
261 $SW = 2; $OUT = "";
\r
262 while (list($id, $aid, $start, $end, $title, $alogin, $active) = SQL_FETCHROW($result))
\r
264 $select = "<INPUT type=\"checkbox\" name=\"sel[".$id."]\" class=\"admin_normal\" value=\"1\">";
\r
265 if ($active == "Y") $select = "<STRONG class=\"big\">".$id."</STRONG>";
\r
267 // Prepare data for the row template
\r
271 'select' => $select,
\r
274 'email_link' => CREATE_EMAIL_LINK($aid),
\r
275 'alogin' => $alogin,
\r
276 'start' => MAKE_DATETIME($start, "3"),
\r
277 'end' => MAKE_DATETIME($end, "3"),
\r
280 // Load row template and switch color
\r
281 $OUT .= LOAD_TEMPLATE("admin_list_rallye_prices_row", true, $content);
\r
286 SQL_FREERESULT($result);
\r
287 define('__RALLYE_ROWS', $OUT);
\r
289 // Load main template
\r
290 LOAD_TEMPLATE("admin_list_rallye_prices");
\r
294 // No rallyes setup so far
\r
295 LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_NO_RALLYES_SETUP);
\r