Project

General

Profile

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

    
278
} else {
279

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
455
// Check if the user forgot to enter values into all the required fields
456
		if(sizeof($required )) {
457

    
458
			if(!isset($MESSAGE['MOD_FORM_REQUIRED_FIELDS'])) {
459
				echo '<h3>You must enter details for the following fields</h3>';
460
			} else {
461
				echo '<h3>'.$MESSAGE['MOD_FORM_REQUIRED_FIELDS'].'</h3>';
462
			}
463
			echo "<ol class=\"warning\">\n";
464
			foreach($required AS $field_title) {
465
				if($field_title!=''){
466
					echo '<li>'.$field_title."</li>\n";
467
				}
468
			}
469

    
470
			if(isset($email_error)) {
471
				echo '<li>'.$email_error."</li>\n";
472
			}
473

    
474
			if(isset($captcha_error)) {
475
				echo '<li>'.$captcha_error."</li>\n";
476
			}
477
			// Create blank "required" array
478
			$required = array();
479
			echo "</ol>\n";
480

    
481
			echo '<p>&nbsp;</p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
482
		} else {
483
			if(isset($email_error)) {
484
				echo '<br /><ol class=\"warning\">'."\n";
485
				echo '<li>'.$email_error.'</li>'."\n";
486
				echo '</ol>'."\n";
487
				echo '<a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a>';
488
			} elseif(isset($captcha_error)) {
489
				echo '<br /><ol class=\"warning\">'."\n";
490
				echo '<li>'.$captcha_error.'</li>'."\n";
491
				echo '</ol>'."\n";
492
				echo '<p>&nbsp;</p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
493
			} else {
494
				// Check how many times form has been submitted in last hour
495
				$last_hour = time()-3600;
496
				$sql  = 'SELECT `submission_id` FROM `'.TABLE_PREFIX.'mod_form_submissions` ';
497
				$sql .= 'WHERE `submitted_when` >= '.$last_hour.'';
498
				$sql .= '';
499
				if($query_submissions = $database->query($sql))
500
				{
501
					if($query_submissions->numRows() > $max_submissions)
502
					{
503
						// Too many submissions so far this hour
504
						echo $MESSAGE['MOD_FORM_EXCESS_SUBMISSIONS'];
505
						$success = false;
506
					} else {
507
						// Adding the IP to the body and try to send the email
508
						// $email_body .= "\n\nIP: ".$_SERVER['REMOTE_ADDR'];
509
						$iFormRequestId = isset($_POST['fri']) ? intval($_POST['fri']) : 0;
510
						if($iFormRequestId) {
511
							$email_body .= "\n\nFormRequestID: ".$iFormRequestId;
512
						}
513
						$recipient = preg_replace( "/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $email_fromname );
514
						$email_fromname = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient );
515
						$email_body = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $email_body );
516

    
517
						if($mail_replyto != '') {
518

    
519
							if($email_from != '') {
520
								$success = $wb->mail(SERVER_EMAIL,$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
521
							} else {
522
								$success = $wb->mail('',$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
523
							}
524
						}
525

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

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

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

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

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

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

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

    
662
			$oTpl->parse('main', 'main_block', false);
663
			$output = $oTpl->finish($oTpl->parse('output', 'page'));
664
			unset($oTpl);
665
			print $output;
666

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

    
683
}
(24-24/25)