2007-05-07 19:34:45 +00:00
|
|
|
<?php
|
|
|
|
|
2007-11-12 22:28:17 +00:00
|
|
|
require_once("../inc/boinc_db.inc");
|
2007-05-07 19:34:45 +00:00
|
|
|
require_once("../inc/email.inc");
|
2007-11-12 20:57:15 +00:00
|
|
|
require_once("../inc/pm.inc");
|
|
|
|
require_once("../inc/forum.inc");
|
2007-05-07 19:34:45 +00:00
|
|
|
require_once("../inc/akismet.inc");
|
|
|
|
|
2007-11-01 23:04:39 +00:00
|
|
|
function show_block_link($userid) {
|
2007-11-12 20:57:15 +00:00
|
|
|
echo " <a href=\"pm.php?action=block&id=$userid\">";
|
2007-11-23 21:05:52 +00:00
|
|
|
show_image(REPORT_POST_IMAGE, "Block messages from this user", "Block user", REPORT_POST_IMAGE_HEIGHT);
|
2007-11-01 23:04:39 +00:00
|
|
|
echo "</a>";
|
|
|
|
}
|
|
|
|
|
2007-05-07 19:34:45 +00:00
|
|
|
$action = get_str("action", true);
|
2007-11-02 20:51:39 +00:00
|
|
|
if ($action == null) {
|
|
|
|
$action = post_str("action", true);
|
|
|
|
}
|
|
|
|
|
2007-10-03 10:03:49 +00:00
|
|
|
if ($action == null) {
|
|
|
|
// Prepend "select_" because translated actions may clash with default actions
|
|
|
|
$action = "select_".post_str("action_select", true);
|
|
|
|
}
|
2007-11-01 23:04:39 +00:00
|
|
|
if ($action == "select_") {
|
|
|
|
$action = "inbox";
|
|
|
|
}
|
2007-05-07 19:34:45 +00:00
|
|
|
|
|
|
|
$logged_in_user = get_logged_in_user();
|
2007-11-20 00:55:35 +00:00
|
|
|
BoincForumPrefs::lookup($logged_in_user);
|
2007-05-07 19:34:45 +00:00
|
|
|
|
2007-11-02 20:51:39 +00:00
|
|
|
function make_script() {
|
|
|
|
echo "
|
|
|
|
<script>
|
|
|
|
function set_all(val) {
|
|
|
|
f = document.msg_list;
|
|
|
|
n = f.elements.length;
|
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
e = f.elements[i];
|
|
|
|
if (e.type=='checkbox') {
|
|
|
|
e.checked = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
2007-12-30 22:02:16 +00:00
|
|
|
// show all private messages,
|
|
|
|
// and delete notifications of new messages
|
|
|
|
//
|
2007-11-02 20:51:39 +00:00
|
|
|
function do_inbox($logged_in_user) {
|
2007-11-01 23:04:39 +00:00
|
|
|
page_head(tra("Private messages").": ".tra("Inbox"));
|
2007-05-26 17:00:01 +00:00
|
|
|
|
2007-11-02 20:51:39 +00:00
|
|
|
make_script();
|
2007-05-26 17:00:01 +00:00
|
|
|
if (get_int("sent", true) == 1) {
|
2007-08-25 15:04:29 +00:00
|
|
|
echo "<div class=\"notice\">".tra("Your message has been sent.")."</div>\n";
|
2007-05-26 17:00:01 +00:00
|
|
|
}
|
2007-11-20 00:55:35 +00:00
|
|
|
$options = get_output_options($logged_in_user);
|
2007-05-26 17:00:01 +00:00
|
|
|
|
2007-12-30 22:02:16 +00:00
|
|
|
BoincNotify::delete_aux("userid=$logged_in_user->id and type=".NOTIFY_PM);
|
|
|
|
|
2007-11-12 22:28:17 +00:00
|
|
|
$msgs = BoincPrivateMessage::enum(
|
2007-11-12 20:57:15 +00:00
|
|
|
"userid=$logged_in_user->id ORDER BY date DESC"
|
|
|
|
);
|
|
|
|
if (count($msgs) == 0) {
|
2007-08-25 15:04:29 +00:00
|
|
|
echo tra("You have no private messages.");
|
2007-05-07 19:34:45 +00:00
|
|
|
} else {
|
2007-11-12 20:57:15 +00:00
|
|
|
echo "<form name=msg_list action=\"pm.php\" method=\"POST\">\n";
|
2007-10-03 10:03:49 +00:00
|
|
|
echo form_tokens($logged_in_user->authenticator);
|
2007-11-03 04:26:47 +00:00
|
|
|
start_table();
|
2007-11-01 23:04:39 +00:00
|
|
|
echo "<tr><th>".tra("Subject")."</th><th>".tra("Sender and date")."</th><th>".tra("Message")."</th></tr>\n";
|
2007-11-02 20:51:39 +00:00
|
|
|
$i = 0;
|
2007-11-12 20:57:15 +00:00
|
|
|
foreach($msgs as $msg) {
|
2007-11-02 20:51:39 +00:00
|
|
|
$i++;
|
|
|
|
$class = ($i%2)? "row0": "row1";
|
|
|
|
echo "<tr class=$class>\n";
|
2007-11-18 22:17:39 +00:00
|
|
|
$checkbox = "<input type=\"checkbox\" name=\"pm_select[]\" value=\"".$msg->id."\">";
|
2007-11-12 20:57:15 +00:00
|
|
|
if (!$msg->opened) {
|
|
|
|
$msg->update("opened=1");
|
2007-05-07 19:34:45 +00:00
|
|
|
}
|
2007-11-12 20:57:15 +00:00
|
|
|
echo "<td valign=top> $checkbox $msg->subject </td>\n";
|
|
|
|
echo "<td valign=top>".user_links(get_user_from_id($msg->senderid));
|
|
|
|
show_block_link($msg->senderid);
|
|
|
|
echo "<br>".time_str($msg->date)."</td>\n";
|
|
|
|
echo "<td valign=top>".output_transform($msg->content, $options)."<p>";
|
2007-11-03 04:26:47 +00:00
|
|
|
$tokens = url_tokens($logged_in_user->authenticator);
|
2007-11-12 20:57:15 +00:00
|
|
|
show_button("pm.php?action=delete&id=$msg->id&$tokens", tra("Delete"), "Delete this message");
|
|
|
|
show_button("pm.php?action=new&replyto=$msg->id", tra("Reply"), "Reply to this message");
|
2007-11-01 23:04:39 +00:00
|
|
|
echo "</td></tr>\n";
|
2007-05-07 19:34:45 +00:00
|
|
|
}
|
2007-11-02 20:51:39 +00:00
|
|
|
echo "
|
|
|
|
<tr><td class=shaded>
|
|
|
|
<a href=\"javascript:set_all(1)\">Select all</a>
|
|
|
|
|
|
|
|
|
<a href=\"javascript:set_all(0)\">Unselect all</a>
|
|
|
|
</td>
|
|
|
|
<td class=shaded colspan=2>
|
|
|
|
<input type=\"submit\" name=\"action_select\" value=\"".tra("Delete")."\">
|
2007-11-03 04:26:47 +00:00
|
|
|
selected messages
|
2007-11-02 20:51:39 +00:00
|
|
|
</td></tr>
|
|
|
|
";
|
2007-05-07 19:34:45 +00:00
|
|
|
end_table();
|
2007-10-03 10:03:49 +00:00
|
|
|
echo "</form>\n";
|
2007-05-07 19:34:45 +00:00
|
|
|
}
|
2007-11-02 20:51:39 +00:00
|
|
|
}
|
|
|
|
|
2007-11-12 20:57:15 +00:00
|
|
|
// the following isn't currently used - we never show single messages
|
|
|
|
//
|
2007-11-02 20:51:39 +00:00
|
|
|
function do_read($logged_in_user) {
|
2007-05-07 19:34:45 +00:00
|
|
|
$id = get_int("id");
|
2007-11-12 20:57:15 +00:00
|
|
|
$message = BoincPrivateMessage::lookup_id($id);
|
|
|
|
if (!$message || $message->userid != $logged_in_user->id) {
|
|
|
|
error_page("no such message");
|
|
|
|
}
|
|
|
|
page_head(tra("Private messages")." : ".$message->subject);
|
|
|
|
pm_header();
|
|
|
|
|
|
|
|
$sender = BoincUser::lookup_id($message->senderid);
|
|
|
|
|
|
|
|
start_table();
|
|
|
|
echo "<tr><th>".tra("Subject")."</th><td>".$message->subject."</td></tr>";
|
|
|
|
echo "<tr><th>".tra("Sender")."</th><td>".user_links($sender);
|
|
|
|
show_block_link($message->senderid);
|
|
|
|
echo "</td></tr>";
|
|
|
|
echo "<tr><th>".tra("Date")."</th><td>".time_str($message->date)."</td></tr>";
|
|
|
|
echo "<tr><th>".tra("Message")."</th><td>".output_transform($message->content, $options)."</td></tr>";
|
|
|
|
echo "<tr><td class=\"pm_footer\"></td><td>\n";
|
|
|
|
echo "<a href=\"pm.php?action=delete&id=$id\">".tra("Delete")."</a>\n";
|
|
|
|
echo " | <a href=\"pm.php?action=new&replyto=$id\">".tra("Reply")."</a>\n";
|
|
|
|
echo " | <a href=\"pm.php?action=inbox\">".tra("Inbox")."</a>\n";
|
|
|
|
end_table();
|
|
|
|
|
|
|
|
if ($message->opened == 0) {
|
|
|
|
$message->update("opened=1");
|
2007-05-07 19:34:45 +00:00
|
|
|
}
|
2007-11-02 20:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function do_new($logged_in_user) {
|
2007-11-12 20:57:15 +00:00
|
|
|
check_banished($logged_in_user);
|
2007-05-07 19:34:45 +00:00
|
|
|
pm_create_new();
|
2007-11-02 20:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function do_delete($logged_in_user) {
|
2007-05-07 19:34:45 +00:00
|
|
|
$id = get_int("id", true);
|
2007-11-12 22:28:17 +00:00
|
|
|
if ($id == null) {
|
|
|
|
$id = post_int("id");
|
|
|
|
}
|
2007-11-03 04:26:47 +00:00
|
|
|
check_tokens($logged_in_user->authenticator);
|
2007-11-12 22:28:17 +00:00
|
|
|
BoincPrivateMessage::delete_aux("userid=".$logged_in_user->id." AND id=$id");
|
2007-11-12 20:57:15 +00:00
|
|
|
header("Location: pm.php");
|
2007-11-02 20:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function do_send($logged_in_user) {
|
2007-11-12 22:28:17 +00:00
|
|
|
check_banished($logged_in_user);
|
2007-05-07 19:34:45 +00:00
|
|
|
check_tokens($logged_in_user->authenticator);
|
2007-06-02 17:11:19 +00:00
|
|
|
|
2008-06-11 19:36:10 +00:00
|
|
|
$to = post_str("to", true);
|
|
|
|
$subject = post_str("subject", true);
|
|
|
|
$content = post_str("content", true);
|
2007-06-02 17:11:19 +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
|
|
|
pm_create_new();
|
|
|
|
}
|
2007-05-07 19:34:45 +00:00
|
|
|
if (($to == null) || ($subject == null) || ($content == null)) {
|
2007-08-25 15:04:29 +00:00
|
|
|
pm_create_new(tra("You need to fill all fields to send a private message"));
|
2007-05-07 19:34:45 +00:00
|
|
|
} else {
|
2007-11-12 22:28:17 +00:00
|
|
|
akismet_check($logged_in_user, $content);
|
2007-05-07 19:34:45 +00:00
|
|
|
$to = str_replace(", ", ",", $to); // Filter out spaces after separator
|
|
|
|
$users = explode(",", $to);
|
|
|
|
|
|
|
|
$userlist = array();
|
|
|
|
$userids = array(); // To prevent from spamming a single user by adding it multiple times
|
|
|
|
|
|
|
|
foreach ($users as $username) {
|
|
|
|
$user = explode(" ", $username);
|
|
|
|
if (is_numeric($user[0])) { // user ID is gived
|
|
|
|
$userid = $user[0];
|
|
|
|
$user = lookup_user_id($userid);
|
|
|
|
if ($user == null) {
|
2007-08-25 15:04:29 +00:00
|
|
|
pm_create_new(tra("Could not find user with id %1", $userid));
|
2007-05-07 19:34:45 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$user = lookup_user_name($username);
|
|
|
|
if ($user == null) {
|
2007-08-25 15:04:29 +00:00
|
|
|
pm_create_new(tra("Could not find user with username %1", $username));
|
2007-05-11 20:34:16 +00:00
|
|
|
} elseif ($user == -1) { // Non-unique username
|
2007-08-25 15:04:29 +00:00
|
|
|
pm_create_new(tra("%1 is not a unique username; you will have to use user ID", $username));
|
2007-05-07 19:34:45 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-12 20:57:15 +00:00
|
|
|
BoincForumPrefs::lookup($user);
|
|
|
|
if (is_ignoring($user, $logged_in_user)) {
|
2007-08-25 15:04:29 +00:00
|
|
|
pm_create_new(tra("User %1 (ID: %2) is not accepting private messages from you.", $user->name, $user->id));
|
2007-05-07 19:34:45 +00:00
|
|
|
}
|
|
|
|
if ($userids[$user->id] == null) {
|
|
|
|
$userlist[] = $user;
|
|
|
|
$userids[$user->id] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($userlist as $user) {
|
2007-06-14 19:43:11 +00:00
|
|
|
check_pm_count($logged_in_user->id);
|
2007-05-07 19:34:45 +00:00
|
|
|
pm_send($user, $subject, $content);
|
|
|
|
}
|
|
|
|
|
2007-11-12 20:57:15 +00:00
|
|
|
Header("Location: pm.php?action=inbox&sent=1");
|
2007-05-07 19:34:45 +00:00
|
|
|
}
|
2007-11-02 20:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function do_block($logged_in_user) {
|
2007-05-26 17:00:01 +00:00
|
|
|
$id = get_int("id");
|
2007-11-12 20:57:15 +00:00
|
|
|
$user = BoincUser::lookup_id($id);
|
|
|
|
if (!$user) {
|
2007-08-25 15:04:29 +00:00
|
|
|
error_page(tra("No such user"));
|
2007-05-07 19:34:45 +00:00
|
|
|
}
|
2007-11-12 20:57:15 +00:00
|
|
|
page_head(tra("Really block %1?", $user->name));
|
|
|
|
echo "<div>".tra("Are you really sure you want to block user %1 from sending you private messages?", $user->name)."<br>\n";
|
|
|
|
echo tra("Please note that you can only block a limited amount of users.")."</div>\n";
|
|
|
|
echo "<div>".tra("Once the user has been blocked you can unblock it using forum preferences page.")."</div>\n";
|
|
|
|
|
|
|
|
echo "<form action=\"pm.php\" method=\"POST\">\n";
|
|
|
|
echo form_tokens($logged_in_user->authenticator);
|
|
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"confirmedblock\">\n";
|
|
|
|
echo "<input type=\"hidden\" name=\"id\" value=\"$id\">\n";
|
|
|
|
echo "<input type=\"submit\" value=\"".tra("Add user to filter")."\">\n";
|
|
|
|
echo "<a href=\"pm.php?action=inbox\">".tra("No, cancel")."</a>\n";
|
|
|
|
echo "</form>\n";
|
2007-11-02 20:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function do_confirmedblock($logged_in_user) {
|
2007-05-26 17:00:01 +00:00
|
|
|
check_tokens($logged_in_user->authenticator);
|
|
|
|
$id = post_int("id");
|
2007-11-12 20:57:15 +00:00
|
|
|
$blocked_user = BoincUser::lookup_id($id);
|
|
|
|
if (!$blocked_user) error_page("no such user");
|
|
|
|
add_ignored_user($logged_in_user, $blocked_user);
|
2007-06-02 17:11:19 +00:00
|
|
|
|
2007-11-12 20:57:15 +00:00
|
|
|
page_head(tra("User %1 blocked", $blocked_user->name));
|
2007-05-26 17:00:01 +00:00
|
|
|
|
2007-11-12 20:57:15 +00:00
|
|
|
echo "<div>".tra("User %1 has been blocked from sending you private messages.", $blocked_user->name)."\n";
|
2007-08-25 15:04:29 +00:00
|
|
|
echo tra("To unblock, visit %1message board preferences%2", "<a href=\"edit_forum_preferences_form.php\">", "</a>")."</div>\n";
|
2007-11-02 20:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function do_delete_selected($logged_in_user) {
|
2007-10-03 10:03:49 +00:00
|
|
|
check_tokens($logged_in_user->authenticator);
|
|
|
|
foreach ($_POST["pm_select"] as $id) {
|
2007-11-12 22:28:17 +00:00
|
|
|
$id = BoincDb::escape_string($id);
|
2007-11-12 20:57:15 +00:00
|
|
|
$msg = BoincPrivateMessage::lookup_id($id);
|
|
|
|
if ($msg && $msg->userid == $logged_in_user->id) {
|
|
|
|
$msg->delete();
|
2007-10-03 10:03:49 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-12 20:57:15 +00:00
|
|
|
Header("Location: pm.php?action=inbox&deleted=1");
|
2007-11-02 20:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function do_mark_as_read_selected($logged_in_user) {
|
2007-10-03 10:03:49 +00:00
|
|
|
check_tokens($logged_in_user->authenticator);
|
|
|
|
foreach ($_POST["pm_select"] as $id) {
|
2007-11-12 22:28:17 +00:00
|
|
|
$id = BoincDb::escape_string($id);
|
2007-11-12 20:57:15 +00:00
|
|
|
$msg = BoincPrivateMessage::lookup_id($id);
|
|
|
|
if ($msg && $msg->userid == $logged_in_user->id) {
|
|
|
|
$msg->update("opened=1");
|
2007-10-03 10:03:49 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-12 20:57:15 +00:00
|
|
|
Header("Location: pm.php?action=inbox");
|
2007-11-02 20:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function do_mark_as_unread_selected($logged_in_user) {
|
2007-10-03 10:03:49 +00:00
|
|
|
check_tokens($logged_in_user->authenticator);
|
|
|
|
foreach ($_POST["pm_select"] as $id) {
|
2007-11-12 22:28:17 +00:00
|
|
|
$id = BoincDb::escape_string($id);
|
2007-11-12 20:57:15 +00:00
|
|
|
$msg = BoincPrivateMessage::lookup_id($id);
|
|
|
|
if ($msg && $msg->userid == $logged_in_user->id) {
|
|
|
|
$msg->update("opened=0");
|
2007-10-03 10:03:49 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-12 20:57:15 +00:00
|
|
|
Header("Location: pm.php?action=inbox");
|
2007-05-07 19:34:45 +00:00
|
|
|
}
|
|
|
|
|
2007-11-02 20:51:39 +00:00
|
|
|
if ($action == "inbox") {
|
|
|
|
do_inbox($logged_in_user);
|
|
|
|
} elseif ($action == "read") {
|
|
|
|
do_read($logged_in_user);
|
|
|
|
} elseif ($action == "new") {
|
|
|
|
do_new($logged_in_user);
|
|
|
|
} elseif ($action == "delete") {
|
|
|
|
do_delete($logged_in_user);
|
|
|
|
} elseif ($action == "send") {
|
|
|
|
do_send($logged_in_user);
|
|
|
|
} elseif ($action == "block") {
|
|
|
|
do_block($logged_in_user);
|
|
|
|
} elseif ($action == "confirmedblock") {
|
|
|
|
do_confirmedblock($logged_in_user);
|
|
|
|
} elseif ($action == "select_".tra("Delete")) {
|
|
|
|
do_delete_selected($logged_in_user);
|
|
|
|
} elseif ($action == "select_".tra("Mark as read")) {
|
|
|
|
do_mark_as_read_selected($logged_in_user);
|
|
|
|
} elseif ($action == "select_".tra("Mark as unread")) {
|
|
|
|
do_mark_as_unread_selected($logged_in_user);
|
|
|
|
} else {
|
|
|
|
error_page("Unknown action");
|
|
|
|
}
|
|
|
|
|
2007-05-26 17:00:01 +00:00
|
|
|
page_tail();
|
2007-05-07 19:34:45 +00:00
|
|
|
|
2007-11-12 20:57:15 +00:00
|
|
|
$cvs_version_tracker[]="\$Id: pm.php 14077 2007-11-03 04:26:47Z davea $";
|
2007-05-07 19:34:45 +00:00
|
|
|
?>
|