\n\t\t
\n\t\t\t
" .
- strtolower($settings['type']) . "
\n\t\t\t
\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t
\n\t
\n\t\t
" .
- $db->getPhrase(-1) . "
\n\t\t
\n\t
\n\n";
-
-}
-
-die ($output);
\ No newline at end of file
+?>
+
+
+
+
+
getPhrase(-1)->getPhrase()); ?>
+
+
+
+
+cur = $db->getColor();
- }
-
- function rgbIntArray(){
- return $this->cur;
- }
-
- function rgbHexArray() {
- return array(
- dechex($this->cur[0]),
- dechex($this->cur[1]),
- dechex($this->cur[2])
- );
- }
-
- function rgbCSS() {
- $t = $this->cur;
- return "rgb(" . $this->cur[0] . "," . $this->cur[1] . "," .
- $this->cur[2] . ")";
- }
-
- function html() {
- $r = "#";
- if ($this->cur[0] < 16)
- $r .= "0";
- $r .= dechex($this->cur[0]);
- if ($this->cur[1] < 16)
- $r .= "0";
- $r .= dechex($this->cur[1]);
- if ($this->cur[2] < 16)
- $r .= "0";
- $r .= dechex($this->cur[2]);
- return $r;
- }
-
- function newColor(){
- $this->cur = $dtb->getColor();
- }
-}
\ No newline at end of file
diff --git a/lib/db.php b/lib/db.php
deleted file mode 100755
index e568c15..0000000
--- a/lib/db.php
+++ /dev/null
@@ -1,42 +0,0 @@
-= FLOOR(RAND()*MAX(id)) LIMIT 1
-class Database implements ReadableDatabase, WritableDatabase {
-
-}
\ No newline at end of file
diff --git a/lib/db_php.php b/lib/db_php.php
deleted file mode 100755
index 16da5a2..0000000
--- a/lib/db_php.php
+++ /dev/null
@@ -1,42 +0,0 @@
-cont=array(
- 0=>'This software is distributed under a BSD license.',
- 1=>'This software is still under development.',
- 2=>'This software is open source.',
- 3=>'This software is awesomesauce.',
- 4=>'This software can be downloaded from github.',
- );
- $this->colo = array(
- array(0,128,255), //blue
- array(255,0,128), //magenta
- array(1,223,58), //green
- array(255,191,0), //oragnge-yellow
- );
- $this->sets = $settings;
- }
-
- function getPhrase($number=-1) {
- $tc = count($this->cont) - 1;
- if ($number > -1 && $number <= $tc) {
- return $this->cont[$number];
- }
- return $this->cont[rand(0,$tc)];
- }
-
- function getColor() {
- return $this->colo[rand(0,count($this->colo)-1)];
- }
-
- function canWrite() {
- return self::$wri;
- }
-
- function ready() {
- return (isset($this->cont) && isset($this->colo));
- }
-}
diff --git a/lib/db_sqlite.php b/lib/db_sqlite.php
deleted file mode 100755
index 7c69455..0000000
--- a/lib/db_sqlite.php
+++ /dev/null
@@ -1,5 +0,0 @@
-color = $color;
+ $this->id = $id;
+ }
+
+ function rgbIntArray(){
+ return $this->color;
+ }
+
+ function rgbHexArray() {
+ return array(dechex($this->color[0]), dechex($this->color[1]), dechex($this->color[2]));
+ }
+
+ function rgbCSS() {
+ return "rgb(" . $this->color[0] . "," . $this->color[1] . "," .
+ $this->color[2] . ")";
+ }
+
+ function html() {
+ $r = "#";
+ if ($this->color[0] < 16)
+ $r .= "0";
+ $r .= dechex($this->color[0]);
+ if ($this->color[1] < 16)
+ $r .= "0";
+ $r .= dechex($this->color[1]);
+ if ($this->color[2] < 16)
+ $r .= "0";
+ $r .= dechex($this->color[2]);
+ return $r;
+ }
+}
+class Phrase {
+ private $phrase = false, $id = false, $error = false;
+
+ function __construct($id, $phrase, $error=false) {
+ if ($error !== false) {
+ if ($error === true) {
+ $this->error = 'Generic';
+ } else {
+ $this->error = $error;
+ }
+ }
+ $this->id = $id;
+ $this->phrase = $phrase;
+ }
+
+ public function getError() {
+ return $this->error;
+ }
+
+ public function getID() {
+ return $this->id;
+ }
+
+ public function getPhrase() {
+ return $this->phrase;
+ }
+}
+interface ReadableDatabase {
+ /**
+ * Should connect to the database and get ready for queries.
+ */
+ function __construct();
+
+ /**
+ * Function should return a random color.
+ */
+ public function randomColor();
+
+ /**
+ * Function should return the specified or a random phrase.
+ */
+ public function getPhrase($id=-1);
+
+ /**
+ *
+ */
+ public function randomPhraseID();
+
+ /**
+ * Returns true if the database can be read from (and write if it supports it).
+ */
+ public function ready();
+}
+
+interface WritableDatabase {
+ /**
+ * Function stores a submission into the submitted table.
+ * It is up to the implementing class
+ */
+ public function storeSubmission($submission, $clientIP);
+
+ /**
+ * Function moves a submission into the approved table.
+ */
+ public function approveSubmission($id);
+
+ /**
+ * Function drops a submission from the database table.
+ */
+ public function removeSubmission($id);
+
+ /**
+ * Function drops a phrase from the database.
+ */
+ public function removePhrase($id);
+
+ /**
+ * Function adds a color to the proper table
+ */
+ public function addColor($color);
+
+ /**
+ * Deletes the color with $id from the proper table
+ */
+ public function removeColor($id);
+}
\ No newline at end of file
diff --git a/lib/ess-db_pdo_mysql.php b/lib/ess-db_pdo_mysql.php
new file mode 100755
index 0000000..d1b373d
--- /dev/null
+++ b/lib/ess-db_pdo_mysql.php
@@ -0,0 +1,76 @@
+conn = new PDO("mysql:host=" . ESS_DB_HOST . "dbname=" . ESS_DB_DATABASE . ";charset=utf8", ESS_DB_USER, ESS_DB_PASS);
+ $this->ready = true;
+ } catch (PDOException $e) {
+ }
+ }
+
+ function randomColor() {
+ try{
+ if ($this->stm2 === null) {
+ $this->stm2 = $this->conn->prepare("SELECT * FROM " . ESS_DB_TBL_COLORS . " ORDER BY RAND() LIMIT 1");
+ }
+ $ta = $this->stm2->fetch(PDO::FETCH_ASSOC);
+ if ($ta !== false) {
+ return $ta['id'];
+ }
+ } catch (PDOException $e) {
+ }
+ return false;
+ }
+
+ function getPhrase($id=-1) {
+ try{
+ if ($id >= 0) {
+ try{
+ if ($this->stm1 === null) {
+ $this->stm1 = $this->conn->prepare("SELECT * FROM " . ESS_DB_TBL_PHRASES . " WHERE id = ? LIMIT 1");
+ }
+ $this->stm1->execute(array($id));
+ $ta = $this->stm1->fetch(PDO::FETCH_ASSOC);
+ if ($ta !== false) {
+ return new Phrase($ta['id'], $ta['phrase']);
+ }
+ } catch (PDOException $e) {
+ }
+ }
+ if ($this->stm3 === null) {
+ $this->stm3 = $this->conn->prepare("SELECT * FROM " . ESS_DB_TBL_PHRASES . " ORDER BY RAND() LIMIT 1");
+ }
+ $this->stm3->execute();
+ $ta = $this->stm3->fetch(PDO::FETCH_ASSOC);
+ if ($ta !== false) {
+ return new Phrase($ta['id'], $ta['phrase']);
+ }
+ } catch (PDOException $e) {
+ }
+ return false;
+ }
+
+ function randomPhraseID() {
+ try{
+ if ($this->stm3 === null) {
+ $this->stm3 = $this->conn->prepare("SELECT * FROM " . ESS_DB_TBL_PHRASES . " ORDER BY RAND() LIMIT 1");
+ }
+ $this->stm3->execute();
+ $ta = $this->stm3->fetch(PDO::FETCH_ASSOC);
+ if ($ta !== false) {
+ return $ta['id'];
+ }
+ } catch (PDOException $e) {
+ }
+ return false;
+ }
+
+ function ready() {
+ return ($this->conn->ready && $this->PDO !== false && $this->PDO !== null);
+ }
+}
diff --git a/lib/ess-db_php.php b/lib/ess-db_php.php
new file mode 100755
index 0000000..86b0961
--- /dev/null
+++ b/lib/ess-db_php.php
@@ -0,0 +1,45 @@
+cont=array(
+ 0=>'This software is distributed under a BSD license.',
+ 1=>'This software is still under development.',
+ 2=>'This software is awesomesauce.',
+ 3=>'This software can be downloaded from