4eba5b5d02d2460b43ee1c76e0a3e1730615fb2d
[cacert-boardvoting.git] / motion.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 $db->getStatement("stats")->execute();
15 $stats = $db->getStatement("stats")->fetch();
16 ?>
17 <html>
18 <head>
19 <title>CAcert Board Decisions</title>
20 <meta http-equiv="Content-Type" content="text/html; charset='UTF-8'" />
21 <link rel="stylesheet" type="text/css" href="styles.css" />
22 </head>
23 <body>
24 <?php
25 if ($_REQUEST['action'] == "store") {
26 if (is_numeric($_REQUEST['motion'])) {
27 $stmt = $db->getStatement("update decision");
28 $stmt->bindParam(":id",$_POST['motion']);
29 $stmt->bindParam(":proponent",$_POST['proponent']);
30 $stmt->bindParam(":title",$_POST['title']);
31 $stmt->bindParam(":content",$_POST['content']);
32 $stmt->bindParam(":quorum",$_POST['quorum']);
33 $stmt->bindParam(":majority",$_POST['majority']);
34 $stmt->bindParam(":due",$_POST['due']);
35 if ($stmt->execute()) {
36 ?>
37 <b>The motion has been proposed!</b><br/>
38 <a href="motions.php">Back to motions</a><br/>
39 <br/>
40 <br/>
41 <?php
42 $decision = $db->getStatement("get decision")->execute(array($_POST['motion']))?$db->getStatement("get decision")->fetch():array();
43 $name = $user['name'];
44 $tag = $decision['tag'];
45 $title = $decision['title'];
46 $content =$decision['content'];
47 $due = $decision['due']." UTC";
48 $quorum = $decision['quorum'];
49 $majority = $decision['majority'];
50 $baseurl = "https://".$_SERVER['HTTP_HOST'].":".$_SERVER['SERVER_PORT'].preg_replace('/motion\.php/','',$_SERVER['REQUEST_URI']);
51 $voteurl = $baseurl."vote.php?motion=".$decision['id'];
52 $unvoted = $baseurl."motions.php?unvoted=1";
53 $body = <<<BODY
54 Dear Board,
55
56 $name has modified motion $tag to the following:
57
58 $title
59 $content
60
61 To pass a minimum of $quorum votes and a $majority% acceptance will be required.
62 Voting will close $due.
63
64 To vote please choose:
65
66 Aye: $voteurl&vote=1
67 Naye: $voteurl&vote=-1
68 Abstain: $voteurl&vote=0
69
70 Please be aware, that if you have voted already your vote is still registered and valid.
71 If this modification has an impact on how you wish to vote, you are responsible for voting
72 again.
73
74 To see all your outstanding votes : $unvoted
75
76 Kind regards,
77 the voting system
78 BODY;
79 $db->notify("Re: $tag - $title - modified",$body,$tag);
80 } else {
81 ?>
82 <b>The motion has NOT been proposed!</b><br/>
83 <a href="motions.php">Back to motions</a><br/>
84 <i><?php echo join("<br/>\n",$stmt->errorInfo()); ?></i><br/>
85 <br/>
86 <br/>
87 <?php
88 }
89 } else {
90 $stmt = $db->getStatement("create decision");
91 $stmt->bindParam(":proponent",$_POST['proponent']);
92 $stmt->bindParam(":title",$_POST['title']);
93 $stmt->bindParam(":content",$_POST['content']);
94 $stmt->bindParam(":quorum",$_POST['quorum']);
95 $stmt->bindParam(":majority",$_POST['majority']);
96 $stmt->bindParam(":due",$_POST['due']);
97 if ($stmt->execute()) {
98 $db->getStatement("post create")->execute();
99 ?>
100 <b>The motion has been proposed!</b><br/>
101 <a href="motions.php">Back to motions</a><br/>
102 <br/>
103 <br/>
104 <?php
105 $decision = $db->getStatement("get new decision")->execute()?$db->getStatement("get new decision")->fetch():array();
106 $name = $user['name'];
107 $tag = $decision['tag'];
108 $title = $decision['title'];
109 $content =$decision['content'];
110 $due = $decision['due']." UTC";
111 $quorum = $decision['quorum'];
112 $majority = $decision['majority'];
113 $baseurl = "https://".$_SERVER['HTTP_HOST'].":".$_SERVER['SERVER_PORT'].preg_replace('/motion\.php/','',$_SERVER['REQUEST_URI']);
114 $voteurl = $baseurl."vote.php?motion=".$decision['id'];
115 $unvoted = $baseurl."motions.php?unvoted=1";
116 $body = <<<BODY
117 Dear Board,
118
119 $name has made the following motion:
120
121 $title
122 $content
123
124 To pass a minimum of $quorum votes and a $majority% acceptance will be required.
125 Voting will close $due.
126
127 To vote please choose:
128
129 Aye: $voteurl&vote=1
130 Naye: $voteurl&vote=-1
131 Abstain: $voteurl&vote=0
132
133 To see all your outstanding votes : $unvoted
134
135 Kind regards,
136 the voting system
137 BODY;
138 $db->notify("$tag - $title",$body,$tag,TRUE);
139 } else {
140 ?>
141 <b>The motion has NOT been proposed!</b><br/>
142 <a href="motions.php">Back to motions</a><br/>
143 <i><?php echo join("<br/>\n",$stmt->errorInfo()); ?></i><br/>
144 <br/>
145 <br/>
146 <?php
147 }
148 }
149
150 }
151 if (is_numeric($_REQUEST['motion'])) {
152 $stmt = $db->getStatement("get decision");
153 if ($stmt->execute(array($_REQUEST['motion']))) {
154 $motion = $stmt->fetch();
155 }
156 if (!is_numeric($motion['id'])) {
157 $motion = array();
158 foreach (array("title","content","quorum","majority") as $column) {
159 $motion[$column] = "";
160 }
161 $motion["proponent"] = $user['id'];
162 $motion["proposer"] = $user['name'];
163 }
164 } else {
165 $motion = array();
166 foreach (array("title","content","quorum","majority") as $column) {
167 $motion[$column] = "";
168 }
169 $motion["proponent"] = $user['id'];
170 $motion["proposer"] = $user['name'];
171 }
172 ?>
173 <form <?php if (is_numeric($_REQUEST['motion'])) { echo(" action=\"?\""); } ?> method="POST">
174 <input type="hidden" name="action" value="store" />
175 <?php
176 if (is_numeric($_REQUEST['motion'])) {
177 ?><input type="hidden" name="motion" value="<?php echo($_REQUEST["motion"]); ?>" /><?php
178 }
179 ?>
180 <table>
181 <tr><td>ID:</td><td><?php echo htmlentities($motion['tag']); ?></td></tr>
182 <tr><td>Proponent:</td><td><?php echo htmlentities($motion['proposer']); ?><input type="hidden" name="proponent" value="<?php echo htmlentities($user['id']); ?>"></td></tr>
183 <tr><td>Proposed Date/Time:</td><td><?php echo htmlentities($motion['proposed'] ? $motion['proposed']." UTC" : '(auto filled to current date/time)'); ?></td></tr>
184 <tr><td>Title:</td><td><input name="title" value="<?php echo htmlentities($motion['title'])?>"></td></tr>
185 <tr><td>Text:</td><td><textarea name="content"><?php echo htmlspecialchars($motion['content'])?></textarea></td></tr>
186 <tr><td>Quorum:</td><td><select name="quorum">
187 <option value="<?php echo(ceil($stats["voters"])); ?>" <?php if($motion['quorum'] == $stats["voters"]) { echo(" selected=\"selected\""); } ?>>100% Votes (<?php echo($stats["voters"]); ?>)</option>
188 <option value="<?php echo(ceil($stats["voters"] / 2)); ?>" <?php if($motion['quorum'] == ceil($stats["voters"] / 2)) { echo(" selected=\"selected\""); } ?>>50% Votes (<?php echo(ceil($stats["voters"] / 2)); ?>)</option>
189 <option value="2" <?php if($motion['quorum'] == 2) { echo(" selected=\"selected\""); } ?>>2 Votes</option>
190 <option value="1" <?php if($motion['quorum'] == 1) { echo(" selected=\"selected\""); } ?>>1 Vote</option>
191 </select></td></tr>
192 <tr><td>Majority:</td><td><select name="majority">
193 <option value="50" <?php if($motion['majority'] == 50) { echo(" selected=\"selected\""); } ?>>50%</option>
194 <option value="67" <?php if($motion['majority'] == 67) { echo(" selected=\"selected\""); } ?>>67%</option>
195 <option value="75" <?php if($motion['majority'] == 75) { echo(" selected=\"selected\""); } ?>>75%</option>
196 <option value="100" <?php if($motion['majority'] == 100) { echo(" selected=\"selected\""); } ?>>100%</option>
197 </td></tr>
198 <tr><td rowspan="2">Due:</td><td><?php echo($motion['due'] ? $motion['due'].' UTC' : '(autofilled from option below)')?></td></tr>
199 <tr><td><select name="due">
200 <option value="+3 days">In 3 Days</option>
201 <option value="+7 days">In 1 Week</option>
202 <option value="+14 days">In 2 Weeks</option>
203 </select></td></tr>
204 <tr><td>&nbsp;</td><td><input type="submit" value="Propose" /></td></tr>
205 </table>
206 </form>
207 <br/>
208 <a href="motions.php">Back to motions</a>
209 </body>
210 </html>