1
|
<?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: save.php 1457 2011-06-25 17:18:50Z Luisehahne $
|
14
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/save.php $
|
15
|
* @lastmodified $Date: 2011-06-25 19:18:50 +0200 (Sat, 25 Jun 2011) $
|
16
|
*
|
17
|
*/
|
18
|
|
19
|
// Print admin header
|
20
|
require('../../config.php');
|
21
|
require_once(WB_PATH.'/framework/class.admin.php');
|
22
|
// suppress to print the header, so no new FTAN will be set
|
23
|
$admin = new admin('Access', 'users_modify', false);
|
24
|
|
25
|
// Create a javascript back link
|
26
|
$js_back = ADMIN_URL.'/users/index.php';
|
27
|
|
28
|
if( !$admin->checkFTAN() )
|
29
|
{
|
30
|
$admin->print_header();
|
31
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back);
|
32
|
}
|
33
|
// After check print the header
|
34
|
$admin->print_header();
|
35
|
|
36
|
// Check if user id is a valid number and doesnt equal 1
|
37
|
if(!isset($_POST['user_id']) OR !is_numeric($_POST['user_id']) OR $_POST['user_id'] == 1) {
|
38
|
header("Location: index.php");
|
39
|
exit(0);
|
40
|
} else {
|
41
|
$user_id = $_POST['user_id'];
|
42
|
}
|
43
|
|
44
|
// Gather details entered
|
45
|
$groups_id = (isset($_POST['groups'])) ? implode(",", $admin->add_slashes($_POST['groups'])) : '';
|
46
|
$active = $admin->add_slashes($_POST['active'][0]);
|
47
|
$username_fieldname = $admin->get_post_escaped('username_fieldname');
|
48
|
$username = strtolower($admin->get_post_escaped($username_fieldname));
|
49
|
$password = $admin->get_post('password');
|
50
|
$password2 = $admin->get_post('password2');
|
51
|
$display_name = $admin->get_post_escaped('display_name');
|
52
|
$email = $admin->get_post_escaped('email');
|
53
|
$home_folder = $admin->get_post_escaped('home_folder');
|
54
|
|
55
|
// Check values
|
56
|
if($groups_id == "") {
|
57
|
$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
|
58
|
}
|
59
|
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
|
60
|
$admin->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '.
|
61
|
$MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back);
|
62
|
}
|
63
|
if($password != "") {
|
64
|
if(strlen($password) < 2) {
|
65
|
$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
|
66
|
}
|
67
|
if($password != $password2) {
|
68
|
$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
|
69
|
}
|
70
|
}
|
71
|
|
72
|
if($email != "")
|
73
|
{
|
74
|
if($admin->validate_email($email) == false)
|
75
|
{
|
76
|
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
77
|
}
|
78
|
} else { // e-mail must be present
|
79
|
$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back);
|
80
|
}
|
81
|
|
82
|
// Check if the email already exists
|
83
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."' AND user_id <> '".$user_id."' ");
|
84
|
if($results->numRows() > 0)
|
85
|
{
|
86
|
if(isset($MESSAGE['USERS']['EMAIL_TAKEN']))
|
87
|
{
|
88
|
$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
|
89
|
} else {
|
90
|
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
91
|
}
|
92
|
}
|
93
|
|
94
|
// Prevent from renaming user to "admin"
|
95
|
if($username != 'admin') {
|
96
|
$username_code = ", username = '$username'";
|
97
|
} else {
|
98
|
$username_code = '';
|
99
|
}
|
100
|
|
101
|
// Update the database
|
102
|
if($password == "") {
|
103
|
$query = "UPDATE ".TABLE_PREFIX."users SET groups_id = '$groups_id', active = '$active'$username_code, display_name = '$display_name', home_folder = '$home_folder', email = '$email' WHERE user_id = '$user_id'";
|
104
|
} else {
|
105
|
// MD5 supplied password
|
106
|
$md5_password = md5($password);
|
107
|
$query = "UPDATE ".TABLE_PREFIX."users SET groups_id = '$groups_id', active = '$active'$username_code, display_name = '$display_name', home_folder = '$home_folder', email = '$email', password = '$md5_password' WHERE user_id = '$user_id'";
|
108
|
}
|
109
|
$database->query($query);
|
110
|
if($database->is_error()) {
|
111
|
$admin->print_error($database->get_error(),$js_back);
|
112
|
} else {
|
113
|
$admin->print_success($MESSAGE['USERS']['SAVED']);
|
114
|
}
|
115
|
|
116
|
// Print admin footer
|
117
|
$admin->print_footer();
|