Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        module
5
 * @package         Form
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.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 1919 2013-06-07 04:21:49Z Luisehahne $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/form/view.php $
14
 * @lastmodified    $Date: 2013-06-07 06:21:49 +0200 (Fri, 07 Jun 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

    
155
	// Get list of fields
156
	$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_fields` ';
157
	$sql .= 'WHERE section_id = '.$section_id.' ';
158
	$sql .= 'ORDER BY position ASC ';
159

    
160
	if($query_fields = $database->query($sql)) {
161
		if($query_fields->numRows() > 0) {
162
?>
163
			<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">
164
            <fieldset class="frm-fieldset">
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="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
				} elseif($field['type'] == 'heading') {
204
					$field_title = PHP_EOL.'<label>'.$field['title'].'</label>'.PHP_EOL;
205
				}else {
206
					$field_title = PHP_EOL.'<label for="field'.$field_id.'">'.$field['title'].'</label>'.PHP_EOL;
207
				}
208
				$values = array($field_title);
209
				if ($field['required'] == 1) {
210
					$values[] = '<span class="frm-required">*</span>';
211
				} else {
212
					$values[] = '';
213
				}
214
				if($field['type'] == 'textfield') {
215
					$vars[] = '{FIELD}';
216
					$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
217
					$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" />';
218
				} elseif($field['type'] == 'textarea') {
219
					$vars[] = '{FIELD}';
220
					$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>';
221
				} elseif($field['type'] == 'select') {
222
					$vars[] = '{FIELD}';
223
					$options = explode(',', $value);
224
					array_walk($options, 'make_option', (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array()));
225
					$field['extra'] = explode(',',$field['extra']);
226
					$field['extra'][1] = ($field['extra'][1]=='multiple') ? $field['extra'][1].'="'.$field['extra'][1].'"' : '';
227
					$values[] = '<select name="field'.$field_id.'[]" id="field'.$field_id.'" size="'.$field['extra'][0].'" '.$field['extra'][1].' class="frm-select">'.implode($options).'</select>'."\n";
228
				} elseif($field['type'] == 'heading') {
229
					$vars[] = '{FIELD}';
230
					$str = '<input type="hidden" name="field'.$field_id.'" id="field'.$field_id.'" value="===['.$field['title'].']===" />';
231
					$values[] = ( true == $use_xhtml_strict) ? "<div>".$str."</div>" : $str;
232
					$tmp_field_loop = $field_loop;		// temporarily modify the field loop template
233
					$field_loop = $field['extra'];
234
				} elseif($field['type'] == 'checkbox') {
235
					$vars[] = '{FIELD}';
236
					$options = explode(',', $value);
237
					array_walk($options, 'make_checkbox', array(array($field_id,$field['extra']),(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array())));
238
                    $x = sizeof($options)-1;
239
					$options[$x]=substr($options[$x],0,strlen($options[$x]));
240
					$values[] = implode($options);
241
				} elseif($field['type'] == 'radio') {
242
					$vars[] = '{FIELD}';
243
					$options = explode(',', $value);
244
					array_walk($options, 'make_radio', array($field_id,$field['title'],$field['extra'], (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:'')));
245
                    $x = sizeof($options)-1;
246
					$options[$x]=substr($options[$x],0,strlen($options[$x]));
247
					$values[] = implode($options);
248
				} elseif($field['type'] == 'email') {
249
					$vars[] = '{FIELD}';
250
					$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
251
					$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" />';
252
				}
253
				if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
254
				if($field['type'] != '') {
255
					echo str_replace($vars, $values, $field_loop);
256
				}
257
				if (isset($tmp_field_loop)){ $field_loop = $tmp_field_loop; }
258
			}
259
			// Captcha
260
			if($use_captcha) { ?>
261
				<tr>
262
				<td class="frm-field_title"><?php echo $TEXT['VERIFICATION']; ?>:</td>
263
				<td><?php call_captcha(); ?></td>
264
				</tr>
265
				<?php
266
			}
267
		// Print footer
268
		// $out = $footer.PHP_EOL;
269
		$out .= str_replace('{SUBMIT_FORM}', $MOD_FORM['SUBMIT_FORM'], $footer);
270
		echo $out;
271
// Add form end code
272
?>
273
        </fieldset>
274
</form>
275
<?php
276
		}
277
	}
278

    
279
} else {
280

    
281
	// Check that submission ID matches
282
	if(isset($_SESSION['form_submission_id']) AND isset($_POST['submission_id']) AND $_SESSION['form_submission_id'] == $_POST['submission_id']) {
283

    
284
	   $mail_replyto = '';
285
	   $mail_replyName = '';
286
		if( $wb->is_authenticated() && $wb->get_email() ) {
287
		   $mail_replyto = $wb->get_email();
288
		   $mail_replyName = htmlspecialchars($wb->add_slashes($wb->get_display_name()));
289
		}
290

    
291
		// Set new submission ID in session
292
		$_SESSION['form_submission_id'] = new_submission_id();
293

    
294
		if(ENABLED_ASP && ( // form faked? Check the honeypot-fields.
295
			(!isset($_POST['submitted_when']) OR !isset($_SESSION['submitted_when'])) OR
296
			($_POST['submitted_when'] != $_SESSION['submitted_when']) OR
297
			(!isset($_POST['email']) OR $_POST['email']) OR
298
			(!isset($_POST['homepage']) OR $_POST['homepage']) OR
299
			(!isset($_POST['comment']) OR $_POST['comment']) OR
300
			(!isset($_POST['url']) OR $_POST['url'])
301
		)) {
302
			// spam
303
			header("Location: ".WB_URL."");
304
            exit();
305
		}
306
		// Submit form data
307
		// First start message settings
308
		$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_settings` ';
309
		$sql .= 'WHERE `section_id` = '.(int)$section_id.'';
310
		if($query_settings = $database->query($sql) )
311
		{
312
			if($query_settings->numRows() > 0)
313
			{
314
				$fetch_settings = $query_settings->fetchRow(MYSQL_ASSOC);
315

    
316
				// $email_to = $fetch_settings['email_to'];
317
				$email_to = (($fetch_settings['email_to'] != '') ? $fetch_settings['email_to'] : emailAdmin());
318
				$email_from = $wb->add_slashes(SERVER_EMAIL);
319
/*
320
				if(substr($email_from, 0, 5) == 'field') {
321
					// Set the email from field to what the user entered in the specified field
322
					$email_from = htmlspecialchars($wb->add_slashes($_POST[$email_from]));
323
				}
324
*/
325
				$email_fromname = $fetch_settings['email_fromname'];
326
 				$email_fromname = (($mail_replyName='') ? $fetch_settings['email_fromname'] : $mail_replyName);
327
// 				$email_fromname = (($mail_replyName='') ? htmlspecialchars($wb->add_slashes($fetch_settings['email_fromname'])) : $mail_replyName);
328

    
329
				if(substr($email_fromname, 0, 5) == 'field') {
330
					// Set the email_fromname to field to what the user entered in the specified field
331
					$email_fromname = htmlspecialchars($wb->add_slashes($_POST[$email_fromname]));
332
				}
333

    
334
				$email_subject = (($fetch_settings['email_subject'] != '') ? $fetch_settings['email_subject'] : $MOD_FORM['EMAIL_SUBJECT']);
335
				$success_page = $fetch_settings['success_page'];
336
				$success_email_to = $mail_replyto;
337
				$success_email_from = $wb->add_slashes(SERVER_EMAIL);
338
				$success_email_fromname = $fetch_settings['success_email_fromname'];
339
/*
340
*/
341
				if($mail_replyto == '') {
342
					$success_email_to = (($fetch_settings['success_email_to'] != '') ? $fetch_settings['success_email_to'] : '');
343
					if(substr($success_email_to, 0, 5) == 'field') {
344
						// Set the success_email to field to what the user entered in the specified field
345
						 $mail_replyto = $success_email_to = htmlspecialchars($wb->add_slashes($_POST[$success_email_to]));
346
					}
347
					$success_email_to = '';
348
					$email_fromname = $TEXT['GUEST'];
349
//					$success_email_fromname = $TEXT['UNKNOWN'];
350
//					$email_from = $TEXT['UNKNOWN'];
351
				}
352

    
353
				$success_email_text = htmlspecialchars($wb->add_slashes($fetch_settings['success_email_text']));
354
				$success_email_text = (($success_email_text != '') ? $success_email_text : $MOD_FORM['SUCCESS_EMAIL_TEXT']);
355
				$success_email_subject = (($fetch_settings['success_email_subject'] != '') ? $fetch_settings['success_email_subject'] : $MOD_FORM['SUCCESS_EMAIL_SUBJECT']);
356
				$max_submissions = $fetch_settings['max_submissions'];
357
				$stored_submissions = $fetch_settings['stored_submissions'];
358
				$use_captcha = $fetch_settings['use_captcha'];
359
			} else {
360
				exit($TEXT['UNDER_CONSTRUCTION']);
361
			}
362
		}
363

    
364
		$email_body = '';
365
		// Create blank "required" array
366
		$required = array();
367

    
368
		// Captcha
369
		if($use_captcha) {
370
			if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
371
				// Check for a mismatch get email user_id
372
				if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
373
					$replace = array('webmaster_email' => emailAdmin() );
374
					$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'], $replace);
375
					$required[]= '';
376
				}
377
			} else {
378
				$replace = array('webmaster_email'=>emailAdmin() );
379
				$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'],$replace );
380
				$required[]= '';
381
			}
