tu.php 3.25 KB
Newer Older
Callan Barrett's avatar
Callan Barrett committed
1
2
<?php

3
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');
Callan Barrett's avatar
Callan Barrett committed
4

5
include_once("aur.inc.php");
Callan Barrett's avatar
Callan Barrett committed
6
7
set_lang();
check_sid();
8
9
10
11

$title = __("Trusted User");

html_header($title);
Callan Barrett's avatar
Callan Barrett committed
12

13
# Default votes per page
14
15
$pp = 10;
$prev_Len = 75;
16
17

$atype = "";
Callan Barrett's avatar
Callan Barrett committed
18
19
20
21
if (isset($_COOKIE["AURSID"])) {
  $atype = account_from_sid($_COOKIE["AURSID"]);
}

22
if ($atype == "Trusted User" || $atype == "Developer") {
Callan Barrett's avatar
Callan Barrett committed
23

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

Callan Barrett's avatar
Callan Barrett committed
28
			if (empty($row)) {
29
				print __("Could not retrieve proposal details.");
Callan Barrett's avatar
Callan Barrett committed
30
			} else {
31
				$isrunning = $row['End'] > time() ? 1 : 0;
32

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

36
				$canvote = 1;
37
				$hasvoted = 0;
38
				$errorvote = "";
Callan Barrett's avatar
Callan Barrett committed
39
40
				if ($isrunning == 0) {
					$canvote = 0;
41
					$errorvote = __("Voting is closed for this proposal.");
Callan Barrett's avatar
Callan Barrett committed
42
43
				} else if ($row['User'] == username_from_sid($_COOKIE["AURSID"])) {
					$canvote = 0;
44
					$errorvote = __("You cannot vote in an proposal about you.");
45
				} else if (tu_voted($row['ID'], uid_from_sid($_COOKIE["AURSID"]))) {
Callan Barrett's avatar
Callan Barrett committed
46
					$canvote = 0;
47
					$hasvoted = 1;
Loui Chang's avatar
Loui Chang committed
48
					$errorvote = __("You've already voted for this proposal.");
Callan Barrett's avatar
Callan Barrett committed
49
50
51
				}

				if ($canvote == 1) {
52
					if (isset($_POST['doVote']) && check_token()) {
Callan Barrett's avatar
Callan Barrett committed
53
						if (isset($_POST['voteYes'])) {
54
							$myvote = "Yes";
Callan Barrett's avatar
Callan Barrett committed
55
						} else if (isset($_POST['voteNo'])) {
56
							$myvote = "No";
Callan Barrett's avatar
Callan Barrett committed
57
						} else if (isset($_POST['voteAbstain'])) {
58
							$myvote = "Abstain";
Callan Barrett's avatar
Callan Barrett committed
59
60
						}

61
						cast_proposal_vote($row['ID'], uid_from_sid($_COOKIE["AURSID"]), $myvote, $row[$myvote] + 1);
Callan Barrett's avatar
Callan Barrett committed
62
63
64
65

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

68
69
70
						# Update if they voted
						if (tu_voted($row['ID'], uid_from_sid($_COOKIE["AURSID"]))) {
							$hasvoted = 1;
71
						}
72
						$row = vote_details($_GET['id']);
Callan Barrett's avatar
Callan Barrett committed
73
74
					}
				}
75
				include("tu_details.php");
Callan Barrett's avatar
Callan Barrett committed
76
77
			}
		} else {
78
			print __("Vote ID not valid.");
Callan Barrett's avatar
Callan Barrett committed
79
80
81
		}

	} else {
82
		$limit = $pp;
83
84
85
86
87
88
		if (isset($_GET['off']))
			$offset = $_GET['off'];

		if (isset($_GET['by']))
			$by = $_GET['by'];
		else
89
			$by = 'desc';
Callan Barrett's avatar
Callan Barrett committed
90

91
		if (!empty($offset) && is_numeric($offset)) {
92
93
94
95
96
97
98
99
			if ($offset >= 1) {
				$off = $offset;
			} else {
				$off = 0;
			}
		} else {
			$off = 0;
		}
Callan Barrett's avatar
Callan Barrett committed
100

101
		$order = ($by == 'asc') ? 'ASC' : 'DESC';
102
		$lim = ($limit > 0) ? " LIMIT $limit OFFSET $off" : "";
103
		$by_next = ($by == 'desc') ? 'asc' : 'desc';
Callan Barrett's avatar
Callan Barrett committed
104

105
		$result = current_proposal_list($order);
106
107
108
		$type = __("Current Votes");
		include("tu_list.php");
?>
Callan Barrett's avatar
Callan Barrett committed
109

110
<?php
111
		$result = past_proposal_list($order, $lim);
Callan Barrett's avatar
Callan Barrett committed
112

113
		$type = __("Past Votes");
114
		include("tu_list.php");
Callan Barrett's avatar
Callan Barrett committed
115

116
		$nextresult = proposal_count();
117
?>
118
<div class="box">
Lukas Fleischer's avatar
Lukas Fleischer committed
119
	<p><a href="<?= get_uri('/addvote/'); ?>"><?= __("Add Proposal") ?></a></p>
120

121
	<?php if ($result):
122
123
124
		$by = htmlentities($by, ENT_QUOTES); ?>
		<?php if ($off != 0):
			$back = (($off - $limit) <= 0) ? 0 : $off - $limit; ?>
Lukas Fleischer's avatar
Lukas Fleischer committed
125
			<a href='<?= get_uri('/tu/'); ?>?off=<?= $back ?>&amp;by=<?= $by ?>'><?= __("Back") ?></a>
126
		<?php endif; ?>
127
		<?php if (($off + $limit) < $nextresult):
128
			$forw = $off + $limit; ?>
Lukas Fleischer's avatar
Lukas Fleischer committed
129
		<a href="<?= get_uri('/tu/'); ?>?off=<?= $forw ?>&amp;by=<?= $by ?>"><?= __("Next") ?></a>
130
131
		<?php endif; ?>
	<?php endif; ?>
132
</div>
133
<?php
Callan Barrett's avatar
Callan Barrett committed
134
	}
135
136
}
else {
137
	header('Location: /');
Callan Barrett's avatar
Callan Barrett committed
138
139
140
}

html_footer(AUR_VERSION);
141