phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

View unanswered posts (number of)

Goto page 1, 2  Next
 
Search this topic... | Search MOD Requests... | Search Box
Register or Login to Post    Index » MOD Requests  Previous TopicPrint TopicNext Topic
Author Message
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Tue Sep 08, 2009 4:23 am 
Post subject: View unanswered posts (number of)

Hi,

the link to unanswered posts
search.php?search_id=unanswered
leads to a page showing unanswered posts. Very useful.
The page shows the number of unanswered posts.
I would like to add that in the link.
E.g. "156 unanswered posts"
How can I do that?!

/Holger
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Tue Sep 08, 2009 4:24 am 
Post subject: Re: View unanswered posts (number of)

Ah! And the next question in this issue: how can I exclude certain forums or users from the searchresult?
With searchresult I mean the searchresult-page and the number.
Back to top
drathbun
Board Member



Joined: 24 Jul 2008

Posts: 729
Location: Texas


flag
PostPosted: Tue Sep 08, 2009 8:35 am 
Post subject: Re: View unanswered posts (number of)

The different "tagged" searches are all handled by a specific block of code in search.php. If you open the file and search for the string 'unanswered' oddly enough you will fine the SQL code and other bits used to drive that search. If you want to exclude certain forums from the list, you can edit the SQL that looks like this:
Code:
                        if ( $auth_sql != '' )
                        {
                                $sql = "SELECT t.topic_id, f.forum_id
                                        FROM " . TOPICS_TABLE . "  t, " . FORUMS_TABLE . " f
                                        WHERE t.topic_replies = 0
                                                AND t.forum_id = f.forum_id
                                                AND t.topic_moved_id = 0
                                                AND $auth_sql";
                        }
                        else
                        {
                                $sql = "SELECT topic_id
                                        FROM " . TOPICS_TABLE . "
                                        WHERE topic_replies = 0
                                                AND topic_moved_id = 0";
                        }

Simply add
Code:
                                                AND t.forum_id NOT IN (1, 2, 3)

to the first SQL, or this:
Code:
                                                AND forum_id NOT IN (1, 2, 3)

to the second SQL. Replace (1, 2, 3) with the list of forum_id values that you want to exclude. That would take care of part two of your question.

For part 1, it's a bit trickier. I would take the following approach:

First, open languages/lang_english/lang_main.php and find the string $lang['Search_unanswered']. You need to put in a placeholder in the string for the number. So this:
Code:
$lang['Search_unanswered'] = 'View unanswered posts';

Becomes this:
Code:
$lang['Search_unanswered'] = 'View %s unanswered posts';

That takes care of the language string.

Next, you have to fill that value with something, and that's going to be done in includes/page_header.php. I'm going to give you a simple version. A more complete version would involve checking which forums the user is authorized to see.

