# FILE: src-board-subs-10
#-------------------------------------------------------------------------------
# This script is copyright (c) 1998 by DiscusWare, LLC, all rights reserved.
# Its use is subject to the license agreement that can be found at the following
# URL:  http://www.chem.hope.edu/discus/license
#-------------------------------------------------------------------------------

#---SEPARATOR---#

sub compare_profiles {
	local ($input) = @_;
	@input = split(/\n/, $input);
	local ($line, $file, $user, $pass, $email, $fullname, $edit, $notify, $lastcheck, $EMAIL_FORCE);
	foreach $line (@input) {
		($file, $user, $pass, $email, $fullname, $edit, $notify, $lastcheck) = split(/:/, $line);
		if ($edit == 2) {
			$EMAIL_FORCE = $email;
		}
	}
	$line = shift(@input);	
	($file, $user, $pass, $email, $fullname, $edit, $notify, $lastcheck) = split(/:/, $line);
	$email = $EMAIL_FORCE if $EMAIL_FORCE;
	@emt = split(/,/, $notify);
	foreach $l (@emt) {
		if ($l =~ m|^(\d+)/|) {
			$l = $1;
		}
	}
	$notify = join(",", @emt);
	$e{$email} = 1; $f{$fullname} = 1; $n{$notify} = 1;
	foreach $line (@input) {
		($file, $user, $pass, $email, $fullname, $edit, $notify, $lastcheck) = split(/:/, $line);
		$email = $EMAIL_FORCE if $EMAIL_FORCE;
		@emt = split(/,/, $notify);
		foreach $l (@emt) {
			if ($l =~ m|^(\d+)/|) {
				$l = $1;
			}
		}
		$notify = join(",", @emt);
		return 1 if !$n{$notify};
		return 1 if !$e{$email};
		return 1 if !$f{$fullname};
	}
	return 0;
}

#---SEPARATOR---#
#REQ:printuntil

sub display_profile_differences {
	local ($username, $password, $input) = @_;
	@input = split(/\n/, $input);
	open (TOP, "$message_dir/board-topics.html"); @top = <TOP>; close (TOP);
	@tpc = grep(/<!-Top/, @top);
	foreach $line (@tpc) {
		if ($line =~ m|<!-Top: (\d+)-!>|) {
			$t = $1; &extract("//$t/$t.$ext"); $topic{$t} = &remove_html($topic_name);
		}
	}
	&header;
	&printuntil(1, 1, 0, $L{PROFILE_SYNC_TITLE});
	print "<FONT SIZE=3><CENTER><B>$L{PROFILE_SYNC_TITLE}</B></CENTER></FONT>\n";
	print "<HR>\n";
	print $L{PROFILE_SYNC_DESCR};
	print "<P><CENTER><TABLE BORDER=0><TR>\n";
	$ct = 0;
	foreach $line (@input) {
		$line =~ s/\n$//;
		($file, $user, $pass, $email, $fullname, $edit, $notify, $last, $group)	= split(/:/, $line);
		@emt = split(/,/, $notify);
		foreach $l (@emt) {
			if ($l =~ m|^(\d+)/|) {
				$l = $1;
			}
		}
		$notify = join(",", @emt);
		print "<TD VALIGN=TOP>\n" if $ct == 0;
		print "<TD>&nbsp;</TD><TD VALIGN=TOP>" if $ct == 1;
		print "</TR><TR><TD VALIGN=TOP>" if $ct == 2;
		$ct += 1; $ct = 1 if $ct >= 3;
		print "<TABLE BORDER=1><TR><TD>\n";
		print "<FORM ACTION=$script_url/board-profile.$cgi_extension METHOD=POST>\n";
		print "<FONT FACE=\"$face\" SIZE=\"$size\">\n";
		print "<U>$L{PROFEDIT_INFO}</U><BR>\n";
		print "\u$user<BR>\n";
		print "$email<BR>\n";
		print "$fullname<P>\n";
		print "<U>$L{PROFEDIT_EMAILNOTIFY}</U><BR>\n";
		foreach $line_n (split(/,/, $notify)) {
			print "- ", substr($topic{$line_n}, 0, 30) if $topic{$line_n} ne "";
			print "..." if length($topic{$line_n}) > 30;
			print "<BR>\n" if $topic{$line_n} ne "";
		}
		print "- $L{PROFILE_MYPOSTS}<BR>\n" if grep(/^0$/, split(/,/, $notify));
		print "<P><CENTER><INPUT TYPE=SUBMIT VALUE=\"$L{PROFILE_CHOOSETHISONE}\"></CENTER>\n";
		print "<INPUT TYPE=HIDDEN NAME=action VALUE=\"sync\">\n";
		print "<INPUT TYPE=HIDDEN NAME=file VALUE=\"$file\">\n";
		print "<INPUT TYPE=HIDDEN NAME=group VALUE=\"$group\">\n";
		print "<INPUT TYPE=HIDDEN NAME=username VALUE=\"$username\">\n";
		print "<INPUT TYPE=HIDDEN NAME=password VALUE=\"$password\">\n";
		print "</FORM></TD></TR></TABLE></TD>\n";
	}
	print "</TR></TABLE></CENTER>\n";
	&printuntil(3, 17, 0, "", 0, 1);
	exit(0);
}

#---SEPARATOR---#

sub data_recovery {
	&header;
	print "<HTML><HEAD><TITLE>Data Recovery</TITLE></HEAD>\n";
	print '<BODY BGCOLOR="ffffff" TEXT="000000" LINK="0000FF" VLINK="0000FF" ';
	print "onLoad=\"window.defaultStatus = 'Data Recovery'\">$fs\n";
	print "<FONT SIZE=3><CENTER><B>Data Recovery</B></CENTER></FONT>\n";
	print "<HR>\n";
	if (open (TOP, "$message_dir/board-topics.html")) {
		@top = <TOP>;
		close (TOP);
	} else {
		if (open (TOP, ">$message_dir/board-topics.html")) {
			print TOP "\n";
			close (TOP);
		} else {	
			print "The problem is that the script cannot read the board-topics.html file,\n";
			print "probably because your specification of the HTML directory is not correct.\n";
			print "The reason the system cannot read the file is: <B>$!</B>.<P>";
			print "If this is something to the effect of &quot;No such file or directory&quot;\n";
			print "then you need to correct your setting of the HTML directory by editing your\n";
			print "discus.conf file.<P>\n";
			print "</TD></TR></TABLE></BODY></HTML>";
			exit(0);
		}
	}
	if (!grep(/^<!-Top: (\d+)-!>/, @top)) {
		print "The data recovery utility has detected that the topics page has been\n";
		print "corrupted, probably due to editing the file with an HTML editor.\n";
		print "<P>This message could also occur if you have not ever created any topics\n";
		print "on your board.<P>\n";
		print "<FORM ACTION=$cgiurl METHOD=POST>\n";
		print "<TABLE BORDER=1 BGCOLOR=#ffffcc WIDTH=100%><TR><TD>$fs";
		print "You have two options for recovery:<P>\n";
		print "<INPUT TYPE=RADIO NAME=rectype VALUE=1 CHECKED><B>Salvage Page</B>\n";
		print "<UL>This will attempt to save as much information as possible from your\n";
		print "page (such as topic names, descriptions, last modified times, and so\n";
		print "on).  Depending on the extent of corruption, this may or may not find\n";
		print "any topics.  We recommend that you use this option first, and if it does\n";
		print "not work, use the regeneration option below.</UL><P>\n";
		print "<INPUT TYPE=RADIO NAME=rectype VALUE=2><B>Regenerate Page</B>\n";
		print "<UL>This will regenerate all of the topics on the topics page, but you\n";
		print "will lose all topic descriptions, the main message, and anything else\n";
		print "that ordinarily is displayed on the top page.  We recommend this option\n";
		print "only in those cases where &quot;Salvage Page&quot; fails.</UL><P>\n";
		print "<INPUT TYPE=SUBMIT VALUE='Run Data Recovery'>\n";
		print "</TD></TR></TABLE>\n";
		print "<INPUT TYPE=HIDDEN NAME=username VALUE=$superuser>\n";
		print "<INPUT TYPE=HIDDEN NAME=action VALUE=data_recovery_top>\n";
		print "</FORM>\n";
		print "</BODY></HTML>\n";
		exit(0);
	}	
	print "The data recovery utility allows you to fix pages which have been corrupted\n";
	print "or inadvertantly deleted from your board.  In most cases, subtopic data can\n";
	print "be re-created by analyzing the other files in the topic directory.  However,\n";
	print "the text of any messages is permanently lost unless you restore from a backup.<P>\n";
	print "<FORM ACTION=$cgiurl METHOD=POST>\n";
	print "<TABLE BORDER=1 BGCOLOR=#ffffcc WIDTH=100%><TR><TD>$fs";
	print "Select the name of the topic that contains the corrupted page from the list\n";
	print "below.  If you want the Data Recovery procedure to automatically fix the\n";
	print "corrupted file for you, make sure &quot;Automically Fix Errors&quot; is checked.\n";
	print "<P>Topic name: <SELECT NAME=topic SIZE=1>\n";
	@topics = grep(/<!-Top:/, @top);
	foreach $line (@topics) {
		$line =~ m|<!-Top: (\d+)-!>.*<a[^>]+>(.*)</A>|i;
		$topic_number = $1; $topic_name = &remove_html($2);
		print "<OPTION VALUE=$topic_number>$topic_name\n";
	}
	print "</SELECT>\n";
	print "<P><INPUT TYPE=CHECKBOX NAME=fixem VALUE=1 CHECKED> Automatically Fix Errors\n";
	print "<P><INPUT TYPE=SUBMIT VALUE=\"Run Data Recovery\">\n";
	print "</TD></TR></TABLE>\n";
	print "<INPUT TYPE=HIDDEN NAME=username VALUE=$superuser>\n";
	print "<INPUT TYPE=HIDDEN NAME=action VALUE=data_recovery>\n";
	print "</FORM>\n";
	print "</BODY></HTML>\n";
	exit(0);
}

