Kim Keown fa6847ab39 Revision to edit-user.php - Admin folder rename
Update 10-27. Upon further reading about global variables, it seems they are only declared when the string replacement is within a function. After testing deletion of the global intended to encompass if/else replacements occurring within a function file outside of the functions, the pages appear to work normally. The additional global on the function pages is apparently unnecessary, therefore I am removing them.

Add variable in bl-kernel/boot/init.php that allows User to rename bl-kernel/admin folder. 
User can then define variable in bl-kernel/boot/init.php and change the foldername itself to effect the rename. 

Add global $adminfolder variable as necessary and replace relevant 'admin' strings with $adminfolder.
Applies to most of the files in bl-kernel/admin/controllers.

Line 114 - Replace Admin string with folder variable:
	        Redirect::page($adminfolder, 'users');
Original: 	Redirect::page('admin', 'users');
2016-10-27 09:19:08 -06:00

116 lines
2.7 KiB
PHP

<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Functions
// ============================================================================
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) ) {
Alert::set($Language->g('The changes have been saved'));
}
else {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to edit the user.');
}
}
function editUser($args)
{
global $dbUsers;
global $Language;
if( $dbUsers->set($args) ) {
Alert::set($Language->g('The changes have been saved'));
}
else {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to edit the user.');
}
}
function deleteUser($args, $deleteContent=false)
{
global $dbUsers;
global $dbPosts;
global $Language;
global $Login;
// The user admin cannot be deleted.
if($args['username']=='admin') {
return false;
}
// The editors cannot delete users.
if($Login->role()!=='admin') {
return false;
}
if($deleteContent) {
$dbPosts->deletePostsByUser($args['username']);
}
else {
$dbPosts->linkPostsToUser($args['username'], 'admin');
}
if( $dbUsers->delete($args['username']) ) {
Alert::set($Language->g('User deleted'));
}
else {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to delete the user.');
}
}
// ============================================================================
// Main before POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
// Prevent editors to administrate other users.
if($Login->role()!=='admin')
{
$_POST['username'] = $Login->username();
unset($_POST['role']);
}
if(isset($_POST['delete-user-all'])) {
deleteUser($_POST, true);
}
elseif(isset($_POST['delete-user-associate'])) {
deleteUser($_POST, false);
}
elseif(isset($_POST['disable-user'])) {
disableUser($_POST['username']);
}
else {
editUser($_POST);
}
}
// ============================================================================
// Main after POST
// ============================================================================
if($Login->role()!=='admin') {
$layout['parameters'] = $Login->username();
}
$_User = $dbUsers->getUser($layout['parameters']);
// If the user doesn't exist, redirect to the users list.
if($_User===false) {
Redirect::page($adminfolder, 'users');
}