Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles

Reply
 
Thread Tools
[How to] Send Auto PM in vb4.0
bpr
Join Date: Dec 2009
Posts: 57

German person living in London, writing some crazy php codes and usually provide my knowledge to others over the internet by writing or recording tutorials

London
Show Printable Version Email this Page Subscription
bpr bpr is offline 05-02-2010, 10:00 PM

In this article I am going to explain you how to send a PM with the Vbulletin 4.0.X

it is based on this article
https://vborg.vbsupport.ru/showthread.php?t=82786
written by Andreas

PHP Code:
            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''Meeting Bot');
            
$pmSystem->set('title'$pnTitel);
            
$pmSystem->set('message'$pnText);
            
$pmSystem->set('dateline'TIMENOW);
            
$pmSystem->set('iconid'4);
            
            
$pmSystem->set_recipients("bpr");

//"send" pn
            
if ( $pmSystem->pre_save() === false )
            {
                 if (
$pmSystem->errors) {
                    return 
$pmSystem->errors;
                } 
            }
            else
            {
                 
$pmSystem->save();               
            } 
That's it basically. Lets go through those lines:

Firstly it is to say, that you have to use the following three 3 lines if you are excluding that code in a class or function in a folder like /includes.
PHP Code:
            global $vbulletin;            
            require_once(
DIR "/includes/class_dm.php");
            require_once(
DIR "/includes/class_dm_pm.php"); 
Those will provide you the usage of the whole system. I assume, that you dont need those lines if you already included the global.php! - But I am not that shure maybe somebody could confirm that.

Anyway lets continue:
Before we can start setting anykind of information, we need a class with which we can work, this class is called "vB_DataManager_PM" it extends "vB_DataManager". (that is the reason why we had to require 2 classes from the /includes directory).


"vB_DataManager_PM" works with the table: "pmtext" of your database.

However we have to give her the registry, which is $vbulletin.
So it should like this:

PHP Code:
 $pmSystem   =   new vB_DataManager_PM$vbulletin ); 

from now on "$pmSystem" represents our class and we are finally able to set things up for sending a pm - so lets do it:

Before I actually set the message and the title to the PM I want to make shure, that it is ok and that there are no unallowed things inside.

PHP Code:
$pmSystem->verify_message$pnText );
            
$pmSystem->verify_title$pnTitel ); 
(Just to let you know if you did not recognize it, I was creating two variables for the text and the title earlier in the script I had shown above)

After that we do the actual PM set up:

PHP Code:
$pmSystem->set('fromuserid'1);
            
$pmSystem->set('fromusername''PM Bot');
            
$pmSystem->set('title'$pnTitel);
            
$pmSystem->set('message'$pnText);
            
$pmSystem->set('dateline'TIMENOW);
            
$pmSystem->set('iconid'4); 
$pmSystem->set_recipients("bpr");[/PHP]

We say:
  1. The PM is from the User with the ID 1
  2. The name of the sender is "PM Bot" - it doesn't have to be the name of the user with the id
  3. We set up the title!
  4. After that the message
  5. Now we need a date time when it was sent
  6. The iconid is not required, in this case it represents the red one with the ! symbol
  7. Who will get the message, you can provide more recipients by doing it as followed "user1;user2;user3;user4;..." Important is just the ; which identifies the list and another user


So lets send our PM or not?

Before we actually send we can check if it successes by:
PHP Code:
$pmSystem->pre_save() 
This will return "true" or "false" - obviously true represents that it will be successfull and false it wont!

