Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 4.4.9 and higher
13
 * @version         $Id: add.php 1304 2010-03-16 23:10:17Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/add.php $
15
 * @lastmodified    $Date: 2010-03-17 00:10:17 +0100 (Wed, 17 Mar 2010) $
16
 *
17
 */
18

    
19
// Print admin header
20
require('../../config.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22
$admin = new admin('Access', 'users_add');
23

    
24
// Create new database object
25
$database = new database();
26

    
27
// Get details entered
28
$groups_id = implode(",", $admin->add_slashes($_POST['groups'])); //should check permissions
29
$groups_id = trim($groups_id, ','); // there will be an additional ',' when "Please Choose" was selected, too
30
$active = $admin->add_slashes($_POST['active'][0]);
31
$username_fieldname = $admin->get_post_escaped('username_fieldname');
32
$username = strtolower($admin->get_post_escaped($username_fieldname));
33
$password = $admin->get_post('password');
34
$password2 = $admin->get_post('password2');
35
$display_name = $admin->get_post_escaped('display_name');
36
$email = $admin->get_post_escaped('email');
37
$home_folder = $admin->get_post_escaped('home_folder');
38
$default_language = DEFAULT_LANGUAGE;
39

    
40
// Create a javascript back link
41
$js_back = 'javascript: history.go(-1);';
42

    
43
// Check values
44
if($groups_id == '') {
45
	$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
46
}
47
if(strlen($username) < 2) {
48
	$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
49
}
50
if(strlen($password) < 2) {
51
	$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
52
}
53
if($password != $password2) {
54
	$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
55
}
56
if($email != '')
57
{
58
	if($admin->validate_email($email) == false)
59
    {
60
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
61
	}
62
} else { // e-mail must be present
63
	$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back);
64
}
65

    
66
// choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
67
$gid_tmp = explode(',', $groups_id);
68
if(in_array('1', $gid_tmp)) $group_id = '1'; // if user is in administrator-group, get this group
69
else $group_id = $gid_tmp[0]; // else just get the first one
70
unset($gid_tmp);
71

    
72
// Check if username already exists
73
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
74
if($results->numRows() > 0) {
75
	$admin->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back);
76
}
77

    
78
// Check if the email already exists
79
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'");
80
if($results->numRows() > 0)
81
{
82
	if(isset($MESSAGE['USERS']['EMAIL_TAKEN']))
83
    {
84
		$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
85
	} else {
86
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
87
	}
88
}
89

    
90
// MD5 supplied password
91
$md5_password = md5($password);
92

    
93
// Inser the user into the database
94
$query = "INSERT INTO ".TABLE_PREFIX."users (group_id,groups_id,active,username,password,display_name,home_folder,email,timezone, language) VALUES ('$group_id', '$groups_id', '$active', '$username','$md5_password','$display_name','$home_folder','$email','-72000', '$default_language')";
95
$database->query($query);
96
if($database->is_error()) {
97
	$admin->print_error($database->get_error());
98
} else {
99
	$admin->print_success($MESSAGE['USERS']['ADDED']);
100
}
101

    
102
// Print admin footer
103
$admin->print_footer();
104

    
105
?>
(1-1/4)