Project

General

Profile

1 4 ryan
<?php
2
3 40 stefan
// $Id$
4 4 ryan
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8 519 Ruebenwurz
 Copyright (C) 2004-2008, Ryan Djurovich
9 4 ryan
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24
*/
25
26
// Print admin header
27
require('../../config.php');
28
require_once(WB_PATH.'/framework/class.admin.php');
29
$admin = new admin('Access', 'users_add');
30
31
// Create new database object
32
$database = new database();
33
34
// Get details entered
35
$group_id = $admin->get_post('group');
36
$active = $_POST['active'][0];
37
$username_fieldname = $admin->get_post('username_fieldname');
38
$username = strtolower($admin->get_post($username_fieldname));
39
$password = $admin->get_post('password');
40
$password2 = $admin->get_post('password2');
41
$display_name = $admin->get_post('display_name');
42
$email = $admin->get_post('email');
43
$home_folder = $admin->get_post('home_folder');
44
45
// Create a javascript back link
46
$js_back = "javascript: history.go(-1);";
47
48
// Check values
49
if($group_id == "") {
50
	$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
51
}
52
if(strlen($username) < 2) {
53
	$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
54
}
55
if(strlen($password) < 2) {
56
	$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
57
}
58
if($password != $password2) {
59
	$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
60
}
61
if($email != "") {
62
	if($admin->validate_email($email) == false) {
63
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
64
	}
65
}
66
67
// Check if username already exists
68
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
69
if($results->numRows() > 0) {
70
	$admin->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back);
71
}
72
73
// Check if the email already exists
74 40 stefan
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'");
75 4 ryan
if($results->numRows() > 0) {
76
	if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) {
77
		$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
78
	} else {
79
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
80
	}
81
}
82
83
// MD5 supplied password
84
$md5_password = md5($password);
85
86
// Inser the user into the database
87
$query = "INSERT INTO ".TABLE_PREFIX."users (group_id,active,username,password,display_name,home_folder,email,timezone) VALUES ('$group_id', '$active', '$username','$md5_password','$display_name','$home_folder','$email','-72000')";
88
$database->query($query);
89
if($database->is_error()) {
90
	$admin->print_error($database->get_error());
91
} else {
92
	$admin->print_success($MESSAGE['USERS']['ADDED']);
93
}
94
95
// Print admin footer
96
$admin->print_footer();
97
98
?>