Community Documentation

PAC tree module snippet: Who gets to see this node?

Last updated October 26, 2006. Created by Squidgy on October 26, 2006.
Log in to edit this page.

This goes into your page.tpl.php or flexinode-x.tpl.php as necessary - I'm sure it could be converted to a block as well.

I use it for sensitive flexinodes that shouldn't be seen by everyone to make sure I don't accidentally give too wide permissions. One should note that this ONLY works with the PAC tree module, although it could doubtless be harassed into working with any permissions scheme with a few changes to the sql.

Screenshot of working snippet.

While not necessary, you might want also to throw this CSS into your themes/ styles.css to make things appear cleaner.

#folder_viewer { border:2px solid #CCCCCC; padding:10px; background-color:#FFFFFF;}
#checkbox { float:left;background-color:#C7FFC6; padding:3px; margin:2px;}
#checkbox_fail {float:left; background-color:#FFCECE; padding:3px; margin:2px;}

<?php
   
print '<div id="folder_viewer"><TABLE><TR><TD colspan=4>These roles have access to this node.<BR></TD></TR>';
//Check who has write access.
$result = pager_query(db_rewrite_sql('SELECT na.gid, r.name, na.grant_view, na.grant_update, na.grant_delete FROM `node_access` na INNER JOIN `role` r ON na.gid = r.rid WHERE nid = "' . $nid  . '" AND na.grant_view = "1"', n), 20);
while (
$node = db_fetch_object($result)) {
    print
'<TR><TD><B>' . $node->name . '</B> (' . $node->gid . ')</TD>';

        if (
$node->grant_view == 1) {
            print
'<TD><div id="checkbox"> &radic; Can see files:</div></TD>';
        }

        if (
$node->grant_update == 1) {
            print
'<TD><div id="checkbox"> &radic; Can add files</div></TD>';
        }
        else {print
'<TD><div id="checkbox_fail"> &times; Cannot add files</div></TD>';}

        if (
$node->grant_delete == 1) {
            print
'<TD><div id="checkbox"> &radic Can delete files</div></TD>';
        }               
        else {print
'<TD><div id="checkbox_fail"> &times; Cannot delete files</div></TD>';}
       
    print
'</TD></TR>';
    }
print
'</TABLE></div>';
   
?>

About this page

Drupal version
Drupal 4.7.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here