#---SEPARATOR---#

sub data_recovery_action {
	local ($topic, $autofix) = @_;
	$topic =~ s/\D//g;
	$page =~ s/\D//g;
	if (!-e "$message_dir/$topic" && !-e "$secdir/$topic") {
		&error_message("Topic Specification Error", "The requested topic does not have its own subdirectory.");
	}
	undef %head_content; undef %parent; undef %sub_content;
	if (-e "$message_dir/$topic") {
		opendir(MESSAGEDIR, "$message_dir/$topic");
	} else {
		opendir(MESSAGEDIR, "$secdir/$topic");
	}
	undef @filelist;
	while ($file = readdir(MESSAGEDIR)) {
		push (@filelist, $file);
	}
	@filelist = grep(/^(\d+)\.$ext$/, @filelist);
	undef @corrupt;
	foreach $file (@filelist) {
		$file =~ s/\D//g;
		($head, $color, $lm, $announce, $announce_src, $sublist, $about, $about_src, $message, $message_src) = &get_page($topic, $file);
		$head{$file} = $head;
		$wf = $file if $head ne "";
		$color_works = $color if $head ne "";
		$sublist{$file} = $sublist;
		push (@corrupt, $file) if $head eq "";
	}
	foreach $file (keys(%head)) {
		$head = $head{$file};
		if ($head =~ m|<!--Parent: (\d+)-->|) {
			$p = $1;
			$parent{$file} = $p;
			if ($head{$p} eq "") {
				push (@corrupt, $p) if !grep(/^$p$/, @corrupt);
			} else {
				$wf = $file;
			}
		}
		$st = $sublist{$file}; @st = split(/\n/, $st); @st = grep(/<!-Top:/, @st);
		foreach $s (@st) {
			$s =~ m|<!-Top: (\d+)-!>|; $sl = $1;
			if ($head{$sl} eq "") {
				push (@corrupt, $sl) if !grep(/^$sl$/, @corrupt);
			}
			$parent{$sl} = $file;
		}
	}
	$fixed = 0; undef @fixedpage; $sls = "";
	if (scalar(@corrupt)) {
		foreach $f (@corrupt) {
			if ($f == $topic) {
				if ($wf != 0) {
					($head, $color, $lm, $announce, $announce_src, $sublist, $about, $about_src, $message, $message_src) = &get_page($f, $wf);
					@h = split(/\n/, $head{$wf});
					@h = grep(!/^<!--Me:/, @h);
					@h = grep(!/^<!--Parent:/, @h);
					@h = grep(!/^<!--Param:/, @h);
					@h = grep(!/^<!--Level /, @h);
					($t) = grep(/<!--Topic:/, @h);
					$t =~ m|<!--Topic: (\d+)/(.*)-->|;
					push (@h, "<!--Me: $f/$2-->"); $fixedname{$f} = $2;
					push (@h, "<!--Param: Sublist-->");
					$fixed += 1; push (@fixed, $f);
				}
			} else {
				foreach $key (keys(%parent)) {
					$fixedit = 0;
					if ($parent{$key} == $f) {
						@h = split(/\n/, $head{$key});
						@h = grep(!/^<!--Me:/, @h);
						@h = grep(!/^<!--Parent:/, @h);
						@h = grep(!/^<!--Param:/, @h);
						$ml = 0;
						foreach $l (@h) {
							if ($l =~ m|<!--Level (\d+):|) {
								$ml = $1 if $1 > $ml;
							}
						}
						$mlm1 = $ml - 1;
						($t) = grep(/<!--Level $mlm1:/, @h);
						$t =~ m|<!--Level (\d+): (\d+)/(.*)-->|;
						push (@h, "<!--Me: $2/$3-->"); $fixedname{$f} = $3;
						@h = grep(!/^<!--Level $ml:/, @h);
						$mlm2 = $ml - 2;
						if (($t) = grep(/<!--Level $mlm1:/, @h)) {
							$t =~ m|<!--Level (\d+): (\d+)/|;
							push (@h, "<!--Parent: $2-->");
						} else {
							push (@h, "<!--Parent: $topic-->");
						}
						$fixed += 1; push (@fixed, $f); $fixedit = 1;
						push (@h, "<!--Param: Sublist-->");
						last;					
					}
				}
				if ($fixedit == 0) {
					$mlp1 = $ml + 1;
					$p = $parent{$f};
					@h = split(/\n/, $head{$p});
					@h = grep(!/^<!--Me:/, @h);
					@h = grep(!/^<!--Parent:/, @h);
					@h = grep(!/^<!--Param:/, @h);
					$ml = 0;
					foreach $l (@h) {
						if ($l =~ m|<!--Level (\d+):|) {
							$ml = $1 if $1 > $ml;
						}
					}
					$mlp1 = $ml + 1;
					$st = $sublist{$p}; @st = split(/\n/, $st); @st = grep(/<!-Top:/, @st);
					$this_name = "(Untitled)";
					foreach $s (@st) {
						if ($s =~ m|^<!-Top: $f-!>|) {
							$s =~ m|<A[^>]+>(.*)</A>|i; $this_name = $1;
						}
					}
					push (@h, "<!--Level $mlp1: $f/$this_name-->");
					push (@h, "<!--Me: $f/$this_name-->");
					push (@h, "<!--Param: MessagesAdd-->");
					push (@h, "<!--Parent: $parent{$f}-->");
					$fixed += 1; push (@fixed, $f); $fixedit = 1;
					$fixedname{$f} = "$this_name";
				}
			}
			$h = join("\n", @h);
			foreach $key (keys(%parent)) {
				if ($parent{$key} == $f) {
					$head{$key} =~ m|<!--Me: (\d+)/(.*)-->|;
					$me_number = $1; $me_name = $2;
					($ts) = &ex('get_date_time', 'short');
					$sls .= "<!-Top: $me_number-!><LI><A HREF=\"$message_url/$topic/$me_number.$ext\"";
					$sls .= " onMouseOver=\"return setStatus('" . &JavaScript_prepare($me_name) . "')\">";
					$sls .= "$me_name</A> <FONT SIZE=\"-1\">$ts</FONT></LI><P>\n";						
				}
			}				
			&set_page($topic, $f, $h, $color_works, "", "", "", $sls, "", "", "", "") if $autofix;
		}
	}
	&header;
	print "<HTML><HEAD><TITLE>Data Recovery Report</TITLE></HEAD>\n";
	print '<BODY BGCOLOR="ffffff" TEXT="000000" LINK="0000FF" VLINK="0000FF" ';
	print "onLoad=\"window.defaultStatus = 'Data Recovery Report'\">$fs\n";
	print "<FONT SIZE=3><CENTER><B>Data Recovery Report</B></CENTER></FONT>\n";
	print "<HR>\n";
	if (scalar(@corrupt) == 0) {
		print "The data recovery utility was not able to find any corrupted pages in\n";
		print "this topic.  If any page has become corrupted, you should either delete\n";
		print "that page or regenerate it by making a change to it using one of the\n";
		print "administrative tools.\n";
	} else {
		print "The data recovery utility detected <B>", scalar(@corrupt), "</B> corrupted page";
		print "s" if scalar(@corrupted) > 1;
		print " in this topic.\n";
		print "Of these errors, <B>$fixed</B> ";
		print "were" if ($fixed != 1 && $autofix);
		print "was" if ($fixed == 1 && $autofix);
		print "can be" if !$autofix;
		print " fixed.<P>\n";
		if ($fixed > 0 && $autofix) {
			print "Note that the subtopics on the pages that were fixed will likely be in\n";
			print "a different order than they were before the page was lost.  Thus, you\n";
			print "should access the Page Manager to reorder the subtopics if necessary.\n";
			print "<P>\n";
		}
		if ($autofix) {
			print "The following pages were fixed:<P><UL>\n";
			foreach $l (@fixed) {
				print "<LI><A HREF=\"$cgiurlm?action=page_editor&username=$superuser&HTTP_REFERER=//$topic/$l.$ext\" onMouseOver=\"window.status = 'Edit this subtopic'; return true\">";
				print "$fixedname{$l}</A>\n";
			}
			print "</UL>\n";
		} else {
			print "The following pages can be fixed:<P><UL>\n";
			foreach $l (@fixed) {
				print "<LI>$fixedname{$l}<P>\n";
			}
			print "</UL><P>\n";
			print "<FORM ACTION=\"$cgiurl\" METHOD=POST>\n";
			print "<INPUT NAME=action VALUE=data_recovery TYPE=HIDDEN>\n";
			print "<INPUT TYPE=HIDDEN NAME=username VALUE=$username>\n";
			print "<INPUT TYPE=HIDDEN NAME=topic VALUE=$topic>\n";
			print "<INPUT TYPE=HIDDEN NAME=fixem VALUE=1>\n";
			print "<INPUT TYPE=SUBMIT VALUE='Fix Errors'>\n";
			print "</FORM>\n";
		}
	}
	print "</BODY></HTML>\n";
	exit(0);	
}

