More misc fixes and rewrites (sorry, lame description)
[mailer.git] / inc / modules / guest / 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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 } elseif ((!EXT_IS_ACTIVE('rallye')) && (!IS_ADMIN())) {
44         addFatalMessage(__FILE__, __LINE__, generateExtensionInactiveNotInstalledMessage('rallye'));
45         return;
46 }
47
48 // Add description as navigation point
49 ADD_DESCR('guest', __FILE__);
50
51 // Open div tag
52 OUTPUT_HTML("<div align=\"center\">");
53
54 // Check for possible running rallyes
55 $ADMIN = " AND d.is_active='Y'";
56 if (IS_ADMIN()) $ADMIN = '';
57
58 $result = SQL_QUERY("SELECT DISTINCT
59         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
60 FROM
61         `{!_MYSQL_PREFIX!}_rallye_data` AS d
62 INNER JOIN
63         `{!_MYSQL_PREFIX!}_admins` AS a
64 ON
65         d.admin_id=a.id
66 WHERE
67         d.notified='Y'".$ADMIN."
68 ORDER BY
69         d.end_time
70 LIMIT 1", __FILE__, __LINE__);
71
72 if (SQL_NUMROWS($result) == 1) {
73         // Found some (normally one...
74         list($id, $aid, $login, $title, $descr, $templ, $start, $end, $min_users, $min_prices) = SQL_FETCHROW($result);
75
76         $expired = false;
77         if ($end < time()) {
78                 // Rallye is expired
79                 define('__RALLYE_EXTRAS', getMessage('RALLYE_HAS_EXPIRED'));
80                 $expired = true;
81         } elseif (time() >= ($end - getConfig('one_day'))) {
82                 // Rallye will expire in less one day!
83                 define('__RALLYE_EXTRAS', getMessage('RALLYE_EXPIRE_ONE_DAY'));
84         } else {
85                 define('__RALLYE_EXTRAS', "<a href=\"{!URL!}/modules.php?module=index&amp;what=register\">{--RALLYE_REGISTER_NOW--}</a>");
86         }
87         // Set admin line (currently set to impressum, later to contact form)
88         define('__RALLYE_ADMIN', "<a href=\"{!URL!}/modules.php?module=index&amp;what=impressum&amp;admin=".$aid."\">".$login."</a>");
89
90         // Set title
91         define('__RALLYE_TITLE', COMPILE_CODE($title));
92
93         // Handle description...
94         if ((empty($descr)) && (!empty($templ))) {
95                 // Use description from template
96                 define('__RALLYE_DESCR', LOAD_TEMPLATE("rallye_".$templ, true));
97         } else {
98                 // Use description from database
99                 define('__RALLYE_DESCR', COMPILE_CODE($descr));
100         }
101
102         // Set start and end time
103         define('__RALLYE_START', generateDateTime($start, '1'));
104         define('__RALLYE_END'  , generateDateTime($end  , '1'));
105
106         // Determine min_users
107         define('__RALLYE_MAX_USERS', RALLYE_DETERMINE_MIN_USERS($min_users));
108
109         // Determine min prices (now in function)
110         define('__RALLYE_MIN_PRICES', RALLYE_DETERMINE_MIN_PRICES());
111
112         if ($expired === true) {
113                 define('__RALLYE_PRICES', RALLYE_LIST_WINNERS($id));
114                 define('__RALLYE_TOP_USERS', "<div align=\"center\" class=\"big\">{!__RALLYE_EXTRAS!}</div>");
115                 define('__RALLYE_CAN_WIN_THIS', getMessage('RALLYE_OUR_WINNERS_ARE'));
116         } else {
117                 define('__RALLYE_PRICES', RALLYE_ADD_PRICES($id, 'html'));
118                 define('__RALLYE_TOP_USERS', RALLYE_ADD_TOPUSERS($id, getUserId()));
119                 define('__RALLYE_CAN_WIN_THIS', getMessage('RALLYE_YOU_CAN_WIN'));
120         }
121
122         // And load final template
123         LOAD_TEMPLATE('guest_rallye_show');
124 } else {
125         // No rallye found so far
126         LOAD_TEMPLATE('guest_no_rallyes');
127 }
128
129 // Close the div tag
130 OUTPUT_HTML('</div>');
131
132 //
133 ?>