Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: save.php 1710 2012-08-29 11:50:26Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/save.php $
14
 * @lastmodified    $Date: 2012-08-29 13:50:26 +0200 (Wed, 29 Aug 2012) $
15
 *
16
 */
17

    
18
// Print admin header
19
require('../../config.php');
20
require_once(WB_PATH.'/framework/class.admin.php');
21
// suppress to print the header, so no new FTAN will be set
22
$admin = new admin('Access', 'users_modify', false);
23

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

    
27
if( !$admin->checkFTAN() )
28
{
29
	$admin->print_header();
30
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back);
31
}
32
// After check print the header
33
$admin->print_header();
34

    
35
// Check if user id is a valid number and doesnt equal 1
36
if(!isset($_POST['user_id']) OR !is_numeric($_POST['user_id']) OR $_POST['user_id'] == 1) {
37
	header("Location: index.php");
38
	exit(0);
39
} else {
40
	$user_id = intval($_POST['user_id']);
41
}
42

    
43
// Gather details entered
44
$groups_id = (isset($_POST['groups'])) ? implode(",", $admin->add_slashes($_POST['groups'])) : '';
45
$active = $admin->add_slashes($_POST['active'][0]);
46
$username_fieldname = $admin->get_post_escaped('username_fieldname');
47
$username = strtolower($admin->get_post_escaped($username_fieldname));
48
$password = $admin->get_post('password');
49
$password2 = $admin->get_post('password2');
50
$display_name = $admin->get_post_escaped('display_name');
51
$email = $admin->get_post_escaped('email');
52
$home_folder = $admin->get_post_escaped('home_folder');
53

    
54
// Check values
55
if($groups_id == "") {
56
	$admin->print_error($MESSAGE['USERS_NO_GROUP'], $js_back);
57
}
58
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username))
59
{
60

    
61
//	print '<pre style="text-align: left;"><strong>function '.__FUNCTION__.'( '.''.' );</strong>  basename: '.basename(__FILE__).'  line: '.__LINE__.' -> <br />';
62
//	print_r( $_POST ); print '</pre>';
63
	$admin->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '.
64
	                  $MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back);
65
}
66
if($password != "") {
67
	if(strlen($password) < 2) {
68
		$admin->print_error($MESSAGE['USERS_PASSWORD_TOO_SHORT'], $js_back);
69
	}
70
	if($password != $password2) {
71
		$admin->print_error($MESSAGE['USERS_PASSWORD_MISMATCH'], $js_back);
72
	}
73
}
74

    
75
if($email != "")
76
{
77
	if($admin->validate_email($email) == false)
78
    {
79
        $admin->print_error($MESSAGE['USERS_INVALID_EMAIL'], $js_back);
80
	}
81
} else { // e-mail must be present
82
	$admin->print_error($MESSAGE['SIGNUP_NO_EMAIL'], $js_back);
83
}
84

    
85
// Check if the email already exists
86
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."' AND user_id <> '".$user_id."' ");
87
if($results->numRows() > 0)
88
{
89
	if(isset($MESSAGE['USERS_EMAIL_TAKEN']))
90
    {
91
		$admin->print_error($MESSAGE['USERS_EMAIL_TAKEN'], $js_back);
92
	} else {
93
		$admin->print_error($MESSAGE['USERS_INVALID_EMAIL'], $js_back);
94
	}
95
}
96

    
97
// Prevent from renaming user to "admin"
98
if($username != 'admin') {
99
	$username_code = ", username = '$username'";
100
} else {
101
	$username_code = '';
102
}
103

    
104
// Update the database
105
if($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' WHERE user_id = '$user_id'";
107
} else {
108
	// MD5 supplied password
109
	$md5_password = md5($password);
110
	$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'";
111
}
112
$database->query($query);
113
if($database->is_error()) {
114
	$admin->print_error($database->get_error(),$js_back);
115
} else {
116
	$admin->print_success($MESSAGE['USERS_SAVED']);
117
}
118

    
119
// Print admin footer
120
$admin->print_footer();
(3-3/4)