2003-07-29 01:15:41 +00:00
< ? php
2008-08-05 22:43:14 +00:00
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
2007-04-29 13:02:35 +00:00
2007-11-12 20:57:15 +00:00
// This file allows people to rate posts in a thread
2004-02-02 23:34:39 +00:00
require_once ( '../inc/forum.inc' );
2006-07-10 17:00:31 +00:00
require_once ( '../inc/util.inc' );
2005-04-20 21:11:20 +00:00
2006-07-10 17:00:31 +00:00
$config = get_config ();
2007-04-29 13:02:35 +00:00
if ( parse_bool ( $config , " no_forum_rating " )) {
2011-08-25 22:12:48 +00:00
page_head ( tra ( " Rating offline " ));
echo tra ( " This function is turned off by the project " );
2007-04-29 13:02:35 +00:00
page_tail ();
exit ( 0 );
2006-12-29 20:57:29 +00:00
}
2006-07-10 17:18:42 +00:00
2003-07-30 00:52:46 +00:00
if ( ! empty ( $_GET [ 'post' ])) {
2005-04-20 22:46:47 +00:00
$postId = get_int ( 'post' );
$choice = post_str ( 'submit' , true );
$rating = post_int ( 'rating' , true );
if ( ! $choice ) $choice = get_str ( 'choice' , true );
2004-10-25 22:04:15 +00:00
if ( $choice == SOLUTION or $choice == " p " ) {
2003-08-13 22:09:50 +00:00
$rating = 1 ;
2006-06-16 23:53:56 +00:00
} else {
2003-08-22 23:44:48 +00:00
$rating = - 1 ;
2003-08-01 20:30:49 +00:00
}
2003-08-22 23:44:48 +00:00
2007-11-12 20:57:15 +00:00
$user = get_logged_in_user ();
2006-06-16 23:53:56 +00:00
2003-08-01 20:30:49 +00:00
if ( $choice == null && ( $rating == null || $rating > 2 || $rating < - 2 )) {
2007-11-12 20:57:15 +00:00
show_result_page ( false , NULL , NULL , $choice );
2003-07-30 00:52:46 +00:00
}
2003-08-22 23:44:48 +00:00
2007-11-12 20:57:15 +00:00
$post = BoincPost :: lookup_id ( $postId );
$thread = BoincThread :: lookup_id ( $post -> thread );
$forum = BoincForum :: lookup_id ( $thread -> forum );
2005-04-28 09:33:07 +00:00
2007-11-12 20:57:15 +00:00
// 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 ) {
2011-08-25 22:12:48 +00:00
error_page ( tra ( " You need more average or total credit to rate a post. " ));
2005-04-20 21:11:20 +00:00
}
2004-10-25 22:04:15 +00:00
2007-11-12 20:57:15 +00:00
if ( BoincPostRating :: lookup ( $user -> id , $post -> id )) {
2011-08-25 22:12:48 +00:00
error_page ( tra ( " You have already rated this post. " ) . " <br /><br /><a href= \" forum_thread.php?nowrap=true&id= " . $thread -> id . " # " . $post -> id . " \" > " . tra ( " Return to thread " ) . " </a> " );
2004-10-25 22:04:15 +00:00
} else {
2007-11-12 20:57:15 +00:00
$success = BoincPostRating :: replace ( $user -> id , $post -> id , $rating );
show_result_page ( $success , $post , $thread , $choice );
2004-10-25 22:04:15 +00:00
}
2003-07-29 01:15:41 +00:00
}
2007-11-12 20:57:15 +00:00
function show_result_page ( $success , $post , $thread , $choice ) {
2005-02-13 06:13:33 +00:00
if ( $success ) {
if ( $choice ) {
2011-08-25 22:12:48 +00:00
page_head ( tra ( " Input Recorded " ));
echo tra ( " Your input has been recorded. Thanks for your help. " );
2005-02-13 06:13:33 +00:00
} else {
2011-08-25 22:12:48 +00:00
page_head ( tra ( " Vote Registered " ));
echo tra ( " Your rating has been recorded. Thanks for your input. " );
2005-02-13 06:13:33 +00:00
}
2011-08-25 22:12:48 +00:00
echo " <a href= \" forum_thread.php?nowrap=true&id= " , $thread -> id , " # " , $post -> id , " \" > " . tra ( " Return to thread " ) . " </a> " ;
2003-07-29 01:15:41 +00:00
} else {
2011-08-25 22:12:48 +00:00
page_head ( tra ( " Vote Submission Problem " ));
2003-07-29 01:15:41 +00:00
if ( $post ) {
2011-08-25 22:12:48 +00:00
echo " There was a problem recording your vote in our database. Please try again later. " ;
echo " <a href= \" forum_thread.php?id= " , $thread -> id , " # " , $post -> id , " \" > " . tra ( " Return to thread " ) . " </a> " ;
2003-07-29 01:15:41 +00:00
} else {
2011-07-31 16:23:37 +00:00
echo " The post you specified does not exist, or your rating was invalid. " ;
2003-07-29 01:15:41 +00:00
}
}
2003-08-15 01:01:00 +00:00
page_tail ();
2006-06-16 23:53:56 +00:00
exit ;
2003-07-29 01:15:41 +00:00
}
2007-11-12 20:57:15 +00:00
$cvs_version_tracker [] = " \$ Id $ " ; //Generated automatically - do not edit
2004-02-02 23:34:39 +00:00
?>