1 |
560
|
Ruebenwurz
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
915
|
Ruebenwurz
|
Copyright (C) 2004-2009, Ryan Djurovich
|
9 |
560
|
Ruebenwurz
|
|
10 |
|
|
Website Baker is free software; you can redistribute it and/or modify
|
11 |
|
|
it under the terms of the GNU General Public License as published by
|
12 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
(at your option) any later version.
|
14 |
|
|
|
15 |
|
|
Website Baker is distributed in the hope that it will be useful,
|
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
GNU General Public License for more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License
|
21 |
|
|
along with Website Baker; if not, write to the Free Software
|
22 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
|
24 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
/*
|
27 |
|
|
The Website Baker Project would like to thank Rudolph Lartey <www.carbonect.com>
|
28 |
|
|
for his contributions to this module - adding extra field types
|
29 |
|
|
*/
|
30 |
|
|
|
31 |
|
|
// Must include code to stop this file being access directly
|
32 |
|
|
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
|
33 |
|
|
|
34 |
|
|
// check if frontend.css file needs to be included into the <body></body> of view.php
|
35 |
570
|
doc
|
if((!function_exists('register_frontend_modfiles') || !defined('MOD_FRONTEND_CSS_REGISTERED')) &&
|
36 |
|
|
file_exists(WB_PATH .'/modules/form/frontend.css')) {
|
37 |
|
|
echo '<style type="text/css">';
|
38 |
|
|
include(WB_PATH .'/modules/form/frontend.css');
|
39 |
|
|
echo "\n</style>\n";
|
40 |
560
|
Ruebenwurz
|
}
|
41 |
|
|
|
42 |
596
|
thorn
|
require_once(WB_PATH.'/include/captcha/captcha.php');
|
43 |
|
|
|
44 |
789
|
doc
|
// obtain the settings of the output filter module
|
45 |
|
|
if(file_exists(WB_PATH.'/modules/output_filter/filter-routines.php')) {
|
46 |
|
|
include_once(WB_PATH.'/modules/output_filter/filter-routines.php');
|
47 |
|
|
$filter_settings = get_output_filter_settings();
|
48 |
|
|
} else {
|
49 |
|
|
// no output filter used, define default settings
|
50 |
|
|
$filter_settings['email_filter'] = 0;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
560
|
Ruebenwurz
|
// Function for generating an optionsfor a select field
|
54 |
570
|
doc
|
if (!function_exists('make_option')) {
|
55 |
618
|
thorn
|
function make_option(&$n, $k, $values) {
|
56 |
560
|
Ruebenwurz
|
// start option group if it exists
|
57 |
|
|
if (substr($n,0,2) == '[=') {
|
58 |
|
|
$n = '<optgroup label="'.substr($n,2,strlen($n)).'">';
|
59 |
|
|
} elseif ($n == ']') {
|
60 |
|
|
$n = '</optgroup>';
|
61 |
|
|
} else {
|
62 |
760
|
Ruebenwurz
|
if(in_array($n, $values)) {
|
63 |
618
|
thorn
|
$n = '<option selected="selected" value="'.$n.'">'.$n.'</option>';
|
64 |
760
|
Ruebenwurz
|
} else {
|
65 |
618
|
thorn
|
$n = '<option value="'.$n.'">'.$n.'</option>';
|
66 |
760
|
Ruebenwurz
|
}
|
67 |
560
|
Ruebenwurz
|
}
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
// Function for generating a checkbox
|
71 |
570
|
doc
|
if (!function_exists('make_checkbox')) {
|
72 |
560
|
Ruebenwurz
|
function make_checkbox(&$n, $idx, $params) {
|
73 |
618
|
thorn
|
$field_id = $params[0][0];
|
74 |
|
|
$seperator = $params[0][1];
|
75 |
760
|
Ruebenwurz
|
$label_id = 'wb_'.str_replace(" ", "_", $n);
|
76 |
|
|
if(in_array($n, $params[1])) {
|
77 |
|
|
$n = '<input class="field_checkbox" type="checkbox" id="'.$label_id.'" name="field'.$field_id.'['.$idx.']" value="'.$n.'" checked="checked" />'.'<label for="'.$label_id.'" class="checkbox_label">'.$n.'</lable>'.$seperator;
|
78 |
|
|
} else {
|
79 |
|
|
$n = '<input class="field_checkbox" type="checkbox" id="'.$label_id.'" name="field'.$field_id.'['.$idx.']" value="'.$n.'" />'.'<label for="'.$label_id.'" class="checkbox_label">'.$n.'</label>'.$seperator;
|
80 |
|
|
}
|
81 |
560
|
Ruebenwurz
|
}
|
82 |
|
|
}
|
83 |
|
|
// Function for generating a radio button
|
84 |
570
|
doc
|
if (!function_exists('make_radio')) {
|
85 |
560
|
Ruebenwurz
|
function make_radio(&$n, $idx, $params) {
|
86 |
|
|
$field_id = $params[0];
|
87 |
|
|
$group = $params[1];
|
88 |
|
|
$seperator = $params[2];
|
89 |
760
|
Ruebenwurz
|
$label_id = 'wb_'.str_replace(" ", "_", $n);
|
90 |
|
|
if($n == $params[3]) {
|
91 |
|
|
$n = '<input class="field_radio" type="radio" id="'.$label_id.'" name="field'.$field_id.'" value="'.$n.'" checked="checked" />'.'<label for="'.$label_id.'" class="radio_label">'.$n.'</label>'.$seperator;
|
92 |
|
|
} else {
|
93 |
|
|
$n = '<input class="field_radio" type="radio" id="'.$label_id.'" name="field'.$field_id.'" value="'.$n.'" />'.'<label for="'.$label_id.'" class="radio_label">'.$n.'</label>'.$seperator;
|
94 |
|
|
}
|
95 |
560
|
Ruebenwurz
|
}
|
96 |
|
|
}
|
97 |
864
|
aldus
|
|
98 |
|
|
if (!function_exists("new_submission_id") ) {
|
99 |
|
|
function new_submission_id() {
|
100 |
|
|
$submission_id = '';
|
101 |
|
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
102 |
|
|
srand((double)microtime()*1000000);
|
103 |
|
|
$i = 0;
|
104 |
|
|
while ($i <= 7) {
|
105 |
|
|
$num = rand() % 33;
|
106 |
|
|
$tmp = substr($salt, $num, 1);
|
107 |
|
|
$submission_id = $submission_id . $tmp;
|
108 |
|
|
$i++;
|
109 |
|
|
}
|
110 |
|
|
return $submission_id;
|
111 |
560
|
Ruebenwurz
|
}
|
112 |
|
|
}
|
113 |
935
|
aldus
|
|
114 |
560
|
Ruebenwurz
|
// Work-out if the form has been submitted or not
|
115 |
|
|
if($_POST == array()) {
|
116 |
|
|
|
117 |
|
|
// Set new submission ID in session
|
118 |
|
|
$_SESSION['form_submission_id'] = new_submission_id();
|
119 |
|
|
|
120 |
|
|
// Get settings
|
121 |
936
|
aldus
|
$query_settings = $database->query("SELECT header,field_loop,footer,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
|
122 |
560
|
Ruebenwurz
|
if($query_settings->numRows() > 0) {
|
123 |
|
|
$fetch_settings = $query_settings->fetchRow();
|
124 |
|
|
$header = str_replace('{WB_URL}',WB_URL,$fetch_settings['header']);
|
125 |
|
|
$field_loop = $fetch_settings['field_loop'];
|
126 |
|
|
$footer = str_replace('{WB_URL}',WB_URL,$fetch_settings['footer']);
|
127 |
|
|
$use_captcha = $fetch_settings['use_captcha'];
|
128 |
936
|
aldus
|
$form_name = 'form';
|
129 |
|
|
$use_xhtml_strict = false;
|
130 |
560
|
Ruebenwurz
|
} else {
|
131 |
|
|
$header = '';
|
132 |
|
|
$field_loop = '';
|
133 |
|
|
$footer = '';
|
134 |
935
|
aldus
|
$form_name = 'form';
|
135 |
|
|
$use_xhtml_strict = false;
|
136 |
560
|
Ruebenwurz
|
}
|
137 |
|
|
|
138 |
|
|
?>
|
139 |
937
|
aldus
|
<form <?php echo ( ( (strlen($form_name) > 0) AND (false == $use_xhtml_strict) ) ? "name=\"".$form_name."\"" : ""); ?> action="<?php echo htmlspecialchars(strip_tags($_SERVER['PHP_SELF'])); ?>#wb_<?PHP echo $section_id;?>" method="post">
|
140 |
935
|
aldus
|
<div><input type="hidden" name="submission_id" value="<?php echo $_SESSION['form_submission_id']; ?>" /></div>
|
141 |
560
|
Ruebenwurz
|
<?php
|
142 |
596
|
thorn
|
if(ENABLED_ASP) { // first add some honeypot-fields
|
143 |
|
|
?>
|
144 |
935
|
aldus
|
<div><input type="hidden" name="submitted_when" value="<?php $t=time(); echo $t; $_SESSION['submitted_when']=$t; ?>" /></div>
|
145 |
739
|
thorn
|
<p class="nixhier">
|
146 |
596
|
thorn
|
email address:
|
147 |
762
|
thorn
|
<label for="email">Leave this field email-address blank:</label>
|
148 |
596
|
thorn
|
<input id="email" name="email" size="56" value="" /><br />
|
149 |
|
|
Homepage:
|
150 |
762
|
thorn
|
<label for="homepage">Leave this field homepage blank:</label>
|
151 |
596
|
thorn
|
<input id="homepage" name="homepage" size="55" value="" /><br />
|
152 |
|
|
URL:
|
153 |
762
|
thorn
|
<label for="url">Leave this field url blank:</label>
|
154 |
596
|
thorn
|
<input id="url" name="url" size="61" value="" /><br />
|
155 |
|
|
Comment:
|
156 |
762
|
thorn
|
<label for="comment">Leave this field comment blank:</label>
|
157 |
760
|
Ruebenwurz
|
<textarea id="comment" name="comment" cols="50" rows="10"></textarea><br />
|
158 |
596
|
thorn
|
</p>
|
159 |
760
|
Ruebenwurz
|
|
160 |
596
|
thorn
|
<?php }
|
161 |
|
|
|
162 |
760
|
Ruebenwurz
|
// Print header
|
163 |
|
|
echo $header;
|
164 |
|
|
|
165 |
560
|
Ruebenwurz
|
// Get list of fields
|
166 |
|
|
$query_fields = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
|
167 |
760
|
Ruebenwurz
|
|
168 |
560
|
Ruebenwurz
|
if($query_fields->numRows() > 0) {
|
169 |
|
|
while($field = $query_fields->fetchRow()) {
|
170 |
|
|
// Set field values
|
171 |
|
|
$field_id = $field['field_id'];
|
172 |
|
|
$value = $field['value'];
|
173 |
|
|
// Print field_loop after replacing vars with values
|
174 |
|
|
$vars = array('{TITLE}', '{REQUIRED}');
|
175 |
760
|
Ruebenwurz
|
if (($field['type'] == "radio") || ($field['type'] == "checkbox")) {
|
176 |
|
|
$field_title = $field['title'];
|
177 |
560
|
Ruebenwurz
|
} else {
|
178 |
760
|
Ruebenwurz
|
$field_title = '<label for="field'.$field_id.'">'.$field['title'].'</label>';
|
179 |
|
|
}
|
180 |
|
|
$values = array($field_title);
|
181 |
|
|
if ($field['required'] == 1) {
|
182 |
|
|
$values[] = '<span class="required">*</span>';
|
183 |
|
|
} else {
|
184 |
560
|
Ruebenwurz
|
$values[] = '';
|
185 |
|
|
}
|
186 |
|
|
if($field['type'] == 'textfield') {
|
187 |
|
|
$vars[] = '{FIELD}';
|
188 |
618
|
thorn
|
$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" maxlength="'.$field['extra'].'" value="'.(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:$value).'" class="textfield" />';
|
189 |
560
|
Ruebenwurz
|
} elseif($field['type'] == 'textarea') {
|
190 |
|
|
$vars[] = '{FIELD}';
|
191 |
760
|
Ruebenwurz
|
$values[] = '<textarea name="field'.$field_id.'" id="field'.$field_id.'" class="textarea" cols="25" rows="5">'.(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:$value).'</textarea>';
|
192 |
560
|
Ruebenwurz
|
} elseif($field['type'] == 'select') {
|
193 |
|
|
$vars[] = '{FIELD}';
|
194 |
|
|
$options = explode(',', $value);
|
195 |
618
|
thorn
|
array_walk($options, 'make_option', (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array()));
|
196 |
760
|
Ruebenwurz
|
$field['extra'] = explode(',',$field['extra']);
|
197 |
914
|
Ruebenwurz
|
$values[] = '<select name="field'.$field_id.'[]" id="field'.$field_id.'" size="'.$field['extra'][0].'" '.$field['extra'][1].' class="select">'.implode($options).'</select>';
|
198 |
560
|
Ruebenwurz
|
} elseif($field['type'] == 'heading') {
|
199 |
|
|
$vars[] = '{FIELD}';
|
200 |
935
|
aldus
|
$str = '<input type="hidden" name="field'.$field_id.'" id="field'.$field_id.'" value="===['.$field['title'].']===" />';
|
201 |
|
|
$values[] = ( true == $use_xhtml_strict) ? "<div>".$str."</div>" : $str;
|
202 |
560
|
Ruebenwurz
|
$tmp_field_loop = $field_loop; // temporarily modify the field loop template
|
203 |
|
|
$field_loop = $field['extra'];
|
204 |
|
|
} elseif($field['type'] == 'checkbox') {
|
205 |
|
|
$vars[] = '{FIELD}';
|
206 |
|
|
$options = explode(',', $value);
|
207 |
618
|
thorn
|
array_walk($options, 'make_checkbox', array(array($field_id,$field['extra']),(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array())));
|
208 |
560
|
Ruebenwurz
|
$options[count($options)-1]=substr($options[count($options)-1],0,strlen($options[count($options)-1])-strlen($field['extra']));
|
209 |
|
|
$values[] = implode($options);
|
210 |
|
|
} elseif($field['type'] == 'radio') {
|
211 |
|
|
$vars[] = '{FIELD}';
|
212 |
|
|
$options = explode(',', $value);
|
213 |
618
|
thorn
|
array_walk($options, 'make_radio', array($field_id,$field['title'],$field['extra'], (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:'')));
|
214 |
560
|
Ruebenwurz
|
$options[count($options)-1]=substr($options[count($options)-1],0,strlen($options[count($options)-1])-strlen($field['extra']));
|
215 |
|
|
$values[] = implode($options);
|
216 |
|
|
} elseif($field['type'] == 'email') {
|
217 |
|
|
$vars[] = '{FIELD}';
|
218 |
760
|
Ruebenwurz
|
$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" value="'.(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:'').'" maxlength="'.$field['extra'].'" class="email" />';
|
219 |
560
|
Ruebenwurz
|
}
|
220 |
618
|
thorn
|
if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
|
221 |
560
|
Ruebenwurz
|
if($field['type'] != '') {
|
222 |
|
|
echo str_replace($vars, $values, $field_loop);
|
223 |
|
|
}
|
224 |
|
|
if (isset($tmp_field_loop)) $field_loop = $tmp_field_loop;
|
225 |
|
|
}
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
// Captcha
|
229 |
596
|
thorn
|
if($use_captcha) { ?>
|
230 |
|
|
<tr>
|
231 |
|
|
<td class="field_title"><?php echo $TEXT['VERIFICATION']; ?>:</td>
|
232 |
|
|
<td><?php call_captcha(); ?></td>
|
233 |
|
|
</tr>
|
234 |
560
|
Ruebenwurz
|
<?php
|
235 |
|
|
}
|
236 |
|
|
|
237 |
|
|
// Print footer
|
238 |
|
|
echo $footer;
|
239 |
|
|
|
240 |
789
|
doc
|
/**
|
241 |
|
|
NOTE: comment out the line ob_end_flush() if you indicate problems (e.g. when using ob_start in the index.php of your template)
|
242 |
|
|
With ob_end_flush(): output filter will be disabled for this page (and all sections embedded on this page)
|
243 |
|
|
Without ob_end_flush(): emails are rewritten (e.g. name@domain.com --> name(at)domain(dot)com) if output filter is enabled
|
244 |
|
|
All replacements made by the Output-Filter module will be reverted before the email is send out
|
245 |
|
|
*/
|
246 |
|
|
if($filter_settings['email_filter'] && !($filter_settings['at_replacement']=='@' && $filter_settings['dot_replacement']=='.')) {
|
247 |
|
|
ob_end_flush();
|
248 |
|
|
}
|
249 |
|
|
|
250 |
560
|
Ruebenwurz
|
// Add form end code
|
251 |
|
|
?>
|
252 |
|
|
</form>
|
253 |
|
|
<?php
|
254 |
|
|
|
255 |
|
|
} else {
|
256 |
|
|
|
257 |
|
|
// Check that submission ID matches
|
258 |
|
|
if(isset($_SESSION['form_submission_id']) AND isset($_POST['submission_id']) AND $_SESSION['form_submission_id'] == $_POST['submission_id']) {
|
259 |
|
|
|
260 |
|
|
// Set new submission ID in session
|
261 |
|
|
$_SESSION['form_submission_id'] = new_submission_id();
|
262 |
|
|
|
263 |
596
|
thorn
|
if(ENABLED_ASP && ( // form faked? Check the honeypot-fields.
|
264 |
|
|
(!isset($_POST['submitted_when']) OR !isset($_SESSION['submitted_when'])) OR
|
265 |
|
|
($_POST['submitted_when'] != $_SESSION['submitted_when']) OR
|
266 |
|
|
(!isset($_POST['email']) OR $_POST['email']) OR
|
267 |
|
|
(!isset($_POST['homepage']) OR $_POST['homepage']) OR
|
268 |
|
|
(!isset($_POST['comment']) OR $_POST['comment']) OR
|
269 |
|
|
(!isset($_POST['url']) OR $_POST['url'])
|
270 |
|
|
)) {
|
271 |
|
|
exit(header("Location: ".WB_URL.PAGES_DIRECTORY.""));
|
272 |
|
|
}
|
273 |
|
|
|
274 |
560
|
Ruebenwurz
|
// Submit form data
|
275 |
|
|
// First start message settings
|
276 |
|
|
$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
|
277 |
|
|
if($query_settings->numRows() > 0) {
|
278 |
|
|
$fetch_settings = $query_settings->fetchRow();
|
279 |
|
|
$email_to = $fetch_settings['email_to'];
|
280 |
|
|
$email_from = $fetch_settings['email_from'];
|
281 |
|
|
if(substr($email_from, 0, 5) == 'field') {
|
282 |
|
|
// Set the email from field to what the user entered in the specified field
|
283 |
656
|
thorn
|
$email_from = htmlspecialchars($wb->add_slashes($_POST[$email_from]));
|
284 |
560
|
Ruebenwurz
|
}
|
285 |
638
|
thorn
|
$email_fromname = $fetch_settings['email_fromname'];
|
286 |
560
|
Ruebenwurz
|
$email_subject = $fetch_settings['email_subject'];
|
287 |
|
|
$success_page = $fetch_settings['success_page'];
|
288 |
|
|
$success_email_to = $fetch_settings['success_email_to'];
|
289 |
|
|
if(substr($success_email_to, 0, 5) == 'field') {
|
290 |
|
|
// Set the success_email to field to what the user entered in the specified field
|
291 |
656
|
thorn
|
$success_email_to = htmlspecialchars($wb->add_slashes($_POST[$success_email_to]));
|
292 |
560
|
Ruebenwurz
|
}
|
293 |
|
|
$success_email_from = $fetch_settings['success_email_from'];
|
294 |
638
|
thorn
|
$success_email_fromname = $fetch_settings['success_email_fromname'];
|
295 |
560
|
Ruebenwurz
|
$success_email_text = $fetch_settings['success_email_text'];
|
296 |
|
|
$success_email_subject = $fetch_settings['success_email_subject'];
|
297 |
|
|
$max_submissions = $fetch_settings['max_submissions'];
|
298 |
|
|
$stored_submissions = $fetch_settings['stored_submissions'];
|
299 |
|
|
$use_captcha = $fetch_settings['use_captcha'];
|
300 |
|
|
} else {
|
301 |
|
|
exit($TEXT['UNDER_CONSTRUCTION']);
|
302 |
|
|
}
|
303 |
|
|
$email_body = '';
|
304 |
|
|
|
305 |
|
|
// Create blank "required" array
|
306 |
|
|
$required = array();
|
307 |
|
|
|
308 |
618
|
thorn
|
// Captcha
|
309 |
|
|
if($use_captcha) {
|
310 |
|
|
if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
|
311 |
|
|
// Check for a mismatch
|
312 |
|
|
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
|
313 |
|
|
$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
|
314 |
|
|
}
|
315 |
|
|
} else {
|
316 |
|
|
$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
|
317 |
|
|
}
|
318 |
|
|
}
|
319 |
|
|
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
|
320 |
|
|
|
321 |
560
|
Ruebenwurz
|
// Loop through fields and add to message body
|
322 |
|
|
// Get list of fields
|
323 |
|
|
$query_fields = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
|
324 |
|
|
if($query_fields->numRows() > 0) {
|
325 |
|
|
while($field = $query_fields->fetchRow()) {
|
326 |
|
|
// Add to message body
|
327 |
|
|
if($field['type'] != '') {
|
328 |
|
|
if(!empty($_POST['field'.$field['field_id']])) {
|
329 |
760
|
Ruebenwurz
|
if (is_array($_POST['field'.$field['field_id']])) {
|
330 |
|
|
$_SESSION['field'.$field['field_id']] = $_POST['field'.$field['field_id']];
|
331 |
|
|
} else {
|
332 |
|
|
$_SESSION['field'.$field['field_id']] = htmlspecialchars($_POST['field'.$field['field_id']]);
|
333 |
|
|
}
|
334 |
789
|
doc
|
// if the output filter is active, we need to revert (dot) to . and (at) to @ (using current filter settings)
|
335 |
|
|
// otherwise the entered mail will not be accepted and the recipient would see (dot), (at) etc.
|
336 |
|
|
if ($filter_settings['email_filter']) {
|
337 |
|
|
$field_value = $_POST['field'.$field['field_id']];
|
338 |
|
|
$field_value = str_replace($filter_settings['at_replacement'], '@', $field_value);
|
339 |
|
|
$field_value = str_replace($filter_settings['dot_replacement'], '.', $field_value);
|
340 |
|
|
$_POST['field'.$field['field_id']] = $field_value;
|
341 |
|
|
}
|
342 |
560
|
Ruebenwurz
|
if($field['type'] == 'email' AND $admin->validate_email($_POST['field'.$field['field_id']]) == false) {
|
343 |
|
|
$email_error = $MESSAGE['USERS']['INVALID_EMAIL'];
|
344 |
|
|
}
|
345 |
|
|
if($field['type'] == 'heading') {
|
346 |
|
|
$email_body .= $_POST['field'.$field['field_id']]."\n\n";
|
347 |
|
|
} elseif (!is_array($_POST['field'.$field['field_id']])) {
|
348 |
|
|
$email_body .= $field['title'].': '.$_POST['field'.$field['field_id']]."\n\n";
|
349 |
|
|
} else {
|
350 |
|
|
$email_body .= $field['title'].": \n";
|
351 |
|
|
foreach ($_POST['field'.$field['field_id']] as $k=>$v) {
|
352 |
|
|
$email_body .= $v."\n";
|
353 |
|
|
}
|
354 |
|
|
$email_body .= "\n";
|
355 |
|
|
}
|
356 |
|
|
} elseif($field['required'] == 1) {
|
357 |
|
|
$required[] = $field['title'];
|
358 |
|
|
}
|
359 |
|
|
}
|
360 |
|
|
}
|
361 |
|
|
}
|
362 |
760
|
Ruebenwurz
|
|
363 |
560
|
Ruebenwurz
|
// Check if the user forgot to enter values into all the required fields
|
364 |
|
|
if($required != array()) {
|
365 |
|
|
if(!isset($MESSAGE['MOD_FORM']['REQUIRED_FIELDS'])) {
|
366 |
|
|
echo 'You must enter details for the following fields';
|
367 |
|
|
} else {
|
368 |
|
|
echo $MESSAGE['MOD_FORM']['REQUIRED_FIELDS'];
|
369 |
|
|
}
|
370 |
|
|
echo ':<br /><ul>';
|
371 |
|
|
foreach($required AS $field_title) {
|
372 |
|
|
echo '<li>'.$field_title;
|
373 |
|
|
}
|
374 |
760
|
Ruebenwurz
|
if(isset($email_error)) {
|
375 |
|
|
echo '<li>'.$email_error.'</li>';
|
376 |
|
|
}
|
377 |
|
|
if(isset($captcha_error)) {
|
378 |
|
|
echo '<li>'.$captcha_error.'</li>';
|
379 |
|
|
}
|
380 |
|
|
echo '</ul><a href="'.htmlspecialchars(strip_tags($_SERVER['PHP_SELF'])).'">'.$TEXT['BACK'].'</a>';
|
381 |
560
|
Ruebenwurz
|
} else {
|
382 |
|
|
if(isset($email_error)) {
|
383 |
|
|
echo '<br /><ul>';
|
384 |
|
|
echo '<li>'.$email_error.'</li>';
|
385 |
760
|
Ruebenwurz
|
echo '</ul><a href="'.htmlspecialchars(strip_tags($_SERVER['PHP_SELF'])).'">'.$TEXT['BACK'].'</a>';
|
386 |
560
|
Ruebenwurz
|
} elseif(isset($captcha_error)) {
|
387 |
|
|
echo '<br /><ul>';
|
388 |
|
|
echo '<li>'.$captcha_error.'</li>';
|
389 |
760
|
Ruebenwurz
|
echo '</ul><a href="'.htmlspecialchars(strip_tags($_SERVER['PHP_SELF'])).'">'.$TEXT['BACK'].'</a>';
|
390 |
560
|
Ruebenwurz
|
} else {
|
391 |
|
|
// Check how many times form has been submitted in last hour
|
392 |
|
|
$last_hour = time()-3600;
|
393 |
|
|
$query_submissions = $database->query("SELECT submission_id FROM ".TABLE_PREFIX."mod_form_submissions WHERE submitted_when >= '$last_hour'");
|
394 |
|
|
if($query_submissions->numRows() > $max_submissions) {
|
395 |
|
|
// Too many submissions so far this hour
|
396 |
|
|
echo $MESSAGE['MOD_FORM']['EXCESS_SUBMISSIONS'];
|
397 |
|
|
$success = false;
|
398 |
|
|
} else {
|
399 |
889
|
aldus
|
/**
|
400 |
|
|
* Adding the IP to the body and try to send the email
|
401 |
|
|
*/
|
402 |
|
|
$email_body .= "\n\nIP: ".$_SERVER['REMOTE_ADDR'];
|
403 |
|
|
|
404 |
560
|
Ruebenwurz
|
if($email_to != '') {
|
405 |
|
|
if($email_from != '') {
|
406 |
638
|
thorn
|
if($wb->mail($email_from,$email_to,$email_subject,$email_body,$email_fromname)) {
|
407 |
560
|
Ruebenwurz
|
$success = true;
|
408 |
|
|
}
|
409 |
|
|
} else {
|
410 |
638
|
thorn
|
if($wb->mail('',$email_to,$email_subject,$email_body,$email_fromname)) {
|
411 |
560
|
Ruebenwurz
|
$success = true;
|
412 |
|
|
}
|
413 |
|
|
}
|
414 |
|
|
}
|
415 |
|
|
if($success_email_to != '') {
|
416 |
|
|
if($success_email_from != '') {
|
417 |
638
|
thorn
|
if($wb->mail($success_email_from,$success_email_to,$success_email_subject,$success_email_text,$success_email_fromname)) {
|
418 |
560
|
Ruebenwurz
|
$success = true;
|
419 |
|
|
}
|
420 |
|
|
} else {
|
421 |
638
|
thorn
|
if($wb->mail('',$success_email_to,$success_email_subject,$success_email_text,$success_email_fromname)) {
|
422 |
560
|
Ruebenwurz
|
$success = true;
|
423 |
|
|
}
|
424 |
|
|
}
|
425 |
|
|
}
|
426 |
|
|
|
427 |
|
|
// Write submission to database
|
428 |
596
|
thorn
|
if(isset($admin) AND $admin->is_authenticated() AND $admin->get_user_id() > 0) {
|
429 |
|
|
$submitted_by = $admin->get_user_id();
|
430 |
560
|
Ruebenwurz
|
} else {
|
431 |
|
|
$submitted_by = 0;
|
432 |
|
|
}
|
433 |
|
|
$email_body = $wb->add_slashes($email_body);
|
434 |
|
|
$database->query("INSERT INTO ".TABLE_PREFIX."mod_form_submissions (page_id,section_id,submitted_when,submitted_by,body) VALUES ('".PAGE_ID."','$section_id','".mktime()."','$submitted_by','$email_body')");
|
435 |
|
|
// Make sure submissions table isn't too full
|
436 |
|
|
$query_submissions = $database->query("SELECT submission_id FROM ".TABLE_PREFIX."mod_form_submissions ORDER BY submitted_when");
|
437 |
|
|
$num_submissions = $query_submissions->numRows();
|
438 |
|
|
if($num_submissions > $stored_submissions) {
|
439 |
|
|
// Remove excess submission
|
440 |
|
|
$num_to_remove = $num_submissions-$stored_submissions;
|
441 |
|
|
while($submission = $query_submissions->fetchRow()) {
|
442 |
|
|
if($num_to_remove > 0) {
|
443 |
|
|
$submission_id = $submission['submission_id'];
|
444 |
|
|
$database->query("DELETE FROM ".TABLE_PREFIX."mod_form_submissions WHERE submission_id = '$submission_id'");
|
445 |
|
|
$num_to_remove = $num_to_remove-1;
|
446 |
|
|
}
|
447 |
|
|
}
|
448 |
|
|
}
|
449 |
|
|
if(!$database->is_error()) {
|
450 |
|
|
$success = true;
|
451 |
|
|
}
|
452 |
|
|
}
|
453 |
|
|
}
|
454 |
|
|
}
|
455 |
|
|
}
|
456 |
|
|
|
457 |
|
|
// Now check if the email was sent successfully
|
458 |
|
|
if(isset($success) AND $success == true) {
|
459 |
760
|
Ruebenwurz
|
if ($success_page=='none') {
|
460 |
560
|
Ruebenwurz
|
echo str_replace("\n","<br />",$success_email_text);
|
461 |
|
|
} else {
|
462 |
|
|
$query_menu = $database->query("SELECT link,target FROM ".TABLE_PREFIX."pages WHERE `page_id` = '$success_page'");
|
463 |
|
|
if($query_menu->numRows() > 0) {
|
464 |
760
|
Ruebenwurz
|
$fetch_settings = $query_menu->fetchRow();
|
465 |
|
|
$link = WB_URL.PAGES_DIRECTORY.$fetch_settings['link'].PAGE_EXTENSION;
|
466 |
|
|
echo "<script type='text/javascript'>location.href='".$link."';</script>";
|
467 |
560
|
Ruebenwurz
|
}
|
468 |
|
|
}
|
469 |
760
|
Ruebenwurz
|
// clearing session on success
|
470 |
935
|
aldus
|
$query_fields = $database->query("SELECT field_id FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id'");
|
471 |
760
|
Ruebenwurz
|
while($field = $query_fields->fetchRow()) {
|
472 |
|
|
$field_id = $field[0];
|
473 |
|
|
if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
|
474 |
|
|
}
|
475 |
560
|
Ruebenwurz
|
} else {
|
476 |
760
|
Ruebenwurz
|
if(isset($success) AND $success == false) {
|
477 |
|
|
echo $TEXT['ERROR'];
|
478 |
|
|
}
|
479 |
935
|
aldus
|
}
|
480 |
560
|
Ruebenwurz
|
}
|
481 |
|
|
|
482 |
760
|
Ruebenwurz
|
?>
|