The UDT was originally posted here.
It is called as follows in the template:
Code: Select all
{feu_upload_cats userid=feu_smarty::get_current_userid() permit='1' assign='categories'}The UDT looks like this:
Code: Select all
# UDT to return the list of FEU uploads categories a FEU user has access to, (or not).
#$params['userid']; # The numeric FEU user id.
#$params['permit']; # 1 -> return permitted categories, 0 -> return not permitted categories.
#$params['prefix'] ; # An optional prefix to add to each returned category name.
$smarty =& cmsms()->GetSmarty();
$db =& cmsms()->GetDb();
$ug = array(); #List of groups the user belongs to.
$cg = array(); #List of groups having access to a category.
$test = array(); #The intersection of ug and cg.
$cn = array(); #List of categories the user has access to, (or not).
$permit = $params['permit']; #1 -> return permitted categories, 0 -> return not permitted categories.
#Find all groups the user belongs to.
$sql = 'SELECT groupid FROM cms_module_feusers_belongs WHERE userid="' . $params['userid'] .'";';
$dbresult =& $db->Execute($sql);
while ($dbresult && $row = $dbresult->FetchRow()) {
$ug[] = $row['groupid'];
}
#Find all category names and the list of groups having access to each category.
$sql = 'SELECT upload_category_name,upload_category_groups FROM cms_module_uploads_categories WHERE upload_category_listable="1" ORDER BY upload_category_description;';
$dbresult =& $db->Execute($sql);
#For each category, match the list of groups having access with the list of groups the user belongs to.
while ($dbresult && $row = $dbresult->FetchRow()) {
$cg = split( '[,]', $row['upload_category_groups']);
$test = array_intersect( $ug, $cg);
if ( (count($test) > 0 && $permit > 0) || (count($test) == 0 && $permit == 0) ) {
$cn[] = $params['prefix'] . $row['upload_category_name'];
}
}
if ( empty($params['assign']) ) {
echo join( $cn, ','); #Return list of categories as a string.
} else {
$smarty->assign( $params['assign'], $cn); #Return list of categories as an array.
}

