0265f94e6f910505dcf99c74b8284c470f1f5f2e
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://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')) {
40         exit();
41 } elseif (!isMember()) {
42         redirectToIndexMemberOnlyModule();
43 }
44
45 // Add description as navigation point
46 addYouAreHereLink('member', __FILE__);
47
48 if ((!isExtensionActive('rallye')) && (!isAdmin())) {
49         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=rallye%}');
50         return;
51 } // END - if
52
53 // Check for possible running rallyes
54 $ADD = " AND d.`is_active`='Y'";
55 if (isAdmin()) $ADD = '';
56
57 $result = SQL_QUERY("SELECT
58         d.`id`,
59         d.`admin_id`,
60         a.`login`,
61         d.`title`,
62         d.`descr`,
63         d.`template`,
64         d.`start_time`,
65         d.`end_time`,
66         d.`min_users`,
67         d.`min_prices`
68 FROM
69         `{?_MYSQL_PREFIX?}_rallye_data` AS d
70 INNER JOIN
71         `{?_MYSQL_PREFIX?}_admins` AS a
72 ON
73         d.`admin_id`=a.`id`
74 WHERE
75         d.`notified`='Y'
76         " . $ADD . "
77 ORDER BY
78         d.`end_time` ASC
79 LIMIT 1", __FILE__, __LINE__);
80
81 if (SQL_NUMROWS($result) == 1) {
82         // Found some (normally one...
83         $content = SQL_FETCHARRAY($result);
84
85         $expired = FALSE;
86         if (($content['end_time'] < time()) && (getTotalConfirmedUser() >= $content['min_users']) && (getTotalRallyeWinners($content['id']) >= $content['min_prices'])) {
87                 // Rallye is expired
88                 $content['extras'] = '{--RALLYE_HAS_EXPIRED--}';
89                 $expired = TRUE;
90         } elseif (time() >= ($content['end_time'] - getOneDay())) {
91                 // Rallye will expire in less one day!
92                 $content['extras'] = '{--RALLYE_EXPIRE_ONE_DAY--}';
93         } else {
94                 // Link to referral links page
95                 $content['extras'] = '<a href="{%url=modules.php?module=login&amp;what=reflinks%}">{--RALLYE_GET_REFERRAL_LINK--}</a>';
96         }
97
98         // Set admin line (currently set to impressum, later to contact form)
99         // @TODO Reactivate this: $content['admin'] = '<a href="{%url=modules.php?module=index&amp;what=impressum&amp;id=' . $content['admin_id'] . '%}">' . $content['login'] . '</a>';
100
101         // Handle description...
102         if ((empty($content['descr'])) && (!empty($content['template']))) {
103                 // Use description from template
104                 $content['descr'] = loadTemplate('rallye_' . $content['template'], TRUE);
105         } // END - if
106
107         // Determine min_users/prices
108         $content['min_users']  = determineReferralRallyeMinimumUsers($content['min_users']);
109         $content['min_prices'] = determineReferralRallyeMinimumPrices($content['min_prices']);
110
111         // Set start and end time
112         $content['start_time'] = generateDateTime($content['start_time'], 1);
113         $content['end_time']   = generateDateTime($content['end_time']  , 1);
114
115         if ($expired === TRUE) {
116                 $content['prices']       = addReferralRallyeWinners('member', $content['id']);
117                 $content['top_users']    = '<div align="center" class="big">' . $content['extras'] . '</div>';
118                 $content['can_win_this'] = '{--RALLYE_OUR_WINNERS_ARE--}';
119         } else {
120                 $content['prices']       = addReferralRallyePrices($content['id'], 'html');
121                 $content['top_users']    = addReferralRallyeTopUsers('member', $content['id'], getMemberId());
122                 $content['can_win_this'] = '{--RALLYE_YOU_CAN_WIN--}';
123         }
124
125         // And load final template
126         loadTemplate('member_show_rallye', FALSE, $content);
127 } else {
128         // No rallye found so far
129         loadTemplate('member_rallye_404');
130 }
131
132 // Free result
133 SQL_FREERESULT($result);
134
135 // [EOF]
136 ?>