1
|
<?php
|
2
|
|
3
|
// $Id: add.php 812 2008-04-07 17:29:40Z thorn $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2008, Ryan Djurovich
|
9
|
|
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
|
$groups_id = implode(",", $admin->add_slashes($_POST['groups'])); //should check permissions
|
36
|
$groups_id = trim($groups_id, ','); // there will be an additional ',' when "Please Choose" was selected, too
|
37
|
$active = $admin->add_slashes($_POST['active'][0]);
|
38
|
$username_fieldname = $admin->get_post_escaped('username_fieldname');
|
39
|
$username = strtolower($admin->get_post_escaped($username_fieldname));
|
40
|
$password = $admin->get_post('password');
|
41
|
$password2 = $admin->get_post('password2');
|
42
|
$display_name = $admin->get_post_escaped('display_name');
|
43
|
$email = $admin->get_post_escaped('email');
|
44
|
$home_folder = $admin->get_post_escaped('home_folder');
|
45
|
$default_language = DEFAULT_LANGUAGE;
|
46
|
|
47
|
// Create a javascript back link
|
48
|
$js_back = 'javascript: history.go(-1);';
|
49
|
|
50
|
// Check values
|
51
|
if($groups_id == '') {
|
52
|
$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
|
53
|
}
|
54
|
if(strlen($username) < 2) {
|
55
|
$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
|
56
|
}
|
57
|
if(strlen($password) < 2) {
|
58
|
$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
|
59
|
}
|
60
|
if($password != $password2) {
|
61
|
$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
|
62
|
}
|
63
|
if($email != '') {
|
64
|
if($admin->validate_email($email) == false) {
|
65
|
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
66
|
}
|
67
|
}
|
68
|
|
69
|
// choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
|
70
|
$gid_tmp = explode(',', $groups_id);
|
71
|
if(in_array('1', $gid_tmp)) $group_id = '1'; // if user is in administrator-group, get this group
|
72
|
else $group_id = $gid_tmp[0]; // else just get the first one
|
73
|
unset($gid_tmp);
|
74
|
|
75
|
// Check if username already exists
|
76
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
|
77
|
if($results->numRows() > 0) {
|
78
|
$admin->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back);
|
79
|
}
|
80
|
|
81
|
// Check if the email already exists
|
82
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'");
|
83
|
if($results->numRows() > 0) {
|
84
|
if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) {
|
85
|
$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
|
86
|
} else {
|
87
|
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
88
|
}
|
89
|
}
|
90
|
|
91
|
// MD5 supplied password
|
92
|
$md5_password = md5($password);
|
93
|
|
94
|
// Inser the user into the database
|
95
|
$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')";
|
96
|
$database->query($query);
|
97
|
if($database->is_error()) {
|
98
|
$admin->print_error($database->get_error());
|
99
|
} else {
|
100
|
$admin->print_success($MESSAGE['USERS']['ADDED']);
|
101
|
}
|
102
|
|
103
|
// Print admin footer
|
104
|
$admin->print_footer();
|
105
|
|
106
|
?>
|