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.
Yeah I didn't want to run another query it's a relatively small table.. but I just wasn't thinking and storing the username also is the smart move... thanks for waking me up
How do I send a PM to a user A (normal) and the same PM to user B (with BCC)? user B shall receive the same PM from A but user A should'nt know that user B got the PM too.
How do I send a PM to a user A (normal) and the same PM to user B (with BCC)? user B shall receive the same PM from A but user A should'nt know that user B got the PM too.
untested but should work: set_recipients($recipientlist, $botpermissions, $type = 'bcc')
I made a modul in wich a member can add a text.
I want this member to receive a pm in case I erase his text.
I have accomplished a modul but I want to know if the code is correct .
Code:
//The link is : script.php?do=delete&p=$row['text_id']
if(isset($_GET['p']) AND is_numeric($_GET['p']))
{
$me = $db->query_read("SELECT text_title,text_uid,text_user FROM " . TABLE_PREFIX . "table WHERE text_id='{$_GET['p']}'");
$me_s = $db->fetch_array($me);
$txtuid = $me_s['text_uid'];
$username = $me_s['text_user'];
$title = $me_s['text_title'];
$pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$pmdm->set('fromuserid', $txtuid);
$pmdm->set('fromusername', $username);
$pmdm->set('title', 'Information');
$pmdm->set('message', "I delete your text : $title .......");
$pmdm->set_recipients($username, $botpermissions);
$pmdm->set('dateline', TIMENOW);
$pmdm->errors;
$pmdm->save();
$db->query_write("DELETE FROM " . TABLE_PREFIX . "table WHERE text_id='{$_GET['p']}'");
define('CP_REDIRECT', "script.php?do=show");
print_stop_message('text_deleted');
exit;
}
I made a modul in wich a member can add a text.
I want this member to receive a pm in case I erase his text.
I have accomplished a modul but I want to know if the code is correct .
Code:
//The link is : script.php?do=delete&p=$row['text_id']
if(isset($_GET['p']) AND is_numeric($_GET['p']))
{
$me = $db->query_read("SELECT text_title,text_uid,text_user FROM " . TABLE_PREFIX . "table WHERE text_id='{$_GET['p']}'");
$me_s = $db->fetch_array($me);
$txtuid = $me_s['text_uid'];
$username = $me_s['text_user'];
$title = $me_s['text_title'];
$pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$pmdm->set('fromuserid', $txtuid);
$pmdm->set('fromusername', $username);
$pmdm->set('title', 'Information');
$pmdm->set('message', "I delete your text : $title .......");
$pmdm->set_recipients($username, $botpermissions);
$pmdm->set('dateline', TIMENOW);
$pmdm->errors;
$pmdm->save();
$db->query_write("DELETE FROM " . TABLE_PREFIX . "table WHERE text_id='{$_GET['p']}'");
define('CP_REDIRECT', "script.php?do=show");
print_stop_message('text_deleted');
exit;
}
Thank you .
This looks like a horrible idea, as anyone could just enumerate through the textid's and delete them all.
I am using this snippet on a non-VB page. Beforehand I am including the global.html and so on - as described in various "login from non-vb page" threads/hacks.
$to is set to a valid username, however i get the following error right with the "set_recipients" part.
Quote:
Fatal error: Call to undefined function: query_first_slave() in /user/public_html/community/includes/functions.html on line 1154
Anyone have an idea? I did a var_dump(get_class_methods($vbulletin->db)); right beforeit uses the query_first_slave and it shows the query_first_slave method. My PHP is 4.4.x - so do I need to update my vb? We are still on 3.6.4 (only on the development server).