r887: Removing all the annoying calls to intval() in place of ISSO's cleaning framework
[bugdar.git] / vote.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 [#]gpl[#] 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 define('SVN', '$Id$');
23
24 $focus['showreport'] = 'focus';
25
26 require_once('./global.php');
27
28 // ###################################################################
29
30 if (empty($_REQUEST['do']))
31 {
32 $message->error($lang->getlex('error_invalid_id'));
33 }
34
35 // ###################################################################
36
37 if ($_REQUEST['do'] == 'vote')
38 {
39 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $bugsys->input_clean('bugid', TYPE_UINT) . ((!can_perform('canviewhidden')) ? " AND !hidden" : ''));
40 $vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
41
42 if (!can_perform('canvote', $bug['productid']))
43 {
44 $message->error_permission();
45 }
46
47 if (!$bug)
48 {
49 $message->error($lang->getlex('error_invalid_id'));
50 }
51
52 if ($vote['uservote'])
53 {
54 $message->error($lang->string('You have already voted on this bug.'));
55 }
56
57 // handle userids
58 $userids = $vote['userids'];
59 if ($bugsys->userinfo['userid'])
60 {
61 if (trim($vote['userids']))
62 {
63 $userids .= ',' . $bugsys->userinfo['userid'];
64 }
65 else
66 {
67 $userids = $bugsys->userinfo['userid'];
68 }
69 }
70
71 $uservote = $bugsys->input_clean('vote', TYPE_UINT);
72
73 $votefor = $vote['votefor'];
74 $voteagainst = $vote['voteagainst'];
75
76 if ($uservote > 0)
77 {
78 $votefor++;
79 }
80 else if ($uservote < 0)
81 {
82 $voteagainst++;
83 }
84 else
85 {
86 $message->error($lang->string('You need to specify whether you want to vote for or against this bug.'));
87 }
88
89 $db->query("UPDATE " . TABLE_PREFIX . "vote SET userids = '$userids', votefor = $votefor, voteagainst = $voteagainst WHERE bugid = $bug[bugid]");
90
91 $message->redirect($lang->string('Your vote has been added.'), "showreport.php?bugid=$bug[bugid]");
92 }
93
94 /*=====================================================================*\
95 || ###################################################################
96 || # $HeadURL$
97 || # $Id$
98 || ###################################################################
99 \*=====================================================================*/
100 ?>