fix schema documentation
[cacert-boardvoting.git] / motions.php
index 7784e23..a087c9e 100644 (file)
@@ -3,6 +3,40 @@
        $db = new DB();
        $db->closeVotes();
        $page = is_numeric($_REQUEST['page'])?$_REQUEST['page']:1;
+       $user = $db->auth();
+
+       if ($_REQUEST['withdrawl'] && $_REQUEST['confirm'] && $_REQUEST['id']) {
+               if (!$user) {
+                       header("HTTP/1.0 302 Redirect");
+                       header("Location: denied.php");
+                       exit();
+               }
+               $stmt = $db->getStatement("get decision");
+               $stmt->bindParam(":decision",$_REQUEST['id']);
+               if ($stmt->execute() && ($decision=$stmt->fetch())) {
+                       $name = $user['name'];
+                       $tag = $decision['tag'];
+                       $title = $decision['title'];
+                       $content = $decision['content'];
+                       $body = <<<BODY
+Dear Board,
+
+$name has withdrawn the motion $tag that was as follows:
+
+$title
+$content
+
+Kind regards,
+the voting system
+BODY;
+                       $db->notify("Re: $tag - $title - withdrawn",$body,$tag);
+               }
+               $stmt = $db->getStatement("close decision");
+               $status = -2;
+               $stmt->bindParam(":status",$status);
+               $stmt->bindParam(":decision",$_REQUEST['id']);
+               $stmt->execute();
+       }
 ?>
 <html>
        <head>
@@ -11,6 +45,9 @@
                <link rel="stylesheet" type="text/css" href="styles.css" />
        </head>
        <body>
+       <?php
+               if ($user) echo '<a href="?unvoted=1">Show my outstanding votes</a><br/>'; 
+       ?>
                <table class="list">
                        <tr>
                                <th>Status</th>
                                <th>Actions</th>
                        </tr>
                        <?php
-                               if ($_REQUEST['withdrawl'] && $_REQUEST['confirm'] && $_REQUEST['id']) {
-                                       $stmt = $db->getStatement("close decision");
-                                       $status = -2;
-                                       $stmt->bindParam(":status",$status);
-                                       $stmt->bindParam(":decision",$_REQUEST['id']);
-                                       $stmt->execute();
-                               }
                                if ($_REQUEST['motion']) {
                                        $stmt = $db->getStatement("list decision");
                                        $stmt->execute(array($_REQUEST['motion']));
                                } else {
-                                       $stmt = $db->getStatement("list decisions");
-                                       $stmt->execute(array($page));
+                                       if ($user && $_REQUEST['unvoted']) {
+                                               $stmt = $db->getStatement("list my unvoted decisions");
+                                               $stmt->bindParam(":id",$user['id']);
+                                       } else {
+                                               $stmt = $db->getStatement("list decisions");
+                                       }
+                                       $stmt->bindParam(":page",$page);
+                                       $stmt->execute();
                                }
                                $items = 0;
                                $id = -1;
                                                ?>
                                                </td>
                                                <td>
-                                               <i><a href="motions.php?id=<?php echo $row['tag'].'">'.$row['tag']; ?></a></i><br/>
-                                               <b><?php echo htmlentities($row['title']); ?></b><br/>
-                                               <pre><?php echo htmlspecialchars($row['content']); ?></pre>
+                                               <i><a href="motions.php?motion=<?php echo $row['tag'].'">'.$row['tag']; ?></a></i><br/>
+                                               <b><?php echo htmlspecialchars($row['title']); ?></b><br/>
+                                               <pre><?php echo wordwrap(htmlspecialchars($row['content'])); ?></pre>
                                                <br/>
                                                <i>Due: <?php echo($row['due']); ?> UTC</i><br/>
                                                <i>Proposed: <?php echo($row['proposer']); ?> (<?php echo($row['proposed']); ?> UTC)</i><br/>
-                                               <i>Required Votes: <?php echo($row['quorum']); ?></i><br/>
-                                               <i>Majority: <?php echo($row['majority']); ?>%</i><br/>
+                                               <i>Vote type: <?php echo(!$row['votetype']?'motion':'veto'); ?></i><br/>
                                                <i>Aye|Naye|Abstain: <?php echo($row['ayes']); ?>|<?php echo($row['nayes']); ?>|<?php echo($row['abstains']); ?></i><br/>
                                        <?php
                                                if ($row['status'] ==0 || $_REQUEST['showvotes']) {
                                                        $vstmt->execute(array($row['id']));
                                                        echo "<i>Votes:</i><br/>";
                                                        while ($vrow = $vstmt->fetch()) {
-                                                               echo "<i>".$vrow['name']." ".$state[$vrow['vote']+1]."</i><br/>";
+                                                               echo "<i>".$vrow['name'].": ".$state[$vrow['vote']+1]."</i><br/>";
                                                        }
                                                } else {
                                                        echo '<i><a href="motions.php?motion='.$row['tag'].'&showvotes=1">Show Votes</a></i><br/>';
                                                </td>
                                        <td class="actions">
                                                <?php
-                                                       if ($row['status'] == 0) {
+                                                       if ($row['status'] == 0 && $user ) {
                                                                ?>
                                                                <ul>
                                                                        <li><a href="vote.php?motion=<?php echo($row['id']); ?>&amp;vote=1">Aye</a></li>
                                        <?php if ($items>9) { ?><a href="?page=<?php echo($page+1); ?>">&gt;</a><?php } else { ?>&nbsp;<?php } ?>
                                </td>
                                <td class="actions">
-                                       <ul>
-                                               <li><a href="motion.php">New Motion</a></li>
-                                       </ul>
+                                       <?php if ($user) echo('<ul><li><a href="motion.php">New Motion</a></li></ul>'); ?>
                                </td>
                        </tr>
                        <?php