2015-05-05 03:00:01 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Functions
|
|
|
|
// ============================================================================
|
|
|
|
|
2016-09-07 02:14:57 +02:00
|
|
|
function disableUser($username) {
|
|
|
|
|
|
|
|
global $dbUsers;
|
|
|
|
global $Language;
|
|
|
|
global $Login;
|
|
|
|
|
|
|
|
// The editors can't disable users
|
|
|
|
if($Login->role()!=='admin') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $dbUsers->disableUser($username) ) {
|
2017-06-05 22:36:09 +02:00
|
|
|
// Add to syslog
|
|
|
|
$Syslog->add(array(
|
|
|
|
'dictionaryKey'=>'user-disabled',
|
|
|
|
'notes'=>$username
|
|
|
|
));
|
|
|
|
|
|
|
|
// Create an alert
|
2016-09-07 02:14:57 +02:00
|
|
|
Alert::set($Language->g('The changes have been saved'));
|
|
|
|
}
|
2017-06-05 22:36:09 +02:00
|
|
|
|
|
|
|
return true;
|
2016-09-07 02:14:57 +02:00
|
|
|
}
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
function editUser($args)
|
|
|
|
{
|
|
|
|
global $dbUsers;
|
2015-07-20 05:14:12 +02:00
|
|
|
global $Language;
|
2015-08-03 02:49:12 +02:00
|
|
|
|
2015-07-22 05:15:02 +02:00
|
|
|
if( $dbUsers->set($args) ) {
|
2017-06-05 22:36:09 +02:00
|
|
|
// Add to syslog
|
|
|
|
$Syslog->add(array(
|
|
|
|
'dictionaryKey'=>'user-edited',
|
|
|
|
'notes'=>$args['username']
|
|
|
|
));
|
|
|
|
|
|
|
|
// Create an alert
|
2015-07-22 05:15:02 +02:00
|
|
|
Alert::set($Language->g('The changes have been saved'));
|
|
|
|
}
|
2017-06-05 22:36:09 +02:00
|
|
|
|
|
|
|
return true;
|
2015-07-22 05:15:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteUser($args, $deleteContent=false)
|
|
|
|
{
|
|
|
|
global $dbUsers;
|
|
|
|
global $dbPosts;
|
|
|
|
global $Language;
|
2015-10-19 00:45:58 +02:00
|
|
|
global $Login;
|
2015-07-22 05:15:02 +02:00
|
|
|
|
2015-07-23 03:45:54 +02:00
|
|
|
// The user admin cannot be deleted.
|
|
|
|
if($args['username']=='admin') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-30 03:59:02 +02:00
|
|
|
// The editors cannot delete users.
|
|
|
|
if($Login->role()!=='admin') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-22 05:15:02 +02:00
|
|
|
if($deleteContent) {
|
|
|
|
$dbPosts->deletePostsByUser($args['username']);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dbPosts->linkPostsToUser($args['username'], 'admin');
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $dbUsers->delete($args['username']) ) {
|
2017-06-05 22:36:09 +02:00
|
|
|
// Add to syslog
|
|
|
|
$Syslog->add(array(
|
|
|
|
'dictionaryKey'=>'user-deleted',
|
|
|
|
'notes'=>$args['username']
|
|
|
|
));
|
|
|
|
|
|
|
|
// Create an alert
|
2015-07-22 05:15:02 +02:00
|
|
|
Alert::set($Language->g('User deleted'));
|
|
|
|
}
|
2017-06-05 22:36:09 +02:00
|
|
|
|
|
|
|
return true;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-08-03 02:49:12 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Main before POST
|
|
|
|
// ============================================================================
|
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
// ============================================================================
|
|
|
|
// POST Method
|
|
|
|
// ============================================================================
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
|
|
|
{
|
2015-10-19 00:45:58 +02:00
|
|
|
// Prevent editors to administrate other users.
|
2015-05-15 00:07:45 +02:00
|
|
|
if($Login->role()!=='admin')
|
|
|
|
{
|
|
|
|
$_POST['username'] = $Login->username();
|
|
|
|
unset($_POST['role']);
|
|
|
|
}
|
|
|
|
|
2015-07-22 05:15:02 +02:00
|
|
|
if(isset($_POST['delete-user-all'])) {
|
|
|
|
deleteUser($_POST, true);
|
|
|
|
}
|
|
|
|
elseif(isset($_POST['delete-user-associate'])) {
|
|
|
|
deleteUser($_POST, false);
|
|
|
|
}
|
2016-09-07 02:14:57 +02:00
|
|
|
elseif(isset($_POST['disable-user'])) {
|
|
|
|
disableUser($_POST['username']);
|
|
|
|
}
|
2015-10-19 00:45:58 +02:00
|
|
|
else {
|
2015-07-22 05:15:02 +02:00
|
|
|
editUser($_POST);
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
2015-05-15 00:07:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
2015-08-03 02:49:12 +02:00
|
|
|
// Main after POST
|
2015-05-15 00:07:45 +02:00
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
if($Login->role()!=='admin') {
|
|
|
|
$layout['parameters'] = $Login->username();
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2016-01-01 00:31:51 +01:00
|
|
|
$_User = $dbUsers->getUser($layout['parameters']);
|
2015-05-05 03:00:01 +02:00
|
|
|
|
|
|
|
// If the user doesn't exist, redirect to the users list.
|
2016-01-01 00:31:51 +01:00
|
|
|
if($_User===false) {
|
2017-06-05 22:36:09 +02:00
|
|
|
Redirect::page('users');
|
2015-05-15 00:07:45 +02:00
|
|
|
}
|