2007-05-26 17:00:01 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-11-12 20:57:15 +00:00
|
|
|
|
|
|
|
require_once("boinc_db.inc");
|
2008-09-16 23:06:37 +00:00
|
|
|
require_once("sanitize_html.inc");
|
2007-05-26 17:00:01 +00:00
|
|
|
|
|
|
|
function pm_header() {
|
|
|
|
echo "<div>\n";
|
2007-11-12 20:57:15 +00:00
|
|
|
echo " <a href=\"pm.php?action=inbox\">".tra("Inbox")."</a>\n";
|
|
|
|
echo " | <a href=\"pm.php?action=new\">".tra("Write")."</a>\n";
|
2007-05-26 17:00:01 +00:00
|
|
|
echo "</div>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function pm_create_new($error = null) {
|
2009-02-06 03:40:54 +00:00
|
|
|
global $g_logged_in_user;
|
2009-06-23 16:31:42 +00:00
|
|
|
page_head(tra("Send private message"),'','','','<script type="text/javascript" src="bbcode_toolbar.js"></script>');
|
2007-05-26 17:00:01 +00:00
|
|
|
|
2007-08-25 15:04:29 +00:00
|
|
|
if (post_str("preview", true) == tra("Preview")) {
|
2007-08-20 17:59:24 +00:00
|
|
|
$options = new output_options;
|
|
|
|
echo "<div id=\"preview\">\n";
|
2007-08-25 15:04:29 +00:00
|
|
|
echo "<div class=\"header\">".tra("Preview")."</div>\n";
|
2007-08-20 17:59:24 +00:00
|
|
|
echo output_transform(post_str("content", true), $options);
|
|
|
|
echo "</div>\n";
|
|
|
|
}
|
|
|
|
|
2007-05-26 17:00:01 +00:00
|
|
|
$replyto = get_int("replyto", true);
|
|
|
|
$userid = get_int("userid", true);
|
|
|
|
|
2007-10-28 15:03:14 +00:00
|
|
|
$subject = null;
|
|
|
|
$content = null;
|
2007-05-26 17:00:01 +00:00
|
|
|
if ($replyto) {
|
2007-11-12 20:57:15 +00:00
|
|
|
$message = BoincPrivateMessage::lookup_id($replyto);
|
2008-06-05 04:35:21 +00:00
|
|
|
if (!$message || $message->userid != $g_logged_in_user->id) {
|
2007-11-12 20:57:15 +00:00
|
|
|
error_page("no such message");
|
2007-05-26 17:00:01 +00:00
|
|
|
}
|
2007-11-12 20:57:15 +00:00
|
|
|
$content = "[quote]".$message->content."[/quote]\n";
|
|
|
|
$userid = $message->senderid;
|
|
|
|
$user = BoincUser::lookup_id($userid);
|
2007-05-26 17:00:01 +00:00
|
|
|
if ($user != null) {
|
|
|
|
$writeto = $userid." (".$user->name.")";
|
|
|
|
}
|
2007-11-12 20:57:15 +00:00
|
|
|
$subject = $message->subject;
|
|
|
|
if (substr($subject, 0, 3) != "re:") {
|
|
|
|
$subject = "re: ".$subject;
|
|
|
|
}
|
|
|
|
} elseif ($userid) {
|
|
|
|
$user = BoincUser::lookup_id($userid);
|
|
|
|
if ($user) {
|
|
|
|
$writeto = $userid." (".$user->name.")";
|
|
|
|
}
|
2007-05-26 17:00:01 +00:00
|
|
|
} else {
|
|
|
|
$writeto = post_str("to", true);
|
2008-06-11 19:36:10 +00:00
|
|
|
$subject = post_str("subject", true);
|
|
|
|
$content = post_str("content", true);
|
2007-05-26 17:00:01 +00:00
|
|
|
}
|
|
|
|
|
2007-09-12 14:08:34 +00:00
|
|
|
$content = htmlspecialchars($content);
|
2007-05-26 17:00:01 +00:00
|
|
|
$subject = htmlspecialchars($subject);
|
|
|
|
|
|
|
|
if ($error != null) {
|
2007-08-25 15:04:29 +00:00
|
|
|
echo "<div class=\"error\">".$error."</div>\n";
|
2007-05-26 17:00:01 +00:00
|
|
|
}
|
|
|
|
|
2009-06-23 16:31:42 +00:00
|
|
|
echo "<form action=\"pm.php\" method=\"post\" name=\"post\" onsubmit=\"return checkForm(this)\">\n";
|
2007-05-26 17:00:01 +00:00
|
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"send\">\n";
|
2008-06-05 04:35:21 +00:00
|
|
|
echo form_tokens($g_logged_in_user->authenticator);
|
2007-05-26 17:00:01 +00:00
|
|
|
start_table();
|
2007-11-26 03:05:27 +00:00
|
|
|
row2(tra("To")."<br /><span class=\"smalltext\">".tra("User IDs or unique usernames, separated with commas")."</span>",
|
|
|
|
"<input type=\"text\" name=\"to\" value=\"$writeto\" size=\"60\">"
|
|
|
|
);
|
|
|
|
row2(tra("Subject"), "<input type=\"text\" name=\"subject\" value=\"$subject\" size=\"60\">");
|
2009-06-23 16:31:42 +00:00
|
|
|
$bbcode_bbcodehtml = file_get_contents('../inc/bbcode_bbcodehtml.inc');
|
2007-11-26 03:05:27 +00:00
|
|
|
row2(tra("Message")."<span class=\"smalltext\">".html_info()."</span>",
|
2009-06-23 16:31:42 +00:00
|
|
|
$bbcode_bbcodehtml."<textarea name=\"content\" rows=\"18\" cols=\"80\">$content</textarea>"
|
2007-11-26 03:05:27 +00:00
|
|
|
);
|
2007-08-25 15:04:29 +00:00
|
|
|
echo "<tr><td></td><td><input type=\"submit\" name=\"preview\" value=\"".tra("Preview")."\"> <input type=\"submit\" value=\"".tra("Send message")."\"></td></tr>\n";
|
2007-05-26 17:00:01 +00:00
|
|
|
end_table();
|
|
|
|
|
|
|
|
page_tail();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2007-12-30 22:02:16 +00:00
|
|
|
function send_pm_notification_email(
|
|
|
|
$logged_in_user, $to_user, $subject, $content
|
|
|
|
) {
|
|
|
|
$message = "
|
2007-11-29 18:14:56 +00:00
|
|
|
You have received a new private message at ".PROJECT.".
|
|
|
|
|
|
|
|
From: $logged_in_user->name (ID $logged_in_user->id)
|
|
|
|
Subject: $subject
|
|
|
|
|
|
|
|
$content
|
|
|
|
|
|
|
|
--------------------------
|
|
|
|
To delete or respond to this message, visit:
|
|
|
|
".URL_BASE."pm.php
|
|
|
|
|
2007-12-30 22:02:16 +00:00
|
|
|
To change email preferences, visit:
|
2007-11-29 18:14:56 +00:00
|
|
|
".URL_BASE."edit_forum_preferences_form.php
|
|
|
|
Do not reply to this message.
|
|
|
|
" ;
|
2007-12-30 22:02:16 +00:00
|
|
|
send_email($to_user, "[".PROJECT."] private message", $message);
|
|
|
|
}
|
|
|
|
|
|
|
|
function pm_email_line($notify) {
|
|
|
|
$pm = BoincPrivateMessage::lookup_id($notify->opaque);
|
|
|
|
$from_user = BoincUser::lookup_id($pm->senderid);
|
|
|
|
return "$from_user->name sent you a private message; subject: '$pm->subject'";
|
|
|
|
}
|
|
|
|
|
|
|
|
function pm_web_line($notify) {
|
|
|
|
$pm = BoincPrivateMessage::lookup_id($notify->opaque);
|
|
|
|
$from_user = BoincUser::lookup_id($pm->senderid);
|
|
|
|
return "<a href=pm.php>Private message</a> from $from_user->name, subject: $pm->subject";
|
|
|
|
}
|
|
|
|
|
2008-12-09 22:41:29 +00:00
|
|
|
function pm_send($to_user, $subject, $content, $send_email) {
|
2008-06-05 04:35:21 +00:00
|
|
|
global $g_logged_in_user;
|
2008-09-16 23:06:37 +00:00
|
|
|
$sql_subject = boinc_real_escape_string(strip_tags($subject));
|
2008-12-15 17:46:40 +00:00
|
|
|
$sql_content = boinc_real_escape_string($content);
|
2008-06-05 04:35:21 +00:00
|
|
|
$mid = BoincPrivateMessage::insert("(userid, senderid, date, subject, content) VALUES ($to_user->id, $g_logged_in_user->id, UNIX_TIMESTAMP(), '$sql_subject', '$sql_content')");
|
2007-12-30 22:02:16 +00:00
|
|
|
if (!$mid) {
|
|
|
|
error_page("Couldn't create message");
|
|
|
|
}
|
|
|
|
// send email notification if needed
|
|
|
|
//
|
2008-12-09 22:41:29 +00:00
|
|
|
if ($send_email) {
|
|
|
|
BoincForumPrefs::lookup($to_user);
|
|
|
|
switch ($to_user->prefs->pm_notification) {
|
|
|
|
case 0:
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
send_pm_notification_email(
|
|
|
|
$g_logged_in_user, $to_user, $subject, $content
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2007-12-30 22:02:16 +00:00
|
|
|
|
2008-12-09 22:41:29 +00:00
|
|
|
// create notification in any case
|
|
|
|
//
|
|
|
|
BoincNotify::insert("(userid, create_time, type, opaque) values ($to_user->id, ".time().", ".NOTIFY_PM.", $mid)");
|
|
|
|
}
|
2007-05-26 17:00:01 +00:00
|
|
|
}
|
|
|
|
|
2007-06-14 19:43:11 +00:00
|
|
|
function pm_count($userid, $duration) {
|
|
|
|
$time = time() - $duration;
|
2007-11-12 22:28:17 +00:00
|
|
|
return BoincPrivateMessage::count("senderid=$userid AND date>$time");
|
2007-06-14 19:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function check_pm_count($userid) {
|
|
|
|
if ((pm_count($userid, 60) >= 2) || (pm_count($userid, 600) >= 5) ||
|
|
|
|
(pm_count($userid, 3600) >= 15) || (pm_count($userid, 86400) >= 50)) {
|
2007-08-25 15:04:29 +00:00
|
|
|
error_page(tra("You are not allowed to send privates messages so often. Please wait some time before sending more messages."));
|
2007-06-14 19:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-01 23:04:39 +00:00
|
|
|
function pm_notification($user) {
|
|
|
|
$output = "";
|
2007-11-12 20:57:15 +00:00
|
|
|
$unread = BoincPrivateMessage::count("userid=$user->id AND opened=0");
|
2007-11-01 23:04:39 +00:00
|
|
|
|
2007-11-19 16:44:24 +00:00
|
|
|
$output .= "<a href=\"pm.php?action=inbox\">".tra("Inbox")."</a>";
|
|
|
|
if ($unread) {
|
|
|
|
$output .= "<span class=\"inboxunread\"> ($unread ".tra("unread").")</span>\n";
|
|
|
|
}
|
|
|
|
$output .= " | <a href=\"pm.php?action=new\">".tra("Write")."</a>\n";
|
2007-11-01 23:04:39 +00:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2007-11-26 00:51:00 +00:00
|
|
|
function pm_email_remind($user) {
|
|
|
|
if (!$user->prefs->pm_notification) {
|
|
|
|
return "
|
|
|
|
<br><span class=note>For email notification,
|
|
|
|
<a href=edit_forum_preferences_form.php>edit community prefs</a></span>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2008-01-04 22:59:21 +00:00
|
|
|
function pm_rss($notify, &$title, &$msg, &$url) {
|
|
|
|
$pm = BoincPrivateMessage::lookup_id($notify->opaque);
|
|
|
|
$from_user = BoincUser::lookup_id($pm->senderid);
|
|
|
|
$title = "New private message";
|
|
|
|
$msg = "$from_user->name sent you a private message; subject: $pm->subject";
|
|
|
|
$url = URL_BASE."pm.php";
|
|
|
|
}
|
|
|
|
|
2007-11-12 20:57:15 +00:00
|
|
|
$cvs_version_tracker[]="\$Id: pm.inc 14019 2007-11-01 23:04:39Z davea $";
|
2007-05-26 17:00:01 +00:00
|
|
|
?>
|