Project

General

Profile

1 1457 Luisehahne
<?php
2
/**
3
 *
4
 * @category        module
5
 * @package         Form
6
 * @author          WebsiteBaker Project
7 1898 Luisehahne
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.org/
9 1457 Luisehahne
 * @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$
13 1898 Luisehahne
 * @filesource      $HeadURL$
14 1457 Luisehahne
 * @lastmodified    $Date$
15 1553 Luisehahne
 * @description
16 1457 Luisehahne
 */
17
18
// Must include code to stop this file being access directly
19 1538 Luisehahne
/* -------------------------------------------------------- */
20
if(defined('WB_PATH') == false)
21
{
22
	// Stop this file being access directly
23 1714 Luisehahne
		die('<h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2>');
24 1538 Luisehahne
}
25
/* -------------------------------------------------------- */
26 1457 Luisehahne
27 1553 Luisehahne
// load module language file
28
$lang = (dirname(__FILE__)) . '/languages/' . LANGUAGE . '.php';
29
require_once(!file_exists($lang) ? (dirname(__FILE__)) . '/languages/EN.php' : $lang );
30 1573 Luisehahne
31
include_once(WB_PATH .'/framework/functions.php');
32 1655 Luisehahne
$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 1553 Luisehahne
/*
38
function removebreaks($value) {
39
	return trim(preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i', null, $value));
40 1457 Luisehahne
}
41 1553 Luisehahne
function checkbreaks($value) {
42
	return $value === removebreaks($value);
43
}
44
*/
45 1714 Luisehahne
$aSuccess =array();
46 1573 Luisehahne
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 1457 Luisehahne
// Function for generating an optionsfor a select field
61
if (!function_exists('make_option')) {
62 1553 Luisehahne
	function make_option(&$n, $k, $values) {
63
		// start option group if it exists
64
		if (substr($n,0,2) == '[=') {
65 1801 Luisehahne
		 	$n = '<optgroup label="'.substr($n,2,strlen($n)).'">';
66 1553 Luisehahne
		} elseif ($n == ']') {
67 1801 Luisehahne
			$n = '</optgroup>'."\n";
68 1457 Luisehahne
		} else {
69 1553 Luisehahne
			if(in_array($n, $values)) {
70 1801 Luisehahne
				$n = '<option selected="selected" value="'.$n.'">'.$n.'</option>'."\n";
71 1553 Luisehahne
			} else {
72 1801 Luisehahne
				$n = '<option value="'.$n.'">'.$n.'</option>'."\n";
73 1553 Luisehahne
			}
74 1457 Luisehahne
		}
75
	}
76
}
77
// Function for generating a checkbox
78
if (!function_exists('make_checkbox')) {
79 1553 Luisehahne
	function make_checkbox(&$key, $idx, $params) {
80
		$field_id = $params[0][0];
81
		$seperator = $params[0][1];
82
83 1582 Luisehahne
		$label_id = 'wb_'.preg_replace('/[^a-z0-9]/i', '_', $key).$field_id;
84 1553 Luisehahne
		if(in_array($key, $params[1])) {
85 1868 Luisehahne
			$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 1553 Luisehahne
		} else {
87 1868 Luisehahne
			$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 1553 Luisehahne
		}
89
	}
90 1457 Luisehahne
}
91
// Function for generating a radio button
92
if (!function_exists('make_radio')) {
93 1553 Luisehahne
	function make_radio(&$n, $idx, $params) {
94
		$field_id = $params[0];
95
		$group = $params[1];
96
		$seperator = $params[2];
97 1582 Luisehahne
		$label_id = 'wb_'.preg_replace('/[^a-z0-9]/i', '_', $n).$field_id;
98 1553 Luisehahne
		if($n == $params[3]) {
99 1868 Luisehahne
			$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 1553 Luisehahne
		} else {
101 1868 Luisehahne
			$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 1553 Luisehahne
		}
103 1457 Luisehahne
	}
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 1655 Luisehahne
if($_POST == array())
124
{
125 1553 Luisehahne
	require_once(WB_PATH.'/include/captcha/captcha.php');
126 1457 Luisehahne
127 1553 Luisehahne
	// Set new submission ID in session
128
	$_SESSION['form_submission_id'] = new_submission_id();
129
    $out = '';
130 1457 Luisehahne
	$header = '';
131
	$field_loop = '';
132
	$footer = '';
133
	$form_name = 'form';
134
	$use_xhtml_strict = false;
135 1553 Luisehahne
	// Get settings
136
	$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_settings` ';
137
	$sql .= 'WHERE section_id = '.$section_id.' ';
138 1655 Luisehahne
	if($query_settings = $database->query($sql))
139
	{
140
		if($query_settings->numRows() > 0)
141
		{
142 1553 Luisehahne
			$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 1655 Luisehahne
			$page_id = $fetch_settings['page_id'];
150 1553 Luisehahne
		}
151
	}
152 1457 Luisehahne
153 1553 Luisehahne
// do not use sec_anchor, can destroy some layouts
154 1457 Luisehahne
155 1553 Luisehahne
	// 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 1457 Luisehahne
160 1553 Luisehahne
	if($query_fields = $database->query($sql)) {
161
		if($query_fields->numRows() > 0) {
162
?>
163 1781 Luisehahne
			<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 1898 Luisehahne
            <fieldset class="frm-fieldset">
165 1553 Luisehahne
				<input type="hidden" name="submission_id" value="<?php echo $_SESSION['form_submission_id']; ?>" />
166 1590 darkviper
				<?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 1553 Luisehahne
				<?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 1714 Luisehahne
					<p class="nixhier">
178 1553 Luisehahne
					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 1457 Luisehahne
193 1553 Luisehahne
	// Print header  MYSQL_ASSOC
194 1655 Luisehahne
		   echo $header."\n";
195 1553 Luisehahne
			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 1868 Luisehahne
				} 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 1553 Luisehahne
				}
208
				$values = array($field_title);
209
				if ($field['required'] == 1) {
210 1801 Luisehahne
					$values[] = '<span class="frm-required">*</span>';
211 1553 Luisehahne
				} else {
212
					$values[] = '';
213
				}
214
				if($field['type'] == 'textfield') {
215
					$vars[] = '{FIELD}';
216 1607 Luisehahne
					$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
217 1801 Luisehahne
					$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 1553 Luisehahne
				} elseif($field['type'] == 'textarea') {
219
					$vars[] = '{FIELD}';
220 1801 Luisehahne
					$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 1553 Luisehahne
				} 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 1740 Luisehahne
					$field['extra'][1] = ($field['extra'][1]=='multiple') ? $field['extra'][1].'="'.$field['extra'][1].'"' : '';
227 1801 Luisehahne
					$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 1553 Luisehahne
				} 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 1607 Luisehahne
					$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
251 1801 Luisehahne
					$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 1553 Luisehahne
				}
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 1457 Luisehahne
// Add form end code
272
?>
273 1781 Luisehahne
        </fieldset>
274 1457 Luisehahne
</form>
275
<?php
276 1553 Luisehahne
		}
277
	}
278 1457 Luisehahne
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 1553 Luisehahne
284 1655 Luisehahne
	   $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 1457 Luisehahne
		// Set new submission ID in session
292
		$_SESSION['form_submission_id'] = new_submission_id();
293 1553 Luisehahne
294 1457 Luisehahne
		if(ENABLED_ASP && ( // form faked? Check the honeypot-fields.
295 1553 Luisehahne
			(!isset($_POST['submitted_when']) OR !isset($_SESSION['submitted_when'])) OR
296 1457 Luisehahne
			($_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 1553 Luisehahne
			// spam
303 1714 Luisehahne
			header("Location: ".WB_URL."");
304 1553 Luisehahne
            exit();
305 1457 Luisehahne
		}
306
		// Submit form data
307
		// First start message settings
308 1553 Luisehahne
		$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_settings` ';
309
		$sql .= 'WHERE `section_id` = '.(int)$section_id.'';
310 1714 Luisehahne
		if($query_settings = $database->query($sql) )
311
		{
312
			if($query_settings->numRows() > 0)
313
			{
314 1553 Luisehahne
				$fetch_settings = $query_settings->fetchRow(MYSQL_ASSOC);
315
316 1573 Luisehahne
				// $email_to = $fetch_settings['email_to'];
317
				$email_to = (($fetch_settings['email_to'] != '') ? $fetch_settings['email_to'] : emailAdmin());
318 1714 Luisehahne
				$email_from = $wb->add_slashes(SERVER_EMAIL);
319 1579 Luisehahne
/*
320 1553 Luisehahne
				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 1579 Luisehahne
*/
325 1553 Luisehahne
				$email_fromname = $fetch_settings['email_fromname'];
326 1714 Luisehahne
 				$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 1655 Luisehahne
329 1553 Luisehahne
				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 1655 Luisehahne
334 1573 Luisehahne
				$email_subject = (($fetch_settings['email_subject'] != '') ? $fetch_settings['email_subject'] : $MOD_FORM['EMAIL_SUBJECT']);
335 1553 Luisehahne
				$success_page = $fetch_settings['success_page'];
336 1655 Luisehahne
				$success_email_to = $mail_replyto;
337 1714 Luisehahne
				$success_email_from = $wb->add_slashes(SERVER_EMAIL);
338
				$success_email_fromname = $fetch_settings['success_email_fromname'];
339 1655 Luisehahne
/*
340 1714 Luisehahne
*/
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 1804 Luisehahne
					$email_fromname = $TEXT['GUEST'];
349 1714 Luisehahne
//					$success_email_fromname = $TEXT['UNKNOWN'];
350
//					$email_from = $TEXT['UNKNOWN'];
351 1553 Luisehahne
				}
352 1714 Luisehahne
353 1553 Luisehahne
				$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 1573 Luisehahne
				$success_email_subject = (($fetch_settings['success_email_subject'] != '') ? $fetch_settings['success_email_subject'] : $MOD_FORM['SUCCESS_EMAIL_SUBJECT']);
356 1553 Luisehahne
				$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 1457 Luisehahne
			}
362
		}
363 1655 Luisehahne
364 1457 Luisehahne
		$email_body = '';
365
		// Create blank "required" array
366
		$required = array();
367 1553 Luisehahne
368 1457 Luisehahne
		// Captcha
369
		if($use_captcha) {
370
			if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
371 1573 Luisehahne
				// Check for a mismatch get email user_id
372 1457 Luisehahne
				if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
373 1573 Luisehahne
					$replace = array('webmaster_email' => emailAdmin() );
374 1575 Luisehahne
					$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'], $replace);
375 1655 Luisehahne
					$required[]= '';
376 1457 Luisehahne
				}
377
			} else {
378 1573 Luisehahne
				$replace = array('webmaster_email'=>emailAdmin() );
379
				$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'],$replace );
380 1655 Luisehahne
				$required[]= '';
381 1457 Luisehahne
			}
