UBB.Dev
Posted By: foppen email every new post to the moderator - 01/02/2003 12:44 AM
Hi All,
As an administrator I want an email from every new post>
In Threads version 6.1 I used this blok in bleu wich I found on this board.
When I paste it in to Version 6.2 it works fine but every time when the mail is send out I see a MySqL error for a few seconds.
What can I do to fix it?
Thanks in advance,
Pim Foppen
[:"blue"] /*
# This code snippet will email every new post to the moderator(s) of the
# forum the post is in, *and* the main administrator of the whole board (user #2).
#
# It mimics the behavior of UBB.Classic.
#
# In addpost.php, insert the code block below directly above the lines:
#
# // ---------------------------------------------
# // Update the total post if the post is Approved
#
#
# Disclaimer: I cobbled this together from existing code,
# I'm using it on my busy board and it works fine for me. I can't and
# won't be responsible if it doesn't work properly for you, or
# for any possible data loss or any incidental damages that may occur,
# etc etc etc legalese. Backup your original files first.
# In other words, use at your own risk, or "modify at your own peril".
#
# I doubt I'll be doing any other work on this since it now does exactly what
# I need it to do, so I'll leave improvements and enhancements to PHP gurus.
#
# That being said, I hope you find it useful, and that someone will
# clean it up and find a way to make it configurable from the Admin
# area, perhaps on a per-forum basis.
#
# This could be made shorter and more efficient by changing prior
# blocks of code, but I decided to make it a snippet to be dropped in,
# so no other modifications are necessary, getting ease of implementation
# but sacrificing a little brevity and efficiency.
#
#
# Helice, http://foolmoon.com
# mailto:[email protected]
#
# June 16, 2002
*/


//-------------Fool Moon Modified-------------------------
$EmailBody = $Body;
$EmailBody = preg_replace("/<([^>])*>/","",$EmailBody);
$newline = "\n";
if (stristr(PHP_OS,"win")) {
$newline = "\r\n";
}

// Find the moderators to notify
$query = "
SELECT Mod_Username
FROM w3t_Moderators
WHERE Mod_Board = '$Board_q'
";
$sth = $dbh -> do_query($query);

$mailer = new mailer;
$header = $mailer -> headers();
$blurb = "has just posted in : ";
// Construct the message body
$msg = "$postername $blurb $Title $newline{$config['phpurl']}/showthreaded.php?Cat=$Cat&Board=$Board&Number=$Mnumber$newline$newline$EmailBody";

// Find the email address for each moderator
while ( list($Mod) = $dbh -> fetch_array($sth)) {
$Mod_q = addslashes($Mod);
$query = "
SELECT U_Email
FROM w3t_Users
WHERE U_Username = '$Mod_q'
";
$sti = $dbh -> do_query($query);
list($to) = $dbh -> fetch_array($sti);
// Mail the package out
mail("$to","$Subject",$msg,$header);
}

// Then find the email address for the main administrator
$query = "
SELECT U_Email
FROM w3t_Users
WHERE U_Number = 2
";
$sth = $dbh -> do_query($query);
list($to) = $dbh -> fetch_array($sth);
// Mail the package out
mail("$to","$Subject",$msg,$header);

//-------------Fool Moon Modified------------------------- [/]
Posted By: JoshPet Re: email every new post to the moderator - 01/02/2003 2:03 AM
What error are you seeing?

Is the prefix to your tables "w3t_"? Or do you use a custom database prefix.
Posted By: Dave_L_dup1 Re: email every new post to the moderator - 01/02/2003 2:07 AM
Code
SELECT Mod_Username<br />FROM w3t_Moderators<br />WHERE Mod_Board = '$Board_q'


That won't work, because Mod_Username has been replaced by Mod_Uid. Do you need the email sent to all the moderators, or only to user #2?

Posted By: omegatron Re: email every new post to the moderator - 01/02/2003 3:45 AM
Like Dave said the Mod_Username column is invalid now. Below is the proper code. I tested this on my test forum and it works.

//-------------Fool Moon Modified-------------------------
$EmailBody = $Body;
$EmailBody = preg_replace("/<([^>])*>/","",$EmailBody);
$newline = "\n";
if (stristr(PHP_OS,"win")) {
$newline = "\r\n";
}

// Find the moderators to notify
$query = "
SELECT Mod_Uid
FROM w3t_Moderators
WHERE Mod_Board = '$Board_q'
";
$sth = $dbh -> do_query($query);

$mailer = new mailer;
$header = $mailer -> headers();
$blurb = "has just posted in : ";
// Construct the message body
$msg = "$postername $blurb $Title $newline{$config['phpurl']}/showthreaded.php?Cat=$Cat&Board=$Board&Number=$Mnumber$newline$newline$EmailBody";

// Find the email address for each moderator
while ( list($Mod) = $dbh -> fetch_array($sth)) {
$Mod_q = addslashes($Mod);
$query = "
SELECT U_Email
FROM w3t_Users
WHERE U_Username = '$Mod_q'
";
$sti = $dbh -> do_query($query);
list($to) = $dbh -> fetch_array($sti);
// Mail the package out
mail("$to","$Subject",$msg,$header);
}

// Then find the email address for the main administrator
$query = "
SELECT U_Email
FROM w3t_Users
WHERE U_Number = 2
";
$sth = $dbh -> do_query($query);
list($to) = $dbh -> fetch_array($sth);
// Mail the package out
mail("$to","$Subject",$msg,$header);

//-------------Fool Moon Modified-------------------------

Hi Chuck

Does the above do this........

Admin receives ALL new posts.

Mods only the forums that they moderate.

Just what I need
Posted By: foppen Re: email every new post to the moderator - 01/02/2003 1:35 PM
I just woke up this morning and I found the suprise on the board.
It works great, thanks a lot, it gives me more and more insight how things work....
Regards,
Pim Foppen
Hi Chuck

That didn't work for me.

Gave me an 500 internal server error.

So I took OUT .....this part

===============================================
// Find the email address for each moderator
while ( list($Mod) = $dbh -> fetch_array($sth)) {
$Mod_q = addslashes($Mod);
$query = "
SELECT U_Email
FROM w3t_Users
WHERE U_Username = '$Mod_q'
";
$sti = $dbh -> do_query($query);
list($to) = $dbh -> fetch_array($sti);
// Mail the package out
mail("$to","$Subject",$msg,$header);
}
========================================

This worked and just emailed the admin but not the moderator.

So is there something needing changed in that part? lol
Posted By: Dave_L_dup1 Re: email every new post to the moderator - 01/02/2003 6:14 PM
$Mod is a user number, not a user name. Try this:

Code
// Find the email address for each moderator <br />while ( list($Mod) = $dbh -> fetch_array($sth)) { <br />$query = " <br />   SELECT U_Email <br />   FROM w3t_Users <br />   WHERE U_Number = $Mod <br />";


(The addslashes() isn't needed, and the quotes around $Mod aren't needed, since $Mod is a number, not a string.)
Posted By: omegatron Re: email every new post to the moderator - 01/03/2003 2:01 AM
LOL weird it worked for me and I have 6.2 well its not like I am using it anyway. I just tested it with the Uid to check it out and see if it worked.
Posted By: qube Re: email every new post to the moderator - 01/07/2003 12:40 PM
Same thread over at infopop:
http://community.infopop.net/2/OpenTopic?a=tpc&s=729094322&f=5163077913&m=7963092986

That code works on <6.2 but its trivial to change to adding a join for the UIDs now.
(one minor bug in it, 3rd last line should read:
$dbh -> finish_sth($sth_mod);
)

Paul
© UBB.Developers