1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category module
|
5
|
* @package Form
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2009-2012, WebsiteBaker 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 1868 2013-02-19 21:07:19Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/form/view.php $
|
14
|
* @lastmodified $Date: 2013-02-19 22:07:19 +0100 (Tue, 19 Feb 2013) $
|
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('<h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2>');
|
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
|
$aSuccess =array();
|
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)).'">';
|
66
|
} elseif ($n == ']') {
|
67
|
$n = '</optgroup>'."\n";
|
68
|
} else {
|
69
|
if(in_array($n, $values)) {
|
70
|
$n = '<option selected="selected" value="'.$n.'">'.$n.'</option>'."\n";
|
71
|
} else {
|
72
|
$n = '<option value="'.$n.'">'.$n.'</option>'."\n";
|
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.'" />'.PHP_EOL.'<label for="'.$label_id.'" class="frm-checkbox_label">'.$key.'</lable>'.$seperator;
|
86
|
} else {
|
87
|
$key = '<input class="frm-field_checkbox" type="checkbox" id="'.$label_id.'" name="field'.$field_id.'['.$idx.']" value="'.$key.'" />'.PHP_EOL.'<label for="'.$label_id.'" class="frm-checkbox_label">'.$key.'</label>'.$seperator;
|
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" />'.PHP_EOL.'<label for="'.$label_id.'" class="frm-checkbox_label">'.$n.'</label>'.$seperator;
|
100
|
} else {
|
101
|
$n = '<input class="frm-field_checkbox" type="radio" id="'.$label_id.'" name="field'.$field_id.'" value="'.$n.'" />'.PHP_EOL.'<label for="'.$label_id.'" class="frm-checkbox_label">'.$n.'</label>'.$seperator;
|
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.$fetch_settings['section_id'] : '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) ) ? "id=\"".$form_name.$section_id."\"" : ""); ?> action="<?php echo htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'';?>" method="post">
|
165
|
<fieldset>
|
166
|
<input type="hidden" name="submission_id" value="<?php echo $_SESSION['form_submission_id']; ?>" />
|
167
|
<?php
|
168
|
$iFormRequestId = isset($_GET['fri']) ? intval($_GET['fri']) : 0;
|
169
|
if($iFormRequestId) {
|
170
|
echo '<input type="hidden" name="fri" value="'.$iFormRequestId.'" />'."\n";
|
171
|
}
|
172
|
?>
|
173
|
<?php // echo $admin->getFTAN(); ?>
|
174
|
<?php
|
175
|
if(ENABLED_ASP) { // first add some honeypot-fields
|
176
|
?>
|
177
|
<input type="hidden" name="submitted_when" value="<?php $t=time(); echo $t; $_SESSION['submitted_when']=$t; ?>" />
|
178
|
<p class="nixhier">
|
179
|
email address:
|
180
|
<label for="email">Leave this field email-address blank:</label>
|
181
|
<input id="email" name="email" size="56" value="" /><br />
|
182
|
Homepage:
|
183
|
<label for="homepage">Leave this field homepage blank:</label>
|
184
|
<input id="homepage" name="homepage" size="55" value="" /><br />
|
185
|
URL:
|
186
|
<label for="url">Leave this field url blank:</label>
|
187
|
<input id="url" name="url" size="61" value="" /><br />
|
188
|
Comment:
|
189
|
<label for="comment">Leave this field comment blank:</label>
|
190
|
<textarea id="comment" name="comment" cols="50" rows="10"></textarea><br />
|
191
|
</p>
|
192
|
<?php }
|
193
|
|
194
|
// Print header MYSQL_ASSOC
|
195
|
echo $header."\n";
|
196
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
197
|
// Set field values
|
198
|
$field_id = $field['field_id'];
|
199
|
$value = $field['value'];
|
200
|
// Print field_loop after replacing vars with values
|
201
|
$vars = array('{TITLE}', '{REQUIRED}');
|
202
|
if (($field['type'] == "radio") || ($field['type'] == "checkbox")) {
|
203
|
$field_title = $field['title'];
|
204
|
} elseif($field['type'] == 'heading') {
|
205
|
$field_title = PHP_EOL.'<label>'.$field['title'].'</label>'.PHP_EOL;
|
206
|
}else {
|
207
|
$field_title = PHP_EOL.'<label for="field'.$field_id.'">'.$field['title'].'</label>'.PHP_EOL;
|
208
|
}
|
209
|
$values = array($field_title);
|
210
|
if ($field['required'] == 1) {
|
211
|
$values[] = '<span class="frm-required">*</span>';
|
212
|
} else {
|
213
|
$values[] = '';
|
214
|
}
|
215
|
if($field['type'] == 'textfield') {
|
216
|
$vars[] = '{FIELD}';
|
217
|
$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
|
218
|
$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" />';
|
219
|
} elseif($field['type'] == 'textarea') {
|
220
|
$vars[] = '{FIELD}';
|
221
|
$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>';
|
222
|
} elseif($field['type'] == 'select') {
|
223
|
$vars[] = '{FIELD}';
|
224
|
$options = explode(',', $value);
|
225
|
array_walk($options, 'make_option', (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array()));
|
226
|
$field['extra'] = explode(',',$field['extra']);
|
227
|
$field['extra'][1] = ($field['extra'][1]=='multiple') ? $field['extra'][1].'="'.$field['extra'][1].'"' : '';
|
228
|
$values[] = '<select name="field'.$field_id.'[]" id="field'.$field_id.'" size="'.$field['extra'][0].'" '.$field['extra'][1].' class="frm-select">'.implode($options).'</select>'."\n";
|
229
|
} elseif($field['type'] == 'heading') {
|
230
|
$vars[] = '{FIELD}';
|
231
|
$str = '<input type="hidden" name="field'.$field_id.'" id="field'.$field_id.'" value="===['.$field['title'].']===" />';
|
232
|
$values[] = ( true == $use_xhtml_strict) ? "<div>".$str."</div>" : $str;
|
233
|
$tmp_field_loop = $field_loop; // temporarily modify the field loop template
|
234
|
$field_loop = $field['extra'];
|
235
|
} elseif($field['type'] == 'checkbox') {
|
236
|
$vars[] = '{FIELD}';
|
237
|
$options = explode(',', $value);
|
238
|
array_walk($options, 'make_checkbox', array(array($field_id,$field['extra']),(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array())));
|
239
|
$x = sizeof($options)-1;
|
240
|
$options[$x]=substr($options[$x],0,strlen($options[$x]));
|
241
|
$values[] = implode($options);
|
242
|
} elseif($field['type'] == 'radio') {
|
243
|
$vars[] = '{FIELD}';
|
244
|
$options = explode(',', $value);
|
245
|
array_walk($options, 'make_radio', array($field_id,$field['title'],$field['extra'], (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:'')));
|
246
|
$x = sizeof($options)-1;
|
247
|
$options[$x]=substr($options[$x],0,strlen($options[$x]));
|
248
|
$values[] = implode($options);
|
249
|
} elseif($field['type'] == 'email') {
|
250
|
$vars[] = '{FIELD}';
|
251
|
$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
|
252
|
$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" />';
|
253
|
}
|
254
|
if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
|
255
|
if($field['type'] != '') {
|
256
|
echo str_replace($vars, $values, $field_loop);
|
257
|
}
|
258
|
if (isset($tmp_field_loop)){ $field_loop = $tmp_field_loop; }
|
259
|
}
|
260
|
// Captcha
|
261
|
if($use_captcha) { ?>
|
262
|
<tr>
|
263
|
<td class="frm-field_title"><?php echo $TEXT['VERIFICATION']; ?>:</td>
|
264
|
<td><?php call_captcha(); ?></td>
|
265
|
</tr>
|
266
|
<?php
|
267
|
}
|
268
|
// Print footer
|
269
|
// $out = $footer.PHP_EOL;
|
270
|
$out .= str_replace('{SUBMIT_FORM}', $MOD_FORM['SUBMIT_FORM'], $footer);
|
271
|
echo $out;
|
272
|
// Add form end code
|
273
|
?>
|
274
|
</fieldset>
|
275
|
</form>
|
276
|
<?php
|
277
|
}
|
278
|
}
|
279
|
|
280
|
} else {
|
281
|
|
282
|
// Check that submission ID matches
|
283
|
if(isset($_SESSION['form_submission_id']) AND isset($_POST['submission_id']) AND $_SESSION['form_submission_id'] == $_POST['submission_id']) {
|
284
|
|
285
|
$mail_replyto = '';
|
286
|
$mail_replyName = '';
|
287
|
if( $wb->is_authenticated() && $wb->get_email() ) {
|
288
|
$mail_replyto = $wb->get_email();
|
289
|
$mail_replyName = htmlspecialchars($wb->add_slashes($wb->get_display_name()));
|
290
|
}
|
291
|
|
292
|
// Set new submission ID in session
|
293
|
$_SESSION['form_submission_id'] = new_submission_id();
|
294
|
|
295
|
if(ENABLED_ASP && ( // form faked? Check the honeypot-fields.
|
296
|
(!isset($_POST['submitted_when']) OR !isset($_SESSION['submitted_when'])) OR
|
297
|
($_POST['submitted_when'] != $_SESSION['submitted_when']) OR
|
298
|
(!isset($_POST['email']) OR $_POST['email']) OR
|
299
|
(!isset($_POST['homepage']) OR $_POST['homepage']) OR
|
300
|
(!isset($_POST['comment']) OR $_POST['comment']) OR
|
301
|
(!isset($_POST['url']) OR $_POST['url'])
|
302
|
)) {
|
303
|
// spam
|
304
|
header("Location: ".WB_URL."");
|
305
|
exit();
|
306
|
}
|
307
|
// Submit form data
|
308
|
// First start message settings
|
309
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_settings` ';
|
310
|
$sql .= 'WHERE `section_id` = '.(int)$section_id.'';
|
311
|
if($query_settings = $database->query($sql) )
|
312
|
{
|
313
|
if($query_settings->numRows() > 0)
|
314
|
{
|
315
|
$fetch_settings = $query_settings->fetchRow(MYSQL_ASSOC);
|
316
|
|
317
|
// $email_to = $fetch_settings['email_to'];
|
318
|
$email_to = (($fetch_settings['email_to'] != '') ? $fetch_settings['email_to'] : emailAdmin());
|
319
|
$email_from = $wb->add_slashes(SERVER_EMAIL);
|
320
|
/*
|
321
|
if(substr($email_from, 0, 5) == 'field') {
|
322
|
// Set the email from field to what the user entered in the specified field
|
323
|
$email_from = htmlspecialchars($wb->add_slashes($_POST[$email_from]));
|
324
|
}
|
325
|
*/
|
326
|
$email_fromname = $fetch_settings['email_fromname'];
|
327
|
$email_fromname = (($mail_replyName='') ? $fetch_settings['email_fromname'] : $mail_replyName);
|
328
|
// $email_fromname = (($mail_replyName='') ? htmlspecialchars($wb->add_slashes($fetch_settings['email_fromname'])) : $mail_replyName);
|
329
|
|
330
|
if(substr($email_fromname, 0, 5) == 'field') {
|
331
|
// Set the email_fromname to field to what the user entered in the specified field
|
332
|
$email_fromname = htmlspecialchars($wb->add_slashes($_POST[$email_fromname]));
|
333
|
}
|
334
|
|
335
|
$email_subject = (($fetch_settings['email_subject'] != '') ? $fetch_settings['email_subject'] : $MOD_FORM['EMAIL_SUBJECT']);
|
336
|
$success_page = $fetch_settings['success_page'];
|
337
|
$success_email_to = $mail_replyto;
|
338
|
$success_email_from = $wb->add_slashes(SERVER_EMAIL);
|
339
|
$success_email_fromname = $fetch_settings['success_email_fromname'];
|
340
|
/*
|
341
|
*/
|
342
|
if($mail_replyto == '') {
|
343
|
$success_email_to = (($fetch_settings['success_email_to'] != '') ? $fetch_settings['success_email_to'] : '');
|
344
|
if(substr($success_email_to, 0, 5) == 'field') {
|
345
|
// Set the success_email to field to what the user entered in the specified field
|
346
|
$mail_replyto = $success_email_to = htmlspecialchars($wb->add_slashes($_POST[$success_email_to]));
|
347
|
}
|
348
|
$success_email_to = '';
|
349
|
$email_fromname = $TEXT['GUEST'];
|
350
|
// $success_email_fromname = $TEXT['UNKNOWN'];
|
351
|
// $email_from = $TEXT['UNKNOWN'];
|
352
|
}
|
353
|
|
354
|
$success_email_text = htmlspecialchars($wb->add_slashes($fetch_settings['success_email_text']));
|
355
|
$success_email_text = (($success_email_text != '') ? $success_email_text : $MOD_FORM['SUCCESS_EMAIL_TEXT']);
|
356
|
$success_email_subject = (($fetch_settings['success_email_subject'] != '') ? $fetch_settings['success_email_subject'] : $MOD_FORM['SUCCESS_EMAIL_SUBJECT']);
|
357
|
$max_submissions = $fetch_settings['max_submissions'];
|
358
|
$stored_submissions = $fetch_settings['stored_submissions'];
|
359
|
$use_captcha = $fetch_settings['use_captcha'];
|
360
|
} else {
|
361
|
exit($TEXT['UNDER_CONSTRUCTION']);
|
362
|
}
|
363
|
}
|
364
|
|
365
|
$email_body = '';
|
366
|
// Create blank "required" array
|
367
|
$required = array();
|
368
|
|
369
|
// Captcha
|
370
|
if($use_captcha) {
|
371
|
if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
|
372
|
// Check for a mismatch get email user_id
|
373
|
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
|
374
|
$replace = array('webmaster_email' => emailAdmin() );
|
375
|
$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'], $replace);
|
376
|
$required[]= '';
|
377
|
}
|
378
|
} else {
|
379
|
$replace = array('webmaster_email'=>emailAdmin() );
|
380
|
$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'],$replace );
|
381
|
$required[]= '';
|
382
|
}
|
383
|
}
|
384
|
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
|
385
|
|
386
|
/* for StripCodeFromText test only
|
387
|
[[loginbox]]
|
388
|
|
389
|
<script type="text/javascript">
|
390
|
var WB_URL = '{WB_URL}';
|
391
|
var THEME_URL = '{THEME_URL}';
|
392
|
var ADMIN_URL = '{ADMIN_URL}';
|
393
|
var LANGUAGE = '{LANGUAGE}';
|
394
|
</script>
|
395
|
|
396
|
Hier testen wir Module und stellen Tutorials zur Verfügung
|
397
|
|
398
|
<?php
|
399
|
function confirm_link(message, url) {
|
400
|
if(confirm(message)) location.href = url;
|
401
|
}
|
402
|
?>
|
403
|
*/
|
404
|
//
|
405
|
|
406
|
// Loop through fields and add to message body
|
407
|
// Get list of fields
|
408
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_fields` ';
|
409
|
$sql .= 'WHERE `section_id` = '.(int)$section_id.' ';
|
410
|
$sql .= 'ORDER BY position ASC';
|
411
|
if($query_fields = $database->query($sql)) {
|
412
|
if($query_fields->numRows() > 0) {
|
413
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
414
|
// Add to message body
|
415
|
if($field['type'] != '') {
|
416
|
if(!empty($_POST['field'.$field['field_id']]))
|
417
|
{
|
418
|
$sPostVar = '';
|
419
|
$aPostVar['field'.$field['field_id']] = array();
|
420
|
// do not allow code in user input!
|
421
|
if (is_array($_POST['field'.$field['field_id']])) {
|
422
|
|
423
|
foreach ($_POST['field'.$field['field_id']] as $key=>$val) {
|
424
|
$aPostVar['field'.$field['field_id']][$key] = $wb->strip_slashes($wb->StripCodeFromText($val),true);
|
425
|
}
|
426
|
$_SESSION['field'.$field['field_id']] = $aPostVar['field'.$field['field_id']];
|
427
|
} else {
|
428
|
$sPostVar = $wb->strip_slashes($wb->StripCodeFromText($wb->get_post('field'.$field['field_id']),true));
|
429
|
$_SESSION['field'.$field['field_id']] = $sPostVar;
|
430
|
}
|
431
|
|
432
|
if($field['type'] == 'email' AND $wb->validate_email($sPostVar) == false) {
|
433
|
$email_error = $MESSAGE['USERS_INVALID_EMAIL'];
|
434
|
$required[]= '';
|
435
|
}
|
436
|
if($field['type'] == 'heading') {
|
437
|
$email_body .= $sPostVar."\n\n";
|
438
|
|
439
|
} elseif (($sPostVar!='')) {
|
440
|
$email_body .= $field['title'].": ".$sPostVar."\n\n";
|
441
|
} elseif(sizeof($aPostVar['field'.$field['field_id']] > 0) ) {
|
442
|
$email_body .= $field['title'].": ";
|
443
|
foreach ($aPostVar['field'.$field['field_id']] as $key=>$val) {
|
444
|
$email_body .= $val."\n";
|
445
|
}
|
446
|
$email_body .= "\n";
|
447
|
}
|
448
|
|
449
|
} elseif($field['required'] == 1) {
|
450
|
$required[] = $field['title'];
|
451
|
}
|
452
|
}
|
453
|
} // while
|
454
|
} // numRows
|
455
|
} // query
|
456
|
|
457
|
// Check if the user forgot to enter values into all the required fields
|
458
|
if(sizeof($required )) {
|
459
|
|
460
|
if(!isset($MESSAGE['MOD_FORM_REQUIRED_FIELDS'])) {
|
461
|
echo '<h3>You must enter details for the following fields</h3>';
|
462
|
} else {
|
463
|
echo '<h3>'.$MESSAGE['MOD_FORM_REQUIRED_FIELDS'].'</h3>';
|
464
|
}
|
465
|
echo "<ol class=\"warning\">\n";
|
466
|
foreach($required AS $field_title) {
|
467
|
if($field_title!=''){
|
468
|
echo '<li>'.$field_title."</li>\n";
|
469
|
}
|
470
|
}
|
471
|
|
472
|
if(isset($email_error)) {
|
473
|
echo '<li>'.$email_error."</li>\n";
|
474
|
}
|
475
|
|
476
|
if(isset($captcha_error)) {
|
477
|
echo '<li>'.$captcha_error."</li>\n";
|
478
|
}
|
479
|
// Create blank "required" array
|
480
|
$required = array();
|
481
|
echo "</ol>\n";
|
482
|
|
483
|
echo '<p> </p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
|
484
|
} else {
|
485
|
if(isset($email_error)) {
|
486
|
echo '<br /><ol class=\"warning\">'."\n";
|
487
|
echo '<li>'.$email_error.'</li>'."\n";
|
488
|
echo '</ol>'."\n";
|
489
|
echo '<a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a>';
|
490
|
} elseif(isset($captcha_error)) {
|
491
|
echo '<br /><ol class=\"warning\">'."\n";
|
492
|
echo '<li>'.$captcha_error.'</li>'."\n";
|
493
|
echo '</ol>'."\n";
|
494
|
echo '<p> </p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
|
495
|
} else {
|
496
|
// Check how many times form has been submitted in last hour
|
497
|
$last_hour = time()-3600;
|
498
|
$sql = 'SELECT `submission_id` FROM `'.TABLE_PREFIX.'mod_form_submissions` ';
|
499
|
$sql .= 'WHERE `submitted_when` >= '.$last_hour.'';
|
500
|
$sql .= '';
|
501
|
if($query_submissions = $database->query($sql))
|
502
|
{
|
503
|
if($query_submissions->numRows() > $max_submissions)
|
504
|
{
|
505
|
// Too many submissions so far this hour
|
506
|
echo $MESSAGE['MOD_FORM_EXCESS_SUBMISSIONS'];
|
507
|
$success = false;
|
508
|
} else {
|
509
|
// Adding the IP to the body and try to send the email
|
510
|
// $email_body .= "\n\nIP: ".$_SERVER['REMOTE_ADDR'];
|
511
|
$iFormRequestId = isset($_POST['fri']) ? intval($_POST['fri']) : 0;
|
512
|
if($iFormRequestId) {
|
513
|
$email_body .= "\n\nFormRequestID: ".$iFormRequestId;
|
514
|
}
|
515
|
$recipient = preg_replace( "/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $email_fromname );
|
516
|
$email_fromname = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient );
|
517
|
$email_body = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $email_body );
|
518
|
|
519
|
if($mail_replyto != '') {
|
520
|
|
521
|
if($email_from != '') {
|
522
|
$success = $wb->mail(SERVER_EMAIL,$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
|
523
|
} else {
|
524
|
$success = $wb->mail('',$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
|
525
|
}
|
526
|
}
|
527
|
|
528
|
if($success==true)
|
529
|
{
|
530
|
$recipient = preg_replace( "/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $success_email_fromname );
|
531
|
$success_email_fromname = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient );
|
532
|
$success_email_text = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $success_email_text );
|
533
|
if($success_email_to != '')
|
534
|
{
|
535
|
if($success_email_from != '')
|
536
|
{
|
537
|
$success = $wb->mail(SERVER_EMAIL,$success_email_to,$success_email_subject,($success_email_text).'<br /><br />'.($email_body).$MOD_FORM['SUCCESS_EMAIL_TEXT_GENERATED'],$success_email_fromname);
|
538
|
} else {
|
539
|
$success = $wb->mail('',$success_email_to,$success_email_subject,($success_email_text).'<br /><br />'.($email_body).$MOD_FORM['SUCCESS_EMAIL_TEXT_GENERATED'],$success_email_fromname);
|
540
|
}
|
541
|
}
|
542
|
}
|
543
|
|
544
|
if($success==true)
|
545
|
{
|
546
|
$aSuccess[] .= 'INSERT INTO '.TABLE_PREFIX.'mod_form_submissions<br /> ';;
|
547
|
// Write submission to database
|
548
|
if(isset($wb) AND $wb->is_authenticated() AND $wb->get_user_id() > 0) {
|
549
|
$submitted_by = $wb->get_user_id();
|
550
|
} else {
|
551
|
$submitted_by = 0;
|
552
|
}
|
553
|
$email_body = htmlspecialchars($wb->add_slashes($email_body));
|
554
|
$sql = 'INSERT INTO '.TABLE_PREFIX.'mod_form_submissions ';
|
555
|
$sql .= 'SET ';
|
556
|
$sql .= 'page_id='.$wb->page_id.',';
|
557
|
$sql .= 'section_id='.$section_id.',';
|
558
|
$sql .= 'submitted_when='.time().',';
|
559
|
$sql .= 'submitted_by=\''.$submitted_by.'\', ';
|
560
|
$sql .= 'body=\''.$email_body.'\' ';
|
561
|
if($database->query($sql))
|
562
|
{
|
563
|
// Get the page id
|
564
|
$iSubmissionId = intval($database->get_one("SELECT LAST_INSERT_ID()"));
|
565
|
|
566
|
if(!$database->is_error()) {
|
567
|
$success = true;
|
568
|
}
|
569
|
// Make sure submissions table isn't too full
|
570
|
$query_submissions = $database->query("SELECT submission_id FROM ".TABLE_PREFIX."mod_form_submissions ORDER BY submitted_when");
|
571
|
$num_submissions = $query_submissions->numRows();
|
572
|
if($num_submissions > $stored_submissions)
|
573
|
{
|
574
|
// Remove excess submission
|
575
|
$num_to_remove = $num_submissions-$stored_submissions;
|
576
|
while($submission = $query_submissions->fetchRow(MYSQL_ASSOC))
|
577
|
{
|
578
|
if($num_to_remove > 0)
|
579
|
{
|
580
|
$submission_id = $submission['submission_id'];
|
581
|
$database->query("DELETE FROM ".TABLE_PREFIX."mod_form_submissions WHERE submission_id = '$submission_id'");
|
582
|
$num_to_remove = $num_to_remove-1;
|
583
|
}
|
584
|
}
|
585
|
} // $num_submissions
|
586
|
} // numRows
|
587
|
} // $success
|
588
|
}
|
589
|
} // end how many times form has been submitted in last hour
|
590
|
}
|
591
|
} // email_error
|
592
|
} else {
|
593
|
|
594
|
echo '<p> </p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
|
595
|
}
|
596
|
|
597
|
$success_page = ( (isset($success_page) ) ? $success_page : $page_id);
|
598
|
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` ';
|
599
|
$sql .= 'WHERE `page_id` = '.(int)$success_page;
|
600
|
$sSuccessLink = WB_URL; // if failed set default
|
601
|
if( ($link = $database->get_one($sql)) ) {
|
602
|
$sSuccessLink = WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
|
603
|
}
|
604
|
// Now check if the email was sent successfully
|
605
|
if(isset($success) && $success == true)
|
606
|
{
|
607
|
if ($success_page=='none') {
|
608
|
|
609
|
// Get submission details
|
610
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_submissions` ';
|
611
|
$sql .= 'WHERE submission_id = '.$iSubmissionId.' ';
|
612
|
if($query_content = $database->query($sql)) {
|
613
|
$submission = $query_content->fetchRow(MYSQL_ASSOC);
|
614
|
}
|
615
|
$Message = '';
|
616
|
$NixHier = 'nixhier';
|
617
|
// Get the user details of whoever did this submission
|
618
|
$sql = 'SELECT `username`,`display_name` FROM `'.TABLE_PREFIX.'users` ';
|
619
|
$sql .= 'WHERE `user_id` = '.$submission['submitted_by'];
|
620
|
if($get_user = $database->query($sql))
|
621
|
{
|
622
|
if($get_user->numRows() != 0) {
|
623
|
$user = $get_user->fetchRow(MYSQL_ASSOC);
|
624
|
} else {
|
625
|
$Message = $MOD_FORM['PRINT'];
|
626
|
$NixHier = '';
|
627
|
$user['display_name'] = $TEXT['GUEST'];
|
628
|
$user['username'] = $TEXT['UNKNOWN'];
|
629
|
}
|
630
|
}
|
631
|
|
632
|
$aSubSuccess = array();
|
633
|
// set template file and assign module and template block
|
634
|
$oTpl = new Template(WB_PATH.'/modules/form/htt','keep');
|
635
|
// $tpl = new Template(dirname($admin->correct_theme_source('switchform.htt')),'keep');
|
636
|
$oTpl->set_file('page', 'submessage.htt');
|
637
|
$oTpl->debug = false; // false, true
|
638
|
$oTpl->set_block('page', 'main_block', 'main');
|
639
|
$oTpl->set_var(array(
|
640
|
'ADMIN_URL' => ADMIN_URL,
|
641
|
'THEME_URL' => THEME_URL,
|
642
|
'MODULE_URL' => WB_URL.'/modules/form',
|
643
|
'WB_URL' => WB_URL
|
644
|
)
|
645
|
);
|
646
|
$oTpl->set_var(array(
|
647
|
'SUCCESS_EMAIL_TEXT' => $success_email_text,
|
648
|
'TEXT_SUBMISSION_ID' => $TEXT['SUBMISSION_ID'],
|
649
|
'submission_submission_id' => $submission['submission_id'],
|
650
|
'TEXT_SUBMITTED' => $TEXT['SUBMITTED'],
|
651
|
'submission_submitted_when' => gmdate( DATE_FORMAT .', '.TIME_FORMAT, $submission['submitted_when']+TIMEZONE ),
|
652
|
'NIX_HIER' => $NixHier,
|
653
|
'TEXT_USER' => $TEXT['USER'],
|
654
|
'TEXT_USERNAME' => $TEXT['USERNAME'],
|
655
|
'TEXT_PRINT_PAGE' => $TEXT['PRINT_PAGE'],
|
656
|
'TEXT_REQUIRED_JS' => $TEXT['REQUIRED_JS'],
|
657
|
'user_display_name' => $user['display_name'],
|
658
|
'user_username' => $user['username'],
|
659
|
'SUCCESS_PRINT' => $Message,
|
660
|
'submission_body' => nl2br($submission['body'])
|
661
|
)
|
662
|
);
|
663
|
|
664
|
$oTpl->parse('main', 'main_block', false);
|
665
|
$output = $oTpl->finish($oTpl->parse('output', 'page'));
|
666
|
unset($oTpl);
|
667
|
print $output;
|
668
|
|
669
|
} else {
|
670
|
echo "<script type='text/javascript'>location.href='".$sSuccessLink."';</script>";
|
671
|
}
|
672
|
// clearing session on success
|
673
|
$query_fields = $database->query("SELECT field_id FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id'");
|
674
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
675
|
$field_id = $field['field_id'];
|
676
|
if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
|
677
|
}
|
678
|
} else {
|
679
|
if(isset($success) && $success == false) {
|
680
|
echo '<br />'.$MOD_FORM['ERROR'];
|
681
|
echo '<p> </p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
|
682
|
}
|
683
|
}
|
684
|
|
685
|
}
|