382
		}
383
		if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
384
385 1801 Luisehahne
/* 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 1457 Luisehahne
		// Loop through fields and add to message body
406
		// Get list of fields
407 1553 Luisehahne
		$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 1655 Luisehahne
						if(!empty($_POST['field'.$field['field_id']]))
416
						{
417 1801 Luisehahne
                            $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 1553 Luisehahne
							} else {
427 1801 Luisehahne
                                $sPostVar = $wb->strip_slashes($wb->StripCodeFromText($wb->get_post('field'.$field['field_id']),true));
428
                                $_SESSION['field'.$field['field_id']] = $sPostVar;
429 1457 Luisehahne
							}
430 1655 Luisehahne
431 1801 Luisehahne
							if($field['type'] == 'email' AND $wb->validate_email($sPostVar) == false) {
432 1573 Luisehahne
								$email_error = $MESSAGE['USERS_INVALID_EMAIL'];
433 1655 Luisehahne
								$required[]= '';
434 1553 Luisehahne
							}
435
							if($field['type'] == 'heading') {
436 1801 Luisehahne
								$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 1553 Luisehahne
								}
445
								$email_body .= "\n";
446
							}
447 1655 Luisehahne
448 1553 Luisehahne
						} elseif($field['required'] == 1) {
449
							$required[] = $field['title'];
450 1457 Luisehahne
						}
451
					}
452 1553 Luisehahne
				} //  while
453
			}  // numRows
454
		} //  query
455 1655 Luisehahne
456 1553 Luisehahne
// Check if the user forgot to enter values into all the required fields
457
		if(sizeof($required )) {
458 1898 Luisehahne
			echo "<div class=\"frm-warning\">\n";
459 1553 Luisehahne
			if(!isset($MESSAGE['MOD_FORM_REQUIRED_FIELDS'])) {
460
				echo '<h3>You must enter details for the following fields</h3>';
461 1457 Luisehahne
			} else {
462 1553 Luisehahne
				echo '<h3>'.$MESSAGE['MOD_FORM_REQUIRED_FIELDS'].'</h3>';
463 1457 Luisehahne
			}
464 1898 Luisehahne
			echo "<ol>\n";
465 1457 Luisehahne
			foreach($required AS $field_title) {
466 1655 Luisehahne
				if($field_title!=''){
467
					echo '<li>'.$field_title."</li>\n";
468
				}
469 1457 Luisehahne
			}
470
			if(isset($email_error)) {
471 1655 Luisehahne
				echo '<li>'.$email_error."</li>\n";
472 1457 Luisehahne
			}
473
			if(isset($captcha_error)) {
474 1655 Luisehahne
				echo '<li>'.$captcha_error."</li>\n";
475 1457 Luisehahne
			}
476 1553 Luisehahne
			// Create blank "required" array
477
			$required = array();
478 1714 Luisehahne
			echo "</ol>\n";
479 1898 Luisehahne
			echo "</div>\n";
480
			echo '<p class="frm-warning"><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
481 1457 Luisehahne
		} else {
482
			if(isset($email_error)) {
483 1898 Luisehahne
			echo "<div class=\"frm-warning\">\n";
484
				echo '<br /><ol>'."\n";
485 1655 Luisehahne
				echo '<li>'.$email_error.'</li>'."\n";
486 1714 Luisehahne
				echo '</ol>'."\n";
487 1898 Luisehahne
			echo "</div>\n";
488
				echo '<p class="frm-warning"><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
489 1457 Luisehahne
			} elseif(isset($captcha_error)) {
490 1898 Luisehahne
			echo "<div class=\"frm-warning\">\n";
491
				echo '<br /><ol>'."\n";
492 1655 Luisehahne
				echo '<li>'.$captcha_error.'</li>'."\n";
493 1714 Luisehahne
				echo '</ol>'."\n";
494 1898 Luisehahne
			echo "</div>\n";
495
				echo '<p class="frm-warning"><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
496 1457 Luisehahne
			} else {
497 1919 Luisehahne
				$success = false;
498 1898 Luisehahne
// Check how many times form has been submitted in last hour
499 1457 Luisehahne
				$last_hour = time()-3600;
500 1553 Luisehahne
				$sql  = 'SELECT `submission_id` FROM `'.TABLE_PREFIX.'mod_form_submissions` ';
501
				$sql .= 'WHERE `submitted_when` >= '.$last_hour.'';
502
				$sql .= '';
503 1655 Luisehahne
				if($query_submissions = $database->query($sql))
504
				{
505
					if($query_submissions->numRows() > $max_submissions)
506
					{
507 1898 Luisehahne
// Too many submissions so far this hour
508 1553 Luisehahne
						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 1594 Luisehahne
						$iFormRequestId = isset($_POST['fri']) ? intval($_POST['fri']) : 0;
514 1590 darkviper
						if($iFormRequestId) {
515
							$email_body .= "\n\nFormRequestID: ".$iFormRequestId;
516
						}
517 1553 Luisehahne
						$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 1655 Luisehahne
521 1714 Luisehahne
						if($mail_replyto != '') {
522
523 1553 Luisehahne
							if($email_from != '') {
524 1655 Luisehahne
								$success = $wb->mail(SERVER_EMAIL,$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
525 1553 Luisehahne
							} else {
526 1655 Luisehahne
								$success = $wb->mail('',$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
527 1553 Luisehahne
							}
528
						}
529 1491 Luisehahne
530 1655 Luisehahne
						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 1714 Luisehahne
							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 1655 Luisehahne
								} else {
541 1714 Luisehahne
									$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 1553 Luisehahne
								}
543 1457 Luisehahne
							}
544
						}
545 1553 Luisehahne
546 1655 Luisehahne
						if($success==true)
547
						{
548 1714 Luisehahne
							$aSuccess[] .= 'INSERT INTO '.TABLE_PREFIX.'mod_form_submissions<br /> ';;
549 1655 Luisehahne
							// Write submission to database
550 1714 Luisehahne
							if(isset($wb) AND $wb->is_authenticated() AND $wb->get_user_id() > 0) {
551
								$submitted_by = $wb->get_user_id();
552 1655 Luisehahne
							} 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 1714 Luisehahne
								// Get the page id
566
								$iSubmissionId = intval($database->get_one("SELECT LAST_INSERT_ID()"));
567
568 1655 Luisehahne
								if(!$database->is_error()) {
569
									$success = true;
570 1553 Luisehahne
								}
571 1655 Luisehahne
								// 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 1553 Luisehahne
			}
593
		}  // email_error
594
	} else {
595
596 1801 Luisehahne
	echo '<p>&nbsp;</p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
597 1457 Luisehahne
	}
598 1553 Luisehahne
599 1655 Luisehahne
	$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 1457 Luisehahne
	// Now check if the email was sent successfully
607 1655 Luisehahne
	if(isset($success) && $success == true)
608
	{
609 1457 Luisehahne
	   if ($success_page=='none') {
610 1714 Luisehahne
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 1761 Luisehahne
            		'MODULE_URL' => WB_URL.'/modules/form',
645 1714 Luisehahne
            		'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 1804 Luisehahne
					'TEXT_USERNAME' => $TEXT['USERNAME'],
657 1714 Luisehahne
					'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 1457 Luisehahne
  		} else {
672 1655 Luisehahne
			echo "<script type='text/javascript'>location.href='".$sSuccessLink."';</script>";
673 1457 Luisehahne
		}
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 1553 Luisehahne
		while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
677
			$field_id = $field['field_id'];
678 1457 Luisehahne
			if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
679
		}
680
	} else {
681 1655 Luisehahne
		if(isset($success) && $success == false) {
682
			echo '<br />'.$MOD_FORM['ERROR'];
683 1801 Luisehahne
			echo '<p>&nbsp;</p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
684 1457 Luisehahne
		}
685
	}
686 1553 Luisehahne
687 1590 darkviper
}