Updated copyright year.
[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 - 2016 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         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
179
180         // Make sure the referral id is detected
181         assert(isValidReferralId());
182
183         // Update ref counter, determineReferralId() must already be called before this filter is executed
184         sqlQuery('UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_clicks`=`ref_clicks`+1 WHERE `userid`={%pipe,getReferralId%} LIMIT 1', __FUNCTION__, __LINE__);
185
186         // Return filter data
187         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
188         return $filterData;
189 }
190
191 // Filter for updating sub id records
192 function FILTER_UPDATE_USER_SUBID ($filterData) {
193         // Make sure the referral id is detected
194         assert(isValidReferralId());
195
196         // Get sub id and secure it
197         $subId = sqlEscapeString(getRequestElement('subid'));
198
199         // Is the sub id available and registered with referral id?
200         if (countSumTotalData(getReferralId(), 'user_subids', 'id', 'userid', TRUE, sprintf(" AND `subid`='%s'", $subId)) == 1) {
201                 // Sub id is assigned to referral id, so add a record
202                 sqlQueryEscaped("INSERT INTO
203         `{?_MYSQL_PREFIX?}_subid_log`
204 (
205         `refid`,
206         `subid`,
207         `referral_url`,
208         `remote_address`,
209         `user_agent`
210 ) VALUES (
211         {%%pipe,getReferralId%%},
212         '%s',
213         '{%%pipe,detectReferer%%}',
214         '{%%pipe,detectRemoteAddr%%}',
215         '{%%pipe,detectUserAgent%%}'
216 )",
217                         array(
218                                 // @NOTE: sqlQueryEscaped() already escape it, don't use $subId here
219                                 getRequestElement('subid')
220                         ), __FUNCTION__, __LINE__);
221
222                 // Add insert id for other filters
223                 $filterData['insert_id'] = getSqlInsertId();
224
225                 // Register sub id in filter
226                 setSession('subid', $subId);
227         } // END - if
228
229         // Return filter data
230         return $filterData;
231 }
232
233 // Filter for adding member action
234 function FILTER_ADD_USER_SUBID_MEMBER_ACTION ($filterData) {
235         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
236         // Add entry
237         array_push($filterData, 'list_user_subid');
238
239         // Return data
240         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
241         return $filterData;
242 }
243
244 // Filter for rendering content for sub id listing in what=reflinks
245 function FILTER_MEMBER_REFLINK_USER_SUBIDS_CONTENT ($content = '') {
246         // Do this only for members
247         assert(isMember());
248         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
249
250         // Does the current user have sub ids?
251         if (getTotalMemberSubIds() > 0) {
252                 // Then Load all
253                 $result = sqlQueryEscaped('SELECT `id`, `subid` FROM `{?_MYSQL_PREFIX?}_user_subids` WHERE `userid`=%s ORDER BY `subid` ASC',
254                         array(getMemberId()), __FUNCTION__, __LINE__);
255
256                 // There should be entries left
257                 assert(!ifSqlHasZeroNumRows($result));
258
259                 // Load all
260                 $out = '';
261                 while ($row = sqlFetchArray($result)) {
262                         // Load row template
263                         $out .= loadTemplate('member_list_reflink_user_subids_row', TRUE, $row);
264                 } // END - while
265
266                 // Load main template
267                 $content .= loadTemplate('member_list_reflink_user_subids', TRUE, $out);
268
269                 // Free result
270                 sqlFreeResult($result);
271         } // END - if
272
273         // Return data
274         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
275         return $content;
276 }
277
278 // Filter for generic user login
279 // @TODO 0% done
280 function FILTER_GENERIC_USER_LOGIN ($filterData) {
281         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
282
283         // Return filter data
284         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
285         return $filterData;
286 }
287
288 // Filter for generic user login check
289 // @TODO 0% done
290 function FILTER_GENERIC_USER_LOGIN_CHECK ($filterData) {
291         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
292
293         // Return filter data
294         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
295         return $filterData;
296 }
297
298 // [EOF]
299 ?>