Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Send PMs (automatically)
Andreas's Avatar
Andreas
Join Date: Jan 2004
Posts: 6,863

 

Germany
Show Printable Version Email this Page Subscription
Andreas Andreas is offline 06-09-2005, 10:00 PM

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'$vbulletinERRTYPE_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.
Reply With Quote
  #72  
Old 03-07-2007, 04:49 PM
cashpath cashpath is offline
 
Join Date: Jul 2003
Posts: 216
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #73  
Old 03-13-2007, 04:46 PM
Deriel Deriel is offline
 
Join Date: May 2005
Location: Curitiba/PR - Brazil
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #74  
Old 03-13-2007, 05:07 PM
CyberRanger's Avatar
CyberRanger CyberRanger is offline
 
Join Date: Mar 2004
Posts: 1,319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Deriel View Post
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')
Reply With Quote
  #75  
Old 03-28-2007, 05:00 PM
xman_79's Avatar
xman_79 xman_79 is offline
 
Join Date: Jun 2006
Location: Romania
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you for your useful and explicite answer .

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 .
Reply With Quote
  #76  
Old 03-30-2007, 08:53 PM
budlight budlight is offline
 
Join Date: Mar 2007
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by xman_79 View Post
Thank you for your useful and explicite answer .

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.
Reply With Quote
  #77  
Old 04-01-2007, 12:27 AM
xman_79's Avatar
xman_79 xman_79 is offline
 
Join Date: Jun 2006
Location: Romania
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by budlight View Post
This looks like a horrible idea, as anyone could just enumerate through the textid's and delete them all.

This isn't the entire code , I wrote just the part that I was more intrested in .
I am interested in the idea not in the code itself .

Thanks .
Reply With Quote
  #78  
Old 04-18-2007, 01:19 PM
Till Till is offline
 
Join Date: May 2002
Posts: 51
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.

Code:
$pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$pmdm->set('fromuserid', 5);
$pmdm->set('fromusername', 'Foo');
$pmdm->set('title', sprintf('Einladung %s', $name));
$pmdm->set('message', $message);
$pmdm->set_recipients($to, $botpermissions);
$pmdm->set('dateline', TIMENOW);
//var_dump($pmdm->errors);
$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).
Reply With Quote
  #79  
Old 04-19-2007, 05:56 PM
Factory Ten Factory Ten is offline
 
Join Date: Oct 2006
Posts: 48
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there a way I can use this to automatically PM someone when they get an infraction?
Reply With Quote
  #80  
Old 04-19-2007, 06:05 PM
CyberRanger's Avatar
CyberRanger CyberRanger is offline
 
Join Date: Mar 2004
Posts: 1,319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Factory Ten View Post
Is there a way I can use this to automatically PM someone when they get an infraction?
That's already an option in the infraction system.
Reply With Quote
  #81  
Old 05-04-2007, 01:28 PM
Punky Guy's Avatar
Punky Guy Punky Guy is offline
 
Join Date: Feb 2006
Location: London, England
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there a way I can call this from a link or button? Some hook I could use?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:15 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05002 seconds
  • Memory Usage 2,329KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (3)bbcode_code
  • (4)bbcode_php
  • (6)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (3)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete