Project

General

Profile

« Previous | Next » 

Revision 298

Added by stefan almost 19 years ago

/modules/form/modify_settings.php
  • ticket 118 - line 89, added formfield type to check for email/text
    /modules/form/save_settings.php
  • ticket 115 - line 66, changed comparision
    /modules/form/view.php
  • ticket 115 - line 311, added correct timecheck
  • ticket 86 - line 320?, changed mail to wb_mail (from field will be checked by wb_mail
  • ticket 107 - line 195, changed captcha.php call to include timestamp

View differences:

trunk/wb/modules/form/modify_settings.php
1 1
<?php
2 2

  
3 3
// $Id$
4

  
4

  
5 5
/*
6 6

  
7 7
 Website Baker Project <http://www.websitebaker.org/>
......
27 27
The Website Baker Project would like to thank Rudolph Lartey <www.carbonect.com>
28 28
for his contributions to this module - adding extra field types
29 29
*/
30

  
31
require('../../config.php');
32

  
33
// Include WB admin wrapper script
34
require(WB_PATH.'/modules/admin.php');
35

  
36
// Get header and footer
37
$query_content = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
38
$setting = $query_content->fetchRow();
39

  
40
// Set raw html <'s and >'s to be replace by friendly html code
41
$raw = array('<', '>');
42
$friendly = array('&lt;', '&gt;');
43

  
44
?>
45

  
46
<style type="text/css">
47
.setting_name {
48
	vertical-align: top;
49
}
50
</style>
51

  
52
<form name="edit" action="<?php echo WB_URL; ?>/modules/form/save_settings.php" method="post" style="margin: 0;">
53

  
54
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
55
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
56

  
57
<table cellpadding="2" cellspacing="0" border="0" width="100%">
58
<tr>
59
	<td class="setting_name" width="220"><?php echo $TEXT['HEADER']; ?>:</td>
60
	<td class="setting_name">
61
		<textarea name="header" style="width: 100%; height: 80px;"><?php echo ($setting['header']); ?></textarea>
62
	</td>
63
</tr>
64
<tr>
65
	<td class="setting_name"><?php echo $TEXT['FIELD'].' '.$TEXT['LOOP']; ?>:</td>
66
	<td class="setting_name">
67
		<textarea name="field_loop" style="width: 100%; height: 60px;"><?php echo ($setting['field_loop']); ?></textarea>
68
	</td>
69
</tr>
70
<tr>
71
	<td class="setting_name"><?php echo $TEXT['FOOTER']; ?>:</td>
72
	<td class="setting_name">
73
		<textarea name="footer" style="width: 100%; height: 80px;"><?php echo str_replace($raw, $friendly, ($setting['footer'])); ?></textarea>
74
	</td>
75
</tr>
76
<tr>
77
	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['TO']; ?>:</td>
78
	<td class="setting_name">
79
		<textarea name="email_to" style="width: 100%; height: 30px;"><?php echo str_replace($raw, $friendly, ($setting['email_to'])); ?></textarea>
80
	</td>
81
</tr>
82
<tr>
83
	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['FROM']; ?>:</td>
30

  
31
require('../../config.php');
32

  
33
// Include WB admin wrapper script
34
require(WB_PATH.'/modules/admin.php');
35

  
36
// Get header and footer
37
$query_content = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
38
$setting = $query_content->fetchRow();
39

  
40
// Set raw html <'s and >'s to be replace by friendly html code
41
$raw = array('<', '>');
42
$friendly = array('&lt;', '&gt;');
43

  
44
?>
45

  
46
<style type="text/css">
47
.setting_name {
48
	vertical-align: top;
49
}
50
</style>
51

  
52
<form name="edit" action="<?php echo WB_URL; ?>/modules/form/save_settings.php" method="post" style="margin: 0;">
53

  
54
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
55
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
56

  
57
<table cellpadding="2" cellspacing="0" border="0" width="100%">
58
<tr>
59
	<td class="setting_name" width="220"><?php echo $TEXT['HEADER']; ?>:</td>
84 60
	<td class="setting_name">
61
		<textarea name="header" style="width: 100%; height: 80px;"><?php echo ($setting['header']); ?></textarea>
62
	</td>
63
</tr>
64
<tr>
65
	<td class="setting_name"><?php echo $TEXT['FIELD'].' '.$TEXT['LOOP']; ?>:</td>
66
	<td class="setting_name">
67
		<textarea name="field_loop" style="width: 100%; height: 60px;"><?php echo ($setting['field_loop']); ?></textarea>
68
	</td>
69
</tr>
70
<tr>
71
	<td class="setting_name"><?php echo $TEXT['FOOTER']; ?>:</td>
72
	<td class="setting_name">
73
		<textarea name="footer" style="width: 100%; height: 80px;"><?php echo str_replace($raw, $friendly, ($setting['footer'])); ?></textarea>
74
	</td>
75
</tr>
76
<tr>
77
	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['TO']; ?>:</td>
78
	<td class="setting_name">
79
		<textarea name="email_to" style="width: 100%; height: 30px;"><?php echo str_replace($raw, $friendly, ($setting['email_to'])); ?></textarea>
80
	</td>
81
</tr>
82
<tr>
83
	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['FROM']; ?>:</td>
84
	<td class="setting_name">
85 85
		<select name="email_from_field" style="width: 100%;">
86 86
			<option value="" onclick="javascript: document.getElementById('email_from').style.display = 'block';"><?php echo $TEXT['CUSTOM']; ?>:</option>
87 87
			<?php
88 88
			$email_from_value = str_replace($raw, $friendly, ($setting['email_from']));
89
			$query_email_fields = $database->query("SELECT field_id,title FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
89
			$query_email_fields = $database->query("SELECT field_id,title FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' AND ( type = 'textfield' OR  type = 'email' ) ORDER BY position ASC");
90 90
			if($query_email_fields->numRows() > 0) {
91 91
				while($field = $query_email_fields->fetchRow()) {
92 92
					?>
......
97 97
				}
98 98
			}
99 99
			?>
100
		</select>
101
		<input type="text" name="email_from" id="email_from" style="width: 100%; display: <?php if(isset($selected) AND $selected == true) { echo 'none'; } else { echo 'block'; } ?>;" maxlength="255" value="<?php if(substr($email_from_value, 0, 5) != 'field') { echo $email_from_value; } ?>" />
102
	</td>
103
</tr>
104
<tr>
105
	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['SUBJECT']; ?>:</td>
106
	<td class="setting_name">
107
		<input type="text" name="email_subject" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['email_subject'])); ?>" />
