add show outstanding votes option for board members
authorcommunity.cacert.org <community.cacert.org@d4452222-2f33-11de-9270-010000000000>
Fri, 29 May 2009 08:06:52 +0000 (08:06 +0000)
committercommunity.cacert.org <community.cacert.org@d4452222-2f33-11de-9270-010000000000>
Fri, 29 May 2009 08:06:52 +0000 (08:06 +0000)
git-svn-id: http://svn.cacert.cl/Software/Voting/vote@47 d4452222-2f33-11de-9270-010000000000

database.php
motion.php
motions.php

index ec501e9..a47b2b3 100644 (file)
@@ -7,6 +7,7 @@
                        $this->dbh = new PDO("sqlite:".dirname(__FILE__)."/database.sqlite");
                        $this->statement = array();
                        $this->statement['list decisions'] = $this->dbh->prepare("SELECT decisions.id AS id, decisions.tag AS tag, voters.name AS proposer, decisions.proposed, decisions.title, decisions.content, decisions.quorum, decisions.majority, decisions.status, decisions.due, decisions.modified, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=1) AS ayes, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=-1) AS nayes, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=0) AS abstains FROM decisions, voters WHERE decisions.proponent=voters.id ORDER BY proposed DESC LIMIT 10 OFFSET 10 * (:page - 1);");
+                       $this->statement['list my unvoted decisions'] = $this->dbh->prepare("SELECT  * FROM (SELECT decisions.id AS id, decisions.tag AS tag, voters.name AS proposer,decisions.proposed AS proposed, decisions.title AS title, decisions.content AS content, decisions.quorum AS quorum, decisions.majority AS majority, decisions.status AS status, decisions.due AS due, decisions.modified AS modified,(SELECT COUNT(*) AS ayes FROM votes WHERE decision=decisions.id AND vote=1), (SELECT COUNT(*) AS nayes FROM votes WHERE decision=decisions.id AND vote=-1), (SELECT COUNT(*) AS abstains FROM votes WHERE decision=decisions.id AND vote=0) FROM decisions, voters WHERE decisions.proponent=voters.id AND decisions.status=0) WHERE NOT EXISTS (SELECT vote FROM votes WHERE votes.decision=id AND votes.voter=:id) ORDER BY proposed DESC LIMIT 10 OFFSET 10 * (:page - 1);");
                        $this->statement['list decision'] = $this->dbh->prepare("SELECT decisions.id AS id, decisions.tag AS tag, voters.name AS proposer, decisions.proposed, decisions.title, decisions.content, decisions.quorum, decisions.majority, decisions.status, decisions.due, decisions.modified, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=1) AS ayes, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=-1) AS nayes, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=0) AS abstains FROM decisions, voters WHERE decisions.proponent=voters.id AND decisions.tag=:id ORDER BY proposed DESC;");
                        $this->statement['closed decisions'] = $this->dbh->prepare("SELECT decisions.id, decisions.tag, voters.name AS proposer, decisions.proposed, decisions.title, decisions.content, decisions.quorum, decisions.majority, decisions.status, decisions.due, decisions.modified, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=1) AS ayes, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=-1) AS nayes, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=0) AS abstains FROM decisions, voters WHERE decisions.proponent=voters.id AND decisions.status=0 AND datetime('now','utc') > datetime(due);");
                        $this->statement['get decision'] = $this->dbh->prepare("SELECT decisions.id, decisions.tag, decisions.proponent, voters.name AS proposer, decisions.proposed, decisions.title, decisions.content, decisions.quorum, decisions.majority, decisions.status, decisions.due, decisions.modified, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=1) AS ayes, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=-1) AS nayes, (SELECT COUNT(*) FROM votes WHERE decision=decisions.id AND vote=0) AS abstains FROM decisions, voters WHERE decisions.proponent=voters.id AND decisions.id=:decision;");
index f2accea..96412ce 100644 (file)
@@ -47,7 +47,9 @@
                                        $due = $decision['due']." UTC";
                                        $quorum = $decision['quorum'];
                                        $majority = $decision['majority'];
-                                       $voteurl = "https://".$_SERVER['HTTP_HOST'].":".$_SERVER['SERVER_PORT'].preg_replace('/motion\.php/','vote.php',$_SERVER['REQUEST_URI'])."?motion=".$decision['id'];
+                                       $baseurl = "https://".$_SERVER['HTTP_HOST'].":".$_SERVER['SERVER_PORT'].preg_replace('/motion\.php/','',$_SERVER['REQUEST_URI']);
+                                       $voteurl = $baseurl."vote.php?motion=".$decision['id'];
+                                       $unvoted = $baseurl."motions.php?unvoted=1";
                                        $body = <<<BODY
 Dear Board,
 
@@ -69,6 +71,8 @@ Please be aware, that if you have voted already your vote is still registered an
 If this modification has an impact on how you wish to vote, you are responsible for voting
 again.
 
+To see all your outstanding votes : $unvoted
+
 Kind regards,
 the voting system
 BODY;
@@ -106,7 +110,9 @@ BODY;
                                        $due = $decision['due']." UTC";
                                        $quorum = $decision['quorum'];
                                        $majority = $decision['majority'];
-                                       $voteurl = "https://".$_SERVER['HTTP_HOST'].":".$_SERVER['SERVER_PORT'].preg_replace('/motion\.php/','vote.php',$_SERVER['REQUEST_URI'])."?motion=".$decision['id'];
+                                       $baseurl = "https://".$_SERVER['HTTP_HOST'].":".$_SERVER['SERVER_PORT'].preg_replace('/motion\.php/','',$_SERVER['REQUEST_URI']);
+                                       $voteurl = $baseurl."vote.php?motion=".$decision['id'];
+                                       $unvoted = $baseurl."motions.php?unvoted=1";
                                        $body = <<<BODY
 Dear Board,
 
@@ -124,6 +130,8 @@ Aye: $voteurl&vote=1
 Naye: $voteurl&vote=-1
 Abstain: $voteurl&vote=0
 
+To see all your outstanding votes : $unvoted
+
 Kind regards,
 the voting system
 BODY;
index 2f56af4..f4ebdac 100644 (file)
@@ -3,9 +3,10 @@
        $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 = $db->auth())) {
+               if (!$user) {
                        header("HTTP/1.0 302 Redirect");
                        header("Location: denied.php");
                        exit();
@@ -44,6 +45,9 @@ BODY;
                <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>
@@ -55,8 +59,14 @@ BODY;
                                        $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;