This repository has been archived by the owner on Apr 5, 2019. It is now read-only.
forked from basisentscheid/basisentscheid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vote.php
103 lines (86 loc) · 2.32 KB
/
vote.php
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
<?
/**
* vote
*
* @author Magnus Rosenbaum <dev@cmr.cx>
* @package Basisentscheid
*/
require "inc/common_http.php";
$issue = new Issue(@$_GET['issue']);
if (!$issue->id) {
error(_("The requested issue does not exist."));
}
$_SESSION['ngroup'] = $issue->area()->ngroup;
Login::access("entitled", $_SESSION['ngroup']);
if ($issue->state == 'finished') {
error(_("The voting on this issue is already closed."));
} elseif ($issue->state != 'voting') {
error(_("The issue is not in voting state."));
}
$token = $issue->vote_token();
if (!$token) {
error(_("You can not vote in this voting period, because you were not yet entitled when the voting started."));
}
if ($action) {
switch ($action) {
case "submit":
action_required_parameters('vote');
$issue->vote($token, $_POST['vote']);
//redirect("proposals.php?ngroup=".$ngroup->id."&filter=voting");
redirect();
break;
default:
warning(_("Unknown action"));
redirect();
}
}
html_head(_("Vote"), true);
?>
<p><?=sprintf(_("Voting goes until %s."), datetimeformat($issue->period()->counting))?></p>
<?
list($proposals, $submitted) = $issue->proposals_list(true);
$sql = "SELECT token, vote, votetime FROM vote_vote
WHERE token=".DB::esc($token)."
ORDER BY votetime DESC";
$result = DB::query($sql);
// get only the first record, which is the last submitted vote
if ( $row = DB::fetch_assoc($result) ) {
$vote = unserialize($row['vote']);
} else {
// default
$vote = array();
foreach ( $proposals as $proposal ) {
$vote[$proposal->id]['acceptance'] = -1; // default is abstention
if (count($proposals) > 1) $vote[$proposal->id]['score'] = 0; // default is 0
}
}
// voting form
form(BN."?issue=".$issue->id, "", "", "vote", true);
?>
<input type="hidden" name="action" value="submit">
<table class="proposals">
<?
Issue::display_proposals_th(false, count($proposals) > 1);
$issue->display_proposals($proposals, $submitted, count($proposals), false, 0, $vote);
?>
<tr>
<td></td>
<td<?
if (count($proposals) > 1) { ?> colspan="2"<? }
?> class="th"><input type="submit" value="<?=_("Submit vote")?>"></td>
</tr>
</table>
<?
form_end();
// submitted votes
if ( DB::num_rows($result) ) {
?>
<h2><?=_("Your submitted votes on this issue:")?></h2>
<?
DB::result_seek($result, 0);
Issue::display_votes($proposals, $result);
}
?>
<div class="clearfix"></div>
<?
html_foot();