Project

General

Profile

1 1457 Luisehahne
<?php
2
/**
3
 *
4
 * @category        module
5
 * @package         Form
6
 * @author          WebsiteBaker Project
7 1714 Luisehahne
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1457 Luisehahne
 * @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$
13
 * @filesource		$HeadURL$
14
 * @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 1801 Luisehahne
			$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 1553 Luisehahne
		} else {
87 1801 Luisehahne
			$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 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 1801 Luisehahne
			$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 1553 Luisehahne
		} else {
101 1801 Luisehahne
			$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 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 1757 Luisehahne
$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? '#'.SEC_ANCHOR.$fetch_settings['section_id'] : 'section_'.$section_id );
155 1457 Luisehahne
156 1553 Luisehahne
	// 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 1457 Luisehahne
161 1553 Luisehahne
	if($query_fields = $database->query($sql)) {
162
		if($query_fields->numRows() > 0) {
163
?>
164 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">
165
            <fieldset>
166 1553 Luisehahne
				<input type="hidden" name="submission_id" value="<?php echo $_SESSION['form_submission_id']; ?>" />
167 1590 darkviper
				<?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 1553 Luisehahne
				<?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 1714 Luisehahne
					<p class="nixhier">
179 1553 Luisehahne
					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 1457 Luisehahne
194 1553 Luisehahne
	// Print header  MYSQL_ASSOC
195 1655 Luisehahne
		   echo $header."\n";
196 1553 Luisehahne
			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 1801 Luisehahne
					$field_title = '<label for="field'.$field_id.'">'.$field['title'].'</label>';
206 1553 Luisehahne
				}
207
				$values = array($field_title);
208
				if ($field['required'] == 1) {
209 1801 Luisehahne
					$values[] = '<span class="frm-required">*</span>';
210 1553 Luisehahne
				} else {
211
					$values[] = '';
212
				}
213
				if($field['type'] == 'textfield') {
214
					$vars[] = '{FIELD}';
215 1607 Luisehahne
					$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
216 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" />';
217 1553 Luisehahne
				} elseif($field['type'] == 'textarea') {
218
					$vars[] = '{FIELD}';
219 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>';
220 1553 Luisehahne
				} 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 1740 Luisehahne
					$field['extra'][1] = ($field['extra'][1]=='multiple') ? $field['extra'][1].'="'.$field['extra'][1].'"' : '';
226 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";
227 1553 Luisehahne
				} 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 1607 Luisehahne
					$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
250 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" />';
251 1553 Luisehahne
				}
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 1457 Luisehahne
// Add form end code
271
?>
272 1781 Luisehahne
        </fieldset>
273 1457 Luisehahne
</form>
274
<?php
275 1553 Luisehahne
		}
276
	}
277 1457 Luisehahne
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 1553 Luisehahne
283 1655 Luisehahne
	   $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 1457 Luisehahne
		// Set new submission ID in session
291
		$_SESSION['form_submission_id'] = new_submission_id();
292 1553 Luisehahne
293 1457 Luisehahne
		if(ENABLED_ASP && ( // form faked? Check the honeypot-fields.
294 1553 Luisehahne
			(!isset($_POST['submitted_when']) OR !isset($_SESSION['submitted_when'])) OR
295 1457 Luisehahne
			($_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 1553 Luisehahne
			// spam
302 1714 Luisehahne
			header("Location: ".WB_URL."");
303 1553 Luisehahne
            exit();
304 1457 Luisehahne
		}
305
		// Submit form data
306
		// First start message settings
307 1553 Luisehahne
		$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_settings` ';
308
		$sql .= 'WHERE `section_id` = '.(int)$section_id.'';
309 1714 Luisehahne
		if($query_settings = $database->query($sql) )
310
		{
311
			if($query_settings->numRows() > 0)
312
			{
313 1553 Luisehahne
				$fetch_settings = $query_settings->fetchRow(MYSQL_ASSOC);
314
315 1573 Luisehahne
				// $email_to = $fetch_settings['email_to'];
316
				$email_to = (($fetch_settings['email_to'] != '') ? $fetch_settings['email_to'] : emailAdmin());
317 1714 Luisehahne
				$email_from = $wb->add_slashes(SERVER_EMAIL);
318 1579 Luisehahne
/*
319 1553 Luisehahne
				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 1579 Luisehahne
*/
324 1553 Luisehahne
				$email_fromname = $fetch_settings['email_fromname'];
325 1714 Luisehahne
 				$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 1655 Luisehahne
328 1553 Luisehahne
				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 1655 Luisehahne
333 1573 Luisehahne
				$email_subject = (($fetch_settings['email_subject'] != '') ? $fetch_settings['email_subject'] : $MOD_FORM['EMAIL_SUBJECT']);
