<?php

/*
 *	W-AGORA 4.0
 *	-----------
 *	$Id: post.php,v 1.23 2005/06/04 10:21:24 mdruilhe Exp $
 *	Usage:		Display Post/Reply form
 *	Author:		Marc Druilhe <mdruilhe@w-agora.com>
 *
 */	

	if (isset ($_POST["key"])) {
		$key = $_POST["key"];
	} elseif (isset ($_GET["key"])) {
		$key = $_GET["key"];
	}

	$bn_action = (empty($key)) ? "post" : "reply";
	$bn_action_mode="W";
	$popup=1;
	require ("init.inc");

# A forum must be selected
# ------------------------
	if (empty($bn)) {
		die (ERROR_NO_FORUM_SPECIFIED);
	}

# If the form has already been submitted (eg. msgForm) then extract all submitted fields
# --------------------------------------------------------------------------------------
	if (!empty($_POST) ) {
		foreach($db_var as $field) {
			$$field = strip_magic_quotes($_POST[$field]);
		}	
	}

# action=reply => Initialize fields (subject, reply address & quoted reply)
# -------------------------------------------------------------------------
	if ($bn_action == "reply") {
		$note = $db->getNote ($bn_db, $key);
		if (!$note) {
			if (!empty($before_access)) include $before_access;
			display_header (LABEL_POST, $header_footer);
			MsgForm (sprintf(ERROR_NOTE_NOT_FOUND, $msg[0]), "list.$ext", "close");
			display_footer ($header_footer);
		}

// Raptor: Closed Thread
		if (($note["closed"]==1) && !$is_moderator) {
			if (!empty($before_access)) include $before_access;
			display_header (LABEL_POST, $header_footer);
			msgForm (MSG_THREAD_IS_CLOSED, "view.$ext?bn=$bn&key=$key", "close");
			display_footer ($header_footer);
		}

		// set user's name and e-mail
		$reply_name = stripSlashes($note["username"]);
		$reply_address = stripSlashes($note["useraddress"]);
		
		// set subject field
		if (!isset($_POST['subject']) ) {
			$subject = kill_quotes(stripSlashes($note["subject"]));
			if (!eregi ("^re:", $subject)) {
				$subject = "Re: $subject";
			}
		}

		// set BODY field
		if (!empty($note["body"]) ) {
			$reply_body = strip_url (strip_smileys (stripSlashes ($note["body"]) ) );
			if ($reply_name != "") {
				$quoted_text = sprintf (LABEL_WROTE, $reply_name) . "\n";
			}
			$quoted_text .= quote_text($reply_body);
		}
	}

# Execute before_access program
# -----------------------------
	if (!empty($before_access)) include $before_access;

# Display form
# ------------
	$setUserField = (isset($_POST['username'])) ? false : true;	// Set username and password in form fields
	$form_action = "insert.$ext";
	$back_form="post";

	display_header (LABEL_POST, $header_footer);
	include "$inc_dir/form.$ext";

# Display footer
# --------------
	display_footer ($header_footer);
?>
