2007-05-26 17:00:01 +00:00
|
|
|
<?php
|
2007-11-12 20:57:15 +00:00
|
|
|
|
|
|
|
require_once("boinc_db.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) {
|
2007-08-25 15:04:29 +00:00
|
|
|
page_head(tra("Private messages")." : ".tra("Create new"));
|
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
|
|
|
global $logged_in_user;
|
|
|
|
$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);
|
|
|
|
if (!$message || $message->userid != $logged_in_user->id) {
|
|
|
|
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);
|
2007-09-12 14:08:34 +00:00
|
|
|
$subject = stripslashes(post_str("subject", true));
|
|
|
|
$content = stripslashes(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
|
|
|
}
|
|
|
|
|
2007-11-12 20:57:15 +00:00
|
|
|
echo "<form action=\"pm.php\" method=\"post\">\n";
|
2007-05-26 17:00:01 +00:00
|
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"send\">\n";
|
|
|
|
echo form_tokens($logged_in_user->authenticator);
|
|
|
|
start_table();
|
2007-08-25 15:04:29 +00:00
|
|
|
echo "<tr><th>".tra("To")."<br /><span class=\"smalltext\">".tra("User IDs or unique usernames, separated with commas")."</span></th>\n";
|
2007-05-26 17:00:01 +00:00
|
|
|
echo "<td><input type=\"text\" name=\"to\" value=\"$writeto\" size=\"60\"></td></tr>\n";
|
2007-08-25 15:04:29 +00:00
|
|
|
echo "<tr><th>".tra("Subject")."</th><td><input type=\"text\" name=\"subject\" value=\"$subject\" size=\"60\"></td></tr>\n";
|
|
|
|
echo "<tr><th>".tra("Message")."<br /><span class=\"smalltext\">".html_info()."</span></th>\n";
|
2007-05-26 17:00:01 +00:00
|
|
|
echo "<td><textarea name=\"content\" rows=\"18\" cols=\"80\">$content</textarea></td></tr>\n";
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
function pm_send($to, $subject, $content) {
|
|
|
|
global $logged_in_user;
|
|
|
|
$userid = $to->id;
|
|
|
|
$senderid = $logged_in_user->id;
|
|
|
|
$sql_subject = mysql_real_escape_string($subject);
|
|
|
|
$sql_content = mysql_real_escape_string($content);
|
2007-11-12 20:57:15 +00:00
|
|
|
$to_user = BoincUser::lookup_id($userid);
|
|
|
|
BoincForumPrefs::lookup($to_user);
|
|
|
|
$send_email = false;
|
|
|
|
if ($to_user->prefs->pm_notification) $send_email = true;
|
|
|
|
BoincPrivateMessage::insert("(userid, senderid, date, subject, content) VALUES ($userid, $senderid, UNIX_TIMESTAMP(), '$sql_subject', '$sql_content')");
|
2007-06-04 19:35:11 +00:00
|
|
|
if ($send_email) { // Send email notification
|
2007-05-26 17:00:01 +00:00
|
|
|
$message = "Dear ".$to->name.",\n\n";
|
|
|
|
$message .= "You have received a new private message at ".PROJECT." from ".$logged_in_user->name.", entitled \"".$subject."\".\n\n";
|
|
|
|
$message .= "To read the original version, respond to, or delete this message, you must log in here:\n";
|
2007-11-18 22:42:47 +00:00
|
|
|
$message .= URL_BASE."pm.php\n\n";
|
2007-05-26 17:00:01 +00:00
|
|
|
$message .= "Do not reply to this message. To disable email notification, go to\n";
|
2007-11-18 22:42:47 +00:00
|
|
|
$message .= URL_BASE."prefs.php?subset=project\n";
|
2007-05-26 17:00:01 +00:00
|
|
|
$message .= "and change email notification settings.\n";
|
|
|
|
|
|
|
|
send_email($to, "[".PROJECT."] Private message notification", $message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
?>
|