From ef22955143a25dc1c2ff15c4953189ec9b320f9d Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 10 Jul 2005 00:40:13 +0000 Subject: [PATCH] r281: Added voting system. --- docs/roadmap.txt | 1 - docs/schema_changes.sql | 10 +++++- docs/todo.txt | 1 - showreport.php | 11 ++++++ templates/SHOWREPORT.tpl | 35 ++++++++++++++++++ vote.php | 78 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 vote.php diff --git a/docs/roadmap.txt b/docs/roadmap.txt index b355a2a..4418bda 100755 --- a/docs/roadmap.txt +++ b/docs/roadmap.txt @@ -8,7 +8,6 @@ BUGTRACK 1.0 ---------------------------------------- BETA 2 ---------------------------------------- -- Voting system - Complete phrase tool system for administrators - Dependency graph (?) diff --git a/docs/schema_changes.sql b/docs/schema_changes.sql index 313eebb..901740a 100644 --- a/docs/schema_changes.sql +++ b/docs/schema_changes.sql @@ -5,4 +5,12 @@ CREATE TABLE `favourite` ( `bugid` INT(10) UNSIGNED NOT NULL ); -ALTER TABLE `favourite` ADD PRIMARY KEY (`userid`,`bugid`); \ No newline at end of file +ALTER TABLE `favourite` ADD PRIMARY KEY (`userid`,`bugid`); + +CREATE TABLE `vote` ( + `bugid` INT(10) UNSIGNED NOT NULL, + `userids` MEDIUMTEXT NOT NULL, + `votefor` INT(10) UNSIGNED NOT NULL, + `voteagainst` INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (`bugid`) +); \ No newline at end of file diff --git a/docs/todo.txt b/docs/todo.txt index 7682ad5..df5c10d 100755 --- a/docs/todo.txt +++ b/docs/todo.txt @@ -24,7 +24,6 @@ BUGTRACK 1.0 BUG REPORTING/EDITING ---------------------------------------- - Help bubbles detailing each field -- Voting system ############################################################################### BUGTRACK 1.1 diff --git a/showreport.php b/showreport.php index 1c2d89a..b39345f 100644 --- a/showreport.php +++ b/showreport.php @@ -178,6 +178,17 @@ if ($show['getattachments'] OR $show['putattachments']) } } +// ------------------------------------------------------------------- +// votes + +$vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]"); + +$vote['total'] = $vote['votefor'] + $vote['voteagainst']; +$vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100; +$vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100; + +$show['vote'] = ((can_perform('canvote') AND !$vote['uservote']) ? true : false); + // ------------------------------------------------------------------- // get comments $comments_fetch = $db->query(" diff --git a/templates/SHOWREPORT.tpl b/templates/SHOWREPORT.tpl index 021a3a9..a548202 100644 --- a/templates/SHOWREPORT.tpl +++ b/templates/SHOWREPORT.tpl @@ -38,6 +38,41 @@ $attachments
+ + + + + + + + + + + + + + + + + +
Votes for this Bug
+ Votes for this Bug: $vote[votefor] ($vote[forpercent]%)
+ Votes against this bug: $vote[voteagainst] ($vote[againstpercent]%)
+ Total Votes: $vote[total] +
+
+ + + + Vote For (+1)
+ Vote Against (-1)
+ + +
+
+ +
+ $comments
[New Comment]
\ No newline at end of file diff --git a/vote.php b/vote.php new file mode 100644 index 0000000..f121eba --- /dev/null +++ b/vote.php @@ -0,0 +1,78 @@ +error(lang::p('error_invalid_id')); +} + +// ################################################################### + +if ($_REQUEST['do'] == 'vote') +{ + $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . intval($bugsys->in['bugid']) . ((!can_perform('canviewhidden')) ? " AND !bug.hidden" : '')); + $vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]"); + + if (!$bug) + { + $message->error(lang::p('error_invalid_id')); + } + + if ($vote['uservote']) + { + $message->error('you have already voted on this bug'); + } + + // handle userids + $userids = $vote['userids']; + if ($bugsys->userinfo['userid']) + { + if (trim($vote['userids'])) + { + $userids .= ',' . $bugsys->userinfo['userid']; + } + else + { + $userids = $bugsys->userinfo['userid']; + } + } + + $uservote = intval($bugsys->in['vote']); + + $votefor = $vote['votefor']; + $voteagainst = $vote['voteagainst']; + + if ($uservote > 0) + { + $votefor++; + } + else + { + $voteagainst++; + } + + $db->query("UPDATE " . TABLE_PREFIX . "vote SET userids = '$userids', votefor = $votefor, voteagainst = $voteagainst WHERE bugid = $bug[bugid]"); + + $message->redirect('your vote has been added', "showreport.php?bugid=$bug[bugid]"); +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.22.5