From 4ce4fa2e05b3a1a0dd56996ef5b540196c96760a Mon Sep 17 00:00:00 2001 From: "community.cacert.org" Date: Wed, 27 May 2009 05:39:41 +0000 Subject: [PATCH] add empty SQL structure. Add links to single entities git-svn-id: http://svn.cacert.cl/Software/Voting/vote@41 d4452222-2f33-11de-9270-010000000000 --- database.php | 6 ++++-- database.sql | 4 ++++ motions.php | 17 ++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 database.sql diff --git a/database.php b/database.php index 33a8130..3bba8c3 100644 --- a/database.php +++ b/database.php @@ -1,11 +1,13 @@ 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, 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 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 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;"); $this->statement['get new 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=last_insert_rowid();"); diff --git a/database.sql b/database.sql new file mode 100644 index 0000000..bf5b801 --- /dev/null +++ b/database.sql @@ -0,0 +1,4 @@ +CREATE TABLE decisions (id INTEGER PRIMARY KEY, proposed DATETIME, proponent INTEGER, title VARCHAR(255), content TEXT, quorum INTEGER, majority INTEGER, status INTEGER, due DATETIME, modified DATETIME, tag varchar(255)); +CREATE TABLE emails (voter INT4, address VARCHAR(255)); +CREATE TABLE voters (id INTEGER PRIMARY KEY, name VARCHAR(255), enabled INTEGER default 0); +CREATE TABLE votes (decision INT4, voter INT4, vote INT4, voted DATETIME, notes text default ''); diff --git a/motions.php b/motions.php index bbf1825..a4df212 100644 --- a/motions.php +++ b/motions.php @@ -18,8 +18,13 @@ Actions getStatement("list decisions"); - $stmt->execute(array($page)); + if ($_REQUEST['id']) { + $stmt = $db->getStatement("list decision"); + $stmt->execute(array($_REQUEST['id'])); + } else { + $stmt = $db->getStatement("list decisions"); + $stmt->execute(array($page)); + } $items = 0; while ($row = $stmt->fetch()) { $items++; @@ -34,7 +39,7 @@ ?> -
+ '.$row['tag']; ?>


@@ -52,10 +57,12 @@ while ($vrow = $vstmt->fetch()) { echo "".$vrow['name']." ".$state[$vrow['vote']+1]."
"; } + } else { + echo 'Show Votes
'; } ?> - + +