From 7f4dfecdbf2505b3fa91fb00f07d345ae3b3b456 Mon Sep 17 00:00:00 2001
From: Jesse Morgan
Date: Wed, 25 May 2011 12:29:55 -0700
Subject: Starting to add stages to the registration process
---
htdocs/new-post.php | 203 +++++++++++++++++++++++++++++++++++++++-------------
1 file 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 "Submit Post
";
+echo "New Posting
";
+
+/*
+ * 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 "Start by choosing a category from the list below
";
+
+ // List Categories
+ foreach (Category::getCategories() as $short => $name) {
+ echo "$name
";
+ }
+
+}
+
+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 "";
+
+ 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 .= "Email addresses must match.
";
}
- if ($_POST['tos'] != '1') {
- $error .= "You must accept the terms of service.
";
+ 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 .= "Invalid category.
";
+ 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 "Your posting is awaiting email verification
";
+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 "Your posting is awaiting email verification
";
+}
+
+
+function form_start($stage) {
+ echo "";
}
+
+
require_once "src/footer.inc.php";
@@ -86,18 +211,6 @@ function render_form($error="") {
echo "$error
";
}
- echo "
";
echo "";
+ echo "
";
- echo "";
-
- // TODO: Link to terms of service.
- echo "";
- // TODO: Allow picture uploads.
- echo "";
}
--
cgit v1.2.3