2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 07/02/2011 *
4 * =================== Last change: 07/02/2011 *
6 * -------------------------------------------------------------------- *
7 * File : order_filter.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Filters for ext-order *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Filter fuer ext-order *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2015 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Filter for returning given user's points
44 function FILTER_USER_POINTS ($filterData) {
45 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
47 // Get the points and add them to the existing
48 $filterData['points'] += countSumTotalData($filterData['userid'], 'user_points', 'points');
50 // Return the data for next filter
51 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
55 // Filter for returning given user's locked points
56 function FILTER_LOCKED_USER_POINTS ($filterData) {
57 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
59 // Get the points and add them to the existing
60 $filterData['points'] += countSumTotalData($filterData['userid'], 'user_points', 'locked_points');
62 // Return the data for next filter
63 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
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'];
73 // Return the data for next filter
74 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
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);
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.
86 if (ifTesterAccountsAllowed()) {
87 // Do not exclude tester accounts
91 // Add it, as of this filter is registered only with ext-user >= 0.5.0
94 $sql = " WHERE `surname` NOT LIKE '{?tester_user_surname_prefix?}%%'";
97 $sql .= " AND `surname` NOT LIKE '{?tester_user_surname_prefix?}%%'";
100 // Return the data for next filter
101 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done! - sql(' . strlen($sql) . ')=' . $sql);
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
111 $sql = " WHERE `surname` LIKE '{?tester_user_surname_prefix?}%%'";
114 $sql .= " AND `surname` LIKE '{?tester_user_surname_prefix?}%%'";
117 // Return the data for next filter
118 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done! - sql(' . strlen($sql) . ')=' . $sql);
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!');
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');
132 // Return filter data
133 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
134 //* NOISY-DEBUG: */ print __FUNCTION__.':filterData=<pre>'.print_r($filterData,TRUE).'</pre>';
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);
143 $sql .= ', UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`';
145 // Return the data for next filter
146 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done! - sql(' . strlen($sql) . ')=' . $sql);
150 // Filter for handling user subids (called by referral link)
151 function FILTER_HANDLE_USER_SUBID ($filterData) {
152 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
154 // Return filter data
155 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
156 //* NOISY-DEBUG: */ print __FUNCTION__.':filterData=<pre>'.print_r($filterData,TRUE).'</pre>';
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!');
164 // Is the sub id set in session?
165 if (isSessionVariableSet('subid')) {
166 // Okay, add subid here
167 addExtraRegistrationColumns(', `subid`');
168 addExtraRegistrationData(", '" . getSession('subid') . "'");
171 // Return filter data
172 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
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!');
180 // Make sure the referral id is detected
181 assert(isValidReferralId());
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__);
186 // Return filter data
187 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
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());
196 // Get sub id and secure it
197 $subId = sqlEscapeString(getRequestElement('subid'));
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`
211 {%%pipe,getReferralId%%},
213 '{%%pipe,detectReferer%%}',
214 '{%%pipe,detectRemoteAddr%%}',
215 '{%%pipe,detectUserAgent%%}'
218 // @NOTE: sqlQueryEscaped() already escape it, don't use $subId here
219 getRequestElement('subid')
220 ), __FUNCTION__, __LINE__);
222 // Add insert id for other filters
223 $filterData['insert_id'] = getSqlInsertId();
225 // Register sub id in filter
226 setSession('subid', $subId);
229 // Return filter data
233 // Filter for adding member action
234 function FILTER_ADD_USER_SUBID_MEMBER_ACTION ($filterData) {
235 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
237 array_push($filterData, 'list_user_subid');
240 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
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
248 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
250 // Does the current user have sub ids?
251 if (getTotalMemberSubIds() > 0) {
253 $result = sqlQueryEscaped('SELECT `id`, `subid` FROM `{?_MYSQL_PREFIX?}_user_subids` WHERE `userid`=%s ORDER BY `subid` ASC',
254 array(getMemberId()), __FUNCTION__, __LINE__);
256 // There should be entries left
257 assert(!ifSqlHasZeroNumRows($result));
261 while ($row = sqlFetchArray($result)) {
263 $out .= loadTemplate('member_list_reflink_user_subids_row', TRUE, $row);
266 // Load main template
267 $content .= loadTemplate('member_list_reflink_user_subids', TRUE, $out);
270 sqlFreeResult($result);
274 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
278 // Filter for generic user login
280 function FILTER_GENERIC_USER_LOGIN ($filterData) {
281 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
283 // Return filter data
284 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
288 // Filter for generic user login check
290 function FILTER_GENERIC_USER_LOGIN_CHECK ($filterData) {
291 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
293 // Return filter data
294 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');