6f43d830f979943193c9ae299423334bcaed7010
[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 `{?_MYSQL_PREFIX?}_rallye_prices` SET rallye_id=%s, price_level='%s', points='%s', info='%s' WHERE `id`=%s LIMIT 1",
97                         array(
98                         postRequestElement('rallye_id', $id),
99                         bigintval($level),
100                         postRequestElement('points', $id),
101                         postRequestElement('infos', $id),
102                         $id
103                         ), __FILE__, __LINE__);
104                 }
105
106                 // Output message
107                 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ENTRIES_CHANGED'));
108         }
109
110         if (isPostRequestElementSet('edit')) {
111                 // Check if at last one line is selected
112                 $SEL = countPostSelection();
113                 if ($SEL > 0) {
114                         // Make selected editable
115                         $OUT = ''; $SW = 2;
116                         foreach (postRequestElement('sel') as $id => $sel) {
117                                 // Load data to selected rallye
118                                 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
119                                 array(bigintval($id)), __FILE__, __LINE__);
120                                 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
121                                 SQL_FREERESULT($result);
122
123                                 // Prepare data for the row template
124                                 $content = array(
125                                         'sw'      => $SW,
126                                         'id'      => $id,
127                                         'rallyes' => generateOptionList("rallye_data", 'id', "title", $rallye),
128                                         'level'   => $level,
129                                         'points'  => $points,
130                                         'infos'   => $infos,
131                                 );
132
133                                 // Load row template and switch color
134                                 $OUT .= loadTemplate('admin_config_rallye_edit_row', true, $content);
135                                 $SW = 3 - $SW;
136                         }
137                         $content['rows'] = $OUT;
138
139                         // Prepare data for the main template
140                         $content['rallye'] = getRequestElement('rallye');
141
142                         // Load main template
143                         loadTemplate('admin_config_rallye_edit', false, $content);
144                 } else {
145                         // Nothing selected
146                         $content = sprintf(getMessage('RALLYE_NO_PRICES_SELECTED'), "<a href=\"{?URL?}/modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=".getRequestElement('rallye')."\">", "</a>");
147                         loadTemplate('admin_settings_saved', false, $content);
148                 }
149         } elseif (isPostRequestElementSet('del')) {
150                 // Check if at last one line is selected
151                 $SEL = countPostSelection();
152                 if ($SEL > 0) {
153                         // List all prices
154                         $OUT = ''; $SW = 2;
155                         foreach (postRequestElement('sel') as $id => $sel) {
156                                 // Load data to selected rallye
157                                 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
158                                 array(bigintval($id)), __FILE__, __LINE__);
159                                 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
160                                 SQL_FREERESULT($result);
161
162                                 if (empty($infos)) $infos = '---';
163
164                                 // Prepare data for the row template
165                                 $content = array(
166                                         'sw'      => $SW,
167                                         'id'      => $id,
168                                         'level'   => $level,
169                                         'points'  => $points,
170                                         'infos'   => $infos,
171                                 );
172
173                                 // Load row template and switch color
174                                 $OUT .= loadTemplate('admin_config_rallye_del_row', true, $content);
175                                 $SW = 3 - $SW;
176                         }
177                         $content['rows'] = $OUT;
178
179                         // Prepare data for the main template
180                         $content['rallye'] = getRequestElement('rallye');
181
182                         // Load main template
183                         loadTemplate('admin_config_rallye_del', false, $content);
184                 } else {
185                         // Nothing selected
186                         $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--}";
187                         loadTemplate('admin_settings_saved', false, $content);
188                 }
189         } else {
190                 // a rallye was selected, so check if there are already prices assigned...
191                 $result = SQL_QUERY_ESC("SELECT id, price_level, points, info FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE rallye_id=%s ORDER BY price_level",
192                 array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__);
193
194                 if (SQL_NUMROWS($result) > 0) {
195                         // Load all prices for the selected rallye
196                         $OUT = ''; $SW = 2;
197                         while ($content = SQL_FETCHARRAY($result)) {
198                                 // Fix empty info
199                                 if (empty($content['info'])) $content['info'] = '---';
200
201                                 // Prepare data for the row template
202                                 // @TODO Rewritings: level->price_level, infos->info in template
203                                 $content = array(
204                                         'sw'      => $SW,
205                                         'id'      => $content['id'],
206                                         'level'   => $content['price_level'],
207                                         'points'  => $content['points'],
208                                         'infos'   => $content['info'],
209                                 );
210
211                                 // Load row template and switch color
212                                 $OUT .= loadTemplate('admin_config_rallye_prices_row', true, $content);
213                                 $SW = 3 - $SW;
214                         } // END - while
215
216                         // Free memory
217                         SQL_FREERESULT($result);
218
219                         // @TODO Rewrite these two constants
220                         $content['rows'] = $OUT;
221
222                         // Prepare data for the main template
223                         $content['rallye'] = getRequestElement('rallye');
224
225                         // Load main template
226                         loadTemplate('admin_config_rallye_prices', false, $content);
227                 }
228         }
229
230         // Add form for adding new price level
231         if (!isPostRequestElementSet('edit')) {
232                 loadTemplate('admin_add_rallye_prices', false, getRequestElement('rallye'));
233         }
234 } else {
235         // No rallye selected so display all available without prices
236         $result = SQL_QUERY("SELECT
237         d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
238 FROM
239         `{?_MYSQL_PREFIX?}_rallye_data` AS d,
240 LEFT JOIN
241         `{?_MYSQL_PREFIX?}_admins` AS a
242 ON
243         d.admin_id=a.id
244 ORDER BY
245         `d.start_time` DESC", __FILE__, __LINE__);
246         if (SQL_NUMROWS($result) > 0) {
247                 // List found rallyes
248                 $OUT = ''; $SW = 2;
249                 while ($content = SQL_FETCHARRAY($result)) {
250                         $select = "<input type=\"checkbox\" name=\"sel[".$content['id']."]\" class=\"admin_normal\" value=\"1\">";
251                         if ($content['is_active'] == 'Y') $select = "<div class=\"big\">".$content['id']."</div>";
252
253                         // Prepare data for the row template
254                         // @TODO Rewritings: admin_id->admin_id, alogin->login in template
255                         $content = array(
256                                 'sw'         => $SW,
257                                 'id'         => $content['id'],
258                                 'select'     => $select,
259                                 'title'      => $content['title'],
260                                 'admin_id'        => $content['admin_id'],
261                                 'email_link' => generateEmailLink($content['admin_id']),
262                                 'alogin'     => $content['login'],
263                                 'start'      => generateDateTime($content['start_time'], '3'),
264                                 'end'        => generateDateTime($content['end_time'], '3'),
265                         );
266
267                         // Load row template and switch color
268                         $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
269                         $SW = 3 - $SW;
270                 }
271
272                 // Free memory
273                 SQL_FREERESULT($result);
274
275                 // Load main template
276                 loadTemplate('admin_list_rallye_prices', false, $OUT);
277         } else {
278                 // No rallyes setup so far
279                 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_NO_RALLYES_SETUP'));
280         }
281 }
282
283 // [EOF]
284 ?>