Project

General

Profile

1 1347 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8 1349 Luisehahne
 * @copyright       2009-2011, Website Baker Org. e.V.
9 1347 Luisehahne
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12 1374 Luisehahne
 * @requirements    PHP 5.2.2 and higher
13 1347 Luisehahne
 * @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_modify');
23
24 1425 Luisehahne
25
// Create a javascript back link
26
$js_back = ADMIN_URL.'/users/index.php';
27
28 1347 Luisehahne
// Create new database object
29 1353 FrankH
//$database = new database();
30
if( !$admin->checkFTAN() )
31
{
32 1425 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back);
33 1353 FrankH
	exit();
34
}
35 1347 Luisehahne
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 1425 Luisehahne
	$admin->print_error($database->get_error(),$js_back);
111 1347 Luisehahne
} else {
112
	$admin->print_success($MESSAGE['USERS']['SAVED']);
113
}
114
115
// Print admin footer
116
$admin->print_footer();
117
118 4 ryan
?>