News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Query to determine if a User can view a topic

Started by EV, September 30, 2008, 01:54:06 PM

Previous topic - Next topic

EV

I need a query to determine whether a specific user has access to read a topic.

SMF version 1.1.5

Can someone help?

I have this so far:

   $request = db_query("
      SELECT t.ID_TOPIC
       FROM {$db_prefix}topics as t
  LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = t.ID_BOARD)
      WHERE ID_TOPIC = $topic
      AND $user_info[query_see_board]
      LIMIT 1", __FILE__, __LINE__);
      list ($exists) = mysql_fetch_row($request);
      mysql_free_result($request);


The problem is, even on topics they have access to, I get nothing.  mysql_fetch_row($request) is always empty or nothing.

Fustrate

Try this code, and see what it spits out:

   die("
      SELECT t.ID_TOPIC
       FROM {$db_prefix}topics as t
  LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = t.ID_BOARD)
      WHERE ID_TOPIC = $topic
      AND $user_info[query_see_board]
      LIMIT 1");


and is $user_info globalized if this is in a function? I had that problem a while ago, and didn't notice it for some time.
Steven Hoffman
Former Team Member, 2009-2012

EV

#2
I get the following:


SELECT t.ID_TOPIC FROM smf_topics as t LEFT JOIN smf_boards AS b ON (b.ID_BOARD = t.ID_BOARD) WHERE ID_TOPIC = 175172 AND FIND_IN_SET(-1, b.memberGroups) LIMIT 1

The bold portion had me concerned.  Is that the desired result from $user_info[query_see_board]

Fustrate

The -1 shows that it thinks you're a guest - what does die($user_info['is_logged'] ? 'Logged in' : 'Not logged in'); show? I'm willing to bet I'm overlooking something...
Steven Hoffman
Former Team Member, 2009-2012

EV

Quote from: YodaOfDarkness on September 30, 2008, 06:18:08 PM
The -1 shows that it thinks you're a guest - what does die($user_info['is_logged'] ? 'Logged in' : 'Not logged in'); show? I'm willing to bet I'm overlooking something...

It does indeed say "Not logged in"!

But it also lists my proper $user_settings[ID_GROUP] as 11 which is correct.

Why would it think I wasn't logged in, yet know what user group I belong to?  hmm...

Fustrate

and you're doing this through SSI, or are you in a source file?
Steven Hoffman
Former Team Member, 2009-2012

EV

Quote from: YodaOfDarkness on September 30, 2008, 09:22:53 PM
and you're doing this through SSI, or are you in a source file?

In the LogInOut.php file.  This is a mod "Force Topic Read on Login Mod".  I'm trying to make it work.

Here's the applicable code:

- <file name="$sourcedir/LogInOut.php" error="fatal">
- <operation error="fatal">
- <search position="replace" regexp="false" whitespace="exact">
- <![CDATA[
// Just log you back out if it's in maintenance mode and you AREN'T an admin.
if (empty($maintenance) || allowedTo('admin_forum'))
redirectexit('action=login2;sa=check;member=' . $ID_MEMBER, $context['server']['needs_login_fix']);
else
redirectexit('action=logout;sesc=' . $sc, $context['server']['needs_login_fix']);


  ]]>
  </search>
- <add>
- <![CDATA[
if (!empty($modSettings['force_read_enable']) && !empty($modSettings['force_read_topic_id']))
{
$topic = (int) $modSettings['force_read_topic_id'];
       
   // Check if the user can see the topic first.
   $request = db_query("
      SELECT t.ID_TOPIC
       FROM {$db_prefix}topics as t
  LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = t.ID_BOARD)
      WHERE ID_TOPIC = $topic
      AND $user_info[query_see_board]
      LIMIT 1", __FILE__, __LINE__);
      list ($exists) = mysql_fetch_row($request);
      mysql_free_result($request);

// Check if he read that topic.
   $request = db_query("
  SELECT ID_TOPIC
  FROM {$db_prefix}log_topics
  WHERE ID_TOPIC = $topic
AND ID_MEMBER = $ID_MEMBER
  LIMIT 1", __FILE__, __LINE__);
   list ($read) = mysql_fetch_row($request);
   mysql_free_result($request);
   
   // Just log you back out if it's in maintenance mode and you AREN'T an admin.
   if((empty($maintenance) || allowedTo('admin_forum')) && (empty($read) && !empty($exists)))
      redirectexit('topic=' . $topic . '.0');
   elseif ((empty($maintenance) || allowedTo('admin_forum')) && ((!empty($read)) || empty($exists)))
  redirectexit('action=login2;sa=check;member=' . $ID_MEMBER, $context['server']['needs_login_fix']);
   else
      redirectexit('action=logout;sesc=' . $sc, $context['server']['needs_login_fix']);
   }
   else
   {
    // Just log you back out if it's in maintenance mode and you AREN'T an admin.
if (empty($maintenance) || allowedTo('admin_forum'))
redirectexit('action=login2;sa=check;member=' . $ID_MEMBER, $context['server']['needs_login_fix']);
else
redirectexit('action=logout;sesc=' . $sc, $context['server']['needs_login_fix']);
}


  ]]>
  </add>
  </operation>
  </file>


That is from the install.xml file.  You can see what they substituted. 

Fustrate

Have you tried asking in the mod's support topic?
Steven Hoffman
Former Team Member, 2009-2012

EV

Quote from: YodaOfDarkness on September 30, 2008, 10:07:53 PM
Have you tried asking in the mod's support topic?

Yes, kinda fell on deaf ears.

I have a workaround in place, thanks to you in part.

Advertisement: