* */ require_once "src/base.inc.php"; require_once "src/header.inc.php"; const MAX_IMAGE_UPLOADS = 4; 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(); } function finish_post() { $post = $_SESSION['newpost']; $required = array( 'title' => 'Title', 'description' => 'Description', 'email' => 'Email Address', 'email2' => 'Confirm Email Address', ); $error = ''; $values = array(); foreach ($required as $field => $desc) { if (!isset($_POST[$field]) or trim($_POST[$field]) == '') { $error .= "

$desc is a required field.

"; } else { $values[$field] = trim($_POST[$field]); } } if ($values['email'] != $values['email2']) { $error .= "

Email addresses must match.

"; } if ($error == '') { $post->setEmail($values['email']); $post->setName($values['title']); $post->setDescription($values['description']); if ($post->save()) { return true; } else { $error .= 'An internal error has occured.'; } } handle_post($error); return false; } function handle_images() { $post = $_SESSION['newpost']; // Display image form echo "

You may upload up to four images with your post.

"; form_start('finish'); for ($i = 1; $i <= MAX_IMAGE_UPLOADS; $i++) { echo "

"; } form_end(); } function finish_images() { $post = $_SESSION['newpost']; if (isset($_FILES['images']) and is_array($_FILES['images'])) { foreach ($_FILES['images'] as $file) { $post->addImage($file['tmp_name']); } } return true; } function handle_finish() { $post = $_SESSION['newpost']; // Send validation email. $post->sendValidation(); // Display confirmation message echo "

Your posting is almost complete. You must verify your email address by visiting the link we have emailed you, then your posting will be reviewed by our moderation team.

"; } function form_start($stage) { echo "
"; } function form_end() { echo "

"; } require_once "src/footer.inc.php"; function render_form($error="") { global $values; if ($error != '') { echo "
$error
"; } echo "

"; echo "

"; echo "

"; echo "

"; echo "

" . "

Your email address will only be visible to our moderators.

"; } ?>