Rewrote 'we' word a little, rewrote mail order to use SQL_INSERTID() instead of anoth...
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         exit();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if (isGetRequestElementSet('rallye_id')) {
47         // Price submitted?
48         if (isFormSent('add')) {
49                 if ((isPostRequestElementSet('level')) && ((isPostRequestElementSet('points')) || (isPostRequestElementSet('info')))) {
50                         // Submitted data is valid, but maybe we already have this price level?
51                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s AND `price_level`='%s' LIMIT 1",
52                         array(bigintval(getRequestElement('rallye_id')), bigintval(postRequestElement('level'))), __FILE__, __LINE__);
53
54                         if (SQL_HASZERONUMS($result)) {
55                                 // Ok, new price level entered!
56                                 SQL_QUERY_ESC("INSERT INTO
57         `{?_MYSQL_PREFIX?}_rallye_prices`
58 (`rallye_id`,`price_level`,`points`,`info`)
59         VALUES
60 (%s, %s, '%s', '%s')",
61                                 array(
62                                         bigintval(getRequestElement('rallye_id')),
63                                         bigintval(postRequestElement('level')),
64                                         convertCommaToDot(postRequestElement('points')),
65                                         postRequestElement('info')
66                                 ), __FILE__, __LINE__);
67                                 displayMessage('{--ADMIN_RALLYE_PRICE_LEVEL_SAVED--}');
68                         } else {
69                                 // Free memory
70                                 SQL_FREERESULT($result);
71
72                                 // Price level found
73                                 displayMessage('{--ADMIN_RALLYE_PRICE_ALREADY_FOUND--}');
74                         }
75                 }
76         } elseif (isFormSent('do_delete')) {
77                 // Check if at last one line is selected
78                 if (ifPostContainsSelections()) {
79                         // Delete selected entries
80                         foreach (postRequestElement('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__);
83                         } // END - foreach
84
85                         // Output message
86                         displayMessage('{--ADMIN_RALLYE_PRICES_DELETED--}');
87                 } else {
88                         displayMessage('{--ADMIN_RALLYE_PRICES_NOT_DELETED--}');
89                 }
90         } elseif (isFormSent('do_edit')) {
91                 // Change entries
92                 foreach (postRequestElement('level') as $id => $level) {
93                         // Secure id
94                         $id = bigintval($id);
95
96                         // Update entry
97                         SQL_QUERY_ESC("UPDATE
98         `{?_MYSQL_PREFIX?}_rallye_prices`
99 SET
100         `rallye_id`=%s,
101         `price_level`=%d,
102         `points`=%s,
103         `info`='%s'
104 WHERE
105         `id`=%s
106 LIMIT 1",
107                                 array(
108                                         postRequestElement('rallye_id', $id),
109                                         bigintval($level),
110                                         convertCommaToDot(postRequestElement('points', $id)),
111                                         postRequestElement('info', $id),
112                                         $id
113                                 ), __FILE__, __LINE__);
114                 }
115
116                 // Output message
117                 displayMessage('{--ADMIN_RALLYE_PRICES_CHANGED--}');
118         }
119
120         if (isFormSent('edit')) {
121                 // Check if at last one line is selected
122                 if (ifPostContainsSelections()) {
123                         // Make selected editable
124                         $OUT = '';
125                         foreach (postRequestElement('sel') as $id => $sel) {
126                                 // Load data to selected rallye
127                                 $result = SQL_QUERY_ESC("SELECT
128         `id`,
129         `rallye_id`,
130         `price_level`,
131         `points`,
132         `info`
133 FROM
134         `{?_MYSQL_PREFIX?}_rallye_prices`
135 WHERE
136         `id`=%s
137 LIMIT 1",
138                                         array(bigintval($id)), __FILE__, __LINE__);
139
140                                 // Fetch data
141                                 $content = SQL_FETCHARRAY($result);
142
143                                 // Free result
144                                 SQL_FREERESULT($result);
145
146                                 // Add more content
147                                 $content['rallye_content'] = generateOptions('rallye_data', 'id', 'title', $content['rallye_id']);
148
149                                 // Load row template and switch color
150                                 $OUT .= loadTemplate('admin_edit_rallye_prices_row', true, $content);
151                         } // END - foreach
152
153                         // Remember row content
154                         $content['rows'] = $OUT;
155
156                         // Prepare data for the main template
157                         $content['rallye_id'] = bigintval(getRequestElement('rallye_id'));
158
159                         // Load main template
160                         loadTemplate('admin_edit_rallye_prices', false, $content);
161                 } else {
162                         // Nothing selected
163                         displayMessage('{%message,ADMIN_RALLYE_NO_PRICES_SELECTED=' . getRequestElement('rallye_id') . '%}');
164                 }
165         } elseif (isFormSent('delete')) {
166                 // Check if at last one line is selected
167                 if (ifPostContainsSelections()) {
168                         // List all prices
169                         $OUT = '';
170                         foreach (postRequestElement('sel') as $id => $sel) {
171                                 // Load data to selected rallye
172                                 $result = SQL_QUERY_ESC("SELECT
173         `id`,
174         `rallye_id`,
175         `price_level`,
176         `points`,
177         `info`
178 FROM
179         `{?_MYSQL_PREFIX?}_rallye_prices`
180 WHERE
181         `id`=%s
182 LIMIT 1",
183                                         array(bigintval($id)), __FILE__, __LINE__);
184
185                                 // Fetch data
186                                 $content = SQL_FETCHARRAY($result);
187
188                                 // Free result
189                                 SQL_FREERESULT($result);
190
191                                 // Load row template and switch color
192                                 $OUT .= loadTemplate('admin_delete_rallye_prices_row', true, $content);
193                         } // END - foreach
194                         $content['rows'] = $OUT;
195
196                         // Prepare data for the main template
197                         $content['rallye_id'] = bigintval(getRequestElement('rallye_id'));
198
199                         // Load main template
200                         loadTemplate('admin_delete_rallye_prices', false, $content);
201                 } else {
202                         // Nothing selected
203                         $content = '{--RALLYE_NO_PRICES_SELECTED_1--}<a href="{%url=modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye_id=' . getRequestElement('rallye_id') . '%}">{--RALLYE_NO_PRICES_SELECTED_2--}</a>{--RALLYE_NO_PRICES_SELECTED_3--}';
204                         displayMessage($content);
205                 }
206         } else {
207                 // A rallye was selected, so check if there are already prices assigned...
208                 $result = SQL_QUERY_ESC("SELECT `id`,`price_level`,`points`,`info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
209                         array(bigintval(getRequestElement('rallye_id'))), __FILE__, __LINE__);
210
211                 if (!SQL_HASZERONUMS($result)) {
212                         // Load all prices for the selected rallye
213                         $OUT = '';
214                         while ($content = SQL_FETCHARRAY($result)) {
215                                 // Load row template and switch color
216                                 $OUT .= loadTemplate('admin_list_rallye_prices_simple_row', true, $content);
217                         } // END - while
218
219                         // Free memory
220                         SQL_FREERESULT($result);
221
222                         // @TODO Rewrite these two constants
223                         $content['rows'] = $OUT;
224
225                         // Prepare data for the main template
226                         $content['rallye_id'] = bigintval(getRequestElement('rallye_id'));
227
228                         // Load main template
229                         loadTemplate('admin_list_rallye_prices_simple', false, $content);
230                 } // END - if
231         }
232
233         // Add form for adding new price level
234         if ((!isFormSent('edit')) && (!isFormSent('delete'))) {
235                 loadTemplate('admin_add_rallye_prices', false, getRequestElement('rallye_id'));
236         } // END - if
237 } else {
238         // No rallye selected so display all available without prices
239         $result = SQL_QUERY("SELECT
240         d.id AS `rallye_id`,
241         d.admin_id,
242         d.start_time,
243         d.end_time,
244         d.title,
245         a.login,
246         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_HASZERONUMS($result)) {
256                 // List found rallyes
257                 $OUT = '';
258                 while ($content = SQL_FETCHARRAY($result)) {
259                         // Prepare data for the row template
260                         $content['start_time'] = generateDateTime($content['start_time'], '3');
261                         $content['end_time']   = generateDateTime($content['end_time']  , '3');
262
263                         // Load row template and switch color
264                         $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
265                 } // END - while
266
267                 // Free memory
268                 SQL_FREERESULT($result);
269
270                 // Load main template
271                 loadTemplate('admin_list_rallye_prices', false, $OUT);
272         } else {
273                 // No rallyes setup so far
274                 displayMessage('{--ADMIN_RALLYE_NO_RALLYES_SETUP--}');
275         }
276 }
277
278 // [EOF]
279 ?>