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