From 801db51a1c29b2bd324404a31125b8be465f5bfd Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 13 Oct 2000 10:17:30 +0000 Subject: [PATCH] * removed poll.php - it's totally outdated. * fixed 2 bugs in the discussion forum. --- discussion.php | 61 +++++------ poll.php | 267 ------------------------------------------------- 2 files changed, 25 insertions(+), 303 deletions(-) delete mode 100644 poll.php diff --git a/discussion.php b/discussion.php index 79e48d0dc64..1a06b042652 100644 --- a/discussion.php +++ b/discussion.php @@ -8,25 +8,27 @@ function discussion_score($comment) { function discussion_moderate($moderate) { global $user, $comment_votes; - $na = $comment_votes[key($comment_votes)]; + if ($user->id && $moderate) { + $na = $comment_votes[key($comment_votes)]; - foreach ($moderate as $id=>$vote) { - if ($user->id && $vote != $comment_votes[$na] && !user_getHistory($user->history, "c$id")) { - ### Update the comment's score: - $result = db_query("UPDATE comments SET score = score $vote, votes = votes + 1 WHERE cid = $id"); + foreach ($moderate as $id=>$vote) { + if ($vote != $comment_votes[$na] && !user_getHistory($user->history, "c$id")) { + ### Update the comment's score: + $result = db_query("UPDATE comments SET score = score $vote, votes = votes + 1 WHERE cid = $id"); - ### Update the user's history: - user_setHistory($user, "c$id", $vote); + ### Update the user's history: + user_setHistory($user, "c$id", $vote); + } } } } -function discussion_kids($cid, $mode, $level = 0, $dummy = 0) { +function discussion_kids($cid, $mode, $thold, $level = 0, $dummy = 0) { global $user, $theme; $comments = 0; - $result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.pid = $cid ORDER BY c.timestamp, c.cid"); + $result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.pid = $cid AND (c.votes = 0 OR c.score / c.votes >= $thold) ORDER BY c.timestamp, c.cid"); if ($mode == "nested") { while ($comment = db_fetch_object($result)) { @@ -37,33 +39,30 @@ function discussion_kids($cid, $mode, $level = 0, $dummy = 0) { $link = "sid&pid=$comment->cid\">hlcolor2\">reply to this comment"; $theme->comment($comment->userid, stripslashes($comment->subject), stripslashes($comment->comment), $comment->timestamp, stripslashes($comment->url), stripslashes($comment->femail), discussion_score($comment), $comment->votes, $comment->cid, $link); - discussion_kids($comment->cid, $mode, $level + 1, $dummy + 1); + discussion_kids($comment->cid, $mode, $thold, $level + 1, $dummy + 1); } } } - elseif ($mode == "flat") { + else { // mode == 'flat' while ($comment = db_fetch_object($result)) { if ($comment->score >= $thold) { $link = "sid&pid=$comment->cid\">hlcolor2\">reply to this comment"; $theme->comment($comment->userid, check_output($comment->subject), check_output($comment->comment), $comment->timestamp, $comment->url, $comment->femail, discussion_score($comment), $comment->votes, $comment->cid, $link); } - discussion_kids($comment->cid, $mode); + discussion_kids($comment->cid, $mode, $thold); } } - else { - print "ERROR: we should not get here!"; - } if ($level && $comments) { print ""; } } -function discussion_childs($cid, $level = 0, $thread) { +function discussion_childs($cid, $thold, $level = 0, $thread) { global $theme, $user; ### Perform SQL query: - $result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.pid = $cid ORDER BY c.timestamp, c.cid"); + $result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.pid = $cid AND (c.votes = 0 OR c.score / c.votes >= $thold) ORDER BY c.timestamp, c.cid"); if ($level == 0) $thread = ""; $comments = 0; @@ -79,7 +78,7 @@ function discussion_childs($cid, $level = 0, $thread) { $thread .= "
  • sid&cid=$comment->cid&pid=$comment->pid\">". check_output($comment->subject) ." by ". format_username($comment->userid) ." (". discussion_score($comment) .")
  • "; ### Recursive: - discussion_childs($comment->cid, $level + 1, &$thread); + discussion_childs($comment->cid, $thold, $level + 1, &$thread); } if ($level && $comments) { @@ -113,27 +112,17 @@ function discussion_display($sid, $pid, $cid, $level = 0) { $story = db_fetch_object($result); ### Display story: - if ($story->status == 1) { - $theme->article($story, "[ hlcolor2\">submission queue | id&pid=0\">hlcolor2\">add a comment ]"); - } - else { - $theme->article($story, "[ hlcolor2\">home | id&pid=0\">hlcolor2\">add a comment ]"); - } + if ($story->status == 1) $theme->article($story, "[ hlcolor2\">submission queue | id&pid=0\">hlcolor2\">add a comment ]"); + else $theme->article($story, "[ hlcolor2\">home | id&pid=0\">hlcolor2\">add a comment ]"); ### Display `comment control'-box: - if ($user->id) { - $theme->commentControl($sid, $title, $thold, $mode, $order); - } + if ($user->id) $theme->commentControl($sid, $title, $thold, $mode, $order); ### Compose query: - $query = "SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.sid = $sid AND c.pid = $pid"; - if ($mode == 'threaded' || mode == 'nested') { - if ($thold != "") $query .= " AND c.score >= $thold"; - else $query .= " AND c.score >= 0"; - } + $query .= "SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.sid = $sid AND c.pid = $pid AND (c.votes = 0 OR c.score / c.votes >= $thold)"; if ($order == 1) $query .= " ORDER BY c.timestamp DESC"; if ($order == 2) $query .= " ORDER BY c.score DESC"; - $result = db_query("$query"); + $result = db_query($query); print "
    \n"; @@ -141,7 +130,7 @@ function discussion_display($sid, $pid, $cid, $level = 0) { while ($comment = db_fetch_object($result)) { ### Dynamically compose the `reply'-link: if ($pid != 0) { - list($pid) = mysql_fetch_row(mysql_query("SELECT pid FROM comments WHERE cid = $comment->pid")); + list($pid) = db_fetch_row(db_query("SELECT pid FROM comments WHERE cid = $comment->pid")); $link = "sid&pid=$pid\">hlcolor2\">return to parent | sid&pid=$comment->cid\">hlcolor2\">reply to this comment"; } else { @@ -150,12 +139,12 @@ function discussion_display($sid, $pid, $cid, $level = 0) { ### Display the comments: if (empty($mode) || $mode == "threaded") { - $thread = discussion_childs($comment->cid); + $thread = discussion_childs($comment->cid, $thold); $theme->comment($comment->userid, check_output($comment->subject), check_output($comment->comment), $comment->timestamp, $comment->url, $comment->femail, discussion_score($comment), $comment->votes, $comment->cid, $link, $thread); } else { $theme->comment($comment->userid, check_output($comment->subject), check_output($comment->comment), $comment->timestamp, $comment->url, $comment->femail, discussion_score($comment), $comment->votes, $comment->cid, $link); - discussion_kids($comment->cid, $mode, $level); + discussion_kids($comment->cid, $mode, $thold, $level); } } diff --git a/poll.php b/poll.php deleted file mode 100644 index 36bebaa71b0..00000000000 --- a/poll.php +++ /dev/null @@ -1,267 +0,0 @@ -$vote + 1; - $query = "UPDATE poll SET $vote = '$result' WHERE id = $poll->id"; - $result = mysql_query($query); - } -} - -function addPoll($question, $answer1, $answer2, $answer3 = "", $answer4 = "", $answer5 = "", $answer6 = "") { - $query = "INSERT INTO poll (question, answer1, answer2, answer3, answer4, answer5, answer6) VALUES ('$question', '$answer1', '$answer2', '$answer3', '$answer4', '$answer5', '$answer6')"; - $result = mysql_query($query); -} - -function updatePoll($id, $question, $answer1, $answer2, $answer3 = "", $answer4 = "", $answer5 = "", $answer6 = "") { - $query = "UPDATE poll SET question = '$question', answer1 = '$answer1', answer2 = '$answer2', answer3 = '$answer3', answer4 = '$answer4', answer5 = '$answer5', answer6 = '$answer6' WHERE id = $id"; - $result = mysql_query($query); -} - -function getPoll($id) { - $query = "SELECT * FROM poll WHERE id = $id"; - $result = mysql_query($query); - if ($poll = mysql_fetch_object($result)) return $poll; -} - -function getActivePoll() { - $query = "SELECT * FROM poll WHERE status = 1"; - $result = mysql_query($query); - if ($poll = mysql_fetch_object($result)) return $poll->id; -} - -function getPollArray() { - $query = "SELECT * FROM poll"; - $result = mysql_query($query); - - $index = 0; - while ($poll = mysql_fetch_object($result)) { - $rval[$index] = $poll; - $index++; - } - - return $rval; -} - -function displayForm() { - global $PHP_SELF; - - if ($poll = getPoll(getActivePoll())) { - $rval = "

    $poll->question

    \n"; - $rval .= "\n"; - if ($poll->answer1) $rval .= " $poll->answer1
    \n"; - if ($poll->answer2) $rval .= " $poll->answer2
    \n"; - if ($poll->answer3) $rval .= " $poll->answer3
    \n"; - if ($poll->answer4) $rval .= " $poll->answer4
    \n"; - if ($poll->answer5) $rval .= " $poll->answer5
    \n"; - if ($poll->answer6) $rval .= " $poll->answer6
    \n"; - $rval .= "
    \n"; - $rval .= "
    "; - } - else { - $rval = "There is currently no poll available."; - } - return $rval; -} - -function displayResult($id) { - global $PHP_SELF, $barImage; - - if ($poll = getPoll($id)) { - # total number of votes: - $total = $poll->votes1 + $poll->votes2 + $poll->votes3 + $poll->votes4 + $poll->votes5 + $poll->votes6; - $rval = "

    $poll->question

    \n"; - - if ($total) { - # percentage: - if ($poll->answer1) { - $per1 = round($poll->votes1 / $total * 100); - $wid1 = ($per1) ? $per1 : 1; - $rval .= "

    $poll->answer1
    $poll->votes1 ($per1 %)

    "; - } - if ($poll->answer2) { - $per2 = round($poll->votes2 / $total * 100); - $wid2 = ($per2) ? $per2 : 1; - $rval .= "

    $poll->answer2
    $poll->votes2 ($per2 %)

    "; - } - if ($poll->answer3) { - $per3 = round($poll->votes3 / $total * 100); - $wid3 = ($per3) ? $per3 : 1; - $rval .= "

    $poll->answer3
    $poll->votes3 ($per3 %)

    "; - } - if ($poll->answer4) { - $per4 = round($poll->votes4 / $total * 100); - $wid4 = ($per4) ? $per4 : 1; - $rval .= "

    $poll->answer4
    $poll->votes4 ($per4 %)

    "; - } - if ($poll->answer5) { - $per5 = round($poll->votes5 / $total * 100); - $wid5 = ($per5) ? $per5 : 1; - $rval .= "

    $poll->answer5
    $poll->votes5 ($per5 %)

    "; - } - if ($poll->answer6) { - $per6 = round($poll->votes6 / $total * 100); - $wid6 = ($per6) ? $per6 : 1; - $rval .= "

    $poll->answer6
    $poll->votes6 ($per6 %)

    "; - } - } - $rval .= "

    Total votes: $total

    "; - } - else { - $rval = "There is currently no poll available."; - } - return $rval; -} - -function adminPolls() { - global $PHP_SELF; - - $polls = getPollArray(); - $rval = "\n"; - for (reset($polls); $poll = current($polls); next($polls)) { - $status = ($poll->status) ? "" : ""; - $rval .= " $status\n"; - } - $rval .= "
    *id\">disable*id\">enable
    $poll->questionid\">viewid\">editid\">delete
    "; - - return $rval; -} - -if (!$box) { - include "function.inc"; - include "theme.inc"; - $theme->header(); -} - -if ($section == "poll") { - if ($method == "add") { - if ($admin) { - addPoll($question, $answer1, $answer2, $answer3, $answer4, $answer5, $answer6); - $theme->box("Poll manager", "

    Status: new poll added.

    \n

    Overview:

    \n". adminPolls() ."

    Add poll:

    \n
    \n\n \n \n \n \n \n \n \n \n
    Question:
    Answer 1:
    Answer 2:
    Answer 3:
    Answer 4:
    Answer 5:
    Answer 6:
     
    \n
    "); - } - else $theme->box("Failed", "You don't have permission to access this section.

    [ back ]

    "); - } - else if ($method == "edit") { - if ($admin) { - $poll = getPoll($id); - $theme->box("Poll manager", "

    Edit poll:

    \n
    id\">\n\n \n \n \n \n \n \n \n \n
    Question:question\">
    Answer 1:answer1\">
    Answer 2:answer2\">
    Answer 3:answer3\">
    Answer 4:answer4\">
    Answer 5:answer5\">
    Answer 6:answer6\">
     
    \n
    "); - } - else $theme->box("Failed", "You don't have permission to access this section.

    [ back ]

    "); - } - else if ($method == "enable") { - if ($admin) { - enablePoll($id); - $theme->box("Poll manager", "

    Status: poll enabled.

    \n

    Overview:

    \n". adminPolls() ."

    Add poll:

    \n
    \n\n \n \n \n \n \n \n \n \n
    Question:
    Answer 1:
    Answer 2:
    Answer 3:
    Answer 4:
    Answer 5:
    Answer 6:
     
    \n
    "); - } - else $theme->box("Failed", "You don't have permission to access this section.

    [ back ]

    "); - } - else if ($method == "delete") { - if ($admin) { - deletePoll($id); - $theme->box("Poll manager", "

    Status: poll deleted.

    \n

    Overview:

    \n". adminPolls() ."

    Add poll:

    \n
    \n\n \n \n \n \n \n \n \n \n
    Question:
    Answer 1:
    Answer 2:
    Answer 3:
    Answer 4:
    Answer 5:
    Answer 6:
     
    \n
    "); - } - else $theme->box("Failed", "You don't have permission to access this section.

    [ back ]

    "); - } - else if ($method == "disable") { - if ($admin) { - disablePoll($id); - $theme->box("Poll manager", "

    Status: poll disabled.

    \n

    Overview:

    \n". adminPolls() ."

    Add poll:

    \n
    \n\n \n \n \n \n \n \n \n \n
    Question:
    Answer 1:
    Answer 2:
    Answer 3:
    Answer 4:
    Answer 5:
    Answer 6:
     
    \n
    "); - } - else $theme->box("Failed", "You don't have permission to access this section.

    [ back ]

    "); } - else if ($method == "update") { - if ($admin) { - updatePoll($id, $question, $answer1, $answer2, $answer3, $answer4, $answer5, $answer6); - $theme->box("Poll manager", "

    Status: poll updated.

    \n

    Overview:

    \n". adminPolls() ."

    Add poll:

    \n
    \n\n \n \n \n \n \n \n \n \n
    Question:
    Answer 1:
    Answer 2:
    Answer 3:
    Answer 4:
    Answer 5:
    Answer 6:
     
    \n
    "); - } - else $theme->box("Failed", "You don't have permission to access this section.

    [ back ]

    "); - } - else if ($method == "result") { - if ($id) $theme->box("Voting poll", displayResult($id)); - else $theme->box("Voting poll", displayResult(getActivePoll())); - } - else if ($method == "vote") { - if ($poll) { - $theme->box("Voting poll", displayResult(getActivePoll()) ."

    Note: you have voted already recently.

    "); - } - else { - castVote($answer); - $theme->box("Voting poll", displayResult(getActivePoll())); - } - } - else { - if ($admin) { - $theme->box("Poll manager", "

    Overview:

    \n". adminPolls() ."

    Add poll:

    \n
    \n\n \n \n \n \n \n \n \n \n
    Question:
    Answer 1:
    Answer 2:
    Answer 3:
    Answer 4:
    Answer 5:
    Answer 6:
     
    \n
    "); - } - else $theme->box("Failed", "You don't have permission to access this section.

    [ back ]

    "); - } -} -else { - if ($poll) { - $theme->box("Voting poll", displayResult(getActivePoll()) ."

    Note: you have voted already recently.

    "); - } - else { - $theme->box("Voting poll", displayForm() ."

    [ hlcolor2\">results ]

    "); - } -} - -if (!$box) $theme->footer(); -?> \ No newline at end of file