vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Automatic Private Message (https://vborg.vbsupport.ru/showthread.php?t=267294)

EquinoxWorld 07-23-2011 05:46 PM

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.

kh99 07-23-2011 05:52 PM

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).

EquinoxWorld 07-23-2011 05:54 PM

Quote:

Originally Posted by kh99 (Post 2224022)
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 :confused:.. Please help!

kh99 07-24-2011 01:19 AM

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.

EquinoxWorld 07-24-2011 02:54 AM

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).


All times are GMT. The time now is 10:41 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.01862 seconds
  • Memory Usage 1,763KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete