1 |
1392
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
|
|
* @package users
|
6 |
|
|
* @author WebsiteBaker Project
|
7 |
|
|
* @copyright 2004-2009, Ryan Djurovich
|
8 |
|
|
* @copyright 2009-2011, 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 5.2.2 and higher
|
13 |
|
|
* @version $Id$
|
14 |
|
|
* @filesource $HeadURL$
|
15 |
|
|
* @lastmodified $Date$
|
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 |
|
|
if( !$admin->checkFTAN() )
|
27 |
|
|
{
|
28 |
|
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],'index.php');
|
29 |
|
|
exit();
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
// Get details entered
|
33 |
|
|
$groups_id = implode(",", $admin->add_slashes($_POST['groups'])); //should check permissions
|
34 |
|
|
$groups_id = trim($groups_id, ','); // there will be an additional ',' when "Please Choose" was selected, too
|
35 |
|
|
$active = $admin->add_slashes($_POST['active'][0]);
|
36 |
|
|
$username_fieldname = $admin->get_post_escaped('username_fieldname');
|
37 |
|
|
$username = strtolower($admin->get_post_escaped($username_fieldname));
|
38 |
|
|
$password = $admin->get_post('password');
|
39 |
|
|
$password2 = $admin->get_post('password2');
|
40 |
|
|
$display_name = $admin->get_post_escaped('display_name');
|
41 |
|
|
$email = $admin->get_post_escaped('email');
|
42 |
|
|
$home_folder = $admin->get_post_escaped('home_folder');
|
43 |
|
|
$default_language = DEFAULT_LANGUAGE;
|
44 |
|
|
|
45 |
|
|
// Create a javascript back link
|
46 |
|
|
$js_back = 'javascript: history.go(-1);';
|
47 |
|
|
|
48 |
|
|
// Check values
|
49 |
|
|
if($groups_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 |
|
|
{
|
63 |
|
|
if($admin->validate_email($email) == false)
|
64 |
|
|
{
|
65 |
|
|
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
66 |
|
|
}
|
67 |
|
|
} else { // e-mail must be present
|
68 |
|
|
$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back);
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
// choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
|
72 |
|
|
$gid_tmp = explode(',', $groups_id);
|
73 |
|
|
if(in_array('1', $gid_tmp)) $group_id = '1'; // if user is in administrator-group, get this group
|
74 |
|
|
else $group_id = $gid_tmp[0]; // else just get the first one
|
75 |
|
|
unset($gid_tmp);
|
76 |
|
|
|
77 |
|
|
// Check if username already exists
|
78 |
|
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
|
79 |
|
|
if($results->numRows() > 0) {
|
80 |
|
|
$admin->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back);
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
// Check if the email already exists
|
84 |
|
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'");
|
85 |
|
|
if($results->numRows() > 0)
|
86 |
|
|
{
|
87 |
|
|
if(isset($MESSAGE['USERS']['EMAIL_TAKEN']))
|
88 |
|
|
{
|
89 |
|
|
$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
|
90 |
|
|
} else {
|
91 |
|
|
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
// MD5 supplied password
|
96 |
|
|
$md5_password = md5($password);
|
97 |
|
|
|
98 |
|
|
// Inser the user into the database
|
99 |
|
|
$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')";
|
100 |
|
|
$database->query($query);
|
101 |
|
|
if($database->is_error()) {
|
102 |
|
|
$admin->print_error($database->get_error());
|
103 |
|
|
} else {
|
104 |
|
|
$admin->print_success($MESSAGE['USERS']['ADDED']);
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
// Print admin footer
|
108 |
|
|
$admin->print_footer();
|
109 |
|
|
|
110 |
4
|
ryan
|
?>
|