108
	</td>
109
</tr>
110
<tr>
111
	<td class="setting_name"><?php echo $TEXT['SUCCESS'].' '.$TEXT['MESSAGE']; ?>:</td>
112
	<td class="setting_name">
113
		<textarea name="success_message" style="width: 100%; height: 80px;"><?php echo str_replace($raw, $friendly, ($setting['success_message'])); ?></textarea>
114
	</td>
100
		</select>
101
		<input type="text" name="email_from" id="email_from" style="width: 100%; display: <?php if(isset($selected) AND $selected == true) { echo 'none'; } else { echo 'block'; } ?>;" maxlength="255" value="<?php if(substr($email_from_value, 0, 5) != 'field') { echo $email_from_value; } ?>" />
102
	</td>
115 103
</tr>
116
<tr>

117
	<td class="setting_name"><?php echo $TEXT['MAX_SUBMISSIONS_PER_HOUR']; ?>:</td>

118
	<td class="setting_name">

119
		<input type="text" name="max_submissions" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['max_submissions'])); ?>" />

120
	</td>

104
<tr>
105
	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['SUBJECT']; ?>:</td>
106
	<td class="setting_name">
107
		<input type="text" name="email_subject" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['email_subject'])); ?>" />
108
	</td>
121 109
</tr>
122
<tr>

123
	<td class="setting_name"><?php echo $TEXT['SUBMISSIONS_STORED_IN_DATABASE']; ?>:</td>

124
	<td class="setting_name">

125
		<input type="text" name="stored_submissions" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['stored_submissions'])); ?>" />

126
	</td>

110
<tr>
111
	<td class="setting_name"><?php echo $TEXT['SUCCESS'].' '.$TEXT['MESSAGE']; ?>:</td>
112
	<td class="setting_name">
113
		<textarea name="success_message" style="width: 100%; height: 80px;"><?php echo str_replace($raw, $friendly, ($setting['success_message'])); ?></textarea>
114
	</td>
127 115
</tr>
116
<tr>
117
	<td class="setting_name"><?php echo $TEXT['MAX_SUBMISSIONS_PER_HOUR']; ?>:</td>
118
	<td class="setting_name">
119
		<input type="text" name="max_submissions" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['max_submissions'])); ?>" />
120
	</td>
121
</tr>
122
<tr>
123
	<td class="setting_name"><?php echo $TEXT['SUBMISSIONS_STORED_IN_DATABASE']; ?>:</td>
124
	<td class="setting_name">
125
		<input type="text" name="stored_submissions" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['stored_submissions'])); ?>" />
126
	</td>
