91fe4c618a77fdd2552b2cc8670d4ad93fd6827f
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 if (REQUEST_ISSET_GET(('rallye')))
44 {
45         // Price submitted?
46         if (REQUEST_ISSET_POST(('add')))
47         {
48                 if ((REQUEST_ISSET_POST(('level'))) && ((REQUEST_ISSET_POST(('points'))) || (REQUEST_ISSET_POST(('info')))))
49                 {
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(REQUEST_GET('rallye')), bigintval(REQUEST_POST('level'))), __FILE__, __LINE__);
53
54                         if (SQL_NUMROWS($result) == 0)
55                         {
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(REQUEST_GET('rallye')),
61         bigintval(REQUEST_POST('level')),
62         REQUEST_POST('points'),
63         REQUEST_POST('info')
64 ), __FILE__, __LINE__);
65                                 LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_PRICE_LEVEL_SAVED);
66                         }
67                          else
68                         {
69                                 // Free memory
70                                 SQL_FREERESULT($result);
71
72                                 // Price level found!
73                                 LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_PRICE_ALREADY_FOUND);
74                         }
75                 }
76         } elseif (REQUEST_ISSET_POST(('remove'))) {
77                 // Check if at last one line is selected
78                 $SEL = SELECTION_COUNT(REQUEST_POST('sel'));
79                 if ($SEL > 0) {
80                         // Delete selected entries
81                         foreach (REQUEST_POST('sel') as $id => $sel) {
82                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE id=%s LIMIT 1",
83                                         array(bigintval($id)), __FILE__, __LINE__);
84                         }
85
86                         // Output message
87                         LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_ENTRIES_DELETED);
88                 } else {
89                         LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_ENTRIES_NOT_DELETED);
90                 }
91         } elseif (REQUEST_ISSET_POST(('change'))) {
92                 // Change entries
93                 foreach (REQUEST_POST('level') as $id => $level) {
94                         // Secure ID
95                         $id = bigintval($id);
96
97                         // Update entry
98                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_rallye_prices` SET rallye_id=%s, price_level='%s', points='%s', info='%s' WHERE id=%s LIMIT 1",
99                                 array(
100                                         REQUEST_POST('rallye_id', $id),
101                                         bigintval($level),
102                                         REQUEST_POST('points', $id]),
103                                         REQUEST_POST('infos', $id),
104                                         $id
105                                 ), __FILE__, __LINE__);
106                 }
107
108                 // Output message
109                 LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_ENTRIES_CHANGED);
110         }
111
112         if (REQUEST_ISSET_POST('edit')) {
113                 // Check if at last one line is selected
114                 $SEL = SELECTION_COUNT(REQUEST_POST('sel'));
115                 if ($SEL > 0) {
116                         // Make selected editable
117                         $SW = 2; $OUT = "";
118                         foreach (REQUEST_POST('sel') as $id => $sel) {
119                                 // Load data to selected rallye
120                                 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE id=%s LIMIT 1",
121                                         array(bigintval($id)), __FILE__, __LINE__);
122                                 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
123                                 SQL_FREERESULT($result);
124
125                                 // Prepare data for the row template
126                                 $content = array(
127                                         'sw'      => $SW,
128                                         'id'      => $id,
129                                         'rallyes' => ADD_OPTION_LINES("rallye_data", "id", "title", $rallye),
130                                         'level'   => $level,
131                                         'points'  => $points,
132                                         'infos'   => $infos,
133                                 );
134
135                                 // Load row template and switch color
136                                 $OUT .= LOAD_TEMPLATE("admin_config_rallye_edit_row", true, $content);
137                                 $SW = 3 - $SW;
138                         }
139                         define('__PRICE_ROWS', $OUT);
140
141                         // Prepare data for the main template
142                         define('__RALLYE_ID', REQUEST_GET('rallye'));
143
144                         // Load main template
145                         LOAD_TEMPLATE("admin_config_rallye_edit");
146                 }
147                  else
148                 {
149                         // Nothing selected
150                         $content = RALLYE_NO_PRICES_SELECTED_1."<a href=\"{!URL!}/modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=".REQUEST_GET('rallye')."\">".RALLYE_NO_PRICES_SELECTED_2."</a>".RALLYE_NO_PRICES_SELECTED_3;
151                         LOAD_TEMPLATE("admin_settings_saved", false, $content);
152                 }
153         }
154          elseif (REQUEST_ISSET_POST('del'))
155         {
156                 // Check if at last one line is selected
157                 $SEL = SELECTION_COUNT(REQUEST_POST('sel'));
158                 if ($SEL > 0)
159                 {
160                         // List all prices
161                         $SW = 2; $OUT = "";
162                         foreach (REQUEST_POST('sel') as $id => $sel)
163                         {
164                                 // Load data to selected rallye
165                                 $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE id=%s LIMIT 1",
166                                  array(bigintval($id)), __FILE__, __LINE__);
167                                 list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
168                                 SQL_FREERESULT($result);
169
170                                 if (empty($infos)) $infos = "---";
171
172                                 // Prepare data for the row template
173                                 $content = array(
174                                         'sw'      => $SW,
175                                         'id'      => $id,
176                                         'level'   => $level,
177                                         'points'  => $points,
178                                         'infos'   => $infos,
179                                 );
180
181                                 // Load row template and switch color
182                                 $OUT .= LOAD_TEMPLATE("admin_config_rallye_del_row", true, $content);
183                                 $SW = 3 - $SW;
184                         }
185                         define('__PRICE_ROWS', $OUT);
186
187                         // Prepare data for the main template
188                         define('__RALLYE_ID', REQUEST_GET('rallye'));
189
190                         // Load main template
191                         LOAD_TEMPLATE("admin_config_rallye_del");
192                 }
193                  else
194                 {
195                         // Nothing selected
196                         $content = RALLYE_NO_PRICES_SELECTED_1."<a href=\"{!URL!}/modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=".REQUEST_GET('rallye')."\">".RALLYE_NO_PRICES_SELECTED_2."</a>".RALLYE_NO_PRICES_SELECTED_3;
197                         LOAD_TEMPLATE("admin_settings_saved", false, $content);
198                 }
199         }
200          else
201         {
202                 // a rallye was selected, so check if there are already prices assigned...
203                 $result = SQL_QUERY_ESC("SELECT id, price_level, points, info FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE rallye_id=%s ORDER BY price_level",
204                  array(bigintval(REQUEST_GET('rallye'))), __FILE__, __LINE__);
205
206                 if (SQL_NUMROWS($result) > 0)
207                 {
208                         // Load all prices for the selected rallye
209                         $SW = 2; $OUT = "";
210                         while (list($id, $level, $points, $infos) = SQL_FETCHROW($result))
211                         {
212                                 if (empty($infos)) $infos = "---";
213
214                                 // Prepare data for the row template
215                                 $content = array(
216                                         'sw'      => $SW,
217                                         'id'      => $id,
218                                         'level'   => $level,
219                                         'points'  => $points,
220                                         'infos'   => $infos,
221                                 );
222
223                                 // Load row template and switch color
224                                 $OUT .= LOAD_TEMPLATE("admin_config_rallye_prices_row", true, $content);
225                                 $SW = 3 - $SW;
226                         }
227
228                         // Free memory
229                         SQL_FREERESULT($result);
230                         define('__PRICE_ROWS', $OUT);
231
232                         // Prepare data for the main template
233                         define('__RALLYE_ID', REQUEST_GET('rallye'));
234
235                         // Load main template
236                         LOAD_TEMPLATE("admin_config_rallye_prices");
237                 }
238         }
239
240         // Add form for adding new price level
241         if (!REQUEST_ISSET_POST('edit')) {
242                 LOAD_TEMPLATE("admin_add_rallye_prices", false, REQUEST_GET('rallye'));
243         }
244 } else {
245         // No rallye selected so display all available without prices
246         $result = SQL_QUERY("SELECT d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
247 FROM `{!_MYSQL_PREFIX!}_rallye_data` AS d, `{!_MYSQL_PREFIX!}_admins` AS a
248 WHERE d.admin_id=a.id ORDER BY start_time DESC", __FILE__, __LINE__);
249         if (SQL_NUMROWS($result) > 0)
250         {
251                 // List found rallyes
252                 $SW = 2; $OUT = "";
253                 while (list($id, $aid, $start, $end, $title, $alogin, $active) = SQL_FETCHROW($result))
254                 {
255                         $select = "<input type=\"checkbox\" name=\"sel[".$id."]\" class=\"admin_normal\" value=\"1\">";
256                         if ($active == "Y") $select = "<div class=\"big\">".$id."</div>";
257
258                         // Prepare data for the row template
259                         $content = array(
260                                 'sw'         => $SW,
261                                 'id'         => $id,
262                                 'select'     => $select,
263                                 'title'      => $title,
264                                 'aid'        => $aid,
265                                 'email_link' => CREATE_EMAIL_LINK($aid),
266                                 'alogin'     => $alogin,
267                                 'start'      => MAKE_DATETIME($start, "3"),
268                                 'end'        => MAKE_DATETIME($end, "3"),
269                         );
270
271                         // Load row template and switch color
272                         $OUT .= LOAD_TEMPLATE("admin_list_rallye_prices_row", true, $content);
273                         $SW = 3 - $SW;
274                 }
275
276                 // Free memory
277                 SQL_FREERESULT($result);
278                 define('__RALLYE_ROWS', $OUT);
279
280                 // Load main template
281                 LOAD_TEMPLATE("admin_list_rallye_prices");
282         }
283          else
284         {
285                 // No rallyes setup so far
286                 LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_NO_RALLYES_SETUP);
287         }
288 }
289 //
290 ?>