Topic: Make non-readable forums visible in the index

I'd asked about this here, so I'll just present my solution.

I have users segregated into public and private users, or "members" and "trons". I want the trons to have access to everything, and the members only the first two forums. This is covered by the engine. However, I also was the non-accessible forums to show up in the index listing, and a special message to show up when they're accessed by a non-tron.

In Index.php, around line 40, there's a big huge query. The entire WHERE condition needs to go, so it becomes this:

$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());

In Viewforum.php, also around line 40, there's a condition immediately following the big query, which sends you to the "Bad Request" screen if you don't have permission or the forum doesn't exist. We want to split this so that it differentiates the two types of errors:

if (!$db->num_rows($result))
{
    $result = $db->query('SELECT f.forum_name FROM '.$db->prefix.'forums AS f WHERE f.id='.$id);
    if (!$db->num_rows($result))
        message($lang_common['Bad request']);
    else
        message($lang_common['No view']);        
}

Okay, you're done, unless you want to give the user a special message. In that case, change 'No view' above to 'Nope', and then add your custom line to the /lang/English/common.php file right below 'No view'.

You can see it all in action here: http://dev.tron09.com/forum/ (unless it's broken... this is a live dev site)

Re: Make non-readable forums visible in the index

can this be used for guest also

Re: Make non-readable forums visible in the index

You've misunderstood it. What it does is to display all the forums on the index page, not just the forums you have permission to view.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Make non-readable forums visible in the index

Will this work if I have three different forums, but one of them I want to be private?  I still want people to be able to see the third forum exists, but I don't want them to be able to read any of it unless they have a special status.

Re: Make non-readable forums visible in the index

Yes wink

Re: Make non-readable forums visible in the index

So if I just make these two code changes, it will do what I want, by listing all three forums on the index page, but only allowing them to view the 2 public forums and denying access to the third?  I hope so.  I was under the impression from the above post that it would only work for all-or-none of the forums.

Re: Make non-readable forums visible in the index

Help?Your "http://dev.tron09.com/forum" has been well setted.
I want my forum like this too! But I don't know PHP very well, can you just teach too and show more how to change the code?
Thank you very much!   

My forum: http://lagein.free-site-host.com/