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 1804 2012-11-01 22:50:49Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/save.php $
14
 * @lastmodified    $Date: 2012-11-01 23:50:49 +0100 (Thu, 01 Nov 2012) $
15
 *
16
 */
17

    
18
$config_file = realpath('../../config.php');
19
if(file_exists($config_file) && !defined('WB_URL'))
20
{
21
	require_once($config_file);
22
}
23

    
24
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
25

    
26
// suppress to print the header, so no new FTAN will be set
27
$admin = new admin('Access', 'users_modify', false);
28

    
29
// Create a javascript back link
30
$js_back = ADMIN_URL.'/users/index.php';
31

    
32
if( !$admin->checkFTAN() )
33
{
34
	$admin->print_header();
35
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back);
36
}
37
// After check print the header
38
$admin->print_header();
39

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

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

    
59
// Check values
60
if($groups_id == "") {
61
	$admin->print_error($MESSAGE['USERS_NO_GROUP'], $js_back);
62
}
63
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username))
64
{
65

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

    
80
if($email != "")
81
{
82
	if($admin->validate_email($email) == false)
83
    {
84
        $admin->print_error($MESSAGE['USERS_INVALID_EMAIL'], $js_back);
85
	}
86
} else { // e-mail must be present
87
	$admin->print_error($MESSAGE['SIGNUP_NO_EMAIL'], $js_back);
88
}
89

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

    
102
// Prevent from renaming user to "admin"
103
if($username != 'admin') {
104
	$username_code = ", username = '$username'";
105
} else {
106
	$username_code = '';
107
}
108

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

    
124
// Print admin footer
125
$admin->print_footer();
(3-3/4)