127
</tr>
128 128
<?php if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) { /* Make's sure GD library is installed */ ?>
129 129
<tr>
130 130
	<td class="setting_name"><?php echo $TEXT['CAPTCHA_VERIFICATION']; ?>:</td>
......
135 135
		<label for="use_captcha_false"><?php echo $TEXT['DISABLED']; ?></label>
136 136
	</td>
137 137
</tr>
138
<?php } ?>

139
</table>

140
<table cellpadding="0" cellspacing="0" border="0" width="100%">

141
<tr>

142
	<td width="225">&nbsp;</td>

143
	<td align="left">

144
		<input name="save" type="submit" value="<?php echo $TEXT['SAVE'].' '.$TEXT['SETTINGS']; ?>" style="width: 200px; margin-top: 5px;"></form>

145
	</td>

146
	<td align="right">

147
		<input type="button" value="<?php echo $TEXT['CANCEL']; ?>" onclick="javascript: window.location = '<?php echo ADMIN_URL; ?>/pages/modify.php?page_id=<?php echo $page_id; ?>';" style="width: 100px; margin-top: 5px;" />

148
	</td>

149
</tr>

150
</table>

151

  
152

  
153
<?php

154

  
155
// Print admin footer

156
$admin->print_footer();

157

  
138
<?php } ?>
139
</table>
140
<table cellpadding="0" cellspacing="0" border="0" width="100%">
141
<tr>
142
	<td width="225">&nbsp;</td>
143
	<td align="left">
144
		<input name="save" type="submit" value="<?php echo $TEXT['SAVE'].' '.$TEXT['SETTINGS']; ?>" style="width: 200px; margin-top: 5px;"></form>
145
	</td>
146
	<td align="right">
147
		<input type="button" value="<?php echo $TEXT['CANCEL']; ?>" onclick="javascript: window.location = '<?php echo ADMIN_URL; ?>/pages/modify.php?page_id=<?php echo $page_id; ?>';" style="width: 100px; margin-top: 5px;" />
148
	</td>
149
</tr>
150
</table>
151

  
152

  
153
<?php
154

  
155
// Print admin footer
156
$admin->print_footer();
157

  
158 158
?>
trunk/wb/modules/form/view.php
27 27
The Website Baker Project would like to thank Rudolph Lartey <www.carbonect.com>
28 28
for his contributions to this module - adding extra field types
29 29
*/
30

  
31
// Must include code to stop this file being access directly

30

  
31
// Must include code to stop this file being access directly
32 32
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
33

  
33

  
34 34
// Function for generating an optionsfor a select field
35
function make_option(&$n) {

36
	// start option group if it exists

37
	if (substr($n,0,2) == '[=') {

38
	 	$n = '<optgroup label="'.substr($n,2,strlen($n)).'">';

39
	} elseif ($n == ']') {

40
		$n = '</optgroup>';

41
	} else {

42
		$n = '<option value="'.$n.'">'.$n.'</option>';

43
	}

44
}

45

  
35
function make_option(&$n) {
36
	// start option group if it exists
37
	if (substr($n,0,2) == '[=') {
38
	 	$n = '<optgroup label="'.substr($n,2,strlen($n)).'">';
39
	} elseif ($n == ']') {
40
		$n = '</optgroup>';
41
	} else {
42
		$n = '<option value="'.$n.'">'.$n.'</option>';
43
	}
44
}
45

  
46 46
// Function for generating a checkbox
47
function make_checkbox(&$n, $idx, $params) {

48
	$field_id = $params[0];

49
	$seperator = $params[1];

50
	//$n = '<input class="field_checkbox" type="checkbox" id="'.$n.'" name="field'.$field_id.'" value="'.$n.'">'.'<font class="checkbox_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = !document.getElementById(\''.$n.'\').checked;">'.$n.'</font>'.$seperator;

51
	$n = '<input class="field_checkbox" type="checkbox" id="'.$n.'" name="field'.$field_id.'['.$idx.']" value="'.$n.'">'.'<font class="checkbox_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = !document.getElementById(\''.$n.'\').checked;">'.$n.'</font>'.$seperator;

52
}

