Access level report for all users

7 posts by 2 authors in: Forums > CMS Builder
Last Post: October 5, 2015   (RSS)

By Damon - October 1, 2015 - edited: January 27, 2016

Hi Jerry,

Here is the updated code that will work:

<?PHP
# Require Login
define('START_SESSION', true);
require_once "lib/viewer_functions.php";
require_once "lib/admin_functions.php";
$CURRENT_USER = getCurrentUserFromCMS();

if (!@$CURRENT_USER['isAdmin']) { die("This page is only available for admin users!"); }


# load access levels
list($accessListRecords) = getRecords(array(
'tableName' => '_accesslist',
'loadCreatedBy' => false,
'loadListDetails' => false,
'orderBy' => 'tableName',
'where' => 'accessLevel >= 6',
));

# load users
list($usersRecords) = getRecords(array(
'tableName' => 'accounts',
'loadCreatedBy' => false,
'loadListDetails' => false,
'orderBy' => 'last_name',
'allowSearch' => false,
));

# create lookup array of users by num
$usersByNum = array();
foreach ($usersRecords as $user) {
$usersByNum[$user['num']] = $user;
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
<!-- (YOUR CSS STYLES GO HERE) -->
</style>

<!-- (OR THE LINK TO YOUR EXTERNAL STYLE SHEET GOES HERE) -->
<link href="your.css" rel="stylesheet" type="text/css" />
</head>
<body>

<h1 class="your_css_style">Users By Section</h1>

<?PHP foreach ($accessListRecords as $accessRecord): ?>

<?PHP if (@$lastTable != $accessRecord['tableName']): ?>
<h2 class="your_css_style"><?php echo ucfirst(str_replace("_", " ", $accessRecord['tableName'])); ?></h2>
<?PHP endif; ?>
<?PHP $lastTable = $accessRecord['tableName']; ?>

<?PHP if ($user = @$usersByNum[$accessRecord['userNum']]): ?>

<a class="your_css_style" href="/cmsb/admin.php?menu=accounts&action=edit&num=<?PHP echo $user['num'] ?>"><?PHP echo $user['first_name'] ?> <?PHP echo $user['last_name'] ?></a><br />
<?php if($user['isAdmin']) : ?>  - Admin <?php endif; ?>
<?php if($accessRecord['accessLevel'] == 6 ) : ?>  - Author <?php endif; ?>
<?php if($accessRecord['accessLevel'] == 9 ) : ?>  - Editor <?php endif; ?>
<?php if($accessRecord['accessLevel'] == 7 ) : ?>  - Author &amp; Viewer<?php endif; ?>
<br />
<?PHP endif; ?>

<?PHP endforeach ?>

</body>
</html>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By gkornbluth - October 1, 2015 - edited: October 1, 2015

Thanks for the fix Damon,

Right now the report only lists the name of the individual sorted by section but doesn't indicate whether they are editors, authors, etc...

Is there an easy way that the individual's access level can be output in this report as well?

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Damon - October 2, 2015

Hi Jerry,

Is there an easy way that the individual's access level can be output in this report as well?

Yes, just add this line of code (in bold):

<a class="your_css_style" href="admin.php?menu=accounts&action=edit&num=<?PHP echo $user['num'] ?>"><?PHP echo $user['first_name'] ?> <?PHP echo $user['last_name'] ?></a>

<?php if($user['isAdmin']) : ?>  - Admin <?php endif; ?>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By gkornbluth - October 3, 2015 - edited: October 12, 2015

Thanks Damon,

I had wanted to show all member's access levels, so, based on your approach I added:

<?php if($user['isAdmin']) : ?>  - Admin <?php endif; ?>
<?php if($accessRecord['accessLevel'] == 6 ) : ?>  - Author <?php endif; ?>
<?php if($accessRecord['accessLevel'] == 9 ) : ?>  - Editor <?php endif; ?>

Are there other levels that I should add? (7, 8, etc.) and if so, what do they represent?

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Damon - October 5, 2015

Hi Jerry,

The other one you could add is Author & Viewer:

<?php if($accessRecord['accessLevel'] == 7 ) : ?>  - Author &amp; Viewer<?php endif; ?>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Thanks for the heads up Damon.

I'll add that one.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php