334 1553 Luisehahne
				$success_page = $fetch_settings['success_page'];
335 1655 Luisehahne
				$success_email_to = $mail_replyto;
336 1714 Luisehahne
				$success_email_from = $wb->add_slashes(SERVER_EMAIL);
337
				$success_email_fromname = $fetch_settings['success_email_fromname'];
338 1655 Luisehahne
/*
339 1714 Luisehahne
*/
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 1804 Luisehahne
					$email_fromname = $TEXT['GUEST'];
348 1714 Luisehahne
//					$success_email_fromname = $TEXT['UNKNOWN'];
349
//					$email_from = $TEXT['UNKNOWN'];
350 1553 Luisehahne
				}
351 1714 Luisehahne
352 1553 Luisehahne
				$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 1573 Luisehahne
				$success_email_subject = (($fetch_settings['success_email_subject'] != '') ? $fetch_settings['success_email_subject'] : $MOD_FORM['SUCCESS_EMAIL_SUBJECT']);
355 1553 Luisehahne
				$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 1457 Luisehahne
			}
361
		}
362 1655 Luisehahne
363 1457 Luisehahne
		$email_body = '';
364
		// Create blank "required" array
365
		$required = array();
366 1553 Luisehahne
367 1457 Luisehahne
		// Captcha
368
		if($use_captcha) {
369
			if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
370 1573 Luisehahne
				// Check for a mismatch get email user_id
371 1457 Luisehahne
				if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
372 1573 Luisehahne
					$replace = array('webmaster_email' => emailAdmin() );
373 1575 Luisehahne
					$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'], $replace);
374 1655 Luisehahne
					$required[]= '';
375 1457 Luisehahne
				}
376
			} else {
377 1573 Luisehahne
				$replace = array('webmaster_email'=>emailAdmin() );
378
				$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'],$replace );
379 1655 Luisehahne
				$required[]= '';
380 1457 Luisehahne
			}
381
		}
382
		if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