So in the case shown above we say:
if its possible and everything is fine, then: send it! ($pmSystem->save()
otherwise check if there are errors!
PHP Code:
$pmSystem->errors 
if there are errors, then print them.

That is it. You should now be able to automatically send a message with the Vbulletin 4.0.X

What can you do after reading this article?
Have a look at the API
http://members.vbulletin.com/api/vBu...anager_PM.html

I hope that I was able to help at least one person! Because it took me like three hours to figure this out!!! Enjoy, maybe you could write for what you are using automatic PMs

All the best,
Bjoern aka bpr
Reply With Quote
  #2  
Old 05-07-2010, 03:16 PM
dtommy79 dtommy79 is offline
 
Join Date: Jul 2007
Location: Hungary
Posts: 148
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is it mass PM to all members?
Reply With Quote
  #3  
Old 05-07-2010, 04:45 PM
bpr bpr is offline
 
Join Date: Dec 2009
Location: London
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No, it is an article to show how you can automatically send a pm !
Reply With Quote
  #4  
Old 05-10-2010, 07:35 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is the code from my mod:
Code:
$dm =& datamanager_init('PM', $vbulletin);
$dm->set('fromuserid', 1);
$dm->set('fromusername', 'Jaxel');
$dm->set('title', "this is a test title");
$dm->set('message', "this is a test message");
$dm->set('dateline', TIMENOW);
$dm->set_recipients('testaccount', $botpermissions);
$dm->overridequota = true;
$dm->save();
As you can see, there are no mistakes in this code... however it prompts the following error:
Code:
Database error in vBulletin 4.0.3:

Invalid SQL:
INSERT INTO pmtext
	(fromuserid, fromusername, title, message, dateline, touserarray, pmtextid) VALUES
	(1, 'Jaxel', 'this is a test title', 'this is a test message', 1273475035, 'a:1:{s:3:\"bcc\";a:1:{i:2;s:11:\"testaccount\";}}', 5);

MySQL Error   : Duplicate entry '5' for key 1
Error Number  : 1062
Request Date  : Monday, May 10th 2010 @ 03:03:55 AM
Error Date    : Monday, May 10th 2010 @ 03:03:56 AM
Script        : ...../media_ajax.php?do=comment
Referrer      : ...../media/m621-algol-killer-combos
IP Address    : ....
Username      : testaccount
Classname     : vB_Database
MySQL Version : 

Stack Trace:

#0 vB_Database->halt() called in [path]/includes/class_core.php on line 421
#1 vB_Database->execute_query() called in [path]/includes/class_core.php on line 439
#2 vB_Database->query_write() called in [path]/includes/class_dm.php on line 740
#3 vB_DataManager->db_insert() called in [path]/includes/class_dm.php on line 890
#4 vB_DataManager->save() called in [path]/media/media_comment.php on line 80
#5 require_once([path]/media/media_comment.php) called in [path]/media_ajax.php on line 87
It looks like the system attempts to input the PMTEXT into the database twice... anyone know how to fix?
Reply With Quote
  #5  
Old 05-12-2010, 12:34 PM
bpr bpr is offline
 
Join Date: Dec 2009
Location: London
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmm looks interesting,
I had never developed for 3.X and dont have that much experience with the 4.X but why are you not using

PHP Code:
$dm   =   new vB_DataManager_PM$vbulletin ); 
and does the same happen if you use it like I wrote in the article ?

i dont think it would change something .... but I also dont have any idea, why it tries to write it twice in the db
Reply With Quote
  #6  
Old 05-12-2010, 01:18 PM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1.
PHP Code:
            require_once(DIR "/includes/class_dm.php");
            require_once(
DIR "/class_dm_pm.php"); 
is wrong
the second file is also in the includes folder

2. that wouldn't happen if you would use datamanager_init
Reply With Quote
  #7  
Old 05-12-2010, 02:22 PM
bpr bpr is offline
 
Join Date: Dec 2009
Location: London
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ragtek View Post
1.
PHP Code:
            require_once(DIR "/includes/class_dm.php");
            require_once(
DIR "/class_dm_pm.php"); 
is wrong
the second file is also in the includes folder

2. that wouldn't happen if you would use datamanager_init
1. thanks ragtek i was changing it immediately

2. ah sounds good, why is nobody saying those kind of things : (
Reply With Quote
  #8  
Old 05-19-2010, 04:06 AM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's how i would make it in vB4

PHP Code:
<?
            $pmSystem   =   datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY); 
            
            //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', 'Meeting Bot');
            $pmSystem->set_r('title', $pnTitel);
            $pmSystem->set_r('message', $pnText);
            $pmSystem->set('dateline', TIMENOW);
            $pmSystem->set('iconid', 4);
            
            $pmSystem->set_recipients("bpr");

            if ( $pmSystem->pre_save() === false )
            {
                 if ($pmSystem->errors) {
# do something with  $pmSystem->errors array for example
# because youre return helps not, $pmSystem->errors is a array;) 
# so you could do for debuging a var_dump or die(print_r( ....

                   require_once DIR . '/includes/functions_newpost.php';
                    $template_errors = construct_errors($errors);
# now you can use $template_errors for a nice output;)
                    $show['pmerror'] = true;
                } 
            }
            else
            {
                $newpmid =    $pmSystem->save();               
            }
Reply With Quote
  #9  
Old 05-24-2010, 12:50 AM
ChopSuey ChopSuey is offline
 
Join Date: Jun 2009
Location: Alaska
Posts: 2,140
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ragtek your so mean lol! Couldv'e atleast just pointed out what spots he did wrong
Reply With Quote
  #10  
Old 05-24-2010, 08:43 AM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ChopSuey View Post
ragtek your so mean lol! Couldv'e atleast just pointed out what spots he did wrong
And why i'm that?
I've commented everything in the code...

But ok, i've seen that the big part of the user here don't need help in making the code better....

The "only" thing you'll get when you help somebody, are some "very friendly" messages in the forum or per skype/icq "why i attack other users which are helping,etc......."
Reply With Quote
Reply

Thread Tools

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 11:23 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04368 seconds
  • Memory Usage 2,334KB
  • Queries Executed 23 (?)
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
  • (2)bbcode_code
  • (11)bbcode_php
  • (2)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
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • 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