THANK_YOU.txt updated, fixed over-long message
[mailer.git] / inc / filter / user_filter.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 07/02/2011 *
4  * ===================                          Last change: 07/02/2011 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : order_filter.php                                 *
8  * -------------------------------------------------------------------- *
9  * Short description : Filters for ext-order                            *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Filter fuer ext-order                            *
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 returning given user's points
44 function FILTER_USER_POINTS ($filterData) {
45         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
46
47         // Get the points and add them to the existing
48         $filterData['points'] += countSumTotalData($filterData['userid'], 'user_points', 'points');
49
50         // Return the data for next filter
51         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
52         return $filterData;
53 }
54
55 // Filter for returning given user's locked points
56 function FILTER_LOCKED_USER_POINTS ($filterData) {
57         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
58
59         // Get the points and add them to the existing
60         $filterData['points'] += countSumTotalData($filterData['userid'], 'user_points', 'locked_points');
61
62         // Return the data for next filter
63         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
64         return $filterData;
65 }
66
67 // Filter for returning all user points column names
68 function FILTER_GET_ALL_USER_POINTS_COLUMN_NAMES ($filterData) {
69         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
70         // Add 'points' and 'locked_points'
71         $filterData['columns'] .= $filterData['alias'] . 'points' . $filterData['separator'] . $filterData['alias'] . 'locked_points' . $filterData['separator'];
72
73         // Return the data for next filter
74         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
75         return $filterData;
76 }
77
78 // Filter for excluding tester users in WHERE statements
79 function FILTER_TESTER_USER_EXCLUSION_SQL ($sql) {
80         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called! - sql(' . strlen($sql) . ')=' . $sql);
81
82         /*
83          * Allow testers to be included? Do only this when you only want to test
84          * it, normally you don't want these accounts being included everywhere.
85          */
86         if (ifTesterAccountsAllowed()) {
87                 // Do not exclude tester accounts
88                 return $sql;
89         } // END - if
90
91         // Add it, as of this filter is registered only with ext-user >= 0.5.0
92         if (empty($sql)) {
93                 // Add WHERE
94                 $sql = " WHERE `surname` NOT LIKE '{?tester_user_surname_prefix?}%%'";
95         } else {
96                 // Add AND
97                 $sql .= " AND `surname` NOT LIKE '{?tester_user_surname_prefix?}%%'";
98         }
99
100         // Return the data for next filter
101         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done! - sql(' . strlen($sql) . ')=' . $sql);
102         return $sql;
103 }
104
105 // Filter for including tester users in WHERE statements
106 function FILTER_TESTER_USER_INCLUSION_SQL ($sql) {
107         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called! - sql(' . strlen($sql) . ')=' . $sql);
108         // Add it, as of this filter is registered only with ext-user >= 0.5.0
109         if (empty($sql)) {
110                 // Add WHERE
111                 $sql = " WHERE `surname` LIKE '{?tester_user_surname_prefix?}%%'";
112         } else {
113                 // Add AND
114                 $sql .= " AND `surname` LIKE '{?tester_user_surname_prefix?}%%'";
115         }
116
117         // Return the data for next filter
118         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done! - sql(' . strlen($sql) . ')=' . $sql);
119         return $sql;
120 }
121
122 // Filter to add SQL columns to user registration
123 function FILTER_TESTER_USER_REGISTRATION_ADD_SQL_COLUMNS ($filterData) {
124         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
125
126         // Does the admin create a tester account?
127         if ((isAdmin()) && (isTesterUserName(postRequestElement('surname')))) {
128                 // Yes, these accounts never needs confirmation (you can still test it by creating a usual account).
129                 setPostRequestElement('status', 'CONFIRMED');
130         } // END - if
131
132         // Return filter data
133         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
134         //* NOISY-DEBUG: */ print __FUNCTION__.':filterData=<pre>'.print_r($filterData,true).'</pre>';
135         return $filterData;
136 }
137
138 // Filter to add 'converting' SQL statements
139 function FILTER_ADD_USER_DATA_CONVERT_SQL_COLUMNS ($sql) {
140         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called! - sql(' . strlen($sql) . ')=' . $sql);
141
142         // Add it
143         $sql .= ', UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`';
144
145         // Return the data for next filter
146         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done! - sql(' . strlen($sql) . ')=' . $sql);
147         return $sql;
148 }
149
150 // Filter for handling user subids (called by referral link)
151 function FILTER_HANDLE_USER_SUBID ($filterData) {
152         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
153
154         // Return filter data
155         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
156         //* NOISY-DEBUG: */ print __FUNCTION__.':filterData=<pre>'.print_r($filterData,true).'</pre>';
157         return $filterData;
158 }
159
160 // Filter for adding SQL columns on user registration for subid
161 function FILTER_SUBID_USER_REGISTRATION_ADD_SQL_COLUMNS ($filterData) {
162         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
163
164         // Is the sub id set in session?
165         if (isSessionVariableSet('subid')) {
166                 // Okay, add subid here
167                 addExtraRegistrationColumns(', `subid`');
168                 addExtraRegistrationData(", '" . getSession('subid') . "'");
169         } // END - if
170
171         // Return filter data
172         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
173         return $filterData;
174 }
175
176 // Generic filter for updating referral counter of currently detected referral id
177 function FILTER_GENERIC_UPDATE_USER_REFERRAL ($filterData) {
178         // Make sure the referral id is detected
179         assert(isReferralIdValid());
180
181         // Update ref counter, determineReferralId() must already be called before this filter is executed
182         SQL_QUERY('UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_clicks`=`ref_clicks`+1 WHERE `userid`={%pipe,getReferralId%} LIMIT 1', __FUNCTION__, __LINE__);
183
184         // Return filter data
185         return $filterData;
186 }
187
188 // Filter for updating sub id records
189 function FILTER_UPDATE_USER_SUBID ($filterData) {
190         // Make sure the referral id is detected
191         assert(isReferralIdValid());
192
193         // Get sub id and secure it
194         $subId = SQL_ESCAPE(getRequestElement('subid'));
195
196         // Is the sub id available and registered with referral id?
197         if (countSumTotalData(getReferralId(), 'user_subids', 'id', 'userid', true, sprintf(" AND `subid`='%s'", $subId)) == 1) {
198                 // Sub id is assigned to referral id, so add a record
199                 SQL_QUERY_ESC("INSERT INTO
200         `{?_MYSQL_PREFIX?}_subid_log`
201 (
202         `refid`,
203         `subid`,
204         `referral_url`,
205         `remote_address`,
206         `user_agent`
207 ) VALUES (
208         {%%pipe,getReferralId%%},
209         '%s',
210         '{%%pipe,detectReferer%%}',
211         '{%%pipe,detectRemoteAddr%%}',
212         '{%%pipe,detectUserAgent%%}'
213 )",
214                         array(
215                                 // @NOTE: SQL_QUERY_ESC() already escape it, don't use $subId here
216                                 getRequestElement('subid')
217                         ), __FUNCTION__, __LINE__);
218
219                 // Add insert id for other filters
220                 $filterData['insert_id'] = SQL_INSERTID();
221
222                 // Register sub id in filter
223                 setSession('subid', $subId);
224         } // END - if
225
226         // Return filter data
227         return $filterData;
228 }
229
230 // [EOF]
231 ?>