updated the code again... now I don't get the error!

Unfortunately, now I get the first row (record) of the db table three times...! and nothing else.  There are three other rows in the db table.

Hmmm.  I really don't get how the loop works, etc. so I'm kinda taking shots in the dark.  As it is now, the loop part is transplanted from viewforum.php. while the tables themselves are from help.php

Thanks Rickard!!  I added that snippet and now I get a 'Bad Request' error which I've determined originates from the if statement immediately following the $result query.  Any ideas?

So I've been workin gon this FAQ thing...  I have the DB stuff done... I created a table called 'faq' with the following fields: id, question, answer, disp_position.
The FAQ Admin panel allows add/delete/edit (almost bug-free) so the DB side works.  I'm having trouble, though, with faq.php.
The code for faq.php is below...  i get an error on the '$result' line...  I really have no idea how this is supposed to work... if anyone has the time to take a look, I'd appreciate it!

$pun_root = './';
require $pun_root.'include/common.php';

//$id = intval($_GET['id']);
//if (empty($id) || $id < 0)
//    message($lang_common['Bad request']);


// Load the faq.php language file
require $pun_root.'lang/'.$language.'/'.$language.'_faq.php';





$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_faq['faq'];
require $pun_root.'header.php';

?>
<table class="punspacer" cellspacing="1" cellpadding="4"><tr><td><b><a href="index.php"><?php echo pun_htmlspecialchars($pun_config['o_board_title']) ?></a> / <?php echo $lang_faq['long_faq'] ?></b></td></tr></table>

<table class="punmain" cellspacing="1" cellpadding="4">
    <tr class="punhead">
        <td class="punhead" colspan="2"><b>Question not answered here? Post your question to the <a href="viewtopic.php?pid=112#112">FAQ Topic.</a></b></td>
    </tr>
<?php

// Fetch some info from the faq
$result = $db->query('SELECT faq_name, question, answer, disp_position FROM '.$db->prefix.'faq ORDER BY disp_position') or error('Unable to fetch faq info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
    message($lang_common['Bad request'], true);

list($faq_name, $question, $answer, $disp_position) = $db->fetch_row($result);


if ($db->num_rows($result))
{
    while ($id = $db->fetch_assoc($result))
    {
    list($faq_name, $question, $answer, $disp_position) = $db->fetch_row($result);
?>    

    <tr>
        <td class="puncon1" style="width: 240px; vertical-align: top" ><p style="margin-bottom: 0"><b><?php echo $lang_faq['question'].$disp_position.'</p><p style="margin-left: 10px; margin-top: 5px; margin-bottom: 5px"></b>'.$question ?></p></td>
        <td class="puncon2" style="vertical-align: top"><p style="margin-bottom: 0"><b><?php echo $lang_faq['answer'].'</b></p><p style="margin-left: 10px; margin-top: 5px; margin-bottom: 5px">'.$answer ?></p></td>
    </tr>

<?php    
    }
}
else    
    echo "\t".'<tr><td class="puncon1" colspan="6">'.$lang_faq['Empty FAQ'].'</td></tr>'."\n";

?>       
</table>

<table class="punspacer" cellspacing="1" cellpadding="4"><tr><td> </td></tr></table>
<?php

require $pun_root.'footer.php';

edit: updated code

Two last things and then I'm done and I'll compile all of this into a proper mod.

1) Mail Templates
I basically copied and modified reply_topic.tpl and reply_topic_full.tpl and renamed them new_topic.tpl and new_topic_full.tpl.
How do I go about adding 'forum_name' to the new templates?

2) $is_subscribed
I have hit a brick wall on setting $is_subscribed in viewforum.php.  I've tried transplanting some queries from viewtopic but nothing I try seems to work.  (the subscription itself works but it always says "Subscribe to this forum" even if you already are!)

I've amended my code posts above for viewforum.php and misc.php to reflect how they look now.

SUCCESS!!!!!!!!

i modified the above mentioned db query to read:

