f21bad00b33d7e39aa4dc7eef2c6c3fbc043c6e0
[mailer.git] / inc / modules / admin / what-config_rallye_prices.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 07/03/2004 *
4  * ================                             Last change: 08/22/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-config_rallye_prices.php                    *
8  * -------------------------------------------------------------------- *
9  * Short description : Setup rallye prices                              *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Rallye-Preise einrichten                         *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 }
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 if (isGetRequestElementSet('rallye')) {
48         // Price submitted?
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__);
54
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')",
59                                 array(
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'));
66                         } else {
67                                 // Free memory
68                                 SQL_FREERESULT($result);
69
70                                 // Price level found!
71                                 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_PRICE_ALREADY_FOUND'));
72                         }
73                 }
74         } elseif (isPostRequestElementSet('remove')) {
75                 // Check if at last one line is selected
76                 $SEL = countPostSelection();
77                 if ($SEL > 0) {
78                         // Delete selected entries
79                         foreach (postRequestElement('sel') as $id => $sel) {
80                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
81                                 array(bigintval($id)), __FILE__, __LINE__);
82                         }
83
84                         // Output message
85                         loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_DELETED'));
86                 } else {
87                         loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_NOT_DELETED'));
88                 }
89         } elseif (isPostRequestElementSet('change')) {
90                 // Change entries
91                 foreach (postRequestElement('level') as $id => $level) {
92                         // Secure id
93                         $id = bigintval($id);
94
95                         // Update entry
96                         SQL_QUERY_ESC("UPDATE
97         `{?_MYSQL_PREFIX?}_rallye_prices`
98 SET
99         `rallye_id`=%s,
100         `price_`level``='%s',
101         `points`='%s',
102         `info`='%s'
103 WHERE
104         `id`=%s
105 LIMIT 1",
106                                 array(
107                                         postRequestElement('rallye_id', $id),
108                                         bigintval($level),
109                                         postRequestElement('points', $id),
110                                         postRequestElement('infos', $id),
111                                         $id
112                                 ), __FILE__, __LINE__);
113                 }
114
115                 // Output message
116                 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_CHANGED'));
117         }
118
119         if (isPostRequestElementSet('edit')) {
120                 // Check if at last one line is selected
121                 $SEL = countPostSelection();
122                 if ($SEL > 0) {
123                         // Make selected editable
124                         $OUT = ''; $SW = 2;
125                         foreach (postRequestElement('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                                 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
130                                 SQL_FREERESULT($result);
131
132                                 // Prepare data for the row template
133                                 $content = array(
134                                         'sw'      => $SW,
135                                         'id'      => $id,
136                                         'rallyes' => generateOptionList('rallye_data', 'id', 'title', $rallye),
137                                         'level'   => $level,
138                                         'points'  => $points,
139                                         'infos'   => $infos,
140                                 );
141
142                                 // Load row template and switch color
143                                 $OUT .= loadTemplate('admin_config_rallye_edit_row', true, $content);
144                                 $SW = 3 - $SW;
145                         }
146                         $content['rows'] = $OUT;
147
148                         // Prepare data for the main template
149                         $content['rallye'] = getRequestElement('rallye');
150
151                         // Load main template
152                         loadTemplate('admin_config_rallye_edit', false, $content);
153                 } else {
154                         // Nothing selected
155                         $content = sprintf(getMessage('RALLYE_NO_PRICES_SELECTED'), "<a href=\"{?URL?}/modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=".getRequestElement('rallye')."\">", "</a>");
156                         loadTemplate('admin_settings_saved', false, $content);
157                 }
158         } elseif (isPostRequestElementSet('del')) {
159                 // Check if at last one line is selected
160                 $SEL = countPostSelection();
161                 if ($SEL > 0) {
162                         // List all prices
163                         $OUT = ''; $SW = 2;
164                         foreach (postRequestElement('sel') as $id => $sel) {
165                                 // Load data to selected rallye
166                                 $result = SQL_QUERY_ESC("SELECT `rallye_id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
167                                         array(bigintval($id)), __FILE__, __LINE__);
168                                 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
169                                 SQL_FREERESULT($result);
170
171                                 if (empty($infos)) $infos = '---';
172
173                                 // Prepare data for the row template
174                                 $content = array(
175                                         'sw'      => $SW,
176                                         'id'      => $id,
177                                         'level'   => $level,
178                                         'points'  => $points,
179                                         'infos'   => $infos,
180                                 );
181
182                                 // Load row template and switch color
183                                 $OUT .= loadTemplate('admin_config_rallye_del_row', true, $content);
184                                 $SW = 3 - $SW;
185                         }
186                         $content['rows'] = $OUT;
187
188                         // Prepare data for the main template
189                         $content['rallye'] = getRequestElement('rallye');
190
191                         // Load main template
192                         loadTemplate('admin_config_rallye_del', false, $content);
193                 } else {
194                         // Nothing selected
195                         $content = "{--RALLYE_NO_PRICES_SELECTED_1--}<a href=\"{?URL?}/modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=".getRequestElement('rallye')."\">{--RALLYE_NO_PRICES_SELECTED_2--}</a>{--RALLYE_NO_PRICES_SELECTED_3--}";
196                         loadTemplate('admin_settings_saved', false, $content);
197                 }
198         } else {
199                 // a rallye was selected, so check if there are already prices assigned...
200                 $result = SQL_QUERY_ESC("SELECT `id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
201                         array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__);
202
203                 if (SQL_NUMROWS($result) > 0) {
204                         // Load all prices for the selected rallye
205                         $OUT = ''; $SW = 2;
206                         while ($content = SQL_FETCHARRAY($result)) {
207                                 // Fix empty info
208                                 if (empty($content['info'])) $content['info'] = '---';
209
210                                 // Prepare data for the row template
211                                 // @TODO Rewritings: level->price_level, infos->info in template
212                                 $content = array(
213                                         'sw'      => $SW,
214                                         'id'      => $content['id'],
215                                         'level'   => $content['price_level'],
216                                         'points'  => $content['points'],
217                                         'infos'   => $content['info'],
218                                 );
219
220                                 // Load row template and switch color
221                                 $OUT .= loadTemplate('admin_config_rallye_prices_row', true, $content);
222                                 $SW = 3 - $SW;
223                         } // END - while
224
225                         // Free memory
226                         SQL_FREERESULT($result);
227
228                         // @TODO Rewrite these two constants
229                         $content['rows'] = $OUT;
230
231                         // Prepare data for the main template
232                         $content['rallye'] = getRequestElement('rallye');
233
234                         // Load main template
235                         loadTemplate('admin_config_rallye_prices', false, $content);
236                 }
237         }
238
239         // Add form for adding new price level
240         if (!isPostRequestElementSet('edit')) {
241                 loadTemplate('admin_add_rallye_prices', false, getRequestElement('rallye'));
242         }
243 } else {
244         // No rallye selected so display all available without prices
245         $result = SQL_QUERY("SELECT
246         d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
247 FROM
248         `{?_MYSQL_PREFIX?}_rallye_data` AS d
249 LEFT JOIN
250         `{?_MYSQL_PREFIX?}_admins` AS a
251 ON
252         d.admin_id=a.id
253 ORDER BY
254         d.start_time DESC", __FILE__, __LINE__);
255         if (SQL_NUMROWS($result) > 0) {
256                 // List found rallyes
257                 $OUT = ''; $SW = 2;
258                 while ($content = SQL_FETCHARRAY($result)) {
259                         // Prepare data for the row template
260                         $content = array(
261                                 'sw'         => $SW,
262                                 'id'         => $content['id'],
263                                 'title'      => $content['title'],
264                                 'admin_id'   => $content['admin_id'],
265                                 'admin_link' => generateAdminLink($content['admin_id']),
266                                 'login'      => $content['login'],
267                                 'start'      => generateDateTime($content['start_time'], 3),
268                                 'end'        => generateDateTime($content['end_time'], 3),
269                         );
270
271                         // Load row template and switch color
272                         $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
273                         $SW = 3 - $SW;
274                 }
275
276                 // Free memory
277                 SQL_FREERESULT($result);
278
279                 // Load main template
280                 loadTemplate('admin_list_rallye_prices', false, $OUT);
281         } else {
282                 // No rallyes setup so far
283                 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_NO_RALLYES_SETUP'));
284         }
285 }
286
287 // [EOF]
288 ?>