('/(? 0)
{
$this->info['numusers'] += sizeof($names);
}
// query recipients
$checkusers = $this->dbobject->query_read_slave("
SELECT usertextfield.*, user.*
FROM " . TABLE_PREFIX . "user AS user
LEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON(usertextfield.userid = user.userid)
WHERE username IN('" . implode('\', \'', array_map(array($this->dbobject, 'escape_string'), $names)) . "')
ORDER BY user.username
");
// build array of checked users
while ($checkuser = $this->dbobject->fetch_array($checkusers))
{
$lowname = vbstrtolower($checkuser['username']);
$checkuserperms = fetch_permissions(0, $checkuser['userid'], $checkuser);
if ($checkuserperms['pmquota'] < 1 AND !$this->overridequota) // can't use pms
{
if ($checkuser['options'] & $this->registry->bf_misc_useroptions['receivepm'])
{
// This will cause the 'can't receive pms' error below to be triggered
$checkuser['options'] -= $this->registry->bf_misc_useroptions['receivepm'];
}
}
$users["$lowname"] = $checkuser;
}
$this->dbobject->free_result($checkusers);
// check to see if any recipients were not found
foreach ($names AS $name)
{
$lowname = vbstrtolower($name);
if (!isset($users["$lowname"]))
{
$notfound[] = $name;
}
}
if (!empty($notfound)) // error - some users were not found
{
$comma = $vbphrase['comma_space'];
$this->error('pmrecipientsnotfound', implode("$comma
", $notfound));
return false;
}
// run through recipients to check if we can insert the message
foreach ($users AS $lowname => $user)
{
if (!($user['options'] & $this->registry->bf_misc_useroptions['receivepm']) AND !$this->overridequota)
{
// recipient has private messaging disabled
$this->error('pmrecipturnedoff', $user['username']);
return false;
}
else if (($user['options'] & $this->registry->bf_misc_useroptions['receivepmbuddies']) AND strpos(" $user[buddylist] ", " $fromuser[userid] ") === false AND !can_moderate() AND !$this->overridequota)
{
// recipient receives PMs only from buddies and sender is not on the list and not board staff
$this->error('pmrecipturnedoff', $user['username']);
return false;
}
else
{
// don't allow a tachy user to sends pms to anyone other than himself
if (in_coventry($fromuser['userid'], true) AND $user['userid'] != $fromuser['userid'])
{
$this->info['tostring']["$type"]["$user[userid]"] = $user['username'];
continue;
}
else if (strpos(" $user[ignorelist] ", ' ' . $fromuser['userid'] . ' ') !== false AND !$this->overridequota)
{
// recipient is ignoring sender
if ($permissions['adminpermissions'] & $this->registry->bf_ugp_adminpermissions['cancontrolpanel'])
{
$recipients["$lowname"] = true;
$this->info['tostring']["$type"]["$user[userid]"] = $user['username'];
}
else
{
// bbuser is being ignored by recipient - do not send, but do not error
$this->info['tostring']["$type"]["$user[userid]"] = $user['username'];
continue;
}
}
else
{
cache_permissions($user, false);
if ($user['permissions'] < 1)
{
// recipient has no pm permission
$this->error('pmusernotallowed', $user['username']);
}
else
{
if ($user['pmtotal'] >= $user['permissions']['pmquota'] AND !$this->overridequota)
{
// recipient is over their pm quota, is the sender allowed to ignore it?
if ($permissions['pmpermissions'] & $this->registry->bf_ugp_pmpermissions['canignorequota'])
{
$recipients["$lowname"] = true;
$this->info['tostring']["$type"]["$user[userid]"] = $user['username'];
}
else if ($user['usergroupid'] != 3 AND $user['usergroupid'] != 4)
{
$touserinfo =& $user;
eval(fetch_email_phrases('pmboxfull', $touserinfo['languageid'], '', 'email'));
vbmail($touserinfo['email'], $emailsubject, $emailmessage, true);
$this->error('pmquotaexceeded', $user['username']);
}
else
{
$this->error('pmquotaexceeded', $user['username']);
}
}
else
{
if (!($user['options'] & $this->registry->bf_misc_useroptions['pmboxwarning']) AND $user['permissions']['pmquota'] AND ((($user['pmtotal'] + 1 ) / $user['permissions']['pmquota']) >= .9))
{ // Send email about box being almost full
$this->info['pmwarning']["$user[userid]"] = true;
}
// okay, send the message!
$recipients["$lowname"] = true;
$this->info['tostring']["$type"]["$user[userid]"] = $user['username'];
}
}
}
}
}
if (empty($this->errors))
{
foreach ($recipients AS $lowname => $bool)
{
$user =& $users["$lowname"];
$this->info['recipients']["$user[userid]"] = $user;
}
return true;
}
else
{
return false;
}
}
// #############################################################################
// data saving
/**
* Any checks to run immediately before saving. If returning false, the save will not take place.
*
* @param boolean Do the query?
*
* @return boolean True on success; false if an error occurred
*/
function pre_save($doquery = true)
{
if ($this->presave_called !== null)
{
return $this->presave_called;
}
if (empty($this->errors))
{
if (empty($this->info['tostring']))
{
$this->error('pminvalidrecipient', $this->registry->session->vars['sessionurl_q']);
return false;
}
else if ($this->info['numusers'] > $this->info['permissions']['pmsendmax'])
{
$this->error('pmtoomanyrecipients', $this->info['numusers'], $this->info['permissions']['pmsendmax']);
return false;
}
}
// Check if the parent pm is already a child of a thread
if ($parentpmid = intval($this->info['parentpmid']))
{
$pm = $this->dbobject->query_first_slave("
SELECT parentpmid
FROM " . TABLE_PREFIX . "pm
WHERE pmid = $parentpmid
AND userid = " . intval($this->fetch_field('fromuserid'))
);
$this->info['parentpmid'] = (intval($pm['parentpmid']) ? $pm['parentpmid'] : $parentpmid);
}
$tostring = serialize($this->info['tostring']);
$this->do_set('touserarray', $tostring);
$return_value = true;
($hook = vBulletinHook::fetch_hook('pmdata_presave')) ? eval($hook) : false;
$this->presave_called = $return_value;
return $return_value;
}
function post_save_each($doquery = true, $result = false)
{
$pmtextid = ($this->existing['pmtextid'] ? $this->existing['pmtextid'] : $this->pmtext['pmtextid']);
$fromuserid = intval($this->fetch_field('fromuserid'));
$fromusername = $this->fetch_field('fromusername');
$parentpmid = intval($this->info['parentpmid']);
if (!$this->condition)
{
if (is_array($this->info['recipients']))
{
$receipt_sql = array();
$popupusers = array();
$warningusers = array();
require_once(DIR . '/includes/class_bbcode_alt.php');
$plaintext_parser = new vB_BbCodeParser_PlainText($this->registry, fetch_tag_list());
$plaintext_title = unhtmlspecialchars($this->fetch_field('title'));
// insert records for recipients
foreach ($this->info['recipients'] AS $userid => $user)
{
/*insert query*/
$query = $this->dbobject->query_write($sql = "INSERT INTO " . TABLE_PREFIX . "pm (pmtextid, userid, parentpmid) VALUES ($pmtextid, $user[userid], $parentpmid)");
// ensure all subsequent pm's use a common parentpmid
if (!$parentpmid)
{
$parentpmid = $this->info['parentpmid'] = $this->dbobject->insert_id();
}
if ($this->info['receipt'])
{
$receipt_sql[] = "(" . $this->dbobject->insert_id() . ", $fromuserid, $user[userid],
'" . $this->dbobject->escape_string($user['username']) . "', '" . $this->dbobject->escape_string($this->pmtext['title']) .
"', " . TIMENOW . ")";
}
if ($user['pmpopup'])
{
$popupusers[] = $user['userid'];
}
$email_phrases = array(
'pmreceived' => 'pmreceived',
'pmboxalmostfull' => 'pmboxalmostfull'
);
($hook = vBulletinHook::fetch_hook('pmdata_postsave_recipient')) ? eval($hook) : false;
if (($user['options'] & $this->registry->bf_misc_useroptions['emailonpm']) AND $user['usergroupid'] != 3 AND $user['usergroupid'] != 4)
{
$touserinfo =& $user;
$plaintext_parser->set_parsing_language($touserinfo['languageid']);
$plaintext_message = $plaintext_parser->parse($this->fetch_field('message'), 'privatemessage');
eval(fetch_email_phrases($email_phrases['pmreceived'], $touserinfo['languageid'], '', 'email'));
vbmail($touserinfo['email'], $emailsubject, $emailmessage);
}
if (!empty($this->info['pmwarning']["$user[userid]"]) AND !($user['options'] & $this->registry->bf_misc_useroptions['pmboxwarning']))
{ // email user about pm box nearly being full
$warningusers[] = $user['userid'];
$touserinfo =& $user;
eval(fetch_email_phrases($email_phrases['pmboxalmostfull'], $touserinfo['languageid'], '', 'email'));
vbmail($touserinfo['email'], $emailsubject, $emailmessage, true);
}
}
// insert receipts
if (!empty($receipt_sql) AND $this->info['cantrackpm'])
{
/*insert query*/
$this->dbobject->query_write("INSERT INTO " . TABLE_PREFIX . "pmreceipt\n\t(pmid, userid, touserid, tousername, title, sendtime)\nVALUES\n\t" . implode(",\n\t", $receipt_sql));
}
$querysql = array(
"pmtotal = pmtotal + 1",
"pmunread = pmunread + 1"
);
if (!empty($warningusers))
{
$querysql[] = "
options =
CASE
WHEN userid IN(" . implode(', ', $warningusers) . ") THEN options | " . $this->registry->bf_misc_useroptions['pmboxwarning'] . "
ELSE options
END
";
}
if (!empty($popupusers))
{
$querysql[] = "
pmpopup =
CASE
WHEN userid IN(" . implode(', ', $popupusers) . ") THEN 2
ELSE pmpopup
END
";
}
$this->dbobject->query_write("
UPDATE " . TABLE_PREFIX . "user
SET " . implode(', ', $querysql) . "
WHERE userid IN(" . implode(', ', array_keys($this->info['recipients'])) . ")
");
}
// update replied to / forwarded message 'messageread' status
if (!empty($this->info['replypmid']))
{
$this->dbobject->query_write("
UPDATE " . TABLE_PREFIX . "pm SET
messageread = " . ($this->info['forward'] ? 3 : 2) . "
WHERE userid = $fromuserid AND pmid = " . intval($this->info['replypmid'])
);
// mark receipt as read
$this->dbobject->query_write("
UPDATE " . TABLE_PREFIX . "pmreceipt
SET readtime = " . TIMENOW . ",
denied = 0
WHERE pmid = " . intval($this->info['replypmid']) . "
AND touserid = " . $fromuserid . "
AND readtime = 0
");
}
// save a copy in the sent items folder
if ($this->info['savecopy'])
{
/*insert query*/
$this->dbobject->query_write("
INSERT INTO " . TABLE_PREFIX . "pm
(pmtextid, userid, folderid, messageread, parentpmid)
VALUES
($pmtextid, $fromuserid, -1, 1, $parentpmid)
");
$user = fetch_userinfo($fromuserid);
$userdm =& datamanager_init('User', $this->registry, ERRTYPE_SILENT);
$userdm->set_existing($user);
$userdm->set('pmtotal', 'pmtotal + 1', false);
$userdm->save();
unset($userdm);
}
// log message for throttling
$frompermissions = fetch_permissions(0, $fromuserid);
if ($this->registry->options['pmthrottleperiod'] AND $frompermissions['pmthrottlequantity'])
{
$throttle_sql = array();
foreach ($this->info['recipients'] AS $user)
{
$throttle_sql[] = "($fromuserid, " . TIMENOW . ")";
}
if (!empty($throttle_sql))
{
$this->registry->db->query_write("
INSERT INTO " . TABLE_PREFIX . "pmthrottle (userid, dateline) VALUES " .
implode(",\n\t", $throttle_sql)
);
}
}
}
($hook = vBulletinHook::fetch_hook('pmdata_postsave')) ? eval($hook) : false;
}
}
/*======================================================================*\
|| ####################################################################
|| # CVS: $RCSfile$ - $Revision: 53471 $
|| ####################################################################
\*======================================================================*/
?>
ʼ*)*]Jf( "K?/c[ ${x *#hȌƖr~3uwt&pccN&9c"UT/2[<@wmEwimzsupǤC}ܿ`8 @:unty:;}?~#@ 1` D#He8YvJon!Lm5rīZO=cO:WN}t(OE
q\mWƷʟ!^`{µՇjVxдjy -