Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-23-2011, 06:46 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Automatic Private Message

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.
Reply With Quote
  #2  
Old 07-23-2011, 06:52 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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).
Reply With Quote
  #3  
Old 07-23-2011, 06:54 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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 [DATE]1311474514[/DATE] at [TIME]1311474514[/TIME] ---------------

OK After an entire day of meddelling with the code I have gotten it down to this..:

PHP Code:
<?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'$vbulletinERRTYPE_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:
PHP Code:
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 .. Please help!
Reply With Quote
  #4  
Old 07-24-2011, 02:19 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm pretty sure what you want to do with the query lines is something like:

PHP Code:
$result1 $vbulletin->db->query_first("SELECT (username) FROM oftw_nominations ORDER BY (votes) DESC LIMIT 1"); 
$username $result1['username']; 
etc.
Reply With Quote
  #5  
Old 07-24-2011, 03:54 AM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK Got It!!

For example: Create a php file:

PHP Code:
<?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).
Reply With Quote
Благодарность от:
Mooff
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 11:00 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.04117 seconds
  • Memory Usage 2,247KB
  • Queries Executed 13 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (1)post_thanks_box_bit
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_postinfo_query
  • fetch_postinfo
  • 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
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete