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 order points
44 function FILTER_ORDER_POINTS ($filterData) {
45 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
46 // Is ext-user installed and active?
47 if (isExtensionActive('user')) {
48 // Get the points and add them to the existing
49 $filterData['points'] += countSumTotalData($filterData['userid'], 'user_points', 'order_points');
52 // Return the data for next filter
53 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
57 // Filter for returning given user's locked order points
58 function FILTER_LOCKED_ORDER_POINTS ($filterData) {
59 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
60 // Is ext-user installed and active?
61 if (isExtensionActive('user')) {
62 // Get the points and add them to the existing
63 $filterData['points'] += countSumTotalData($filterData['userid'], 'user_points', 'locked_order_points');
66 // Return the data for next filter
67 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
71 // Filter for returning all user's order points column names
72 function FILTER_GET_ALL_ORDER_POINTS_COLUMN_NAMES ($filterData) {
73 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
74 // Add 'order_points' and 'locked_order_points'
75 $filterData['columns'] .= $filterData['alias'] . 'order_points' . $filterData['separator'] . $filterData['alias'] . 'locked_order_points' . $filterData['separator'];
77 // Return the data for next filter
78 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
82 // Filter for ZIP code inclusion (not exclusion but it must be run in exclusion filter chain)
83 function FILTER_ORDER_ZIP_CODE_SQL ($sql) {
84 // Check if category and number of receivers is okay
85 if (isOrderMultiPageEnabled()) {
86 // Default is no zip code limitation
89 // POST or GET elements?
90 if ((isPostRequestElementSet('zip')) && (postRequestElement('zip') != '')) {
91 // Choose recipients by zip code from POST
92 $zip = bigintval(postRequestElement('zip'));
93 } elseif ((isGetRequestElementSet('zip')) && (getRequestElement('zip') != '')) {
94 // Choose recipients by zip code from GET
95 $zip = bigintval(getRequestElement('zip'));
98 // Is the zip code set?
100 // Is the previous SQL statement empty?
102 // SQL statemet is empty, so use WHERE
103 $sql = sprintf(" WHERE `zip` LIKE '%s%%%%'", $zip);
105 // ... otherwise use AND
106 $sql .= sprintf(" AND `zip` LIKE '%s%%%%'", $zip);
111 // Return expanded SQL
115 // Filter for adding columns of points to array
116 function FILTER_ORDER_POINTS_COLUMNS ($filterData) {
117 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
119 array_push($filterData, 'order_points');
121 // Return the data for next filter
122 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
126 // Filter for generic check of subject line
127 function FILTER_MAIL_ORDER_GENERIC_CHECK_SUBJECT ($filterData) {
128 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
130 // Shall I test the subject line against URLs?
131 if (!isAllowUrlInSubjectEnabled()) {
132 // @TODO 200 is hard-coded here, swap it out to config + admin_config_order.tpl
133 $filterData['subject'] = str_replace(chr(92), '[nl]', substr($filterData['subject'], 0, 200));
135 // Check the subject line for unwanted things
136 if ((isInStringIgnoreCase('https://', $filterData['subject'])) || (isInStringIgnoreCase('http://', $filterData['subject'])) || (isInStringIgnoreCase('www', $filterData['subject']))) {
137 // URL in subject found
138 $filterData['redirect'] = 'modules.php?module=login&what=order&code=' . getCode('SUBJECT_URL');
139 interruptFilterChain();
143 // Return the data for next filter
144 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
148 // Filter for generic check of mail text
149 function FILTER_MAIL_ORDER_GENERIC_CHECK_TEXT ($filterData) {
150 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
152 if (!isAllowUrlInTextEnabled()) {
153 // Test submitted text against some filters (length, URLs in text etc.)
154 if ((isInStringIgnoreCase('https://', $filterData['text'])) || (isInStringIgnoreCase('http://', $filterData['text'])) || (isInStringIgnoreCase('www', $filterData['text']))) {
156 $filterData['redirect'] = 'modules.php?module=login&what=order&code=' . getCode('URL_FOUND');
157 interruptFilterChain();
160 // Remove new-line and carriage-return characters
161 $TEST = str_replace(array(PHP_EOL, chr(13)), array('', ''), $filterData['text']);
163 // Text length within allowed length?
164 if (strlen($TEST) > getMaxTextLength()) {
166 $filterData['redirect'] = 'modules.php?module=login&what=order&code=' . getCode('OVERLENGTH');
167 interruptFilterChain();
171 // Return the data for next filter
172 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
176 // Filter for generic check of mail type
177 function FILTER_MAIL_ORDER_GENERIC_CHECK_TYPE ($filterData) {
178 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
181 if ((!isset($filterData['mail_type'])) || ($filterData['mail_type'] < 1)) {
183 $filterData['redirect'] = 'modules.php?module=login&what=order&code=' . getCode('NO_MAIL_TYPE');
184 interruptFilterChain();
187 // Return the data for next filter
188 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
192 // Filter for generic check of URL
193 function FILTER_MAIL_ORDER_GENERIC_CHECK_URL ($filterData) {
194 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
197 if (!isUrlValid($filterData['url'])) {
199 $filterData['redirect'] = 'modules.php?module=login&what=order&code=' . getCode('INVALID_URL');
200 interruptFilterChain();
203 // Return the data for next filter
204 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
208 // Filter for generic check of receiver amount
209 function FILTER_MAIL_ORDER_GENERIC_CHECK_RECEIVER ($filterData) {
210 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
212 // Enougth receivers entered?
213 if (($filterData['receiver'] < getOrderMin()) && (!isAdmin())) {
214 // Less than allowed receivers entered!
215 $filterData['redirect'] = 'modules.php?module=login&what=order&code=' . getCode('MORE_RECEIVERS3');
216 interruptFilterChain();
219 // Return the data for next filter
220 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');