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-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 1425 2011-02-03 23:16:12Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/save.php $
15
 * @lastmodified    $Date: 2011-02-04 00:16:12 +0100 (Fri, 04 Feb 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

    
25
// Create a javascript back link
26
$js_back = ADMIN_URL.'/users/index.php';
27

    
28
// Create new database object
29
//$database = new database();
30
if( !$admin->checkFTAN() )
31
{
32
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back);
33
	exit();
34
}
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(strlen($username) < 2) {
60
	$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
61
}
62
if($password != "") {
63
	if(strlen($password) < 2) {
64
		$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
65
	}
66
	if($password != $password2) {
67
		$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
68
	}
69
}
70

    
71
if($email != "")
72
{
73
	if($admin->validate_email($email) == false)
74
    {
75
        $admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
76
	}
77
} else { // e-mail must be present
78
	$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $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'])."' AND user_id <> '".$user_id."' ");
83
if($results->numRows() > 0)
84
{
85
	if(isset($MESSAGE['USERS']['EMAIL_TAKEN']))
86
    {
87
		$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
88
	} else {
89
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
90
	}
91
}
92

    
93
// Prevent from renaming user to "admin"
94
if($username != 'admin') {
95
	$username_code = ", username = '$username'";
96
} else {
97
	$username_code = '';
98
}
99

    
100
// Update the database
101
if($password == "") {
102
	$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'";
103
} else {
104
	// MD5 supplied password
105
	$md5_password = md5($password);
106
	$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'";
107
}
108
$database->query($query);
109
if($database->is_error()) {
110
	$admin->print_error($database->get_error(),$js_back);
111
} else {
112
	$admin->print_success($MESSAGE['USERS']['SAVED']);
113
}
114

    
115
// Print admin footer
116
$admin->print_footer();
117

    
118
?>
(3-3/4)