Introduced interruptFilterChain() and continueFilterChain(). Please DO ALWAYS use...
[mailer.git] / inc / filter / order_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 - 2013 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 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');
50         } // END - if
51
52         // Return the data for next filter
53         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
54         return $filterData;
55 }
56
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');
64         } // END - if
65
66         // Return the data for next filter
67         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
68         return $filterData;
69 }
70
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'];
76
77         // Return the data for next filter
78         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
79         return $filterData;
80 }
81
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
87                 $zip = NULL;
88
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'));
96                 }
97
98                 // Is the zip code set?
99                 if (!is_null($zip)) {
100                         // Is the previous SQL statement empty?
101                         if (empty($sql)) {
102                                 // SQL statemet is empty, so use WHERE
103                                 $sql = sprintf(" WHERE `zip` LIKE '%s%%%%'", $zip);
104                         } else {
105                                 // ... otherwise use AND
106                                 $sql .= sprintf(" AND `zip` LIKE '%s%%%%'", $zip);
107                         }
108                 } // END - if
109         } // END - if
110
111         // Return expanded SQL
112         return $sql;
113 }
114
115 // Filter for adding columns of points to array
116 function FILTER_ORDER_POINTS_COLUMNS ($filterData) {
117         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
118         // Add column
119         array_push($filterData, 'order_points');
120
121         // Return the data for next filter
122         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
123         return $filterData;
124 }
125
126 // Filter for generic check of subject line
127 function FILTER_MAIL_ORDER_GENERIC_CHECK_SUBJECT ($filterData) {
128         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
129
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));
134
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&amp;what=order&amp;code=' . getCode('SUBJECT_URL');
139                         interruptFilterChain();
140                 } // END - if
141         } // END - if
142
143         // Return the data for next filter
144         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
145         return $filterData;
146 }
147
148 // Filter for generic check of mail text
149 function FILTER_MAIL_ORDER_GENERIC_CHECK_TEXT ($filterData) {
150         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
151
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']))) {
155                         // URL found
156                         $filterData['redirect'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('URL_FOUND');
157                         interruptFilterChain();
158                 } // END - if
159
160                 // Remove new-line and carriage-return characters
161                 $TEST = str_replace(array(PHP_EOL, chr(13)), array('', ''), $filterData['text']);
162
163                 // Text length within allowed length?
164                 if (strlen($TEST) > getMaxTextLength()) {
165                         // Text is too long!
166                         $filterData['redirect'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('OVERLENGTH');
167                         interruptFilterChain();
168                 } // END - if
169         } // END - if
170
171         // Return the data for next filter
172         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
173         return $filterData;
174 }
175
176 // Filter for generic check of mail type
177 function FILTER_MAIL_ORDER_GENERIC_CHECK_TYPE ($filterData) {
178         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
179
180         // Is mail type set?
181         if ((!isset($filterData['mail_type'])) || ($filterData['mail_type'] < 1)) {
182                 // Not correctly set
183                 $filterData['redirect'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('NO_MAIL_TYPE');
184                 interruptFilterChain();
185         } // END - if
186
187         // Return the data for next filter
188         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
189         return $filterData;
190 }
191
192 // Filter for generic check of URL
193 function FILTER_MAIL_ORDER_GENERIC_CHECK_URL ($filterData) {
194         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
195
196         // Validate URL
197         if (!isUrlValid($filterData['url'])) {
198                 // URL is invalid!
199                 $filterData['redirect'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('INVALID_URL');
200                 interruptFilterChain();
201         } // END - if
202
203         // Return the data for next filter
204         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
205         return $filterData;
206 }
207
208 // Filter for generic check of receiver amount
209 function FILTER_MAIL_ORDER_GENERIC_CHECK_RECEIVER ($filterData) {
210         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
211
212         // Enougth receivers entered?
213         if (($filterData['receiver'] < getOrderMin()) && (!isAdmin())) {
214                 // Less than allowed receivers entered!
215                 $filterData['redirect'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_RECEIVERS3');
216                 interruptFilterChain();
217         } // END - if
218
219         // Return the data for next filter
220         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
221         return $filterData;
222 }
223
224 // [EOF]
225 ?>