$result = $db->query('SELECT u.id, u.email, u.notify_with_post FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'subscriptions_forums AS s ON u.id=s.user_id LEFT JOIN '.$db->prefix.'bans AS b ON u.username=b.username WHERE b.username IS NULL AND s.forum_id='.$fid.' AND u.id!='.intval($cur_user['id'])) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());

Now all I have to do is add some e-mail templates cuz it sends reply e-mails at the moment.  I also still have that problem with viewforum.php not realizing that I'm subscribed and offering the unsubscribe link.

BTW, thanks to anyone (like Rickard) who has taken the time to try and decipher my ramblings...   I feel I am so-o-o close to getting this...!

alright, I feel I am close!!
I replaced s.topic_id with s.forum_id and $tid with $fid
now I only get this:

File: /home/forum/public_html/post.php
Line: 315

PunBB reported: Unable to fetch subscription info
Database reported: You have an error in your SQL syntax near 'AND u.id!=8' at line 1 (Errno: 1064)

edit: don't know if this is relevant, but I noticed that the new topic does get posted...

this is the 'debug mode' error i get

File: /home/forum/public_html/post.php
Line: 315

PunBB reported: Unable to fetch subscription info
Database reported: You have an error in your SQL syntax near 'AND u.last_action> AND u.id!=8' at line 1 (Errno: 1064)

so  I added the table (only thing I was stumped on was cardinality in the indexes... what IS that?)
I still get errors on the transplanted db query:

$result = $db->query('SELECT u.id, u.email, u.notify_with_post FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'subscriptions_forums AS s ON u.id=s.user_id LEFT JOIN '.$db->prefix.'bans AS b ON u.username=b.username WHERE b.username IS NULL AND s.topic_id='.$tid.' AND u.last_action>'.$previous_post_time.' AND u.id!='.intval($cur_user['id'])) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());

'subscriptions_forums' is the new table I created... what do i do with the topic_id stuff and how do add the forum_id?  I tried just replacing them but that didn't seem to work.

Rickard wrote:

I think the easiest way will be to add a new table to the database that keeps track of forum subscriptions. You can then do something along the lines of what you did above

So I should add a table identical to 'subscriptions' and call it forum_subscriptions' or something so that one will handle topics and the other forums?  That makes sense.

I'll still need some help with the db queries in post.php as I said above.  (my last post was posted before I read your post...)

k, getting closer....

I realised that I needed to add the subscribe/emailing code to the part of post.php that does new topics...  so I did that but now I get an 'unable to fetch", etc. error.
I know that it's this line that causing problems... how do I change for forums? (you'll notice i tried replacing every occurrence of 'topic' with 'forum' -- no dice)

$result = $db->query('SELECT u.id, u.email, u.notify_with_post FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'subscriptions AS s ON u.id=s.user_id LEFT JOIN '.$db->prefix.'bans AS b ON u.username=b.username WHERE b.username IS NULL AND s.forum_id='.$fid.' AND u.last_action>'.$previous_post_time.' AND u.id!='.intval($cur_user['id'])) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());

OK, so I tried out my plan and I think it's almost working except that I'm getting an "unable to fetch subscription info' error.  This would be a db problem, right?

Here's what I did:

viewforum.php: (around line 239 or so)

<!--SUBSCRIBE FORUM MOD-->
<?php

if (!$cookie['is_guest'] && $pun_config['o_subscriptions'] == '1')
{
    if ($is_subscribed)
        // I apologize for the variable naming here. It's a mix of subscription and action I guess :-)
        $subscraction = $lang_forum['Is subscribed'].' - <a href="misc.php?unsubscribe_forum='.$id.'">'.$lang_forum['Unsubscribe'].'</a>';
    else
        $subscraction = '<a href="misc.php?subscribe_forum='.$id.'">'.$lang_forum['Subscribe'].'</a>';
}
else
    $subscraction = ' ';


?>
<!-- END SUBSCRIBE FORUM MOD-->

<table class="punspacer" cellspacing="1" cellpadding="4">
    <tr>
        <td style="width: 46%"><?php echo $lang_common['Pages'].': '.paginate($num_pages, $p, 'viewforum.php?id='.$id) ?></td>
<!--SUBSCRIBE FORUM MOD-->
        <td class="punright" style="width: 35%"><?php echo $subscraction ?></td>
<!--END SUBSCRIBE FORUM MOD-->
        <td class="punright" style="width: 19%"><b><?php echo $post_link ?></b></td>
    </tr>
</table>

misc.php: (line 288 or so)

// SUBSCRIBE FORUM MOD

else if (isset($_GET['subscribe_forum']))
{
    $forum_id = intval($_GET['subscribe_forum']);
    if (empty($forum_id))
        message($lang_common['Bad request']);

    if ($cookie['is_guest'])
        message($lang_common['No permission']);

    $result = $db->query('SELECT 1 FROM '.$db->prefix.'subscriptions_forums WHERE user_id='.$cur_user['id'].' AND forum_id='.$forum_id) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
    if ($db->num_rows($result))
        message($lang_misc['Already subscribed_f']);
    
    $db->query('INSERT INTO '.$db->prefix.'subscriptions_forums (user_id, forum_id) VALUES('.$cur_user['id'].' ,'.$forum_id.')') or error('Unable to add subscription', __FILE__, __LINE__, $db->error());

    redirect('viewforum.php?id='.$forum_id, $lang_misc['Subscribe redirect']);
}


else if (isset($_GET['unsubscribe_forum']))
{
    $forum_id = intval($_GET['unsubscribe_forum']);
    if (empty($forum_id))
        message($lang_common['Bad request']);

    if ($cookie['is_guest'])
        message($lang_common['No permission']);

    $result = $db->query('SELECT 1 FROM '.$db->prefix.'subscriptions_forums WHERE user_id='.$cur_user['id'].' AND forum_id='.$forum_id) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
    if (!$db->num_rows($result))
        message($lang_misc['Not subscribed_f']);

    $db->query('DELETE FROM '.$db->prefix.'subscriptions_forums WHERE user_id='.$cur_user['id'].' AND forum_id='.$forum_id) or error('Unable to remove subscription', __FILE__, __LINE__, $db->error());

    redirect('viewforum.php?id='.$forum_id, $lang_misc['Unsubscribe redirect']);
}

// end SUBSCRIBE FORUM MOD

I also made changes to the forum and misc lang files but they don't seem to causing problems...

EDIT:  I checked the db and noticed that there is no 'forum_id' field in the 'subscriptions' table...  If I just add this field will my problems be solved?

EDIT2: OK so I added the field to the db and now get no errors...  but the mail doesn't go through....  not really surprising since I didn't change any mailing stuff...  next?  Also, viewforum.php isn't recognizing me as subscribed so is showing the 'subscribe to this forum' link but when I click it it says I'm already subscribed -- I'm guessing that '$is_subscribed' isn't set but I don't know how to do that.

EDIT3!!: updated code boxes to reflect current status.

Any help would be appreciated....   my MySQL knowledge is minimal...

k, so no takers... wink

can someone point me in the right direction?  I've looked at the 'subscribe/unsubscribe' code from viewtopic.php and misc.php but am unclear how to proceed.

EDIT:
So I just looked at misc.php again...  what if I:

1) add new 'sub/unsub' sections with, say, 'subscribe_forum' instead of 'subscribe'
2) copy everything from the topic sub/unsub sections
3) change all references of '$topic_id' to 'forum_id'

