PortalParts.com Site

 Forum Index > Geeklog > Misc Projects New Topic Post Reply
 Group Access Block (Table-less markup)
 |  Printable Version
mst3kroqs
 May 13 2008 20:44 PM (Read 1495 times)  
Forum Full Poster
Full Poster

Status: offline

Registered: 04/29/07
Posts: 16

Hi Blaine -

This is truly one of my favorite utilities, thank you for creating it.

Recently, I modified it to generate markup that is more consistent with some of the more recent themes that are gravitating towards table-less CSS markup.

This version works well with 'Nouveau' and Chameleon, as well as the professional theme that shipped with 1.4.1:

PHP Formatted Code
/***
*
* Group Access - Check Feature and Group Access Access Block
* Blaine Lang v1.1 Jan 29/2007
* Modified for table-less markup by M. A. Howard May 08/2008
*
*/


function phpblock_groupAccess () {
global $PHP_SELF,$_CONF, $_TABLES, $_USER;

$hasfeature=false;

$retval .= '<form action="' .$_CONF['site_url']. '/index.php" method="POST">';

$retval .= '<div style="font-size:75%;text-align:center;">Select Feature & Group to Check</div>';

$retval .= '<div style="margin-top:5px;">';
$retval .= '<b>Feature</b>';
$retval .= '<select name="featureid" style="width:100%;margin-top:3px;">';
$retval .= COM_optionList ($_TABLES['features'],'ft_id,ft_name',$_POST['featureid']) . '</select>';
$retval .= '</div>';

$retval .= '<div style="margin-top:5px;">';
$retval .= '<b>Group</b>';
$retval .= '<select name="groupid" STYLE="width:100%;margin-top:3px;">';
$retval .= COM_optionList ($_TABLES['groups'],'grp_id,grp_name',$_POST['groupid']) . '</select>';
$retval .= '</div>';

if ($_POST['addaccess'] != "") {
        $hasfeature=true;    // Will have access when we add record
        $retval .= '<div style="font-size:75%;margin-top:10px;text-align:center;">';
        $retval .= '<b>Record Updated</b>';
        $retval .= '</div>';
        DB_query("INSERT INTO {$_TABLES['access']} (acc_ft_id,acc_grp_id)
            VALUES ('{$_POST['featureid']}','{$_POST['groupid']}')"
);
} elseif ($_POST['delaccess'] != "") {
        $hasfeature=false;    // Will not have access when we update record
        $retval .= '<div style="font-size:75%;margin-top:10px;text-align:center;">';
        $retval .= '<b>Record Updated</b>';
        $retval .= '</div>';
        DB_query("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = {$_POST['featureid']} AND acc_grp_id = {$_POST['groupid']}");

} elseif (isset($_POST['chkaccess'])) {
    $groups = DB_query("SELECT * FROM {$_TABLES['group_assignments']} WHERE ug_grp_id = {$_POST['groupid']}");
    $ngroups = DB_numROWS( $groups );
    COM_errorLOG("Found $ngroups");
    $chkretval = '<div style="font-size:75%;margin-top:10px;text-align:center;"><b>Group does not have access</b></div>';

    if ($ngroups > 0) {
        for ( $g = 1; $g <= $ngroups; $g++ ) {
            $group = DB_fetchArray($groups);
            $features = DB_query("SELECT acc_ft_id FROM {$_TABLES['access']} WHERE acc_grp_id = {$group['ug_main_grp_id']} OR acc_grp_id = {$_POST['groupid']}");
            $nfeatures = DB_numROWS( $features );
            COM_errorLOG("Checking group {$group['ug_main_grp_id']}");
            for ( $f = 1; $f <= $nfeatures; $f++ ) {
               $feature = DB_fetchArray($features);
                if ($feature['acc_ft_id'] == $_POST['featureid']) { ;
                    $chkretval = '<div style="font-size:75%;text-align:center;margin-top:10px">Group ' .$group['ug_main_grp_id']. ' has access to feature ' .$_POST['featureid']. '</div>';
                    $hasfeature=true;
                    break;
                }
            }
        }
    } else {
        $features = DB_query("SELECT acc_ft_id FROM {$_TABLES['access']} WHERE acc_grp_id = {$_POST['groupid']}");
        $nfeatures = DB_numROWS( $features );
        for ( $f = 1; $f <= $nfeatures; $f++ ) {
            $feature = DB_fetchArray($features);
            if ($feature['acc_ft_id'] == $_POST['featureid']) { ;
                $chkretval = '<div style="font-size:75%;text-align:center;">Group ' .$_POST['groupid']. ' has access to feature ' .$_POST['featureid']. '</div>';
                $hasfeature=true;
                break;
            }
        }
    }

    $retval .= $chkretval;

}

$retval .= '<div style="margin-top:10px;">';
if ($_POST['chkaccess'] != '' AND !$hasfeature) {
    $retval .= '<p align="center">';
    $retval .= '<input type="submit" name="chkaccess" value="Check">';
    $retval .= '<input type="submit" name="addaccess" value="Add">';
    $retval .= '</p>';
} else {
    $retval .= '<p align="center">';
    $retval .= '<input type="submit" name="chkaccess" value="Check">';
    $retval .= '<input type="submit" name="delaccess" value="Remove">';
    $retval .= '</p>';
}
$retval .= '</div>';
$retval .= '</form>';

return $retval;

}

Best regards,

-m


 
Profile Email PM
Quote
Content generated in: 0.35 seconds
New Topic Post Reply



 All times are CDT. The time is now 05:06 AM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Anonymous users can post 
Filtered HTML Allowed 
Censored Content