Filters for configurable userid exclusion added:
[mailer.git] / inc / filter / earning_filter.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 08/03/2011 *
4  * ===================                          Last change: 08/03/2011 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : earning_filter.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Filters for ext-earning                          *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Filter fuer ext-earning                          *
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 function to add 'earning_group' POPUP
44 function FILTER_ADD_EARNING_GROUP_POPUP ($filterData) {
45         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
46         // Check if the current userid is same as in $filterData
47         if (getMemberId() != $filterData['userid']) {
48                 // Not the same
49                 reportBug(__FUNCTION__, __LINE__, 'Validation of userid failed. ' . getMemberId() . '!=' . $filterData['userid']);
50         } // END - if
51
52         // Now check if the user has subscription and amount left
53         $result = SQL_QUERY_ESC("SELECT
54         `d`.`earning_id`,
55         `d`.`earning_provider`,
56         `u`.`earning_current_amount`,
57         `u`.`earning_daily_amount`,
58         `u`.`earning_active`,
59         `u`.`earning_added`,
60         `u`.`earning_canceled`,
61         `u`.`earning_points`
62 FROM
63         `{?_MYSQL_PREFIX?}_user_earning` AS `u`
64 INNER JOIN
65         `{?_MYSQL_PREFIX?}_earning_data` AS `d`
66 ON
67         `u`.`earning_id`=`d`.`earning_id`
68 WHERE
69         `u`.`earning_userid`=%s AND
70         `u`.`earning_active`='Y' AND
71         `u`.`earning_current_amount` < `u`.`earning_daily_amount` AND
72         `d`.`earning_group`='POPUP'
73 ORDER BY
74         `d`.`earning_sorting` ASC",
75                 array(
76                         getMemberId()
77                 ), __FUNCTION__, __LINE__);
78
79         // Are there entries left?
80         if (!SQL_HASZERONUMS($result)) {
81                 // Load all names
82                 while ($content = SQL_FETCHARRAY($result)) {
83                         // Merge the $filterData array in
84                         $content = merge_array($content, $filterData);
85
86                         // Construct callback function name
87                         $callbackName = 'get' . capitalizeUnderscoreString($content['earning_provider']) . 'DataByEarningArray';
88
89                         /*
90                          * And call it, the called function should NOT write data in
91                          * '__output'. This however is done here in this function. The
92                          * called function shall ALWAYS put it's data in '__data'.
93                          */
94                         $content = call_user_func($callbackName, $content);
95                 } // END - if
96         } // END - if
97
98         // Free result
99         SQL_FREERESULT($result);
100
101         // Return filter data
102         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
103         return $filterData;
104 }
105
106 // [EOF]
107 ?>