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