#---SEPARATOR---#

sub data_recovery_top {
	local ($option) = @_;
	if ($FORM{'rectype'} == 2) {
		opendir(DIR, "$message_dir");
		undef @dir;
		while ($dir = readdir(DIR)) {
			push (@dir, $dir) if $dir =~ m|^(\d+)$|;
		}
		closedir(DIR);
		opendir(DIR, "$secdir");
		while ($dir = readdir(DIR)) {
			push (@dir, $dir) if $dir =~ m|^(\d+)$|;
		}
		closedir(DIR);
		open (FILE, ">$message_dir/board-topics.html");
		foreach $line (@dir) {
			print FILE "<!-Top: $line-!>\n";
		}
		close (FILE);
	}	
	($bgcolor, $text, $link, $vlink, $alink, $font, $size, $bg) = &ex('extract_colorsonly', 1);
	&ex('change_board_colors', $bgcolor, $text, $link, $vlink, $alink, $font, $size, $bg, 0, -45);
	open (FILE, "$admin_dir/frontpage_conf.txt"); @file = <FILE>; close (FILE);
	foreach $line (@file) {
		if ($line =~ m|^(\w+)=(\d+)|) {
			$FORM{$1} = $2;
		}
	}
	if ($FORM{'Bold'}) { $boldon = 1; } else { $boldon = 0; }
	if ($FORM{'Group'}) { $groupon = 1; } else { $groupon = 0; }
	if ($FORM{'Date'}) { $dateon = 1; } else { $dateon = 0; }
	if ($FORM{'Logo'}) { $logoon = 1; } else { $logoon = 0; }
	&ex('change_board_toppage', $boldon, $groupon, $dateon, $logoon);
	&ex('board_manager', $FORM{"username"}); exit(0);
	exit(0);
}

