#!/usr/bin/perl
$discus_conf = '/u1/tonyl/discus_admin/discus.conf';
#Discus board post script (board-post.cgi)
#-------------------------------------------------------------------------------
# DISCUS VERSION 3.10 COPYRIGHT NOTICE
#
# Discus 3.10 is copyright (c) 2000 by DiscusWare, LLC, all rights reserved.
# The use of Discus is governed by the Discus License Agreement which is
# available from the Discus WWW site at:
#    http://www.discusware.com/discus/license
#
# Pursuant to the Discus License Agreement, this copyright notice may not be
# removed or altered in any way.
#-------------------------------------------------------------------------------
$double_post_threshold = 120;
if (open (FILE, "$discus_conf")) {
	@file = <FILE>;
	close (FILE);
	foreach $line (@file) {
		if ($line =~ /^(\w+)=(.*)/) {
			$varname = $1;
			$value = $2;
			$value =~ s/\r//g;
			${$varname} = $value;
		}
	}
	require "$admin_dir/source/src-board-subs-common";
} else {
	print "Content-type: text/html\n\n";
	print "<HTML><HEAD><TITLE>Script Execution Error</TITLE></HEAD>\n";
	print "<BODY BGCOLOR=#ffffff TEXT=#000000>\n";
	print "<H1>Script Execution Error</H1>\n";
	print "Discus scripts could not execute because the discus.conf file\n";
	print "could not be opened.";
	print "<P>Reason: <FONT COLOR=#ff0000><B>$!</B></FONT>" if $!;
	print "<P>This generally indicates a setup error of some kind.\n";
	print "Consult the <A HREF=\"http://www.discusware.com/support\">Discus ";
	print "Resource Center</A> for troubleshooting information.</BODY></HTML>\n";
	exit(0);
}
&quota_message if $DO_NOT_WRITE_FILES_FLAG;
require "$admin_dir/source/src-board-subs-admin";
# Added for reply by e-mail script
$reply_by_email = 1;
if ($ARGV[0] ne "") {
	$tempfile = $ARGV[0];
	$tempfile =~ s/\D//g;
	if (open(TEMPFILE, "$admin_dir/msg_index/$tempfile-reply.txt")) {
		@tempfile = <TEMPFILE>;
		close (TEMPFILE);
		$post = $tempfile[0]; chomp $post;
		$ENV{'QUERY_STRING'} = $post;
		$ENV{'CONTENT_LENGTH'} = 0;
		unlink("$admin_dir/msg_index/$tempfile-reply.txt");
	}
}
&parse_form;
&read_cookie;
$COOKIE{"cpwd$COOKIE_ID"} = $FORM{'crypted_pw'} if ($ARGV[0] ne "" && $FORM{'crypted_pw'} ne "");
if ($FORM{'action'} eq "spch") {
	&ex('spellchecker_javascript', 1);
}
$FORM{'name'} = $FORM{'username'} if $FORM{'username'} ne "";
$FORM{'number'} = $FORM{'passwd'} if $FORM{'passwd'} ne "";
$adminappend = "?username=$FORM{'name'}";
$adminappend .= "&HTTP_REFERER=$FORM{'HTTP_REFERER'}&action=page_editor#Messages";
if ($GLOBAL_OPTIONS{'posting'} == 0 && $GLOBAL_OPTIONS{'options_used'} == 1) {
	&error_message($L{BPAUTHERROR}, $L{AUTHERROR_CLOSED}, 0, 1);
}
if ($ENV{'HTTP_REFERER'} =~ /(.*)\.$cgi_extension/i || $FORM{'HTTP_REFERER'}) {
	$_ = $FORM{'HTTP_REFERER'};
	s/#(.*)//g;
} else {
	$_ = $ENV{'HTTP_REFERER'};
	$FORM{'HTTP_REFERER'} = $_;
	s/#(.*)//g;
}
&extract ($_) if $_ ne "";
$FORM{'name'} =~ s/[\(\)]//g;
$username_input = $FORM{'name'};
$password_input = $FORM{'number'};
($auth, $passwordline, $poster_type, $is_su, $is_mod, $is_user, $poster_binary) = &ex('verify_postread_privileges', $topic_number, $username_input, $password_input, $password_input, "posting", 1);
if ($pro) {
	&ex('get_preferences', "*", "*", $passwordline);
}
undef @file; undef $line;
open (FILE, "$admin_dir/postoptions.txt"); @file = <FILE>; close (FILE);
($line) = grep(/^$topic_number:/, @file); chomp $line;
($tn, $anonymous_forbidden, $stamp_forbidden, $email_forbidden) = split(/:/, $line);
if ($passwordline ne "") {
	$passwordline =~ s/\s+$//;
	($file, $user, $pass, $email, $full, $foo1, $foo2, $foo3, $group) = split(/:/, $passwordline);
	$user_x = $user;
	if ($GLOBAL_OPTIONS{'capitalize_username'} == 1 || $GLOBAL_OPTIONS{'capitalize_username'} eq "") {
		@x = split(/_/, $user_x);
		foreach $x (@x) {
			$x = "\u$x";
		}
		$user_x = join("_", @x);
	}
	$ccux = &remove_html(&char_convert($user_x));
	$full = $ccux if ($full eq "fullname" || $full eq "" || $stamp_forbidden || ($GLOBAL_OPTIONS{'fullnames'} == 0 && $GLOBAL_OPTIONS{'options_used'} == 1));
	$full .= " ($ccux)" if $GLOBAL_OPTIONS{'user_paren'} eq "";
	$full .= " ($ccux)" if $GLOBAL_OPTIONS{'user_paren'} == 1;
	if ($group !~ /\S/) {
		$group_hold = "MODERATOR";
	} else {
		$group_hold = $group;
	}
	$FULLNAME = $full;
	$PROFILE_LINK = "";
	$EMAIL = "";
	if ($pro) {
		if (($GLOBAL_OPTIONS{'anonymous'} == 1 || $GLOBAL_OPTIONS{'options_used'} == 0) && $FORM{'Anon'} && !$anonymous_forbidden) {
			$FULLNAME = $L{BPANONYMOUS};
			$PROFILE_LINK = "<A HREF=\"javascript:alert('* $L{BPANONYMOUS} *');\">";
			$EMAIL = "";
		} else {
			$warn_anon = 1 if $FORM{'Anon'};
			$filename = "$user-$group_hold.txt";
			$filename = &getfn($filename);
			if (-e "$admin_dir/profiles/$filename" && !$email_forbidden && ($GLOBAL_OPTIONS{'email_on_post'} == 1 || $GLOBAL_OPTIONS{'options_used'} == 0)) {
				$PROFILE_LINK = "<A HREF=\"$script_url/board-profile.$cgi_extension?action=display_profile&profile=$user-$group_hold\">";
			} else {
				$EMAIL = $email if ($PREF{'noemail'} == 0 && $email ne "" && $email ne "email" && !$email_forbidden && ($GLOBAL_OPTIONS{'email_on_post'} == 1 || $GLOBAL_OPTIONS{'options_used'} == 0));
			}
		}
	} else {
		if (($GLOBAL_OPTIONS{'anonymous'} == 1 || $GLOBAL_OPTIONS{'options_used'} == 0) && $FORM{'Anon'} && !$anonymous_forbidden) {
			$FULLNAME = $L{BPANONYMOUS};
		} else {
			$warn_anon = 1 if $FORM{'Anon'};
			$EMAIL = $email if ($email ne "" && $email ne "email" && !$email_forbidden && ($GLOBAL_OPTIONS{'email_on_post'} == 1 || $GLOBAL_OPTIONS{'options_used'} == 0));
		}
	}
	$username = $user;
} else {
	$FULLNAME = &remove_html(&char_convert(&remove_html($username_input)));
	$PROFILE_LINK = "<A HREF=\"javascript:alert('* $L{BPANONYMOUS} *');\">";
	$EMAIL = "";
	if (($GLOBAL_OPTIONS{'anonymous'} == 1 || $GLOBAL_OPTIONS{'options_used'} == 0) && $FORM{'Anon'} && !$anonymous_forbidden) {
		$FULLNAME = $L{BPANONYMOUS};
	} else {
		$warn_anon = 1 if $FORM{'Anon'};
		if ($FORM{'email'} ne "") {
			$FORM{'email'} = &remove_html($FORM{'email'});
			$EMAIL = $FORM{'email'};
			if ($EMAIL =~ m|^https?://|i && !$GLOBAL_OPTIONS{'allow_email_url'}) {
				$EMAIL = ""; $FORM{'email'} = "";
			}
		}
	}
	$username = "PUBLIC";
	$group_hold = "PUBLIC";
}
if ($GLOBAL_OPTIONS{'ip_on_post'}) {
	$rh = $ENV{'REMOTE_HOST'};
	$rh =~ s/[<>]//g;
	$ra = $ENV{'REMOTE_ADDR'};
	$ra =~ s/[<>]//g;
	$FULLNAME .= " ($rh - $ra)" if $rh;
	$FULLNAME .= " ($ra)" if !$rh;
}
$FORM{'message'} =~ s/\s+$//;
$FORM{'message'} =~ s/^\s+//;
$FORM{'message'} =~ s/\n{3,}/\n\n\n/g;
if ($FORM{"message"} =~ m|^\{\\rtf| && $pro && $GLOBAL_OPTIONS{'RTF'}) {
	($FORM{"message"}) = &ex('rtf_to_webtags', $FORM{"message"});
	($lint, $newmessage) = &ex('webtags', $FORM{"message"}, 0, 1, $is_mod, $is_su);
	&error_message("$L{FORMATTINGERROR}", "$newmessage") if ($FORM{'generate_error'} && $lint_subj eq "!Error");
}
undef $swear_error;
if ($FORM{"message"} !~ /\\(\S+)\{/ && $FORM{"message"} =~ m|<(\s*)([^>]*)(\s*)>| && $GLOBAL_OPTIONS{'html'}) {
	($message_html) = &ex('html_to_webtags', $FORM{"message"});
	$NEW_SOURCE = $message_html;
	$message_html =~ s/<([^>]*)>//g;
	if ($GLOBAL_OPTIONS{'profanity'}) {
		($message_html) = &ex('remove_swearing', $message_html) if ($GLOBAL_OPTIONS{'profanity_detected'} == 1 || $GLOBAL_OPTIONS{'profanity_detected'} eq "");
		($x) = &ex('remove_swearing', $message_html) if $GLOBAL_OPTIONS{'profanity_detected'} == 2;
		$swear_error .= $x if $x;
	}
	($lint, $newmessage) = &ex('webtags', $message_html, 0, 1, $is_mod, $is_su);
	&error_message("$L{FORMATTINGERROR}", "$newmessage") if ($FORM{'generate_error'} && $lint_subj eq "!Error");
} else {
	$NEW_SOURCE = "";
	if ($FORM{"message"} !~ /\\(\S+)\{/ && $GLOBAL_OPTIONS{'active_links'}) {
		$FORM{"message"} = join("", " ", $FORM{"message"}, " ");
		$m = ""; $after = $FORM{"message"};
		while ($after =~ m|(http://)([\w\-\.\+/~\%\?\&\=\:\,]+)|i) {
			$url = join("", $1, $2); $b4 = $`; $after = $';
			if ($url =~ m|([\.\:\;\,])$|) {
				$url = $`; $after = "$1$after";
			}
			$url_link = $url;
			$url_link =~ s/,(.)/\%2C$1/g;
			$m .= join("", $b4, "\\topurl\{$url_link,$url}");
		}
		$FORM{"message"} = $m . $after;
		$m = ""; $after = $FORM{"message"};
		while ($after =~ m|([\w\-\+\.]+)\@([\w\-\+\.]+)|i) {
			$url = join("", $1, "\@", $2); $b4 = $`; $after = $';
			if ($url =~ m|([\.\:\;\,])$|) {
				$url = $`; $after = "$1$after";
			}
			$url_link = $url;
			$url_link =~ s/,(.)/\%2C$1/g;
			$m .= join("", $b4, "\\mail\{$url_link,$url}");
		}
		$FORM{"message"} = $m . $after;
	}
	$message_temp = $FORM{"message"};
	if ($GLOBAL_OPTIONS{'profanity'}) {
		($message_temp) = &ex('remove_swearing', $message_temp) if ($GLOBAL_OPTIONS{'profanity_detected'} == 1 || $GLOBAL_OPTIONS{'profanity_detected'} eq "");
		($swear_error) = &ex('remove_swearing', $message_temp) if $GLOBAL_OPTIONS{'profanity_detected'} == 2;
	}
	($lint, $newmessage) = &ex('webtags', $message_temp, 0, 1, $is_mod, $is_su);
	&error_message("$L{FORMATTINGERROR}", "$newmessage") if ($FORM{'generate_error'} && $lint_subj eq "!Error");
	$error_observed = 1;
}
if ($FORM{'subject'} ne "") {
	$newsubject = $FORM{'subject'};
	if ($GLOBAL_OPTIONS{'profanity'}) {
		($newsubject) = &ex('remove_swearing', $newsubject) if ($GLOBAL_OPTIONS{'profanity_detected'} == 1 || $GLOBAL_OPTIONS{'profanity_detected'} eq "");
		($x) = &ex('remove_swearing', $newsubject) if $GLOBAL_OPTIONS{'profanity_detected'} == 2;
		$swear_error .= $x if $x ne "";
	}
	($lint_subj, $newsubject) = &ex('webtags', $newsubject, 3, 1, $is_mod, $is_su);
	&error_message("$L{FORMATTINGERROR}", "$newsubject") if ($FORM{'generate_error'} && $lint_subj eq "!Error");
	$newsubject = "\u$newsubject" if $GLOBAL_OPTIONS{'capitalize'};
	$newsubj = 1;
}
if ($GLOBAL_OPTIONS{'profanity'}) {
	($FULLNAME) = &ex('remove_swearing', $FULLNAME, 0, 1) if ($GLOBAL_OPTIONS{'profanity_detected'} == 1 || $GLOBAL_OPTIONS{'profanity_detected'} eq "");
	($x) = &ex('remove_swearing', $FULLNAME, 0, 1) if $GLOBAL_OPTIONS{'profanity_detected'} == 2;
	$swear_error .= $x if $x ne "";
}
if ($auth == 0) {
	$newmessage = "<H3>$L{BPAUTHERROR}</H3>$L{BPAUTHERRORINVALID}";
	&error_message("$L{BPAUTHERROR}", "$L{BPAUTHERRORINVALID}") if $FORM{'generate_error'};
} elsif ($auth == 2) {
	$newmessage = "<H3>$L{BPAUTHERROR}</H3>$L{AUTHERROR_BANNED}";
	&error_message("$L{BPAUTHERROR}", "$L{AUTHERROR_BANNED}") if $FORM{'generate_error'};
} elsif ($auth == 3) {
	$newmessage = "<H3>$L{BPAUTHERROR}</H3>$L{AUTHERROR_CLOSED}";
	&error_message("$L{BPAUTHERROR}", "$L{AUTHERROR_CLOSED}") if $FORM{'generate_error'};
} elsif ($FULLNAME !~ /\S/ || ($username_input !~ /\S/ && ($FORM{'Anon'} eq "" || $warn_anon == 1))) {
	$newmessage = "<H3>$L{BPAUTHERROR}</H3>$L{BPAUTHERRORNONAME}";
	&error_message("$L{BPAUTHERROR}", "$L{BPAUTHERRORNONAME}") if $FORM{'generate_error'};
} elsif ($FORM{"message"} !~ /\S/) {
	$newmessage = "<H3>$L{BPADDMSGERROR}</H3>$L{BPADDMSGERRORDESC}";
	&error_message("$L{BPADDMSGERROR}", "$L{BPADDMSGERRORDESC}") if $FORM{'generate_error'};
} elsif ($FORM{"new_conversation"} == 1 && $FORM{"subject"} !~ /\S/) {
	$newmessage = "<H3>$L{BPCREATEERROR}</H3>$L{BPCREATEERRORDESC}";
	$newsubj = 1;
	&error_message("$L{BPCREATEERROR}", "$L{BPCREATEERRORDESC}") if $FORM{'generate_error'};
} elsif ($poster_type == 8 && (length($FORM{'message'})/1000) > $GLOBAL_OPTIONS{'public_msgsize'} && $GLOBAL_OPTIONS{'options_used'} && $GLOBAL_OPTIONS{'public_msgsize'}) {
	$newmessage = "<H3>$L{BPADDMSGERROR}</H3>";
	$toolong = $L{BP_MESSAGE_EXCEEDED_MAXLENGTH};
	$mxs = $GLOBAL_OPTIONS{'public_msgsize'}; $toolong =~ s/\%maxsize/$mxs/g;
	$ys = length($FORM{'message'})/1000; $toolong =~ s/\%yoursize/$ys/g;
	$newmessage .= $toolong;
	&error_message("$L{BPADDMSGERROR}", "$toolong") if $FORM{'generate_error'};
} elsif ($poster_type != 8 && (length($FORM{'message'})/1000) > $GLOBAL_OPTIONS{'registered_msgsize'} && $GLOBAL_OPTIONS{'options_used'} && $GLOBAL_OPTIONS{'registered_msgsize'}) {
	$newmessage = "<H3>$L{BPADDMSGERROR}</H3>";
	$toolong = $L{BP_MESSAGE_EXCEEDED_MAXLENGTH};
	$mxs = $GLOBAL_OPTIONS{'registered_msgsize'}; $toolong =~ s/\%maxsize/$mxs/g;
	$ys = length($FORM{'message'})/1000; $toolong =~ s/\%yoursize/$ys/g;
	$newmessage .= $toolong;
	&error_message("$L{BPADDMSGERROR}", "$toolong") if $FORM{'generate_error'};
} elsif ($swear_error) {
	$newmessage = "<H3>$L{PROFANITY_DETECTED}</H3>";
	$l = $L{PROFANITY_DETECTED_MESSAGE};
	$l =~ s/\%wordlist/$swear_error/g;
	$newmessage .= $l; $l =~ s/<LI>/\*/g;
	&error_message("$L{PROFANITY_DETECTED}", "$l") if $FORM{'generate_error'};
} else {
	$error_observed = 0;
}
$error_observed = 1 if $lint eq "!Error";
$error_observed = 1 if $lint_subj eq "!Error";
$error_observed = 1 if $swear_error;
$newmessage = $newsubject if $lint_subj eq "!Error";
if ($error_observed && $FORM{'generate_error'}) {
	&error_message("$L{FORMATTINGERROR}", $newmessage);
}
$message_hold = $FORM{'message'}; $message_hold =~ s/&/&amp;/g;
$message_hold =~ s/>/&gt;/g; $message_hold =~ s/</&lt;/g; $message_hold =~ s/"/&quot;/g;
$subject_hold = $FORM{'subject'}; $subject_hold =~ s/&/&amp;/g;
$subject_hold =~ s/>/&gt;/g; $subject_hold =~ s/</&lt;/g; $subject_hold =~ s/"/&quot;/g;
$p1 = $L{PREVIEW}; $p2 = $L{PREVIEW2};
$p1 = "x" x 100 if $L{PREVIEW} eq "";
$p2 = "x" x 100 if $L{PREVIEW2} eq "";
$p1 =~ s/^\s+//; $p1 =~ s/\s+$//;
$p2 =~ s/^\s+//; $p2 =~ s/\s+$//;
&flush_language($topic_number);
$p3 = $L{PREVIEW}; $p4 = $L{PREVIEW2};
$p3 = "x" x 100 if $L{PREVIEW} eq "";
$p4 = "x" x 100 if $L{PREVIEW2} eq "";
$p3 =~ s/^\s+//; $p3 =~ s/\s+$//;
$p4 =~ s/^\s+//; $p4 =~ s/\s+$//;
if ($pro) {
	$FORM{'submit'} = "" if ($PREF{'skip_preview'} == 1);
}
if ($FORM{'force_preview'} == 1 || $FORM{'submit'} =~ /$p1/i || $FORM{'submit'} =~ /$p2/i || $FORM{'submit'} =~ /$p3/i || $FORM{'submit'} =~ /$p4/i || $error_observed == 1) {
	&flush_language("*", $topic_number);
	&header;
	($bgcolor, $text, $link, $vlink, $alink, $face, $size, $image) = &extract_colorsonly;
	$str = "$L{BPNORMALTITLE}";
	$spellchecker = 1 if ($GLOBAL_OPTIONS{'spellchecker'} == 1 || $GLOBAL_OPTIONS{'spellchecker'} eq "");
	$spellchecker = 0 if $PREF{'disable_spellchecker'} == 1;
	$checkform = 1 if $GLOBAL_OPTIONS{'noload_warning'};
	&ex('printuntil', 1, 1, $topic_number, "$L{BPNORMALTITLE}", 0, 0, $spellchecker, $checkform);
	print "<FONT SIZE=+1><CENTER><B>$L{BPNORMALTITLE}</B></CENTER></FONT>\n" if $newsubj == 0;
	print "<FONT SIZE=+1><CENTER><B>$L{BPCREATETITLE}</B></CENTER></FONT>\n" if $newsubj == 1;
	print "<HR>\n";
	&ex('printuntil', 3, 3, $topic_number, $title, 0, 1, 0, 0, $spellchecker);
	$file = "$message_dir/$topic_number/$me_number.$ext" if -e "$message_dir/$topic_number/$me_number.$ext";
	if (!-e "$message_dir/$topic_number/$me_number.$ext") {
		$file = "$secdir/$topic_number/$me_number.$ext";
		$secure = 1;
	}
	open (FILE, $file);
	@file = <FILE>;
	close (FILE);
	if ($FORM{'isitok'} ne "okiedokie") {
		($pre) = &ex('get_navbar', $topic_number, $me_number, "post");
		$pre = "<A HREF=\"$message_url/$board_topics_file\" onMouseOver=\"window.status = '$L{NBRETURN} $L{NBMAINPAGE}'; return true\">$title</A>: $pre" if $GLOBAL_OPTIONS{'alternate_topic_navbar'} == 0;
		$pre = "<A HREF=\"$GLOBAL_OPTIONS{'alternate_topic_navbar_url'}\" onMouseOver=\"window.status = '$L{NBRETURN} $L{NBMAINPAGE}'; return true\">$title</A>: $pre" if ($GLOBAL_OPTIONS{'alternate_topic_navbar'} == 1 && $GLOBAL_OPTIONS{'alternate_topic_navbar_url'});
	} else {
		&extract("$FORM{'HTTP_REFERER'}");
		my (@array) = ("$topic_number:$topic_name");
		foreach $key (sort by_number keys(%level_number)) {
			push (@array, "$level_number{$key}:$level_name{$key}");
		}
		$pre = "<A HREF=\"$cgiurlm?username=$FORM{'name'}&action=mgr_1";
		$pre .= "&HTTP_REFERER=$page_referer\" onMouseOver=\"return setStatus('";
		$pre .= "Return to topic selection screen')\"><FONT COLOR=$link>Page Manager</FONT></A>:&nbsp;\n";
		foreach $line (@array) {
			($number,$name) = split(/:/, $line, 2);
			$pre .= "<A HREF=\"$cgiurlm?username=$FORM{'name'}&action=page_editor";
			$pre .= "&HTTP_REFERER=//$topic_number/$number.$ext\" onMouseOver=\"return ";
			$str = &JavaScript_prepare($name);
			$pre .= "setStatus('Return to editing $str')\"><FONT COLOR=$link>$name</FONT></A>: ";
		}
	}
	$pre .= "$L{BPCREATEDISPLAY}" if $newsubj == 1;
	$pre .= "$L{BPNORMALDISPLAY}" if $newsubj == 0;
	&ex('printuntil', 5, 9, $topic_number, $title, 0, 1);
	print "<strong>$pre</strong>\n";
	print "<HR>\n";
	if (!($error_observed)) {
		print "<FONT SIZE=-1>$L{BPMESSAGEPOST}</FONT>" if $newsubj == 0;
		print "<FONT SIZE=-1>$L{BPCREATEPOST}</FONT>" if $newsubj == 1;
		print "<P>";
		if ($warn_anon == 1) {
			print "$L{BPWARNANONYMOUS}<P>\n";
		}
		if ($lint ne "") {
			print "<FONT SIZE=+1><B>$L{BPPOSSIBLEFORMATTINGERRORS}</B></FONT><P>";
			print "<FONT SIZE=-1>$L{BPPOSSIBLEFORMATTINGERRORSDESC}";
			print "<P>\n";
			print "<OL>$lint</OL><P></FONT>\n";
		}
		if ($pro && $PREF{'spellcheck'} == 1 && $dictionary ne "") {
			($newmessage, $scmessage) = &ex('spellcheck', $newmessage);
			if ($scmessage ne "") {
				print $scmessage;
			}
		}
		&ex('printuntil', 11, 11, $topic_number, $title, 0, 1);
		print "<TABLE BORDER=1 WIDTH=97% HEIGHT=40%><TR><TD VALIGN=TOP><BASEFONT SIZE=$size><FONT FACE=\"$face\" SIZE=\"$size\" COLOR=$text>\n";
		if ($newsubj == 1) {
			print "<B>$L{BPSUBJECTTAG}</B> $newsubject<HR SIZE=0>\n";
		}
		$postby = $FULLNAME;
		$postby = join("", $PROFILE_LINK, $FULLNAME, "</A>") if $PROFILE_LINK;
		$postby = join("", "<A HREF=\"mailto:$EMAIL\">", $FULLNAME, "</A>") if $EMAIL !~ m|^https?://|i;
		$postby = join("", "<A HREF=\"$EMAIL\" TARGET=_blank>", $FULLNAME, "</A>") if $EMAIL =~ m|^https?://|i;
		$pb = $L{POSTBY};
		$postby = join("", "<BLINK>", $postby, "</BLINK>") if $warn_anon == 1;
		($datetime) = &ex('get_date_time', "long");
		$pb =~ s/\%name/$postby/g;
		$pb =~ s/\%date/$datetime/g;
		print "$pb<P>\n";
	}
	print "$newmessage";
	if (!$error_observed) {
		print "</FONT></TD></TR>\n";
		print "</TABLE>\n";
		print "<FORM METHOD=POST NAME=MF ACTION=\"$script_url/board-post.$cgi_extension\"";
		if ($FORMINFO_LOAD && $GLOBAL_OPTIONS{'noload_warning'}) {
			$L{FORM_LOADED} = "Please wait for the page to completely load before submitting your message." if $L{FORM_LOADED} eq "";
			print " onSubmit=\"if (document.MF.pgloaded.value == 0) { alert('$L{FORM_LOADED}'); return false; } else { return true; }\"";
		}
		print ">\n";
		print "<INPUT Type=hidden name=\"HTTP_REFERER\" value=\"$FORM{'HTTP_REFERER'}\">\n";
		print "<INPUT TYPE=HIDDEN NAME=\"new_conversation\" value=\"1\">\n" if $FORM{'new_conversation'} == 1;
		print "<INPUT TYPE=HIDDEN NAME=pgloaded VALUE=0>\n";
		print "<INPUT Type=hidden name=\"isitok\" value=\"okiedokie\">\n" if $FORM{'isitok'} eq "okiedokie";
		print "<INPUT TYPE=HIDDEN NAME=no_email VALUE=1>\n" if $FORM{'no_email'};
		print "<HR>\n";
		print "<CENTER>\n";
		if ($spellchecker_net_feature_on) {
			$button_ok = 0; $bv = 0;
			if ($ENV{'HTTP_USER_AGENT'} =~ m|MSIE ([\d\.]+)|) {
				$bv = $1;
				$button_ok = 1 if $bv >= 4;
				$button_ok = 0 if ($ENV{'HTTP_USER_AGENT'} =~ m|Mac| && $bv == 5);
			} elsif ($ENV{'HTTP_USER_AGENT'} =~ m|Mozilla/([\d\.]+)|) {
				$bv = $1;
				$button_ok = 1 if $bv >= 4;
				$button_ok = 0 if $bv == 6;
				$button_ok = 0 if $bv >= 4.5 && $bv < 4.6;
			}
			if ($button_ok && ($GLOBAL_OPTIONS{'spellchecker'} == 1 || $GLOBAL_OPTIONS{'spellchecker'} eq "") && $PREF{'disable_spellchecker'} != 1) {
				print "<INPUT TYPE=\"BUTTON\" NAME=scbutton VALUE=\"";
				print "Check Spelling" if $L{RUN_SPELLCHECKER} eq "";
				print $L{RUN_SPELLCHECKER} if $L{RUN_SPELLCHECKER} ne "";
				print "\" onClick=\"if (document.MF.force_preview.value == 0) { var f=document.MF; doSpell ('";
				print "en" if $GLOBAL_OPTIONS{'spellchecker_language'} eq "";
				print $GLOBAL_OPTIONS{'spellchecker_language'} if ($GLOBAL_OPTIONS{'spellchecker_language'} ne "" && $GLOBAL_OPTIONS{'spellchecker_language'} !~ m|^\*|);
				print $' if $GLOBAL_OPTIONS{'spellchecker_language'} =~ m|^\*|;
				print "', f.message, '$script_url/sproxy.$cgi_extension', true); }\">\n";
			}
		}
		print "<INPUT TYPE=SUBMIT VALUE=\"$L{BPPOSTTHISMESSAGE}\">\n" if !$error_observed;
		print "<INPUT TYPE=\"button\" VALUE=\"$L{BPCANCELPOST}\" onClick=\"window.location=";
		if ($FORM{'isitok'} ne 'okiedokie') {
			$url = "$message_url/$topic_number/$me_number.$ext" if !$secure;
			$url = "$script_url/board-auth.$cgi_extension?file=/$topic_number/$me_number.$ext" if $secure;
			print "'$url'\">&nbsp;";
		} else {
			print "'$cgiurlm$adminappend'\">&nbsp;";
		}
		print "</CENTER>\n";
	} else {
		print "<BR><BR>\n";
		print "<FORM Method=Post Action=\"$script_url/board-post.$cgi_extension\" NAME=MF>\n";
		print "<INPUT Type=hidden name=\"HTTP_REFERER\" value=\"$FORM{'HTTP_REFERER'}\">\n";
		print "<INPUT TYPE=HIDDEN NAME=\"new_conversation\" value=\"1\">\n" if $FORM{'new_conversation'} == 1;
		print "<INPUT Type=hidden name=\"isitok\" value=\"okiedokie\">\n" if $FORM{'isitok'} eq "okiedokie";
		print "<INPUT TYPE=HIDDEN NAME=no_email VALUE=1>\n" if $FORM{'no_email'};
		print "<INPUT TYPE=HIDDEN NAME=pgloaded VALUE=0>\n";
	}
	print "<HR>\n";
	&ex('printuntil', 13, 13, $topic_number, $title, 0, 1);
	print "<INPUT TYPE=HIDDEN NAME=force_preview VALUE=0>\n";
	($page, $add) = &determine_templates($topic_number, 1);
	@file = split(/\n/, $add);
	$am = $L{ADDMESSAGE};
	if ($newsubj == 1) {
		$flag = 0;
		foreach $line (@file) {
			if ($line =~ m|$am|i && $flag == 0) {
				print join("", $`, "$L{BPREVISESUBJECT}", $');
				$flag = 1;
			}
		}
		print "<H3>$L{BPREVISESUBJECT}</H3>\n" if $flag == 0;
		print "$L{BPFSUBJECT}<BR><BR>\n";
		print "<TABLE><TR><TD><INPUT TYPE=TEXT NAME=\"subject\" VALUE=\"$subject_hold\" SIZE=53></TD></TR></TABLE><P>\n";
		print "<HR>\n";
	}
	$flag = 0;
	$message_hold =~ s/^\s+//;
	$message_hold =~ s/\s+$//;
	foreach $line (@file) {
		if ($line =~ /<!-Conversation - LEAVE THIS HERE!-!>/) {
			$flag = 1;
		} elsif ($line =~ /<!-\/Identification/) {
			$flag = 0;
		} elsif ($line =~ /<!-Skip next line-!>/) {
			$flag = 2+$flag;
		} elsif ($flag >= 2) {
			$flag -= 2;
		} elsif ($line =~ /<!-Submit button included-!>/) {
			$submit_included = 1;
		} elsif ($flag == 1) {
			$line = &common_discus_variables($line, $topic_number, $me_number);
			if ($line =~ /NAME="name" VALUE=""/i) {
				$line = join("", $`, "NAME=\"name\" VALUE=\"$username_input\"", $');
			} elsif ($line =~ /NAME="number" VALUE=""/i) {
				$line = join("", $`, "NAME=\"number\" VALUE=\"$FORM{'number'}\"", $');
				$line = "" if $FORM{'isitok'} eq "okiedokie";
			} elsif ($line =~ /NAME="Anon"/i) {
				$line = join("", $`, "NAME=\"Anon\" CHECKED", $') if $FORM{'Anon'} eq "on";
			} elsif ($line =~ /NAME="username" VALUE=""/i) {
				$line = join("", $`, "NAME=\"username\" VALUE=\"$username_input\"", $');
			} elsif ($line =~ /NAME="passwd" VALUE=""/i) {
				$line = join("", $`, "NAME=\"passwd\" VALUE=\"$FORM{'number'}\"", $');
				$line = "" if $FORM{'isitok'} eq "okiedokie";
			} elsif ($line =~ /NAME="email" VALUE=""/i) {
				$line = join("", $`, "NAME=\"email\" VALUE=\"$FORM{'email'}\"", $');
			} elsif ($line =~ /$am/i) {
				$line = join("", $`, "$L{BPREVISEMESSAGE}", $');
			}
			if ($line =~ m|</TEXTAREA>|i) {
				$line = join("", $`, $message_hold, $&, $');
			}
			print $line;
		}
	}
	print "<HR>\n";
	if ($submit_included == 0) {
		print "<CENTER>\n";
		print "<INPUT TYPE=SUBMIT VALUE=\"$L{BPPREVIEWPOST}\" onClick=\"document.MF.force_preview.value = 1;\">\n";
		print "</CENTER><HR>\n";
		print "</FORM>\n";
	}
	&ex('printuntil', 15, 17, $topic_number, $title, 0, 1);
	exit(0);
}
&error_message ("Error", "This page ($me_number) does not allow for public posting of messages!",0,1) if $param !~ /Add/ && $newsubj == 0 && $FORM{'isitok'} ne "okiedokie";
&error_message ("Error", "This page does not allow for public creation of conversations!",0,1) if $param !~ /Create/ && $newsubj == 1;
&error_message ("Error", "Your username/password combination was invalid, or you are not allowed to post to this topic.",0,1) if $passwordline eq "invalid";
if ($GLOBAL_OPTIONS{'double_post'}) {
	if ($newsubj == 0) {
		($head, $color, $lm, $ann, $ann_src, $sublist, $about, $about_src, $message, $message_src, $description_src) = &get_page($topic_number, $me_number);
		@msg = split(/\n/, $message);
		foreach $line (@msg) {
			if ($line =~ m|<!-Post: (\d+)-!><!-Time: (\d+)-!>|) {
				$time = $2;
			} elsif ($line =~ m|<!-Text-!>(.*)<!-/Text-!>|) {
				$text = $1;
			} elsif ($line =~ m|<!-/Post: (\d+)-!>|) {
				next if (time - $double_post_threshold) > $time;
				if ($text eq $newmessage) {
					if ($FORM{'isitok'} ne 'okiedokie') {
						$url = "$message_url/$topic_number/$me_number.$ext" if !-e "$secdir/$topic_number";
						$url = "$script_url/board-auth.$cgi_extension?file=/$topic_number/$me_number.$ext" if -e "$secdir/$topic_number";
					} else {
						$url = "$cgiurlm$adminappend";
					}
					&error_message("$L{BPALREADYPOSTED}", "$L{BPALREADYPOSTEDDESC}<P><B><A HREF=\"$url\">$L{BPCLICKCONTINUE}</A></B><P>", 0, 1);
				}
			}
		}
	} else {
		open (TREE, "$admin_dir/msg_index/$topic_number-tree.txt");
		@TREE_STRUCTURE_FILE = <TREE>;
		close (TREE);
		@ll = grep(/^(\d+)\t$topic_number\t(\d+)\t$me_number\t/, @TREE_STRUCTURE_FILE);
		foreach $line (@ll) {
			@c = split(/\t/, $line);
			if (&unescape($c[4]) eq $newsubject && (time - $double_post_threshold) <= $c[9]) {
				if ($FORM{'isitok'} ne 'okiedokie') {
					$url = "$message_url/$c[1]/$c[2].$ext" if !-e "$secdir/$c[1]";
					$url = "$script_url/board-auth.$cgi_extension?file=/$c[1]/$c[2].$ext" if -e "$secdir/$c[1]";
				} else {
					$url = "$cgiurlm$adminappend";
				}
				&error_message("$L{BPALREADYPOSTED}", "$L{BPALREADYPOSTEDDESC}<P><B><A HREF=\"$url\">$L{BPCLICKCONTINUE}</A></B><P>", 0, 1);
			}
		}
	}
}
$message_hold = $message_html if $message_html;
if ($pro) {
	($queue) = &ex('check_queue_status', $topic_number, $poster_type);
}
$locked_the_tree = 0;
if ($newsubj == 1 && !$queue) {
	$create_new_subject = $newsubject;
} elsif ($newsubj == 1 && $queue) {
	$subject_line = $newsubject;
}
if (!$queue) {
	$me_number_hold = $me_number; $topic_number_hold = $topic_number;
	($postindex, $source_out, $me_number) = &ex('post_message',$topic_number,$me_number,$message_hold,$newmessage,$FULLNAME,$EMAIL,$PROFILE_LINK,$username,$group_hold,time, "", "", $create_new_subject);
	$topic_number = $topic_number_hold;
	if ($postindex == 0 || $me_number eq "") {
		&log_error("board-post.cgi", "posting operation", "post_message returned flawed data ($postindex;$me_number)... $@ $!");
	} else {
		if ($pro) {
			($notify_flag) = &ex('check_notification_hold', $poster_binary);
			if ($GLOBAL_OPTIONS{'email'} && (!$notify_flag || $FORM{'no_email'} != 1)) {
				&ex('email_notification_pro', $topic_number, $me_number, $FULLNAME, $newmessage, $username, $group_hold, 0, $postindex);
			}
		} else {
			&ex('email_notification', $topic_number, $me_number, $FULLNAME, $newmessage, $username, $group_hold, $postindex) if ($GLOBAL_OPTIONS{'email'} && !$pro);
		}
	}
} else {
	$me_number_hold = $me_number; $topic_number_hold = $topic_number;
	($queue_id, $source_out) = &ex('send_message_to_queue', $topic_number, $me_number, $message_hold, $newmessage, $FULLNAME, $username, $group_hold, $subject_line, $EMAIL, $PROFILE_LINK);
	$me_number = $me_number_hold; $topic_number = $topic_number_hold;
	&ex('email_notification_pro', $topic_number, $me_number, $FULLNAME, $newmessage, $username, $group_hold, 1, $queue_id) if ($GLOBAL_OPTIONS{'email'} && $pro);
}
if ($source_out =~ m|\\image_notuploaded\{| || $source_out =~ m|\\attachment_notuploaded\{|) {
	$string = $source_out;
	&header;
	($bgcolor, $text, $link, $vlink, $alink, $face, $size, $image) = &ex('extract_colorsonly', 1);
	&ex('printuntil', 1, 1, $topic_number, "$L{BPIMGUPLOADTITLE3_00}");
	print "<FONT SIZE=+1><CENTER><B>$L{BPIMGUPLOADTITLE3_00}</B></CENTER></FONT>\n<HR>\n";
	for ($i = 3; $i <= 9; $i += 2) {
		&ex('printuntil', $i, $i, $topic_number, "$L{BPIMGUPLOADTITLE3_00}");
	}
	print "$L{BPIMGUPLOADINSTR3_00}<P>\n";
	print "<FORM ACTION=\"$script_url/board-image.$cgi_extension\" METHOD=POST ENCTYPE=\"multipart/form-data\">\n";
	print "<HR>\n";
	for ($i = 11; $i <= 13; $i += 2) {
		&ex('printuntil', $i, $i, $topic_number);
	}
	$message = $string;
	while ($source_out =~ m|\\image_notuploaded\{(\d+),([^\}]*)\}|g) {
		$ctr = $1; $descr = $2;
		print "$L{BPPROVIDEFILE} <B>$descr</B>:<P>\n";
		print "<TABLE><TR><TD><INPUT TYPE=FILE NAME=\"Image$ctr\" SIZE=40></TD></TR></TABLE>\n";
		print "<HR>\n";
	}
	while ($source_out =~ m|\\attachment_notuploaded\{(\d+),([^\}]*)\}|g) {
		$ctr = $1; $descr = $2;
		print "$L{BPPROVIDEFILE} <B>$descr</B>:<P>\n";
		print "<TABLE><TR><TD><INPUT TYPE=FILE NAME=\"Attachment$ctr\" SIZE=40></TD></TR></TABLE>\n";
		print "<HR>\n";
	}
	print "<INPUT TYPE=SUBMIT VALUE=\"$L{BPIMGUPLOADBUTTON}\">\n";
	print "<INPUT TYPE=HIDDEN NAME=name VALUE=\"$username_input\">\n";
	print "<INPUT TYPE=HIDDEN NAME=number VALUE=\"$FORM{'number'}\">\n";
	print "<INPUT TYPE=HIDDEN NAME=HTTP_REFERER VALUE=\"//$topic_number/$me_number.$ext\">\n";
	print "<INPUT TYPE=HIDDEN NAME=postindex VALUE=\"$postindex\">\n";
	print "<INPUT Type=hidden name=\"isitok\" value=\"okiedokie\">\n" if $FORM{'isitok'} eq "okiedokie";
	print "<INPUT TYPE=HIDDEN NAME=queue VALUE=\"$queue_id\">\n";
	print "<INPUT TYPE=HIDDEN NAME=sourceover VALUE=\"", &escape($source_out), "\">\n";
	print "<HR>\n";
	print "</FORM>\n";
	if ($FORM{'isitok'} ne "okiedokie") {
		print "$L{BPIMGUPLOADCANCEL13_00} <A HREF=\"$url\">\n";
	} else {
		print "$L{BPIMGUPLOADCANCEL13_00} <A HREF=\"$cgiurlm$adminappend\">\n";
	}
	print "$L{BPIMGUPLOADCANCEL2}</A>. ";
	print "$L{BPIMGUPLOADCANCEL33_00}\n";
	print "<BR></FONT>\n";
	for ($i = 15; $i <= 17; $i += 2) {
		&ex('printuntil', $i, $i, $topic_number);
	}
	exit(0);
} else {
	&ex('queue_submitted', $topic_number, $me_number, $adminappend, $FORM{'isitok'}) if $queue;
	$secure = 0;
	$secure = 1 if !-e "$message_dir/$topic_number";
	$secure = 0 if !$pro;
	$ts = time;
	$url = "$message_url/$topic_number/$me_number.$ext" if !$secure;
	$url .= "?$ts" if (!$noqm && !$secure);
	$url = "$script_url/board-auth.$cgi_extension?file=/$topic_number/$me_number.$ext&lm=$ts" if $secure;
	&seturl("$url") if $FORM{'isitok'} ne "okiedokie";
	&seturl("$cgiurlm$adminappend") if $FORM{'isitok'} eq "okiedokie";
}
sub verify_owner {
	my ($owner, $username) = @_;
	my (@group_data, $group, $usernames, @username, $groupname);
	open (GROUP, "$admin_dir/groups.txt") || &error_message("File Error", "Cannot open group file (groups.txt)!");
	@group_data = <GROUP>;
	close (GROUP);
	foreach $group (@group_data) {
		chop ($group) if $group =~ /\n$/;
		($groupname, $usernames) = split(/:/, $group);
		if ($groupname eq $owner) {
			@username = split(/,/, $usernames);
			if (grep (/^$username$/, @username)) {
				return 1;
			} else {
				return 0;
			}
		}
	}
	return 0;
}
# END - FILE IS CORRECTLY UPLOADED #
