voting types now all implemented. majority and quorum removed from database
[cacert-boardvoting.git] / motions.php
1 <?php
2 require_once("database.php");
3 $db = new DB();
4 $db->closeVotes();
5 $page = is_numeric($_REQUEST['page'])?$_REQUEST['page']:1;
6 $user = $db->auth();
7
8 if ($_REQUEST['withdrawl'] && $_REQUEST['confirm'] && $_REQUEST['id']) {
9 if (!$user) {
10 header("HTTP/1.0 302 Redirect");
11 header("Location: denied.php");
12 exit();
13 }
14 $stmt = $db->getStatement("get decision");
15 $stmt->bindParam(":decision",$_REQUEST['id']);
16 if ($stmt->execute() && ($decision=$stmt->fetch())) {
17 $name = $user['name'];
18 $tag = $decision['tag'];
19 $title = $decision['title'];
20 $content = $decision['content'];
21 $body = <<<BODY
22 Dear Board,
23
24 $name has withdrawn the motion $tag that was as follows:
25
26 $title
27 $content
28
29 Kind regards,
30 the voting system
31 BODY;
32 $db->notify("Re: $tag - $title - withdrawn",$body,$tag);
33 }
34 $stmt = $db->getStatement("close decision");
35 $status = -2;
36 $stmt->bindParam(":status",$status);
37 $stmt->bindParam(":decision",$_REQUEST['id']);
38 $stmt->execute();
39 }
40 ?>
41 <html>
42 <head>
43 <title>CAcert Board Decisions</title>
44 <meta http-equiv="Content-Type" content="text/html; charset='UTF-8'" />
45 <link rel="stylesheet" type="text/css" href="styles.css" />
46 </head>
47 <body>
48 <?php
49 if ($user) echo '<a href="?unvoted=1">Show my outstanding votes</a><br/>';
50 ?>
51 <table class="list">
52 <tr>
53 <th>Status</th>
54 <th>Motion</th>
55 <th>Actions</th>
56 </tr>
57 <?php
58 if ($_REQUEST['motion']) {
59 $stmt = $db->getStatement("list decision");
60 $stmt->execute(array($_REQUEST['motion']));
61 } else {
62 if ($user && $_REQUEST['unvoted']) {
63 $stmt = $db->getStatement("list my unvoted decisions");
64 $stmt->bindParam(":id",$user['id']);
65 } else {
66 $stmt = $db->getStatement("list decisions");
67 }
68 $stmt->bindParam(":page",$page);
69 $stmt->execute();
70 }
71 $items = 0;
72 $id = -1;
73 while ($row = $stmt->fetch()) {
74 $items++;
75 $id = $row['id'];
76 ?><tr>
77 <td class="<?php switch($row['status']) { case 0: echo "pending"; break; case 1: echo "approved"; break; case -1: echo "declined"; break; case -2: echo "withdrawn"; break; }?>">
78 <?php
79 switch($row['status']) {
80 case 0: echo "Pending<br/><i>".$row['due']." UTC</i>"; break;
81 case 1: echo "Approved<br/><i>".$row['modified']." UTC</i>"; break;
82 case -1: echo "Declined<br/><i>".$row['modified']." UTC</i>"; break;
83 case -2: echo "Withdrawn<br/><i>".$row['modified']." UTC</i>"; break;
84 }
85 ?>
86 </td>
87 <td>
88 <i><a href="motions.php?motion=<?php echo $row['tag'].'">'.$row['tag']; ?></a></i><br/>
89 <b><?php echo htmlentities($row['title']); ?></b><br/>
90 <pre><?php echo htmlspecialchars($row['content']); ?></pre>
91 <br/>
92 <i>Due: <?php echo($row['due']); ?> UTC</i><br/>
93 <i>Proposed: <?php echo($row['proposer']); ?> (<?php echo($row['proposed']); ?> UTC)</i><br/>
94 <i>Vote type: <?php echo(!$row['votetype']?'motion':'veto'); ?></i><br/>
95 <i>Aye|Naye|Abstain: <?php echo($row['ayes']); ?>|<?php echo($row['nayes']); ?>|<?php echo($row['abstains']); ?></i><br/>
96 <?php
97 if ($row['status'] ==0 || $_REQUEST['showvotes']) {
98 $state = array('Naye','Abstain','Aye');
99 $vstmt = $db->getStatement("list votes");
100 $vstmt->execute(array($row['id']));
101 echo "<i>Votes:</i><br/>";
102 while ($vrow = $vstmt->fetch()) {
103 echo "<i>".$vrow['name']." ".$state[$vrow['vote']+1]."</i><br/>";
104 }
105 } else {
106 echo '<i><a href="motions.php?motion='.$row['tag'].'&showvotes=1">Show Votes</a></i><br/>';
107 }
108 ?>
109 </td>
110 <td class="actions">
111 <?php
112 if ($row['status'] == 0) {
113 ?>
114 <ul>
115 <li><a href="vote.php?motion=<?php echo($row['id']); ?>&amp;vote=1">Aye</a></li>
116 <li><a href="vote.php?motion=<?php echo($row['id']); ?>&amp;vote=0">Abstain</a></li>
117 <li><a href="vote.php?motion=<?php echo($row['id']); ?>&amp;vote=-1">Naye</a></li>
118 <li><a href="proxy.php?motion=<?php echo($row['id']); ?>">Proxy Vote</a></li>
119 <li><a href="motion.php?motion=<?php echo($row['id']); ?>">Modify</a></li>
120 <li><a href="motions.php?motion=<?php echo($row['tag']); ?>&amp;withdrawl=1">Withdrawl</a></li>
121 </ul>
122 <?php
123 } else {
124 ?>
125 &nbsp;
126 <?php
127 }
128 ?>
129 </td>
130 </tr><?php
131 }
132 ?>
133 <tr>
134 <td colspan="2" class="navigation">
135 <?php if ($page>1) { ?><a href="?page=<?php echo($page-1); ?>">&lt;</a><?php } else { ?>&nbsp;<?php } ?>
136 &nbsp;
137 <?php if ($items>9) { ?><a href="?page=<?php echo($page+1); ?>">&gt;</a><?php } else { ?>&nbsp;<?php } ?>
138 </td>
139 <td class="actions">
140 <ul>
141 <li><a href="motion.php">New Motion</a></li>
142 </ul>
143 </td>
144 </tr>
145 <?php
146 if ($_REQUEST['withdrawl']) {
147 ?>
148 <tr>
149 <td colspan="3">
150 <?php
151 if ($_REQUEST['confirm'] && $_REQUEST['id']) {
152 ?>
153 <a href="motions.php">Motion Withdrawn</a>
154 <?php
155 } else {
156 ?>
157 <form action="?withdrawl=1&amp;confirm=1&amp;id=<?php echo $id;?>" method="post">
158 <input type="submit" value="Withdrawl">
159 </form>
160 <?php
161 }
162 ?>
163 </td>
164 </tr>
165 <?php
166 }
167 ?>
168 </table>
169 </body>
170 </html>