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