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