Code rewritings, load base config improved and many minor fixes...
[mailer.git] / 0.2.1 / inc / modules / admin / what-list_rallyes.php
1 <?php\r
2 /************************************************************************\r
3  * MXChange v0.2.1                                    Start: 06/29/2004 *\r
4  * ================                             Last change: 02/11/2005 *\r
5  *                                                                      *\r
6  * -------------------------------------------------------------------- *\r
7  * File              : what-list_rallyes.php                            *\r
8  * -------------------------------------------------------------------- *\r
9  * Short description : List existing rallyes                            *\r
10  * -------------------------------------------------------------------- *\r
11  * Kurzbeschreibung  : Bestehende Rallyes auflisten                     *\r
12  * -------------------------------------------------------------------- *\r
13  *                                                                      *\r
14  * -------------------------------------------------------------------- *\r
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *\r
16  * For more information visit: http://www.mxchange.org                  *\r
17  *                                                                      *\r
18  * This program is free software; you can redistribute it and/or modify *\r
19  * it under the terms of the GNU General Public License as published by *\r
20  * the Free Software Foundation; either version 2 of the License, or    *\r
21  * (at your option) any later version.                                  *\r
22  *                                                                      *\r
23  * This program is distributed in the hope that it will be useful,      *\r
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *\r
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *\r
26  * GNU General Public License for more details.                         *\r
27  *                                                                      *\r
28  * You should have received a copy of the GNU General Public License    *\r
29  * along with this program; if not, write to the Free Software          *\r
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *\r
31  * MA  02110-1301  USA                                                  *\r
32  ************************************************************************/\r
33 \r
34 // Some security stuff...\r
35 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))\r
36 {\r
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";\r
38         require($INC);\r
39 }\r
40 \r
41 // Add description as navigation point\r
42 ADD_DESCR("admin", basename(__FILE__));\r
43 \r
44 if (empty($_GET['sub'])) $_GET['sub'] = "";\r
45 $MSG = "";\r
46 \r
47 // Quick actions on a rallye\r
48 if (isset($_GET['rallye']))\r
49 {\r
50         // Activate / deactivate\r
51         $SQL = "";\r
52         if (isset($_GET['activate']))\r
53         {\r
54                 switch ($_GET['activate'])\r
55                 {\r
56                 case "1": // Activate\r
57                         $SQL = "UPDATE "._MYSQL_PREFIX."_rallye_data SET is_active='Y' WHERE id=%d AND is_active='N' LIMIT 1";\r
58                         break;\r
59 \r
60                 case "0": // Deactivate\r
61                         $SQL = "UPDATE "._MYSQL_PREFIX."_rallye_data SET is_active='N' WHERE id=%d AND is_active='Y' LIMIT 1";\r
62                         break;\r
63                 }\r
64         }\r
65 \r
66         // Automatic notification\r
67         if (isset($_GET['notify']))\r
68         {\r
69                 switch ($_GET['notify'])\r
70                 {\r
71                 case "1": // Activate\r
72                         $SQL = "UPDATE "._MYSQL_PREFIX."_rallye_data SET send_notify='Y' WHERE id=%d AND send_notify='N' LIMIT 1";\r
73                         break;\r
74 \r
75                 case "0": // Deactivate\r
76                         $SQL = "UPDATE "._MYSQL_PREFIX."_rallye_data SET send_notify='N' WHERE id=%d AND send_notify='Y' LIMIT 1";\r
77                         break;\r
78                 }\r
79         }\r
80 \r
81         // Automatic adding of new members\r
82         if (isset($_GET['auto']))\r
83         {\r
84                 switch ($_GET['auto'])\r
85                 {\r
86                 case "1": // Activate\r
87                         $SQL = "UPDATE "._MYSQL_PREFIX."_rallye_data SET auto_add_new_user='Y' WHERE id=%d AND auto_add_new_user='N' LIMIT 1";\r
88                         break;\r
89 \r
90                 case "0": // Deactivate\r
91                         $SQL = "UPDATE "._MYSQL_PREFIX."_rallye_data SET auto_add_new_user='N' WHERE id=%d AND auto_add_new_user='Y' LIMIT 1";\r
92                         break;\r
93                 }\r
94         }\r
95 \r
96         // Run SQL command\r
97         if (!empty($SQL))\r
98         {\r
99                 $result = SQL_QUERY_ESC($SQL, array(bigintval($_GET['rallye'])), __FILE__, __LINE__);\r
100         }\r
101 }\r
102  elseif (isset($_POST['remove']))\r
103 {\r
104         // Delete rallyes\r
105         $SEL = SELECTION_COUNT($_POST['sel']);\r
106         if ($SEL > 0)\r
107         {\r
108                 // Delete selected rallyes and all it's data\r
109                 foreach ($_POST['sel'] as $id=>$sel)\r
110                 {\r
111                         // Remove selected rallye entirely...\r
112                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_rallye_data WHERE id=%d LIMIT 1",\r
113                          array(bigintval($id)), __FILE__, __LINE__);\r
114                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id=%d",\r
115                          array(bigintval($id)), __FILE__, __LINE__);\r
116                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_rallye_users WHERE rallye_id=%d",\r
117                          array(bigintval($id)), __FILE__, __LINE__);\r
118                 }\r
119 \r
120                 // Output message\r
121                 $MSG = RALLYE_DELETED;\r
122         }\r
123          else\r
124         {\r
125                 // No rallye selected to delete!\r
126                 $MSG = RALLYE_DELETE_NOTHING_SELECTED;\r
127         }\r
128 }\r
129  elseif (isset($_POST['change']))\r
130 {\r
131         // Change rallye\r
132         $SEL = SELECTION_COUNT($_POST['title']);\r
133         if ($SEL > 0)\r
134         {\r
135                 // Change selected rallyes and all it's data\r
136                 foreach ($_POST['title'] as $id=>$title)\r
137                 {\r
138                         // Secure ID number\r
139                         $id = bigintval($id);\r
140 \r
141                         // Generate timestamps\r
142                         $START = mktime($_POST['start_hour'][$id], $_POST['start_min'][$id], $_POST['start_sec'][$id], $_POST['start_month'][$id], $_POST['start_day'][$id], $_POST['start_year'][$id]);\r
143                         $END   = mktime($_POST['end_hour'][$id]  , $_POST['end_min'][$id]  , $_POST['end_sec'][$id]  , $_POST['end_month'][$id]  , $_POST['end_day'][$id]  , $_POST['end_year'][$id]  );\r
144 \r
145                         // Update entry\r
146                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_rallye_data SET\r
147 title='%s',\r
148 descr='%s',\r
149 template='%s',\r
150 start_time='%s',\r
151 end_time='%s',\r
152 min_users='%s',\r
153 min_prices='%s'\r
154 WHERE id='".$id."' LIMIT 1",\r
155  array($title, $_POST['descr'][$id], $_POST['templ'][$id], bigintval($START), bigintval($END), bigintval($_POST['min_users'][$id]), bigintval($_POST['min_prices'][$id]), $id),\r
156  __FILE__, __LINE__);\r
157                 }\r
158 \r
159                 // Output message\r
160                 $MSG = RALLYE_CHANGED;\r
161         }\r
162 }\r
163 \r
164 if (isset($_POST['edit']))\r
165 {\r
166         // Check for selections\r
167         $SEL = SELECTION_COUNT($_POST['sel']);\r
168         if ($SEL > 0)\r
169         {\r
170                 // Make all selected and deactivated rallyes editable\r
171                 $SW = 2; $OUT = "";\r
172                 foreach ($_POST['sel'] as $id=>$sel)\r
173                 {\r
174                         // Load rallye basic data\r
175                         $result = SQL_QUERY_ESC("SELECT title, descr, template, start_time, end_time, min_users, min_prices FROM "._MYSQL_PREFIX."_rallye_data WHERE id=%d LIMIT 1",\r
176                          array(bigintval($id)), __FILE__, __LINE__);\r
177                         list($title, $descr, $templ, $start, $end, $min_users, $min_prices) = SQL_FETCHROW($result);\r
178                         SQL_FREERESULT($result);\r
179 \r
180                         // Starting day\r
181                         $content['s_sec']   = ADD_SELECTION("sec"  , date("s", $start), "start", $id);\r
182                         $content['s_min']   = ADD_SELECTION("min"  , date("i", $start), "start", $id);\r
183                         $content['s_hour']  = ADD_SELECTION("hour" , date("G", $start), "start", $id);\r
184                         $content['s_day']   = ADD_SELECTION("day"  , date("d", $start), "start", $id);\r
185                         $content['s_month'] = ADD_SELECTION("month", date("m", $start), "start", $id);\r
186                         $content['s_year']  = ADD_SELECTION("year" , date("Y", $start), "start", $id);\r
187 \r
188                         // Ending day\r
189                         $content['e_sec']   = ADD_SELECTION("sec"  , date("s", $end)  , "end"  , $id);\r
190                         $content['e_min']   = ADD_SELECTION("min"  , date("i", $end)  , "end"  , $id);\r
191                         $content['e_hour']  = ADD_SELECTION("hour" , date("G", $end)  , "end"  , $id);\r
192                         $content['e_day']   = ADD_SELECTION("day"  , date("d", $end)  , "end"  , $id);\r
193                         $content['e_month'] = ADD_SELECTION("month", date("m", $end)  , "end"  , $id);\r
194                         $content['e_year']  = ADD_SELECTION("year" , date("Y", $end)  , "end"  , $id);\r
195 \r
196                         // Remember over values\r
197                         $content['templ']      = RALLYE_TEMPLATE_SELECTION("templ[".$id."]", $templ);\r
198                         $content['sw']         = $SW;\r
199                         $content['id']         = $id;\r
200                         $content['title']      = $title;\r
201                         $content['descr']      = $descr;\r
202                         $content['min_users']  = $min_users;\r
203                         $content['min_prices'] = $min_prices;\r
204 \r
205                         // Output row\r
206                         $OUT .= LOAD_TEMPLATE("admin_edit_rallyes_row", true, $content);\r
207 \r
208                         // Color switching\r
209                         $SW = 3 - $SW;\r
210                 }\r
211                 // Remember rows in constant\r
212                 define('__RALLYE_ROWS', $OUT);\r
213 \r
214                 // Load final template\r
215                 LOAD_TEMPLATE("admin_edit_rallyes");\r
216         }\r
217          else\r
218         {\r
219                 // Nothing selected to edit\r
220                 LOAD_TEMPLATE("admin_settings_saved", false, LOAD_TEMPLATE("admin_list_rallye_noselect", true));\r
221         }\r
222 }\r
223  elseif (($_GET['sub'] == "users") && ($_GET['rallye'] > 0))\r
224 {\r
225         // List users and their refs before start and current\r
226         $result = SQL_QUERY_ESC("SELECT userid, refs, curr_points FROM "._MYSQL_PREFIX."_rallye_users WHERE rallye_id=%d ORDER BY userid",\r
227          array(bigintval($_GET['rallye'])), __FILE__, __LINE__);\r
228         if (SQL_NUMROWS($result) > 0)\r
229         {\r
230                 $SW = 2; $OUT = "";\r
231                 define('__RALLYE_VALUE', $_GET['rallye']);\r
232                 while (list($uid, $old, $opoints) = SQL_FETCHROW($result))\r
233                 {\r
234                         // Check for referral count\r
235                         $cnt = RALLYE_GET_REFCOUNT($uid, $old);\r
236 \r
237                         // Output row\r
238                         $Bl = ""; $Br = "";\r
239                         if (($opoints > 0) && ($cnt > 0)) { $Bl = "<STRONG>"; $Br = "</STRONG>"; }\r
240                         if (($old > 0) || ($cnt > 0))\r
241                         {\r
242                                 // Insert link to referral list\r
243                                 //* DEBUG: */ echo "-".$uid."/".$cnt."/".$old."-<BR>";\r
244                                 $cnt = ADMIN_USER_PROFILE_LINK($uid, $cnt, "list_refs");\r
245                                 $old = ADMIN_USER_PROFILE_LINK($uid, $old, "list_refs");\r
246                         }\r
247                         $content = array(\r
248                                 'sw'      => $SW ,\r
249                                 'uid'     => $uid,\r
250                                 'bold_l'  => $Bl ,\r
251                                 'bold_r'  => $Br ,\r
252                                 'old'     => $old,\r
253                                 'cnt'     => $cnt,\r
254                                 'opoints' => TRANSLATE_COMMA($opoints),\r
255                         );\r
256                         $OUT .= LOAD_TEMPLATE("admin_list_rallye_usr_row", true, $content);\r
257                         $SW = 3 - $SW;\r
258                 }\r
259 \r
260                 // Free memory\r
261                 SQL_FREERESULT($result);\r
262                 define('__RALLYE_USER_ROWS', $OUT);\r
263 \r
264                 // Load template\r
265                 LOAD_TEMPLATE("admin_list_rallye_usr");\r
266         }\r
267          else\r
268         {\r
269                 // No entries found?\r
270                 LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_ADMIN_USERS_404);\r
271         }\r
272 }\r
273  else\r
274 {\r
275         // Start listing rallyes\r
276         $result = SQL_QUERY("SELECT id, admin_id, title, descr, template, start_time, end_time, auto_add_new_user, is_active, send_notify, notified, min_users, min_prices\r
277 FROM "._MYSQL_PREFIX."_rallye_data\r
278 ORDER BY start_time DESC",\r
279  __FILE__, __LINE__);\r
280         if (SQL_NUMROWS($result) > 0)\r
281         {\r
282                 // List found rallyes\r
283                 $SW = 2; $OUT = "";\r
284                 while (list($id, $aid, $title, $descr, $templ, $start, $end, $auto_add, $active, $notify, $notified, $min_users, $min_prices) = SQL_FETCHROW($result))\r
285                 {\r
286                         // Load admin login\r
287                         $alogin = GET_ADMIN_LOGIN($aid);\r
288 \r
289                         // Count assigned prices\r
290                         $result_prices = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id=%d",\r
291                          array(bigintval($id)), __FILE__, __LINE__);\r
292 \r
293                         // Count joined userids\r
294                         $result_user = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_rallye_users WHERE rallye_id=%d",\r
295                          array($id), __FILE__, __LINE__);\r
296                         $joined = SQL_NUMROWS($result_user);\r
297 \r
298                         // Did some users joined this rallye?\r
299                         if ($joined > 0)\r
300                         {\r
301                                 // List joined users\r
302                                 $joined = "<A href=\"".URL."/modules.php?module=admin&amp;what=list_rallyes&amp;sub=users&amp;rallye=".$id."\" title=\"".RALLYE_LIST_USERS."\">".$joined."</A>";\r
303                         }\r
304 \r
305                         // Alter some variables\r
306                         if (empty($alogin)) $alogin = "???";\r
307                         if (empty($templ))  $templ  = "---";\r
308                         if (empty($descr))  $descr  = "---";\r
309 \r
310                         // Transfer data into array for the template\r
311                         $content = array(\r
312                                 'select'     => "<INPUT type=\"checkbox\" name=\"sel[".$id."]\" class=\"admin_normal\" value=\"1\">",\r
313                                 'aid'        => $aid,\r
314                                 'email_link' => CREATE_EMAIL_LINK($aid),\r
315                                 'alogin'     => $alogin,\r
316                                 'id'         => $id,\r
317                                 'sw'         => $SW,\r
318                                 'title'      => $title,\r
319                                 'template'   => $templ,\r
320                                 'joined'     => $joined,\r
321                                 'start_date' => MAKE_DATETIME($start, "2"),\r
322                                 'end_date'   => MAKE_DATETIME($end  , "2"),\r
323                                 'active_lnk' => TRANSLATE_YESNO($active),\r
324                                 'notify_lnk' => TRANSLATE_YESNO($notify),\r
325                                 'auto_lnk'   => TRANSLATE_YESNO($auto_add),\r
326                                 'notified'   => TRANSLATE_YESNO($notified),\r
327                                 'prices_cnt' => SQL_NUMROWS($result_prices),\r
328                                 'descr'      => COMPILE_CODE($descr),\r
329                                 'min_users'  => $min_users,\r
330                                 'min_prices' => $min_prices,\r
331                         );\r
332 \r
333                         // Free memory\r
334                         SQL_FREERESULT($result_prices);\r
335                         SQL_FREERESULT($result_user);\r
336 \r
337                         // Is the rallye active or not?\r
338                         switch ($active)\r
339                         {\r
340                         case "Y":\r
341                                 // Rallye is active so do not edit it!\r
342                                 $content['select'] = "<STRONG class=\"big\">".$id."</STRONG>";\r
343                                 $content['active_title'] = RALLYE_DEACTIVATE_NOW;\r
344                                 $content['active'] = "0";\r
345                                 break;\r
346 \r
347                         case "N":\r
348                                 $content['active_title'] = RALLYE_ACTIVATE_NOW;\r
349                                 $content['active'] = "1";\r
350                                 break;\r
351                         }\r
352 \r
353                         // Notification to members?\r
354                         switch ($notify)\r
355                         {\r
356                         case "Y":\r
357                                 $content['notify_title'] = RALLYE_STOP_NOTIFY_NOW;\r
358                                 $content['notify'] = "0";\r
359                                 break;\r
360 \r
361                         case "N":\r
362                                 $content['notify_title'] = RALLYE_START_NOTIFY_NOW;\r
363                                 $content['notify'] = "1";\r
364                                 break;\r
365                         }\r
366 \r
367                         // Auto-add of new joined members?\r
368                         switch ($auto_add)\r
369                         {\r
370                         case "Y":\r
371                                 $content['auto_title'] = RALLYE_STOP_AUTO_ADD_NOW;\r
372                                 $content['auto'] = "0";\r
373                                 break;\r
374 \r
375                         case "N":\r
376                                 $content['auto_title'] = RALLYE_START_AUTO_ADD_NOW;\r
377                                 $content['auto'] = "1";\r
378                                 break;\r
379                         }\r
380 \r
381                         // Output row\r
382                         $OUT .= LOAD_TEMPLATE("admin_list_rallyes_row", true, $content);\r
383                         $SW = 3 - $SW;\r
384                 }\r
385 \r
386                 // Free memory\r
387                 SQL_FREERESULT($result);\r
388                 define('__RALLYE_ROWS', $OUT);\r
389 \r
390                 // Load template\r
391                 LOAD_TEMPLATE("admin_list_rallyes");\r
392         }\r
393          else\r
394         {\r
395                 // No rallyes setup so far\r
396                 LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_NO_RALLYES_SETUP);\r
397         }\r
398 }\r
399 //\r
400 ?>\r