Programmatic Create Private Message

Discussion of general topics related to the new version and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Forum rules
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Post Reply
ManagingMeals
Registered User
Posts: 9
Joined: Mon Jan 26, 2009 3:27 am

Programmatic Create Private Message

Post by ManagingMeals »

Id like to integrate pm's into my site a little bit more (i have a site using phpbb's login, my site built on top is coded from scratch). I would like to add a report feature that sends me (the admin) a pm every time a user reports an article.

So i wrote a little function. And set up the report link. The function is below. The issue is that when i go into the forum near the top it says "0 new messages" but once i click on that it has a message in my inbox, and is marked as unread (according to the icon). What am i missing?

Note the code is rough and uses all static info until i get it working.

Code: Select all

function pm_user() {
global $dblink;	//This is my db connection

    if( !$dblink )
            include_once('db.php');
            db_connect();




$sql = "INSERT INTO `phpbb_privmsgs` (`author_id`,`author_ip`,`message_time`,`message_subject`,`message_text`,`bbcode_uid`)
			VALUES ('55','127.0.0.1','".time()."','test subj','prg test','3ikap621');";
$measurements=mysql_query($sql) or die('Failed getting measurements: ' . mysql_error());
$newid=mysql_insert_id();

$sql = "INSERT INTO `phpbb_privmsgs_to` (`msg_id`, `user_id`, `author_id`,`pm_unread`,`pm_new`)
			VALUES ('".$newid."', '2', '55','1','0');";
$measurements=mysql_query($sql) or die('Failed getting measurements: ' . mysql_error());

	
}
User avatar
poyntesm
Registered User
Posts: 176
Joined: Fri May 13, 2005 4:08 pm
Location: Dublin, Ireland
Contact:

Re: Programmatic Create Private Message

Post by poyntesm »

You would be best to ask in MOD writter on phpBB.com

However you should examine the submit_pm() function, below is a example of it in use by a MOD I wrote.

Code: Select all

                include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
                include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);

                $message_parser = new parse_message();
                $message_parser->message = sprintf($user->lang['PENDING_NOTIFY_TEXT'], '<a href="mcp.' . $phpEx . '?i=garage&mode=' . $mcp_mode_to_approve .'">' . $user->lang['HERE'] . '</a>');
                $message_parser->parse(true, true, true, false, false, true, true);

                $pm_data = array(
                    'from_user_id'            => $user->data['user_id'],
                    'from_user_ip'            => $user->data['user_ip'],
                    'from_username'            => $user->data['username'],
                    'enable_sig'            => false,
                    'enable_bbcode'            => true,
                    'enable_smilies'        => true,
                    'enable_urls'            => false,
                    'icon_id'            => 0,
                    'bbcode_bitfield'        => $message_parser->bbcode_bitfield,
                    'bbcode_uid'            => $message_parser->bbcode_uid,
                    'message'            => $message_parser->message,
                    'address_list'            => array('u' => array($moderators_to_pm[$i]['user_id'] => 'to')),
                );

                //Now We Have All Data Lets Send The PM!!
                submit_pm('post', $user->lang['PENDING_ITEMS'], $pm_data, false, false); 
ManagingMeals
Registered User
Posts: 9
Joined: Mon Jan 26, 2009 3:27 am

Re: Programmatic Create Private Message

Post by ManagingMeals »

Thanks, that seems to be the right direction, however. I keep getting a page with the output below.
NO_RECIPIENT
I also noticed that you have a comma at the end of the array, did you cut out unneeded fields?

Here is my code.

Code: Select all

include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
                   include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);


                    $message_parser = new parse_message();
                    $message_parser->message = sprintf($user->lang['PENDING_NOTIFY_TEXT'], '<a href="mcp.' . $phpEx . '?i=garage&mode=' . $mcp_mode_to_approve .'">' . $user->lang['HERE'] . '</a>');
                    $message_parser->parse(true, true, true, false, false, true, true);

                    $pm_data = array(
                        'from_user_id'            => $user->data['55'],
                        'from_user_ip'            => $user->data['127.0.0.1'],
                        'from_username'            => $user->data['steve'],
                        'enable_sig'            => false,
                        'enable_bbcode'            => true,
                        'enable_smilies'        => true,
                        'enable_urls'            => false,
                        'icon_id'            => 0,
                        'bbcode_bitfield'        => $message_parser->bbcode_bitfield,
                        'bbcode_uid'            => $message_parser->bbcode_uid,
                        'message'            => $message_parser->test,
                        'address_list'            => array('u' => array($moderators_to_pm[$i]['2'] => 'to'))
                    );

                    //Now We Have All Data Lets Send The PM!!
                    submit_pm('post', $user->lang['PENDING_ITEMS'], $pm_data, false, false); 
User avatar
poyntesm
Registered User
Posts: 176
Joined: Fri May 13, 2005 4:08 pm
Location: Dublin, Ireland
Contact:

Re: Programmatic Create Private Message

Post by poyntesm »

Dude its an example. It needs other code to get the address list.

Code: Select all

array('u' => array($moderators_to_pm[$i]['user_id'] => 'to')), 
You will not have that array :|
ManagingMeals
Registered User
Posts: 9
Joined: Mon Jan 26, 2009 3:27 am

Re: Programmatic Create Private Message

Post by ManagingMeals »

Ah, Too early.

Thanks i got it to work
Post Reply