Function To Retrieve Usergroup Forum CANVIEW Permissions
by
02 Sep 2002
This is a new, cleaner thread, holding my input to the following thread : http://www.vbulletin.org/forum/showthread.php?s=&threadid=41934 I noticed that with the function in the above mentioned thread, though an excellent routine, if you use usergroup permissions inherited from parent forum permissions, inside the Forum Permissions in your AdminCP, that function can return false results. I needed a function to tell my scripts which forums any usergroup has CANVIEW access to, and this is my solution. This function handles forum CANVIEW permissions that are set in the Forum Permissions screen of the AdminCP, it does not cater for AccessMasks or anything, because we don't use accessmasks on our forums. This function also shouldn't be relied upon if you have several tiers of forums/sub-forums... this should only cater for those who have forum categories, and sub-forums of the category.... if your setup has sub-forums of sub-forums, do not rely on this function. The restrictions of this function, as just mentioned, should not cause a problem to perhaps the majority of forum setups, as it's very rare that I see sub-forums of sub-forums (etc.) at vB boards. Ok, i've cleaned this code up, and have done some more testing, so let's get on with the good stuff... here is the function : PHP Code:
function getForumPermissionsDSS($usergroupID) {
Right, that's the function - you may place that in your 'admin/functions.php' file, if you wish. Then, in any script that you intend to use the function, place this : PHP Code:
$forumsCannotView_strList = getForumPermissionsDSS($bbuserinfo[usergroupid]);
PHP Code:
require ("global.php");
What those two lines do, is get a string list of all forums that the current visitor has CANVIEW permissions to, and then generates a WHERE clause for you, ready for easy inclusion into an SQL query. Unless you will need the string list for other reasons, you'll only be interested in this $whereClause_forumPermissions variable... which holds the WHERE clause. Here is an example of how forums using permissions inherited from it's parent forum might look inside your AdminCP : Code:
Example Forums (COPPA) Users Awaiting Moderation Administrators .... etc .... .... etc .... Registered .... etc .... Example Sub Forum, Of Above Category (COPPA) Users Awaiting Moderation Administrators .... etc .... .... etc .... Registered .... etc .... Example Sub Forum II, Of Above Category (COPPA) Users Awaiting Moderation Administrators .... etc .... .... etc .... Registered .... etc .... This function will cater for this. The following is also allowable by this function : Code:
Example Forums (COPPA) Users Awaiting Moderation Administrators .... etc .... .... etc .... Registered .... etc .... Example Sub Forum, Of Above Category (COPPA) Users Awaiting Moderation Administrators .... etc .... .... etc .... Registered .... etc .... Example Sub Forum II, Of Above Category (COPPA) Users Awaiting Moderation Administrators .... etc .... .... etc .... Registered .... etc .... Only one thing to be carful of, is not setting any permissions for a forum.... this function will not include that forum. A forum must have either custom permissions, or inherited permissions, (show in either RED or BLUE) or the forum will be classed as "viewable". So, your "viewable by all" forums can be left without special permissions set, if you wish. You only need to set permissions for those forums where certain usergroups should not have CANVIEW access. Right, the next thing to do, is show some examples of usage. We've already called the function, and setup the WHERE clause, so let's execute a query.... the following example, is so that you can test this out - it will display the list of forums which a usergroup can access : PHP Code:
$testPermissions_result = $DB_site->query("SELECT forumid,title FROM forum WHERE $whereClause_forumPermissions active=1 ORDER BY forumid ASC");
During testing, you can subsitute the $bbuserinfo[usergroupid] in the calling of the function, for any usergroup number, if you wish... but be sure to put it back before going "live" with the function... example : PHP Code:
$forumsCannotView_strList = getForumPermissionsDSS(6);
Another test, would be to return the most viewed thread stored in your database, but only threads in forums that are viewable by the current usergroup will be counted : PHP Code:
$topViewedThread_result = $DB_site->query_first("SELECT *
That's the jist, it does the job for me, and I hope you may find it usfull too. Our forums only use usergroup permissions, inherited from parent forums, and occasionally some custom permissions for usergroups, but, we don't use accessmasks, and we don't have sub-forums of sub-forums... this function works for us, and maybe for alot you too. Biggup the "open source / community source".... it's saved me alot of time and headache at times.... as i'm sure i've saved others from the same.... again.... big it up. |