If you want to (automatically) send a PM to a user, you can use the Class vB_Datamanager_PM.
This class makes sure that all values are correct, handles quota for the recipients, notification eMails, etc.
Example
PHP Code:
// create the DM to do error checking and insert the new PM
$pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$pmdm->set('fromuserid', 1234);
$pmdm->set('fromusername', 'Welcome-Bot');
$pmdm->set('title', 'Welcom to our Forums');
$pmdm->set('message', "Hello\nI am a Bot and would like to give you a warm welcome :)");
$pmdm->set_recipients('newuser', $botpermissions);
$pmdm->set('dateline', TIMENOW);
If anything goes wrong you can check for errors using
PHP Code:
$pmdm->errors
This is an erray containing the errors.
If everything is OK
PHP Code:
$pmdm->save();
This will send a PM to user newuser telling him
Quote:
Hello.
I am a Bot and would like to give you a warm welcome
The message will appear to be coming from User Welcom-Bot (Userid 1234).
$botpermissions must be the permissions for the sending user, but can just be empty.
If you want to send PMs no matter if the PM box of the recipient is full or not:
PHP Code:
$botpermissions['adminpermissions'] = 2;
If you want, you can set other options as well ($pmdm->set_info(...)):
forward = 1/0 if this is a forwarded PM, Default=0
savecopy = 1/0 to keep a copy if the PM in outbox, Default=0
receipt = 1/0 to request a read-receipt, Default=0
parentpmid = ID of the PM you are responding to (if applicable)
Furthermore you can specify ($pmdm->set(...)):
iconid = ID of the message icon the PM should carry, Default=0
showsignature = 0/1 Whether the signature should be shown or not, Default=0
showsmilie = 0/1 Wheter smilies should be parsed or not, Default=1
For multiple receipients just use user1;user2;useer3.
This How-To is (C) 2005 by KirbyDE and you are not allowed to redistribute it in any way without my explicit consent.
Any new/novel solutions to the problem of PMs not updating in their count #? I dont want to do the digitalcrowd method of manually incrementing the # in teh database because it seems to sometimes update correctly and not other times.
Is there a way to tell vb to reasses the PM count using a built in function?
Any new/novel solutions to the problem of PMs not updating in their count #? I dont want to do the digitalcrowd method of manually incrementing the # in teh database because it seems to sometimes update correctly and not other times.
Is there a way to tell vb to reasses the PM count using a built in function?
Yes, I'd like to know this as well. Doesn't vb have a built in function to do this? I'm very hesitant of making a database call to vb's database if I don't have to.
Yes, I'd like to know this as well. Doesn't vb have a built in function to do this? I'm very hesitant of making a database call to vb's database if I don't have to.
In private.php:
Code:
// ###################### Start pm update counters #######################
// update the pm counters for $vbulletin->userinfo
function build_pm_counters()
{
global $vbulletin;
$pmcount = $vbulletin->db->query_first("
SELECT
COUNT(pmid) AS pmtotal,
SUM(IF(messageread = 0 AND folderid >= 0, 1, 0)) AS pmunread
FROM " . TABLE_PREFIX . "pm AS pm
WHERE pm.userid = " . $vbulletin->userinfo['userid'] . "
");
$pmcount['pmtotal'] = intval($pmcount['pmtotal']);
$pmcount['pmunread'] = intval($pmcount['pmunread']);
if ($vbulletin->userinfo['pmtotal'] != $pmcount['pmtotal'] OR $vbulletin->userinfo['pmunread'] != $pmcount['pmunread'])
{
// init user data manager
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
$userdata->set_existing($vbulletin->userinfo);
$userdata->set('pmtotal', $pmcount['pmtotal']);
$userdata->set('pmunread', $pmcount['pmunread']);
$userdata->save();
}
}
FYI, there seems to be a new function within the PM datamanager in version 3.7.0, which is needed for sending automatic PMs (such as in the welcome pm)
I am receiving an error that the user has PMs disabled, when the user doesn't. Any ideas? I'm attempting to send a PM to the main administrator account.
Code:
$pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$pmdm->set_info('savecopy', 1);
$pmdm->set('fromuserid', $userid);
$pmdm->set('fromusername', $username);
$pmdm->set('title', 'this is a title');
$pmdm->set('message', 'this is a message');
$pmdm->set_recipients('xxclixxx', $permissions);
$pmdm->set('dateline', TIMENOW);
$pmdm->pre_save();
// process errors if there are any
$errors = $pmdm->errors;
($userid and $username are properly filled during the test. It works if I send to the test account, but not to the admin account.)