d2933e6ec14ae0c93af466a2f6666113bd3bbeda
[mailer.git] / inc / modules / admin / what-config_rallye_prices.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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                 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__);
81                         }
82
83                         // Output message
84                         loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_DELETED'));
85                 } else {
86                         loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_NOT_DELETED'));
87                 }
88         } elseif (isPostRequestElementSet('change')) {
89                 // Change entries
90                 foreach (postRequestElement('level') as $id => $level) {
91                         // Secure id
92                         $id = bigintval($id);
93
94                         // Update entry
95                         SQL_QUERY_ESC("UPDATE
96         `{?_MYSQL_PREFIX?}_rallye_prices`
97 SET
98         `rallye_id`=%s,
99         `price_level`=%d,
100         `points`=%s,
101         `info`='%s'
102 WHERE
103         `id`=%s
104 LIMIT 1",
105                                 array(
106                                         postRequestElement('rallye_id', $id),
107                                         bigintval($level),
108                                         postRequestElement('points', $id),
109                                         postRequestElement('infos', $id),
110                                         $id
111                                 ), __FILE__, __LINE__);
112                 }
113
114                 // Output message
115                 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_CHANGED'));
116         }
117
118         if (isPostRequestElementSet('edit')) {
119                 // Check if at last one line is selected
120                 if (countPostSelection() > 0) {
121                         // Make selected editable
122                         $OUT = ''; $SW = 2;
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);
129
130                                 // Prepare data for the row template
131                                 $content = array(
132                                         'sw'      => $SW,
133                                         'id'      => $id,
134                                         'rallyes' => generateOptionList('rallye_data', 'id', 'title', $rallye),
135                                         'level'   => $level,
136                                         'points'  => $points,
137                                         'infos'   => $infos,
138                                 );
139
140                                 // Load row template and switch color
141                                 $OUT .= loadTemplate('admin_config_rallye_edit_row', true, $content);
142                                 $SW = 3 - $SW;
143                         }
144                         $content['rows'] = $OUT;
145
146                         // Prepare data for the main template
147                         $content['rallye'] = getRequestElement('rallye');
148
149                         // Load main template
150                         loadTemplate('admin_config_rallye_edit', false, $content);
151                 } else {
152                         // Nothing selected
153                         $content = sprintf(getMessage('RALLYE_NO_PRICES_SELECTED'), "<a href=\"{?URL?}/modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=".getRequestElement('rallye')."\">", "</a>");
154                         loadTemplate('admin_settings_saved', false, $content);
155                 }
156         } elseif (isPostRequestElementSet('del')) {
157                 // Check if at last one line is selected
158                 if (countPostSelection() > 0) {
159                         // List all prices
160                         $OUT = ''; $SW = 2;
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);
167
168                                 if (empty($infos)) $infos = '---';
169
170                                 // Prepare data for the row template
171                                 $content = array(
172                                         'sw'      => $SW,
173                                         'id'      => $id,
174                                         'level'   => $level,
175                                         'points'  => $points,
176                                         'infos'   => $infos,
177                                 );
178
179                                 // Load row template and switch color
180                                 $OUT .= loadTemplate('admin_config_rallye_del_row', true, $content);
181                                 $SW = 3 - $SW;
182                         }
183                         $content['rows'] = $OUT;
184
185                         // Prepare data for the main template
186                         $content['rallye'] = getRequestElement('rallye');
187
188                         // Load main template
189                         loadTemplate('admin_config_rallye_del', false, $content);
190                 } else {
191                         // Nothing selected
192                         $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--}";
193                         loadTemplate('admin_settings_saved', false, $content);
194                 }
195         } else {
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__);
199
200                 if (SQL_NUMROWS($result) > 0) {
201                         // Load all prices for the selected rallye
202                         $OUT = ''; $SW = 2;
203                         while ($content = SQL_FETCHARRAY($result)) {
204                                 // Fix empty info
205                                 if (empty($content['info'])) $content['info'] = '---';
206
207                                 // Prepare data for the row template
208                                 // @TODO Rewritings: level->price_level, infos->info in template
209                                 $content = array(
210                                         'sw'      => $SW,
211                                         'id'      => $content['id'],
212                                         'level'   => $content['price_level'],
213                                         'points'  => $content['points'],
214                                         'infos'   => $content['info'],
215                                 );
216
217                                 // Load row template and switch color
218                                 $OUT .= loadTemplate('admin_config_rallye_prices_row', true, $content);
219                                 $SW = 3 - $SW;
220                         } // END - while
221
222                         // Free memory
223                         SQL_FREERESULT($result);
224
225                         // @TODO Rewrite these two constants
226                         $content['rows'] = $OUT;
227
228                         // Prepare data for the main template
229                         $content['rallye'] = getRequestElement('rallye');
230
231                         // Load main template
232                         loadTemplate('admin_config_rallye_prices', false, $content);
233                 }
234         }
235
236         // Add form for adding new price level
237         if (!isPostRequestElementSet('edit')) {
238                 loadTemplate('admin_add_rallye_prices', false, getRequestElement('rallye'));
239         }
240 } else {
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
244 FROM
245         `{?_MYSQL_PREFIX?}_rallye_data` AS d
246 LEFT JOIN
247         `{?_MYSQL_PREFIX?}_admins` AS a
248 ON
249         d.admin_id=a.id
250 ORDER BY
251         d.start_time DESC", __FILE__, __LINE__);
252         if (SQL_NUMROWS($result) > 0) {
253                 // List found rallyes
254                 $OUT = ''; $SW = 2;
255                 while ($content = SQL_FETCHARRAY($result)) {
256                         // Prepare data for the row template
257                         $content = array(
258                                 'sw'         => $SW,
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),
266                         );
267
268                         // Load row template and switch color
269                         $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
270                         $SW = 3 - $SW;
271                 }
272
273                 // Free memory
274                 SQL_FREERESULT($result);
275
276                 // Load main template
277                 loadTemplate('admin_list_rallye_prices', false, $OUT);
278         } else {
279                 // No rallyes setup so far
280                 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_NO_RALLYES_SETUP'));
281         }
282 }
283
284 // [EOF]
285 ?>