1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');
include_once("aur.inc.php");
set_lang();
check_sid();
html_header();
# Default votes per page
$pp = 10;
$prev_Len = 75;
$atype = "";
if (isset($_COOKIE["AURSID"])) {
$atype = account_from_sid($_COOKIE["AURSID"]);
}
if ($atype == "Trusted User" OR $atype == "Developer") {
if (isset($_GET['id'])) {
if (is_numeric($_GET['id'])) {
$q = "SELECT * FROM TU_VoteInfo ";
$q.= "WHERE ID = " . $_GET['id'];
$dbh = db_connect();
$results = db_query($q, $dbh);
$row = mysql_fetch_assoc($results);
if (empty($row)) {
print _("Could not retrieve proposal details.");
} else {
$isrunning = $row['End'] > time() ? 1 : 0;
$qvoted = "SELECT * FROM TU_Votes WHERE ";
$qvoted.= "VoteID = " . $row['ID'] . " AND ";
$qvoted.= "UserID = " . uid_from_sid($_COOKIE["AURSID"]);
$result = db_query($qvoted, $dbh);
if ($result) {
$hasvoted = mysql_num_rows($result);
}
else {
$hasvoted = 0;
}
# List voters of a proposal.
$qwhoVoted = "SELECT tv.UserID,U.Username
FROM TU_Votes tv, Users U
WHERE tv.VoteID = {$row['ID']}
AND tv.UserID = U.ID
ORDER BY Username";
$result = db_query($qwhoVoted,$dbh);
if (mysql_num_rows($result) > 0) {
$whovoted = '';
while ($who = mysql_fetch_assoc($result)) {
$whovoted.= '<a href="account.php?Action=AccountInfo&ID='.$who['UserID'].'">'.$who['Username'].'</a> ';
}
}
$canvote = 1;
$errorvote = "";
if ($isrunning == 0) {
$canvote = 0;
$errorvote = _("Voting is closed for this proposal.");
} else if ($row['User'] == username_from_sid($_COOKIE["AURSID"])) {
$canvote = 0;
$errorvote = _("You cannot vote in an proposal about you.");
} else if ($hasvoted != 0) {
$canvote = 0;
$errorvote = _("You've already voted for this proposal.");
}
if ($canvote == 1) {
if (isset($_POST['doVote'])) {
if (isset($_POST['voteYes'])) {
$myvote = "Yes";
} else if (isset($_POST['voteNo'])) {
$myvote = "No";
} else if (isset($_POST['voteAbstain'])) {
$myvote = "Abstain";
}
$qvote = "UPDATE TU_VoteInfo SET " . $myvote . " = " . ($row[$myvote] + 1) . " WHERE ID = " . $row['ID'];
db_query($qvote, $dbh);
$qvote = "INSERT INTO TU_Votes (VoteID, UserID) VALUES (" . $row['ID'] . ", " . uid_from_sid($_COOKIE["AURSID"]) . ")";
db_query($qvote, $dbh);
# Can't vote anymore
#
$canvote = 0;
$errorvote = _("You've already voted for this proposal.");
# Update if they voted
$result = db_query($qvoted, $dbh);
if ($result) {
$hasvoted = mysql_num_rows($result);
}
$results = db_query($q, $dbh);
if ($results) {
$row = mysql_fetch_assoc($results);
}
}
}
include("tu_details.php");
}
} else {
print _("Vote ID not valid.");
}
} else {
$dbh = db_connect();
$limit = $pp;
if (isset($_GET['off']))
$offset = $_GET['off'];
if (isset($_GET['by']))
$by = $_GET['by'];
else
$by = 'desc';
if (!empty($offset) AND is_numeric($offset)) {
if ($offset >= 1) {
$off = $offset;
} else {
$off = 0;
}
} else {
$off = 0;
}
$order = ($by == 'asc') ? 'ASC' : 'DESC';
$lim = ($limit > 0) ? " LIMIT $limit OFFSET $off" : "";
$by_next = ($by == 'desc') ? 'asc' : 'desc';
$q = "SELECT * FROM TU_VoteInfo WHERE End > " . time() . " ORDER BY Submitted " . $order;
$result = db_query($q, $dbh);
$type = _("Current Votes");
include("tu_list.php");
?>
<?php
$q = "SELECT * FROM TU_VoteInfo WHERE End < " . time() . " ORDER BY Submitted " . $order . $lim;
$result = db_query($q, $dbh);
$type = _("Past Votes");
include("tu_list.php");
$qnext = "SELECT ID FROM TU_VoteInfo";
$nextresult = db_query($qnext, $dbh);
?>
<div class="pgbox">
<p><a href='addvote.php'><?php print _("Add Proposal") ?></a></p>
<?php if (mysql_num_rows($result)) { $by = htmlentities($by, ENT_QUOTES); ?>
<?php if ($off != 0) { $back = (($off - $limit) <= 0) ? 0 : $off - $limit; ?>
<a href='tu.php?off=<?php print $back ?>&by=<?php print $by ?>'><?php print _("Back") ?></a>
<?php } ?>
<?php if (($off + $limit) < mysql_num_rows($nextresult)) { $forw = $off + $limit; ?>
<a href='tu.php?off=<?php print $forw ?>&by=<?php print $by ?>'><?php print _("Next") ?></a>
<?php } ?>
<?php } ?>
</div>
<?php
}
}
else {
header('Location: index.php');
}
html_footer(AUR_VERSION);
|