382
		}
383
		if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
384

    
385
/* for StripCodeFromText test only
386
[[loginbox]]
387

    
388
<script type="text/javascript">
389
var WB_URL = '{WB_URL}';
390
var THEME_URL = '{THEME_URL}';
391
var ADMIN_URL = '{ADMIN_URL}';
392
var LANGUAGE = '{LANGUAGE}';
393
</script>
394

    
395
Hier testen wir Module und stellen Tutorials zur Verfügung
396

    
397
<?php
398
function confirm_link(message, url) {
399
	if(confirm(message)) location.href = url;
400
}
401
?>
402
*/
403
//
404

    
405
		// Loop through fields and add to message body
406
		// Get list of fields
407
		$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_fields` ';
408
		$sql .= 'WHERE `section_id` = '.(int)$section_id.' ';
409
		$sql .= 'ORDER BY position ASC';
410
		if($query_fields = $database->query($sql)) {
411
			if($query_fields->numRows() > 0) {
412
				while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
413
					// Add to message body
414
					if($field['type'] != '') {
415
						if(!empty($_POST['field'.$field['field_id']]))
416
						{
417
                            $sPostVar = '';
418
                            $aPostVar['field'.$field['field_id']] = array();
419
                            // do not allow code in user input!
420
                            if (is_array($_POST['field'.$field['field_id']])) {
421

    
422
                                foreach ($_POST['field'.$field['field_id']] as $key=>$val) {
423
                                	$aPostVar['field'.$field['field_id']][$key] =  $wb->strip_slashes($wb->StripCodeFromText($val),true);
424
                                }
425
                                $_SESSION['field'.$field['field_id']] = $aPostVar['field'.$field['field_id']];
426
							} else {
427
                                $sPostVar = $wb->strip_slashes($wb->StripCodeFromText($wb->get_post('field'.$field['field_id']),true));
428
                                $_SESSION['field'.$field['field_id']] = $sPostVar;
429
							}
430

    
431
							if($field['type'] == 'email' AND $wb->validate_email($sPostVar) == false) {
432
								$email_error = $MESSAGE['USERS_INVALID_EMAIL'];
433
								$required[]= '';
434
							}
435
							if($field['type'] == 'heading') {
436
								$email_body .= $sPostVar."\n\n";
437

    
438
							} elseif (($sPostVar!='')) {
439
								$email_body .= $field['title'].": ".$sPostVar."\n\n";
440
							} elseif(sizeof($aPostVar['field'.$field['field_id']] > 0) ) {
441
								$email_body .= $field['title'].": ";
442
								foreach ($aPostVar['field'.$field['field_id']] as $key=>$val) {
443
									$email_body .= $val."\n";
444
								}
445
								$email_body .= "\n";
446
							}
447

    
448
						} elseif($field['required'] == 1) {
449
							$required[] = $field['title'];
450
						}
451
					}
452
				} //  while
453
			}  // numRows
454
		} //  query
455

    
456
// Check if the user forgot to enter values into all the required fields
457
		if(sizeof($required )) {
458
			echo "<div class=\"frm-warning\">\n";
459
			if(!isset($MESSAGE['MOD_FORM_REQUIRED_FIELDS'])) {
460
				echo '<h3>You must enter details for the following fields</h3>';
461
			} else {
462
				echo '<h3>'.$MESSAGE['MOD_FORM_REQUIRED_FIELDS'].'</h3>';
463
			}
464
			echo "<ol>\n";
465
			foreach($required AS $field_title) {
466
				if($field_title!=''){
467
					echo '<li>'.$field_title."</li>\n";
468
				}
469
			}
470
			if(isset($email_error)) {
471
				echo '<li>'.$email_error."</li>\n";
472
			}
473
			if(isset($captcha_error)) {
474
				echo '<li>'.$captcha_error."</li>\n";
475
			}
476
			// Create blank "required" array
477
			$required = array();
478
			echo "</ol>\n";
479
			echo "</div>\n";
480
			echo '<p class="frm-warning"><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
481
		} else {
482
			if(isset($email_error)) {
483
			echo "<div class=\"frm-warning\">\n";
484
				echo '<br /><ol>'."\n";
485
				echo '<li>'.$email_error.'</li>'."\n";
486
				echo '</ol>'."\n";
487
			echo "</div>\n";
488
				echo '<p class="frm-warning"><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
489
			} elseif(isset($captcha_error)) {
490
			echo "<div class=\"frm-warning\">\n";
491
				echo '<br /><ol>'."\n";
492
				echo '<li>'.$captcha_error.'</li>'."\n";
493
				echo '</ol>'."\n";
494
			echo "</div>\n";
495
				echo '<p class="frm-warning"><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
496
			} else {
497
				$success = false;
498
// Check how many times form has been submitted in last hour
499
				$last_hour = time()-3600;
500
				$sql  = 'SELECT `submission_id` FROM `'.TABLE_PREFIX.'mod_form_submissions` ';
501
				$sql .= 'WHERE `submitted_when` >= '.$last_hour.'';
502
				$sql .= '';
503
				if($query_submissions = $database->query($sql))
504
				{
505
					if($query_submissions->numRows() > $max_submissions)
506
					{
507
// Too many submissions so far this hour
508
						echo $MESSAGE['MOD_FORM_EXCESS_SUBMISSIONS'];
509
						$success = false;
510
					} else {
511
						// Adding the IP to the body and try to send the email
512
						// $email_body .= "\n\nIP: ".$_SERVER['REMOTE_ADDR'];
513
						$iFormRequestId = isset($_POST['fri']) ? intval($_POST['fri']) : 0;
514
						if($iFormRequestId) {
515
							$email_body .= "\n\nFormRequestID: ".$iFormRequestId;
516
						}
517
						$recipient = preg_replace( "/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $email_fromname );
518
						$email_fromname = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient );
519
						$email_body = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $email_body );
520

    
521
						if($mail_replyto != '') {
522

    
523
							if($email_from != '') {
524
								$success = $wb->mail(SERVER_EMAIL,$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
525
							} else {
526
								$success = $wb->mail('',$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
527
							}
528
						}
529

    
530
						if($success==true)
531
						{
532
							$recipient = preg_replace( "/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $success_email_fromname );
533
							$success_email_fromname = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient );
534
							$success_email_text = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $success_email_text );
535
							if($success_email_to != '')
536
							{
537
								if($success_email_from != '')
538
								{
539
									$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);
540
								} else {
541
									$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);
542
								}
543
							}
544
						}
545

    
546
						if($success==true)
547
						{
548
							$aSuccess[] .= 'INSERT INTO '.TABLE_PREFIX.'mod_form_submissions<br /> ';;
549
							// Write submission to database
550
							if(isset($wb) AND $wb->is_authenticated() AND $wb->get_user_id() > 0) {
551
								$submitted_by = $wb->get_user_id();
552
							} else {
553
								$submitted_by = 0;
554
							}
555
							$email_body = htmlspecialchars($wb->add_slashes($email_body));
556
							$sql  = 'INSERT INTO '.TABLE_PREFIX.'mod_form_submissions ';
557
							$sql .= 'SET ';
558
							$sql .= 'page_id='.$wb->page_id.',';
559
							$sql .= 'section_id='.$section_id.',';
560
							$sql .= 'submitted_when='.time().',';
561
							$sql .= 'submitted_by=\''.$submitted_by.'\', ';
562
							$sql .= 'body=\''.$email_body.'\' ';
563
							if($database->query($sql))
564
							{
565
								// Get the page id
566
								$iSubmissionId = intval($database->get_one("SELECT LAST_INSERT_ID()"));
567

    
568
								if(!$database->is_error()) {
569
									$success = true;
570
								}
571
								// Make sure submissions table isn't too full
572
								$query_submissions = $database->query("SELECT submission_id FROM ".TABLE_PREFIX."mod_form_submissions ORDER BY submitted_when");
573
								$num_submissions = $query_submissions->numRows();
574
								if($num_submissions > $stored_submissions)
575
								{
576
									// Remove excess submission
577
									$num_to_remove = $num_submissions-$stored_submissions;
578
									while($submission = $query_submissions->fetchRow(MYSQL_ASSOC))
579
									{
580
										if($num_to_remove > 0)
581
										{
582
											$submission_id = $submission['submission_id'];
583
											$database->query("DELETE FROM ".TABLE_PREFIX."mod_form_submissions WHERE submission_id = '$submission_id'");
584
											$num_to_remove = $num_to_remove-1;
585
										}
586
									}
587
								} // $num_submissions
588
							}  // numRows
589
						} // $success
590
		 			}
591
	 			} // end how many times form has been submitted in last hour
592
			}
593
		}  // email_error
594
	} else {
595

    
596
	echo '<p>&nbsp;</p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
597
	}
598

    
599
	$success_page = ( (isset($success_page) ) ? $success_page : $page_id);
600
	$sql  = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` ';