Find this:
Code:
//
// The following assigns all _common_ variables that may be used at any point
// in a template.
//
$template->assign_vars(array(

Before that, add this:
Code:
$sql = 'SELECT count(*) as unanswered_topics from ' . TOPICS_TABLE . ' where forum_id NOT IN (1, 2, 3) and topic_replies = 0 and topic_moved_id = 0';

if (!($result = $db->sql_query($sql)))
{
     message_die (GENERAL_ERROR, 'Unable to count unanswered topics');
}

$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$unanswered_topics = $row['unanswered_topics'];

That should be close to what you need to count the unanswered topics.

Finally, poke it into the language string. Find this:
Code:
'L_SEARCH_UNANSWERED' => $lang['Search_unanswered'],

Edit it so it looks like this:
Code:
'L_SEARCH_UNANSWERED' => sprintf($lang['Search_unanswered'],$unanswered_topics),

I did all of this without testing, so buyer beware. icon_smile.gif

The basic concept is sound. First, you have to count how many unanswered topics there are, and that's done by counting topics where the topic_replies value is zero, and the topic is not a shadow topic. Then you display that value in the language string. Everything else is already taken care of for you with the default code.

_________________
phpBBDoctor Blog
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Tue Sep 08, 2009 8:44 am 
Post subject: Re: View unanswered posts (number of)

WOW!
I just finalized the first point, exactly as you described it, but I had f.forum_id instead of t.forum_id. Changed that now.

I will now try the second code.

Quote:
A more complete version would involve checking which forums the user is authorized to see.

I think an authorization check is nessecary, because otherwise the counter would show another number than the result-page.


Thank you very much for your help! icon_biggrin.gif

/Holger
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Tue Sep 08, 2009 8:56 am 
Post subject: Re: View unanswered posts (number of)

Works like charm for admins! But I dont get the authorization working.
Back to top
dogs and things
Board Member



Joined: 18 Nov 2008

Posts: 628
Location: Spain


flag
PostPosted: Tue Sep 08, 2009 12:42 pm 
Post subject: Re: View unanswered posts (number of)

Limiting the unanswered search to certain forums is a good idea, I implemented it.

Instead of
Code:
AND t.forum_id NOT IN (1, 2, 3)
I used
Code:
AND t.forum_id IN (1, 2, 3)
because I only want to include a few forums and this makes the array shorter for me.

Thanks.

_________________
phpBB2 will never die, I hope!
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Tue Sep 08, 2009 12:51 pm 
Post subject: Re: View unanswered posts (number of)

Any idea on how I can implement the auth?
Back to top
dogs and things
Board Member



Joined: 18 Nov 2008

Posts: 628
Location: Spain


flag
PostPosted: Tue Sep 08, 2009 3:44 pm 
Post subject: Re: View unanswered posts (number of)

If you're asking me, no, I don't. icon_sad.gif
_________________
phpBB2 will never die, I hope!
Back to top
drathbun
Board Member



Joined: 24 Jul 2008

Posts: 729
Location: Texas


flag
PostPosted: Tue Sep 08, 2009 8:30 pm 
Post subject: Re: View unanswered posts (number of)

dogs and things wrote:
I used
Code:
AND t.forum_id IN (1, 2, 3)
because I only want to include a few forums and this makes the array shorter for me.

As a bonus, it will be much faster. icon_smile.gif Database indexes work with what data is rather than what data is not so in general any positive condition such as "IN" will be more efficient than a negative condition such as "NOT IN" as I used.

Holger wrote:
Any idea on how I can implement the auth?

Yes, look at search.php and find the code that fills the variable $auth_sql and copy it into the code in page_header that does the counting. icon_smile.gif I'm going to apologize because I don't have time to write more than that right now.

_________________
phpBBDoctor Blog
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Wed Sep 09, 2009 2:34 am 
Post subject: Re: View unanswered posts (number of)

Thank you! I will have a look into that and post here if I have problems.

Edit:
should be this part
Code:
         if ( $auth_sql != '' )
         {
            $sql = "SELECT t.topic_id, f.forum_id
               FROM " . TOPICS_TABLE . "  t, " . FORUMS_TABLE . " f
               WHERE t.topic_replies = 0
                  AND t.forum_id = f.forum_id
                  AND t.forum_id NOT IN (21,108)
                  AND t.topic_moved_id = 0
                  AND $auth_sql";
         }
         else
         {
            $sql = "SELECT topic_id, forum_id
               FROM " . TOPICS_TABLE . "
               WHERE topic_replies = 0
                  AND topic_moved_id = 0
                  AND forum_id NOT IN (21,108)";
         }



So I try this:
Code:
      $auth_sql = '';
      if ( $search_forum != -1 )
      {
         $is_auth = auth(AUTH_READ, $search_forum, $userdata);

         if ( !$is_auth['auth_read'] )
         {
            message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']);
         }

         $auth_sql = "f.forum_id = $search_forum";
      }
      else
      {
         $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);

         if ( $search_cat != -1 )
         {
            $auth_sql = "f.cat_id = $search_cat";
         }

         $ignore_forum_sql = '';
         while( list($key, $value) = each($is_auth_ary) )
         {
            if ( !$value['auth_read'] )
            {
               $ignore_forum_sql .= ( ( $ignore_forum_sql != '' ) ? ', ' : '' ) . $key;
            }
         }

         if ( $ignore_forum_sql != '' )
         {
            $auth_sql .= ( $auth_sql != '' ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) ";
         }
      }

// BEGIN Count unanswered posts
if ( $auth_sql != '' )
{
   $sql = 'SELECT count(*) as unanswered_topics from ' . TOPICS_TABLE . ' where forum_id NOT IN (1, 2, 3) and topic_replies = 0 and topic_moved_id = 0 and $auth_sql';
}
if (!($result = $db->sql_query($sql)))
{
     message_die (GENERAL_ERROR, 'Unable to count unanswered topics');
}
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$unanswered_topics = $row['unanswered_topics'];
// END Count unanswered posts

But what does the else-part do in the code above?
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Wed Sep 09, 2009 2:54 am 
Post subject: Re: View unanswered posts (number of)

The code above that I included in page_header.php gives no result. There is no number transferred to the lang-entry.
Back to top
drathbun
Board Member



Joined: 24 Jul 2008

Posts: 729
Location: Texas


flag
PostPosted: Wed Sep 09, 2009 8:48 pm 
Post subject: Re: View unanswered posts (number of)

If you use a $variable it needs to be inside double quotes. '$auth_sql' will be the text and "$auth_sql" will interpret the variable into a string.
_________________
phpBBDoctor Blog
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Thu Sep 10, 2009 3:16 am 
Post subject: Re: View unanswered posts (number of)

Hm?
Like this?
Code:
$sql = 'SELECT count(*) as unanswered_topics from ' . TOPICS_TABLE . ' where forum_id NOT IN (1, 2, 3) and topic_replies = 0 and topic_moved_id = 0 and "$auth_sql"';

(I am a completely PHP n00b!)

Or possibly:
Code:
$sql = "SELECT count(*) as unanswered_topics from " . TOPICS_TABLE . " where forum_id NOT IN (1, 2, 3) and topic_replies = 0 and topic_moved_id = 0 and $auth_sql";

icon_question.gif icon_redface.gif icon_cry.gif
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Sun Sep 13, 2009 11:35 am 
Post subject: Re: View unanswered posts (number of)

Help please icon_redface.gif
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Wed Sep 16, 2009 8:39 am 
Post subject: Re: View unanswered posts (number of)

*dumpedibump* icon_redface.gif
Back to top
Display posts from previous:   
Register or Login to Post    Index » MOD Requests  Previous TopicPrint TopicNext Topic
Page 1 of 2 All times are GMT - 4 Hours
Goto page 1, 2  Next
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0703 seconds using 16 queries. (SQL 0.0154 Parse 0.0012 Other 0.0537)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo