Deprecated variables for templates removed, mor EL-rewrites, getMessage() rewritten:
[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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
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.                                  *
28  *                                                                      *
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.                         *
33  *                                                                      *
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,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if (isGetRequestParameterSet('rallye')) {
49         // Price submitted?
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__);
55
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`)
61         VALUES
62 (%s, %s, '%s', '%s')",
63                                 array(
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--}');
70                         } else {
71                                 // Free memory
72                                 SQL_FREERESULT($result);
73
74                                 // Price level found!
75                                 loadTemplate('admin_settings_saved', false, '{--RALLYE_PRICE_ALREADY_FOUND--}');
76                         }
77                 }
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__);
85                         } // END - foreach
86
87                         // Output message
88                         loadTemplate('admin_settings_saved', false, '{--RALLYE_ENTRIES_DELETED--}');
89                 } else {
90                         loadTemplate('admin_settings_saved', false, '{--RALLYE_ENTRIES_NOT_DELETED--}');
91                 }
92         } elseif (isFormSent('change')) {
93                 // Change entries
94                 foreach (postRequestParameter('level') as $id => $level) {
95                         // Secure id
96                         $id = bigintval($id);
97
98                         // Update entry
99                         SQL_QUERY_ESC("UPDATE
100         `{?_MYSQL_PREFIX?}_rallye_prices`
101 SET
102         `rallye_id`=%s,
103         `price_level`=%d,
104         `points`=%s,
105         `info`='%s'
106 WHERE
107         `id`=%s
108 LIMIT 1",
109                                 array(
110                                         postRequestParameter('rallye_id', $id),
111                                         bigintval($level),
112                                         postRequestParameter('points', $id),
113                                         postRequestParameter('infos', $id),
114                                         $id
115                                 ), __FILE__, __LINE__);
116                 }
117
118                 // Output message
119                 loadTemplate('admin_settings_saved', false, '{--RALLYE_ENTRIES_CHANGED--}');
120         }
121
122         if (isFormSent('edit')) {
123                 // Check if at last one line is selected
124                 if (countPostSelection() > 0) {
125                         // Make selected editable
126                         $OUT = ''; $SW = 2;
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                                 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
132                                 SQL_FREERESULT($result);
133
134                                 // Prepare data for the row template
135                                 $content = array(
136                                         'sw'      => $SW,
137                                         'id'      => $id,
138                                         'rallyes' => generateOptionList('rallye_data', 'id', 'title', $rallye),
139                                         'level'   => $level,
140                                         'points'  => $points,
141                                         'infos'   => $infos,
142                                 );
143
144                                 // Load row template and switch color
145                                 $OUT .= loadTemplate('admin_config_rallye_edit_row', true, $content);
146                                 $SW = 3 - $SW;
147                         } // END - foreach
148                         $content['rows'] = $OUT;
149
150                         // Prepare data for the main template
151                         $content['rallye'] = getRequestParameter('rallye');
152
153                         // Load main template
154                         loadTemplate('admin_config_rallye_edit', false, $content);
155                 } else {
156                         // Nothing selected
157                         $content = '{--RALLYE_NO_PRICES_SELECTED_1--}<a href="{%url=modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=' . getRequestParameter('rallye') . '%}">{--RALLYE_NO_PRICES_SELECTED_2--}</a>{--RALLYE_NO_PRICES_SELECTED_3--}';
158                         loadTemplate('admin_settings_saved', false, $content);
159                 }
160         } elseif (isFormSent('del')) {
161                 // Check if at last one line is selected
162                 if (countPostSelection() > 0) {
163                         // List all prices
164                         $OUT = ''; $SW = 2;
165                         foreach (postRequestParameter('sel') as $id => $sel) {
166                                 // Load data to selected rallye
167                                 $result = SQL_QUERY_ESC("SELECT `rallye_id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
168                                         array(bigintval($id)), __FILE__, __LINE__);
169                                 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
170                                 SQL_FREERESULT($result);
171
172                                 if (empty($infos)) $infos = '---';
173
174                                 // Prepare data for the row template
175                                 $content = array(
176                                         'sw'      => $SW,
177                                         'id'      => $id,
178                                         'level'   => $level,
179                                         'points'  => $points,
180                                         'infos'   => $infos,
181                                 );
182
183                                 // Load row template and switch color
184                                 $OUT .= loadTemplate('admin_config_rallye_del_row', true, $content);
185                                 $SW = 3 - $SW;
186                         } // END - foreach
187                         $content['rows'] = $OUT;
188
189                         // Prepare data for the main template
190                         $content['rallye'] = getRequestParameter('rallye');
191
192                         // Load main template
193                         loadTemplate('admin_config_rallye_del', false, $content);
194                 } else {
195                         // Nothing selected
196                         $content = '{--RALLYE_NO_PRICES_SELECTED_1--}<a href="{%url=modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=' . getRequestParameter('rallye') . '%}">{--RALLYE_NO_PRICES_SELECTED_2--}</a>{--RALLYE_NO_PRICES_SELECTED_3--}';
197                         loadTemplate('admin_settings_saved', false, $content);
198                 }
199         } else {
200                 // a rallye was selected, so check if there are already prices assigned...
201                 $result = SQL_QUERY_ESC("SELECT `id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
202                         array(bigintval(getRequestParameter('rallye'))), __FILE__, __LINE__);
203
204                 if (SQL_NUMROWS($result) > 0) {
205                         // Load all prices for the selected rallye
206                         $OUT = ''; $SW = 2;
207                         while ($content = SQL_FETCHARRAY($result)) {
208                                 // Fix empty info
209                                 if (empty($content['info'])) $content['info'] = '---';
210
211                                 // Prepare data for the row template
212                                 // @TODO Rewritings: level->price_level, infos->info in template
213                                 $content = array(
214                                         'sw'      => $SW,
215                                         'id'      => $content['id'],
216                                         'level'   => $content['price_level'],
217                                         'points'  => $content['points'],
218                                         'infos'   => $content['info'],
219                                 );
220
221                                 // Load row template and switch color
222                                 $OUT .= loadTemplate('admin_config_rallye_prices_row', true, $content);
223                                 $SW = 3 - $SW;
224                         } // END - while
225
226                         // Free memory
227                         SQL_FREERESULT($result);
228
229                         // @TODO Rewrite these two constants
230                         $content['rows'] = $OUT;
231
232                         // Prepare data for the main template
233                         $content['rallye'] = getRequestParameter('rallye');
234
235                         // Load main template
236                         loadTemplate('admin_config_rallye_prices', false, $content);
237                 } // END - if
238         }
239
240         // Add form for adding new price level
241         if (!isFormSent('edit')) {
242                 loadTemplate('admin_add_rallye_prices', false, getRequestParameter('rallye'));
243         } // END - if
244 } else {
245         // No rallye selected so display all available without prices
246         $result = SQL_QUERY("SELECT
247         d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
248 FROM
249         `{?_MYSQL_PREFIX?}_rallye_data` AS d
250 LEFT JOIN
251         `{?_MYSQL_PREFIX?}_admins` AS a
252 ON
253         d.admin_id=a.id
254 ORDER BY
255         d.start_time DESC", __FILE__, __LINE__);
256         if (SQL_NUMROWS($result) > 0) {
257                 // List found rallyes
258                 $OUT = ''; $SW = 2;
259                 while ($content = SQL_FETCHARRAY($result)) {
260                         // Prepare data for the row template
261                         $content = array(
262                                 'sw'         => $SW,
263                                 'id'         => $content['id'],
264                                 'title'      => $content['title'],
265                                 'admin_id'   => $content['admin_id'],
266                                 'admin_link' => generateAdminLink($content['admin_id']),
267                                 'login'      => $content['login'],
268                                 'start'      => generateDateTime($content['start_time'], 3),
269                                 'end'        => generateDateTime($content['end_time'], 3),
270                         );
271
272                         // Load row template and switch color
273                         $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
274                         $SW = 3 - $SW;
275                 } // END - while
276
277                 // Free memory
278                 SQL_FREERESULT($result);
279
280                 // Load main template
281                 loadTemplate('admin_list_rallye_prices', false, $OUT);
282         } else {
283                 // No rallyes setup so far
284                 loadTemplate('admin_settings_saved', false, '{--RALLYE_NO_RALLYES_SETUP--}');
285         }
286 }
287
288 // [EOF]
289 ?>