Here's the function in uShop 0.96 (which will be released "soon"):
PHP Code:
// Send a PM.
function uttstore_send_pm($title, $text, $user, $from=0) {
global $DB_site, $bbuserinfo, $vboptions;
if ($from == 0) {
$from = $bbuserinfo;
}
if ($from == "default") {
$from = $DB_site->query_first("SELECT * FROM ".TABLE_PREFIX."user WHERE userid=$vboptions[uttstore_pmfrom]");
}
$title = str_replace(" ", " ", $title);
$text = str_replace(" ", " ", $text);
if (isset($user[0]['userid'])) {
// Sending to multiple.
foreach ($user as $omguser) {
$tostring["$omguser[userid]"] = $omguser['username'];
}
} else {
// Sending to one.
$tostring["$user[userid]"] = $user['username'];
}
$DB_site->query("INSERT INTO " . TABLE_PREFIX . "pmtext\n\t(fromuserid, fromusername, title, message, touserarray, iconid, dateline, showsignature, allowsmilie)\nVALUES\n\t($from[userid], '" . addslashes($from['username']) . "', '$title', '".addslashes($text)."', '" . addslashes(serialize($tostring)) . "', 0, " . TIMENOW . ", 0, 1)");
$pmtextid = $DB_site->insert_id();
if (isset($user[0]['userid'])) {
// Sending to multiple.
foreach ($user as $omguser) {
(isset($pmquery) ? $pmquery .= ",\n\t" : $pmquery = '');
$pmquery .= "($pmtextid, $omguser[userid])";
(isset($in) ? $in .= ",$omguser[userid]" : $in = $omguser['userid']);
}
} else {
$pmquery .= "($pmtextid, $user[userid])";
$in = $user['userid'];
}
$DB_site->query("INSERT INTO " . TABLE_PREFIX . "pm (pmtextid, userid) VALUES $pmquery");
$DB_site->shutdown_query("UPDATE " . TABLE_PREFIX . "user SET pmtotal=pmtotal+1, pmunread=pmunread+1 WHERE userid IN ($in)");
}
$title and $text should be the title and body of the message respectively, $user can either be an array of a username and userid, or an array of arrays of usernames and userids if you are sending to multiple people ($user['userid'] and $user['username'] or $user[0]['userid'] and so on). $from should be a username/userid array of the user you want the PM to be from, or if it is not set, it defaults to $bbuserinfo. It also has a $from = "default" code in there which could be used, but you might want to change the setting it looks for.