2003-07-29 01:15:41 +00:00
|
|
|
<?php
|
2003-08-13 22:09:50 +00:00
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
require_once('../inc/forum.inc');
|
|
|
|
require_once('../inc/util.inc');
|
2005-04-20 21:11:20 +00:00
|
|
|
require_once('../inc/credit.inc');
|
|
|
|
|
2003-07-29 01:15:41 +00:00
|
|
|
|
2004-12-27 03:42:11 +00:00
|
|
|
db_init();
|
|
|
|
|
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;
|
2004-10-25 22:04:15 +00:00
|
|
|
} else if ($choice == OFF_TOPIC or $choice=="n") {
|
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
|
|
|
|
2003-07-30 00:52:46 +00:00
|
|
|
// TODO: Define constants for these.
|
2003-08-01 20:30:49 +00:00
|
|
|
if ($choice == null && ($rating == null || $rating > 2 || $rating < -2)) {
|
|
|
|
show_result_page(false, NULL, $choice);
|
2003-07-30 00:52:46 +00:00
|
|
|
exit();
|
|
|
|
}
|
2003-08-22 23:44:48 +00:00
|
|
|
|
2005-04-28 09:33:07 +00:00
|
|
|
$post = getPost($postId);
|
|
|
|
$thread = getThread($post->thread);
|
|
|
|
$forum = getForum($thread->forum);
|
|
|
|
|
2004-10-26 22:27:50 +00:00
|
|
|
$user = get_logged_in_user(true);
|
2004-10-25 22:04:15 +00:00
|
|
|
$user = getForumPreferences($user);
|
2005-04-20 21:11:20 +00:00
|
|
|
|
2005-04-28 09:33:07 +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) {
|
|
|
|
error_page("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
|
|
|
|
2005-02-13 06:13:33 +00:00
|
|
|
if (getHasRated($user,$postId)) {
|
2005-04-20 21:11:20 +00:00
|
|
|
error_page("You have already rated this post once.");
|
2004-10-25 22:04:15 +00:00
|
|
|
} else {
|
|
|
|
$result = mysql_query("SELECT * FROM post WHERE id = $postId");
|
2005-02-13 06:13:33 +00:00
|
|
|
if ($result) {
|
|
|
|
if (mysql_num_rows($result) > 0) {
|
|
|
|
$post = mysql_fetch_object($result);
|
2003-08-22 23:44:48 +00:00
|
|
|
|
2005-02-13 06:13:33 +00:00
|
|
|
if ($choice == NULL || $choice == SOLUTION || $choice == OFF_TOPIC || $choice=="p" || $choice=="n") {
|
|
|
|
$points = $post->votes * $post->score;
|
|
|
|
$votes = $post->votes + 1;
|
|
|
|
$score = ($points + $rating) / $votes;
|
2003-08-22 23:44:48 +00:00
|
|
|
|
2005-02-13 06:13:33 +00:00
|
|
|
$result2 = mysql_query("UPDATE post SET votes = $votes, score = $score WHERE id = $postId");
|
|
|
|
} else if ($choice == SUFFERER) {
|
|
|
|
$sql = "UPDATE thread SET sufferers = sufferers + 1 WHERE id = " . $post->thread;
|
|
|
|
$result2 = mysql_query($sql);
|
|
|
|
}
|
2003-08-22 23:44:48 +00:00
|
|
|
|
2005-02-13 06:13:33 +00:00
|
|
|
if ($result2) {
|
|
|
|
show_result_page(true, $post, $choice);
|
|
|
|
setHasRated($user,$postId);
|
|
|
|
} else {
|
|
|
|
show_result_page(false, $post, $choice);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
show_result_page(false, NULL, $choice);
|
|
|
|
}
|
|
|
|
} else {
|
2003-08-01 20:30:49 +00:00
|
|
|
show_result_page(false, NULL, $choice);
|
2005-02-13 06:13:33 +00:00
|
|
|
}
|
2004-10-25 22:04:15 +00:00
|
|
|
}
|
2003-07-29 01:15:41 +00:00
|
|
|
}
|
|
|
|
|
2003-08-01 20:30:49 +00:00
|
|
|
function show_result_page($success, $post, $choice) {
|
2004-02-03 21:48:49 +00:00
|
|
|
$logged_in_user = get_logged_in_user(false);
|
2003-08-22 23:44:48 +00:00
|
|
|
|
2005-02-13 06:13:33 +00:00
|
|
|
if ($success) {
|
|
|
|
if ($choice) {
|
|
|
|
page_head('Input Recorded');
|
|
|
|
echo "<p>Your input has been successfully recorded. Thank you for your help.</p>";
|
|
|
|
} else {
|
|
|
|
page_head('Vote Registered');
|
2003-08-15 01:01:00 +00:00
|
|
|
echo "<span class=\"title\">Vote Registered</span>";
|
|
|
|
echo "<p>Your rating has been successfully recorded. Thank you for your input.</p>";
|
2005-02-13 06:13:33 +00:00
|
|
|
}
|
|
|
|
echo "<a href=\"forum_thread.php?id=", $post->thread, "#", $post->id, "\">Return to thread</a>";
|
2003-07-29 01:15:41 +00:00
|
|
|
} else {
|
2005-02-13 06:13:33 +00:00
|
|
|
page_head('Vote Submission Problem');
|
2003-07-29 01:15:41 +00:00
|
|
|
echo "<span class=\"title\">Vote submission failed</span>";
|
|
|
|
if ($post) {
|
|
|
|
echo "<p>There was a problem recording your vote in our database. Please try again later.</p>";
|
2004-05-30 21:47:11 +00:00
|
|
|
echo "<a href=\"forum_thread.php?id=", $post->thread, "#", $post->id, "\">Return to thread</a>";
|
2003-07-29 01:15:41 +00:00
|
|
|
} else {
|
2003-07-30 00:52:46 +00:00
|
|
|
echo "<p>There post you specified does not exist, or your rating was invalid.</p>";
|
2003-07-29 01:15:41 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-15 01:01:00 +00:00
|
|
|
page_tail();
|
2003-07-29 01:15:41 +00:00
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
?>
|