| 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 |
|
|
$label_id = 'wb_'.preg_replace('/[^a-z0-1]/i', '_', $key).$field_id;
|
| 79 |
|
|
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 |
|
|
$label_id = 'wb_'.preg_replace('/[^a-z0-1]/i', '_', $n).$field_id;
|
| 93 |
|
|
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 |
|
|
<?php // echo $admin->getFTAN(); ?>
|
| 158 |
|
|
<?php
|
| 159 |
|
|
if(ENABLED_ASP) { // first add some honeypot-fields
|
| 160 |
|
|
?>
|
| 161 |
|
|
<input type="hidden" name="submitted_when" value="<?php $t=time(); echo $t; $_SESSION['submitted_when']=$t; ?>" />
|
| 162 |
|
|
<p class="frm-nixhier">
|
| 163 |
|
|
email address:
|
| 164 |
|
|
<label for="email">Leave this field email-address blank:</label>
|
| 165 |
|
|
<input id="email" name="email" size="56" value="" /><br />
|
| 166 |
|
|
Homepage:
|
| 167 |
|
|
<label for="homepage">Leave this field homepage blank:</label>
|
| 168 |
|
|
<input id="homepage" name="homepage" size="55" value="" /><br />
|
| 169 |
|
|
URL:
|
| 170 |
|
|
<label for="url">Leave this field url blank:</label>
|
| 171 |
|
|
<input id="url" name="url" size="61" value="" /><br />
|
| 172 |
|
|
Comment:
|
| 173 |
|
|
<label for="comment">Leave this field comment blank:</label>
|
| 174 |
|
|
<textarea id="comment" name="comment" cols="50" rows="10"></textarea><br />
|
| 175 |
|
|
</p>
|
| 176 |
|
|
<?php }
|
| 177 |
1457
|
Luisehahne
|
|
| 178 |
1553
|
Luisehahne
|
// Print header MYSQL_ASSOC
|
| 179 |
|
|
echo $header.PHP_EOL;
|
| 180 |
|
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
| 181 |
|
|
// Set field values
|
| 182 |
|
|
$field_id = $field['field_id'];
|
| 183 |
|
|
$value = $field['value'];
|
| 184 |
|
|
// Print field_loop after replacing vars with values
|
| 185 |
|
|
$vars = array('{TITLE}', '{REQUIRED}');
|
| 186 |
|
|
if (($field['type'] == "radio") || ($field['type'] == "checkbox")) {
|
| 187 |
|
|
$field_title = $field['title'];
|
| 188 |
|
|
} else {
|
| 189 |
|
|
$field_title = '<label for="field'.$field_id.'">'.$field['title'].'</label>'.PHP_EOL;
|
| 190 |
|
|
}
|
| 191 |
|
|
$values = array($field_title);
|
| 192 |
|
|
if ($field['required'] == 1) {
|
| 193 |
|
|
$values[] = '<span class="frm-required">*</span>'.PHP_EOL;
|
| 194 |
|
|
} else {
|
| 195 |
|
|
$values[] = '';
|
| 196 |
|
|
}
|
| 197 |
|
|
if($field['type'] == 'textfield') {
|
| 198 |
|
|
$vars[] = '{FIELD}';
|
| 199 |
|
|
$max_lenght_para = (intval($field['extra']) ? ' maxlenght="'.intval($field['extra']).'"' : '');
|
| 200 |
|
|
$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;
|
| 201 |
|
|
} elseif($field['type'] == 'textarea') {
|
| 202 |
|
|
$vars[] = '{FIELD}';
|
| 203 |
|
|
$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;
|
| 204 |
|
|
} elseif($field['type'] == 'select') {
|
| 205 |
|
|
$vars[] = '{FIELD}';
|
| 206 |
|
|
$options = explode(',', $value);
|
| 207 |
|
|
array_walk($options, 'make_option', (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array()));
|
| 208 |
|
|
$field['extra'] = explode(',',$field['extra']);
|
| 209 |
|
|
$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;
|
| 210 |
|
|
} elseif($field['type'] == 'heading') {
|
| 211 |
|
|
$vars[] = '{FIELD}';
|
| 212 |
|
|
$str = '<input type="hidden" name="field'.$field_id.'" id="field'.$field_id.'" value="===['.$field['title'].']===" />';
|
| 213 |
|
|
$values[] = ( true == $use_xhtml_strict) ? "<div>".$str."</div>" : $str;
|
| 214 |
|
|
$tmp_field_loop = $field_loop; // temporarily modify the field loop template
|
| 215 |
|
|
$field_loop = $field['extra'];
|
| 216 |
|
|
} elseif($field['type'] == 'checkbox') {
|
| 217 |
|
|
$vars[] = '{FIELD}';
|
| 218 |
|
|
$options = explode(',', $value);
|
| 219 |
|
|
array_walk($options, 'make_checkbox', array(array($field_id,$field['extra']),(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array())));
|
| 220 |
|
|
$x = sizeof($options)-1;
|
| 221 |
|
|
$options[$x]=substr($options[$x],0,strlen($options[$x]));
|
| 222 |
|
|
$values[] = implode($options);
|
| 223 |
|
|
} elseif($field['type'] == 'radio') {
|
| 224 |
|
|
$vars[] = '{FIELD}';
|
| 225 |
|
|
$options = explode(',', $value);
|
| 226 |
|
|
array_walk($options, 'make_radio', array($field_id,$field['title'],$field['extra'], (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:'')));
|
| 227 |
|
|
$x = sizeof($options)-1;
|
| 228 |
|
|
$options[$x]=substr($options[$x],0,strlen($options[$x]));
|
| 229 |
|
|
$values[] = implode($options);
|
| 230 |
|
|
} elseif($field['type'] == 'email') {
|
| 231 |
|
|
$vars[] = '{FIELD}';
|
| 232 |
|
|
$max_lenght_para = (intval($field['extra']) ? ' maxlenght="'.intval($field['extra']).'"' : '');
|
| 233 |
|
|
$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;
|
| 234 |
|
|
}
|
| 235 |
|
|
if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
|
| 236 |
|
|
if($field['type'] != '') {
|
| 237 |
|
|
echo str_replace($vars, $values, $field_loop);
|
| 238 |
|
|
}
|
| 239 |
|
|
if (isset($tmp_field_loop)){ $field_loop = $tmp_field_loop; }
|
| 240 |
|
|
}
|
| 241 |
|
|
// Captcha
|
| 242 |
|
|
if($use_captcha) { ?>
|
| 243 |
|
|
<tr>
|
| 244 |
|
|
<td class="frm-field_title"><?php echo $TEXT['VERIFICATION']; ?>:</td>
|
| 245 |
|
|
<td><?php call_captcha(); ?></td>
|
| 246 |
|
|
</tr>
|
| 247 |
|
|
<?php
|
| 248 |
|
|
}
|
| 249 |
|
|
// Print footer
|
| 250 |
|
|
// $out = $footer.PHP_EOL;
|
| 251 |
|
|
$out .= str_replace('{SUBMIT_FORM}', $MOD_FORM['SUBMIT_FORM'], $footer);
|
| 252 |
|
|
echo $out;
|
| 253 |
1457
|
Luisehahne
|
// Add form end code
|
| 254 |
|
|
?>
|
| 255 |
|
|
</form>
|
| 256 |
|
|
<?php
|
| 257 |
1553
|
Luisehahne
|
}
|
| 258 |
|
|
}
|
| 259 |
1457
|
Luisehahne
|
|
| 260 |
|
|
} else {
|
| 261 |
|
|
|
| 262 |
|
|
// Check that submission ID matches
|
| 263 |
|
|
if(isset($_SESSION['form_submission_id']) AND isset($_POST['submission_id']) AND $_SESSION['form_submission_id'] == $_POST['submission_id']) {
|
| 264 |
1553
|
Luisehahne
|
|
| 265 |
1457
|
Luisehahne
|
// Set new submission ID in session
|
| 266 |
|
|
$_SESSION['form_submission_id'] = new_submission_id();
|
| 267 |
1553
|
Luisehahne
|
|
| 268 |
1457
|
Luisehahne
|
if(ENABLED_ASP && ( // form faked? Check the honeypot-fields.
|
| 269 |
1553
|
Luisehahne
|
(!isset($_POST['submitted_when']) OR !isset($_SESSION['submitted_when'])) OR
|
| 270 |
1457
|
Luisehahne
|
($_POST['submitted_when'] != $_SESSION['submitted_when']) OR
|
| 271 |
|
|
(!isset($_POST['email']) OR $_POST['email']) OR
|
| 272 |
|
|
(!isset($_POST['homepage']) OR $_POST['homepage']) OR
|
| 273 |
|
|
(!isset($_POST['comment']) OR $_POST['comment']) OR
|
| 274 |
|
|
(!isset($_POST['url']) OR $_POST['url'])
|
| 275 |
|
|
)) {
|
| 276 |
1553
|
Luisehahne
|
// spam
|
| 277 |
|
|
header("Location: ".WB_URL.PAGES_DIRECTORY."");
|
| 278 |
|
|
exit();
|
| 279 |
1457
|
Luisehahne
|
}
|
| 280 |
|
|
// Submit form data
|
| 281 |
|
|
// First start message settings
|
| 282 |
1553
|
Luisehahne
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_settings` ';
|
| 283 |
|
|
$sql .= 'WHERE `section_id` = '.(int)$section_id.'';
|
| 284 |
|
|
if($query_settings = $database->query($sql) ) {
|
| 285 |
|
|
if($query_settings->numRows() > 0) {
|
| 286 |
|
|
$fetch_settings = $query_settings->fetchRow(MYSQL_ASSOC);
|
| 287 |
|
|
|
| 288 |
1573
|
Luisehahne
|
// $email_to = $fetch_settings['email_to'];
|
| 289 |
|
|
$email_to = (($fetch_settings['email_to'] != '') ? $fetch_settings['email_to'] : emailAdmin());
|
| 290 |
1553
|
Luisehahne
|
$email_from = $fetch_settings['email_from'];
|
| 291 |
|
|
if(substr($email_from, 0, 5) == 'field') {
|
| 292 |
|
|
// Set the email from field to what the user entered in the specified field
|
| 293 |
|
|
$email_from = htmlspecialchars($wb->add_slashes($_POST[$email_from]));
|
| 294 |
|
|
}
|
| 295 |
|
|
$email_fromname = $fetch_settings['email_fromname'];
|
| 296 |
|
|
if(substr($email_fromname, 0, 5) == 'field') {
|
| 297 |
|
|
// Set the email_fromname to field to what the user entered in the specified field
|
| 298 |
|
|
$email_fromname = htmlspecialchars($wb->add_slashes($_POST[$email_fromname]));
|
| 299 |
|
|
}
|
| 300 |
1573
|
Luisehahne
|
$email_subject = (($fetch_settings['email_subject'] != '') ? $fetch_settings['email_subject'] : $MOD_FORM['EMAIL_SUBJECT']);
|
| 301 |
1553
|
Luisehahne
|
$success_page = $fetch_settings['success_page'];
|
| 302 |
1573
|
Luisehahne
|
$success_email_to = (($fetch_settings['success_email_to'] != '') ? $fetch_settings['success_email_to'] : '');
|
| 303 |
1553
|
Luisehahne
|
if(substr($success_email_to, 0, 5) == 'field') {
|
| 304 |
|
|
// Set the success_email to field to what the user entered in the specified field
|
| 305 |
|
|
$success_email_to = htmlspecialchars($wb->add_slashes($_POST[$success_email_to]));
|
| 306 |
|
|
}
|
| 307 |
|
|
$success_email_from = $fetch_settings['success_email_from'];
|
| 308 |
|
|
$success_email_fromname = $fetch_settings['success_email_fromname'];
|
| 309 |
|
|
$success_email_text = htmlspecialchars($wb->add_slashes($fetch_settings['success_email_text']));
|
| 310 |
|
|
$success_email_text = (($success_email_text != '') ? $success_email_text : $MOD_FORM['SUCCESS_EMAIL_TEXT']);
|
| 311 |
1573
|
Luisehahne
|
$success_email_subject = (($fetch_settings['success_email_subject'] != '') ? $fetch_settings['success_email_subject'] : $MOD_FORM['SUCCESS_EMAIL_SUBJECT']);
|
| 312 |
1553
|
Luisehahne
|
$max_submissions = $fetch_settings['max_submissions'];
|
| 313 |
|
|
$stored_submissions = $fetch_settings['stored_submissions'];
|
| 314 |
|
|
$use_captcha = $fetch_settings['use_captcha'];
|
| 315 |
|
|
} else {
|
| 316 |
|
|
exit($TEXT['UNDER_CONSTRUCTION']);
|
| 317 |
1457
|
Luisehahne
|
}
|
| 318 |
|
|
}
|
| 319 |
|
|
$email_body = '';
|
| 320 |
1553
|
Luisehahne
|
|
| 321 |
1457
|
Luisehahne
|
// Create blank "required" array
|
| 322 |
|
|
$required = array();
|
| 323 |
1553
|
Luisehahne
|
|
| 324 |
1457
|
Luisehahne
|
// Captcha
|
| 325 |
|
|
if($use_captcha) {
|
| 326 |
|
|
if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
|
| 327 |
1573
|
Luisehahne
|
// Check for a mismatch get email user_id
|
| 328 |
1457
|
Luisehahne
|
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
|
| 329 |
1573
|
Luisehahne
|
$replace = array('webmaster_email' => emailAdmin() );
|
| 330 |
1575
|
Luisehahne
|
$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'], $replace);
|
| 331 |
1457
|
Luisehahne
|
}
|
| 332 |
|
|
} else {
|
| 333 |
1573
|
Luisehahne
|
$replace = array('webmaster_email'=>emailAdmin() );
|
| 334 |
|
|
$captcha_error = replace_vars($MOD_FORM['INCORRECT_CAPTCHA'],$replace );
|
| 335 |
1457
|
Luisehahne
|
}
|
| 336 |
|
|
}
|
| 337 |
|
|
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
|
| 338 |
|
|
|
| 339 |
|
|
// Loop through fields and add to message body
|
| 340 |
|
|
// Get list of fields
|
| 341 |
1553
|
Luisehahne
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_fields` ';
|
| 342 |
|
|
$sql .= 'WHERE `section_id` = '.(int)$section_id.' ';
|
| 343 |
|
|
$sql .= 'ORDER BY position ASC';
|
| 344 |
|
|
if($query_fields = $database->query($sql)) {
|
| 345 |
|
|
if($query_fields->numRows() > 0) {
|
| 346 |
|
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
| 347 |
|
|
// Add to message body
|
| 348 |
|
|
if($field['type'] != '') {
|
| 349 |
|
|
if(!empty($_POST['field'.$field['field_id']])) {
|
| 350 |
|
|
// do not allow droplets in user input!
|
| 351 |
|
|
if (is_array($_POST['field'.$field['field_id']])) {
|
| 352 |
|
|
$_SESSION['field'.$field['field_id']] = str_replace(array("[[", "]]"), array("[[", "]]"), $_POST['field'.$field['field_id']]);
|
| 353 |
|
|
} else {
|
| 354 |
|
|
$_SESSION['field'.$field['field_id']] = str_replace(array("[[", "]]"), array("[[", "]]"), htmlspecialchars($_POST['field'.$field['field_id']]));
|
| 355 |
1457
|
Luisehahne
|
}
|
| 356 |
1553
|
Luisehahne
|
if($field['type'] == 'email' AND $admin->validate_email($_POST['field'.$field['field_id']]) == false) {
|
| 357 |
1573
|
Luisehahne
|
$email_error = $MESSAGE['USERS_INVALID_EMAIL'];
|
| 358 |
1553
|
Luisehahne
|
}
|
| 359 |
|
|
if($field['type'] == 'heading') {
|
| 360 |
|
|
$email_body .= $_POST['field'.$field['field_id']]."\n\n";
|
| 361 |
|
|
} elseif (!is_array($_POST['field'.$field['field_id']])) {
|
| 362 |
|
|
$email_body .= $field['title'].': '.$_POST['field'.$field['field_id']]."\n\n";
|
| 363 |
|
|
} else {
|
| 364 |
|
|
$email_body .= $field['title'].": \n";
|
| 365 |
|
|
foreach ($_POST['field'.$field['field_id']] as $k=>$v) {
|
| 366 |
|
|
$email_body .= $v."\n";
|
| 367 |
|
|
}
|
| 368 |
|
|
$email_body .= "\n";
|
| 369 |
|
|
}
|
| 370 |
|
|
} elseif($field['required'] == 1) {
|
| 371 |
|
|
$required[] = $field['title'];
|
| 372 |
1457
|
Luisehahne
|
}
|
| 373 |
|
|
}
|
| 374 |
1553
|
Luisehahne
|
} // while
|
| 375 |
|
|
} // numRows
|
| 376 |
|
|
} // query
|
| 377 |
|
|
// Check if the user forgot to enter values into all the required fields
|
| 378 |
|
|
if(sizeof($required )) {
|
| 379 |
|
|
|
| 380 |
|
|
if(!isset($MESSAGE['MOD_FORM_REQUIRED_FIELDS'])) {
|
| 381 |
|
|
echo '<h3>You must enter details for the following fields</h3>';
|
| 382 |
1457
|
Luisehahne
|
} else {
|
| 383 |
1553
|
Luisehahne
|
echo '<h3>'.$MESSAGE['MOD_FORM_REQUIRED_FIELDS'].'</h3>';
|
| 384 |
1457
|
Luisehahne
|
}
|
| 385 |
1553
|
Luisehahne
|
echo '<ul>'.PHP_EOL;
|
| 386 |
1457
|
Luisehahne
|
foreach($required AS $field_title) {
|
| 387 |
1553
|
Luisehahne
|
echo '<li>'.$field_title.PHP_EOL;
|
| 388 |
1457
|
Luisehahne
|
}
|
| 389 |
|
|
if(isset($email_error)) {
|
| 390 |
1553
|
Luisehahne
|
echo '<li>'.$email_error.'</li>'.PHP_EOL;
|
| 391 |
1457
|
Luisehahne
|
}
|
| 392 |
|
|
if(isset($captcha_error)) {
|
| 393 |
1553
|
Luisehahne
|
echo '<li>'.$captcha_error.'</li>'.PHP_EOL;
|
| 394 |
1457
|
Luisehahne
|
}
|
| 395 |
1553
|
Luisehahne
|
// Create blank "required" array
|
| 396 |
|
|
$required = array();
|
| 397 |
|
|
echo '</ul>'.PHP_EOL;
|
| 398 |
|
|
echo '<p> </p>'.PHP_EOL.'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'.PHP_EOL;
|
| 399 |
1457
|
Luisehahne
|
} else {
|
| 400 |
|
|
if(isset($email_error)) {
|
| 401 |
1553
|
Luisehahne
|
echo '<br /><ul>'.PHP_EOL;
|
| 402 |
|
|
echo '<li>'.$email_error.'</li>'.PHP_EOL;
|
| 403 |
|
|
echo '</ul>'.PHP_EOL;
|
| 404 |
|
|
echo '<a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a>';
|
| 405 |
1457
|
Luisehahne
|
} elseif(isset($captcha_error)) {
|
| 406 |
1553
|
Luisehahne
|
echo '<br /><ul>'.PHP_EOL;
|
| 407 |
|
|
echo '<li>'.$captcha_error.'</li>'.PHP_EOL;
|
| 408 |
|
|
echo '</ul>'.PHP_EOL;
|
| 409 |
|
|
echo '<p> </p>'.PHP_EOL.'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'.PHP_EOL;
|
| 410 |
1457
|
Luisehahne
|
} else {
|
| 411 |
|
|
// Check how many times form has been submitted in last hour
|
| 412 |
|
|
$last_hour = time()-3600;
|
| 413 |
1553
|
Luisehahne
|
$sql = 'SELECT `submission_id` FROM `'.TABLE_PREFIX.'mod_form_submissions` ';
|
| 414 |
|
|
$sql .= 'WHERE `submitted_when` >= '.$last_hour.'';
|
| 415 |
|
|
$sql .= '';
|
| 416 |
|
|
if($query_submissions = $database->query($sql)){
|
| 417 |
|
|
if($query_submissions->numRows() > $max_submissions) {
|
| 418 |
|
|
// Too many submissions so far this hour
|
| 419 |
|
|
echo $MESSAGE['MOD_FORM_EXCESS_SUBMISSIONS'];
|
| 420 |
|
|
$success = false;
|
| 421 |
|
|
} else {
|
| 422 |
|
|
// Adding the IP to the body and try to send the email
|
| 423 |
|
|
// $email_body .= "\n\nIP: ".$_SERVER['REMOTE_ADDR'];
|
| 424 |
1573
|
Luisehahne
|
|
| 425 |
1553
|
Luisehahne
|
$recipient = preg_replace( "/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $email_fromname );
|
| 426 |
|
|
$email_fromname = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient );
|
| 427 |
|
|
$email_body = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $email_body );
|
| 428 |
|
|
if($email_to != '') {
|
| 429 |
|
|
if($email_from != '') {
|
| 430 |
1573
|
Luisehahne
|
if($wb->mail(SERVER_EMAIL,$email_to,$email_subject,$email_body,$email_fromname)) {
|
| 431 |
1553
|
Luisehahne
|
$success = true;
|
| 432 |
|
|
}
|
| 433 |
|
|
} else {
|
| 434 |
|
|
if($wb->mail('',$email_to,$email_subject,$email_body,$email_fromname)) {
|
| 435 |
|
|
$success = true;
|
| 436 |
|
|
}
|
| 437 |
|
|
}
|
| 438 |
|
|
}
|
| 439 |
1491
|
Luisehahne
|
|
| 440 |
1553
|
Luisehahne
|
$recipient = preg_replace( "/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $success_email_fromname );
|
| 441 |
|
|
$success_email_fromname = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient );
|
| 442 |
|
|
$success_email_text = preg_replace( "/(content-type:|bcc:|cc:|to:|from:)/im", "", $success_email_text );
|
| 443 |
|
|
if($success_email_to != '') {
|
| 444 |
|
|
if($success_email_from != '') {
|
| 445 |
1573
|
Luisehahne
|
if($wb->mail($success_email_from,$success_email_to,$success_email_subject,($success_email_text).$MOD_FORM['SUCCESS_EMAIL_TEXT_GENERATED'],$success_email_fromname)) {
|
| 446 |
1553
|
Luisehahne
|
$success = true;
|
| 447 |
|
|
}
|
| 448 |
|
|
} else {
|
| 449 |
1573
|
Luisehahne
|
if($wb->mail('',$success_email_to,$success_email_subject,($success_email_text).$MOD_FORM['SUCCESS_EMAIL_TEXT_GENERATED'],$success_email_fromname)) {
|
| 450 |
1553
|
Luisehahne
|
$success = true;
|
| 451 |
|
|
}
|
| 452 |
1457
|
Luisehahne
|
}
|
| 453 |
|
|
}
|
| 454 |
1553
|
Luisehahne
|
|
| 455 |
|
|
// Write submission to database
|
| 456 |
|
|
if(isset($admin) AND $admin->is_authenticated() AND $admin->get_user_id() > 0) {
|
| 457 |
|
|
$submitted_by = $admin->get_user_id();
|
| 458 |
1457
|
Luisehahne
|
} else {
|
| 459 |
1553
|
Luisehahne
|
$submitted_by = 0;
|
| 460 |
1457
|
Luisehahne
|
}
|
| 461 |
1553
|
Luisehahne
|
$email_body = htmlspecialchars($wb->add_slashes($email_body));
|
| 462 |
|
|
$sql = 'INSERT INTO '.TABLE_PREFIX.'mod_form_submissions ';
|
| 463 |
|
|
$sql .= 'SET ';
|
| 464 |
|
|
$sql .= 'page_id='.$wb->page_id.',';
|
| 465 |
|
|
$sql .= 'section_id='.$section_id.',';
|
| 466 |
|
|
$sql .= 'submitted_when='.time().',';
|
| 467 |
|
|
$sql .= 'submitted_by=\''.$submitted_by.'\', ';
|
| 468 |
|
|
$sql .= 'body=\''.$email_body.'\' ';
|
| 469 |
|
|
if($database->query($sql)) {
|
| 470 |
|
|
/*
|
| 471 |
|
|
// Make sure submissions table isn't too full
|
| 472 |
|
|
$query_submissions = $database->query("SELECT submission_id FROM ".TABLE_PREFIX."mod_form_submissions ORDER BY submitted_when");
|
| 473 |
|
|
$num_submissions = $query_submissions->numRows();
|
| 474 |
|
|
if($num_submissions > $stored_submissions) {
|
| 475 |
|
|
// Remove excess submission
|
| 476 |
|
|
$num_to_remove = $num_submissions-$stored_submissions;
|
| 477 |
|
|
while($submission = $query_submissions->fetchRow(MYSQL_ASSOC)) {
|
| 478 |
|
|
if($num_to_remove > 0) {
|
| 479 |
|
|
$submission_id = $submission['submission_id'];
|
| 480 |
|
|
$database->query("DELETE FROM ".TABLE_PREFIX."mod_form_submissions WHERE submission_id = '$submission_id'");
|
| 481 |
|
|
$num_to_remove = $num_to_remove-1;
|
| 482 |
|
|
}
|
| 483 |
1457
|
Luisehahne
|
}
|
| 484 |
|
|
}
|
| 485 |
1553
|
Luisehahne
|
*/
|
| 486 |
|
|
if(!$database->is_error()) {
|
| 487 |
|
|
$success = true;
|
| 488 |
|
|
}
|
| 489 |
|
|
} // numRows
|
| 490 |
|
|
}
|
| 491 |
|
|
}
|
| 492 |
|
|
}
|
| 493 |
|
|
} // email_error
|
| 494 |
|
|
} else {
|
| 495 |
|
|
|
| 496 |
|
|
echo '<p> </p>'.PHP_EOL.'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'.PHP_EOL;
|
| 497 |
1457
|
Luisehahne
|
}
|
| 498 |
1553
|
Luisehahne
|
|
| 499 |
1457
|
Luisehahne
|
// Now check if the email was sent successfully
|
| 500 |
|
|
if(isset($success) AND $success == true) {
|
| 501 |
|
|
if ($success_page=='none') {
|
| 502 |
1573
|
Luisehahne
|
echo str_replace("\n","<br />",($success_email_text));
|
| 503 |
|
|
echo '<p> </p>'.PHP_EOL.'<p><a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.$TEXT['BACK'].'</a></p>'.PHP_EOL;
|
| 504 |
1457
|
Luisehahne
|
} else {
|
| 505 |
|
|
$query_menu = $database->query("SELECT link,target FROM ".TABLE_PREFIX."pages WHERE `page_id` = '$success_page'");
|
| 506 |
|
|
if($query_menu->numRows() > 0) {
|
| 507 |
1553
|
Luisehahne
|
$fetch_settings = $query_menu->fetchRow(MYSQL_ASSOC);
|
| 508 |
1457
|
Luisehahne
|
$link = WB_URL.PAGES_DIRECTORY.$fetch_settings['link'].PAGE_EXTENSION;
|
| 509 |
|
|
echo "<script type='text/javascript'>location.href='".$link."';</script>";
|
| 510 |
1553
|
Luisehahne
|
}
|
| 511 |
1457
|
Luisehahne
|
}
|
| 512 |
|
|
// clearing session on success
|
| 513 |
|
|
$query_fields = $database->query("SELECT field_id FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id'");
|
| 514 |
1553
|
Luisehahne
|
while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
|
| 515 |
|
|
$field_id = $field['field_id'];
|
| 516 |
1457
|
Luisehahne
|
if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
|
| 517 |
|
|
}
|
| 518 |
|
|
} else {
|
| 519 |
|
|
if(isset($success) AND $success == false) {
|
| 520 |
|
|
echo $TEXT['ERROR'];
|
| 521 |
|
|
}
|
| 522 |
|
|
}
|
| 523 |
1553
|
Luisehahne
|
|
| 524 |
1457
|
Luisehahne
|
}
|