1 |
1347
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
|
|
* @package users
|
6 |
1710
|
Luisehahne
|
* @author Ryan Djurovich, WebsiteBaker Project
|
7 |
|
|
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
8 |
1347
|
Luisehahne
|
* @link http://www.websitebaker2.org/
|
9 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
10 |
|
|
* @platform WebsiteBaker 2.8.x
|
11 |
1374
|
Luisehahne
|
* @requirements PHP 5.2.2 and higher
|
12 |
1347
|
Luisehahne
|
* @version $Id$
|
13 |
|
|
* @filesource $HeadURL$
|
14 |
|
|
* @lastmodified $Date$
|
15 |
|
|
*
|
16 |
|
|
*/
|
17 |
|
|
|
18 |
1804
|
Luisehahne
|
$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 |
1457
|
Luisehahne
|
// suppress to print the header, so no new FTAN will be set
|
27 |
|
|
$admin = new admin('Access', 'users_modify', false);
|
28 |
1347
|
Luisehahne
|
|
29 |
1425
|
Luisehahne
|
// Create a javascript back link
|
30 |
|
|
$js_back = ADMIN_URL.'/users/index.php';
|
31 |
|
|
|
32 |
1353
|
FrankH
|
if( !$admin->checkFTAN() )
|
33 |
|
|
{
|
34 |
1457
|
Luisehahne
|
$admin->print_header();
|
35 |
1425
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back);
|
36 |
1353
|
FrankH
|
}
|
37 |
1457
|
Luisehahne
|
// After check print the header
|
38 |
|
|
$admin->print_header();
|
39 |
1347
|
Luisehahne
|
|
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 |
1710
|
Luisehahne
|
$user_id = intval($_POST['user_id']);
|
46 |
1347
|
Luisehahne
|
}
|
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 |
1710
|
Luisehahne
|
$admin->print_error($MESSAGE['USERS_NO_GROUP'], $js_back);
|
62 |
1347
|
Luisehahne
|
}
|
63 |
1710
|
Luisehahne
|
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 |
1446
|
DarkViper
|
$admin->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '.
|
69 |
|
|
$MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back);
|
70 |
1347
|
Luisehahne
|
}
|
71 |
|
|
if($password != "") {
|
72 |
1804
|
Luisehahne
|
if(strlen($password) < 6 ) {
|
73 |
1710
|
Luisehahne
|
$admin->print_error($MESSAGE['USERS_PASSWORD_TOO_SHORT'], $js_back);
|
74 |
1347
|
Luisehahne
|
}
|
75 |
|
|
if($password != $password2) {
|
76 |
1710
|
Luisehahne
|
$admin->print_error($MESSAGE['USERS_PASSWORD_MISMATCH'], $js_back);
|
77 |
1347
|
Luisehahne
|
}
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
if($email != "")
|
81 |
|
|
{
|
82 |
|
|
if($admin->validate_email($email) == false)
|
83 |
|
|
{
|
84 |
1710
|
Luisehahne
|
$admin->print_error($MESSAGE['USERS_INVALID_EMAIL'], $js_back);
|
85 |
1347
|
Luisehahne
|
}
|
86 |
|
|
} else { // e-mail must be present
|
87 |
1710
|
Luisehahne
|
$admin->print_error($MESSAGE['SIGNUP_NO_EMAIL'], $js_back);
|
88 |
1347
|
Luisehahne
|
}
|
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 |
1710
|
Luisehahne
|
if(isset($MESSAGE['USERS_EMAIL_TAKEN']))
|
95 |
1347
|
Luisehahne
|
{
|
96 |
1710
|
Luisehahne
|
$admin->print_error($MESSAGE['USERS_EMAIL_TAKEN'], $js_back);
|
97 |
1347
|
Luisehahne
|
} else {
|
98 |
1710
|
Luisehahne
|
$admin->print_error($MESSAGE['USERS_INVALID_EMAIL'], $js_back);
|
99 |
1347
|
Luisehahne
|
}
|
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 |
1425
|
Luisehahne
|
$admin->print_error($database->get_error(),$js_back);
|
120 |
1347
|
Luisehahne
|
} else {
|
121 |
1710
|
Luisehahne
|
$admin->print_success($MESSAGE['USERS_SAVED']);
|
122 |
1347
|
Luisehahne
|
}
|
123 |
|
|
|
124 |
|
|
// Print admin footer
|
125 |
|
|
$admin->print_footer();
|