add email threading headers
[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 $voteurl = "https://".$_SERVER['HTTP_HOST'].":".$_SERVER['SERVER_PORT'].preg_replace('/motion\.php/','vote.php',$_SERVER['REQUEST_URI'])."?motion=".$decision['id'];
51 $body = <<<BODY
52 Dear Board,
53
54 $name has modified motion $tag to the following:
55
56 $title
57 $content
58
59 To pass a minimum of $quorum votes and a $majority% acceptance will be required.
60 Voting will close $due.
61
62 To vote please choose:
63
64 Aye: $voteurl&vote=1
65 Naye: $voteurl&vote=-1
66 Abstain: $voteurl&vote=0
67
68 Please be aware, that if you have voted already your vote is still registered and valid.
69 If this modification has an impact on how you wish to vote, you are responsible for voting
70 again.
71
72 Kind regards,
73 the voting system
74 BODY;
75 $db->notify("Re: $tag - $title - modified",$body,$tag);
76 } else {
77 ?>
78 <b>The motion has NOT been proposed!</b><br/>
79 <a href="motions.php">Back to motions</a><br/>
80 <i><?php echo join("<br/>\n",$stmt->errorInfo()); ?></i><br/>
81 <br/>
82 <br/>
83 <?php
84 }
85 } else {
86 $stmt = $db->getStatement("create decision");
87 $stmt->bindParam(":proponent",$_POST['proponent']);
88 $stmt->bindParam(":title",$_POST['title']);
89 $stmt->bindParam(":content",$_POST['content']);
90 $stmt->bindParam(":quorum",$_POST['quorum']);
91 $stmt->bindParam(":majority",$_POST['majority']);
92 $stmt->bindParam(":due",$_POST['due']);
93 if ($stmt->execute()) {
94 $db->getStatement("post create")->execute();
95 ?>
96 <b>The motion has been proposed!</b><br/>
97 <a href="motions.php">Back to motions</a><br/>
98 <br/>
99 <br/>
100 <?php
101 $decision = $db->getStatement("get new decision")->execute()?$db->getStatement("get new decision")->fetch():array();
102 $name = $user['name'];
103 $tag = $decision['tag'];
104 $title = $decision['title'];
105 $content =$decision['content'];
106 $due = $decision['due']." UTC";
107 $quorum = $decision['quorum'];
108 $majority = $decision['majority'];
109 $voteurl = "https://".$_SERVER['HTTP_HOST'].":".$_SERVER['SERVER_PORT'].preg_replace('/motion\.php/','vote.php',$_SERVER['REQUEST_URI'])."?motion=".$decision['id'];
110 $body = <<<BODY
111 Dear Board,
112
113 $name has made the following motion:
114
115 $title
116 $content
117
118 To pass a minimum of $quorum votes and a $majority% acceptance will be required.
119 Voting will close $due.
120
121 To vote please choose:
122
123 Aye: $voteurl&vote=1
124 Naye: $voteurl&vote=-1
125 Abstain: $voteurl&vote=0
126
127 Kind regards,
128 the voting system
129 BODY;
130 $db->notify("$tag - $title",$body,$tag,TRUE);
131 } else {
132 ?>
133 <b>The motion has NOT been proposed!</b><br/>
134 <a href="motions.php">Back to motions</a><br/>
135 <i><?php echo join("<br/>\n",$stmt->errorInfo()); ?></i><br/>
136 <br/>
137 <br/>
138 <?php
139 }
140 }
141
142 }
143 if (is_numeric($_REQUEST['motion'])) {
144 $stmt = $db->getStatement("get decision");
145 if ($stmt->execute(array($_REQUEST['motion']))) {
146 $motion = $stmt->fetch();
147 }
148 if (!is_numeric($motion['id'])) {
149 $motion = array();
150 foreach (array("title","content","quorum","majority") as $column) {
151 $motion[$column] = "";
152 }
153 $motion["proponent"] = $user['id'];
154 $motion["proposer"] = $user['name'];
155 }
156 } else {
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 ?>
165 <form <?php if (is_numeric($_REQUEST['motion'])) { echo(" action=\"?\""); } ?> method="POST">
166 <input type="hidden" name="action" value="store" />
167 <?php
168 if (is_numeric($_REQUEST['motion'])) {
169 ?><input type="hidden" name="motion" value="<?php echo($_REQUEST["motion"]); ?>" /><?php
170 }
171 ?>
172 <table>
173 <tr><td>ID:</td><td><?php echo htmlentities($motion['tag']); ?></td></tr>
174 <tr><td>Proponent:</td><td><?php echo htmlentities($motion['proposer']); ?><input type="hidden" name="proponent" value="<?php echo htmlentities($user['id']); ?>"></td></tr>
175 <tr><td>Proposed:</td><td><?php echo htmlentities($motion['proposed']); ?> UTC</td></tr>
176 <tr><td>Title:</td><td><input name="title" value="<?php echo htmlentities($motion['title'])?>"></td></tr>
177 <tr><td>Text:</td><td><textarea name="content"><?php echo htmlspecialchars($motion['content'])?></textarea></td></tr>
178 <tr><td>Quorum:</td><td><select name="quorum">
179 <option value="<?php echo(ceil($stats["voters"])); ?>" <?php if($motion['quorum'] == $stats["voters"]) { echo(" selected=\"selected\""); } ?>>100% Votes (<?php echo($stats["voters"]); ?>)</option>
180 <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>
181 <option value="2" <?php if($motion['quorum'] == 2) { echo(" selected=\"selected\""); } ?>>2 Votes</option>
182 <option value="1" <?php if($motion['quorum'] == 1) { echo(" selected=\"selected\""); } ?>>1 Vote</option>
183 </select></td></tr>
184 <tr><td>Majority:</td><td><select name="majority">
185 <option value="50" <?php if($motion['majority'] == 50) { echo(" selected=\"selected\""); } ?>>50%</option>
186 <option value="67" <?php if($motion['majority'] == 67) { echo(" selected=\"selected\""); } ?>>67%</option>
187 <option value="75" <?php if($motion['majority'] == 75) { echo(" selected=\"selected\""); } ?>>75%</option>
188 <option value="100" <?php if($motion['majority'] == 100) { echo(" selected=\"selected\""); } ?>>100%</option>
189 </td></tr>
190 <tr><td rowspan="2">Due:</td><td><?php echo($motion['due'])?> UTC</td></tr>
191 <tr><td><select name="due">
192 <option value="+3 days">In 3 Days</option>
193 <option value="+7 days">In 1 Week</option>
194 <option value="+14 days">In 2 Weeks</option>
195 </select></td></tr>
196 <tr><td>&nbsp;</td><td><input type="submit" value="Propose" /></td></tr>
197 </table>
198 </form>
199 <br/>
200 <a href="motions.php">Back to motions</a>
201 </body>
202 </html>