| 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 |
1457
|
Luisehahne
|
// suppress to print the header, so no new FTAN will be set
|
| 23 |
|
|
$admin = new admin('Access', 'users_modify', false);
|
| 24 |
1347
|
Luisehahne
|
|
| 25 |
1425
|
Luisehahne
|
// Create a javascript back link
|
| 26 |
|
|
$js_back = ADMIN_URL.'/users/index.php';
|
| 27 |
|
|
|
| 28 |
1353
|
FrankH
|
if( !$admin->checkFTAN() )
|
| 29 |
|
|
{
|
| 30 |
1457
|
Luisehahne
|
$admin->print_header();
|
| 31 |
1425
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back);
|
| 32 |
1353
|
FrankH
|
}
|
| 33 |
1457
|
Luisehahne
|
// After check print the header
|
| 34 |
|
|
$admin->print_header();
|
| 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 |
1446
|
DarkViper
|
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
|
| 60 |
|
|
$admin->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '.
|
| 61 |
|
|
$MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back);
|
| 62 |
1347
|
Luisehahne
|
}
|
| 63 |
|
|
if($password != "") {
|
| 64 |
|
|
if(strlen($password) < 2) {
|
| 65 |
|
|
$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
|
| 66 |
|
|
}
|
| 67 |
|
|
if($password != $password2) {
|
| 68 |
|
|
$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
|
| 69 |
|
|
}
|
| 70 |
|
|
}
|
| 71 |
|
|
|
| 72 |
|
|
if($email != "")
|
| 73 |
|
|
{
|
| 74 |
|
|
if($admin->validate_email($email) == false)
|
| 75 |
|
|
{
|
| 76 |
|
|
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
| 77 |
|
|
}
|
| 78 |
|
|
} else { // e-mail must be present
|
| 79 |
|
|
$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back);
|
| 80 |
|
|
}
|
| 81 |
|
|
|
| 82 |
|
|
// Check if the email already exists
|
| 83 |
|
|
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."' AND user_id <> '".$user_id."' ");
|
| 84 |
|
|
if($results->numRows() > 0)
|
| 85 |
|
|
{
|
| 86 |
|
|
if(isset($MESSAGE['USERS']['EMAIL_TAKEN']))
|
| 87 |
|
|
{
|
| 88 |
|
|
$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
|
| 89 |
|
|
} else {
|
| 90 |
|
|
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
| 91 |
|
|
}
|
| 92 |
|
|
}
|
| 93 |
|
|
|
| 94 |
|
|
// Prevent from renaming user to "admin"
|
| 95 |
|
|
if($username != 'admin') {
|
| 96 |
|
|
$username_code = ", username = '$username'";
|
| 97 |
|
|
} else {
|
| 98 |
|
|
$username_code = '';
|
| 99 |
|
|
}
|
| 100 |
|
|
|
| 101 |
|
|
// Update the database
|
| 102 |
|
|
if($password == "") {
|
| 103 |
|
|
$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'";
|
| 104 |
|
|
} else {
|
| 105 |
|
|
// MD5 supplied password
|
| 106 |
|
|
$md5_password = md5($password);
|
| 107 |
|
|
$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'";
|
| 108 |
|
|
}
|
| 109 |
|
|
$database->query($query);
|
| 110 |
|
|
if($database->is_error()) {
|
| 111 |
1425
|
Luisehahne
|
$admin->print_error($database->get_error(),$js_back);
|
| 112 |
1347
|
Luisehahne
|
} else {
|
| 113 |
|
|
$admin->print_success($MESSAGE['USERS']['SAVED']);
|
| 114 |
|
|
}
|
| 115 |
|
|
|
| 116 |
|
|
// Print admin footer
|
| 117 |
|
|
$admin->print_footer();
|