View Full Version : Automatic Private Message
EquinoxWorld
07-23-2011, 06:46 PM
Hello everyone, I was wondering if anyone knows how to send a pm upon a specific action. For example:
if (this condition true) {
send pm
}
I want to send a automatic pm if the member wins a contest for example congratulating. I have been trying to read other mods that do this but they are all somewhat different and to be honest I am not sure where to even begin. If anyone has any insight or can at least point me in the right direction it would be very helpful. Thank you for your time everyone.
You could look at private.php, the section that starts with if ($_POST['do'] == 'insertpm'). In your case you probably just need to set up the pm array and make the datamanager calls, so you can ignore the buddy list and flood check code, and you probably would want to ignore errors as well (so if there are any errors after pre save, you would probably just give up on sending the PM).
EquinoxWorld
07-23-2011, 06:54 PM
You could look at private.php, the section that starts with if ($_POST['do'] == 'insertpm'). In your case you probably just need to set up the pm array and make the datamanager calls, so you can ignore the buddy list and flood check code, and you probably would want to ignore errors as well.
Perfect. Now at least I know where to look, just what I needed. :) Thanks for the fast reply khn.....after taking a better look at it now, it looks easier than I thought it was going to be. Thanks again.
--------------- Added 1311474514 at 1311474514 ---------------
OK After an entire day of meddelling with the code I have gotten it down to this..:
<?php
require_once('./global.php');
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
echo "exit";
exit;
}
require_once('./includes/class_dm.php');
$result1 = $vbulletin->db->query_read("SELECT (username) FROM oftw_nominations ORDER BY (votes) DESC LIMIT 1");
$username = $result1;
$result2 = $vbulletin->db->query_read("SELECT (userid) FROM user WHERE userid = 1");
$postuserid = $result2;
$result3 = $vbulletin->db->query_read("SELECT (username) FROM user WHERE userid = 1");
$postusername = $result3;
// Init the PM datamanager
$oftwpm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$oftwpmperms['adminpermissions'] = 2; // force PM
// Fill in the blanks
$oftwpm->overridequota = true;
$oftwpm->set_info('is_automated', true);
$oftwpm->set_info('receipt', false);
$oftwpm->set_info('savecopy', false);
$oftwpm->set('fromuserid', $postuserid);
$oftwpm->set('fromusername', $postusername);
$oftwpm->set('title', $apposthead);
$oftwpm->set('message', $aptextpost);
$oftwpm->set_recipients($username, $oftwpmperms);
$oftwpm->set('dateline', TIMENOW);
$oftwpm->set('showsignature', 0);
$oftwpm->set('allowsmilie', 1);
// Send the PM
$oftwpm->save();
?>
Although when I try to run it I get a 500 internal server error :( .... When I take off the: require_once('./global.php');
I get a blank page and the echo "exit"...It's not even letting me get to the SQL queries for some reason...Any ideas why anyone?? I feel I am very close to cracking this one :confused:.. Please help!
I'm pretty sure what you want to do with the query lines is something like:
$result1 = $vbulletin->db->query_first("SELECT (username) FROM oftw_nominations ORDER BY (votes) DESC LIMIT 1");
$username = $result1['username'];
etc.
EquinoxWorld
07-24-2011, 03:54 AM
OK Got It!!
For example: Create a php file:
<?php
global $vbulletin;
require_once(DIR . "/includes/class_dm.php");
require_once(DIR . "/includes/class_dm_pm.php");
//pm system
$pmSystem = new vB_DataManager_PM( $vbulletin );
//pm Titel / Text
$pnTitel = "Your Title for the PM";
$pnText = "This is pm which was created automatically. Please do not reply to this pm.";
$pmSystem->verify_message( $pnText );
$pmSystem->verify_title( $pnTitel );
//Set the fields
$pmSystem->set('fromuserid', 1);
$pmSystem->set('fromusername', 'AWDevelopment');
$pmSystem->set('title', $pnTitel);
$pmSystem->set('message', $pnText);
$pmSystem->set('dateline', TIMENOW);
$pmSystem->set('iconid', 4);
$pmSystem->set_recipients("AWDevelopment");
//"send" pn
if ( $pmSystem->pre_save() === false )
{
if ($pmSystem->errors) {
return $pmSystem->errors;
}
}
else
{
$pmSystem->save();
}
?>
Create a new Scheduled Task with this new php file and voila!.
note: This only sends a pm to myself (I'm AWDevelopment).
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.