A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / member / what-rallyes.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 06/29/2004 *
4  * ================                             Last change: 08/22/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-rallyes.php                                 *
8  * -------------------------------------------------------------------- *
9  * Short description : Ref rallyes                                      *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Ref-Rallyes                                      *
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')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!IS_MEMBER()) {
39         LOAD_URL("modules.php?module=index");
40 } elseif ((!EXT_IS_ACTIVE("rallye")) && (!IS_ADMIN())) {
41         addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "rallye");
42         return;
43 }
44
45 // Add description as navigation point
46 ADD_DESCR("member", __FILE__);
47
48 OUTPUT_HTML("<div align=\"center\">");
49
50 // Check for possible running rallyes
51 $ADMIN = " AND d.is_active='Y'";
52 if (IS_ADMIN()) $ADMIN = "";
53 $result = SQL_QUERY("SELECT DISTINCT d.id, d.admin_id, a.login, d.title, d.descr, d.template, d.start_time, d.end_time, d.min_users, d.min_prices
54  FROM `{!_MYSQL_PREFIX!}_rallye_data` AS d, `{!_MYSQL_PREFIX!}_admins` AS a
55  WHERE d.admin_id=a.id".$ADMIN." AND d.notified='Y'
56  ORDER BY d.end_time LIMIT 1", __FILE__, __LINE__);
57
58 if (SQL_NUMROWS($result) == 1) {
59         // Found some (normally one...
60         list($id, $aid, $login, $title, $descr, $templ, $start, $end, $min_users, $min_prices) = SQL_FETCHROW($result);
61         SQL_FREERESULT($result);
62
63         $expired = false;
64         if ($end < time()) {
65                 // Rallye is expired
66                 define('__RALLYE_EXTRAS', getMessage('RALLYE_HAS_EXPIRED'));
67                 $expired = true;
68         } elseif (time() >= ($end - getConfig('one_day'))) {
69                 // Rallye will expire in less one day!
70                 define('__RALLYE_EXTRAS', getMessage('RALLYE_EXPIRE_ONE_DAY'));
71         } else {
72                 define('__RALLYE_EXTRAS', "<a href=\"{!URL!}/modules.php?module=login&amp;what=reflinks\">{--RALLYE_GET_REFLINK--}</a>");
73         }
74
75         // Set admin line (currently set to impressum, later to contact form)
76         define('__RALLYE_ADMIN', "<a href=\"{!URL!}/modules.php?module=index&amp;what=impressum&amp;admin=".$aid."\">".$login."</a>");
77
78         // Set title
79         define('__RALLYE_TITLE', COMPILE_CODE($title));
80
81         // Handle description...
82         if ((empty($descr)) && (!empty($templ))) {
83                 // Use description from template
84                 define('__RALLYE_DESCR', LOAD_TEMPLATE("rallye_".$templ, true));
85         } else {
86                 // Use description from database
87                 define('__RALLYE_DESCR', COMPILE_CODE($descr));
88         }
89
90         // Determine min_users/prices
91         define('__RALLYE_MAX_USERS' ,  RALLYE_DETERMINE_MIN_USERS($min_users));
92         define('__RALLYE_MAX_PRICES',  RALLYE_DETERMINE_MIN_PRICES($min_prices));
93
94         // Set start and end time
95         define('__RALLYE_START', MAKE_DATETIME($start, "1"));
96         define('__RALLYE_END'  , MAKE_DATETIME($end  , "1"));
97
98         if ($expired === true) {
99                 define('__RALLYE_PRICES', RALLYE_LIST_WINNERS($id));
100                 define('__RALLYE_TOP_USERS', "<div align=\"center\" class=\"big\">{!__RALLYE_EXTRAS!}</div>");
101                 define('__RALLYE_CAN_WIN_THIS', getMessage('RALLYE_OUR_WINNERS_ARE'));
102         } else {
103                 define('__RALLYE_PRICES', RALLYE_ADD_PRICES($id, "html"));
104                 define('__RALLYE_TOP_USERS', RALLYE_ADD_TOPUSERS($id, $GLOBALS['userid']));
105                 define('__RALLYE_CAN_WIN_THIS', getMessage('RALLYE_YOU_CAN_WIN'));
106         }
107
108         // And load final template
109         LOAD_TEMPLATE("guest_rallye_show");
110 } else {
111         // No rallye found so far
112         LOAD_TEMPLATE("guest_no_rallyes");
113 }
114
115 //
116 OUTPUT_HTML("</div>");
117
118 //
119 ?>