PDA

View Full Version : Hide private forums from this MySQL query...very hard


Jungleman
08-05-2002, 05:30 PM
I am working on a hack which breaks down a users posts into forums they have posted in..

Example, if a user has 1000 posts, it shows 500 in Off Topic, 300 in Hardware Support, 150 in Software Support, 50 in Web Design, etc.

So far the hack works great, one little problem-- it shows names of private forums to people who aren't supposed to have access to them, and I want to avoid that.

Here is the query that I am using:

SELECT COUNT(p.postid) AS post_count, f.title, f.forumid FROM forum f, post p, thread t, user u WHERE f.forumid = t.forumid AND t.threadid = p.threadid AND p.userid = u.userid AND u.userid = $userid AND t.visible = 1 GROUP BY f.forumid ORDER BY post_count DESC

How can I eliminate forums NOT accessible to regular users?

BTW, if you wanna run that query on your forum to see how it works, replace $userid with the user ID of your choice.

filburt1
08-05-2002, 05:46 PM
...WHERE forumid NOT IN(comma-delimited list of private forumids)

Beyond that, don't know :(

Jungleman
08-05-2002, 05:52 PM
Yep...well, that'd work just for my forum, but I wanted to release this hack.

Just gotta finish this up...OK I can do it :)

Logician
08-05-2002, 08:42 PM
You can ask the users to edit that part of the hack according to their forums so filburt1's solution is good.

But if you are determined to code your hack so that it will automaticly detect this, you can get the help of the function getpermissions like:

$getperms=getpermissions($forumid,-1,-1,$forum['parentlist']);

if (!$getperms['canview'] OR !$getperms['canviewothers'])
{
//user dont have permission for this forum skip it
}

Jungleman
08-05-2002, 09:27 PM
Logician, what would be the usage of that code? Where should I put it?

Thanks :)

Logician
08-05-2002, 10:39 PM
Did I get you wrong?

I thought you are trying to find out if forum X is closed for the user so that you can exclude it from your query. If this is correct the function I refered makes this check so you can call it before your query so that you can detect private forums for the board viewer.

I'm assuming you required global.php" in your script..

Jungleman
08-05-2002, 11:51 PM
I put the require global.php in.

I put the block of code you told me to put right before my query and it did nothing, and I logged in as a test user that has no access to special forums to verify. It kept showing the hidden forums.

I think I'm doing something wrong. :confused:

Jungleman
08-12-2002, 01:08 AM
Bump