Hook on createdByUserNumHTML

Re: [Djulia] Hook on createdByUserNumHTML

By Dave - February 29, 2012

Hi Djulia,

Sorry for the delay, this question required some digging into the code. :)

Can you provide some more details on what you're looking for?
- Are you wanting to update the <select user> pulldown so it only shows users who can access a section
- Are you wanted to get a list of users who can access a section for another purpose?

Would it make sense to have a plugin filter that would allow you to modify an array of users in /lib/common.php ajaxGetUsersAsPulldown() ?

Let me know some more details and I'll try to help or update the code for you. Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Hook on createdByUserNumHTML

By Djulia - February 29, 2012

Hi Dave,

>Sorry for the delay
Your availability is already very large ! :)

> Are you wanting to update the <select user> pulldown
Yes, I have 150 users in the pulldown, but there are only 2 editors and 1 authors for each section. If the list were less important and limited to the authorized accounts (editors, authors), the use would be more ergonomic. Currently, we must check directly in the Accounts section if the editor (or the author) has an access to the section.

>Would it make sense to have a plugin filter
I do not think that there are many scenarios but a plugin would give certainly other possibilities.

Do you think that it is possible?

Thanks again! :)

Djulia

Re: [Djulia] Hook on createdByUserNumHTML

By Dave - February 29, 2012

Hi Djulia,

I've written up some code for that for the next version. Can you help me test it?

Replace this function in /lib/menus/default/common.php

// show pulldown when editor clicks "change" beside "Created By" on edit page in CMS
function ajaxGetUsersAsPulldown() {
global $TABLE_PREFIX, $hasEditorAccess, $tableName;
if (!$hasEditorAccess) { return ''; } // must have section admin access

// get users with access to this section
$query = "SELECT u.num, u.username
FROM {$TABLE_PREFIX}accounts u
JOIN {$TABLE_PREFIX}_accesslist a ON u.num = a.userNum
WHERE a.accessLevel > 1 AND a.tableName IN ('all','$tableName')";
$users = mysql_fetch($query);

// get option values
$userNums = array_pluck($users, 'num');
$userNames = array_pluck($users, 'username');
$optionsHTML = getSelectOptions(null, $userNums, $userNames);

// show pulldown
$selectHTML = "<select name='createdByUserNum'>\n";
$selectHTML .= "<option value=''>" .htmlspecialchars(t("<select user>")). "</option>\n";
$selectHTML .= $optionsHTML;
$selectHTML .= "</select>\n";

//
print $selectHTML;
exit;
}


Hope that helps, can you let me know if that does what you need? Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Hook on createdByUserNumHTML

By Djulia - March 1, 2012

Hi Dave,

It is perfect for me! :)

Thanks to have taken into account this request.

Djulia

Re: [Djulia] Hook on createdByUserNumHTML

By gkornbluth - March 14, 2012

Hi Djulia,

I don't know if this will be of any help, but here's a recipe from my CMSB Cookbook http://www.thecmsbcookbook.com that Dave gave me a hand with a while back.

CREATING A VIEWER TO LIST THE SECTION EDITORS AND THE USERS AUTHORIZED TO EDIT THEM

When you first load the page, you’ll be presented with a log in screen. Only administrators can log in, but there’s an added perk here, because you’ll be logged in to CMSB as an administrator, you can click on a user and you’ll be taken directly to their profile where you can modify their permissions.

Note: you can’t add users through this page, you’ll have to log in to the CMSB interface to do that.

Here’s the code for the viewer page.

UPLOAD IT TO YOUR cmsAdmin DIRECTORY

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

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

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

# load users
list($usersRecords) = getRecords(array(
'Table name' => 'accounts',
'loadCreatedBy' => false,
'loadListDetails' => false,
'orderBy' => 'fullname',
'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 ?>
<?PHP if (@$lastTable != $accessRecord['Table name']): ?>
<h2 class="your_css_style"><?PHP echo $accessRecord['Table name']; ?></h2>
<?PHP endif; ?>
<?PHP $lastTable = $accessRecord['Table name']; ?>

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

<a class="your_css_style" href="cmsAdmin/admin.php?menu=accounts&action=edit&num=<?PHP echo $user['num'] ?>"><?PHP echo $user['fullname'] ?></a><br />
<?PHP endif; ?>

<?PHP endforeach ?>

</body>
</html>


Best,

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

Re: [gkornbluth] Hook on createdByUserNumHTML

By Djulia - March 15, 2012

Hi Jerry,

In fact, my request was really directed on the <select user> pulldown.

Nevertheless, thanks for your effort.

Djulia