52b19648003f718e96c9fe65dec1e28a7a7a600b
[mailer.git] / inc / modules / member / what-rallyes.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } elseif (!isMember()) {
44         redirectToIndexMemberOnlyModule();
45 }
46
47 // Add description as navigation point
48 addMenuDescription('member', __FILE__);
49
50 if ((!isExtensionActive('rallye')) && (!isAdmin())) {
51         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('rallye'));
52         return;
53 } // END - if
54
55 // Check for possible running rallyes
56 $ADD = " AND d.is_active='Y'";
57 if (isAdmin()) $ADD = '';
58
59 $result = SQL_QUERY("SELECT
60         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
61 FROM
62         `{?_MYSQL_PREFIX?}_rallye_data` AS d
63 INNER JOIN
64         `{?_MYSQL_PREFIX?}_admins` AS a
65 ON
66         d.admin_id=a.id
67 WHERE
68         d.notified='Y'" . $ADD . "
69 ORDER BY
70         d.end_time ASC
71 LIMIT 1", __FILE__, __LINE__);
72
73 if (SQL_NUMROWS($result) == 1) {
74         // Found some (normally one...
75         $content = SQL_FETCHARRAY($result);
76
77         $expired = false;
78         if ($content['end_time'] < time()) {
79                 // Rallye is expired
80                 $content['extras'] = getMessage('RALLYE_HAS_EXPIRED');
81                 $expired = true;
82         } elseif (time() >= ($content['end_time'] - getConfig('ONE_DAY'))) {
83                 // Rallye will expire in less one day!
84                 $content['extras'] = getMessage('RALLYE_EXPIRE_ONE_DAY');
85         } else {
86                 // Link to referal links page
87                 $content['extras'] = '<a href="{%url=modules.php?module=login&amp;what=reflinks%}">{--RALLYE_GET_REFLINK--}</a>';
88         }
89
90         // Set admin line (currently set to impressum, later to contact form)
91         // @TODO Reactivate this: $content['admin'] = '<a href="{%url=modules.php?module=index&amp;what=impressum&amp;admin=' . $content['admin_id'] . '%}">' . $content['login'] . '</a>';
92
93         // Handle description...
94         if ((empty($content['descr'])) && (!empty($content['template']))) {
95                 // Use description from template
96                 $content['descr'] = loadTemplate('rallye_' . $content['template'], true);
97         } // END - if
98
99         // Determine min_users/prices
100         $content['min_users']  = determineReferalRallyeMinimumUsers($content['min_users']);
101         $content['min_prices'] = determineReferalRallyeMinimumPrices($content['min_prices']);
102
103         // Set start and end time
104         $content['start'] = generateDateTime($content['start_time'], 1);
105         $content['end']   = generateDateTime($content['end_time']  , 1);
106
107         if ($expired === true) {
108                 $content['prices']       = addReferalRallyeWinners($content['id']);
109                 $content['top_users']    = '<div align="center" class="big">' . $content['extras'] . '</div>';
110                 $content['can_win_this'] = getMessage('RALLYE_OUR_WINNERS_ARE');
111         } else {
112                 $content['prices']       = addReferalRallyePrices($content['id'], 'html');
113                 $content['top_users']    = addReferalRallyeTopUsers($content['id'], getMemberId());
114                 $content['can_win_this'] = getMessage('RALLYE_YOU_CAN_WIN');
115         }
116
117         // And load final template
118         loadTemplate('guest_rallye_show', false, $content);
119 } else {
120         // No rallye found so far
121         loadTemplate('guest_no_rallyes');
122 }
123
124 // Free result
125 SQL_FREERESULT($result);
126
127 // [EOF]
128 ?>