r665: Renaming product from "BugStrike" to "Bugdar"
[bugdar.git] / vote.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]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 define('SVN', '$Id$');
14
15 $focus['showreport'] = 'focus';
16
17 require_once('./global.php');
18
19 // ###################################################################
20
21 if (empty($_REQUEST['do']))
22 {
23 $message->error($lang->getlex('error_invalid_id'));
24 }
25
26 // ###################################################################
27
28 if ($_REQUEST['do'] == 'vote')
29 {
30 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . intval($bugsys->in['bugid']) . ((!can_perform('canviewhidden')) ? " AND !bug.hidden" : ''));
31 $vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
32
33 if (!can_perform('canvote', $bug['productid']))
34 {
35 $message->error_permission();
36 }
37
38 if (!$bug)
39 {
40 $message->error($lang->getlex('error_invalid_id'));
41 }
42
43 if ($vote['uservote'])
44 {
45 $message->error($lang->string('You have already voted on this bug.'));
46 }
47
48 // handle userids
49 $userids = $vote['userids'];
50 if ($bugsys->userinfo['userid'])
51 {
52 if (trim($vote['userids']))
53 {
54 $userids .= ',' . $bugsys->userinfo['userid'];
55 }
56 else
57 {
58 $userids = $bugsys->userinfo['userid'];
59 }
60 }
61
62 $uservote = intval($bugsys->in['vote']);
63
64 $votefor = $vote['votefor'];
65 $voteagainst = $vote['voteagainst'];
66
67 if ($uservote > 0)
68 {
69 $votefor++;
70 }
71 else if ($uservote < 0)
72 {
73 $voteagainst++;
74 }
75 else
76 {
77 $message->error($lang->string('You need to specify whether you want to vote for or against this bug.'));
78 }
79
80 $db->query("UPDATE " . TABLE_PREFIX . "vote SET userids = '$userids', votefor = $votefor, voteagainst = $voteagainst WHERE bugid = $bug[bugid]");
81
82 $message->redirect($lang->string('Your vote has been added.'), "showreport.php?bugid=$bug[bugid]");
83 }
84
85 /*=====================================================================*\
86 || ###################################################################
87 || # $HeadURL$
88 || # $Id$
89 || ###################################################################
90 \*=====================================================================*/
91 ?>