]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-config_rallye_prices.php
- Rewrites to use more the userid than the actual email address when sending
[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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if (isGetRequestParameterSet('rallye')) {
47         // Price submitted?
48         if (isFormSent('add')) {
49                 if ((isPostRequestParameterSet('level')) && ((isPostRequestParameterSet('points')) || (isPostRequestParameterSet('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(getRequestParameter('rallye')), bigintval(postRequestParameter('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(getRequestParameter('rallye')),
63                                         bigintval(postRequestParameter('level')),
64                                         postRequestParameter('points'),
65                                         postRequestParameter('info')
66                                 ), __FILE__, __LINE__);
67                                 displayMessage('{--RALLYE_PRICE_LEVEL_SAVED--}');
68                         } else {
69                                 // Free memory
70                                 SQL_FREERESULT($result);
71
72                                 // Price level found
73                                 displayMessage('{--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 (postRequestParameter('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('{--RALLYE_ENTRIES_DELETED--}');
87                 } else {
88                         displayMessage('{--RALLYE_ENTRIES_NOT_DELETED--}');
89                 }
90         } elseif (isFormSent('do_edit')) {
91                 // Change entries
92                 foreach (postRequestParameter('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                                         postRequestParameter('rallye_id', $id),
109                                         bigintval($level),
110                                         postRequestParameter('points', $id),
111                                         postRequestParameter('infos', $id),
112                                         $id
113                                 ), __FILE__, __LINE__);
114                 }
115
116                 // Output message
117                 displayMessage('{--RALLYE_ENTRIES_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 (postRequestParameter('sel') as $id => $sel) {
126                                 // Load data to selected rallye
127                                 $result = SQL_QUERY_ESC("SELECT `rallye_id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
128                                         array(bigintval($id)), __FILE__, __LINE__);
129                                 $content = SQL_FETCHARRAY($result);
130                                 SQL_FREERESULT($result);
131
132                                 // Add more content
133                                 $content['rallye_content'] = generateOptionList('rallye_data', 'id', 'title', $content['rallye_id']);
134
135                                 // Load row template and switch color
136                                 $OUT .= loadTemplate('admin_config_rallye_edit_row', true, $content);
137                         } // END - foreach
138
139                         // Remember row content
140                         $content['rows'] = $OUT;
141
142                         // Prepare data for the main template
143                         $content['rallye'] = getRequestParameter('rallye');
144
145                         // Load main template
146                         loadTemplate('admin_config_rallye_edit', false, $content);
147                 } else {
148                         // Nothing selected
149                         $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--}';
150                         displayMessage($content);
151                 }
152         } elseif (isFormSent('delete')) {
153                 // Check if at last one line is selected
154                 if (ifPostContainsSelections()) {
155                         // List all prices
156                         $OUT = '';
157                         foreach (postRequestParameter('sel') as $id => $sel) {
158                                 // Load data to selected rallye
159                                 $result = SQL_QUERY_ESC("SELECT `rallye_id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
160                                         array(bigintval($id)), __FILE__, __LINE__);
161                                 $content = SQL_FETCHARRAY($result);
162                                 SQL_FREERESULT($result);
163
164                                 // Load row template and switch color
165                                 $OUT .= loadTemplate('admin_config_rallye_del_row', true, $content);
166                         } // END - foreach
167                         $content['rows'] = $OUT;
168
169                         // Prepare data for the main template
170                         $content['rallye'] = getRequestParameter('rallye');
171
172                         // Load main template
173                         loadTemplate('admin_config_rallye_del', false, $content);
174                 } else {
175                         // Nothing selected
176                         $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--}';
177                         displayMessage($content);
178                 }
179         } else {
180                 // a rallye was selected, so check if there are already prices assigned...
181                 $result = SQL_QUERY_ESC("SELECT `id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
182                         array(bigintval(getRequestParameter('rallye'))), __FILE__, __LINE__);
183
184                 if (!SQL_HASZERONUMS($result)) {
185                         // Load all prices for the selected rallye
186                         $OUT = '';
187                         while ($content = SQL_FETCHARRAY($result)) {
188                                 // Load row template and switch color
189                                 $OUT .= loadTemplate('admin_config_rallye_prices_row', true, $content);
190                         } // END - while
191
192                         // Free memory
193                         SQL_FREERESULT($result);
194
195                         // @TODO Rewrite these two constants
196                         $content['rows'] = $OUT;
197
198                         // Prepare data for the main template
199                         $content['rallye'] = getRequestParameter('rallye');
200
201                         // Load main template
202                         loadTemplate('admin_config_rallye_prices', false, $content);
203                 } // END - if
204         }
205
206         // Add form for adding new price level
207         if (!isFormSent('edit')) {
208                 loadTemplate('admin_add_rallye_prices', false, getRequestParameter('rallye'));
209         } // END - if
210 } else {
211         // No rallye selected so display all available without prices
212         $result = SQL_QUERY("SELECT
213         d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
214 FROM
215         `{?_MYSQL_PREFIX?}_rallye_data` AS d
216 LEFT JOIN
217         `{?_MYSQL_PREFIX?}_admins` AS a
218 ON
219         d.admin_id=a.id
220 ORDER BY
221         d.start_time DESC", __FILE__, __LINE__);
222         if (!SQL_HASZERONUMS($result)) {
223                 // List found rallyes
224                 $OUT = '';
225                 while ($content = SQL_FETCHARRAY($result)) {
226                         // Prepare data for the row template
227                         // @TODO rename: start->start_time, end->end_time
228                         $content['start'] = generateDateTime($content['start_time'], '3');
229                         $content['end']   = generateDateTime($content['end_time']  , '3');
230
231                         // Load row template and switch color
232                         $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
233                 } // END - while
234
235                 // Free memory
236                 SQL_FREERESULT($result);
237
238                 // Load main template
239                 loadTemplate('admin_list_rallye_prices', false, $OUT);
240         } else {
241                 // No rallyes setup so far
242                 displayMessage('{--RALLYE_NO_RALLYES_SETUP--}');
243         }
244 }
245
246 // [EOF]
247 ?>