summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-05-25 12:29:55 -0700
committerJesse Morgan <jesse@jesterpm.net ; true>2011-05-25 12:29:55 -0700
commit7f4dfecdbf2505b3fa91fb00f07d345ae3b3b456 (patch)
treeb38d088299efc3215c5833d604d6a68e68c99f81
parent0c72d673a9056c753503e6b2a8d4fbf3aba75a95 (diff)
Starting to add stages to the registration process
-rw-r--r--htdocs/new-post.php203
1 files changed, 155 insertions, 48 deletions
diff --git a/htdocs/new-post.php b/htdocs/new-post.php
index 3c2fe42..4181b07 100644
--- a/htdocs/new-post.php
+++ b/htdocs/new-post.php
@@ -12,14 +12,125 @@ require_once "src/base.inc.php";
require_once "src/header.inc.php";
-echo "<h2>Submit Post</h2>";
+echo "<h2>New Posting</h2>";
+
+/*
+ * Stages:
+ * 1) Pick a category
+ * 2) ToS
+ * 3) Title, Desc, Location, email
+ * 4) Images
+ * 5) Notify about email
+ *
+ * TODO: Set the source of the post.
+ */
+
+$stage = 'category';
+
+if (isset($_GET['stage'])) {
+ $stage = trim($_GET['stage']);
+}
+
+if (!isset($_SESSION['newpost'])) {
+ $stage = 'category';
+}
+
+switch ($stage) {
+ case 'category':
+ handle_category();
+ break;
+
+ case 'tos':
+ if (finish_category())
+ handle_tos();
+ break;
+
+ case 'post':
+ if (finish_tos())
+ handle_post();
+ break;
+
+ case 'images':
+ if (finish_post())
+ handle_images();
+ break;
+
+ case 'finish':
+ if (finish_images())
+ handle_finish();
+ break;
+
+ default:
+ // Category
+ handle_category();
+}
+
+/* Stage Handlers */
+
+function handle_category() {
+ $_SESSION['newpost'] = new Post();
+
+ // Display instructions
+ echo "<p>Start by choosing a category from the list below</p>";
+
+ // List Categories
+ foreach (Category::getCategories() as $short => $name) {
+ echo "<p><a href=\"". $GLOBALS['CONFIG']['urlroot']
+ . "/new-post.php?stage=tos&category=$short\">$name</a></p>";
+ }
+
+}
+
+function finish_category() {
+ $post = $_SESSION['newpost'];
+
+ if (isset($_GET['category'])) {
+ $category = Category::getByShortname(addslashes($_GET['category']));
+ if ($category) {
+ $post->setCategory($category->getId());
+ return true;
+ }
+ }
+
+ handle_category();
+ return false;
+}
+
+function handle_tos() {
+ // Display ToS
+ // TODO: Display ToS Here
+
+ form_start('post');
+
+ echo "<p><label><input type=\"checkbox\" name=\"tos\" value=\"1\" />"
+ ." I agree to the terms of service.</label></p>";
+
+ form_end();
+}
+
+function finish_tos() {
+ if (isset($_POST['tos']) and $_POST['tos'] == 1) {
+ return true;
+
+ } else {
+ header('Location: ' . $GLOBALS['CONFIG']['urlroot']);
+ exit;
+ }
+}
+
+function handle_post($error='') {
+ // Display Form
+ form_start('images');
+ render_form($error);
+ form_end();
+}
-// Process submission
-if (isset($_POST['category'])) {
+function finish_post() {
+ $post = $_SESSION['newpost'];
+
$required = array(
'title' => 'Title',
'description' => 'Description',
- 'category' => 'Category',
'email' => 'Email Address',
'email2' => 'Confirm Email Address',
);
@@ -39,43 +150,57 @@ if (isset($_POST['category'])) {
$error .= "<p>Email addresses must match.</p>";
}
- if ($_POST['tos'] != '1') {
- $error .= "<p>You must accept the terms of service.</p>";
+ if ($error == '') {
+ $post->setEmail($values['email']);
+ $post->setName($values['title']);
+ $post->setDescription($values['description']);
+
+ return true;
}
- $category = Category::getByShortname(addslashes($values['category']));
- if (!$category) {
- $error .= "<p>Invalid category.</p>";
+ handle_post($error);
+ return false;
+}
+
+function handle_images() {
+ $post = $_SESSION['newpost'];
+
+ // Save Post
+ if (!$post->save()) {
+ $error .= "An internal error has occured.";
}
- if ($error == '') {
- $post = new Post();
+ // Display image form
- $post->setEmail($values['email']);
- $post->setCategory($category->getId());
- $post->setName($values['title']);
- $post->setDescription($values['description']);
+}
- // TODO: Set the source of the post.
+function finish_images() {
- if ($post->save()) {
- $post->sendValidation();
+}
- // TODO: Revise wording.
- echo "<p>Your posting is awaiting email verification</p>";
+function handle_finish() {
+ $post = $_SESSION['newpost'];
- } else {
- $error .= "An internal error has occured.";
- }
+ // Send validation email.
+ $post->sendValidation();
- } else {
- render_form($error);
- }
+ // Display confirmation message
+ // TODO: Revise wording of confirmation message.
+ echo "<p>Your posting is awaiting email verification</p>";
+}
+
+
+function form_start($stage) {
+ echo "<form action=\"". $GLOBALS['CONFIG']['urlroot'] ."/new-post.php?stage=$stage\""
+ ." method=\"post\">";
+}
-} else {
- render_form();
+function form_end() {
+ echo "<p><input type=\"submit\" value=\"Next &gt;\" /></p></form>";
}
+
+
require_once "src/footer.inc.php";
@@ -86,18 +211,6 @@ function render_form($error="") {
echo "<div class=\"errorbox\">$error</div>";
}
- echo "<form action=\"new-post.php\" method=\"post\">";
- echo "<p><label>Category: <select name=\"category\">";
- foreach (Category::getCategories() as $short => $name) {
- if (isset($_POST['category']) and $_POST['category'] == $short) {
- echo "<option name=\"$short\" selected=\"selected\">$name</option>";
-
- } else {
- echo "<option name=\"$short\">$name</option>";
- }
- }
- echo "</select></label</p>";
-
echo "<p><label>Title: <input type=\"text\" name=\"title\" value=\"${values[title]}\" /></label></p>";
echo "<p><label for=\"desc\">Description:</label></p>";
@@ -105,17 +218,11 @@ function render_form($error="") {
. " cols=\"80\">${values[description]}</textarea></p>";
echo "<p><label>Email Address: <input type=\"text\" name=\"email\" value=\"${values[email]}\" />"
+ . "</label>";
+ echo " <label>Confirm Email: <input type=\"text\" name=\"email2\" value=\"${values[email2]}\" />"
. "</label></p>";
- echo "<p><label>Confirm Email: <input type=\"text\" name=\"email2\" value=\"${values[email2]}\" />"
- . "</label></p>";
-
- // TODO: Link to terms of service.
- echo "<p><label><input type=\"checkbox\" name=\"tos\" value=\"1\" />"
- ." I agree to the terms of service.</label></p>";
- // TODO: Allow picture uploads.
- echo "<p><input type=\"submit\" value=\"Submit\" /></p></form>";
}