fix Email address certificate lookup
[cacert-boardvoting.git] / database.php
index a4063f8..0948949 100644 (file)
@@ -20,9 +20,8 @@
                        $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 COUNT(*) AS voters FROM voters WHERE enabled=1;");
                        $this->statement['list votes'] = $this->dbh->prepare("SELECT voters.name AS name, votes.vote AS vote FROM voters,votes WHERE voters.id=votes.voter AND votes.decision=:id;");
-                       $this->statement['create decision'] = $this->dbh->prepare("INSERT INTO decisions (proposed, proponent, title, content, votetype, status, due, modified) VALUES (datetime('now','utc'), :proponent, :title, :content, :votetype, 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, votetype=:votetype, status=0, due=datetime('now','utc',:due), modified=datetime('now','utc') WHERE id=:id;");
+                       $this->statement['create decision'] = $this->dbh->prepare("INSERT INTO decisions (proposed, proponent, title, content, votetype, status, due, modified,tag) VALUES (datetime('now','utc'), :proponent, :title, :content, :votetype, 0, datetime(date('now','utc'),'utc', :due,'+1 day','-1 second'), datetime('now','utc'),'m' || strftime('%Y%m%d','now') || '.' || (select count(*)+1 as num from decisions where proposed between date('now') and date('now','1 day')));");
+                       $this->statement['update decision'] = $this->dbh->prepare("UPDATE decisions SET proposed=datetime('now','utc'), proponent=:proponent, title=:title, content=:content, votetype=:votetype, status=0, due=datetime(date('now','utc'),'utc', :due,'+1 day','-1 second'), modified=datetime('now','utc') WHERE id=:id;");
                        $this->statement['close decision'] = $this->dbh->prepare("UPDATE decisions SET status=:status, modified=datetime('now','utc') WHERE id=:decision");
                        ini_set('mbstring.internal_encoding', 'UTF-8');
                }
@@ -118,13 +117,13 @@ BODY;
                        $stmt->execute(array($_SERVER['REMOTE_USER']));
                        $user = $stmt->fetch();
                        if ($user) return $user;
-                       if ($_SERVER['SSL_CLIENT_S_DN_EMAIL']) {
-                               $stmt->execute(array($_SERVER['SSL_CLIENT_S_DN_EMAIL']));
+                       if ($_SERVER['SSL_CLIENT_S_DN_Email']) {
+                               $stmt->execute(array($_SERVER['SSL_CLIENT_S_DN_Email']));
                                $user = $stmt->fetch();
                                if ($user) return $user;
                        }
                        $d=0;
-                       while ($email=$_SERVER["SSL_CLIENT_S_DN_EMAIL_$d"]) {
+                       while ($email=$_SERVER["SSL_CLIENT_S_DN_Email_$d"]) {
                                $stmt->execute(array($email));
                                $user = $stmt->fetch();
                                if ($user) return $user;