Adding the upgrade script for version 1.2.3
[bugdar.git] / vote.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2009 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22
23 $focus['showreport'] = 'focus';
24
25 require_once('./global.php');
26
27 // ###################################################################
28
29 if (empty($_REQUEST['do']))
30 {
31 $message->error(L_INVALID_ID);
32 }
33
34 // ###################################################################
35
36 if ($_REQUEST['do'] == 'vote')
37 {
38 $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $input->inputClean('bugid', TYPE_UINT));
39 $vote = $db->queryFirst("SELECT *, FIND_IN_SET(" . bugdar::$userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
40
41 if (!check_bug_permissions($bug))
42 {
43 $message->errorPermission();
44 }
45
46 if (!can_perform('canvote', $bug['product']))
47 {
48 $message->errorPermission();
49 }
50
51 if (!$bug)
52 {
53 $message->error(L_INVALID_ID);
54 }
55
56 if ($vote['uservote'])
57 {
58 $message->error(T('You have already voted on this bug.'));
59 }
60
61 // handle userids
62 $userids = $vote['userids'];
63 if (bugdar::$userinfo['userid'])
64 {
65 if (trim($vote['userids']))
66 {
67 $userids .= ',' . bugdar::$userinfo['userid'];
68 }
69 else
70 {
71 $userids = bugdar::$userinfo['userid'];
72 }
73 }
74
75 $uservote = $input->inputClean('vote', TYPE_INT);
76
77 $votefor = $vote['votefor'];
78 $voteagainst = $vote['voteagainst'];
79
80 if ($uservote > 0)
81 {
82 $votefor++;
83 }
84 else if ($uservote < 0)
85 {
86 $voteagainst++;
87 }
88 else
89 {
90 $message->error(T('You need to specify whether you want to vote for or against this bug.'));
91 }
92
93 $db->query("UPDATE " . TABLE_PREFIX . "vote SET userids = '$userids', votefor = $votefor, voteagainst = $voteagainst WHERE bugid = $bug[bugid]");
94
95 $message->redirect(T('Your vote has been added.'), "showreport.php?bugid=$bug[bugid]");
96 }
97
98 ?>