mirror of https://github.com/BOINC/boinc.git
Private message functionality for the forums.
NOTE: needs database update. svn path=/trunk/boinc/; revision=12499
This commit is contained in:
parent
69e5386c8b
commit
4332736ae9
|
@ -4094,3 +4094,28 @@ David 27 Apr 2007
|
|||
html/ops/
|
||||
remind.php
|
||||
mass_email_script.php
|
||||
|
||||
Rytis 29 Apr 2007
|
||||
- Private message functionality for the forums.
|
||||
NOTE: needs database update.
|
||||
|
||||
html/
|
||||
user/
|
||||
forum_forum.php
|
||||
forum_help_desk.php
|
||||
forum_index.php
|
||||
forum_pm.php (new)
|
||||
white.css
|
||||
img/
|
||||
pm.png (new)
|
||||
|
||||
inc/
|
||||
db.inc
|
||||
forum.inc
|
||||
forum_user.inc
|
||||
user.inc
|
||||
|
||||
ops/
|
||||
db_update.php
|
||||
|
||||
db/schema.sql
|
||||
|
|
|
@ -453,3 +453,15 @@ create table sent_email (
|
|||
-- 6 = fundraising appeal
|
||||
primary key(userid)
|
||||
) TYPE=MyISAM;
|
||||
|
||||
create table private_messages (
|
||||
id int(10) unsigned not null auto_increment,
|
||||
userid int(10) unsigned not null,
|
||||
senderid int(10) unsigned not null,
|
||||
date int(10) unsigned not null,
|
||||
opened tinyint(1) unsigned not null default '0',
|
||||
subject varchar(255) not null,
|
||||
content text not null,
|
||||
primary key(id),
|
||||
key userid (userid)
|
||||
) TYPE=MyISAM;
|
|
@ -61,6 +61,20 @@ function lookup_user_email_addr($email_addr) {
|
|||
return null;
|
||||
}
|
||||
|
||||
function lookup_user_name($name) {
|
||||
$result = mysql_query("SELECT * FROM user WHERE name='".mysql_escape_string($name)."'");
|
||||
if ($result) {
|
||||
if (mysql_num_rows($result) == 1) {
|
||||
return mysql_fetch_object($result);
|
||||
} elseif (mysql_num_rows($result) == 0) {
|
||||
return null;
|
||||
} else {
|
||||
return -1; // Non-unique username
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function lookup_host($id) {
|
||||
$result = mysql_query("select * from host where id=$id");
|
||||
if ($result) {
|
||||
|
|
|
@ -393,6 +393,34 @@ function end_forum_table() {
|
|||
* Output the forum/thread title.
|
||||
**/
|
||||
function show_forum_title($forum=NULL, $thread=NULL) {
|
||||
start_table_noborder();
|
||||
echo "<tr>\n";
|
||||
|
||||
// Search
|
||||
echo "<td><form action=\"forum_search_action.php\" method=\"POST\">
|
||||
<input type=\"hidden\" name=\"search_max_time\" value=\"30\">
|
||||
<input type=\"hidden\" name=\"search_forum\" value=\"-1\">
|
||||
<input type=\"hidden\" name=\"search_sort\" value=\"5\">
|
||||
<input type=\"text\" name=\"search_keywords\">
|
||||
<input type=\"submit\" value=\"search\"><br>
|
||||
<span class=\"smalltext\"><a href=\"forum_search.php\">advanced search</a></span>
|
||||
</form>
|
||||
";
|
||||
echo "</td>\n";
|
||||
|
||||
$logged_in_user = get_logged_in_user(false);
|
||||
// Custom stuff for logged in user
|
||||
if ($logged_in_user) {
|
||||
echo "<td align=\"right\">\n";
|
||||
|
||||
// Private messages
|
||||
echo pm_notification($logged_in_user);
|
||||
|
||||
echo "</td>\n";
|
||||
}
|
||||
echo "</tr>\n";
|
||||
end_table();
|
||||
|
||||
echo "<p>\n";
|
||||
if ($forum) {
|
||||
$category = $forum->getCategory();
|
||||
|
@ -543,4 +571,21 @@ function can_reply($thread, $user) {
|
|||
}
|
||||
}
|
||||
|
||||
function pm_notification($user) {
|
||||
$output = "";
|
||||
$pm = mysql_query("SELECT COUNT(*) AS unread FROM private_messages WHERE userid=".$user->id." AND opened=0");
|
||||
$pm = mysql_fetch_object($pm);
|
||||
if ($pm->unread > 1) {
|
||||
$output .= "<strong><a href=\"forum_pm.php?action=inbox\">You have ".$pm->unread." unread private messages.</a> </strong>";
|
||||
} elseif ($pm->unread == 1) {
|
||||
$output .= "<strong><a href=\"forum_pm.php?action=inbox\">You have one unread private message.</a> </strong>";
|
||||
} else {
|
||||
$output .= "You have no unread private messages. ";
|
||||
}
|
||||
|
||||
$output .= "| <a href=\"forum_pm.php?action=inbox\">Inbox</a>\n";
|
||||
$output .= "| <a href=\"forum_pm.php?action=new\">Write</a>\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -370,17 +370,7 @@ function newUser($id, $optional_dbobj="", $optional_prefobj=""){
|
|||
* Construct links to the given user
|
||||
**/
|
||||
function re_user_links($user) {
|
||||
$x = '<a href="show_user.php?userid='.$user->getID().'">'.$user->getName().'</a>';
|
||||
if ($user->hasProfile()) {
|
||||
$x .= ' <a href="view_profile.php?userid='.$user->getID().'"><img border="0" src="img/head_20.png"></a>';
|
||||
}
|
||||
# Does this project accept donations?
|
||||
# If so, do you want to have a link next to user name as it appears on the web site?
|
||||
if ($user->hasDonated() == 1) {
|
||||
@require_once("../project/donations.inc");
|
||||
$x .= DONATION_LINK;
|
||||
}
|
||||
return $x;
|
||||
return user_links(get_user_from_id($user->getID()));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -198,6 +198,8 @@ function show_user_info_private($user) {
|
|||
if ($tot) {
|
||||
row2("Message boards", "<a href=".URL_BASE."forum_user_posts.php?userid=$user->id>$tot posts</a>");
|
||||
}
|
||||
|
||||
row2("Private messages", pm_notification($user));
|
||||
|
||||
row1("Teams");
|
||||
if ($user->teamid) {
|
||||
|
|
|
@ -365,11 +365,26 @@ function update_4_24_2007() {
|
|||
|
||||
}
|
||||
|
||||
function update_4_29_2007() {
|
||||
do_query("CREATE TABLE `private_messages` (
|
||||
`id` int(10) unsigned NOT NULL auto_increment,
|
||||
`userid` int(10) unsigned NOT NULL,
|
||||
`senderid` int(10) unsigned NOT NULL,
|
||||
`date` int(10) unsigned NOT NULL,
|
||||
`opened` tinyint(1) unsigned NOT NULL default '0',
|
||||
`subject` varchar(255) NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `userid` (`userid`)
|
||||
) TYPE=MyISAM;"
|
||||
);
|
||||
}
|
||||
|
||||
// modify the following to call the function you want.
|
||||
// Make sure you do all needed functions, in order.
|
||||
// (Look at your DB structure using "explain" queries to see
|
||||
// which ones you need).
|
||||
|
||||
//update_4_07_2007();
|
||||
//update_4_29_2007();
|
||||
|
||||
?>
|
||||
|
|
|
@ -43,22 +43,14 @@ if ($Category->getType()!=0){
|
|||
// Allow users with a linktab-browser to get some usefull links
|
||||
echo '<link href="forum_index.php" rel="up" title="Forum Index">';
|
||||
|
||||
|
||||
show_forum_title($forum, NULL);
|
||||
|
||||
echo '
|
||||
<table width="100%" cellspacing="0" cellpadding="0">
|
||||
<tr valign="bottom">
|
||||
<td colspan=2>';
|
||||
|
||||
show_forum_title($forum, NULL);
|
||||
|
||||
if ($Category->getType()!=0){
|
||||
echo "
|
||||
<div class=\"helpdesk_note\">
|
||||
<br /><form action=\"forum_search.php\"><input type=\"hidden\" name=\"forumid\" value=\"".$forum->getID()."\"><input type=\"submit\" value=\"Search ".$forum->getTitle()."\"></form>
|
||||
To keep the number of repeated posts to a minimum please <a href=\"forum_search.php\"><b>search</b></a> before you create a new thread.
|
||||
</div></td></tr><tr><td>";
|
||||
}
|
||||
|
||||
|
||||
echo '<a href="forum_post.php?id='.$id.'">';
|
||||
echo "[Create a new thread]</a><br><br></td>";
|
||||
echo ' <form action="forum_forum.php" method="get">
|
||||
|
|
|
@ -7,24 +7,17 @@ require_once('../inc/time.inc');
|
|||
|
||||
db_init();
|
||||
|
||||
get_logged_in_user(false);
|
||||
|
||||
page_head("Questions and answers");
|
||||
|
||||
echo "<p>
|
||||
Talk live via Skype with a volunteer, in any of several languages.
|
||||
Go to
|
||||
<a href=\"http://boinc.berkeley.edu/help.php\">BOINC Online Help</a>.</p>
|
||||
<p>
|
||||
<form action=\"forum_search_action.php\" method=\"POST\">
|
||||
<input type=\"hidden\" name=\"search_max_time\" value=\"30\">
|
||||
<input type=\"hidden\" name=\"search_forum\" value=\"-1\">
|
||||
<input type=\"hidden\" name=\"search_sort\" value=\"5\">
|
||||
<input type=\"text\" name=\"search_keywords\">
|
||||
<input type=\"submit\" value=\"Start forum search\">
|
||||
<span class=\"smalltext\">or do <a href=\"forum_search.php\">advanced search</a></span>
|
||||
</form>
|
||||
</p>
|
||||
";
|
||||
|
||||
show_forum_title(null, null);
|
||||
start_forum_table(array("Topic", "# Questions", "Last post"));
|
||||
|
||||
$categories = getHelpDeskCategories();
|
||||
|
|
|
@ -9,6 +9,8 @@ require_once('../inc/forum.inc');
|
|||
require_once('../inc/forum_std.inc');
|
||||
db_init();
|
||||
|
||||
get_logged_in_user(false);
|
||||
|
||||
function forum_summary($forum) {
|
||||
echo '
|
||||
<tr class="row1">
|
||||
|
@ -32,16 +34,6 @@ echo "
|
|||
<a href=forum_help_desk.php>Questions & answers</a>
|
||||
area instead of the Message boards.
|
||||
</p>
|
||||
<p>
|
||||
<form action=\"forum_search_action.php\" method=\"POST\">
|
||||
<input type=\"hidden\" name=\"search_max_time\" value=\"30\">
|
||||
<input type=\"hidden\" name=\"search_forum\" value=\"-1\">
|
||||
<input type=\"hidden\" name=\"search_sort\" value=\"5\">
|
||||
<input type=\"text\" name=\"search_keywords\">
|
||||
<input type=\"submit\" value=\"Start forum search\">
|
||||
<span class=\"smalltext\">or do <a href=\"forum_search.php\">advanced search</a></span>
|
||||
</form>
|
||||
</p>
|
||||
";
|
||||
|
||||
show_forum_title(NULL, NULL, false);
|
||||
|
|
|
@ -0,0 +1,239 @@
|
|||
<?php
|
||||
$cvs_version_tracker[]="\$Id: util.inc,v 1.119 2007/03/14 18:05:28 mattl Exp $";
|
||||
|
||||
require_once("../inc/forum.inc");
|
||||
require_once("../inc/forum_std.inc");
|
||||
require_once("../inc/email.inc");
|
||||
require_once("../inc/akismet.inc");
|
||||
|
||||
db_init();
|
||||
|
||||
$action = get_str("action", true);
|
||||
if ($action == null) { $action = post_str("action", true); }
|
||||
if ($action == null) { $action = "inbox"; }
|
||||
|
||||
$logged_in_user = get_logged_in_user();
|
||||
|
||||
if ($action == "inbox") {
|
||||
page_head("Private messages : Inbox");
|
||||
pm_header();
|
||||
|
||||
$query = mysql_query("SELECT * FROM private_messages WHERE userid=".$logged_in_user->id." ORDER BY date DESC");
|
||||
if (mysql_num_rows($query) == 0) {
|
||||
echo "You have no private messages.";
|
||||
} else {
|
||||
start_table();
|
||||
print "<tr><th>Subject</th><th>Sender</th><th>Date</th></tr>\n";
|
||||
while ($row = mysql_fetch_object($query)) {
|
||||
print "<tr>\n";
|
||||
$subject = "<a href=\"forum_pm.php?action=read&id=".$row->id."\">".$row->subject."</a>";
|
||||
if ($row->opened) {
|
||||
print "<td>".$subject."</td>\n";
|
||||
} else {
|
||||
print "<td><strong>".$subject."</strong></td>\n";
|
||||
}
|
||||
print "<td>".user_links(get_user_from_id($row->senderid))."</td>\n";
|
||||
print "<td>".time_str($row->date)."</td>\n";
|
||||
print "</tr>\n";
|
||||
}
|
||||
end_table();
|
||||
}
|
||||
|
||||
} elseif ($action == "read") {
|
||||
$id = get_int("id");
|
||||
$message = mysql_query("SELECT * FROM private_messages WHERE id=".$id." AND userid=".$logged_in_user->id);
|
||||
if (mysql_num_rows($message) == 0) {
|
||||
error_page("No such message.");
|
||||
} else {
|
||||
$message = mysql_fetch_object($message);
|
||||
page_head("Private messages : ".$message->subject);
|
||||
pm_header();
|
||||
|
||||
$options = new output_options;
|
||||
|
||||
start_table();
|
||||
echo "<tr><th>Subject</th><td>".$message->subject."</td></tr>";
|
||||
echo "<tr><th>Sender</th><td>".user_links(get_user_from_id($message->senderid))."</td></tr>";
|
||||
echo "<tr><th>Date</th><td>".time_str($message->date)."</td></tr>";
|
||||
echo "<tr><th>Message</th><td>".output_transform($message->content, $options)."</td></tr>";
|
||||
echo "<tr><td class=\"pm_footer\"></td><td>\n";
|
||||
echo "<a href=\"forum_pm.php?action=delete&id=$id\">Delete</a>\n";
|
||||
echo " | <a href=\"forum_pm.php?action=new&replyto=$id\">Reply</a>\n";
|
||||
echo " | <a href=\"forum_pm.php?action=inbox\">Inbox</a>\n";
|
||||
end_table();
|
||||
|
||||
if ($message->opened == 0) {
|
||||
mysql_query("UPDATE private_messages SET opened=1 WHERE id=$id");
|
||||
}
|
||||
}
|
||||
|
||||
} elseif ($action == "new") {
|
||||
pm_create_new();
|
||||
} elseif ($action == "delete") {
|
||||
$id = get_int("id", true);
|
||||
if ($id == null) { $id = post_int("id"); }
|
||||
if (post_int("confirm", true) == 1) {
|
||||
check_tokens($logged_in_user->authenticator);
|
||||
mysql_query("DELETE FROM private_messages WHERE userid=".$logged_in_user->id." AND id=$id");
|
||||
header("Location: forum_pm.php");
|
||||
} else {
|
||||
$message = mysql_query("SELECT * FROM private_messages WHERE userid=".$logged_in_user->id." AND id=$id");
|
||||
if (mysql_num_rows($message) == 1) {
|
||||
$message = mysql_fetch_object($message);
|
||||
$sender = lookup_user_id($message->senderid);
|
||||
page_head("Private messages : Really delete?");
|
||||
pm_header();
|
||||
echo "<div>Are you sure you want to delete the message with subject \"".$message->subject."\" (sent by ".$sender->name." on ".time_str($message->date).")?</div>\n";
|
||||
echo "<form action=\"forum_pm.php\" method=\"post\">\n";
|
||||
echo form_tokens($logged_in_user->authenticator);
|
||||
echo "<input type=\"hidden\" name=\"action\" value=\"delete\">\n";
|
||||
echo "<input type=\"hidden\" name=\"confirm\" value=\"1\">\n";
|
||||
echo "<input type=\"hidden\" name=\"id\" value=\"$id\">\n";
|
||||
echo "<input type=\"submit\" value=\"Yes, delete\">\n";
|
||||
echo "</form>\n";
|
||||
echo "<form action=\"forum_pm.php\" method=\"post\">\n";
|
||||
echo "<input type=\"hidden\" name=\"action\" value=\"inbox\">\n";
|
||||
echo "<input type=\"submit\" value=\"No, cancel\">\n";
|
||||
echo "</form>\n";
|
||||
} else {
|
||||
error_page("No such message.");
|
||||
}
|
||||
}
|
||||
} elseif ($action == "send") {
|
||||
check_tokens($logged_in_user->authenticator);
|
||||
|
||||
$to = post_str("to", true);
|
||||
$subject = post_str("subject", true);
|
||||
$content = post_str("content", true);
|
||||
|
||||
if (($to == null) || ($subject == null) || ($content == null)) {
|
||||
pm_create_new("You need to fill all fields to send a private message");
|
||||
} else {
|
||||
akismet_check(new User($logged_in_user->id), $content);
|
||||
$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) {
|
||||
pm_create_new("Could not find user with id $userid");
|
||||
}
|
||||
} else {
|
||||
$user = lookup_user_name($username);
|
||||
if ($user == null) {
|
||||
pm_create_new("Could not find user $username");
|
||||
}
|
||||
}
|
||||
$ignorelist = mysql_query("SELECT ignorelist FROM forum_preferences WHERE userid=".$user->id);
|
||||
$ignorelist = mysql_fetch_object($ignorelist);
|
||||
$ignorelist = $ignorelist->ignorelist;
|
||||
$ignorelist = explode("|", $ignorelist);
|
||||
if (in_array($logged_in_user->id, $ignorelist)) {
|
||||
pm_create_new("User ".$user->name." (ID: ".$user->id.") is not accepting private messages from you.");
|
||||
}
|
||||
if ($userids[$user->id] == null) {
|
||||
$userlist[] = $user;
|
||||
$userids[$user->id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($userlist as $user) {
|
||||
pm_send($user, $subject, $content);
|
||||
}
|
||||
|
||||
Header("Location: forum_pm.php?action=inbox&sent=1");
|
||||
}
|
||||
}
|
||||
|
||||
page_tail();
|
||||
|
||||
|
||||
function pm_header() {
|
||||
echo "<div>\n";
|
||||
echo " <a href=\"forum_pm.php?action=inbox\">Inbox</a>\n";
|
||||
echo " | <a href=\"forum_pm.php?action=new\">Write</a>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function pm_create_new($error = null) {
|
||||
page_head("Private messages : Create new");
|
||||
pm_header();
|
||||
|
||||
global $logged_in_user;
|
||||
$replyto = get_int("replyto", true);
|
||||
$userid = get_int("userid", true);
|
||||
|
||||
|
||||
if ($replyto) {
|
||||
$message = mysql_query("SELECT * FROM private_messages WHERE userid=".$logged_in_user->id." AND id=$replyto");
|
||||
if ($message) {
|
||||
$message = mysql_fetch_object($message);
|
||||
$content = "[quote]".$message->content."[/quote]\n";
|
||||
$userid = $message->senderid;
|
||||
$user = get_user_from_id($userid);
|
||||
if ($user != null) {
|
||||
$writeto = $userid." (".$user->name.")";
|
||||
}
|
||||
$subject = $message->subject;
|
||||
if (substr($subject, 0, 3) != "re:") {
|
||||
$subject = "re: ".$subject;
|
||||
}
|
||||
}
|
||||
} elseif ($userid) {
|
||||
$user = get_user_from_id($userid);
|
||||
if ($user != null) {
|
||||
$writeto = $userid." (".$user->name.")";
|
||||
}
|
||||
} else {
|
||||
$writeto = post_str("to", true);
|
||||
$subject = post_str("subject", true);
|
||||
$content = post_str("content", true);
|
||||
}
|
||||
|
||||
if ($error != null) {
|
||||
echo "<div class=\"error\">$error</div>\n";
|
||||
}
|
||||
|
||||
echo "<form action=\"forum_pm.php\" method=\"post\">\n";
|
||||
echo "<input type=\"hidden\" name=\"action\" value=\"send\">\n";
|
||||
echo form_tokens($logged_in_user->authenticator);
|
||||
start_table();
|
||||
echo "<tr><th>To<br /><span class=\"smalltext\">User IDs or unique usernames, separated with commas</span></th>\n";
|
||||
echo "<td><input type=\"text\" name=\"to\" value=\"$writeto\" size=\"60\"></td></tr>\n";
|
||||
echo "<tr><th>Subject</th><td><input type=\"text\" name=\"subject\" value=\"$subject\" size=\"60\"></td></tr>\n";
|
||||
echo "<tr><th>Message<br /><span class=\"smalltext\">".html_info()."</span></th>\n";
|
||||
echo "<td><textarea name=\"content\" rows=\"18\" cols=\"80\">$content</textarea></td></tr>\n";
|
||||
echo "<tr><td></td><td><input type=\"submit\" value=\"Send message\"></td></tr>\n";
|
||||
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_escape_string($subject);
|
||||
$sql_content = mysql_escape_string($content);
|
||||
mysql_query("INSERT INTO private_messages (userid, senderid, date, subject, content) VALUES ($userid, $senderid, UNIX_TIMESTAMP(), '$sql_subject', '$sql_content')");
|
||||
if ($to->send_email == 1) { // Send email notification
|
||||
$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";
|
||||
$message .= URL_BASE."forum_pm.php\n\n";
|
||||
$message .= "Do not reply to this message. To disable email notification, go to\n";
|
||||
$message .= URL_BASE."prefs.php?subset=project\n";
|
||||
$message .= "and change email notification settings.\n";
|
||||
|
||||
send_email($to, "[".PROJECT."] Private message notification", $message);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Binary file not shown.
After Width: | Height: | Size: 224 B |
|
@ -282,3 +282,9 @@ span.news_date {
|
|||
.smalltext {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #ff0000;
|
||||
font-weight: bold;
|
||||
font-size: 1.1em;
|
||||
}
|
Loading…
Reference in New Issue