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 - 2013 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 // Make sure the referral id is detected
179 assert(isValidReferralId());
181 // Update ref counter, determineReferralId() must already be called before this filter is executed
182 sqlQuery('UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_clicks`=`ref_clicks`+1 WHERE `userid`={%pipe,getReferralId%} LIMIT 1', __FUNCTION__, __LINE__);
184 // Return filter data
188 // Filter for updating sub id records
189 function FILTER_UPDATE_USER_SUBID ($filterData) {
190 // Make sure the referral id is detected
191 assert(isValidReferralId());
193 // Get sub id and secure it
194 $subId = sqlEscapeString(getRequestElement('subid'));
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 sqlQueryEscaped("INSERT INTO
200 `{?_MYSQL_PREFIX?}_subid_log`
208 {%%pipe,getReferralId%%},
210 '{%%pipe,detectReferer%%}',
211 '{%%pipe,detectRemoteAddr%%}',
212 '{%%pipe,detectUserAgent%%}'
215 // @NOTE: sqlQueryEscaped() already escape it, don't use $subId here
216 getRequestElement('subid')
217 ), __FUNCTION__, __LINE__);
219 // Add insert id for other filters
220 $filterData['insert_id'] = getSqlInsertId();
222 // Register sub id in filter
223 setSession('subid', $subId);
226 // Return filter data
230 // Filter for adding member action
231 function FILTER_ADD_USER_SUBID_MEMBER_ACTION ($filterData) {
232 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
234 array_push($filterData, 'list_user_subid');
237 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
241 // Filter for rendering content for sub id listing in what=reflinks
242 function FILTER_MEMBER_REFLINK_USER_SUBIDS_CONTENT ($content = '') {
243 // Do this only for members
245 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
247 // Does the current user have sub ids?
248 if (getTotalMemberSubIds() > 0) {
250 $result = sqlQueryEscaped('SELECT `id`, `subid` FROM `{?_MYSQL_PREFIX?}_user_subids` WHERE `userid`=%s ORDER BY `subid` ASC',
251 array(getMemberId()), __FUNCTION__, __LINE__);
253 // There should be entries left
254 assert(!ifSqlHasZeroNums($result));
258 while ($row = sqlFetchArray($result)) {
260 $out .= loadTemplate('member_list_reflink_user_subids_row', TRUE, $row);
263 // Load main template
264 $content .= loadTemplate('member_list_reflink_user_subids', TRUE, $out);
267 sqlFreeResult($result);
271 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');