summaryrefslogtreecommitdiff
path: root/web/html/tu.php
blob: 48cd6c10c99744b39d1b4c8ddff1efb63dff2233 (plain)
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
<?php

set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');

include_once("aur.inc.php");
set_lang();
check_sid();

$title = __("Trusted User");

html_header($title);

# Default votes per page
$pp = 10;
$prev_Len = 75;

$atype = "";
if (isset($_COOKIE["AURSID"])) {
  $atype = account_from_sid($_COOKIE["AURSID"]);
}

if ($atype == "Trusted User" || $atype == "Developer") {

	if (isset($_GET['id'])) {
		if (is_numeric($_GET['id'])) {
			$row = vote_details($_GET['id']);

			if (empty($row)) {
				print __("Could not retrieve proposal details.");
			} else {
				$isrunning = $row['End'] > time() ? 1 : 0;

				# List voters of a proposal.
				$whovoted = voter_list($row['ID']);

				$canvote = 1;
				$hasvoted = 0;
				$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 (tu_voted($row['ID'], uid_from_sid($_COOKIE["AURSID"]))) {
					$canvote = 0;
					$hasvoted = 1;
					$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";
						}

						cast_proposal_vote($row['ID'], uid_from_sid($_COOKIE["AURSID"]), $myvote, $row[$myvote] + 1);

						# Can't vote anymore
						#
						$canvote = 0;
						$errorvote = __("You've already voted for this proposal.");

						# Update if they voted
						if (tu_voted($row['ID'], uid_from_sid($_COOKIE["AURSID"]))) {
							$hasvoted = 1;
						}
						$row = vote_details($_GET['id']);
					}
				}
				include("tu_details.php");
			}
		} else {
			print __("Vote ID not valid.");
		}

	} else {
		$limit = $pp;
		if (isset($_GET['off']))
			$offset = $_GET['off'];

		if (isset($_GET['by']))
			$by = $_GET['by'];
		else
			$by = 'desc';

		if (!empty($offset) && 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';

		$result = current_proposal_list($order);
		$type = __("Current Votes");
		include("tu_list.php");
?>

<?php
		$result = past_proposal_list($order, $lim);

		$type = __("Past Votes");
		include("tu_list.php");

		$nextresult = proposal_count();
?>
<div class="box">
	<p><a href="addvote.php"><?php print __("Add Proposal") ?></a></p>

	<?php if ($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 ?>&amp;by=<?php print $by ?>'><?php print __("Back") ?></a>
		<?php endif; ?>
		<?php if (($off + $limit) < $nextresult):
			$forw = $off + $limit; ?>
		<a href="tu.php?off=<?php print $forw ?>&amp;by=<?php print $by ?>"><?php print __("Next") ?></a>
		<?php endif; ?>
	<?php endif; ?>
</div>
<?php
	}
}
else {
	header('Location: index.php');
}

html_footer(AUR_VERSION);