2003-07-29 01:15:41 +00:00
|
|
|
<?php
|
2003-08-13 22:09:50 +00:00
|
|
|
|
|
|
|
require_once('../include/template.inc');
|
|
|
|
require_once('forum.inc');
|
|
|
|
require_once('../util.inc');
|
2003-07-29 01:15:41 +00:00
|
|
|
|
2003-07-30 00:52:46 +00:00
|
|
|
if (!empty($_GET['post'])) {
|
2003-07-29 01:15:41 +00:00
|
|
|
$postId = $_GET['post'];
|
2003-08-01 20:30:49 +00:00
|
|
|
$choice = $_POST['submit'];
|
2003-07-29 01:15:41 +00:00
|
|
|
$rating = $_POST['rating'];
|
2003-08-01 20:30:49 +00:00
|
|
|
|
|
|
|
if ($choice == SOLUTION) {
|
2003-08-13 22:09:50 +00:00
|
|
|
$rating = 1;
|
2003-08-01 20:30:49 +00:00
|
|
|
} else if ($choice == OFF_TOPIC) {
|
2003-08-13 22:09:50 +00:00
|
|
|
$rating = -1;
|
2003-08-01 20:30:49 +00:00
|
|
|
}
|
2003-07-29 01:15:41 +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-01 20:30:49 +00:00
|
|
|
$user = get_logged_in_user($true, '../');
|
|
|
|
|
2003-07-29 01:15:41 +00:00
|
|
|
$result = mysql_query("SELECT * FROM post WHERE id = $postId");
|
2003-08-01 20:30:49 +00:00
|
|
|
if ($result) {
|
2003-07-29 01:15:41 +00:00
|
|
|
if (mysql_num_rows($result) > 0) {
|
2003-08-01 20:30:49 +00:00
|
|
|
$post = mysql_fetch_object($result);
|
|
|
|
|
|
|
|
if ($choice == NULL || $choice == SOLUTION || $choice == OFF_TOPIC) {
|
|
|
|
$points = $post->votes * $post->score;
|
|
|
|
$votes = $post->votes + 1;
|
|
|
|
$score = ($points + $rating) / $votes;
|
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($result2) {
|
|
|
|
show_result_page(true, $post, $choice);
|
|
|
|
} else {
|
|
|
|
show_result_page(false, $post, $choice);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
show_result_page(false, NULL, $choice);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
show_result_page(false, NULL, $choice);
|
|
|
|
}
|
2003-07-29 01:15:41 +00:00
|
|
|
}
|
|
|
|
|
2003-08-01 20:30:49 +00:00
|
|
|
function show_result_page($success, $post, $choice) {
|
2003-07-29 01:15:41 +00:00
|
|
|
if ($success) {
|
2003-08-01 20:30:49 +00:00
|
|
|
if ($choice) {
|
|
|
|
doHeader('Input Recorded');
|
|
|
|
echo "<span class=\"title\">Helpdesk Input Recorded</span>";
|
|
|
|
echo "<p>Your input has been successfully recorded. Thank you for your help.</p>";
|
|
|
|
} else {
|
|
|
|
doHeader('Vote Registered');
|
|
|
|
echo "<span class=\"title\">Vote Registered</span>";
|
|
|
|
echo "<p>Your rating has been successfully recorded. Thank you for your input.</p>";
|
|
|
|
}
|
|
|
|
echo "<a href=\"thread.php?id=", $post->thread, "#", $post->id, "\">Return to thread</a>";
|
2003-07-29 01:15:41 +00:00
|
|
|
} else {
|
|
|
|
doHeader("Vote Submission Problem");
|
|
|
|
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>";
|
2003-08-01 20:30:49 +00:00
|
|
|
echo "<a href=\"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
|
|
|
}
|
|
|
|
}
|
|
|
|
doFooter();
|
|
|
|
}
|
|
|
|
?>
|