PDA

View Full Version : Send Private Message to Public Group Leader on Join Requests


amykhar
01-18-2005, 10:00 PM
This quick and dirty little hack sends a PM to the leaders of a public group when a join request has been made.

I am surprised this isn't built into vbulletin.

Amy

the Sandman
01-19-2005, 02:18 AM
Installed. :) There are two eval(print_standard_redirect('usergroup_requested' ));I added the code above the second. Is that correct?

amykhar
01-19-2005, 02:19 AM
oops. Hold on, let me check for a better reference point.

amykhar
01-19-2005, 02:23 AM
ok. The directions have changed. The code you are looking for is:


// insert the request
$DB_site->query("
INSERT INTO " . TABLE_PREFIX . "usergrouprequest
(userid,usergroupid,reason,dateline)
VALUES
($bbuserinfo[userid], $usergroupid, '" . addslashes(htmlspecialchars_uni($_POST['reason'])) . "', " . TIMENOW . ")
");


Add the code changes after that bit of code. I've changed the directions. Thanks for catching that there were two instances of that code.

the Sandman
01-19-2005, 02:28 AM
OK, so I was the first to post in this Thread, first to install, found the first problem with the instructions, and still installed it correctly? Woohoo!

amykhar
01-19-2005, 02:32 AM
Easy hack for a change, huh? :D

Viks
01-19-2005, 03:39 AM
As u said 'quick and dirty'.......good work!

*clicks install*

the Sandman
01-19-2005, 05:12 PM
Someone finally put in a join request and the PM was properly generated so I can verify that this works (on a security patched vB 3.0.3 Board). :)

Gryphon
01-20-2005, 04:21 PM
This is great timing, I 'just' started using public groups and found it annoying when I discovered that there was no notification other than checking the Group page all the time.

j_86
01-20-2005, 04:30 PM
Nice hack

kall
01-20-2005, 04:38 PM
Someone finally put in a join request and the PM was properly generated so I can verify that this works (on a security patched vB 3.0.3 Board). :)
On 3.0.6 it 'works' .. I get a PM called something like "Join request:*username*" but no more details.

Amy: is it possible to get the group name in the body of the message somewhere?

amykhar
01-20-2005, 04:51 PM
I'll look at making the message more robust.

Amy

amykhar
01-20-2005, 05:32 PM
OK. I updated the instructions to include the group name and a link to the validation page. If you have already installed, do the following to upgrade:

