Project

General

Profile

« Previous | Next » 

Revision 687

Added by doc almost 17 years ago

added visualization of wrong/empty input fields, fixed bug with re-enter of admin password

View differences:

save.php
35 35
$session_rand = rand(1000,9999);
36 36

  
37 37
// Function to set error
38
function set_error($message) {
38
function set_error($message, $field_name = '') {
39 39
	global $_POST;
40 40
	if(isset($message) AND $message != '') {
41 41
		// Copy values entered into session so user doesn't have to re-enter everything
......
67 67
			$_SESSION['admin_username'] = $_POST['admin_username'];
68 68
			$_SESSION['admin_email'] = $_POST['admin_email'];
69 69
			$_SESSION['admin_password'] = $_POST['admin_password'];
70
			$_SESSION['admin_repassword'] = $_POST['admin_repassword'];
70 71
		}
71 72
		// Set the message
72 73
		$_SESSION['message'] = $message;
74
		// Set the element(s) to highlight
75
		if($field_name != '') {
76
			$_SESSION['ERROR_FIELD'] = $field_name;
77
		}
73 78
		// Specify that session support is enabled
74 79
		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
75 80
		// Redirect to first page again and exit
......
139 144

  
140 145
// Check if user has entered the installation url
141 146
if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
142
	set_error('Please enter an absolute URL');
147
	set_error('Please enter an absolute URL', 'wb_url');
143 148
} else {
144 149
	$wb_url = $_POST['wb_url'];
145 150
}
......
158 163
}
159 164
// Get the default time zone
160 165
if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
161
	set_error('Please select a valid default timezone');
166
	set_error('Please select a valid default timezone', 'default_timezone');
162 167
} else {
163 168
	$default_timezone = $_POST['default_timezone']*60*60;
164 169
}
......
167 172
// Get the default language
168 173
$allowed_languages = array('CA', 'DA', 'DE', 'EN', 'ES', 'ET', 'FI', 'FR', 'HR', 'HU', 'IT', 'LV', 'NL', 'PT','SE', 'TR');
169 174
if(!isset($_POST['default_language']) OR !in_array($_POST['default_language'], $allowed_languages)) {
170
	set_error('Please select a valid default backend language');
175
	set_error('Please select a valid default backend language','default_language');
171 176
} else {
172 177
	$default_language = $_POST['default_language'];
173 178
	// make sure the selected language file exists in the language folder
174 179
	if(!file_exists('../languages/' .$default_language .'.php')) {
175
		set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language');
180
		set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language','default_language');
176 181
	}
177 182
}
178 183
// End default language details code
......
200 205
// Begin database details code
201 206
// Check if user has entered a database host
202 207
if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
203
	set_error('Please enter a database host name');
208
	set_error('Please enter a database host name', 'database_host');
204 209
} else {
205 210
	$database_host = $_POST['database_host'];
206 211
}
207 212
// Check if user has entered a database username
208 213
if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
209
	set_error('Please enter a database username');
214
	set_error('Please enter a database username','database_username');
210 215
} else {
211 216
	$database_username = $_POST['database_username'];
212 217
}
213 218
// Check if user has entered a database password
214 219
if(!isset($_POST['database_password'])) {
215
	set_error('Please enter a database password');
220
	set_error('Please enter a database password', 'database_password');
216 221
} else {
217 222
	$database_password = $_POST['database_password'];
218 223
}
219 224
// Check if user has entered a database name
220 225
if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
221
	set_error('Please enter a database name');
226
	set_error('Please enter a database name', 'database_name');
222 227
} else {
223 228
	$database_name = $_POST['database_name'];
224 229
}
......
235 240
// Begin website title code
236 241
// Get website title
237 242
if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
238
	set_error('Please enter a website title');
243
	set_error('Please enter a website title', 'website_title');
239 244
} else {
240 245
	$website_title = add_slashes($_POST['website_title']);
241 246
}
......
244 249
// Begin admin user details code
245 250
// Get admin username
246 251
if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
247
	set_error('Please enter a username for the Administrator account');
252
	set_error('Please enter a username for the Administrator account','admin_username');
248 253
} else {
249 254
	$admin_username = $_POST['admin_username'];
250 255
}
251 256
// Get admin email and validate it
252 257
if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
253
	set_error('Please enter an email for the Administrator account');
258
	set_error('Please enter an email for the Administrator account','admin_email');
254 259
} else {
255 260
	if(eregi("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $_POST['admin_email'])) {
256 261
		$admin_email = $_POST['admin_email'];
257 262
	} else {
258
		set_error('Please enter a valid email address for the Administrator account');
263
		set_error('Please enter a valid email address for the Administrator account','admin_email');
259 264
	}
260 265
}
261 266
// Get the two admin passwords entered, and check that they match
262 267
if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
263
	set_error('Please enter a password for the Administrator account');
268
	set_error('Please enter a password for the Administrator account','admin_password');
264 269
} else {
265 270
	$admin_password = $_POST['admin_password'];
266 271
}
267 272
if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
268
	set_error('Please make sure you re-enter the password for the Administrator account');
273
	set_error('Please make sure you re-enter the password for the Administrator account','admin_repassword');
269 274
} else {
270 275
	$admin_repassword = $_POST['admin_repassword'];
271 276
}
272 277
if($admin_password != $admin_repassword) {
273
	set_error('Sorry, the two Administrator account passwords you entered do not match');
278
	set_error('Sorry, the two Administrator account passwords you entered do not match','admin_repassword');
274 279
}
275 280
// End admin user details code
276 281

  

Also available in: Unified diff