- user web: change forum prefs editing to use new DB interface

svn path=/trunk/boinc/; revision=14175
This commit is contained in:
David Anderson 2007-11-13 17:18:34 +00:00
parent 218aec5717
commit 83362a31ed
5 changed files with 145 additions and 106 deletions

View File

@ -10853,3 +10853,14 @@ Rom 13 Nov 2007
<All Files> <All Files>
curl/mswin/ curl/mswin/
<All Files> <All Files>
David 13 Nov 2007
- user web: change forum prefs editing to use new DB interface
html/
inc/
forum.inc
forum_db.inc
user/
edit_forum_preferences_action.php
edit_forum_preferences_forum.php

View File

@ -370,6 +370,10 @@ function show_posts(
} }
} }
function get_ignored_list($user) {
return explode("|", $user->prefs->ignorelist);
}
function add_ignored_user($user, $other_user) { function add_ignored_user($user, $other_user) {
$list = explode("|", $user->prefs->ignorelist); $list = explode("|", $user->prefs->ignorelist);
foreach ($list as $key=>$userid) { foreach ($list as $key=>$userid) {

View File

@ -121,6 +121,10 @@ class BoincForumPrefs {
$clause = "$clause where userid=$this->userid"; $clause = "$clause where userid=$this->userid";
return $db->update_aux('forum_preferences', $clause); return $db->update_aux('forum_preferences', $clause);
} }
function delete() {
$db = BoincDb::get();
return $db->delete_aux('forum_preferences', "userid=$this->userid");
}
} }
class BoincForumLogging { class BoincForumLogging {

View File

@ -1,51 +1,44 @@
<?php <?php
/**
* This page commits the chanegs made in edit_forum_preferences_form.php to // commit the chanegs made in edit_forum_preferences_form.php to the database.
* the database.
**/
require_once("../inc/forum.inc"); require_once("../inc/forum.inc");
require_once("../inc/image.inc"); // Avatar scaling require_once("../inc/image.inc"); // Avatar scaling
require_once("../inc/forum_std.inc");
db_init();
if (post_str("account_key", true) != null) { if (post_str("account_key", true) != null) {
$user = lookup_user_auth(post_str("account_key")); $user = lookup_user_auth(post_str("account_key"));
// Cast old style user to object-oriented user
$user = newUser($user->id);
$rpc = true; $rpc = true;
} else { } else {
$user = re_get_logged_in_user(); $user = get_logged_in_user();
$rpc = false; $rpc = false;
} }
BoincForumPrefs::lookup($user);
// If the user has requested a total reset of preferences: // If the user has requested a total reset of preferences:
$dbhandler = $mainFactory->getDatabaseHandler(); //
if (post_str("action", true)=="reset"){ if (post_str("action", true)=="reset"){
$post_count = $user->getPostcount(); $posts = $user->prefs->posts;
$banished_until = $user->getBanishedUntil(); $banished_until = $user->prefs->banished_until;
$special_user = $user->getSpecialUser(); $special_user = $user->prefs->special_user;
$dbhandler->deleteUserPrefs($user); $user->prefs->delete();
$user->resetPrefs(); BoincForumPrefs::lookup($user);
$user->setPostcount($post_count); // Recreate postcount $user->prefs->update("posts=$posts, banished_until=$banished_until, special_user=$special_user");
$user->setSpecialUser($special_user); // And recreate special user bitfield
$user->setBanishedUntil($banished_until);
Header("Location: edit_forum_preferences_form.php"); Header("Location: edit_forum_preferences_form.php");
exit; exit;
} }
$avatar_type = post_int("avatar_select"); $avatar_type = post_int("avatar_select");
$newfile=IMAGE_PATH.$user->getID()."_avatar.jpg"; $newfile=IMAGE_PATH.$user->id."_avatar.jpg";
// Update the user avatar // Update the user avatar
if ($avatar_type<0 or $avatar_type>3) $avatar_type=0; if ($avatar_type<0 or $avatar_type>3) $avatar_type=0;
if ($avatar_type==0){ if ($avatar_type==0){
if (file_exists($newfile)){ if (file_exists($newfile)){
unlink($newfile); //Delete the file on the server if the user // Delete the file on the server if the user
//decides not to use an avatar // decides not to use an avatar
// - or should it be kept? //
unlink($newfile);
} }
$avatar_url=""; $avatar_url="";
} elseif ($avatar_type==2){ } elseif ($avatar_type==2){
@ -75,75 +68,68 @@ if ($avatar_type==0){
} }
// Update some simple prefs that are either on or off // Update some simple prefs that are either on or off
$images_as_links = ($_POST["forum_images_as_links"]!=""); $images_as_links = ($_POST["forum_images_as_links"]!="")?1:0;
$link_externally = ($_POST["forum_link_externally"]!=""); $link_popup = ($_POST["forum_link_popup"]!="")?1:0;
$hide_avatars = ($_POST["forum_hide_avatars"]!=""); $hide_avatars = ($_POST["forum_hide_avatars"]!="")?1:0;
$hide_signatures = ($_POST["forum_hide_signatures"]!=""); $hide_signatures = ($_POST["forum_hide_signatures"]!="")?1:0;
$jump_to_unread = ($_POST["forum_jump_to_unread"]!=""); $jump_to_unread = ($_POST["forum_jump_to_unread"]!="")?1:0;
$ignore_sticky_posts = ($_POST["forum_ignore_sticky_posts"]!=""); $ignore_sticky_posts = ($_POST["forum_ignore_sticky_posts"]!="")?1:0;
$signature_by_default = ($_POST["signature_enable"]!=""); $no_signature_by_default = ($_POST["signature_by_default"]!="")?0:1;
$pm_notification = ($_POST["pm_notification"]!=""); $pm_notification = ($_POST["pm_notification"]!="")?1:0;
$user->setImagesAsLinks($images_as_links);
$user->setLinkPopup($link_externally);
$user->setHideAvatars($hide_avatars);
$user->setHideSignatures($hide_signatures);
$user->setJumpToUnread($jump_to_unread);
$user->setIgnoreStickyPosts($ignore_sticky_posts);
$user->setSignatureByDefault($signature_by_default);
$user->setEnabledPMNotification($pm_notification);
// Update avatar
$user->setAvatar($avatar_url);
// Update the rating thresholds for display of posts
$low_rating_threshold = post_int("forum_low_rating_threshold"); $low_rating_threshold = post_int("forum_low_rating_threshold");
$high_rating_threshold = post_int("forum_high_rating_threshold"); $high_rating_threshold = post_int("forum_high_rating_threshold");
$user->setLowRatingThreshold($low_rating_threshold);
$user->setHighRatingThreshold($high_rating_threshold);
// Update the signature for this user
$signature = stripslashes($_POST["signature"]); $signature = stripslashes($_POST["signature"]);
if (strlen($signature)>250) { if (strlen($signature)>250) {
error_page("Your signature was too long, please keep it less than 250 chars"); error_page(
"Your signature was too long, please keep it less than 250 chars"
);
} }
$user->setSignature($signature);
// Sorting styles for different forum areas
$forum_sort = post_int("forum_sort"); $forum_sort = post_int("forum_sort");
$thread_sort = post_int("thread_sort"); $thread_sort = post_int("thread_sort");
$user->setForumSortStyle($forum_sort); $minimum_wrap_postcount = post_int("forum_minimum_wrap_postcount");
$user->setThreadSortStyle($thread_sort); $display_wrap_postcount = post_int("forum_display_wrap_postcount");
if ($minimum_wrap_postcount<0) $minimum_wrap_postcount=0;
if ($display_wrap_postcount>$minimum_wrap_postcount) {
$display_wrap_postcount=round($minimum_wrap_postcount/2);
}
if ($display_wrap_postcount<5) $display_wrap_postcount=5;
$signature = BoincDb::escape_string($signature);
$user->prefs->update("images_as_links=$images_as_links, link_popup=$link_popup, hide_avatars=$hide_avatars, hide_signatures=$hide_signatures, jump_to_unread=$jump_to_unread, ignore_sticky_posts=$ignore_sticky_posts, no_signature_by_default=$no_signature_by_default, pm_notification=$pm_notification, avatar='$avatar_url', low_rating_threshold=$low_rating_threshold, high_rating_threshold=$high_rating_threshold, signature='$signature', forum_sorting=$forum_sort, thread_sorting=$thread_sort, minimum_wrap_postcount=$minimum_wrap_postcount, display_wrap_postcount=$display_wrap_postcount");
// Add users to the ignore list if any users are defined
$add_user_to_filter = ($_POST["add_user_to_filter"]!=""); $add_user_to_filter = ($_POST["add_user_to_filter"]!="");
if ($add_user_to_filter){ if ($add_user_to_filter){
$user_to_add = trim($_POST["forum_filter_user"]); $user_to_add = trim($_POST["forum_filter_user"]);
if ($user_to_add!="" and $user_to_add==strval(intval($user_to_add))){ if ($user_to_add!="" and $user_to_add==strval(intval($user_to_add))){
$user->addIgnoredUser(newUser($user_to_add)); $other_user = BoincUser::lookup_id($user_to_add);
if (!$other_user) {
echo "No such user: $other_user";
} else {
add_ignored_user($user, $other_user);
}
} }
} }
// Or remove some from the ignore list // Or remove some from the ignore list
$ignored_users = $user->getIgnorelist(); //
$ignored_users = get_ignored_list($user);
for ($i=0;$i<sizeof($ignored_users);$i++){ for ($i=0;$i<sizeof($ignored_users);$i++){
if ($_POST["remove".trim($ignored_users[$i])]!=""){ if ($_POST["remove".trim($ignored_users[$i])]!=""){
//this user will be removed and no longer ignored $other_user = BoincUser::lookup_id($user_to_add);
$user->removeIgnoredUser(newUser($ignored_users[$i])); if (!$other_user) {
echo "No such user: $other_user";
} else {
remove_ignored_user($user, $other_user);
}
} }
} }
// Update preferences for the "Display only the Y last posts if there are more than X posts in the thread" feature
$minimum_wrap_postcount = post_int("forum_minimum_wrap_postcount");
$display_wrap_postcount = post_int("forum_display_wrap_postcount");
if ($minimum_wrap_postcount<0) $minimum_wrap_postcount=0;
if ($display_wrap_postcount>$minimum_wrap_postcount) $display_wrap_postcount=round($minimum_wrap_postcount/2);
if ($display_wrap_postcount<5) $display_wrap_postcount=5;
$user->setMinimumWrapPostcount($minimum_wrap_postcount);
$user->setDisplayWrapPostcount($display_wrap_postcount);
if ($rpc == false) { if ($rpc == false) {
// If we get down here everything went ok so let's redirect the user to the setup page again // If we get down here everything went ok
// so that they can view their new preferences in action in the previews. // so redirect the user to the setup page again
Header("Location: edit_forum_preferences_form.php"); Header("Location: edit_forum_preferences_form.php");
} else { } else {
echo "<status>\n"; echo "<status>\n";

View File

@ -1,17 +1,13 @@
<?php <?php
/**
* This provides the form from which the user can edit his or her
* forum preferences. It relies upon edit_forum_preferences_action.php
* to do anything.
**/
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit // This provides the form from which the user can edit his or her
// forum preferences. It relies upon edit_forum_preferences_action.php
// to do anything.
require_once("../inc/forum.inc"); require_once("../inc/forum.inc");
require_once("../inc/forum_std.inc");
db_init();
$user = re_get_logged_in_user();
$user = get_logged_in_user();
BoincForumPrefs::lookup($user);
page_head("Edit message board preferences"); page_head("Edit message board preferences");
echo "<script type=\"text/javascript\"> echo "<script type=\"text/javascript\">
@ -34,7 +30,7 @@ row1("Reset preferences");
row2("<font size=-2>Use this button to reset preferences to the defaults</font>", row2("<font size=-2>Use this button to reset preferences to the defaults</font>",
"<form method=\"post\" action=\"edit_forum_preferences_action.php\"><input type=\"submit\" value=\"Reset preferences\"><input type=\"hidden\" name=\"action\" value=\"reset\"></form>"); "<form method=\"post\" action=\"edit_forum_preferences_action.php\"><input type=\"submit\" value=\"Reset preferences\"><input type=\"hidden\" name=\"action\" value=\"reset\"></form>");
echo "<form method=\"post\" action=\"edit_forum_preferences_action.php\" enctype=\"multipart/form-data\">"; echo "<form method=\"post\" action=\"edit_forum_preferences_action.php\" enctype=\"multipart/form-data\">";
if ($user->hasAvatar()){ if (strlen($user->prefs->avatar)){
$two_select="checked=\"true\""; $two_select="checked=\"true\"";
} else { } else {
$zero_select="checked=\"true\""; $zero_select="checked=\"true\"";
@ -48,34 +44,50 @@ row2("<font size=-2>The virtual representation of you on the message boards<br/>
</table> </table>
" "
); );
if ($user->hasAvatar()){ if (strlen($user->prefs->avatar)){
row2("Avatar preview<br><font size=-2>This is how your avatar will look</font>", row2("Avatar preview<br><font size=-2>This is how your avatar will look</font>",
"<img src=\"".$user->getAvatar()."\" width=\"100\" height=\"100\">"); "<img src=\"".$user->prefs->avatar."\" width=\"100\" height=\"100\">");
} }
row1("Sort styles"); row1("Sort styles");
row2("<font size=-2>How to sort the replies in the message board and Q&amp;A areas</font>", row2("<font size=-2>How to sort the replies in the message board and Q&amp;A areas</font>",
" "
<table> <table>
<tr><td>Message threadlist:</td><td>".select_from_array("forum_sort", $forum_sort_styles, $user->getForumSortStyle())."</td></tr> <tr><td>Message threadlist:</td><td>".select_from_array("forum_sort", $forum_sort_styles, $user->prefs->forum_sorting)."</td></tr>
<tr><td>Message posts:</td><td>".select_from_array("thread_sort", $thread_sort_styles, $user->getThreadSortStyle())."</td></tr> <tr><td>Message posts:</td><td>".select_from_array("thread_sort", $thread_sort_styles, $user->prefs->thread_sorting)."</td></tr>
</table>" </table>"
); );
if ($user->hasLinkPopup()){$forum_link_externally="checked=\"checked\"";} else {$forum_link_externally="";} if ($user->prefs->link_popup){
if ($user->hasImagesAsLinks()){$forum_image_as_link="checked=\"checked\"";} else {$forum_image_as_link="";} $forum_link_popup="checked=\"checked\"";
if ($user->hasJumpToUnread()){$forum_jump_to_unread="checked=\"checked\"";} else {$forum_jump_to_unread="";} } else {
if ($user->hasIgnoreStickyPosts()){$forum_ignore_sticky_posts="checked=\"checked\"";} else {$forum_ignore_sticky_posts="";} $forum_link_popup="";
}
if ($user->prefs->images_as_links){
$forum_image_as_link="checked=\"checked\"";
} else {
$forum_image_as_link="";
}
if ($user->prefs->jump_to_unread){
$forum_jump_to_unread="checked=\"checked\"";
} else {
$forum_jump_to_unread="";
}
if ($user->prefs->ignore_sticky_posts){
$forum_ignore_sticky_posts="checked=\"checked\"";
} else {
$forum_ignore_sticky_posts="";
}
$forum_minimum_wrap_postcount = intval($user->getMinimumWrapPostcount()); $forum_minimum_wrap_postcount = intval($user->minimum_wrap_postcount);
$forum_display_wrap_postcount = intval($user->getDisplayWrapPostcount()); $forum_display_wrap_postcount = intval($user->display_wrap_postcount);
row1("Display and Behavior"); row1("Display and Behavior");
row2( row2(
"<br><font size=-2>How to treat links and images in the forum<br>and how to act on unread posts</font>", "<br><font size=-2>How to treat links and images in the forum<br>and how to act on unread posts</font>",
"<table><tr><td> "<table><tr><td>
<input type=\"checkbox\" name=\"forum_images_as_links\" ".$forum_image_as_link."> Show images as links<br> <input type=\"checkbox\" name=\"forum_images_as_links\" ".$forum_image_as_link."> Show images as links<br>
<input type=\"checkbox\" name=\"forum_link_externally\" ".$forum_link_externally."> Open links in new window/tab<br> <input type=\"checkbox\" name=\"forum_link_popup\" ".$forum_link_popup."> Open links in new window/tab<br>
<input type=\"checkbox\" name=\"forum_jump_to_unread\" ".$forum_jump_to_unread."> Jump to first new post in thread automatically<br> <input type=\"checkbox\" name=\"forum_jump_to_unread\" ".$forum_jump_to_unread."> Jump to first new post in thread automatically<br>
<input type=\"checkbox\" name=\"forum_ignore_sticky_posts\" ".$forum_ignore_sticky_posts.">Do not reorder sticky posts<br> <input type=\"checkbox\" name=\"forum_ignore_sticky_posts\" ".$forum_ignore_sticky_posts.">Do not reorder sticky posts<br>
<br /> <br />
@ -84,16 +96,28 @@ row2(
</td></tr></table>" </td></tr></table>"
); );
if ($user->hasEnabledPMNotification()){$pm_notification="checked=\"checked\"";} else {$pm_notification="";} if ($user->prefs->pm_notification){
$pm_notification="checked=\"checked\"";
} else {
$pm_notification="";
}
row2("Private message email notification", row2("Private message email notification",
"<table><tr><td><input type=\"checkbox\" id=\"pm_notification\" name=\"pm_notification\" ".$pm_notification."> "<table><tr><td><input type=\"checkbox\" id=\"pm_notification\" name=\"pm_notification\" ".$pm_notification.">
<label for=\"pm_notification\">Notify about new private messages by email</label> <label for=\"pm_notification\">Notify about new private messages by email</label>
</td></tr></table>"); </td></tr></table>");
if ($user->hasHideAvatars()){$forum_hide_avatars="checked=\"checked\"";} else {$forum_hide_avatars="";} if ($user->prefs->hide_avatars){
if ($user->hasHideSignatures()){$forum_hide_signatures="checked=\"checked\"";} else {$forum_hide_signatures="";} $forum_hide_avatars = "checked=\"checked\"";
$forum_low_rating_threshold= $user->getLowRatingThreshold(); } else {
$forum_high_rating_threshold= $user->getHighRatingThreshold(); $forum_hide_avatars = "";
}
if ($user->prefs->hide_signatures){
$forum_hide_signatures = "checked=\"checked\"";
} else {
$forum_hide_signatures = "";
}
$forum_low_rating_threshold = $user->prefs->low_rating_threshold;
$forum_high_rating_threshold = $user->prefs->high_rating_threshold;
row1("Filtering"); row1("Filtering");
row2( row2(
@ -112,11 +136,15 @@ row2(
" "
); );
$filtered_userlist=$user->getIgnorelist(); $filtered_userlist = get_ignored_list($user);
for ($i=0;$i<sizeof($filtered_userlist);$i++){ for ($i=0; $i<sizeof($filtered_userlist); $i++){
if ($filtered_userlist[$i]!=""){ if ($filtered_userlist[$i] != ""){
$filtered_user = newUser($filtered_userlist[$i]); $filtered_user = BoincUser::lookup_id($filtered_userlist[$i]);
$forum_filtered_userlist.="<input type =\"submit\" name=\"remove".$filtered_user->getID()."\" value=\"Remove\"> ".$filtered_user->getID()." - ".re_user_links($filtered_user,URL_BASE)."<br>"; if ($filtered_user) {
echo "missing user $filtered_userlist[$i]";
continue;
}
$forum_filtered_userlist .= "<input type =\"submit\" name=\"remove".$filtered_user->id."\" value=\"Remove\"> ".$filtered_user->id." - ".user_links($filtered_user)."<br>";
} }
} }
row2("Filtered users". row2("Filtered users".
@ -134,8 +162,12 @@ row2("Filtered users".
" "
); );
if ($user->hasSignatureByDefault()){$enable_signature="checked=\"checked\"";} else {$enable_signature="";} if (!$user->prefs->no_signature_by_default){
$signature=stripslashes($user->getSignature()); $signature_by_default="checked=\"checked\"";
} else {
$signature_by_default="";
}
$signature=stripslashes($user->prefs->signature);
$maxlen=250; $maxlen=250;
row1("Signature"); row1("Signature");
row2(html_info(). row2(html_info().
@ -144,12 +176,12 @@ row2(html_info().
<textarea name=\"signature\" rows=4 cols=50 id=\"signature\" onkeydown=\"textCounter(this.form.signature, this.form.remLen,$maxlen);\" <textarea name=\"signature\" rows=4 cols=50 id=\"signature\" onkeydown=\"textCounter(this.form.signature, this.form.remLen,$maxlen);\"
onkeyup=\"textCounter(this.form.signature, this.form.remLen,250);\">".$signature."</textarea> onkeyup=\"textCounter(this.form.signature, this.form.remLen,250);\">".$signature."</textarea>
<br><input name=\"remLen\" type=\"text\" id=\"remLen\" value=\"".($maxlen-strlen($signature))."\" size=\"3\" maxlength=\"3\" readonly> chars remaining <br><input name=\"remLen\" type=\"text\" id=\"remLen\" value=\"".($maxlen-strlen($signature))."\" size=\"3\" maxlength=\"3\" readonly> chars remaining
<br><input type=\"checkbox\" name=\"signature_enable\" ".$enable_signature."> Attach signature by default <br><input type=\"checkbox\" name=\"signature_by_default\" ".$signature_by_default."> Attach signature by default
</td></tr></table>"); </td></tr></table>");
if ($user->getSignature()!=""){ if ($user->prefs->signature!=""){
row2("Signature preview". row2("Signature preview".
"<br><font size=-2>This is how your signature will look in the forums</font>", "<br><font size=-2>This is how your signature will look in the forums</font>",
output_transform($user->getSignature()) output_transform($user->prefs->signature)
); );
} }
row1("&nbsp;"); row1("&nbsp;");
@ -157,4 +189,6 @@ row2("", "<input type=submit value='Update info'>");
echo "</form>\n"; echo "</form>\n";
end_table(); end_table();
page_tail(); page_tail();
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
?> ?>