383
384 1801 Luisehahne
/* 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 1457 Luisehahne
		// Loop through fields and add to message body
405
		// Get list of fields
406 1553 Luisehahne
		$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 1655 Luisehahne
						if(!empty($_POST['field'.$field['field_id']]))
415
						{
416 1801 Luisehahne
                            $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 1553 Luisehahne
							} else {
426 1801 Luisehahne
                                $sPostVar = $wb->strip_slashes($wb->StripCodeFromText($wb->get_post('field'.$field['field_id']),true));
427
                                $_SESSION['field'.$field['field_id']] = $sPostVar;
428 1457 Luisehahne
							}
429 1655 Luisehahne
430 1801 Luisehahne
							if($field['type'] == 'email' AND $wb->validate_email($sPostVar) == false) {
431 1573 Luisehahne
								$email_error = $MESSAGE['USERS_INVALID_EMAIL'];
432 1655 Luisehahne
								$required[]= '';
433 1553 Luisehahne
							}
434
							if($field['type'] == 'heading') {
435 1801 Luisehahne
								$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 1553 Luisehahne
								}
444
								$email_body .= "\n";
445
							}
446 1655 Luisehahne
447 1553 Luisehahne
						} elseif($field['required'] == 1) {
448
							$required[] = $field['title'];
449 1457 Luisehahne
						}
450
					}
451 1553 Luisehahne
				} //  while
452
			}  // numRows
453
		} //  query
454 1655 Luisehahne
455 1553 Luisehahne
// 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 1457 Luisehahne
			} else {
461 1553 Luisehahne
				echo '<h3>'.$MESSAGE['MOD_FORM_REQUIRED_FIELDS'].'</h3>';
462 1457 Luisehahne
			}
463 1714 Luisehahne
			echo "<ol class=\"warning\">\n";
464 1457 Luisehahne
			foreach($required AS $field_title) {
465 1655 Luisehahne
				if($field_title!=''){
466
					echo '<li>'.$field_title."</li>\n";
467
				}
468 1457 Luisehahne
			}
469 1655 Luisehahne
470 1457 Luisehahne
			if(isset($email_error)) {
471 1655 Luisehahne
				echo '<li>'.$email_error."</li>\n";
472 1457 Luisehahne
			}
473 1655 Luisehahne
474 1457 Luisehahne
			if(isset($captcha_error)) {
475 1655 Luisehahne
				echo '<li>'.$captcha_error."</li>\n";
476 1457 Luisehahne
			}
477 1553 Luisehahne
			// Create blank "required" array
478
			$required = array();
479 1714 Luisehahne
			echo "</ol>\n";
480 1655 Luisehahne
481
			echo '<p>&nbsp;</p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
482 1457 Luisehahne
		} else {
483
			if(isset($email_error)) {
484 1714 Luisehahne
				echo '<br /><ol class=\"warning\">'."\n";
485 1655 Luisehahne
				echo '<li>'.$email_error.'</li>'."\n";
486 1714 Luisehahne
				echo '</ol>'."\n";
487 1553 Luisehahne
				echo '<a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a>';
488 1457 Luisehahne
			} elseif(isset($captcha_error)) {
489 1714 Luisehahne
				echo '<br /><ol class=\"warning\">'."\n";
490 1655 Luisehahne
				echo '<li>'.$captcha_error.'</li>'."\n";
491 1714 Luisehahne
				echo '</ol>'."\n";
492 1655 Luisehahne
				echo '<p>&nbsp;</p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
493 1457 Luisehahne
			} else {
494
				// Check how many times form has been submitted in last hour
495
				$last_hour = time()-3600;
496 1553 Luisehahne
				$sql  = 'SELECT `submission_id` FROM `'.TABLE_PREFIX.'mod_form_submissions` ';
497
				$sql .= 'WHERE `submitted_when` >= '.$last_hour.'';
498
				$sql .= '';
499 1655 Luisehahne
				if($query_submissions = $database->query($sql))
500
				{
501
					if($query_submissions->numRows() > $max_submissions)
502
					{
503 1553 Luisehahne
						// 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 1594 Luisehahne
						$iFormRequestId = isset($_POST['fri']) ? intval($_POST['fri']) : 0;
510 1590 darkviper
						if($iFormRequestId) {
511
							$email_body .= "\n\nFormRequestID: ".$iFormRequestId;
512
						}
513 1553 Luisehahne
						$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 1655 Luisehahne
517 1714 Luisehahne
						if($mail_replyto != '') {
518
519 1553 Luisehahne
							if($email_from != '') {
520 1655 Luisehahne
								$success = $wb->mail(SERVER_EMAIL,$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
521 1553 Luisehahne
							} else {
522 1655 Luisehahne
								$success = $wb->mail('',$email_to,$email_subject,$email_body,$email_fromname,$mail_replyto);
523 1553 Luisehahne
							}
524
						}
525 1491 Luisehahne
526 1655 Luisehahne
						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 1714 Luisehahne
							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 1655 Luisehahne
								} else {
537 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);
538 1553 Luisehahne
								}
539 1457 Luisehahne
							}
540
						}
541 1553 Luisehahne
542 1655 Luisehahne
						if($success==true)
543
						{
544 1714 Luisehahne
							$aSuccess[] .= 'INSERT INTO '.TABLE_PREFIX.'mod_form_submissions<br /> ';;
545 1655 Luisehahne
							// Write submission to database
546 1714 Luisehahne
							if(isset($wb) AND $wb->is_authenticated() AND $wb->get_user_id() > 0) {
547
								$submitted_by = $wb->get_user_id();
548 1655 Luisehahne
							} 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 1714 Luisehahne
								// Get the page id
562
								$iSubmissionId = intval($database->get_one("SELECT LAST_INSERT_ID()"));
563
564 1655 Luisehahne
								if(!$database->is_error()) {
565
									$success = true;
566 1553 Luisehahne
								}
567 1655 Luisehahne
								// 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 1553 Luisehahne
			}
589
		}  // email_error
590
	} else {
591
592 1801 Luisehahne
	echo '<p>&nbsp;</p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
593 1457 Luisehahne
	}
594 1553 Luisehahne
595 1655 Luisehahne
	$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 1457 Luisehahne
	// Now check if the email was sent successfully
603 1655 Luisehahne
	if(isset($success) && $success == true)
604
	{
605 1457 Luisehahne
	   if ($success_page=='none') {
606 1714 Luisehahne
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 1761 Luisehahne
            		'MODULE_URL' => WB_URL.'/modules/form',
641 1714 Luisehahne
            		'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 1804 Luisehahne
					'TEXT_USERNAME' => $TEXT['USERNAME'],
653 1714 Luisehahne
					'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 1457 Luisehahne
  		} else {
668 1655 Luisehahne
			echo "<script type='text/javascript'>location.href='".$sSuccessLink."';</script>";
669 1457 Luisehahne
		}
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 1553 Luisehahne
		while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
673
			$field_id = $field['field_id'];
674 1457 Luisehahne
			if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
675
		}
676
	} else {
677 1655 Luisehahne
		if(isset($success) && $success == false) {
678
			echo '<br />'.$MOD_FORM['ERROR'];
679 1801 Luisehahne
			echo '<p>&nbsp;</p>'."\n".'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'."\n";
680 1457 Luisehahne
		}
681
	}
682 1553 Luisehahne
683 1590 darkviper
}