819f03aa27fcb4d4207a3aac719cb1811984c882
[cacert-boardvoting.git] / vote.php
1 <?php
2 if ($_SERVER['HTTPS'] != 'on') {
3 header("HTTP/1.0 302 Redirect");
4 header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
5 exit();
6 }
7 $user = $_SERVER['REMOTE_USER'];
8 require_once("database.php");
9 $db = new DB();
10 $stmt = $db->getStatement("get voter");
11 $stmt->execute(array($user));
12 if (!($user = $stmt->fetch())) {
13 header("HTTP/1.0 302 Redirect");
14 header("Location: denied.php");
15 exit();
16 }
17 ?>
18 <html>
19 <head>
20 <title>CAcert Board Decisions</title>
21 <meta http-equiv="Content-Type" content="text/html; charset='UTF-8'" />
22 <link rel="stylesheet" type="text/css" href="styles.css" />
23 </head>
24 <body>
25 <?php
26 if (is_numeric($_REQUEST['motion']) && is_numeric($_REQUEST['vote'])) {
27 $stmt = $db->getStatement("get decision");
28 $stmt->bindParam(":decision",$_REQUEST['motion']);
29 if ($stmt->execute() && ($decision=$stmt->fetch())) {
30 if ($decision['status'] == 0) {
31 $stmt = $db->getStatement("del vote");
32 $stmt->bindParam(":voter",$user['id']);
33 $stmt->bindParam(":decision",$_REQUEST['motion']);
34 if ($stmt->execute()) {
35 $stmt = $db->getStatement("do vote");
36 $stmt->bindParam(":voter",$user['id']);
37 $stmt->bindParam(":decision",$_REQUEST['motion']);
38 $stmt->bindParam(":vote",$_REQUEST['vote']);
39 $notes="Direct Vote\n\n".$_SERVER['SSL_CLIENT_CERT'];
40 $stmt->bindParam(":notes",$notes);
41 if ($stmt->execute()) {
42 ?>
43 <b>Your vote has been registered.</b><br/>
44 <a href="motions.php">Back to motions</a>
45 <?php
46 $name = $user['name'];
47 $vote = '';
48 switch($_REQUEST['vote']) {
49 case 1 : $vote='Aye'; break;
50 case -1: $vote='Naye'; break;
51 default: $vote='Abstain'; break;
52 }
53 $tag = $decision['tag'];
54 $title = $decision['title'];
55 $content = $decision['content'];
56 $due = $decision['due']." UTC";
57 $body = <<<BODY
58 Dear Board,
59
60 $name has just voted $vote on motion $tag.
61
62 Motion:
63 $title
64 $content
65
66 Kind regards,
67 the vote system
68
69 BODY;
70 $db->notify("Re: $tag - $title",$body);
71 } else {
72 ?>
73 <b>Your vote has NOT been registered.</b><br/>
74 <a href="motions.php">Back to motions</a>
75 <i><?php echo join("<br/>\n",$stmt->errorInfo()); ?></i>
76 <?php
77 }
78 } else {
79 ?>
80 <b>Your vote has NOT been registered.</b><br/>
81 <a href="motions.php">Back to motions</a>
82 <i><?php echo join("<br/>\n",$stmt->errorInfo()); ?></i>
83 <?php
84 }
85 } else {
86 ?>
87 <b>Your vote has NOT been registered.</b><br/>
88 <b>Voting is alread closed!</b><br/>
89 <a href="motions.php">Back to motions</a>
90 <?php
91 }
92 } else {
93 ?>
94 <b>Your vote has NOT been registered.</b><br/>
95 <b>Could not find the motion to be voted!</b><br/>
96 <a href="motions.php">Back to motions</a>
97 <?php
98 }
99 } else {
100 ?>
101 <b>This call is not a valid vote!</b><br/>
102 <a href="motions.php">Back to motions</a>
103 <?php
104 }
105 ?>
106 </body>
107 </html>