diff --git a/database.php b/database.php index 07f3318..a522bd8 100644 --- a/database.php +++ b/database.php @@ -1,6 +1,7 @@ dbh = new PDO("sqlite:".dirname(__FILE__)."/database.sqlite"); $this->statement = array(); @@ -13,7 +14,7 @@ $this->statement['get voters'] = $this->dbh->prepare("SELECT voters.id, voters.name FROM voters WHERE voters.enabled=1 ORDER BY name ASC;"); $this->statement['del vote'] = $this->dbh->prepare("DELETE FROM votes WHERE decision=:decision AND voter=:voter;"); $this->statement['do vote'] = $this->dbh->prepare("INSERT INTO votes (decision, voter, vote, voted, notes) VALUES (:decision, :voter, :vote, datetime('now','utc'), :notes);"); - $this->statement['stats'] = $this->dbh->prepare("SELECT (SELECT COUNT(*) FROM voters WHERE enabled=1) AS voters;"); + $this->statement['stats'] = $this->dbh->prepare("SELECT COUNT(*) AS voters FROM voters WHERE enabled=1;"); $this->statement['create decision'] = $this->dbh->prepare("INSERT INTO decisions (proposed, proponent, title, content, quorum, majority, status, due, modified) VALUES (datetime('now','utc'), :proponent, :title, :content, :quorum, :majority, 0, datetime('now','utc', :due), datetime('now','utc'));"); $this->statement['post create'] = $this->dbh->prepare(" UPDATE decisions SET tag='m' || strftime('%Y%m%d','now') || '.' || id WHERE id=last_insert_rowid();"); $this->statement['update decision'] = $this->dbh->prepare("UPDATE decisions SET proposed=datetime('now','utc'), proponent=:proponent, title=:title, content=:content, quorum=:quorum, majority=:majority, status=0, due=datetime('now','utc',:due), modified=datetime('now','utc') WHERE id=:id;"); @@ -50,7 +51,9 @@ $ayes = $decision['ayes']; $nayes = $decision['nayes']; $abstains = $decision['abstains']; - $percent = $decision['ayes'] * 100 / $decision['ayes']+$decision['nayes']; + $totalvotes = $decision['ayes']+$decision['nayes']; + if ($totalvotes <= 0) $percent = 0; + else $percent = $decision['ayes'] * 100 / $totalvotes; $body = <<
"); + $this->notify("Re: ".$decision['tag']." - ".$decision['title'],$body); } } } + function notify($subject,$body) + { + mail($this->board,$subject,$body,"From: Voting System