Log in

View Full Version : How to use permissions with New Posts Query?


DRJ
02-17-2005, 10:21 AM
I have this query in phpinclude

// GET NUMBER OF NEW POSTS
$newposts = $DB_site->query_first("SELECT count(*) AS count FROM " . TABLE_PREFIX . "post WHERE dateline > '$bbuserinfo[lastvisit]'");

It works fine to get the total new posts, but it also counts posts that users cannot see based on the forum permissions.

Is there another condition I could add to check the users permissions to make sure that they can see the post and if not, don't count that post for the total.

Thanks

Akex
02-17-2005, 10:34 AM
Put this before

foreach(array_keys($forumcache) AS $forumid)
{
$forumperms = fetch_permissions($forumid);
if ($forumperms & CANVIEW AND $forumperms & CANVIEWOTHERS)
{
$allow_forumids[] = $forumid;
}
}
$allowids = implode(",", $allow_forumids);
unset ($forumperms);


Then you can use this request :


$newposts = $DB_site->query_first("SELECT count(*) AS count FROM " . TABLE_PREFIX . "post as p
LEFT JOIN " . TABLE_PREFIX . "thread as t ON (t.threadid = p.threadid)
WHERE p.dateline > '" . $bbuserinfo[lastvisit]. "' AND t.forumid IN($allowids)");

DRJ
02-18-2005, 12:56 PM
Thanks :)