r281: Added voting system.
[bugdar.git] / vote.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 require_once('./global.php');
14
15 // ###################################################################
16
17 if (empty($_REQUEST['do']))
18 {
19 $message->error(lang::p('error_invalid_id'));
20 }
21
22 // ###################################################################
23
24 if ($_REQUEST['do'] == 'vote')
25 {
26 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . intval($bugsys->in['bugid']) . ((!can_perform('canviewhidden')) ? " AND !bug.hidden" : ''));
27 $vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
28
29 if (!$bug)
30 {
31 $message->error(lang::p('error_invalid_id'));
32 }
33
34 if ($vote['uservote'])
35 {
36 $message->error('you have already voted on this bug');
37 }
38
39 // handle userids
40 $userids = $vote['userids'];
41 if ($bugsys->userinfo['userid'])
42 {
43 if (trim($vote['userids']))
44 {
45 $userids .= ',' . $bugsys->userinfo['userid'];
46 }
47 else
48 {
49 $userids = $bugsys->userinfo['userid'];
50 }
51 }
52
53 $uservote = intval($bugsys->in['vote']);
54
55 $votefor = $vote['votefor'];
56 $voteagainst = $vote['voteagainst'];
57
58 if ($uservote > 0)
59 {
60 $votefor++;
61 }
62 else
63 {
64 $voteagainst++;
65 }
66
67 $db->query("UPDATE " . TABLE_PREFIX . "vote SET userids = '$userids', votefor = $votefor, voteagainst = $voteagainst WHERE bugid = $bug[bugid]");
68
69 $message->redirect('your vote has been added', "showreport.php?bugid=$bug[bugid]");
70 }
71
72 /*=====================================================================*\
73 || ###################################################################
74 || # $HeadURL$
75 || # $Id$
76 || ###################################################################
77 \*=====================================================================*/
78 ?>