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 546 doc
$groups_id = implode(",", $_POST['groups']); //should check permissions
36 4 ryan
$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 613 doc
$default_language = DEFAULT_LANGUAGE;
45 4 ryan
46
// Create a javascript back link
47
$js_back = "javascript: history.go(-1);";
48
49
// Check values
50 546 doc
if($groups_id == "") {
51 4 ryan
	$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
52
}
53
if(strlen($username) < 2) {
54
	$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
55
}
56
if(strlen($password) < 2) {
57
	$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
58
}
59
if($password != $password2) {
60
	$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
61
}
62
if($email != "") {
63
	if($admin->validate_email($email) == false) {
64
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
65
	}
66
}
67
68
// Check if username already exists
69
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
70
if($results->numRows() > 0) {
71
	$admin->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back);
72
}
73
74
// Check if the email already exists
75 40 stefan
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'");
76 4 ryan
if($results->numRows() > 0) {
77
	if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) {
78
		$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
79
	} else {
80
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
81
	}
82
}
83
84
// MD5 supplied password
85
$md5_password = md5($password);
86
87
// Inser the user into the database
88 613 doc
$query = "INSERT INTO ".TABLE_PREFIX."users (groups_id,active,username,password,display_name,home_folder,email,timezone, language) VALUES ('$groups_id', '$active', '$username','$md5_password','$display_name','$home_folder','$email','-72000', '$default_language')";
89 4 ryan
$database->query($query);
90
if($database->is_error()) {
91
	$admin->print_error($database->get_error());
92
} else {
93
	$admin->print_success($MESSAGE['USERS']['ADDED']);
94
}
95
96
// Print admin footer
97
$admin->print_footer();
98
99
?>