#---SEPARATOR---#

sub auto_configure_email {
	# This automatically configures e-mail notification if the email.txt file does
	# not contain the necessary information.
	
	# If email.txt is good, we exit
	
	if (open(EMAIL, "$admin_dir/email.txt")) {
		@email = <EMAIL>;
		close (EMAIL);
		if (grep(/^command_line=/, @email)) {
			return 1;
		}
	}
	
	undef %EMT_params;
	
	# See if there is a send_mail.conf file
	
	if (open(SMC, "$admin_dir/send_mail.conf")) {
		@smc = <SMC>;
		close (SMC);
		undef @res;
		foreach $line (@smc) {
			$line =~ s/#(.*)//;
			$line =~ s/^\s+//;
			$line =~ s/\s+$//;
			next if $line !~ /\S/;
			next if $line =~ /^#/;
			$line =~ s/\s+/ /g;
			push (@res, $line);
		}
		foreach $line (@res) {
			$line =~ m|^(\w+)\s?=\s?(.*)|; ($varname, $param) = ($1, $2);
			$P{$varname} = $param;
		}
		if ($P{'program_path'}) {
			$EMT_params{'command_line'} = "| $P{'program_path'}";
			$EMT_params{'mail_program'} = $P{'program_path'};
			if ($P{'command_line'}) {
				$EMT_params{'command_line'} .= " $P{'command_line'}";
				$EMT_params{'commandline'} = $P{'command_line'};
			}
		}
		if ($P{'from'}) {
			if ($P{'from'} =~ m|([\w\-\+\.]+)\@([\w\-\+\.]+)|) {
				$EMT_params{'fromaddr'} = "$1\@$2";
				$EMT_params{'fromname'} = join("", $`, $');
				$EMT_params{'fromname'} =~ s/[^\w\s]//g;
			} else {		
				$EMT_params{'fromname'} = $P{'from'};
				$EMT_params{'fromaddr'} = "";
			}
		} else {
			$EMT_params{'fromname'} = $titlej;
			$EMT_params{'fromaddr'} = "";
		}
		if ($P{'subject'}) {
			$EMT_params{'static'} = $P{'subject'};
		} else {
			$EMT_params{'static'} = "E-mail Notification of Post";
		}
		if ($P{'from_name'}) {
			if ($P{'from_name'} =~ m|<(.*)>|) {
				$EMT_params{'fromaddress'} = 0;
				$EMT_params{'fromaddress_prefix'} = $1;
				$EMT_params{'fromaddress_switch'} = "";
				$EMT_params{'input_stream'} .= "$1: \$FROM\n";
			} else {
				$EMT_params{'fromaddress'} = 1;
				$EMT_params{'fromaddress_prefix'} = "";
				$EMT_params{'fromaddress_switch'} = "-$P{'from_name'}";
				$EMT_params{'command_line'} .= " -$P{'from_name'} '\$FROM'";
			}			
		}
		if ($P{'subj'}) {
			if ($P{'subj'} =~ m|<(.*)>|) {
				$EMT_params{'subjectaddress'} = 0;
				$EMT_params{'subjectaddress_prefix'} = $1;
				$EMT_params{'subjectaddress_switch'} = "";
				$EMT_params{'input_stream'} .= "$1: \$SUBJECT\n";
			} else {
				$EMT_params{'subjectaddress'} = 1;
				$EMT_params{'subjectaddress_prefix'} = "";
				$EMT_params{'subjectaddress_switch'} = "-$P{'subj'}";
				$EMT_params{'command_line'} .= " -$P{'subj'} '\$SUBJECT'";
			}			
		}
		if ($P{'to'}) {
			if ($P{'to'} =~ m|<(.*)>|) {
				$EMT_params{'toaddress'} = 0;
				$EMT_params{'toaddress_prefix'} = $1;
				$EMT_params{'toaddress_switch'} = "";
				$EMT_params{'input_stream'} .= "$1: \$TO\n";
			} else {
				$EMT_params{'toaddress'} = 1;
				$EMT_params{'toaddress_prefix'} = "";
				$EMT_params{'toaddress_switch'} = "-$P{'to'}" if $P{'to'} ne "";
				$EMT_params{'command_line'} .= " -$P{'to'} '\$TO'" if $P{'to'} ne "";
				$EMT_params{'command_line'} .= " \$TO" if $P{'to'} eq "";
			}			
		}
	}
	if ($EMT_params{'mail_program'} eq "") {
		if ($mailprog =~ m|/sendmail|) {
			$EMT_params{'command_line'} = "| $mailprog -t";
			$EMT_params{'mail_program'} = $mailprog;
			$EMT_params{'commandline'} = "-t";
			$EMT_params{'toaddress'} = 0;
			$EMT_params{'toaddress_prefix'} = "TO:";
			$EMT_params{'toaddress_switch'} = "";
			$EMT_params{'fromaddress'} = 0;
			$EMT_params{'fromaddress_prefix'} = "FROM:";
			$EMT_params{'fromaddress_switch'} = "";
			$EMT_params{'subjectaddress'} = 0;
			$EMT_params{'subjectaddress_prefix'} = "SUBJECT:";
			$EMT_params{'subjectaddress_switch'} = "";
			$EMT_params{'input_stream'} = "TO: \$TO\nFROM: \$FROM\nSUBJECT: \$SUBJECT\n";
		} elsif ($mailprog =~ m|/mail|) {
			$EMT_params{'command_line'} = "| $mailprog -s '\$SUBJECT' \$TO";
			$EMT_params{'mail_program'} = $mailprog;
			$EMT_params{'commandline'} = "";
			$EMT_params{'toaddress'} = 1;
			$EMT_params{'toaddress_prefix'} = "TO:";
			$EMT_params{'toaddress_switch'} = "";
			$EMT_params{'fromaddress'} = 2;
			$EMT_params{'fromaddress_prefix'} = "";
			$EMT_params{'fromaddress_switch'} = "";
			$EMT_params{'subjectaddress'} = 1;
			$EMT_params{'subjectaddress_prefix'} = "";
			$EMT_params{'subjectaddress_switch'} = "-s";
		}			
	}
	if ($EMT_params{'mail_program'} eq "") {
		@sp = ("/usr/bin", "/bin", "/usr/sbin", "/sbin", "/usr/local/bin", "/usr/local/sbin", "/usr/contrib/bin", "/usr/contrib/sbin", "/usr/lib", "/lib", "/etc", "/");
		foreach $p (@sp) {
			if (-x "$p/sendmail") {
				$EMT_params{'command_line'} = "| $p/sendmail -t";
				$EMT_params{'mail_program'} = "$p/sendmail";
				$EMT_params{'commandline'} = "-t";
				$EMT_params{'toaddress'} = 0;
				$EMT_params{'toaddress_prefix'} = "TO:";
				$EMT_params{'toaddress_switch'} = "";
				$EMT_params{'fromaddress'} = 0;
				$EMT_params{'fromaddress_prefix'} = "FROM:";
				$EMT_params{'fromaddress_switch'} = "";
				$EMT_params{'subjectaddress'} = 0;
				$EMT_params{'subjectaddress_prefix'} = "SUBJECT:";
				$EMT_params{'subjectaddress_switch'} = "";
				$EMT_params{'input_stream'} = "TO: \$TO\nFROM: \$FROM\nSUBJECT: \$SUBJECT\n";
				last;
			}
		}
	}
	if ($EMT_params{'mail_program'} eq "") {
		@sp = ("/usr/bin", "/bin", "/usr/sbin", "/sbin", "/usr/local/bin", "/usr/local/sbin", "/usr/contrib/bin", "/usr/contrib/sbin", "/usr/lib", "/lib", "/etc", "/");
		foreach $p (@sp) {
			if (-x "$p/mail") {
				$EMT_params{'command_line'} = "| $p/mail -s '\$SUBJECT' \$TO";
				$EMT_params{'mail_program'} = "$p/mail";
				$EMT_params{'commandline'} = "";
				$EMT_params{'toaddress'} = 1;
				$EMT_params{'toaddress_prefix'} = "TO:";
				$EMT_params{'toaddress_switch'} = "";
				$EMT_params{'fromaddress'} = 2;
				$EMT_params{'fromaddress_prefix'} = "";
				$EMT_params{'fromaddress_switch'} = "";
				$EMT_params{'subjectaddress'} = 1;
				$EMT_params{'subjectaddress_prefix'} = "";
				$EMT_params{'subjectaddress_switch'} = "-s";
			}
		}
	}
	$EMT_params{'1message'} = 0;
	$EMT_params{'sendtext'} = 1;
	$EMT_params{'tempfile'} = 0;
	$EMT_params{'subjectline'} = 0;
	if ($EMT_params{'fromaddr'} eq "") {
		if ($contact =~ m|<A HREF="mailto:([^"]+)"|) {
			$EMT_params{'fromaddr'} = $1;
		}
	}
	$EMT_params{'fromname'} = &JavaScript_prepare($title) if $EMT_params{'fromname'} eq "";
	if ($FORM{'fromaddr'} eq "") {
		$fromstring = "\"$EMT_params{'fromname'}\" <nobody\@localhost>";
	} else {
		$fromstring = "\"$EMT_params{'fromname'}\" <$EMT_params{'fromaddr'}>";
	}
	$EMT_params{'command_line'} =~ s/\$FROM/$fromstring/g;
	$EMT_params{'input_stream'} =~ s/\$FROM/$fromstring/g;
	$EMT_params{'static'} = "E-mail Notification of Post" if $EMT_params{'static'} eq "";
	$EMT_params{'input_stream'} = &escape($EMT_params{'input_stream'});
	&lock("$admin_dir/email.txt");
	open (EMAIL, ">$admin_dir/email.txt");
	foreach $key (keys(%EMT_params)) {
		print EMAIL "$key=$EMT_params{$key}\n";
	}
	close (EMAIL);
	&unlock("$admin_dir/email.txt");
}

#---SEPARATOR---#

sub admin_from_here {
	if (open(HTML, "$html_dir/admin.html")) {
		@html = <HTML>;
		close (HTML);
	} else {
		&seturl("$html_url/admin.html");
		exit(0);
	}
	foreach $line (@html) {
		if ($line =~ m|board-admin-menuonly.$cgi_extension|) {
			$line = join("", $`, $&, "?startfrom=$FORM{'startfrom'}", $');
		}
	}
	&header;
	print @html;
	exit(0);	
}