Find:
if ($_POST['do'] == 'insertjoinrequest')
{


Add After:
require_once('./includes/functions_bbcodeparse.php');
require_once('./includes/functions_newpost.php');


Find the code block originally added in the hack.

Replace with:



$leaders = $DB_site->query("
SELECT ugl.userid, username
FROM " . TABLE_PREFIX . "usergroupleader AS ugl
INNER JOIN " . TABLE_PREFIX . "user AS user USING(userid)
WHERE ugl.usergroupid = $usergroupid
");
$groupname = $DB_site->query_first("
SELECT title
FROM " . TABLE_PREFIX . "usergroup
WHERE usergroupid = $usergroupid
ORDER BY usergroupid DESC
LIMIT 1
");
if ($DB_site->num_rows($leaders))
{

$_groupleaders = array();
$tostring = array();

while ($leader = $DB_site->fetch_array($leaders))
{
// Send a PM to the leaders letting them know a join request has been made.
$message = construct_phrase($vbphrase['group_memberships_message'], $groupname[title]);
$message = convert_url_to_bbcode($message);
$tostring["$leader[userid]"] = $leader['username'];

$DB_site->query("INSERT INTO " . TABLE_PREFIX . "pmtext\n\t(fromuserid, fromusername, title, message, touserarray, iconid, dateline, showsignature)\nVALUES\n\t($bbuserinfo[userid], '" . addslashes($bbuserinfo['username']) . "', 'Join Request:', '".addslashes(htmlspecialchars($message))."', '" . addslashes(serialize($tostring)) . "', 0, " . TIMENOW . ", 1)");
$pmtextid = $DB_site->insert_id();
$DB_site->query("INSERT INTO " . TABLE_PREFIX . "pm (pmtextid, userid, messageread) VALUES ($pmtextid, $leader[userid], 0)");
$DB_site->shutdown_query("UPDATE " . TABLE_PREFIX . "user SET pmtotal=pmtotal+1, pmunread=pmunread+1 WHERE userid = $leader[userid]");

}
}

trackpads
01-20-2005, 05:51 PM
OK. I updated the instructions to include the group name and a link to the validation page. If you have already installed, do the following to upgrade:

Find:
if ($_POST['do'] == 'insertjoinrequest')
{


Add After:
require_once('./includes/functions_bbcodeparse.php');
require_once('./includes/functions_newpost.php');


Find the code block originally added in the hack.

Replace with:



$leaders = $DB_site->query("
SELECT ugl.userid, username
FROM " . TABLE_PREFIX . "usergroupleader AS ugl
INNER JOIN " . TABLE_PREFIX . "user AS user USING(userid)
WHERE ugl.usergroupid = $usergroupid
");
$groupname = $DB_site->query_first("
SELECT title
FROM " . TABLE_PREFIX . "usergroup
WHERE usergroupid = $usergroupid
ORDER BY usergroupid DESC
LIMIT 1
");
if ($DB_site->num_rows($leaders))
{

$_groupleaders = array();
$tostring = array();

while ($leader = $DB_site->fetch_array($leaders))
{
// Send a PM to the leaders letting them know a join request has been made.
$message = construct_phrase($vbphrase['group_memberships_message'], $groupname[title]);
$message = convert_url_to_bbcode($message);
$tostring["$leader[userid]"] = $leader['username'];

$DB_site->query("INSERT INTO " . TABLE_PREFIX . "pmtext\n\t(fromuserid, fromusername, title, message, touserarray, iconid, dateline, showsignature)\nVALUES\n\t($bbuserinfo[userid], '" . addslashes($bbuserinfo['username']) . "', 'Join Request:', '".addslashes(htmlspecialchars($message))."', '" . addslashes(serialize($tostring)) . "', 0, " . TIMENOW . ", 1)");
$pmtextid = $DB_site->insert_id();
$DB_site->query("INSERT INTO " . TABLE_PREFIX . "pm (pmtextid, userid, messageread) VALUES ($pmtextid, $leader[userid], 0)");
$DB_site->shutdown_query("UPDATE " . TABLE_PREFIX . "user SET pmtotal=pmtotal+1, pmunread=pmunread+1 WHERE userid = $leader[userid]");

}
}

Excellent work Amy! I dont know why this isnt in the stock vb either!

ricker
01-22-2005, 05:10 AM
great hack! thanks.
*installed*

settimio
02-18-2005, 06:18 AM
Well...
I've applied the send html hack shown in another post and I'd like to send a periodical newsletter to people who joined a public group called Newsletter.
The standard Vbulletin doesn't allow to send email to public groups...
Is there a fast and simpler way to hack the forum so I can send bulk email to members of a public group?

amykhar
02-18-2005, 10:13 AM
Setti, your question is off topic for this thread. You should probably start a new thread in general mod discussion if you are going to do it yourself or in one of the request forums if you need somebody to do it for you.

the Sandman
02-19-2005, 03:53 PM
The upgrade instructions for early adopters need to include the new phrase addition. :)

Cyricx
03-07-2005, 04:44 AM
Hmm this doesn't seem to be working with 3.0.7

Anyone have this workin on that version? If so I'll try a clean profile.php

amykhar
03-07-2005, 10:09 AM
It's working on my 3.0.7 with no problems and no changes required.

Cyricx
03-08-2005, 02:19 AM
It's not working for me at all, and I've followed the instructions to a T... even followed the "non-instructions" by adding the phrase in ;)

The pm title comes across as "Join Request:"

and the message comes up with what I set in as the variable with nothing else, so it's not pulling the $groupname[title] and I'm not sure what the "convert to url" code is supposed to do.

Here is my insertjoinrequest function and you can see from it I've followed your instructions to a T.


if ($_POST['do'] == 'insertjoinrequest')
{

require_once('./includes/functions_bbcodeparse.php');
require_once('./includes/functions_newpost.php');

globalize($_POST, array('usergroupid' => INT));

$url = "profile.php?do=editusergroups";

if ($request = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "usergrouprequest

WHERE userid=$bbuserinfo[userid] AND usergroupid=$usergroupid"))
{
// request already exists, just say okay...
eval(print_standard_redirect('usergroup_requested' ));
}
else

{
// insert the request
$DB_site->query("
INSERT INTO " . TABLE_PREFIX . "usergrouprequest
(userid,usergroupid,reason,dateline)
VALUES
($bbuserinfo[userid], $usergroupid, '" .

addslashes(htmlspecialchars_uni($_POST['reason'])) . "', " . TIMENOW . ")
");

$leaders = $DB_site->query("
SELECT ugl.userid, username
FROM " . TABLE_PREFIX . "usergroupleader AS ugl
INNER JOIN " . TABLE_PREFIX . "user AS user USING(userid)
WHERE ugl.usergroupid = $usergroupid
");
$groupname = $DB_site->query_first("
SELECT title
FROM " . TABLE_PREFIX . "usergroup
WHERE usergroupid = $usergroupid
ORDER BY usergroupid DESC
LIMIT 1
");
if ($DB_site->num_rows($leaders))
{

$_groupleaders = array();
$tostring = array();

while ($leader = $DB_site->fetch_array($leaders))
{
// Send a PM to the leaders letting them know a join request has been

made.
$message =

construct_phrase($vbphrase['group_memberships_message'], $groupname[title]);
$message = convert_url_to_bbcode($message);
$tostring["$leader[userid]"] = $leader['username'];

$DB_site->query("INSERT INTO " . TABLE_PREFIX . "pmtext\n\t(fromuserid,

fromusername, title, message, touserarray, iconid, dateline,

showsignature)\nVALUES\n\t($bbuserinfo[userid], '" . addslashes($bbuserinfo['username']) . "',

'Join Request:', '".addslashes(htmlspecialchars($message))."', '" .

addslashes(serialize($tostring)) . "', 0, " . TIMENOW . ", 1)");
$pmtextid = $DB_site->insert_id();
$DB_site->query("INSERT INTO " . TABLE_PREFIX . "pm (pmtextid, userid,

messageread) VALUES ($pmtextid, $leader[userid], 0)");
$DB_site->shutdown_query("UPDATE " . TABLE_PREFIX . "user SET

pmtotal=pmtotal+1, pmunread=pmunread+1 WHERE userid = $leader[userid]");

}
}

eval(print_standard_redirect('usergroup_requested' ));
}

}


Your absolutely right, I can't believe the devs didn't add this in by default. Would really love to have this hack working though, any help is appreciated :)

amykhar
03-08-2005, 02:55 PM
Diid you add the phrase that is listed in the updated instructions? The convert url code simply converts any links you may use in the phrase to make them clickable.

Because you mention the "nonexistant phrase" I am concerned that you didn't see the portion of the instructions where that is added (around line 4 of the instruction file.)

Cyricx
03-08-2005, 03:37 PM
Ah bugger, saw the post by Sandman saying that the upgrade instructions needed to include that, didn't see anything about ya updaing them.

So this is a case of "Open mouth insert foot"

I had an older version that I had snagged when this was first brought up.

Thanks Amy! Awesome mod! :)

amykhar
06-14-2005, 07:35 PM
Ported: https://vborg.vbsupport.ru/showthread.php?t=83086

|Jordan|
02-04-2006, 05:04 PM
This doesnt work in 3.0.12

I've checked and rechecked the file checks and i didnt miss anything.

parash
01-18-2008, 06:44 PM
would it be possible to clear more... i tried it 3times but same error came...i dunno what is worng in it..