.
// This file allows people to rate posts in a thread
require_once('../inc/forum.inc');
require_once('../inc/util.inc');
$config = get_config();
if (parse_bool($config, "no_forum_rating")) {
page_head("Rating offline");
echo "This function is turned off by the project";
page_tail();
exit(0);
}
if (!empty($_GET['post'])) {
$postId = get_int('post');
$choice = post_str('submit', true);
$rating = post_int('rating', true);
if (!$choice) $choice = get_str('choice', true);
if ($choice == SOLUTION or $choice=="p") {
$rating = 1;
} else {
$rating = -1;
}
$user = get_logged_in_user();
if ($choice == null && ($rating == null || $rating > 2 || $rating < -2)) {
show_result_page(false, NULL, NULL, $choice);
}
$post = BoincPost::lookup_id($postId);
$thread = BoincThread::lookup_id($post->thread);
$forum = BoincForum::lookup_id($thread->forum);
// Make sure the user has the forum's minimum amount of RAC and total credit
// before allowing them to rate a post.
//
if ($user->total_credit<$forum->rate_min_total_credit || $user->expavg_credit<$forum->rate_min_expavg_credit) {
error_page("You need more average or total credit to rate a post.");
}
if (BoincPostRating::lookup($user->id, $post->id)) {
error_page("You have already rated this post once.
id."#".$post->id."\">Return to thread");
} else {
$success = BoincPostRating::replace($user->id, $post->id, $rating);
show_result_page($success, $post, $thread, $choice);
}
}
function show_result_page($success, $post, $thread, $choice) {
if ($success) {
if ($choice) {
page_head('Input Recorded');
echo "
Your input has been successfully recorded. Thank you for your help.
"; } else { page_head('Vote Registered'); echo "Vote Registered"; echo "Your rating has been successfully recorded. Thank you for your input.
"; } echo "id, "#", $post->id, "\">Return to thread"; } else { page_head('Vote Submission Problem'); echo "Vote submission failed"; if ($post) { echo "There was a problem recording your vote in our database. Please try again later.
"; echo "id, "#", $post->id, "\">Return to thread"; } else { echo "There post you specified does not exist, or your rating was invalid.
"; } } page_tail(); exit; } $cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit ?>