and then, of course, copy the link info from viewtopic to viewforum...

Thoughts?

If someone could create a Mod that allowed users to subscribe to a Forum (as opposed to a individual topics) so that they could be notified of new topics in that forum but not replies within topics (current subscription feature does that - no need to re-invent the wheel!)

I'd try myself but this is my first experience with PHP.

Rickard wrote:

Voila!

Thanks once again Rickard!  Exactly what I was looking for.

Hi everyone!

I need to make a wee code edit to have the login box appear on index.php... or, on second thought, should I just do an index.html with a redirect to login.php?

Basically, guests cannot view my forum so I'm trying to save my members a step by not having to click on the 'Login' link.

Edit:
I wasn't sure if this question should go here or in 'Troubleshooting' or somewhere else... there doesn't seem to be a place for questions about small code edits that aren't bugs or full mods.

Has any progress been made on this project?  It would be great to be able to integrate PunBB and Gallery so they have the same look!  I was going to install the Coppermine software that my web host provides but if I can integrate "Gallery" with PunBB I'll hold off and install it instead.

I really like PunBB but was srprised that there was no FAQ for users.  It would be nice to have an admin-able FAQ with a link in the header.  The admin should be able to add custom Q & A along with standard PunBB questions.

I would do this if I had a clue how...  right now I'm limited cut&paste programming. sad

Thanks

69

(2 replies, posted in PunBB 1.2 discussion)

Ok, thanks... I didn't want to put anything in there without knowing what is was for...

70

(2 replies, posted in PunBB 1.2 troubleshooting)

Thanks!

71

(20 replies, posted in Feature requests)

I suppose it would have helped to actually look at a subscription email before posting... rookie mistake!! wink

The unsubscribe link in the email is sufficient for I was talking about, though an 'unsubscribe all topics' in the profile might be worthwhile.

While we are on the subject of subscriptions, is there a way to subscribe to a Forums so as to be notified of new topics? (Particularly useful for an 'Event Announcements' forum)

Thanks for taking the time...

72

(2 replies, posted in PunBB 1.2 discussion)

This is my last post today... I promise!!

Anyway, I just wondered what the 'Admin Note' field was for?

Is it for multiple Admins to leave notes about the user for each other?

73

(20 replies, posted in Feature requests)

I don't see an easy way for forum users to manage their subscriptions...  (other than going to each topic individually and clicking 'unsubscribe')

Would it be too difficult to add the subscriptions to the profile page with select/deselect boxes?

My original thought was an unsubscribe link in the e-mails but that seems too complicated... at least for individual subscriptions.... I think.

74

(2 replies, posted in PunBB 1.2 troubleshooting)

Is there a simple way to force mail to be sent through the mail form even if the users e-mail address is set to be displayed?

Many of my users (myself included) access my forum from public terminals (school, etc.) and the mailto: command doesn't work.

It's a hassle to have to copy & paste into hotmail or something...

Thanks...

Two requests....  one likely harder than the other...

1) Add the "Real Name" field to the registration screen and make it a required field.


2) Add the ability for Admin to accept/reject new members before the p/w e-mail is sent.

Any help???


<If this info is elsewhere, I apologize...>