1 |
1457
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category module
|
5 |
|
|
* @package Form
|
6 |
|
|
* @author WebsiteBaker Project
|
7 |
|
|
* @copyright 2009-2011, Website Baker 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$
|
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 |
|
|
die('<head><title>Access denied</title></head><body><h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2></body></html>');
|
24 |
|
|
}
|
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 |
1553
|
Luisehahne
|
/*
|
33 |
|
|
function removebreaks($value) {
|
34 |
|
|
return trim(preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i', null, $value));
|
35 |
1457
|
Luisehahne
|
}
|
36 |
1553
|
Luisehahne
|
function checkbreaks($value) {
|
37 |
|
|
return $value === removebreaks($value);
|
38 |
|
|
}
|
39 |
|
|
*/
|
40 |
1573
|
Luisehahne
|
|
41 |
|
|
if (!function_exists('emailAdmin')) {
|
42 |
|
|
function emailAdmin() {
|
43 |
|
|
global $database,$admin;
|
44 |
|
|
$retval = $admin->get_email();
|
45 |
|
|
if($admin->get_user_id()!='1') {
|
46 |
|
|
$sql = 'SELECT `email` FROM `'.TABLE_PREFIX.'users` ';
|
47 |
|
|
$sql .= 'WHERE `user_id`=\'1\' ';
|
48 |
|
|
$retval = $database->get_one($sql);
|
49 |
|
|
|
50 |
|
|
}
|
51 |
|
|
return $retval;
|
52 |
|
|
}
|
53 |
|
|
}
|
54 |
|
|
|
55 |
1457
|
Luisehahne
|
// Function for generating an optionsfor a select field
|
56 |
|
|
if (!function_exists('make_option')) {
|
57 |
1553
|
Luisehahne
|
function make_option(&$n, $k, $values) {
|
58 |
|
|
// start option group if it exists
|
59 |
|
|
if (substr($n,0,2) == '[=') {
|
60 |
|
|
$n = '<optgroup label="'.substr($n,2,strlen($n)).'">'.PHP_EOL;
|
61 |
|
|
} elseif ($n == ']') {
|
62 |
|
|
$n = '</optgroup>'.PHP_EOL;
|
63 |
1457
|
Luisehahne
|
} else {
|
64 |
1553
|
Luisehahne
|
if(in_array($n, $values)) {
|
65 |
|
|
$n = '<option selected="selected" value="'.$n.'">'.$n.'</option>'.PHP_EOL;
|
66 |
|
|
} else {
|
67 |
|
|
$n = '<option value="'.$n.'">'.$n.'</option>'.PHP_EOL;
|
68 |
|
|
}
|
69 |
1457
|
Luisehahne
|
}
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
// Function for generating a checkbox
|
73 |
|
|
if (!function_exists('make_checkbox')) {
|
74 |
1553
|
Luisehahne
|
function make_checkbox(&$key, $idx, $params) {
|
75 |
|
|
$field_id = $params[0][0];
|
76 |
|
|
$seperator = $params[0][1];
|
77 |
|
|
|
78 |
1582
|
Luisehahne
|
$label_id = 'wb_'.preg_replace('/[^a-z0-9]/i', '_', $key).$field_id;
|
79 |
1553
|
Luisehahne
|
if(in_array($key, $params[1])) {
|
80 |
|
|
$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.PHP_EOL;
|
81 |
|
|
} else {
|
82 |
|
|
$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.PHP_EOL;
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
1457
|
Luisehahne
|
}
|
86 |
|
|
// Function for generating a radio button
|
87 |
|
|
if (!function_exists('make_radio')) {
|
88 |
1553
|
Luisehahne
|
function make_radio(&$n, $idx, $params) {
|
89 |
|
|
$field_id = $params[0];
|
90 |
|
|
$group = $params[1];
|
91 |
|
|
$seperator = $params[2];
|
92 |
1582
|
Luisehahne
|
$label_id = 'wb_'.preg_replace('/[^a-z0-9]/i', '_', $n).$field_id;
|
93 |
1553
|
Luisehahne
|
if($n == $params[3]) {
|
94 |
|
|
$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.PHP_EOL;
|
95 |
|
|
} else {
|
96 |
|
|
$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.PHP_EOL;
|
97 |
|
|
}
|
98 |
1457
|
Luisehahne
|
}
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
if (!function_exists("new_submission_id") ) {
|
102 |
|
|
function new_submission_id() {
|
103 |
|
|
$submission_id = '';
|
104 |
|
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
105 |
|
|
srand((double)microtime()*1000000);
|
106 |
|
|
$i = 0;
|
107 |
|
|
while ($i <= 7) {
|
108 |
|
|
$num = rand() % 33;
|
109 |
|
|
$tmp = substr($salt, $num, 1);
|
110 |
|
|
$submission_id = $submission_id . $tmp;
|
111 |
|
|
$i++;
|
112 |
|
|
}
|
113 |
|
|
return $submission_id;
|
114 |
|
|
}
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
// Work-out if the form has been submitted or not
|
118 |
|
|
if($_POST == array()) {
|
119 |
1553
|
Luisehahne
|
require_once(WB_PATH.'/include/captcha/captcha.php');
|
120 |
1457
|
Luisehahne
|
|
121 |
1553
|
Luisehahne
|
// Set new submission ID in session
|
122 |
|
|
$_SESSION['form_submission_id'] = new_submission_id();
|
123 |
|
|
$out = '';
|
124 |
1457
|
Luisehahne
|
$header = '';
|
125 |
|
|
$field_loop = '';
|
126 |
|
|
$footer = '';
|
127 |
|
|
$form_name = 'form';
|
128 |
|
|
$use_xhtml_strict = false;
|
129 |
1553
|
Luisehahne
|
// Get settings
|
130 |
|
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_settings` ';
|
131 |
|
|
$sql .= 'WHERE section_id = '.$section_id.' ';
|
132 |
|
|
if($query_settings = $database->query($sql)) {
|
133 |
|
|
if($query_settings->numRows() > 0) {
|
134 |
|
|
$fetch_settings = $query_settings->fetchRow(MYSQL_ASSOC);
|
135 |
|
|
$header = str_replace('{WB_URL}',WB_URL,$fetch_settings['header']);
|
136 |
|
|
$field_loop = $fetch_settings['field_loop'];
|
137 |
|
|
$footer = str_replace('{WB_URL}',WB_URL,$fetch_settings['footer']);
|
138 |
|
|
$use_captcha = $fetch_settings['use_captcha'];
|
139 |
|
|
$form_name = 'form';
|
140 |
|
|
$use_xhtml_strict = false;
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
1457
|
Luisehahne
|
|
144 |
1553
|
Luisehahne
|
// do not use sec_anchor, can destroy some layouts
|
145 |
|
|
$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' ) ? '#'.SEC_ANCHOR.$section['section_id'] : '' );
|
146 |
1457
|
Luisehahne
|
|
147 |
1553
|
Luisehahne
|
// Get list of fields
|
148 |
|
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_fields` ';
|
149 |
|
|
$sql .= 'WHERE section_id = '.$section_id.' ';
|
150 |
|
|
$sql .= 'ORDER BY position ASC ';
|
151 |
1457
|
Luisehahne
|
|
152 |
1553
|
Luisehahne
|
if($query_fields = $database->query($sql)) {
|
153 |
|
|
if($query_fields->numRows() > 0) {
|
154 |
|
|
?>
|
155 |
|
|
<form <?php echo ( ( (strlen($form_name) > 0) AND (false == $use_xhtml_strict) ) ? "name=\"".$form_name."\"" : ""); ?> action="<?php echo htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'';?>" method="post">
|
156 |
|
|
<input type="hidden" name="submission_id" value="<?php echo $_SESSION['form_submission_id']; ?>" />
|
157 |
1590
|
darkviper
|
<?php
|
158 |
|
|
$iFormRequestId = isset($_GET['fri']) ? intval($_GET['fri']) : 0;
|
159 |
|
|
if($iFormRequestId) {
|
160 |
|
|
echo '<input type="hidden" name="fri" value="'.$iFormRequestId.'" />'."\n";
|
161 |
|
|
}
|
162 |
|
|
?>
|
163 |
1553
|
Luisehahne
|
<?php // echo $admin->getFTAN(); ?>
|
164 |
|
|
<?php
|
165 |
|
|
if(ENABLED_ASP) { // first add some honeypot-fields
|
166 |
|
|
?>
|
167 |
|
|
<input type="hidden" name="submitted_when" value="<?php $t=time(); echo $t; $_SESSION['submitted_when']=$t; ?>" />
|
168 |
|
|
<p class="frm-nixhier">
|
169 |
|
|
email address:
|
170 |
|
|
<label for="email">Leave this field email-address blank:</label>
|
171 |
|
|
<input id="email" name="email" size="56" value="" /><br />
|
172 |
|
|
Homepage:
|
173 |
|
|
<label for="homepage">Leave this field homepage blank:</label>
|
174 |
|
|
<input id="homepage" name="homepage" size="55" value="" /><br />
|
175 |
|
|
URL:
|
176 |
|
|
<label for="url">Leave this field url blank:</label>
|
177 |
|
|
<input id="url" name="url" size="61" value="" /><br />
|
178 |
|
|
Comment:
|
179 |
|
|
<label for="comment">Leave this field comment blank:</label>
|
180 |
|
|
<textarea id="comment" name="comment" cols="50" rows="10"></textarea><br />
|
181 |
|
|
</p>
|
182 |
|
|
<?php }
|
183 |
1457
|
Luisehahne
|
|
184 |
1553
|
Luisehahne
|
// Print header MYSQL_ASSOC
|
185 |
|
|
echo $header.PHP_EOL;
|
186 |
|
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
187 |
|
|
// Set field values
|
188 |
|
|
$field_id = $field['field_id'];
|
189 |
|
|
$value = $field['value'];
|
190 |
|
|
// Print field_loop after replacing vars with values
|
191 |
|
|
$vars = array('{TITLE}', '{REQUIRED}');
|
192 |
|
|
if (($field['type'] == "radio") || ($field['type'] == "checkbox")) {
|
193 |
|
|
$field_title = $field['title'];
|
194 |
|
|
} else {
|
195 |
|
|
$field_title = '<label for="field'.$field_id.'">'.$field['title'].'</label>'.PHP_EOL;
|
196 |
|
|
}
|
197 |
|
|
$values = array($field_title);
|
198 |
|
|
if ($field['required'] == 1) {
|
199 |
|
|
$values[] = '<span class="frm-required">*</span>'.PHP_EOL;
|
200 |
|
|
} else {
|
201 |
|
|
$values[] = '';
|
202 |
|
|
}
|
203 |
|
|
if($field['type'] == 'textfield') {
|
204 |
|
|
$vars[] = '{FIELD}';
|
205 |
1607
|
Luisehahne
|
$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
|
206 |
1553
|
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" />'.PHP_EOL;
|
207 |
|
|
} elseif($field['type'] == 'textarea') {
|
208 |
|
|
$vars[] = '{FIELD}';
|
209 |
|
|
$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>'.PHP_EOL;
|
210 |
|
|
} elseif($field['type'] == 'select') {
|
211 |
|
|
$vars[] = '{FIELD}';
|
212 |
|
|
$options = explode(',', $value);
|
213 |
|
|
array_walk($options, 'make_option', (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array()));
|
214 |
|
|
$field['extra'] = explode(',',$field['extra']);
|
215 |
|
|
$values[] = '<select name="field'.$field_id.'[]" id="field'.$field_id.'" size="'.$field['extra'][0].'" '.$field['extra'][1].' class="frm-select">'.implode($options).'</select>'.PHP_EOL;
|
216 |
|
|
} elseif($field['type'] == 'heading') {
|
217 |
|
|
$vars[] = '{FIELD}';
|
218 |
|
|
$str = '<input type="hidden" name="field'.$field_id.'" id="field'.$field_id.'" value="===['.$field['title'].']===" />';
|
219 |
|
|
$values[] = ( true == $use_xhtml_strict) ? "<div>".$str."</div>" : $str;
|
220 |
|
|
$tmp_field_loop = $field_loop; // temporarily modify the field loop template
|
221 |
|
|
$field_loop = $field['extra'];
|
222 |
|
|
} elseif($field['type'] == 'checkbox') {
|
223 |
|
|
$vars[] = '{FIELD}';
|
224 |
|
|
$options = explode(',', $value);
|
225 |
|
|
array_walk($options, 'make_checkbox', array(array($field_id,$field['extra']),(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array())));
|
226 |
|
|
$x = sizeof($options)-1;
|
227 |
|
|
$options[$x]=substr($options[$x],0,strlen($options[$x]));
|
228 |
|
|
$values[] = implode($options);
|
229 |
|
|
} elseif($field['type'] == 'radio') {
|
230 |
|
|
$vars[] = '{FIELD}';
|
231 |
|
|
$options = explode(',', $value);
|
232 |
|
|
array_walk($options, 'make_radio', array($field_id,$field['title'],$field['extra'], (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:'')));
|
233 |
|
|
$x = sizeof($options)-1;
|
234 |
|
|
$options[$x]=substr($options[$x],0,strlen($options[$x]));
|
235 |
|
|
$values[] = implode($options);
|
236 |
|
|
} elseif($field['type'] == 'email') {
|
237 |
|
|
$vars[] = '{FIELD}';
|
238 |
1607
|
Luisehahne
|
$max_lenght_para = (intval($field['extra']) ? ' maxlength="'.intval($field['extra']).'"' : '');
|
239 |
1553
|
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" />'.PHP_EOL;
|
240 |
|
|
}
|
241 |
|
|
if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
|
242 |
|
|
if($field['type'] != '') {
|
243 |
|
|
echo str_replace($vars, $values, $field_loop);
|
244 |
|
|
}
|
245 |
|
|
if (isset($tmp_field_loop)){ $field_loop = $tmp_field_loop; }
|
246 |
|
|
}
|
247 |
|
|
// Captcha
|
248 |
|
|
if($use_captcha) { ?>
|
249 |
|
|
<tr>
|
250 |
|
|
<td class="frm-field_title"><?php echo $TEXT['VERIFICATION']; ?>:</td>
|
251 |
|
|
<td><?php call_captcha(); ?></td>
|
252 |
|
|
</tr>
|
253 |
|
|
<?php
|
254 |
|
|
}
|
255 |
|
|
// Print footer
|
256 |
|
|
// $out = $footer.PHP_EOL;
|
257 |
|
|
$out .= str_replace('{SUBMIT_FORM}', $MOD_FORM['SUBMIT_FORM'], $footer);
|
258 |
|
|
echo $out;
|
259 |
1457
|
Luisehahne
|
// Add form end code
|
260 |
|
|
?>
|
261 |
|
|
</form>
|
262 |
|
|
<?php
|
263 |
1553
|
Luisehahne
|
}
|
264 |
|
|
}
|
265 |
1457
|
Luisehahne
|
|
266 |
|
|
} else {
|
267 |
|
|
|
268 |
|
|
// Check that submission ID matches
|
269 |
|
|
if(isset($_SESSION['form_submission_id']) AND isset($_POST['submission_id']) AND $_SESSION['form_submission_id'] == $_POST['submission_id']) {
|
270 |
1553
|
Luisehahne
|
|
271 |
1457
|
Luisehahne
|
// Set new submission ID in session
|
272 |
|
|
$_SESSION['form_submission_id'] = new_submission_id();
|
273 |
1553
|
Luisehahne
|
|
274 |
1457
|
Luisehahne
|
if(ENABLED_ASP && ( // form faked? Check the honeypot-fields.
|
275 |
1553
|
Luisehahne
|
(!isset($_POST['submitted_when']) OR !isset($_SESSION['submitted_when'])) OR
|
276 |
1457
|
Luisehahne
|
($_POST['submitted_when'] != $_SESSION['submitted_when']) OR
|
277 |
|
|
(!isset($_POST['email']) OR $_POST['email']) OR
|
278 |
|
|
(!isset($_POST['homepage']) OR $_POST['homepage']) OR
|
279 |
|
|
(!isset($_POST['comment']) OR $_POST['comment']) OR
|
280 |
|
|
(!isset($_POST['url']) OR $_POST['url'])
|
281 |
|
|
)) {
|
282 |
1553
|
Luisehahne
|
// spam
|
283 |
|
|
header("Location: ".WB_URL.PAGES_DIRECTORY."");
|
284 |
|
|
exit();
|
285 |
1457
|
Luisehahne
|
}
|
286 |
|
|
// Submit form data
|
287 |
|
|
// First start message settings
|
288 |
1553
|
Luisehahne
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_settings` ';
|
289 |
|
|
$sql .= 'WHERE `section_id` = '.(int)$section_id.'';
|
290 |
|
|
if($query_settings = $database->query($sql) ) {
|
291 |
|
|
if($query_settings->numRows() > 0) {
|
292 |
|
|
$fetch_settings = $query_settings->fetchRow(MYSQL_ASSOC);
|
293 |
|
|
|
294 |
1573
|
Luisehahne
|
// $email_to = $fetch_settings['email_to'];
|
295 |
|
|
$email_to = (($fetch_settings['email_to'] != '') ? $fetch_settings['email_to'] : emailAdmin());
|
296 |
1579
|
Luisehahne
|
$email_from = $admin->add_slashes(SERVER_EMAIL);
|
297 |
|
|
/*
|
298 |
1553
|
Luisehahne
|
if(substr($email_from, 0, 5) == 'field') {
|
299 |
|
|
// Set the email from field to what the user entered in the specified field
|
300 |
|
|
$email_from = htmlspecialchars($wb->add_slashes($_POST[$email_from]));
|
301 |
|
|
}
|
302 |
1579
|
Luisehahne
|
*/
|
303 |
1553
|
Luisehahne
|
$email_fromname = $fetch_settings['email_fromname'];
|
304 |
|
|
if(substr($email_fromname, 0, 5) == 'field') {
|
305 |
|
|
// Set the email_fromname to field to what the user entered in the specified field
|
306 |
|
|
$email_fromname = htmlspecialchars($wb->add_slashes($_POST[$email_fromname]));
|
307 |
|
|
}
|
308 |
1573
|
Luisehahne
|
$email_subject = (($fetch_settings['email_subject'] != '') ? $fetch_settings['email_subject'] : $MOD_FORM['EMAIL_SUBJECT']);
|
309 |
1553
|
Luisehahne
|
$success_page = $fetch_settings['success_page'];
|
310 |
1573
|
Luisehahne
|
$success_email_to = (($fetch_settings['success_email_to'] != '') ? $fetch_settings['success_email_to'] : '');
|
311 |
1553
|
Luisehahne
|
if(substr($success_email_to, 0, 5) == 'field') {
|
312 |
|
|
// Set the success_email to field to what the user entered in the specified field
|
313 |
|
|
$success_email_to = htmlspecialchars($wb->add_slashes($_POST[$success_email_to]));
|
314 |
|
|
}
|
315 |
1579
|
Luisehahne
|
$success_email_from = $admin->add_slashes(SERVER_EMAIL);
|
316 |
1553
|
Luisehahne
|
$success_email_fromname = $fetch_settings['success_email_fromname'];
|
317 |
|
|
$success_email_text = htmlspecialchars($wb->add_slashes($fetch_settings['success_email_text']));
|
318 |
|
|
$success_email_text = (($success_email_text != '') ? $success_email_text : $MOD_FORM['SUCCESS_EMAIL_TEXT']);
|
319 |
1573
|
Luisehahne
|
$success_email_subject = (($fetch_settings['success_email_subject'] != '') ? $fetch_settings['success_email_subject'] : $MOD_FORM['SUCCESS_EMAIL_SUBJECT']);
|
320 |
1553
|
Luisehahne
|
$max_submissions = $fetch_settings['max_submissions'];
|
321 |
|
|
$stored_submissions = $fetch_settings['stored_submissions'];
|
322 |
|
|
$use_captcha = $fetch_settings['use_captcha'];
|
323 |
|
|
} else {
|
324 |
|
|
exit($TEXT['UNDER_CONSTRUCTION']);
|
325 |
1457
|
Luisehahne
|
}
|
326 |
|
|
}
|
327 |
|
|
$email_body = '';
|
328 |
1553
|
Luisehahne
|
|
329 |
1457
|
Luisehahne
|
// Create blank "required" array
|
330 |
|
|
$required = array();
|
331 |
1553
|
Luisehahne
|
|
332 |
1457
|
Luisehahne
|
// Captcha
|
333 |
|
|
if($use_captcha) {
|
334 |
|
|
if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
|
335 |
1573
|
Luisehahne
|
// Check for a mismatch get email user_id
|
336 |
1457
|
Luisehahne
|
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
|
337 |
1573
|
Luisehahne
|
$replace = array('webmaster_email' => emailAdmin() );
|
338 |
1575
|
Luisehahne
|
$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'], $replace);
|
339 |
1457
|
Luisehahne
|
}
|
340 |
|
|
} else {
|
341 |
1573
|
Luisehahne
|
$replace = array('webmaster_email'=>emailAdmin() );
|
342 |
|
|
$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'],$replace );
|
343 |
1457
|
Luisehahne
|
}
|
344 |
|
|
}
|
345 |
|
|
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
|
346 |
|
|
|
347 |
|
|
// Loop through fields and add to message body
|
348 |
|
|
// Get list of fields
|
349 |
1553
|
Luisehahne
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_fields` ';
|
350 |
|
|
$sql .= 'WHERE `section_id` = '.(int)$section_id.' ';
|
351 |
|
|
$sql .= 'ORDER BY position ASC';
|
352 |
|
|
if($query_fields = $database->query($sql)) {
|
353 |
|
|
if($query_fields->numRows() > 0) {
|
354 |
|
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
355 |
|
|
// Add to message body
|
356 |
|
|
if($field['type'] != '') {
|
357 |
|
|
if(!empty($_POST['field'.$field['field_id']])) {
|
358 |
|
|
// do not allow droplets in user input!
|
359 |
|
|
if (is_array($_POST['field'.$field['field_id']])) {
|
360 |
|
|
$_SESSION['field'.$field['field_id']] = str_replace(array("[[", "]]"), array("[[", "]]"), $_POST['field'.$field['field_id']]);
|
361 |
|
|
} else {
|
362 |
|
|
$_SESSION['field'.$field['field_id']] = str_replace(array("[[", "]]"), array("[[", "]]"), htmlspecialchars($_POST['field'.$field['field_id']]));
|
363 |
1457
|
Luisehahne
|
}
|
364 |
1553
|
Luisehahne
|
if($field['type'] == 'email' AND $admin->validate_email($_POST['field'.$field['field_id']]) == false) {
|
365 |
1573
|
Luisehahne
|
$email_error = $MESSAGE['USERS_INVALID_EMAIL'];
|
366 |
1553
|
Luisehahne
|
}
|
367 |
|
|
if($field['type'] == 'heading') {
|
368 |
|
|
$email_body .= $_POST['field'.$field['field_id']]."\n\n";
|
369 |
|
|
} elseif (!is_array($_POST['field'.$field['field_id']])) {
|
370 |
|
|
$email_body .= $field['title'].': '.$_POST['field'.$field['field_id']]."\n\n";
|
371 |
|
|
} else {
|
372 |
|
|
$email_body .= $field['title'].": \n";
|
373 |
|
|
foreach ($_POST['field'.$field['field_id']] as $k=>$v) {
|
374 |
|
|
$email_body .= $v."\n";
|
375 |
|
|
}
|
376 |
|
|
$email_body .= "\n";
|
377 |
|
|
}
|
378 |
|
|
} elseif($field['required'] == 1) {
|
379 |
|
|
$required[] = $field['title'];
|
380 |
1457
|
Luisehahne
|
}
|
381 |
|
|
}
|
382 |
1553
|
Luisehahne
|
} // while
|
383 |
|
|
} // numRows
|
384 |
|
|
} // query
|
385 |
|
|
// Check if the user forgot to enter values into all the required fields
|
386 |
|
|
if(sizeof($required )) {
|
387 |
|
|
|
388 |
|
|
if(!isset($MESSAGE['MOD_FORM_REQUIRED_FIELDS'])) {
|
389 |
|
|
echo '<h3>You must enter details for the following fields</h3>';
|
390 |
1457
|
Luisehahne
|
} else {
|
391 |
1553
|
Luisehahne
|
echo '<h3>'.$MESSAGE['MOD_FORM_REQUIRED_FIELDS'].'</h3>';
|
392 |
1457
|
Luisehahne
|
}
|
393 |
1553
|
Luisehahne
|
echo '<ul>'.PHP_EOL;
|
394 |
1457
|
Luisehahne
|
foreach($required AS $field_title) {
|
395 |
1553
|
Luisehahne
|
echo '<li>'.$field_title.PHP_EOL;
|
396 |
1457
|
Luisehahne
|
}
|
397 |
|
|
if(isset($email_error)) {
|
398 |
1553
|
Luisehahne
|
echo '<li>'.$email_error.'</li>'.PHP_EOL;
|
399 |
1457
|
Luisehahne
|
}
|
400 |
|
|
if(isset($captcha_error)) {
|
401 |
1553
|
Luisehahne
|
echo '<li>'.$captcha_error.'</li>'.PHP_EOL;
|
402 |
1457
|
Luisehahne
|
}
|
403 |
1553
|
Luisehahne
|
// Create blank "required" array
|
404 |
|
|
$required = array();
|
405 |
|
|
echo '</ul>'.PHP_EOL;
|
406 |
|
|
echo '<p> </p>'.PHP_EOL.'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'.PHP_EOL;
|
407 |
1457
|
Luisehahne
|
} else {
|
408 |
|
|
if(isset($email_error)) {
|
409 |
1553
|
Luisehahne
|
echo '<br /><ul>'.PHP_EOL;
|
410 |
|
|
echo '<li>'.$email_error.'</li>'.PHP_EOL;
|
411 |
|
|
echo '</ul>'.PHP_EOL;
|
412 |
|
|
echo '<a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a>';
|
413 |
1457
|
Luisehahne
|
} elseif(isset($captcha_error)) {
|
414 |
1553
|
Luisehahne
|
echo '<br /><ul>'.PHP_EOL;
|
415 |
|
|
echo '<li>'.$captcha_error.'</li>'.PHP_EOL;
|
416 |
|
|
echo '</ul>'.PHP_EOL;
|
417 |
|
|
echo '<p> </p>'.PHP_EOL.'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'.PHP_EOL;
|
418 |
1457
|
Luisehahne
|
} else {
|
419 |
|
|
// Check how many times form has been submitted in last hour
|
420 |
|
|
$last_hour = time()-3600;
|
421 |
1553
|
Luisehahne
|
$sql = 'SELECT `submission_id` FROM `'.TABLE_PREFIX.'mod_form_submissions` ';
|
422 |
|
|
$sql .= 'WHERE `submitted_when` >= '.$last_hour.'';
|
423 |
|
|
$sql .= '';
|
424 |
|
|
if($query_submissions = $database->query($sql)){
|
425 |
|
|
if($query_submissions->numRows() > $max_submissions) {
|
426 |
|
|
// Too many submissions so far this hour
|
427 |
|
|
echo $MESSAGE['MOD_FORM_EXCESS_SUBMISSIONS'];
|
428 |
|
|
$success = false;
|
429 |
|
|
} else {
|
430 |
|
|
// Adding the IP to the body and try to send the email
|
431 |
|
|
// $email_body .= "\n\nIP: ".$_SERVER['REMOTE_ADDR'];
|
432 |
1594
|
Luisehahne
|
$iFormRequestId = isset($_POST['fri']) ? intval($_POST['fri']) : 0;
|
433 |
1590
|
darkviper
|
if($iFormRequestId) {
|
434 |
|
|
$email_body .= "\n\nFormRequestID: ".$iFormRequestId;
|
435 |
|
|
}
|
436 |
1553
|
Luisehahne
|
$recipient = preg_replace( "/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $email_fromname );
|
437 |
|
|
$email_fromname = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient );
|
438 |
|
|
$email_body = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $email_body );
|
439 |
|
|
if($email_to != '') {
|
440 |
|
|
if($email_from != '') {
|
441 |
1573
|
Luisehahne
|
if($wb->mail(SERVER_EMAIL,$email_to,$email_subject,$email_body,$email_fromname)) {
|
442 |
1553
|
Luisehahne
|
$success = true;
|
443 |
|
|
}
|
444 |
|
|
} else {
|
445 |
|
|
if($wb->mail('',$email_to,$email_subject,$email_body,$email_fromname)) {
|
446 |
|
|
$success = true;
|
447 |
|
|
}
|
448 |
|
|
}
|
449 |
|
|
}
|
450 |
1491
|
Luisehahne
|
|
451 |
1553
|
Luisehahne
|
$recipient = preg_replace( "/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $success_email_fromname );
|
452 |
|
|
$success_email_fromname = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient );
|
453 |
|
|
$success_email_text = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $success_email_text );
|
454 |
|
|
if($success_email_to != '') {
|
455 |
|
|
if($success_email_from != '') {
|
456 |
1579
|
Luisehahne
|
if($wb->mail(SERVER_EMAIL,$success_email_to,$success_email_subject,($success_email_text).$MOD_FORM['SUCCESS_EMAIL_TEXT_GENERATED'],$success_email_fromname)) {
|
457 |
1553
|
Luisehahne
|
$success = true;
|
458 |
|
|
}
|
459 |
|
|
} else {
|
460 |
1573
|
Luisehahne
|
if($wb->mail('',$success_email_to,$success_email_subject,($success_email_text).$MOD_FORM['SUCCESS_EMAIL_TEXT_GENERATED'],$success_email_fromname)) {
|
461 |
1553
|
Luisehahne
|
$success = true;
|
462 |
|
|
}
|
463 |
1457
|
Luisehahne
|
}
|
464 |
|
|
}
|
465 |
1553
|
Luisehahne
|
|
466 |
|
|
// Write submission to database
|
467 |
|
|
if(isset($admin) AND $admin->is_authenticated() AND $admin->get_user_id() > 0) {
|
468 |
|
|
$submitted_by = $admin->get_user_id();
|
469 |
1457
|
Luisehahne
|
} else {
|
470 |
1553
|
Luisehahne
|
$submitted_by = 0;
|
471 |
1457
|
Luisehahne
|
}
|
472 |
1553
|
Luisehahne
|
$email_body = htmlspecialchars($wb->add_slashes($email_body));
|
473 |
|
|
$sql = 'INSERT INTO '.TABLE_PREFIX.'mod_form_submissions ';
|
474 |
|
|
$sql .= 'SET ';
|
475 |
|
|
$sql .= 'page_id='.$wb->page_id.',';
|
476 |
|
|
$sql .= 'section_id='.$section_id.',';
|
477 |
|
|
$sql .= 'submitted_when='.time().',';
|
478 |
|
|
$sql .= 'submitted_by=\''.$submitted_by.'\', ';
|
479 |
|
|
$sql .= 'body=\''.$email_body.'\' ';
|
480 |
|
|
if($database->query($sql)) {
|
481 |
1584
|
Luisehahne
|
|
482 |
|
|
if(!$database->is_error()) {
|
483 |
|
|
$success = true;
|
484 |
|
|
}
|
485 |
1553
|
Luisehahne
|
// Make sure submissions table isn't too full
|
486 |
|
|
$query_submissions = $database->query("SELECT submission_id FROM ".TABLE_PREFIX."mod_form_submissions ORDER BY submitted_when");
|
487 |
|
|
$num_submissions = $query_submissions->numRows();
|
488 |
|
|
if($num_submissions > $stored_submissions) {
|
489 |
|
|
// Remove excess submission
|
490 |
|
|
$num_to_remove = $num_submissions-$stored_submissions;
|
491 |
|
|
while($submission = $query_submissions->fetchRow(MYSQL_ASSOC)) {
|
492 |
|
|
if($num_to_remove > 0) {
|
493 |
|
|
$submission_id = $submission['submission_id'];
|
494 |
|
|
$database->query("DELETE FROM ".TABLE_PREFIX."mod_form_submissions WHERE submission_id = '$submission_id'");
|
495 |
|
|
$num_to_remove = $num_to_remove-1;
|
496 |
|
|
}
|
497 |
1457
|
Luisehahne
|
}
|
498 |
|
|
}
|
499 |
1553
|
Luisehahne
|
} // numRows
|
500 |
|
|
}
|
501 |
|
|
}
|
502 |
|
|
}
|
503 |
|
|
} // email_error
|
504 |
|
|
} else {
|
505 |
|
|
|
506 |
|
|
echo '<p> </p>'.PHP_EOL.'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'.PHP_EOL;
|
507 |
1457
|
Luisehahne
|
}
|
508 |
1553
|
Luisehahne
|
|
509 |
1457
|
Luisehahne
|
// Now check if the email was sent successfully
|
510 |
|
|
if(isset($success) AND $success == true) {
|
511 |
|
|
if ($success_page=='none') {
|
512 |
1573
|
Luisehahne
|
echo str_replace("\n","<br />",($success_email_text));
|
513 |
|
|
echo '<p> </p>'.PHP_EOL.'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'.PHP_EOL;
|
514 |
1457
|
Luisehahne
|
} else {
|
515 |
|
|
$query_menu = $database->query("SELECT link,target FROM ".TABLE_PREFIX."pages WHERE `page_id` = '$success_page'");
|
516 |
|
|
if($query_menu->numRows() > 0) {
|
517 |
1553
|
Luisehahne
|
$fetch_settings = $query_menu->fetchRow(MYSQL_ASSOC);
|
518 |
1457
|
Luisehahne
|
$link = WB_URL.PAGES_DIRECTORY.$fetch_settings['link'].PAGE_EXTENSION;
|
519 |
|
|
echo "<script type='text/javascript'>location.href='".$link."';</script>";
|
520 |
1553
|
Luisehahne
|
}
|
521 |
1457
|
Luisehahne
|
}
|
522 |
|
|
// clearing session on success
|
523 |
|
|
$query_fields = $database->query("SELECT field_id FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id'");
|
524 |
1553
|
Luisehahne
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
525 |
|
|
$field_id = $field['field_id'];
|
526 |
1457
|
Luisehahne
|
if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
|
527 |
|
|
}
|
528 |
|
|
} else {
|
529 |
|
|
if(isset($success) AND $success == false) {
|
530 |
|
|
echo $TEXT['ERROR'];
|
531 |
|
|
}
|
532 |
|
|
}
|
533 |
1553
|
Luisehahne
|
|
534 |
1590
|
darkviper
|
}
|