53

  
47
function make_checkbox(&$n, $idx, $params) {
48
	$field_id = $params[0];
49
	$seperator = $params[1];
50
	//$n = '<input class="field_checkbox" type="checkbox" id="'.$n.'" name="field'.$field_id.'" value="'.$n.'">'.'<font class="checkbox_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = !document.getElementById(\''.$n.'\').checked;">'.$n.'</font>'.$seperator;
51
	$n = '<input class="field_checkbox" type="checkbox" id="'.$n.'" name="field'.$field_id.'['.$idx.']" value="'.$n.'">'.'<font class="checkbox_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = !document.getElementById(\''.$n.'\').checked;">'.$n.'</font>'.$seperator;
52
}
53

  
54 54
// Function for generating a radio button
55
function make_radio(&$n, $idx, $params) {

56
	$field_id = $params[0];

57
	$group = $params[1];

58
	$seperator = $params[2];

59
	$n = '<input class="field_radio" type="radio" id="'.$n.'" name="field'.$field_id.'" value="'.$n.'">'.'<font class="radio_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = true;">'.$n.'</font>'.$seperator;

55
function make_radio(&$n, $idx, $params) {
56
	$field_id = $params[0];
57
	$group = $params[1];
58
	$seperator = $params[2];
59
	$n = '<input class="field_radio" type="radio" id="'.$n.'" name="field'.$field_id.'" value="'.$n.'">'.'<font class="radio_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = true;">'.$n.'</font>'.$seperator;
60 60
}
61

  
62
// Work-out if the form has been submitted or not

63
if($_POST == array()) {

64

  
65
?>

66
<style type="text/css">

67
.required {

68
	color: #FF0000;

69
}

70
.field_title {

71
	font-size: 12px;

72
	width: 100px;

73
	vertical-align: top;

74
	text-align:right;

75
}

76
.textfield {

77
	font-size: 12px;

78
	width: 200px;

79
}

80
.textarea {

81
	font-size: 12px;

82
	width: 90%;

83
	height: 100px;

84
}

85
.field_heading {

86
	font-size: 12px;

87
	font-weight: bold;

88
	border-bottom-width: 2px;

89
	border-bottom-style: solid;

90
	border-bottom-color: #666666;

91
	padding-top: 10px;

92
	color: #666666;

93
}

94
.select {

95
	font-size: 12px;

96
}

97
.checkbox_label {

61

  
62
// Work-out if the form has been submitted or not
63
if($_POST == array()) {
64

  
65
?>
66
<style type="text/css">
67
.required {
68
	color: #FF0000;
69
}
70
.field_title {
71
	font-size: 12px;
72
	width: 100px;
73
	vertical-align: top;
74
	text-align:right;
75
}
76
.textfield {
77
	font-size: 12px;
78
	width: 200px;
79
}
80
.textarea {
81
	font-size: 12px;
82
	width: 90%;
83
	height: 100px;
84
}
85
.field_heading {
86
	font-size: 12px;
87
	font-weight: bold;
88
	border-bottom-width: 2px;
89
	border-bottom-style: solid;
90
	border-bottom-color: #666666;
91
	padding-top: 10px;
92
	color: #666666;
93
}
94
.select {
95
	font-size: 12px;
96
}
97
.checkbox_label {
98 98
	font-size: 11px;
99
	cursor: pointer;

100
}

101
.radio_label {

99
	cursor: pointer;
100
}
101
.radio_label {
102 102
	font-size: 11px;
103
	cursor: pointer;

103
	cursor: pointer;
104 104
}
105
.email {

106
	font-size: 12px;

107
	width: 200px;

108
}

109
</style>

110
<?php

111

  
112
// Get settings

113
$query_settings = $database->query("SELECT header,field_loop,footer,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");

114
if($query_settings->numRows() > 0) {

115
	$fetch_settings = $query_settings->fetchRow();

116
	$header = str_replace('{WB_URL}',WB_URL,$fetch_settings['header']);

117
	$field_loop = $fetch_settings['field_loop'];

105
.email {
106
	font-size: 12px;
107
	width: 200px;
108
}
109
</style>
110
<?php
111

  
112
// Get settings
113
$query_settings = $database->query("SELECT header,field_loop,footer,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
114
if($query_settings->numRows() > 0) {
115
	$fetch_settings = $query_settings->fetchRow();
116
	$header = str_replace('{WB_URL}',WB_URL,$fetch_settings['header']);
117
	$field_loop = $fetch_settings['field_loop'];
118 118
	$footer = str_replace('{WB_URL}',WB_URL,$fetch_settings['footer']);
119
	$use_captcha = $fetch_settings['use_captcha'];
120
} else {
121
	$header = '';
122
	$field_loop = '';
123
	$footer = '';
124
}
125

  
126
// Add form starter code
127
?>
128
<form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
129
<?php
130

  
131
// Print header
132
echo $header;
133

  
134
// Get list of fields
135
$query_fields = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
136
if($query_fields->numRows() > 0) {
137
	while($field = $query_fields->fetchRow()) {
138
		// Set field values
139
		$field_id = $field['field_id'];
140
		$value = $field['value'];
141
		// Print field_loop after replacing vars with values
142
		$vars = array('{TITLE}', '{REQUIRED}');
143
		$values = array($field['title']);
144
		if($field['required'] == 1) {
145
			$values[] = '<font class="required">*</font>';
146
		} else {
147
			$values[] = '';
148
		}
149
		if($field['type'] == 'textfield') {
150
			$vars[] = '{FIELD}';
151
			$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" maxlength="'.$field['extra'].'" value="'.$value.'" class="textfield" />';
152
		} elseif($field['type'] == 'textarea') {
153
			$vars[] = '{FIELD}';
154
			$values[] = '<textarea name="field'.$field_id.'" id="field'.$field_id.'" class="textarea">'.$value.'</textarea>';
155
		} elseif($field['type'] == 'select') {
156
			$vars[] = '{FIELD}';
157
			$options = explode(',', $value);
158
			array_walk($options, 'make_option');
159
			$field['extra'] = explode(',',$field['extra']); 
160
			$values[] = '<select name="field'.$field_id.'[]" id="field'.$field_id.'" size="'.$field['extra'][0].'" '.$field['extra'][1].' class="select">'.implode($options).'</select>';
161
		} elseif($field['type'] == 'heading') {
162
			$vars[] = '{FIELD}';
163
			$values[] = '<input type="hidden" name="field'.$field_id.'" id="field'.$field_id.'" value="===['.$field['title'].']===" />';
164
			$tmp_field_loop = $field_loop;		// temporarily modify the field loop template
165
			$field_loop = $field['extra'];
166
		} elseif($field['type'] == 'checkbox') {
167
			$vars[] = '{FIELD}';
168
			$options = explode(',', $value);
169
			array_walk($options, 'make_checkbox',array($field_id,$field['extra']));
170
			$values[] = implode($options);
171
		} elseif($field['type'] == 'radio') {
172
			$vars[] = '{FIELD}';
173
			$options = explode(',', $value);
174
			array_walk($options, 'make_radio',array($field_id,$field['title'],$field['extra']));
175
			$values[] = implode($options);
176
		} elseif($field['type'] == 'email') {
177
			$vars[] = '{FIELD}';
178
			$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" maxlength="'.$field['extra'].'" class="email" />';
119
	$use_captcha = $fetch_settings['use_captcha'];
120
} else {
121
	$header = '';
122
	$field_loop = '';
123
	$footer = '';
124
}
125

  
126
// Add form starter code
127
?>
128
<form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
129
<?php
130

  
131
// Print header
132
echo $header;
133

  
134
// Get list of fields
135
$query_fields = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
136
if($query_fields->numRows() > 0) {
137
	while($field = $query_fields->fetchRow()) {
138
		// Set field values
139
		$field_id = $field['field_id'];
140
		$value = $field['value'];
141
		// Print field_loop after replacing vars with values
142
		$vars = array('{TITLE}', '{REQUIRED}');
143
		$values = array($field['title']);
144
		if($field['required'] == 1) {
145
			$values[] = '<font class="required">*</font>';
146
		} else {
147
			$values[] = '';
179 148
		}
180
		if($field['type'] != '') {
149
		if($field['type'] == 'textfield') {
150
			$vars[] = '{FIELD}';
151
			$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" maxlength="'.$field['extra'].'" value="'.$value.'" class="textfield" />';
152
		} elseif($field['type'] == 'textarea') {
153
			$vars[] = '{FIELD}';
154
			$values[] = '<textarea name="field'.$field_id.'" id="field'.$field_id.'" class="textarea">'.$value.'</textarea>';
155
		} elseif($field['type'] == 'select') {
156
			$vars[] = '{FIELD}';
157
			$options = explode(',', $value);
158
			array_walk($options, 'make_option');
159
			$field['extra'] = explode(',',$field['extra']); 
160
			$values[] = '<select name="field'.$field_id.'[]" id="field'.$field_id.'" size="'.$field['extra'][0].'" '.$field['extra'][1].' class="select">'.implode($options).'</select>';
161
		} elseif($field['type'] == 'heading') {
162
			$vars[] = '{FIELD}';
163
			$values[] = '<input type="hidden" name="field'.$field_id.'" id="field'.$field_id.'" value="===['.$field['title'].']===" />';
164
			$tmp_field_loop = $field_loop;		// temporarily modify the field loop template
165
			$field_loop = $field['extra'];
166
		} elseif($field['type'] == 'checkbox') {
167
			$vars[] = '{FIELD}';
168
			$options = explode(',', $value);
169
			array_walk($options, 'make_checkbox',array($field_id,$field['extra']));
170
			$values[] = implode($options);
171
		} elseif($field['type'] == 'radio') {
172
			$vars[] = '{FIELD}';
173
			$options = explode(',', $value);
174
			array_walk($options, 'make_radio',array($field_id,$field['title'],$field['extra']));
175
			$values[] = implode($options);
176
		} elseif($field['type'] == 'email') {
177
			$vars[] = '{FIELD}';
178
			$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" maxlength="'.$field['extra'].'" class="email" />';
179
		}
180
		if($field['type'] != '') {
181 181
			echo str_replace($vars, $values, $field_loop);
182
		}

183
		if (isset($tmp_field_loop)) $field_loop = $tmp_field_loop;

184
	}

185
}

182
		}
183
		if (isset($tmp_field_loop)) $field_loop = $tmp_field_loop;
184
	}
185
}
186 186

  
187 187
// Captcha
188 188
if($use_captcha) {
......
192 192
	}
193 193
	?><tr><td class="field_title"><?php echo $TEXT['VERIFICATION']; ?>:</td><td>
194 194
	<table cellpadding="2" cellspacing="0" border="0">
195
	<tr><td><img src="<?php echo WB_URL; ?>/include/captcha.php" alt="Captcha" /></td>
195
	<tr><td><img src="<?php echo WB_URL; ?>/include/captcha.php?t=<?php echo time(); ?>" alt="Captcha" /></td>
196 196
	<td><input type="text" name="captcha" maxlength="5" /></td>
197 197
	</tr></table>
198 198
	</td></tr>
199 199
	<?php
200 200
}
201

  
202
// Print footer

203
echo $footer;

204

  
205
// Add form end code

206
?>

207
</form>

208
<?php

209

  
210
} else {

211
	
212
	// Submit form data

213
	// First start message settings

214
	$query_settings = $database->query("SELECT email_to,email_from,email_subject,success_message,max_submissions,stored_submissions,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");

215
	if($query_settings->numRows() > 0) {

216
		$fetch_settings = $query_settings->fetchRow();

217
		$email_to = $fetch_settings['email_to'];

201

  
202
// Print footer
203
echo $footer;
204

  
205
// Add form end code
206
?>
207
</form>
208
<?php
209

  
210
} else {
211
	
212
	// Submit form data
213
	// First start message settings
214
	$query_settings = $database->query("SELECT email_to,email_from,email_subject,success_message,max_submissions,stored_submissions,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
215
	if($query_settings->numRows() > 0) {
216
		$fetch_settings = $query_settings->fetchRow();
217
		$email_to = $fetch_settings['email_to'];
218 218
		$email_from = $fetch_settings['email_from'];
219 219
		if(substr($email_from, 0, 5) == 'field') {
220 220
			// Set the email from field to what the user entered in the specified field
221 221
			$email_from = $wb->add_slashes($_POST[$email_from]);
222
		}

223
		$email_subject = $fetch_settings['email_subject'];

222
		}
223
		$email_subject = $fetch_settings['email_subject'];
224 224
		$success_message = $fetch_settings['success_message'];
225 225
		$max_submissions = $fetch_settings['max_submissions'];
226 226
		$stored_submissions = $fetch_settings['stored_submissions'];
227
		$use_captcha = $fetch_settings['use_captcha'];

228
	} else {

229
		exit($TEXT['UNDER_CONSTRUCTION']);

230
	}

231
	$email_body = '';

232
	
233
	// Create blank "required" array

234
	$required = array();

235
	
236
	// Loop through fields and add to message body

237
	// Get list of fields

238
	$query_fields = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");

239
	if($query_fields->numRows() > 0) {

240
		while($field = $query_fields->fetchRow()) {

227
		$use_captcha = $fetch_settings['use_captcha'];
228
	} else {
229
		exit($TEXT['UNDER_CONSTRUCTION']);
230
	}
231
	$email_body = '';
232
	
233
	// Create blank "required" array
234
	$required = array();
235
	
236
	// Loop through fields and add to message body
237
	// Get list of fields
238
	$query_fields = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
239
	if($query_fields->numRows() > 0) {
240
		while($field = $query_fields->fetchRow()) {
241 241
			// Add to message body
242
			if($field['type'] != '') {

242
			if($field['type'] != '') {
243 243
				if(!empty($_POST['field'.$field['field_id']])) {
244 244
					if($field['type'] == 'email' AND $admin->validate_email($_POST['field'.$field['field_id']]) == false) {
245 245
						$email_error = $MESSAGE['USERS']['INVALID_EMAIL'];
246
					}

247
					if($field['type'] == 'heading') {

248
						$email_body .= $_POST['field'.$field['field_id']]."\n\n";

249
					} elseif (!is_array($_POST['field'.$field['field_id']])) {

250
						$email_body .= $field['title'].': '.$_POST['field'.$field['field_id']]."\n\n";

251
					} else {

252
						$email_body .= $field['title'].": \n";

253
						foreach ($_POST['field'.$field['field_id']] as $k=>$v) {

254
							$email_body .= $v."\n";

246
					}
247
					if($field['type'] == 'heading') {
248
						$email_body .= $_POST['field'.$field['field_id']]."\n\n";
249
					} elseif (!is_array($_POST['field'.$field['field_id']])) {
250
						$email_body .= $field['title'].': '.$_POST['field'.$field['field_id']]."\n\n";
251
					} else {
252
						$email_body .= $field['title'].": \n";
253
						foreach ($_POST['field'.$field['field_id']] as $k=>$v) {
254
							$email_body .= $v."\n";
255 255
						}
256
						$email_body .= "\n";

256
						$email_body .= "\n";
257 257
					}
258
				} elseif($field['required'] == 1) {

258
				} elseif($field['required'] == 1) {
259 259
					$required[] = $field['title'];
260
				}

261
			}

262
		}

263
	}

260
				}
261
			}
262
		}
263
	}
264 264
	
265 265
	// Captcha
266 266
	if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) { /* Make's sure GD library is installed */
......
279 279
	
280 280
	// Addslashes to email body - proposed by Icheb in topic=1170.0
281 281
	// $email_body = $wb->add_slashes($email_body);
282
	
283
	// Check if the user forgot to enter values into all the required fields

284
	if($required != array()) {

282
	
283
	// Check if the user forgot to enter values into all the required fields
284
	if($required != array()) {
285 285
		if(!isset($MESSAGE['MOD_FORM']['REQUIRED_FIELDS'])) {
286 286
			echo 'You must enter details for the following fields';
287 287
		} else {
288 288
			echo $MESSAGE['MOD_FORM']['REQUIRED_FIELDS'];
289
		}
290
		echo ':<br /><ul>';
291
		foreach($required AS $field_title) {
292
			echo '<li>'.$field_title;
293 289
		}
290
		echo ':<br /><ul>';
291
		foreach($required AS $field_title) {
292
			echo '<li>'.$field_title;
293
		}
294 294
		if(isset($email_error)) { echo '<li>'.$email_error.'</li>'; }
295
		if(isset($captcha_error)) { echo '<li>'.$captcha_error.'</li>'; }
296
		echo '</ul><a href="javascript: history.go(-1);">'.$TEXT['BACK'].'</a>';
297
		
298
	} else {
295
		if(isset($captcha_error)) { echo '<li>'.$captcha_error.'</li>'; }
296
		echo '</ul><a href="javascript: history.go(-1);">'.$TEXT['BACK'].'</a>';
299 297
		
298
	} else {
299
		
300 300
		if(isset($email_error)) {
301 301
			echo '<br /><ul>';
302 302
			echo '<li>'.$email_error.'</li>';
......
308 308
		} else {
309 309
		
310 310
		// Check how many times form has been submitted in last hour
311
		$query_submissions = $database->query("SELECT submission_id FROM ".TABLE_PREFIX."mod_form_submissions WHERE submitted_when >= '3600'");
311
		$last_hour = time()-3600;
312
		$query_submissions = $database->query("SELECT submission_id FROM ".TABLE_PREFIX."mod_form_submissions WHERE submitted_when >= '$last_hour'");
312 313
		if($query_submissions->numRows() > $max_submissions) {
313 314
			// Too many submissions so far this hour
314 315
			echo $MESSAGE['MOD_FORM']['EXCESS_SUBMISSIONS'];
315 316
			$success = false;
316
		} else {

317
		} else {
317 318
			// Now send the email
318
			if($email_to != '') {
319
				if($email_from != '') {
320
					if(mail($email_to,$email_subject,str_replace("\n", '', $email_body),"From: ".$email_from)) { $success = true; }
321
				} else {
322
					if(mail($email_to,$email_subject,str_replace("\n", '', $email_body))) { $success = true; }
319
			if($email_to != '') {
320
				if($email_from != '') {
321
					if($wb->wb_mail($email_from,$email_to,$email_subject,$email_body)) { $success = true; }
323 322
				}
324 323
			}				
325 324
			// Write submission to database
......
327 326
				$admin->get_user_id();
328 327
			} else {
329 328
				$submitted_by = 0;
330
			}

329
			}
331 330
			$email_body = $wb->add_slashes($email_body);
332 331
			$database->query("INSERT INTO ".TABLE_PREFIX."mod_form_submissions (page_id,section_id,submitted_when,submitted_by,body) VALUES ('".PAGE_ID."','$section_id','".mktime()."','$submitted_by','$email_body')");
333 332
			// Make sure submissions table isn't too full
......
348 347
				$success = true;
349 348
			}
350 349
		}
351
		
352
		// Now check if the email was sent successfully

353
		if(isset($success) AND $success == true) {

354
			echo $success_message;

355
		} else {

356
			echo $TEXT['ERROR'];

350
		
351
		// Now check if the email was sent successfully
352
		if(isset($success) AND $success == true) {
353
			echo $success_message;
354
		} else {
355
			echo $TEXT['ERROR'];
357 356
		}
358
		
359
		}

360
	}

361
	
357
		
358
		}
359
	}
360
	
362 361
}
363

  
362

  
364 363
?>
trunk/wb/modules/form/save_settings.php
1 1
<?php
2 2

  
3 3
// $Id$
4

  
4

  
5 5
/*
6 6

  
7 7
 Website Baker Project <http://www.websitebaker.org/>
......
27 27
The Website Baker Project would like to thank Rudolph Lartey <www.carbonect.com>
28 28
for his contributions to this module - adding extra field types
29 29
*/
30

  
31
require('../../config.php');

32

  
33
// Include WB admin wrapper script

34
$update_when_modified = true; // Tells script to update when this page was last updated

35
require(WB_PATH.'/modules/admin.php');

36

  
37
// This code removes any <?php tags and adds slashes

38
$friendly = array('&lt;', '&gt;', '?php');

39
$raw = array('<', '>', '');

40
$header = $admin->add_slashes($_POST['header']);

41
$field_loop = $admin->add_slashes($_POST['field_loop']);

42
$footer = $admin->add_slashes($_POST['footer']);

30

  
31
require('../../config.php');
32

  
33
// Include WB admin wrapper script
34
$update_when_modified = true; // Tells script to update when this page was last updated
35
require(WB_PATH.'/modules/admin.php');
36

  
37
// This code removes any <?php tags and adds slashes
38
$friendly = array('&lt;', '&gt;', '?php');
39
$raw = array('<', '>', '');
40
$header = $admin->add_slashes($_POST['header']);
41
$field_loop = $admin->add_slashes($_POST['field_loop']);
42
$footer = $admin->add_slashes($_POST['footer']);
43 43
$email_to = $admin->add_slashes($_POST['email_to']);
44 44
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) {
45 45
	$use_captcha = $_POST['use_captcha'];
46 46
} else {
47 47
	$use_captcha = false;
48 48
}
49
if($_POST['email_from_field'] == '') {

49
if($_POST['email_from_field'] == '') {
50 50
	$email_from = $admin->add_slashes($_POST['email_from']);
51 51
} else {
52 52
	$email_from = $admin->add_slashes($_POST['email_from_field']);
53
}

54
$email_subject = $admin->add_slashes($_POST['email_subject']);

53
}
54
$email_subject = $admin->add_slashes($_POST['email_subject']);
55 55
$success_message = $admin->add_slashes($_POST['success_message']);
56 56
if(!is_numeric($_POST['max_submissions'])) {
57 57
	$max_submissions = 50;
......
63 63
} else {
64 64
	$stored_submissions = $_POST['stored_submissions'];
65 65
}
66
// Make sure max submissions is not smaller than stored submissions
67
if($max_submissions < $stored_submissions) {
66
// Make sure max submissions is not greater than stored submissions
67
if($max_submissions > $stored_submissions) {
68 68
	$max_submissions = $stored_submissions;
69 69
}
70

  
71
// Update settings

72
$database->query("UPDATE ".TABLE_PREFIX."mod_form_settings SET header = '$header', field_loop = '$field_loop', footer = '$footer', email_to = '$email_to', email_from = '$email_from', email_subject = '$email_subject', success_message = '$success_message', max_submissions = '$max_submissions', stored_submissions = '$stored_submissions', use_captcha = '$use_captcha' WHERE section_id = '$section_id'");

73

  
74
// Check if there is a db error, otherwise say successful

75
if($database->is_error()) {

76
	$admin->print_error($database->get_error(), ADMIN_URL.'/pages/modify.php?page_id='.$page_id);

77
} else {

78
	$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);

79
}

80

  
81
// Print admin footer

82
$admin->print_footer();

83

  
70

  
71
// Update settings
72
$database->query("UPDATE ".TABLE_PREFIX."mod_form_settings SET header = '$header', field_loop = '$field_loop', footer = '$footer', email_to = '$email_to', email_from = '$email_from', email_subject = '$email_subject', success_message = '$success_message', max_submissions = '$max_submissions', stored_submissions = '$stored_submissions', use_captcha = '$use_captcha' WHERE section_id = '$section_id'");
73

  
74
// Check if there is a db error, otherwise say successful
75
if($database->is_error()) {
76
	$admin->print_error($database->get_error(), ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
77
} else {
78
	$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
79
}
80

  
81
// Print admin footer
82
$admin->print_footer();
83

  
84 84
?>

Also available in: Unified diff