r390: Registering language data
[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 define('SVN', '$Id$');
14
15 $focus['showreport'] = 'focus';
16
17 require_once('./global.php');
18
19 if (!can_perform('canvote'))
20 {
21 $message->error_permission();
22 }
23
24 // ###################################################################
25
26 if (empty($_REQUEST['do']))
27 {
28 $message->error(lang::p('error_invalid_id'));
29 }
30
31 // ###################################################################
32
33 if ($_REQUEST['do'] == 'vote')
34 {
35 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . intval($bugsys->in['bugid']) . ((!can_perform('canviewhidden')) ? " AND !bug.hidden" : ''));
36 $vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
37
38 if (!$bug)
39 {
40 $message->error(lang::p('error_invalid_id'));
41 }
42
43 if ($vote['uservote'])
44 {
45 $message->error(lang::p('error_already_voted'));
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
72 {
73 $voteagainst++;
74 }
75
76 $db->query("UPDATE " . TABLE_PREFIX . "vote SET userids = '$userids', votefor = $votefor, voteagainst = $voteagainst WHERE bugid = $bug[bugid]");
77
78 $message->redirect(lang::p('vote_added'), "showreport.php?bugid=$bug[bugid]");
79 }
80
81 /*=====================================================================*\
82 || ###################################################################
83 || # $HeadURL$
84 || # $Id$
85 || ###################################################################
86 \*=====================================================================*/
87 ?>