summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-05-12 16:59:36 -0700
committerJesse Morgan <jesse@jesterpm.net ; true>2011-05-12 16:59:36 -0700
commitdd24e2c973a7979894971bdc38d904d2aecc7d5d (patch)
tree2f8474d22cbf29749219bd6dd543bb22b959465e
parente159ae5209a561043ceb89aa640b207df15181b7 (diff)
Well, you can see posts on the moderation panel now
-rw-r--r--design/database.sql27
-rw-r--r--htdocs/moderate/admin.css99
-rw-r--r--htdocs/moderate/changepassword.php88
-rw-r--r--htdocs/moderate/index.php50
-rw-r--r--htdocs/moderate/login.php54
-rw-r--r--htdocs/moderate/src/accounts.inc.php67
-rw-r--r--htdocs/moderate/src/footer.inc.php6
-rw-r--r--htdocs/moderate/src/header.inc.php64
-rw-r--r--htdocs/src/Cif_Database.inc.php196
-rw-r--r--htdocs/src/Cif_Database_Exception.inc.php31
-rw-r--r--htdocs/src/Post.inc.php82
-rw-r--r--htdocs/src/PostIterator.inc.php67
-rw-r--r--htdocs/src/User.inc.php74
-rw-r--r--htdocs/src/base.inc.php45
-rw-r--r--htdocs/src/config.inc.php8
15 files changed, 956 insertions, 2 deletions
diff --git a/design/database.sql b/design/database.sql
index c056c1c..8b9c13c 100644
--- a/design/database.sql
+++ b/design/database.sql
@@ -48,11 +48,34 @@ CREATE TABLE post (
secretid VARCHAR(32) NOT NULL,
source_id INTEGER UNSIGNED NOT NULL,
+ stage ENUM('verification',
+ 'moderation',
+ 'approved') NOT NULL DEFAULT 'verification',
PRIMARY KEY(id),
UNIQUE KEY(secretid)
);
+CREATE TABLE user (
+ id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
+ name VARCHAR(60) NOT NULL,
+ email VARCHAR(255) NOT NULL,
+ password VARCHAR(40) NOT NULL,
+ source_id INTEGER NOT NULL,
+ admin TINYINT(1) NOT NULL DEFAULT 0,
+
+ PRIMARY KEY(id),
+ UNIQUE KEY(email)
+);
+
+CREATE TABLE pages (
+ id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
+ url VARCHAR(60) NOT NULL,
+ content TEXT NOT NULL,
+
+ PRIMARY KEY(id),
+ UNIQUE KEY(url)
+);
-- The following creates some sample data
INSERT INTO category (name) VALUES
@@ -63,3 +86,7 @@ INSERT INTO category (name) VALUES
('Needs');
INSERT INTO source (name) VALUES ('Foursquare Church');
+
+INSERT INTO user (name, email, password, source_id, admin)
+ VALUES ('Jesse Morgan', 'jmorgan@foursquarestaff.com',
+ 'password-sha1', 1, 1);
diff --git a/htdocs/moderate/admin.css b/htdocs/moderate/admin.css
new file mode 100644
index 0000000..936c3ec
--- /dev/null
+++ b/htdocs/moderate/admin.css
@@ -0,0 +1,99 @@
+body {
+ font-family: "Lucida Grande", "Lucida Sans", "Lucida", sans-serif;
+ font-size: 0.75em;
+ line-height: 1.5em;
+
+ margin-left: 10%;
+ margin-top: 5%;
+ width: 60%;
+}
+
+h1 {
+ font-size: 4em;
+ margin-bottom: 1.25em;
+}
+
+a, a:visited {
+ color: #1070c0;
+ text-decoration: none;
+}
+
+#content {
+ width: 75%;
+ padding-left: 3em;
+
+}
+
+#nav {
+ float: right;
+}
+
+#nav ul {
+ padding-left: 1em;
+ list-style: none;
+}
+
+#search {
+ float: right;
+ margin-top: -2em;
+}
+
+#listing {
+ margin-top: 1.5em;
+}
+
+#listing .header {
+ background: #555;
+ padding: 0.75em;
+ color: white;
+ font-weight: bold;
+ font-size: 120%;
+}
+
+#listing .row0, #listing .row1 {
+ border-top: solid thin #AAA;
+ padding: 0.75em;
+}
+
+#listing .row0 {
+}
+
+#listing .row1 {
+}
+
+#listing .col0 {
+ display: inline-block;
+ width: 100px;
+ text-align: center;
+}
+
+
+.element input[type=text], .element input[type=password] {
+ width: 90%;
+ padding: .5em;
+}
+
+label {
+ font-weight: bold;
+}
+
+.element {
+ margin-bottom: 1.25em;
+}
+
+.buttons {
+ float: right;
+ margin-right: 10%;
+}
+
+div.error {
+ background: #FAA;
+ border: solid red 2px;
+ padding: 1.5em;
+ margin: 2em 0 2em 0;
+ width: 90%;
+}
+
+p {
+ margin: 0;
+}
diff --git a/htdocs/moderate/changepassword.php b/htdocs/moderate/changepassword.php
new file mode 100644
index 0000000..646af94
--- /dev/null
+++ b/htdocs/moderate/changepassword.php
@@ -0,0 +1,88 @@
+<?php
+/* $Id: changepassword.php 134 2011-03-08 23:35:57Z jessemorgan $ */
+
+require_once('../src/base.inc.php');
+
+if (!isset($_SESSION['currentUser'])) {
+ header('Location: ' . $CONFIG['siteroot'].'/admin/login.php');
+ exit();
+}
+
+require_once('src/accounts.inc.php');
+
+$form['errors'] = "";
+
+if (count($_POST) > 0) {
+ $errors = array();
+
+ if (!isset($_POST['oldpassword']) or $_POST['oldpassword'] == '') {
+ $errors[] = "Old Password is a required field.";
+ }
+
+ if (!isset($_POST['newpassword']) or $_POST['newpassword'] == '') {
+ $errors[] = "New Password is a required field.";
+ }
+
+ if (!isset($_POST['newpassword2']) or $_POST['newpassword2'] == '') {
+ $errors[] = "Confirm New Password is a required field.";
+ }
+
+ if (count($errors) == 0) {
+ if ($_POST['newpassword'] != $_POST['newpassword2']) {
+ $errors[] = "New password must match Confirm New Password";
+ }
+
+ $user = getAccount($_SESSION['currentUser']['id']);
+
+ if (sha1($_POST['oldpassword']) != $user['password']) {
+ $errors[] = "Old Password does not match your current password.";
+
+ } else {
+ // Update the password
+ updatePassword($_SESSION['currentUser']['id'], $_POST['newpassword']);
+
+ header("Location: index.php");
+ }
+ }
+
+
+ if (count($errors) > 0) {
+ $form['errors'] = "<ul><li>". implode("</li>\n<li>", $errors) ."</li></ul>";
+ }
+}
+
+require_once('src/header.inc.php');
+
+?>
+
+<h2>Change Password</h2>
+
+<?php
+ echo $form['errors'];
+?>
+
+<form method="post">
+<label>Old Password</label>
+<div class="element">
+ <input type="password" name="oldpassword" />
+</div>
+
+<label>New Password</label>
+<div class="element">
+ <input type="password" name="newpassword" />
+</div>
+
+<label>Confirm New Password</label>
+<div class="element">
+ <input type="password" name="newpassword2" />
+</div>
+
+<div class="buttons">
+ <input type="submit" value="Change Password" />
+</div>
+
+<?php
+
+require_once('src/footer.inc.php');
+
+?>
diff --git a/htdocs/moderate/index.php b/htdocs/moderate/index.php
new file mode 100644
index 0000000..454a514
--- /dev/null
+++ b/htdocs/moderate/index.php
@@ -0,0 +1,50 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once('../src/base.inc.php');
+
+if (!isset($_SESSION['currentUser'])) {
+ header('Location: ' . $CONFIG['urlroot'].'/moderate/login.php');
+ exit();
+}
+
+require_once('header.inc.php');
+
+?>
+
+<h2>Welcome</h2>
+
+<?php
+
+// List posts to be approved
+echo "<h3>Moderate Posts</h3>";
+
+$posts = new PostIterator();
+$posts->filterStage('moderation');
+$posts->query();
+
+// TODO: Also filter by source?
+
+if ($posts->valid()) {
+ foreach ($posts as $id => $post) {
+ printf("<div class=\"post\"><p><a href=\"preview/%s\">%s</a></p>"
+ . "<div class=\"options\"><a href=\"approve/%s\">Approve</a>"
+ . " <a href=\"reject/%s\">Reject</a></div></div>",
+
+ $id, $post->getName(), $id, $id);
+ }
+
+} else {
+ echo "<p>No posts awaiting approval</p>";
+}
+
+require_once('footer.inc.php');
+
+?>
diff --git a/htdocs/moderate/login.php b/htdocs/moderate/login.php
new file mode 100644
index 0000000..92cddc1
--- /dev/null
+++ b/htdocs/moderate/login.php
@@ -0,0 +1,54 @@
+<?php
+
+require_once('../src/base.inc.php');
+
+$error = "";
+
+if (isset($_GET['logout'])) {
+ unset($_SESSION['currentUser']);
+}
+
+if (isset($_POST['login_email']) and isset($_POST['login_password'])) {
+ $user = User::getByEmail(addslashes($_POST['login_email']));
+
+ if ($user and $user->authenticate($_POST['login_password'])) {
+ $_SESSION['currentUser'] = $user;
+ header('Location: index.php');
+
+ } else {
+ $error = "<div class=\"error\">Invalid Username/Password</div>";
+ }
+}
+
+require_once('header.inc.php');
+
+?>
+
+
+<h2>Login</h2>
+
+<?php echo $error; ?>
+
+<form method="post">
+
+<label>Email</label>
+<div class="element">
+ <input type="text" name="login_email" />
+</div>
+
+<label>Password</label>
+<div class="element">
+ <input type="password" name="login_password" />
+</div>
+
+<div>
+ <input type="submit" value="Login" />
+</div>
+
+</form>
+
+<?php
+
+require_once('footer.inc.php');
+
+?>
diff --git a/htdocs/moderate/src/accounts.inc.php b/htdocs/moderate/src/accounts.inc.php
new file mode 100644
index 0000000..fac6c7c
--- /dev/null
+++ b/htdocs/moderate/src/accounts.inc.php
@@ -0,0 +1,67 @@
+<?php
+/* $Id: accounts.inc.php 134 2011-03-08 23:35:57Z jessemorgan $ */
+
+function getAccount($id) {
+ $query = "SELECT * FROM jpm_users WHERE"
+ . "`id`='$id' OR `email`='$id'";
+
+ $db = getDatabase();
+
+ $results = array();
+
+ try {
+ $results = $db->fetchAssocRow($query);
+
+ } catch (Cif_Database_Exception $e) {
+ $results = false;
+ }
+
+ return $results;
+}
+
+function updatePassword($id, $password) {
+ $db = getDatabase();
+
+ $row['password'] = sha1($password);
+
+ $db->update('jpm_users', $row, "WHERE `id`='$id'");
+}
+
+function getAccounts($s) {
+ $query = "SELECT * FROM jpm_users";
+
+ if (!is_null($s)) {
+ $s = addslashes($s);
+ $query .= " WHERE name LIKE '%$s%' OR email LIKE '%$s%'";
+ }
+
+ $query .= " ORDER BY name";
+
+ $db = getDatabase();
+
+ $results = array();
+
+ try {
+ $results = $db->fetchAssocRows($query);
+
+ } catch (Cif_Database_Exception $e) {
+ $results = array();
+ }
+
+ return $results;
+}
+
+function generatePassword() {
+ $alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz123456789!@#$%*()";
+ $length = strlen($alphabet);
+
+ $password = '';
+ for ($i = 0; $i < 8; $i++) {
+ $pos = rand(0, $length - 1);
+ $password .= substr($alphabet, $pos, 1);
+ }
+
+ return $password;
+}
+
+?>
diff --git a/htdocs/moderate/src/footer.inc.php b/htdocs/moderate/src/footer.inc.php
new file mode 100644
index 0000000..96d3e78
--- /dev/null
+++ b/htdocs/moderate/src/footer.inc.php
@@ -0,0 +1,6 @@
+<?php /* $Id: footer.inc.php 134 2011-03-08 23:35:57Z jessemorgan $ */ ?>
+</div>
+
+
+</body>
+</html>
diff --git a/htdocs/moderate/src/header.inc.php b/htdocs/moderate/src/header.inc.php
new file mode 100644
index 0000000..4310009
--- /dev/null
+++ b/htdocs/moderate/src/header.inc.php
@@ -0,0 +1,64 @@
+<?php
+/* $Id: header.inc.php 151 2011-04-19 23:21:06Z jessemorgan $ */
+
+if (!isset($SESSION['currentUser']['id'])) {
+ if (isset($_POST['login_email']) and isset($_POST['login_password'])) {
+ $db = getDatabase();
+
+ $email = addslashes($_POST['login_email']);
+ $password = sha1($_POST['password']);
+
+ $query = "SELECT * FROM jpm_users WHERE `email`='$email' AND `password`='$password'";
+ $result = $db->fetchAssocRow($query);
+
+ if ($result) {
+ $SESSION['currentUser'] = $result;
+ }
+
+ }
+}
+
+?><!DOCTYPE html>
+<html>
+<head>
+ <link rel="stylesheet" type="text/css" href="<?= $CONFIG['siteroot']?>/admin/admin.css" />
+
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
+ <script>
+ $(document).ready(function() {
+ $('a.delete').click(function() {
+ return confirm('Are you sure you want to delete this?');
+
+ });
+
+ $('a.delete img').hover(function() {
+ $(this).attr('src', '<?= $CONFIG['siteroot'] ?>/admin/images/delete.png');
+ },
+ function() {
+ $(this).attr('src', '<?= $CONFIG['siteroot'] ?>/admin/images/deletegray.png');
+ });
+
+ });
+ </script>
+
+</head>
+<body>
+
+<h1><a href="<?= $CONFIG['siteroot']?>/admin/index.php">Foursquare Admin Panel</a></h1>
+<div id="nav">
+ <h2>Navigation</h2>
+ <ul>
+ <li><a href="<?= $CONFIG['siteroot']?>/admin/online-campus">Online Services</a>
+ <ul>
+ <li><a href="<?= $CONFIG['siteroot']?>/admin/online-campus/attendance">Online Attendance</a></li>
+ </ul>
+ </li>
+
+ <li><a href="<?= $CONFIG['siteroot']?>/troubleshoot.php">Troubleshooting Page</a></li>
+ <li><a href="<?= $CONFIG['siteroot']?>/admin/accounts/">Accounts</a></li>
+ <li><a href="<?= $CONFIG['siteroot']?>/admin/changepassword.php">Change Password</a></li>
+ <li><a href="<?= $CONFIG['siteroot']?>/admin/login.php?logout">Logout</a></li>
+ </ul>
+</div>
+
+<div id="content">
diff --git a/htdocs/src/Cif_Database.inc.php b/htdocs/src/Cif_Database.inc.php
new file mode 100644
index 0000000..e78889c
--- /dev/null
+++ b/htdocs/src/Cif_Database.inc.php
@@ -0,0 +1,196 @@
+<?php
+require_once('Cif_Database_Exception.inc.php');
+
+/**
+ * @category Cif
+ * @package Cif_Database
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ * @copyright Copyright (c) 2009, Jesse Morgan
+ * @version $Id: Cif_Database.inc.php 134 2011-03-08 23:35:57Z jessemorgan $
+ */
+
+/**
+ * Cif_Database is an object providing an
+ * interface to manipulate a MySQL database.
+ *
+ * @package Cif_Database
+ */
+class Cif_Database {
+ /**
+ * Creates a new Cif_Database_Database object and connects to the database.
+ *
+ * @param string $host MySQL Server to connect to.
+ * @param string $user Username to connect with.
+ * @param string $password Password to connect with.
+ * @param string $database Database to select.
+ * @throws Cif_Database_Exception if the database can not be opened.
+ */
+ public function __construct($host, $user, $password, $database) {
+ if (!mysql_connect($host, $user, $password)) {
+ throw new Cif_Database_Exception("Failed to connect to database.");
+ }
+
+ if (!mysql_select_db($database)) {
+ throw new Cif_Database_Exception("Failed to select database.");
+ }
+ }
+
+ /**
+ * Fetch one row from the database with the given query.
+ *
+ * @param string $query The MySQL query.
+ * @return array Array of fields mapped to values.
+ * @throws Cif_Database_Exception if the query fails.
+ */
+ public function fetchAssocRow($query) {
+ $result = mysql_query($query);
+
+ // A query error occured.
+ if (!$result) {
+ throw new Cif_Database_Exception("Query Failed.");
+ }
+
+ return $this->_cleanRow(mysql_fetch_assoc($result));
+ }
+
+ /**
+ * Fetch multiple rows from the database with the given query.
+ *
+ * @param string $query The MySQL query.
+ * @return array Array containing arrays of fields mapped to values for each row.
+ * @throws Cif_Database_Exception if the query fails.
+ */
+ public function fetchAssocRows($query) {
+ $result = mysql_query($query);
+
+ // A query error occured.
+ if (!$result) {
+ throw new Cif_Database_Exception("Query Failed.");
+ }
+
+ $rows = array();
+ while ($row = mysql_fetch_assoc($result)) {
+ $rows[] = $this->_cleanRow($row);
+ }
+
+ return $rows;
+ }
+
+ /**
+ * Update a specified table in the database with the values given.
+ *
+ * @param string $table The table to update.
+ * @param array $values Array of fields mapped to values to update.
+ * @param string $append Optional string to be appended to the MySQL query.
+ * @throws InvalidArgumentException if the table name or values list are empty.
+ * @throws Cif_Database_Exception if the query fails.
+ */
+ public function update($table, $values, $append = "") {
+ // If the table name is empty, or they didn't provide an array of updates,
+ // throw an exception.
+ if ($table == "" or !is_array($values)) {
+ throw new InvalidArgumentException();
+ }
+
+ // Prep the $values for the update.
+ foreach ($values as $field=>$value) {
+ if ($value === NULL) {
+ $updatefields[] = "`$field`=NULL";
+
+ } else {
+ $updatefields[] = "`$field`='$value'";
+ }
+ }
+
+ $result = mysql_query("UPDATE `$table` SET ". implode(",", $updatefields) ." $append");
+
+ if (!$result) {
+ throw new Cif_Database_Exception("Update Failed.");
+ }
+ }
+
+ /**
+ * Insert a collection of rows into the database.
+ *
+ * @param string $table The table to update.
+ * @param array $row Arrays of fields mapped to values for the new row.
+ * @return int Auto-incremented id of the new row.
+ * @throws InvalidArgumentException if the table name or values list are empty.
+ * @throws Cif_Database_Exception if the query fails.
+ */
+ function insert($table, $row) {
+ if (!is_array($row)) {
+ throw new InvalidArgumentException();
+ }
+
+ foreach ($row as $field=>$value) {
+ $fields[] = "`$field`";
+
+ if ($value === NULL) {
+ $values[] = "NULL";
+
+ } else {
+ $values[] = "'$value'";
+ }
+ }
+
+ $result = mysql_query("INSERT INTO `$table` (". implode(', ', $fields) .") VALUES (". implode(", ", $values) .")");
+
+ if ($result) {
+ $id = mysql_insert_id();
+
+ return $id;
+
+ } else {
+ throw new Cif_Database_Exception("Insert Failed.");
+ }
+ }
+
+ /**
+ * Delete rows from the specified table.
+ *
+ * @param string $table The table to delete from.
+ * @param string $where The string to append to the end of the query.
+ * @throws Cif_Database_Exception if the query fails.
+ */
+ function delete($table, $where) {
+ $result = mysql_query("DELETE FROM `$table` WHERE $where");
+
+ if (!$result) {
+ throw new Cif_Database_Exception("Delete Failed.");
+ }
+ }
+
+ /**
+ * Run a query against the database.
+ *
+ * @param string $query The query to run.
+ * @throws Cif_Database_Exception if the query fails.
+ */
+ function raw($command) {
+ $result = mysql_query($command);
+
+ if (!$result) {
+ throw new Cif_Database_Exception("Raw Command.");
+ }
+ }
+
+ /**
+ * Strip the slashes from every field of the given row.
+ *
+ * @param array $row Array of fields mapped to values.
+ * @return array Array of fields mapped to values, without slashes.
+ */
+ private function _cleanRow($row) {
+ if (!$row) return NULL;
+
+ foreach ($row as $key => $value) {
+ $new[$key] = stripslashes($value);
+ }
+ return $new;
+ }
+
+}
+
+?>
diff --git a/htdocs/src/Cif_Database_Exception.inc.php b/htdocs/src/Cif_Database_Exception.inc.php
new file mode 100644
index 0000000..cf70661
--- /dev/null
+++ b/htdocs/src/Cif_Database_Exception.inc.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * @category Cif
+ * @package Cif_Database
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ * @copyright Copyright (c) 2009, Jesse Morgan
+ * @version $Id: Cif_Database_Exception.inc.php 134 2011-03-08 23:35:57Z jessemorgan $
+ */
+
+/**
+ * Cif_Database_Exception is a MySQL specific exception.
+ *
+ * @package Cif_Database
+ */
+class Cif_Database_Exception extends Exception {
+ /**
+ * Constructor for the Cif_Database_Exception.
+ * Creates a new Exception with the mysql error messages as the message.
+ *
+ * @param string $message Message to prepend to the Exception message.
+ */
+ public function __construct($message) {
+ parent::__construct($message . " Error: ". mysql_error(), mysql_errno());
+ }
+
+
+
+}
+
+?> \ No newline at end of file
diff --git a/htdocs/src/Post.inc.php b/htdocs/src/Post.inc.php
new file mode 100644
index 0000000..a4d34f7
--- /dev/null
+++ b/htdocs/src/Post.inc.php
@@ -0,0 +1,82 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "base.inc.php";
+
+class Post {
+ private $info;
+
+
+ public function __construct($info=null) {
+ $this->info = $info;
+ }
+
+ public static function getById($id) {
+ $where = "id='$id'";
+
+ return Post::getPost($where);
+ }
+
+ public static function getBySecretId($secretid) {
+ $where = "secretid='$secretid'";
+
+ return Post::getPost($where);
+ }
+
+ private static function getPost($where) {
+ $query = "SELECT * FROM post WHERE $where";
+
+ $db = getDatabase();
+
+ $row = $db->fetchAssocRow($query);
+
+ if ($row) {
+ $user = new Post();
+ $user->info = $row;
+
+ return $user;
+
+ } else {
+ return false;
+ }
+ }
+
+ public function save() {
+ $db = getDatabase();
+
+ // TODO: Implement Save
+ }
+
+ public function getId() {
+ return $this->info['id'];
+ }
+
+ public function getName() {
+ return $this->info['name'];
+ }
+
+ public function getStage() {
+ return $this->info['stage'];
+ }
+
+ public function approve() {
+ $this->info['stage'] = 'approved';
+ }
+
+ public function verify() {
+ $this->info['stage'] = 'verify';
+ }
+
+ public function getCreated() {
+ return $this->info['created'];
+ }
+}
+
+?>
diff --git a/htdocs/src/PostIterator.inc.php b/htdocs/src/PostIterator.inc.php
new file mode 100644
index 0000000..6106f23
--- /dev/null
+++ b/htdocs/src/PostIterator.inc.php
@@ -0,0 +1,67 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "base.inc.php";
+
+class PostIterator implements Iterator {
+ private $where;
+ private $rows;
+ private $position;
+
+ public function __construct() {
+ $this->where = array();
+ $this->rows = array();
+ $this->position = 0;
+ }
+
+ public function filterStage($stage) {
+ $this->where[] = "stage='$stage'";
+ }
+
+ public function filterSource($source) {
+ $this->where[] = "source_id='$source'";
+ }
+
+ public function rewind() {
+ $this->position = 0;
+ }
+
+ public function current() {
+ return new Post($this->rows[$this->position]);
+ }
+
+ public function key() {
+ return $this->rows[$this->position]['id'];
+ }
+
+ public function next() {
+ ++$this->position;
+ }
+
+ public function valid() {
+ return isset($this->rows[$this->position]);
+ }
+
+ public function query() {
+ $query = "SELECT * FROM post";
+
+ if (count($this->where) > 0) {
+ $where = join(' AND ', $this->where);
+ $query .= " WHERE $where";
+ }
+
+ $db = getDatabase();
+
+ $this->rows = $db->fetchAssocRows($query);
+ $this->position = 0;
+ }
+}
+
+?>
diff --git a/htdocs/src/User.inc.php b/htdocs/src/User.inc.php
new file mode 100644
index 0000000..6821042
--- /dev/null
+++ b/htdocs/src/User.inc.php
@@ -0,0 +1,74 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "base.inc.php";
+
+class User {
+ private $info;
+
+
+ public static function getById($id) {
+ $where = "id='$id'";
+
+ return User::getUser($where);
+ }
+
+ public static function getByEmail($email) {
+ $where = "email='$email'";
+
+ return User::getUser($where);
+ }
+
+ private static function getUser($where) {
+ $query = "SELECT * FROM user WHERE $where";
+
+ $db = getDatabase();
+
+ $row = $db->fetchAssocRow($query);
+
+ if ($row) {
+ $user = new User();
+ $user->info = $row;
+
+ return $user;
+
+ } else {
+ return false;
+ }
+ }
+
+ public function save() {
+ $db = getDatabase();
+
+ // TODO: Implement save
+ }
+
+ public function getId() {
+ return $this->info['id'];
+ }
+
+ public function getName() {
+ return $this->info['name'];
+ }
+
+ public function getEmail() {
+ return $this->info['email'];
+ }
+
+ public function setPassword($password) {
+ $this->info['password'] = sha1($password);
+ }
+
+ public function authenticate($password) {
+ return sha1($password) == $this->info['password'];
+ }
+}
+
+?>
diff --git a/htdocs/src/base.inc.php b/htdocs/src/base.inc.php
new file mode 100644
index 0000000..d7a9354
--- /dev/null
+++ b/htdocs/src/base.inc.php
@@ -0,0 +1,45 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once('config.inc.php');
+
+require_once('Cif_Database.inc.php');
+
+/* Set the timezone for PHP */
+date_default_timezone_set('America/Los_Angeles');
+
+/* Start Session */
+session_start();
+
+/* Helper functions */
+$__DB = null;
+
+function getDatabase() {
+ global $CONFIG, $__DB;
+
+ if ($__DB == null) {
+ try {
+ $__DB = new Cif_Database($CONFIG['dbhost'], $CONFIG['dbuser'],
+ $CONFIG['dbpass'], $CONFIG['dbname']);
+
+ } catch (Cif_Database_Exception $e) {
+ die("Could not connect to database");
+ }
+ }
+
+ return $__DB;
+}
+
+function __autoload($class) {
+ require_once "$class.inc.php";
+}
+
+
+?>
diff --git a/htdocs/src/config.inc.php b/htdocs/src/config.inc.php
index e93eb43..1ca6808 100644
--- a/htdocs/src/config.inc.php
+++ b/htdocs/src/config.inc.php
@@ -12,14 +12,18 @@ $CONFIG = array(
// Database Information
'dbhost' => '127.0.0.1',
'dbuser' => 'p4scommunity',
- 'dbpass' => '',
+ 'dbpass' => 'password',
'dbname' => 'p4scommunity',
// Site Information
'sitetitle' => 'Foursquare Community',
'urlroot' => 'http://localhost/~jesse/p4s/community/htdocs',
+
+ 'root' => '/Users/jesse/Development/P4Square/community/htdocs',
-
+ 'debug' => true,
);
+set_include_path(get_include_path() . PATH_SEPARATOR . $CONFIG['root'].'/src');
+
?>