You are on page 1of 5

Limiting Pages In the Manager Treeview

Step 1:
Add the following field to the table modx_user_attributes (or whatever prefix you are using):
ALTER TABLE `modx_user_attributes` ADD `root_urls` VARCHAR( 255 ) NOT NULL
Step 2:
Add a new field to the manager user (manager/actions/mutate_user.dynamic.php):
before the line:
<?php if($_GET['a']=='12') { ?>
add the following:
<tr>
<td valign="top"><?php echo $_lang['root_urls']; ?>:</td>
<td>&nbsp;</td>
<td>
<input type="text" name="root_urls" style="width:300px" value="<?php echo htmlspecialchars($userdata['root_urls']); ?>"
onchange='documentDirty=true;'>
</td>
</tr>
Step 3:
Language Files:
Add the following line to the language file:
$_lang["root_urls"] = 'Root URLs';
Step 4:
Saving the Manager user (manager/processors/save_user.processor.php):
After the line:
$blockedafter = !empty ($_POST['blockedafter']) ? ConvertDate($_POST['blockedafter']) : 0;
Add the line:
$root_urls = $_POST['root_urls'];
Replace:
$sql = "INSERT INTO $dbase.`" . $table_prefix . "user_attributes` (internalKey, fullname, role, email, phone, mobilephone, fax, zip,
state, country, gender, dob, photo, comment, blocked, blockeduntil, blockedafter)
VALUES($key, '$fullname', '$roleid', '$email', '$phone', '$mobilephone', '$fax', '$zip', '$state', '$country', '$gender', '$dob',
'$photo', '$comment', '$blocked', '$blockeduntil', '$blockedafter');";
With:
$sql = "INSERT INTO $dbase.`" . $table_prefix . "user_attributes` (internalKey, fullname, role, email, phone, mobilephone, fax, zip, state,
country, gender, dob, photo, comment, blocked, blockeduntil, blockedafter, root_urls)
VALUES($key, '$fullname', '$roleid', '$email', '$phone', '$mobilephone', '$fax', '$zip', '$state', '$country', '$gender', '$dob', '$photo',
'$comment', '$blocked', '$blockeduntil', '$blockedafter', '$root_urls');";
Replace:
$sql = "UPDATE $dbase.`" . $table_prefix . "user_attributes` SET
fullname='" . $fullname . "',
role='$roleid',
email='$email',
phone='$phone',
mobilephone='$mobilephone',
fax='$fax',
zip='$zip' ,
state='$state',
country='$country',
gender='$gender',
dob='$dob',
photo='$photo',
comment='$comment',
failedlogincount='$failedlogincount',
blocked=$blocked,
blockeduntil='$blockeduntil',
blockedafter='$blockedafter'
WHERE internalKey=$id";
With:
$sql = "UPDATE $dbase.`" . $table_prefix . "user_attributes` SET
fullname='" . $fullname . "',
role='$roleid',
email='$email',
phone='$phone',
mobilephone='$mobilephone',
fax='$fax',
zip='$zip' ,
state='$state',
country='$country',
gender='$gender',
dob='$dob',
photo='$photo',
comment='$comment',
failedlogincount='$failedlogincount',
blocked=$blocked,
blockeduntil='$blockeduntil',
blockedafter='$blockedafter',
root_urls = '$root_urls'
WHERE internalKey=$id";
Step 5:
The modx manager document tree (manager/frames/nodes.php):
In the function makeHTML after the line:
global $modxDBConn, $output, $dbase, $table_prefix, $_lang, $opened, $opened2, $closed2; //added global vars
Add the following:
$site_content = $modx->getFullTableName("user_attributes");
$root_urls = $modx->db->getValue("SELECT root_urls FROM {$site_content} WHERE internalKey='{$_SESSION['mgrInternalKey']}'");
And replace:
$sql = "SELECT DISTINCT sc.id, pagetitle, parent, isfolder, published, deleted, type, menuindex, hidemenu, alias, contentType,
privateweb, privatemgr,
MAX(IF(1={$mgrRole} OR sc.privatemgr=0" . (!$docgrp ? "":" OR dg.document_group IN ({$docgrp})") . ", 1, 0)) AS has_access
FROM {$tblsc} AS sc
LEFT JOIN {$tbldg} dg on dg.document = sc.id
WHERE (parent={$parent})
$access
GROUP BY sc.id
ORDER BY {$orderby}";
With:
$parent_sql = "parent={$parent}";
if ($parent == 0 && $root_urls)
{
$parent_sql = "sc.id in({$root_urls})";
}
$sql = "SELECT DISTINCT sc.id, pagetitle, parent, isfolder, published, deleted, type, menuindex, hidemenu, alias, contentType,
privateweb, privatemgr,
MAX(IF(1={$mgrRole} OR sc.privatemgr=0" . (!$docgrp ? "":" OR dg.document_group IN ({$docgrp})") . ", 1, 0)) AS has_access
FROM {$tblsc} AS sc
LEFT JOIN {$tbldg} dg on dg.document = sc.id
WHERE ($parent_sql)
$access
GROUP BY sc.id
ORDER BY {$orderby}";
IN USE:
As admin in Security -> Manager Users add set the root url:
(dont forget to save).
Ive done this for the user editor for my site. So while the admin user has this tree:
The editor user only sees this:
This can be used in conjunction with my multi site solution, shown elsewhere on modx.cmsthingies.com, or if you only want a particular user
using seeing one part of the site.

You might also like