1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category module
|
5
|
* @package Form
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
8
|
* @link http://www.websitebaker2.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: view.php 1655 2012-03-31 23:41:19Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/form/view.php $
|
14
|
* @lastmodified $Date: 2012-04-01 01:41:19 +0200 (Sun, 01 Apr 2012) $
|
15
|
* @description
|
16
|
*/
|
17
|
|
18
|
// Must include code to stop this file being access directly
|
19
|
/* -------------------------------------------------------- */
|
20
|
if(defined('WB_PATH') == false)
|
21
|
{
|
22
|
// Stop this file being access directly
|
23
|
die('<head><title>Access denied</title></head><body><h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2></body></html>');
|
24
|
}
|
25
|
/* -------------------------------------------------------- */
|
26
|
|
27
|
// load module language file
|
28
|
$lang = (dirname(__FILE__)) . '/languages/' . LANGUAGE . '.php';
|
29
|
require_once(!file_exists($lang) ? (dirname(__FILE__)) . '/languages/EN.php' : $lang );
|
30
|
|
31
|
include_once(WB_PATH .'/framework/functions.php');
|
32
|
$aWebsiteTitle = (defined('WEBSITE_TITLE') && WEBSITE_TITLE != '' ? WEBSITE_TITLE : $_SERVER['SERVER_NAME']);
|
33
|
$replace = array('WEBSITE_TITLE' => $aWebsiteTitle );
|
34
|
$MOD_FORM['EMAIL_SUBJECT'] = replace_vars($MOD_FORM['EMAIL_SUBJECT'], $replace);
|
35
|
$MOD_FORM['SUCCESS_EMAIL_TEXT'] = replace_vars($MOD_FORM['SUCCESS_EMAIL_TEXT'], $replace);
|
36
|
$MOD_FORM['SUCCESS_EMAIL_SUBJECT'] = replace_vars($MOD_FORM['SUCCESS_EMAIL_SUBJECT'], $replace);
|
37
|
/*
|
38
|
function removebreaks($value) {
|
39
|
return trim(preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i', null, $value));
|
40
|
}
|
41
|
function checkbreaks($value) {
|
42
|
return $value === removebreaks($value);
|
43
|
}
|
44
|
*/
|
45
|
|
46
|
if (!function_exists('emailAdmin')) {
|
47
|
function emailAdmin() {
|
48
|
global $database,$admin;
|
49
|
$retval = $admin->get_email();
|
50
|
if($admin->get_user_id()!='1') {
|
51
|
$sql = 'SELECT `email` FROM `'.TABLE_PREFIX.'users` ';
|
52
|
$sql .= 'WHERE `user_id`=\'1\' ';
|
53
|
$retval = $database->get_one($sql);
|
54
|
|
55
|
}
|
56
|
return $retval;
|
57
|
}
|
58
|
}
|
59
|
|
60
|
// Function for generating an optionsfor a select field
|
61
|
if (!function_exists('make_option')) {
|
62
|
function make_option(&$n, $k, $values) {
|
63
|
// start option group if it exists
|
64
|
if (substr($n,0,2) == '[=') {
|
65
|
$n = '<optgroup label="'.substr($n,2,strlen($n)).'">'.PHP_EOL;
|
66
|
} elseif ($n == ']') {
|
67
|
$n = '</optgroup>'.PHP_EOL;
|
68
|
} else {
|
69
|
if(in_array($n, $values)) {
|
70
|
$n = '<option selected="selected" value="'.$n.'">'.$n.'</option>'.PHP_EOL;
|
71
|
} else {
|
72
|
$n = '<option value="'.$n.'">'.$n.'</option>'.PHP_EOL;
|
73
|
}
|
74
|
}
|
75
|
}
|
76
|
}
|
77
|
// Function for generating a checkbox
|
78
|
if (!function_exists('make_checkbox')) {
|
79
|
function make_checkbox(&$key, $idx, $params) {
|
80
|
$field_id = $params[0][0];
|
81
|
$seperator = $params[0][1];
|
82
|
|
83
|
$label_id = 'wb_'.preg_replace('/[^a-z0-9]/i', '_', $key).$field_id;
|
84
|
if(in_array($key, $params[1])) {
|
85
|
$key = '<input class="frm-field_checkbox" type="checkbox" id="'.$label_id.'" name="field'.$field_id.'['.$idx.']" value="'.$key.'" />'.'<label for="'.$label_id.'" class="frm-checkbox_label">'.$key.'</lable>'.$seperator.PHP_EOL;
|
86
|
} else {
|
87
|
$key = '<input class="frm-field_checkbox" type="checkbox" id="'.$label_id.'" name="field'.$field_id.'['.$idx.']" value="'.$key.'" />'.'<label for="'.$label_id.'" class="frm-checkbox_label">'.$key.'</label>'.$seperator.PHP_EOL;
|
88
|
}
|
89
|
}
|
90
|
}
|
91
|
// Function for generating a radio button
|
92
|
if (!function_exists('make_radio')) {
|
93
|
function make_radio(&$n, $idx, $params) {
|
94
|
$field_id = $params[0];
|
95
|
$group = $params[1];
|
96
|
$seperator = $params[2];
|
97
|
$label_id = 'wb_'.preg_replace('/[^a-z0-9]/i', '_', $n).$field_id;
|
98
|
if($n == $params[3]) {
|
99
|
$n = '<input class="frm-field_checkbox" type="radio" id="'.$label_id.'" name="field'.$field_id.'" value="'.$n.'" checked="checked" />'.'<label for="'.$label_id.'" class="frm-checkbox_label">'.$n.'</label>'.$seperator.PHP_EOL;
|
100
|
} else {
|
101
|
$n = '<input class="frm-field_checkbox" type="radio" id="'.$label_id.'" name="field'.$field_id.'" value="'.$n.'" />'.'<label for="'.$label_id.'" class="frm-checkbox_label">'.$n.'</label>'.$seperator.PHP_EOL;
|
102
|
}
|
103
|
}
|
104
|
}
|
105
|
|
106
|
if (!function_exists("new_submission_id") ) {
|
107
|
function new_submission_id() {
|
108
|
$submission_id = '';
|
109
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
110
|
srand((double)microtime()*1000000);
|
111
|
$i = 0;
|
112
|
while ($i <= 7) {
|
113
|
$num = rand() % 33;
|
114
|
$tmp = substr($salt, $num, 1);
|
115
|
$submission_id = $submission_id . $tmp;
|
116
|
$i++;
|
117
|
}
|
118
|
return $submission_id;
|
119
|
}
|
120
|
}
|
121
|
|
122
|
// Work-out if the form has been submitted or not
|
123
|
if($_POST == array())
|
124
|
{
|
125
|
require_once(WB_PATH.'/include/captcha/captcha.php');
|
126
|
|
127
|
// Set new submission ID in session
|
128
|
$_SESSION['form_submission_id'] = new_submission_id();
|
129
|
$out = '';
|
130
|
$header = '';
|
131
|
$field_loop = '';
|
132
|
$footer = '';
|
133
|
$form_name = 'form';
|
134
|
$use_xhtml_strict = false;
|
135
|
// Get settings
|
136
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_settings` ';
|
137
|
$sql .= 'WHERE section_id = '.$section_id.' ';
|
138
|
if($query_settings = $database->query($sql))
|
139
|
{
|
140
|
if($query_settings->numRows() > 0)
|
141
|
{
|
142
|
$fetch_settings = $query_settings->fetchRow(MYSQL_ASSOC);
|
143
|
$header = str_replace('{WB_URL}',WB_URL,$fetch_settings['header']);
|
144
|
$field_loop = $fetch_settings['field_loop'];
|
145
|
$footer = str_replace('{WB_URL}',WB_URL,$fetch_settings['footer']);
|
146
|
$use_captcha = $fetch_settings['use_captcha'];
|
147
|
$form_name = 'form';
|
148
|
$use_xhtml_strict = false;
|
149
|
$page_id = $fetch_settings['page_id'];
|
150
|
}
|
151
|
}
|
152
|
|
153
|
// do not use sec_anchor, can destroy some layouts
|
154
|
$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' ) ? '#'.SEC_ANCHOR.$section['section_id'] : '' );
|
155
|
|
156
|
// Get list of fields
|
157
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_fields` ';
|
158
|
$sql .= 'WHERE section_id = '.$section_id.' ';
|
159
|
$sql .= 'ORDER BY position ASC ';
|
160
|
|
161
|
if($query_fields = $database->query($sql)) {
|
162
|
if($query_fields->numRows() > 0) {
|
163
|
?>
|
164
|
<form <?php echo ( ( (strlen($form_name) > 0) AND (false == $use_xhtml_strict) ) ? "name=\"".$form_name."\"" : ""); ?> action="<?php echo htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'';?>" method="post">
|
165
|
<input type="hidden" name="submission_id" value="<?php echo $_SESSION['form_submission_id']; ?>" />
|
166
|
<?php
|
167
|
$iFormRequestId = isset($_GET['fri']) ? intval($_GET['fri']) : 0;
|
168
|
if($iFormRequestId) {
|
169
|
echo '<input type="hidden" name="fri" value="'.$iFormRequestId.'" />'."\n";
|
170
|
}
|
171
|
?>
|
172
|
<?php // echo $admin->getFTAN(); ?>
|
173
|
<?php
|
174
|
if(ENABLED_ASP) { // first add some honeypot-fields
|
175
|
?>
|
176
|
<input type="hidden" name="submitted_when" value="<?php $t=time(); echo $t; $_SESSION['submitted_when']=$t; ?>" />
|
177
|
<p class="frm-nixhier">
|
178
|
email address:
|
179
|
<label for="email">Leave this field email-address blank:</label>
|
180
|
<input id="email" name="email" size="56" value="" /><br />
|
181
|
Homepage:
|
182
|
<label for="homepage">Leave this field homepage blank:</label>
|
183
|
<input id="homepage" name="homepage" size="55" value="" /><br />
|
184
|
URL:
|
185
|
<label for="url">Leave this field url blank:</label>
|
186
|
<input id="url" name="url" size="61" value="" /><br />
|
187
|
Comment:
|
188
|
<label for="comment">Leave this field comment blank:</label>
|
189
|
<textarea id="comment" name="comment" cols="50" rows="10"></textarea><br />
|
190
|
</p>
|
191
|
<?php }
|
192
|
|
193
|
// Print header MYSQL_ASSOC
|
194
|
echo $header."\n";
|
195
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
196
|
// Set field values
|
197
|
$field_id = $field['field_id'];
|
198
|
$value = $field['value'];
|
199
|
// Print field_loop after replacing vars with values
|
200
|
$vars = array('{TITLE}', '{REQUIRED}');
|
201
|
if (($field['type'] == "radio") || ($field['type'] == "checkbox")) {
|
202
|
$field_title = $field['title'];
|
203
|
} else {
|
204
|
$field_title = '<label for="field'.$field_id.'">'.$field['title'].'</label>'.PHP_EOL;
|
205
|
}
|
206
|
$values = array($field_title);
|
207
|
if ($field['required'] == 1) {
|
208
|
$values[] = '<span class="frm-required">*</span>'."\n";
|
209
|
} else {
|
210
|
$values[] = '';
|
211
|
}
|
212
|
if($field['type'] == 'textfield') {
|
213
|
$vars[] = '{FIELD}';
|
214
|
$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
|
215
|
$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'"'.$max_lenght_para.' value="'.(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:$value).'" class="frm-textfield" />'.PHP_EOL;
|
216
|
} elseif($field['type'] == 'textarea') {
|
217
|
$vars[] = '{FIELD}';
|
218
|
$values[] = '<textarea name="field'.$field_id.'" id="field'.$field_id.'" class="frm-textarea" cols="30" rows="8">'.(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:$value).'</textarea>'.PHP_EOL;
|
219
|
} elseif($field['type'] == 'select') {
|
220
|
$vars[] = '{FIELD}';
|
221
|
$options = explode(',', $value);
|
222
|
array_walk($options, 'make_option', (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array()));
|
223
|
$field['extra'] = explode(',',$field['extra']);
|
224
|
$values[] = '<select name="field'.$field_id.'[]" id="field'.$field_id.'" size="'.$field['extra'][0].'" '.$field['extra'][1].' class="frm-select">'.implode($options).'</select>'.PHP_EOL;
|
225
|
} elseif($field['type'] == 'heading') {
|
226
|
$vars[] = '{FIELD}';
|
227
|
$str = '<input type="hidden" name="field'.$field_id.'" id="field'.$field_id.'" value="===['.$field['title'].']===" />';
|
228
|
$values[] = ( true == $use_xhtml_strict) ? "<div>".$str."</div>" : $str;
|
229
|
$tmp_field_loop = $field_loop; // temporarily modify the field loop template
|
230
|
$field_loop = $field['extra'];
|
231
|
} elseif($field['type'] == 'checkbox') {
|
232
|
$vars[] = '{FIELD}';
|
233
|
$options = explode(',', $value);
|
234
|
array_walk($options, 'make_checkbox', array(array($field_id,$field['extra']),(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array())));
|
235
|
$x = sizeof($options)-1;
|
236
|
$options[$x]=substr($options[$x],0,strlen($options[$x]));
|
237
|
$values[] = implode($options);
|
238
|
} elseif($field['type'] == 'radio') {
|
239
|
$vars[] = '{FIELD}';
|
240
|
$options = explode(',', $value);
|
241
|
array_walk($options, 'make_radio', array($field_id,$field['title'],$field['extra'], (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:'')));
|
242
|
$x = sizeof($options)-1;
|
243
|
$options[$x]=substr($options[$x],0,strlen($options[$x]));
|
244
|
$values[] = implode($options);
|
245
|
} elseif($field['type'] == 'email') {
|
246
|
$vars[] = '{FIELD}';
|
247
|
$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
|
248
|
$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" value="'.(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:'').'"'.$max_lenght_para.' class="frm-email" />'.PHP_EOL;
|
249
|
}
|
250
|
if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
|
251
|
if($field['type'] != '') {
|
252
|
echo str_replace($vars, $values, $field_loop);
|
253
|
}
|
254
|
if (isset($tmp_field_loop)){ $field_loop = $tmp_field_loop; }
|
255
|
}
|
256
|
// Captcha
|
257
|
if($use_captcha) { ?>
|
258
|
<tr>
|
259
|
<td class="frm-field_title"><?php echo $TEXT['VERIFICATION']; ?>:</td>
|
260
|
<td><?php call_captcha(); ?></td>
|
261
|
</tr>
|
262
|
<?php
|
263
|
}
|
264
|
// Print footer
|
265
|
// $out = $footer.PHP_EOL;
|
266
|
$out .= str_replace('{SUBMIT_FORM}', $MOD_FORM['SUBMIT_FORM'], $footer);
|
267
|
echo $out;
|
268
|
// Add form end code
|
269
|
?>
|
270
|
</form>
|
271
|
<?php
|
272
|
}
|
273
|
}
|
274
|
|
275
|
} else {
|
276
|
|
277
|
// Check that submission ID matches
|
278
|
if(isset($_SESSION['form_submission_id']) AND isset($_POST['submission_id']) AND $_SESSION['form_submission_id'] == $_POST['submission_id']) {
|
279
|
|
280
|
$mail_replyto = '';
|
281
|
$mail_replyName = '';
|
282
|
if( $wb->is_authenticated() && $wb->get_email() ) {
|
283
|
$mail_replyto = $wb->get_email();
|
284
|
$mail_replyName = htmlspecialchars($wb->add_slashes($wb->get_display_name()));
|
285
|
}
|
286
|
|
287
|
// Set new submission ID in session
|
288
|
$_SESSION['form_submission_id'] = new_submission_id();
|
289
|
|
290
|
if(ENABLED_ASP && ( // form faked? Check the honeypot-fields.
|
291
|
(!isset($_POST['submitted_when']) OR !isset($_SESSION['submitted_when'])) OR
|
292
|
($_POST['submitted_when'] != $_SESSION['submitted_when']) OR
|
293
|
(!isset($_POST['email']) OR $_POST['email']) OR
|
294
|
(!isset($_POST['homepage']) OR $_POST['homepage']) OR
|
295
|
(!isset($_POST['comment']) OR $_POST['comment']) OR
|
296
|
(!isset($_POST['url']) OR $_POST['url'])
|
297
|
)) {
|
298
|
// spam
|
299
|
header("Location: ".WB_URL.PAGES_DIRECTORY."");
|
300
|
exit();
|
301
|
}
|
302
|
// Submit form data
|
303
|
// First start message settings
|
304
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_settings` ';
|
305
|
$sql .= 'WHERE `section_id` = '.(int)$section_id.'';
|
306
|
if($query_settings = $database->query($sql) ) {
|
307
|
if($query_settings->numRows() > 0) {
|
308
|
$fetch_settings = $query_settings->fetchRow(MYSQL_ASSOC);
|
309
|
|
310
|
// $email_to = $fetch_settings['email_to'];
|
311
|
$email_to = (($fetch_settings['email_to'] != '') ? $fetch_settings['email_to'] : emailAdmin());
|
312
|
$email_from = $admin->add_slashes(SERVER_EMAIL);
|
313
|
/*
|
314
|
if(substr($email_from, 0, 5) == 'field') {
|
315
|
// Set the email from field to what the user entered in the specified field
|
316
|
$email_from = htmlspecialchars($wb->add_slashes($_POST[$email_from]));
|
317
|
}
|
318
|
*/
|
319
|
$email_fromname = $fetch_settings['email_fromname'];
|
320
|
// $email_fromname = (($mail_replyName='') ? $fetch_settings['email_fromname'] : $mail_replyName);
|
321
|
$email_fromname = (($mail_replyName='') ? htmlspecialchars($wb->add_slashes($fetch_settings['email_fromname'])) : $mail_replyName);
|
322
|
|
323
|
if(substr($email_fromname, 0, 5) == 'field') {
|
324
|
// Set the email_fromname to field to what the user entered in the specified field
|
325
|
$email_fromname = htmlspecialchars($wb->add_slashes($_POST[$email_fromname]));
|
326
|
}
|
327
|
|
328
|
$email_subject = (($fetch_settings['email_subject'] != '') ? $fetch_settings['email_subject'] : $MOD_FORM['EMAIL_SUBJECT']);
|
329
|
$success_page = $fetch_settings['success_page'];
|
330
|
$success_email_to = $mail_replyto;
|
331
|
/*
|
332
|
$success_email_to = (($fetch_settings['success_email_to'] != '') ? $fetch_settings['success_email_to'] : '');
|
333
|
if(substr($success_email_to, 0, 5) == 'field') {
|
334
|
// Set the success_email to field to what the user entered in the specified field
|
335
|
$success_email_to = htmlspecialchars($wb->add_slashes($_POST[$success_email_to]));
|
336
|
}
|
337
|
*/
|
338
|
$success_email_from = $admin->add_slashes(SERVER_EMAIL);
|
339
|
$success_email_fromname = $fetch_settings['success_email_fromname'];
|
340
|
$success_email_text = htmlspecialchars($wb->add_slashes($fetch_settings['success_email_text']));
|
341
|
$success_email_text = (($success_email_text != '') ? $success_email_text : $MOD_FORM['SUCCESS_EMAIL_TEXT']);
|
342
|
$success_email_subject = (($fetch_settings['success_email_subject'] != '') ? $fetch_settings['success_email_subject'] : $MOD_FORM['SUCCESS_EMAIL_SUBJECT']);
|
343
|
$max_submissions = $fetch_settings['max_submissions'];
|
344
|
$stored_submissions = $fetch_settings['stored_submissions'];
|
345
|
$use_captcha = $fetch_settings['use_captcha'];
|
346
|
} else {
|
347
|
exit($TEXT['UNDER_CONSTRUCTION']);
|
348
|
}
|
349
|
}
|
350
|
|
351
|
$email_body = '';
|
352
|
// Create blank "required" array
|
353
|
$required = array();
|
354
|
|
355
|
// Captcha
|
356
|
if($use_captcha) {
|
357
|
if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
|
358
|
// Check for a mismatch get email user_id
|
359
|
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
|
360
|
$replace = array('webmaster_email' => emailAdmin() );
|
361
|
$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'], $replace);
|
362
|
$required[]= '';
|
363
|
}
|
364
|
} else {
|
365
|
$replace = array('webmaster_email'=>emailAdmin() );
|
366
|
$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'],$replace );
|
367
|
$required[]= '';
|
368
|
}
|
369
|
}
|
370
|
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
|
371
|
|
372
|
// Loop through fields and add to message body
|
373
|
// Get list of fields
|
374
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_fields` ';
|
375
|
$sql .= 'WHERE `section_id` = '.(int)$section_id.' ';
|
376
|
$sql .= 'ORDER BY position ASC';
|
377
|
if($query_fields = $database->query($sql)) {
|
378
|
if($query_fields->numRows() > 0) {
|
379
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
380
|
// Add to message body
|
381
|
if($field['type'] != '') {
|
382
|
if(!empty($_POST['field'.$field['field_id']]))
|
383
|
{
|
384
|
// do not allow droplets in user input!
|
385
|
if (is_array($_POST['field'.$field['field_id']])) {
|
386
|
$_SESSION['field'.$field['field_id']] = str_replace(array("[[", "]]"), array("[[", "]]"), $wb->strip_slashes($_POST['field'.$field['field_id']]));
|
387
|
} else {
|
388
|
$_SESSION['field'.$field['field_id']] = str_replace(array("[[", "]]"), array("[[", "]]"), htmlspecialchars($wb->strip_slashes($_POST['field'.$field['field_id']])));
|
389
|
}
|
390
|
|
391
|
if($field['type'] == 'email' AND $admin->validate_email($_POST['field'.$field['field_id']]) == false) {
|
392
|
$email_error = $MESSAGE['USERS_INVALID_EMAIL'];
|
393
|
$required[]= '';
|
394
|
}
|
395
|
if($field['type'] == 'heading') {
|
396
|
$email_body .= $_POST['field'.$field['field_id']]."\n\n";
|
397
|
} elseif (!is_array($_POST['field'.$field['field_id']])) {
|
398
|
$email_body .= $field['title'].': '.$_POST['field'.$field['field_id']]."\n\n";
|
399
|
} else {
|
400
|
$email_body .= $field['title'].": \n";
|
401
|
foreach ($_POST['field'.$field['field_id']] as $k=>$v) {
|
402
|
$email_body .= $v."\n";
|
403
|
}
|
404
|
$email_body .= "\n";
|
405
|
}
|
406
|
|
407
|
} elseif($field['required'] == 1) {
|
408
|
$required[] = $field['title'];
|
409
|
}
|
410
|
}
|
411
|
} // while
|
412
|
} // numRows
|
413
|
} // query
|
414
|
|
415
|
// Check if the user forgot to enter values into all the required fields
|
416
|
if(sizeof($required )) {
|
417
|
|
418
|
if(!isset($MESSAGE['MOD_FORM_REQUIRED_FIELDS'])) {
|
419
|
echo '<h3>You must enter details for the following fields</h3>';
|
420
|
} else {
|
421
|
echo '<h3>'.$MESSAGE['MOD_FORM_REQUIRED_FIELDS'].'</h3>';
|
422
|
}
|
423
|
echo "<ul>\n";
|
424
|
foreach($required AS $field_title) {
|
425
|
if($field_title!=''){
|
426
|
echo '<li>'.$field_title."</li>\n";
|
427
|
}
|
428
|
}
|
429
|
|
430
|
if(isset($email_error)) {
|
431
|
echo '<li>'.$email_error."</li>\n";
|
432
|
}
|
433
|
|
434
|
if(isset($captcha_error)) {
|
435
|
echo '<li>'.$captcha_error."</li>\n";
|
436
|
}
|
437
|
// Create blank "required" array
|
438
|
$required = array();
|
439
|
echo "</ul>\n";
|
440
|
|
441
|
echo '<p> </p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
|
442
|
} else {
|
443
|
if(isset($email_error)) {
|
444
|
echo '<br /><ul>'."\n";
|
445
|
echo '<li>'.$email_error.'</li>'."\n";
|
446
|
echo '</ul>'."\n";
|
447
|
echo '<a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a>';
|
448
|
} elseif(isset($captcha_error)) {
|
449
|
echo '<br /><ul>'."\n";
|
450
|
echo '<li>'.$captcha_error.'</li>'."\n";
|
451
|
echo '</ul>'."\n";
|
452
|
echo '<p> </p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
|
453
|
} else {
|
454
|
// Check how many times form has been submitted in last hour
|
455
|
$last_hour = time()-3600;
|
456
|
$sql = 'SELECT `submission_id` FROM `'.TABLE_PREFIX.'mod_form_submissions` ';
|
457
|
$sql .= 'WHERE `submitted_when` >= '.$last_hour.'';
|
458
|
$sql .= '';
|
459
|
if($query_submissions = $database->query($sql))
|
460
|
{
|
461
|
if($query_submissions->numRows() > $max_submissions)
|
462
|
{
|
463
|
// Too many submissions so far this hour
|
464
|
echo $MESSAGE['MOD_FORM_EXCESS_SUBMISSIONS'];
|
465
|
$success = false;
|
466
|
} else {
|
467
|
// Adding the IP to the body and try to send the email
|
468
|
// $email_body .= "\n\nIP: ".$_SERVER['REMOTE_ADDR'];
|
469
|
$iFormRequestId = isset($_POST['fri']) ? intval($_POST['fri']) : 0;
|
470
|
if($iFormRequestId) {
|
471
|
$email_body .= "\n\nFormRequestID: ".$iFormRequestId;
|
472
|
}
|
473
|
$recipient = preg_replace( "/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $email_fromname );
|
474
|
$email_fromname = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient );
|
475
|
$email_body = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $email_body );
|
476
|
|
477
|
if($email_to != '') {
|
478
|
if($email_from != '') {
|
479
|
$success = $wb->mail(SERVER_EMAIL,$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
|
480
|
} else {
|
481
|
$success = $wb->mail('',$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
|
482
|
}
|
483
|
}
|
484
|
|
485
|
if($success==true)
|
486
|
{
|
487
|
$recipient = preg_replace( "/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $success_email_fromname );
|
488
|
$success_email_fromname = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient );
|
489
|
$success_email_text = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $success_email_text );
|
490
|
if($success_email_to != '') {
|
491
|
if($success_email_from != '') {
|
492
|
$success = $wb->mail(SERVER_EMAIL,$success_email_to,$success_email_subject,($success_email_text).$MOD_FORM['SUCCESS_EMAIL_TEXT_GENERATED'],$success_email_fromname,$mail_replyto);
|
493
|
} else {
|
494
|
$success = $wb->mail('',$success_email_to,$success_email_subject,($success_email_text).$MOD_FORM['SUCCESS_EMAIL_TEXT_GENERATED'],$success_email_fromname,$mail_replyto);
|
495
|
}
|
496
|
}
|
497
|
}
|
498
|
|
499
|
if($success==true)
|
500
|
{
|
501
|
// Write submission to database
|
502
|
if(isset($admin) AND $admin->is_authenticated() AND $admin->get_user_id() > 0) {
|
503
|
$submitted_by = $admin->get_user_id();
|
504
|
} else {
|
505
|
$submitted_by = 0;
|
506
|
}
|
507
|
$email_body = htmlspecialchars($wb->add_slashes($email_body));
|
508
|
$sql = 'INSERT INTO '.TABLE_PREFIX.'mod_form_submissions ';
|
509
|
$sql .= 'SET ';
|
510
|
$sql .= 'page_id='.$wb->page_id.',';
|
511
|
$sql .= 'section_id='.$section_id.',';
|
512
|
$sql .= 'submitted_when='.time().',';
|
513
|
$sql .= 'submitted_by=\''.$submitted_by.'\', ';
|
514
|
$sql .= 'body=\''.$email_body.'\' ';
|
515
|
if($database->query($sql))
|
516
|
{
|
517
|
if(!$database->is_error()) {
|
518
|
$success = true;
|
519
|
}
|
520
|
// Make sure submissions table isn't too full
|
521
|
$query_submissions = $database->query("SELECT submission_id FROM ".TABLE_PREFIX."mod_form_submissions ORDER BY submitted_when");
|
522
|
$num_submissions = $query_submissions->numRows();
|
523
|
if($num_submissions > $stored_submissions)
|
524
|
{
|
525
|
// Remove excess submission
|
526
|
$num_to_remove = $num_submissions-$stored_submissions;
|
527
|
while($submission = $query_submissions->fetchRow(MYSQL_ASSOC))
|
528
|
{
|
529
|
if($num_to_remove > 0)
|
530
|
{
|
531
|
$submission_id = $submission['submission_id'];
|
532
|
$database->query("DELETE FROM ".TABLE_PREFIX."mod_form_submissions WHERE submission_id = '$submission_id'");
|
533
|
$num_to_remove = $num_to_remove-1;
|
534
|
}
|
535
|
}
|
536
|
} // $num_submissions
|
537
|
} // numRows
|
538
|
} // $success
|
539
|
}
|
540
|
} // end how many times form has been submitted in last hour
|
541
|
}
|
542
|
} // email_error
|
543
|
} else {
|
544
|
|
545
|
echo '<p> </p>'.PHP_EOL.'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'.PHP_EOL;
|
546
|
}
|
547
|
|
548
|
$success_page = ( (isset($success_page) ) ? $success_page : $page_id);
|
549
|
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` ';
|
550
|
$sql .= 'WHERE `page_id` = '.(int)$success_page;
|
551
|
$sSuccessLink = WB_URL; // if failed set default
|
552
|
if( ($link = $database->get_one($sql)) ) {
|
553
|
$sSuccessLink = WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
|
554
|
}
|
555
|
// Now check if the email was sent successfully
|
556
|
if(isset($success) && $success == true)
|
557
|
{
|
558
|
if ($success_page=='none') {
|
559
|
echo str_replace("\n","<br />",($success_email_text));
|
560
|
echo '<p> </p>'.PHP_EOL.'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'.PHP_EOL;
|
561
|
} else {
|
562
|
echo "<script type='text/javascript'>location.href='".$sSuccessLink."';</script>";
|
563
|
}
|
564
|
// clearing session on success
|
565
|
$query_fields = $database->query("SELECT field_id FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id'");
|
566
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
567
|
$field_id = $field['field_id'];
|
568
|
if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
|
569
|
}
|
570
|
} else {
|
571
|
if(isset($success) && $success == false) {
|
572
|
echo '<br />'.$MOD_FORM['ERROR'];
|
573
|
echo '<p> </p>'.PHP_EOL.'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'.PHP_EOL;
|
574
|
}
|
575
|
}
|
576
|
|
577
|
}
|