601
	$sql .= 'WHERE `page_id` = '.(int)$success_page;
602
	$sSuccessLink = WB_URL;  // if failed set default
603
	if( ($link = $database->get_one($sql)) ) {
604
	   $sSuccessLink = WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
605
	}
606
	// Now check if the email was sent successfully
607
	if(isset($success) && $success == true)
608
	{
609
	   if ($success_page=='none') {
610

    
611
			// Get submission details
612
			$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_submissions` ';
613
			$sql .= 'WHERE submission_id = '.$iSubmissionId.' ';
614
			if($query_content = $database->query($sql)) {
615
				$submission = $query_content->fetchRow(MYSQL_ASSOC);
616
			}
617
			$Message = '';
618
			$NixHier = 'nixhier';
619
			// Get the user details of whoever did this submission
620
			$sql  = 'SELECT `username`,`display_name` FROM `'.TABLE_PREFIX.'users` ';
621
			$sql .= 'WHERE `user_id` = '.$submission['submitted_by'];
622
			if($get_user = $database->query($sql))
623
			{
624
				if($get_user->numRows() != 0) {
625
					$user = $get_user->fetchRow(MYSQL_ASSOC);
626
				} else {
627
					$Message = $MOD_FORM['PRINT'];
628
					$NixHier = '';
629
					$user['display_name'] = $TEXT['GUEST'];
630
					$user['username'] = $TEXT['UNKNOWN'];
631
				}
632
			}
633

    
634
			$aSubSuccess = array();
635
			// set template file and assign module and template block
636
			$oTpl = new Template(WB_PATH.'/modules/form/htt','keep');
637
			// $tpl = new Template(dirname($admin->correct_theme_source('switchform.htt')),'keep');
638
			$oTpl->set_file('page', 'submessage.htt');
639
			$oTpl->debug = false; // false, true
640
			$oTpl->set_block('page', 'main_block', 'main');
641
            $oTpl->set_var(array(
642
            		'ADMIN_URL' => ADMIN_URL,
643
            		'THEME_URL' => THEME_URL,
644
            		'MODULE_URL' => WB_URL.'/modules/form',
645
            		'WB_URL' => WB_URL
646
            	)
647
            );
648
			$oTpl->set_var(array(
649
					'SUCCESS_EMAIL_TEXT' => $success_email_text,
650
					'TEXT_SUBMISSION_ID' => $TEXT['SUBMISSION_ID'],
651
					'submission_submission_id' => $submission['submission_id'],
652
					'TEXT_SUBMITTED' => $TEXT['SUBMITTED'],
653
					'submission_submitted_when' => gmdate( DATE_FORMAT .', '.TIME_FORMAT, $submission['submitted_when']+TIMEZONE ),
654
					'NIX_HIER' => $NixHier,
655
					'TEXT_USER' => $TEXT['USER'],
656
					'TEXT_USERNAME' => $TEXT['USERNAME'],
657
					'TEXT_PRINT_PAGE' => $TEXT['PRINT_PAGE'],
658
					'TEXT_REQUIRED_JS' => $TEXT['REQUIRED_JS'],
659
					'user_display_name' => $user['display_name'],
660
					'user_username' => $user['username'],
661
					'SUCCESS_PRINT' => $Message,
662
					'submission_body' => nl2br($submission['body'])
663
					)
664
				);
665

    
666
			$oTpl->parse('main', 'main_block', false);
667
			$output = $oTpl->finish($oTpl->parse('output', 'page'));
668
			unset($oTpl);
669
			print $output;
670

    
671
  		} else {
672
			echo "<script type='text/javascript'>location.href='".$sSuccessLink."';</script>";
673
		}
674
		// clearing session on success
675
		$query_fields = $database->query("SELECT field_id FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id'");
676
		while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
677
			$field_id = $field['field_id'];
678
			if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
679
		}
680
	} else {
681
		if(isset($success) && $success == false) {
682
			echo '<br />'.$MOD_FORM['ERROR'];
683
			echo '<p>&nbsp;</p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
684
		}
685
	}
686

    
687
}
(24-24/25)