- 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>
curl/mswin/
<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) {
$list = explode("|", $user->prefs->ignorelist);
foreach ($list as $key=>$userid) {

View File

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

View File

@ -1,51 +1,44 @@
<?php
/**
* This page commits the chanegs made in edit_forum_preferences_form.php to
* the database.
**/
// commit the chanegs made in edit_forum_preferences_form.php to the database.
require_once("../inc/forum.inc");
require_once("../inc/image.inc"); // Avatar scaling
require_once("../inc/forum_std.inc");
db_init();
if (post_str("account_key", true) != null) {
$user = lookup_user_auth(post_str("account_key"));
// Cast old style user to object-oriented user
$user = newUser($user->id);
$rpc = true;
} else {
$user = re_get_logged_in_user();
$user = get_logged_in_user();
$rpc = false;
}
BoincForumPrefs::lookup($user);
// If the user has requested a total reset of preferences:
$dbhandler = $mainFactory->getDatabaseHandler();
//
if (post_str("action", true)=="reset"){
$post_count = $user->getPostcount();
$banished_until = $user->getBanishedUntil();
$special_user = $user->getSpecialUser();
$dbhandler->deleteUserPrefs($user);
$user->resetPrefs();
$user->setPostcount($post_count); // Recreate postcount
$user->setSpecialUser($special_user); // And recreate special user bitfield
$user->setBanishedUntil($banished_until);
$posts = $user->prefs->posts;
$banished_until = $user->prefs->banished_until;
$special_user = $user->prefs->special_user;
$user->prefs->delete();
BoincForumPrefs::lookup($user);
$user->prefs->update("posts=$posts, banished_until=$banished_until, special_user=$special_user");
Header("Location: edit_forum_preferences_form.php");
exit;
}
$avatar_type = post_int("avatar_select");
$newfile=IMAGE_PATH.$user->getID()."_avatar.jpg";
$newfile=IMAGE_PATH.$user->id."_avatar.jpg";
// Update the user avatar
if ($avatar_type<0 or $avatar_type>3) $avatar_type=0;
if ($avatar_type==0){
if (file_exists($newfile)){
unlink($newfile); //Delete the file on the server if the user
//decides not to use an avatar
// - or should it be kept?
// Delete the file on the server if the user
// decides not to use an avatar
//
unlink($newfile);
}
$avatar_url="";
} elseif ($avatar_type==2){
@ -75,75 +68,68 @@ if ($avatar_type==0){
}
// Update some simple prefs that are either on or off
$images_as_links = ($_POST["forum_images_as_links"]!="");
$link_externally = ($_POST["forum_link_externally"]!="");
$hide_avatars = ($_POST["forum_hide_avatars"]!="");
$hide_signatures = ($_POST["forum_hide_signatures"]!="");
$jump_to_unread = ($_POST["forum_jump_to_unread"]!="");
$ignore_sticky_posts = ($_POST["forum_ignore_sticky_posts"]!="");
$signature_by_default = ($_POST["signature_enable"]!="");
$pm_notification = ($_POST["pm_notification"]!="");
$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
$images_as_links = ($_POST["forum_images_as_links"]!="")?1:0;
$link_popup = ($_POST["forum_link_popup"]!="")?1:0;
$hide_avatars = ($_POST["forum_hide_avatars"]!="")?1:0;
$hide_signatures = ($_POST["forum_hide_signatures"]!="")?1:0;
$jump_to_unread = ($_POST["forum_jump_to_unread"]!="")?1:0;
$ignore_sticky_posts = ($_POST["forum_ignore_sticky_posts"]!="")?1:0;
$no_signature_by_default = ($_POST["signature_by_default"]!="")?0:1;
$pm_notification = ($_POST["pm_notification"]!="")?1:0;
$low_rating_threshold = post_int("forum_low_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"]);
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");
$thread_sort = post_int("thread_sort");
$user->setForumSortStyle($forum_sort);
$user->setThreadSortStyle($thread_sort);
$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;
$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"]!="");
if ($add_user_to_filter){
$user_to_add = trim($_POST["forum_filter_user"]);
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
$ignored_users = $user->getIgnorelist();
//
$ignored_users = get_ignored_list($user);
for ($i=0;$i<sizeof($ignored_users);$i++){
if ($_POST["remove".trim($ignored_users[$i])]!=""){
//this user will be removed and no longer ignored
$user->removeIgnoredUser(newUser($ignored_users[$i]));
$other_user = BoincUser::lookup_id($user_to_add);
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 we get down here everything went ok so let's redirect the user to the setup page again
// so that they can view their new preferences in action in the previews.
// If we get down here everything went ok
// so redirect the user to the setup page again
Header("Location: edit_forum_preferences_form.php");
} else {
echo "<status>\n";

View File

@ -1,17 +1,13 @@
<?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_std.inc");
db_init();
$user = re_get_logged_in_user();
$user = get_logged_in_user();
BoincForumPrefs::lookup($user);
page_head("Edit message board preferences");
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>",
"<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\">";
if ($user->hasAvatar()){
if (strlen($user->prefs->avatar)){
$two_select="checked=\"true\"";
} else {
$zero_select="checked=\"true\"";
@ -48,34 +44,50 @@ row2("<font size=-2>The virtual representation of you on the message boards<br/>
</table>
"
);
if ($user->hasAvatar()){
if (strlen($user->prefs->avatar)){
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");
row2("<font size=-2>How to sort the replies in the message board and Q&amp;A areas</font>",
"
<table>
<tr><td>Message threadlist:</td><td>".select_from_array("forum_sort", $forum_sort_styles, $user->getForumSortStyle())."</td></tr>
<tr><td>Message posts:</td><td>".select_from_array("thread_sort", $thread_sort_styles, $user->getThreadSortStyle())."</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->prefs->thread_sorting)."</td></tr>
</table>"
);
if ($user->hasLinkPopup()){$forum_link_externally="checked=\"checked\"";} else {$forum_link_externally="";}
if ($user->hasImagesAsLinks()){$forum_image_as_link="checked=\"checked\"";} else {$forum_image_as_link="";}
if ($user->hasJumpToUnread()){$forum_jump_to_unread="checked=\"checked\"";} else {$forum_jump_to_unread="";}
if ($user->hasIgnoreStickyPosts()){$forum_ignore_sticky_posts="checked=\"checked\"";} else {$forum_ignore_sticky_posts="";}
if ($user->prefs->link_popup){
$forum_link_popup="checked=\"checked\"";
} else {
$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_display_wrap_postcount = intval($user->getDisplayWrapPostcount());
$forum_minimum_wrap_postcount = intval($user->minimum_wrap_postcount);
$forum_display_wrap_postcount = intval($user->display_wrap_postcount);
row1("Display and Behavior");
row2(
"<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>
<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_ignore_sticky_posts\" ".$forum_ignore_sticky_posts.">Do not reorder sticky posts<br>
<br />
@ -84,16 +96,28 @@ row2(
</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",
"<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>
</td></tr></table>");
if ($user->hasHideAvatars()){$forum_hide_avatars="checked=\"checked\"";} else {$forum_hide_avatars="";}
if ($user->hasHideSignatures()){$forum_hide_signatures="checked=\"checked\"";} else {$forum_hide_signatures="";}
$forum_low_rating_threshold= $user->getLowRatingThreshold();
$forum_high_rating_threshold= $user->getHighRatingThreshold();
if ($user->prefs->hide_avatars){
$forum_hide_avatars = "checked=\"checked\"";
} else {
$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");
row2(
@ -112,11 +136,15 @@ row2(
"
);
$filtered_userlist=$user->getIgnorelist();
for ($i=0;$i<sizeof($filtered_userlist);$i++){
if ($filtered_userlist[$i]!=""){
$filtered_user = newUser($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>";
$filtered_userlist = get_ignored_list($user);
for ($i=0; $i<sizeof($filtered_userlist); $i++){
if ($filtered_userlist[$i] != ""){
$filtered_user = BoincUser::lookup_id($filtered_userlist[$i]);
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".
@ -134,8 +162,12 @@ row2("Filtered users".
"
);
if ($user->hasSignatureByDefault()){$enable_signature="checked=\"checked\"";} else {$enable_signature="";}
$signature=stripslashes($user->getSignature());
if (!$user->prefs->no_signature_by_default){
$signature_by_default="checked=\"checked\"";
} else {
$signature_by_default="";
}
$signature=stripslashes($user->prefs->signature);
$maxlen=250;
row1("Signature");
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);\"
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 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>");
if ($user->getSignature()!=""){
if ($user->prefs->signature!=""){
row2("Signature preview".
"<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;");
@ -157,4 +189,6 @@ row2("", "<input type=submit value='Update info'>");
echo "</form>\n";
end_table();
page_tail();
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
?>