2965cc5acc432f2ba5d7558b187302618ec14df1
[mailer.git] / inc / filter / rallye_filter.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/02/2011 *
4  * ===================                          Last change: 06/02/2011 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : _filter.php                                      *
8  * -------------------------------------------------------------------- *
9  * Short description : Filters for ext-                                 *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Filter fuer ext-                                 *
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         die();
41 } // END - if
42
43 // Filter for extra-autpurge
44 function FILTER_RALLYE_EXTRA_AUTOPURGE ($filterData) {
45         // Check expired rallyes (hard-coded 3 days limit for displaying expired rallyes!)
46         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
47         purgeExpiredReferralRallyes();
48
49         // Return data
50         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
51         return $filterData;
52 }
53
54 // Run filter for notifying users about rallyes
55 function FILTER_RALLYE_NOTIFY_USERS ($filterData) {
56         // Do stuff only when not in CSS mode
57         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
58         if (!isCssOutputMode()) {
59                 // Run filter to get SQL "addons"
60                 $sqlAddons = runFilterChain('add_rallye_notify_sqls', array(
61                         'add' => '',
62                         'or'  => ''
63                 ));
64
65                 // Check for new started but not notified rallyes
66                 $result = SQL_QUERY("SELECT SQL_SMALL_RESULT
67         d.`id`,
68         d.`title`,
69         d.`start_time`,
70         d.`end_time`,
71         d.`send_notify`
72         " . $sqlAddons['add'] . "
73 FROM
74         `{?_MYSQL_PREFIX?}_rallye_data` AS d
75 WHERE
76         d.`is_active`='Y' AND
77         d.`notified`='N' AND
78         d.`expired`='N' AND
79         d.`start_time` <= UNIX_TIMESTAMP() AND
80         d.`end_time` > UNIX_TIMESTAMP()
81 LIMIT 1", __FILE__, __LINE__);
82                 if (SQL_NUMROWS($result) == 1) {
83                         // Start rallye
84                         autostartReferralRallyes($result);
85                 } // END - if
86
87                 // Free memory
88                 SQL_FREERESULT($result);
89
90                 // Check for expired rallyes
91                 $result = SQL_QUERY("SELECT SQL_SMALL_RESULT
92         d.`id`,
93         d.`title`,
94         d.`start_time`,
95         d.`end_time`,
96         d.`send_notify`
97         " . $sqlAddons['add'] . "
98 FROM
99         `{?_MYSQL_PREFIX?}_rallye_data` AS d
100 WHERE
101         d.`is_active`='Y' AND
102         d.`notified`='Y' AND
103         d.`expired`='N' AND
104         (d.`end_time` <= UNIX_TIMESTAMP()" . $sqlAddons['or'] . ")
105 LIMIT 1", __FILE__, __LINE__);
106                 if ((SQL_NUMROWS($result) == 1) && (isExtensionActive('autopurge'))) {
107                         // End rallye here...
108                         stopRallyeByResult($result);
109                 } // END - if
110
111                 // Free memory
112                 SQL_FREERESULT($result);
113         } // END - if
114
115         // Return data
116         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
117         return $filterData;
118 }
119
120 // Filter for adding SQL columns
121 function FILTER_ADD_RALLYE_SQL_COLUMNS ($filterData) {
122         // Are all requirements met?
123         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
124         if (isExtensionInstalledAndNewer('rallye', '0.2.0')) {
125                 // Add more data on higher versions
126                 $filterData['add'] .= ',`min_users`, `min_prices`';
127                 $filterData['or']  .= ' OR (d.`min_users` <= ' . getTotalConfirmedUser() . ' AND d.`min_users` > 0)';
128         } // END  - if
129
130         // Return data
131         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
132         return $filterData;
133 }
134
135 // [EOF]
136 ?>