<?php

/*
 *	W-AGORA 4.0
 *	-----------
 *	$Id: post.php,v 1.22 2005/01/25 11:16:46 mdruilhe Exp $
 *	Usage:		Display Post/Reply form
 *	Author:		Marc Druilhe <mdruilhe@w-agora.com>
 *
 */	

	if (isset ($HTTP_POST_VARS["key"])) {
		$key = $HTTP_POST_VARS["key"];
	} elseif (isset ($HTTP_GET_VARS["key"])) {
		$key = $HTTP_GET_VARS["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($HTTP_POST_VARS) ) {
		foreach($db_var as $field) {
			$$field = strip_magic_quotes($HTTP_POST_VARS[$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($HTTP_POST_VARS['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($HTTP_POST_VARS['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);
?>
