# FILE: src-board-subs-1
# Board Manager and topic management
#-------------------------------------------------------------------------------
# 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.
#-------------------------------------------------------------------------------

#---SEPARATOR---#

sub board_manager {
	my ($username); $username = $superuser;
	$append = "?username=$username&action=menu";
	open (FILE, "$message_dir/$board_topics_file") || &error_message("File Error", "Could not open top file ($board_topics_file).");
	@lines = <FILE>;
	close(FILE);
	undef @topic_number;
	undef @topic_name;
	undef @group;
	$count = 0;
	$topics = "";
	foreach $line (@lines) {
		$_ = $line;
		if (/<!-Top: (\d+)-!>/) {
			$count = $count + 1;
			$filename = "$message_dir/$1/$1.$ext";
			$num = $1;
			push (@topic_number, $1);
			$ev{$num} = &extract ($filename, 1);
			push (@topics, "$num:$topic_name (\u$owner)");
			push (@group, $owner);
		}
	}
	&header;
	print "<HTML><HEAD><TITLE>Board Manager</TITLE>\n";
	print "<SCRIPT LANGUAGE=\"JavaScript\"> <!-- Hide\n";
	print "function subact(action, number, name1) {\n";
	print "  document.sf.SELECTION.value = action + number;\n";
	print "  if (action == 'delete') {\n";
	print "    var m = confirm(\"Are you sure you want to delete \" + name1 + \"?\");\n";
	print "    if (m == true) {\n";
	print "      document.sf.submit();\n";
	print "    }\n";
	print "  } else {\n";
	print "    document.sf.submit()\n";
	print "  }\n";
	print "}\n";
	print "function setStatus(msg) {\n";
	print "  window.status=msg\n";
	print "  return true\n";
	print "}\n";
	print "function markto(num,count,dir) {\n";
	print "  if (count == 1) {\n";
	print "    var c = document.sf.MARK.checked;\n";
	print "    document.sf.MARK.checked = 1-c;\n";
	print "  } else {\n";
	print "    var c = document.sf.MARK[num].checked;\n";
	print "    if (dir==1) {\n";
	print "      for (var i=0; i<=num; i++) {\n";
	print "        document.sf.MARK[i].checked = 1-c;\n";
	print "      }\n";
	print "    }\n";
	print "    if (dir==0) {\n";
	print "      for (var i=num; i<count; i++) {\n";
	print "        document.sf.MARK[i].checked = 1-c;\n";
	print "      }\n";
	print "    }\n";
	print "  }\n";
	print "}\n";
	print "//-->\n";
	print "</SCRIPT></HEAD>\n";
	print '<BODY BGCOLOR="ffffff" TEXT="000000" LINK="0000FF" VLINK="0000FF" ';
	print "onLoad=\"window.defaultStatus = 'Board Manager'\">$fs\n";
	print "<FONT SIZE=3><CENTER><B>Board Manager</B></CENTER></FONT>\n";
	print "<HR>\n";
	print "<A NAME=\"TitleMessage\">\n";
	print "<H3>Title Message</H3>\n";
	print "<FORM ACTION=\"$cgiurl2\" METHOD=POST>\n";
	print "<INPUT NAME=action TYPE=hidden value=\"title_message\">\n";
	print "<INPUT NAME=username TYPE=hidden value=\"$FORM{'username'}\">\n";
	print "<TABLE BGCOLOR=ffffcc BORDER=1 WIDTH=100%><TR><TD>";
	print "$fs", "Enter the text for your &quot;Title Message&quot; in the area below.  The &quot;Title Message&quot; appears <I>above</I> the list of topics, and contains the board logo by default.<P></FONT>\n";
	print "<TEXTAREA NAME=message ROWS=6 COLS=60 WRAP=VIRTUAL>";
	open (MAIN, "$message_dir/$board_topics_file");
	@main = <MAIN>;
	close (MAIN);
	$flag = 0; $source = "";
	foreach $line (@main) {
		if ($line =~ m|<!--Title Message-->|) {
			$flag = 1;
		} elsif ($line =~ m|<!--/Title Message-->|) {
			$flag = 0;
		} elsif ($flag == 1) {
			if ($line =~ /<!--Source: (.*) -->/) {
				$source = $1;
			}
			$there_is_an_hr_title = 1 if $line =~ m|^<HR>|;
		}
	}
	$source = &unescape($source);
	$source =~ s/</&lt;/g;
	$source =~ s/>/&gt;/g;
	print $source;
	print "</TEXTAREA><P>\n";
	print "<INPUT TYPE=CHECKBOX NAME=hr VALUE=1";
	print " CHECKED" if $there_is_an_hr_title;
	print ">$fs Display horizontal rule (&lt;HR&gt;) below Title Message</FONT><P>\n";
	print "<INPUT TYPE=submit NAME=submit VALUE=\"Preview/Save Message\">\n";
	print "</TD></TR></TABLE></FORM>\n";
	print "<P><HR>\n";
	print "<A NAME=\"Topics\"><H3>Topics</H3>\n";
	print "<FORM ACTION=\"$cgiurl2\" METHOD=POST NAME=sf>\n";
	print "<INPUT TYPE=HIDDEN NAME=SELECTION VALUE=\"\">\n";
	print "<TABLE CELLSPACING=0 CELLPADDING=2 BORDER=0>\n";
	$c = "ffffcc";
	$jsstr = ""; $jsstr2 = ""; $jsstr3 = "";
	print "<TR ALIGN=CENTER BGCOLOR=c0c0c0><TD>&nbsp;</TD><TD><FONT FACE=\"Verdana,Arial\" SIZE=1><B>Order</B></FONT></TD><TD>&nbsp;</TD><TD><FONT FACE=\"Verdana,Arial\" SIZE=1><B>Mark</B></FONT></TD><TD><FONT FACE=\"Verdana,Arial\" SIZE=1><B>Del</B></FONT></TD><TD><FONT FACE=\"Verdana,Arial\" SIZE=1><B>Grp</B></FONT></TD><TD BGCOLOR=c0c0c0>&nbsp;</TD><TD><FONT FACE=\"Verdana,Arial\" SIZE=1><B>Prop</B></FONT></TD><TD BGCOLOR=c0c0c0>&nbsp;</TD><TD ALIGN=LEFT><FONT FACE=\"Verdana,Arial\" SIZE=1><B>Topic (group)</B></FONT></TD><TD>&nbsp;</TD></TR>\n";
	$counter = 0; $ctr = 0; $ct = scalar(@topics);
	undef @tn;
	foreach $thing (@topics) {
		if ($thing =~ /^(\d+):(.*)/) {
			$num = $1;
			$descr = $2;
			push (@tn, $descr);
		}
	}
	undef %ps;
	@tn = sort(@tn); undef %ps; $ct = 0;
	foreach $line (@tn) {
		$ct += 1;
		$ps{$line} = $ct;
	}
	undef @txl;
	foreach $thing (@topics) {
		if ($thing =~ /^(\d+):(.*)/) {
			$num = $1;
			$descr = $2;
			print "<TR VALIGN=CENTER ALIGN=CENTER BGCOLOR=#$c><TD BGCOLOR=c0c0c0>&nbsp;</TD>";
			$counter += 1;
			if ($c eq "ffffcc") {
				$c = "ffffff";
			} else {
				$c = "ffffcc";
			}
			print "<TD ALIGN=LEFT><INPUT TYPE=TEXT NAME=ORDER$num VALUE=$counter SIZE=3></TD>";
			$jsstr .= "document.sf.ORDER$num.value = (-1 * document.sf.ORDER$num.value); ";
			$jsstr2 .= "document.sf.ORDER$num.value = '$ps{$descr}'; ";
			$jsstr3 .= "document.sf.ORDER$num.value = '" . (scalar(keys(%ps))-$ps{$descr}+1) . "'; ";
			print "<TD BGCOLOR=c0c0c0>&nbsp;</TD>\n";
			print "<TD>";
			print "<A HREF=\"#\" onClick=\"markto($ctr, $ct, 1);return false\" onMouseOver=\"return setStatus('Toggle marks at and above this point')\"><IMG SRC=\"$html_url/icons/mark_up.gif\" HEIGHT=12 WIDTH=12 BORDER=0></A>&nbsp;";
			print "<A HREF=\"#\" onClick=\"markto($ctr, $ct, 0);return false\" onMouseOver=\"return setStatus('Toggle marks at and below this point')\"><IMG SRC=\"$html_url/icons/mark_down.gif\" HEIGHT=12 WIDTH=12 BORDER=0></A>&nbsp;";
			$ctr += 1;
			print "<INPUT TYPE=CHECKBOX NAME=MARK VALUE=$num>&nbsp;&nbsp;</TD>";
			$name2 = &JavaScript_prepare($descr);
			print "<TD><A HREF=\"javascript:subact('delete', '$num', '$name2')\" onMouseOver=\"return setStatus('Delete this topic')\"><IMG SRC=\"$html_url/icons/delete_icon.gif\" HEIGHT=25 WIDTH=25 BORDER=1></A></TD>";
			print "<TD><A HREF=\"javascript:subact('group', '$num', '$name2')\" onMouseOver=\"return setStatus('Change group of this topic')\"><IMG SRC=\"$html_url/icons/group_icon.gif\" HEIGHT=25 WIDTH=25 BORDER=1></A></TD>" if $ev{$num};
			print "<TD>&nbsp;</TD>" if !$ev{$num};
			print "<TD BGCOLOR=c0c0c0>&nbsp;</TD>\n";
			print "<TD><A HREF=\"javascript:subact('properties', '$num', '$name2')\" onMouseOver=\"return setStatus('Set properties for this topic (rename topic / front page description)')\"><IMG SRC=\"$html_url/icons/properties_icon.gif\" HEIGHT=25 WIDTH=25 BORDER=1></A></TD>" if $ev{$num};
			print "<TD>&nbsp;</TD>" if !$ev{$num};
			print "<TD BGCOLOR=c0c0c0>&nbsp;</TD>\n";
			print "<TD WIDTH=100% ALIGN=LEFT>$fs";
			print "<A HREF=\"$cgiurlm?username=$username&action=page_editor" if $ev{$num};
			print "&HTTP_REFERER=$num/$num.$ext\" onMouseOver=\"return " if $ev{$num};
			print "setStatus('Edit this topic in the Page Manager')\">$descr</A>"  if $ev{$num};
			print "$descr" if !$ev{$num};
			&get_page($num, $num);
			print " <FONT SIZE=1>(Hidden)</FONT>" if $DP{'hidden'} == 1;
			print "</TD><TD BGCOLOR=c0c0c0>&nbsp;</TD>";
			print "</TR>\n";
			push (@txl, "<OPTION VALUE=$num>$descr\n");
		}
	}
	if ($counter > 0) {
		print "<TR BGCOLOR=#ccccff ALIGN=CENTER>";
		print "<TD BGCOLOR=c0c0c0>&nbsp;</TD>\n";
		print "<TD><A HREF=\"javascript:subact('reorder', 'all', '')\" onMouseOver=\"return setStatus('Reorder topics')\"><IMG SRC=\"$html_url/icons/reorder_icon.gif\" HEIGHT=25 WIDTH=25 BORDER=1></A></TD>";
		print "<TD BGCOLOR=c0c0c0>&nbsp;</TD>\n";
		print "<TD ALIGN=LEFT><FONT FACE=\"Verdana,Arial\" SIZE=2><B>(Marked)</B></TD>";
		print "<TD><A HREF=\"javascript:subact('delete', 'all', 'all marked topics')\" onMouseOver=\"return setStatus('Delete all marked topics')\"><IMG SRC=\"$html_url/icons/delete_icon.gif\" HEIGHT=25 WIDTH=25 BORDER=1></A></TD>";
		print "<TD><A HREF=\"javascript:subact('group', 'all', 'all marked topics')\" onMouseOver=\"return setStatus('Change group of all marked topics')\"><IMG SRC=\"$html_url/icons/group_icon.gif\" HEIGHT=25 WIDTH=25 BORDER=1></A></TD>";
		print "<TD BGCOLOR=c0c0c0>&nbsp;</TD>\n";
		print "<TD>&nbsp;</TD>";
		print "<TD BGCOLOR=c0c0c0>&nbsp;</TD>\n";
		print "<TD>&nbsp;</TD>";
		print "<TD BGCOLOR=c0c0c0>&nbsp;</TD>\n";
		print "</TR>\n";
	}
	print "<TR BGCOLOR=c0c0c0><TD COLSPAN=11>$fs<FONT SIZE=1><A HREF=\"#Topics\" onClick=\"$jsstr; return false\" onMouseOver=\"window.status = 'Reverse subtopic order'; return true\">Reverse</A> <A HREF=\"#Topics\" onClick=\"$jsstr2; return false\" onMouseOver=\"window.status = 'Sort subtopics alphabetically'; return true\">A-Z</A> <A HREF=\"#Topics\" onClick=\"$jsstr3; return false\" onMouseOver=\"window.status = 'Sort subtopics reverse alphabetically'; return true\">Z-A</A></FONT></TD></TR></TABLE>\n";
	print "<INPUT NAME=action TYPE=hidden value=\"topics\">\n";
	print "<INPUT NAME=username TYPE=hidden value=\"$FORM{'username'}\">\n";
	print "</FORM>\n";
	print "<HR>\n";
	print "<A NAME=\"AddTopic\"><H3>Add a Topic</H3>\n";
	open (GROUP, "$admin_dir/groups.txt");
	@group_input = <GROUP>;
	close (GROUP);
	@group_input = grep(/\S/, @group_input);
	undef @group_list;
	foreach $line (@group_input) {
		($group) = split(/:/, $line);
		if (!grep(/^$group$/, @group_list)) {
			push (@group_list, $group);
		}
	}
	if (!scalar(@group_list)) {
		print "Sorry, you can't create topics at this time because you have not created\n";
		print "any groups on your board.  You can create groups by going to your\n";
		print "<A HREF=\"$cgiurlm?username=$superuser&cmd=group_mgr\">Group Manager</A>.\n";
		print "<P>\n";
		print "Establishing groups and creating topics are each covered in the\n";
		print "<A HREF=\"$html_url/board-admin-instr-03.html\" TARGET=_blank>superuser getting started ";
		print "tutorial</A>.  Click the link to open this document in a new browser window.\n";
		print "<P>\n";
	} else {
		print "<FORM ACTION=\"$cgiurl2\" METHOD=POST>\n";
		print "<INPUT NAME=action TYPE=hidden value=\"Add_Topic\">\n";
		print "<INPUT NAME=username TYPE=hidden value=\"$FORM{'username'}\">\n";
		print "<TABLE BGCOLOR=ffffcc BORDER=1 WIDTH=100%><TR><TD>";
		print "<TABLE><TR><TD>$fs", "Topic Name:</TD><TD><INPUT NAME=topic TYPE=text SIZE=40 VALUE=\"\"></TD></TR>\n";
		print "<TR><TD>$fs", "Topic Group:</TD><TD><SELECT NAME=group SIZE=1>\n";
		foreach $group (sort @group_list) {
			chomp $group;
			next if $group eq "#";
			print "<OPTION VALUE=\"$group\">\u$group\n";
		}
		print "</SELECT></TD></TR>\n";
		print "<TR><TD>$fs", "Posting&nbsp;Privileges:&nbsp;&nbsp;</TD><TD>";
		print "<SELECT NAME=privs SIZE=1>\n";
		print "<OPTION VALUE=private>Private\n";
		print "<OPTION VALUE=public SELECTED>Public\n";
		print "</SELECT></TD></TR>\n";
		print "<TR><TD>$fs", "Initial&nbsp;Content:&nbsp;&nbsp;</TD><TD>";
		print "<SELECT NAME=templ SIZE=1>\n";
		print "<OPTION VALUE=no>Blank page (&quot;Private Index&quot;)\n";
		print "<OPTION VALUE=yes SELECTED>&quot;Create New Conversation&quot; button and brief message\n";
		print "</SELECT></TD></TR>\n";
		print "<TR><TD VALIGN=TOP>$fs", "<I>Optional</I> Description:&nbsp;&nbsp;</TD><TD>";
		print "<TEXTAREA NAME=descr ROWS=5 COLS=40 WRAP=VIRTUAL></TEXTAREA></TD></TR>";
		print "</TABLE>\n";
		print "<P>\n";
		print "<INPUT TYPE=submit VALUE=\"Add this Topic\">\n";
		print "</TD></TR></TABLE></FORM>\n";
	}
	print "<HR><BR>\n";
	print "<A NAME=\"MainMessage\">\n";
	print "<H3>Main Message</H3>\n";
	print "<FORM ACTION=\"$cgiurl2\" METHOD=POST>\n";
	print "<INPUT NAME=action TYPE=hidden value=\"main_message\">\n";
	print "<INPUT NAME=username TYPE=hidden value=\"$FORM{'username'}\">\n";
	print "<TABLE BGCOLOR=ffffcc BORDER=1 WIDTH=100%><TR><TD>";
	print "$fs", "Enter the text for your &quot;Main Message&quot; in the area below.  The &quot;Main Message&quot; appears <I>below</I> the list of topics.<P></FONT>\n";
	print "<TEXTAREA NAME=message ROWS=6 COLS=60 WRAP=VIRTUAL>";
	$flag = 0; $source = "";
	foreach $line (@main) {
		if ($line =~ m|<!--Message-->|) {
			$flag = 1;
		} elsif ($line =~ m|<!--/Message-->|) {
			$flag = 0;
		} elsif ($flag == 1) {
			if ($line =~ /<!--Source: (.*) -->/) {
				$source = $1;
			}
			$there_is_an_hr_main = 1 if $line =~ m|<HR>|;
		}
	}
	$source = &unescape($source);
	$source =~ s/</&lt;/g;
	$source =~ s/>/&gt;/g;
	print $source;
	print "</TEXTAREA><P>\n";
	print "<INPUT TYPE=CHECKBOX NAME=hr VALUE=1";
	print " CHECKED" if $there_is_an_hr_main;
	print ">$fs Display horizontal rule (&lt;HR&gt;) above Main Message</FONT><P>\n";
	print "<INPUT TYPE=submit NAME=submit VALUE=\"Preview/Save Message\">\n";
	print "</TD></TR></TABLE></FORM>\n";
	print "<HR><A NAME=\"COLORS\">\n";
	print "<H3>Board Appearance</H3>\n";
	print "<FORM ACTION=\"$cgiurl2\" METHOD=POST>\n";
	($bgcolor,$text,$link,$vlink,$alink,$face,$size, $image) = &extract_colorsonly;
	print "<TABLE BORDER=1 WIDTH=100% BGCOLOR=ffffcc><TR><TD>";
	print "<TABLE><TR><TD>$fs", "Background:</TD><TD><INPUT NAME=bgcolor SIZE=7 VALUE=\"$bgcolor\"></TD>\n";
	print "<TD ROWSPAN=5 ALIGN=CENTER VALIGN=TOP><TABLE BORDER=1 BGCOLOR=$bgcolor BACKGROUND=\"$image\"><TR><TD BGCOLOR=$bgcolor BACKGROUND=\"$image\">\n";
	print "<BASEFONT SIZE=$size><FONT FACE=\"$face\" SIZE=\"$size\" COLOR=\"$text\"><CENTER>THIS IS A SAMPLE OF YOUR COLORS</CENTER><P>\n";
	print "Text Color<BR>\n";
	print "<FONT COLOR=\"$link\"><U>Unvisited Link</U></FONT><BR>\n";
	print "<FONT COLOR=\"$vlink\"><U>Visited Link</U></FONT><BR>\n";
	print "<FONT COLOR=\"$alink\"><U>Active Link</U></FONT><BR>\n";
	print "<FONT SIZE=-1>Smaller Text</FONT></FONT></TD></TR></TABLE></TD>\n";
	print "</TR>\n";
	print "<TR><TD>$fs", "Text:</TD><TD><INPUT NAME=text SIZE=7 VALUE=\"$text\"></TD></TR>\n";
	print "<TR><TD>$fs", "Link:</TD><TD><INPUT NAME=link SIZE=7 VALUE=\"$link\"></TD></TR>\n";
	print "<TR><TD>$fs", "Visited Link:</TD><TD><INPUT NAME=vlink SIZE=7 VALUE=\"$vlink\"></TD></TR>\n";
	print "<TR><TD>$fs", "Active Link:</TD><TD><INPUT NAME=alink SIZE=7 VALUE=\"$alink\"></TD></TR>\n";
	print "<TR><TD>$fs", "Font Face:</TD><TD COLSPAN=2><INPUT TYPE=text NAME=face SIZE=40 VALUE=\"$face\"></TD></TR>\n";
	print "<TR><TD>$fs", "Font Size:</TD><TD COLSPAN=2><INPUT TYPE=text NAME=size size=3 VALUE=$size></TD></TR>\n";
	print "<TR><TD>$fs", "Background Image:</TD><TD COLSPAN=2><INPUT TYPE=text NAME=image size=40 VALUE=$image></TD></TR>\n";
	print "</TABLE><P>\n";
	print "<INPUT TYPE=submit NAME=submit VALUE=\"Preview/Save Appearance\">\n";
	print "<INPUT NAME=action TYPE=hidden value=\"board_appearance\">\n";
	print "<INPUT NAME=username TYPE=hidden value=\"$FORM{'username'}\">\n";
	print "</TD></TR></TABLE>\n";
	print "</FORM>\n";
	print "<HR>\n";
	print "<A NAME=\"METATAGS\">\n";
	print "<H3>META Tags</H3>\n";
	print "<FORM ACTION=\"$cgiurl2\" METHOD=POST>\n";
	print "<INPUT NAME=action TYPE=hidden value=\"meta_tags_top\">\n";
	print "<INPUT NAME=username TYPE=hidden value=\"$FORM{'username'}\">\n";
	print "<TABLE BGCOLOR=ffffcc BORDER=1 WIDTH=100%><TR><TD>";
	print "$fs", "You can specify META tags, used by search engines when indexing\n";
	print "pages, for the topics page on this board using the text entry boxes below.\n";
	print "Do <I>not</I> use HTML or Discus formatting codes in your META tags.\n";
	print "To learn more about how to use META tags, consult your favorite search\n";
	print "engine.<P>\n";
	@metatags = grep(/^<META/, @main);
	print "<TABLE>\n";
	print "<TR><TD>$fs", "Description:</TD><TD><INPUT SIZE=50 TYPE=TEXT NAME=DESCRIPTION ";
	if (($_) = grep(/^<META NAME="DESCRIPTION"/, @metatags)) {
		m|CONTENT="([^"]*)">|; print "VALUE=\"$1\"";
	}
	print "></TD></TR>\n";
	print "<TR><TD>$fs", "Key Words:</TD><TD><INPUT SIZE=50 TYPE=TEXT NAME=KEYWORDS ";
	if (($_) = grep(/^<META NAME="KEYWORDS"/, @metatags)) {
		m|CONTENT="([^"]*)">|; print "VALUE=\"$1\"";
	}
	print "></TD></TR>\n";
	print "<TR><TD>$fs", "Robots:</TD><TD><INPUT SIZE=50 TYPE=TEXT NAME=ROBOTS ";
	if (($_) = grep(/^<META NAME="ROBOTS"/, @metatags)) {
		m|CONTENT="([^"]*)">|; print "VALUE=\"$1\"";
	}
	print "></TD></TR>\n";
	print "</TABLE><P>\n";
	print "<INPUT TYPE=CHECKBOX NAME=applyall VALUE=1> Apply to all pages on board<P>\n";
	print "<INPUT TYPE=SUBMIT VALUE=\"Save META Tags\">\n";
	print "</TD></TR></TABLE></FORM>\n";
	print "<HR><A NAME=\"TEMPL\">\n";
	print "<H3>Templates and Structure</H3>\n";
	print "<FORM ACTION=\"$cgiurl2\" METHOD=POST NAME=tands>\n";
	print "<TABLE BORDER=1 WIDTH=100% BGCOLOR=ffffcc><TR><TD>$fs";
	print "The options in this section allow you to regenerate pages based on new\n";
	print "templates that you design and to update the index files for your board.\n";
	print "<FONT COLOR=#ff0000><B>Be patient while waiting for these functions.</B></FONT>\n";
	print "The page may appear to reload several times and the process may take a while\n";
	print "depending on the size of your board.  <U>This is normal.</U><P>\n";
	print "<HR NOSHADE><B>Topic Selection:</B><P><UL>\n";
	print "Select topic for operation (unless you have a specific reason to do otherwise,\n";
	print "choose &quot;All Topics&quot;):<P>\n";
	print "<SELECT NAME=tpclist SIZE=1>\n";
	print "<OPTION VALUE=all SELECTED>All Topics\n";
	print @txl;
	print "</SELECT></UL><P>\n";
	print "<HR NOSHADE><B>Index Board</B><P><UL>\n";
	print "The board index keeps track of the topic structure for increased performance\n";
	print "in many board functions.  You should reindex your board only if you are\n";
	print "upgrading to a new version or if your board index has become corrupted.<P>\n";
	print "<INPUT TYPE=SUBMIT NAME=submit VALUE=\"Index Board\" onClick=\"return confirm('Are you sure you want to re-index your board?')\">\n";
	print "<INPUT TYPE=HIDDEN NAME=index_topics VALUE='all'>\n";
	print "</UL><P>\n";
	print "<HR NOSHADE><B>Search Index</B><P><UL>\n";
	print "Condensed versions of posts made are stored for use by the keyword search\n";
	print "engine.  These lists can be regenerated at any time, but this operation is\n";
	print "potentially time consuming.<P>\n";
	print "<INPUT TYPE=SUBMIT NAME=submit VALUE=\"Regenerate Search Index\" onClick=\"return confirm('Are you sure you want to regenerate your search index?')\">\n";
	print "</UL><P>\n";
	print "<HR NOSHADE><B>Subtopic/Message Templates</B><P><UL>\n";
	print "The lists of subtopics and messages on your board can be regenerated according to the\n";
	print "<B>subtopics.conf</B> and <B>messages.conf</B> configuration files, respectively.  This can be safely done at any time,\n";
	print "but is potentially time consuming.<P>\n";
	print "<INPUT TYPE=SUBMIT NAME=submit VALUE=\"Regenerate Subtopic/Message Lists\" onClick=\"return confirm('Are you sure you want to regenerate your subtopic and message lists?')\">\n";
	print "</UL><P>\n";
	print "<HR NOSHADE><B>Topic Template</B><P><UL>\n";
	print "The topic list on the front page of your board can be regenerated according to the\n";
	print "<B>topics.conf</B> configuration file.  This can be safely done at any time.<P>\n";
	print "<INPUT TYPE=SUBMIT NAME=submit VALUE=\"Regenerate Topic List\" onClick=\"return confirm('Are you sure you want to regenerate your topic list?')\">\n";
	print "</UL><P>\n";
	print "<HR NOSHADE><B>Page Templates</B><P><UL>\n";
	print "The pages on your board can be regenerated according to the\n";
	print "<B>newpage.conf</B> and <B>addmessage-*.conf</B> configuration files.  This can be safely done at any time but is potentially time consuming.<P>\n";
	print "<INPUT TYPE=CHECKBOX NAME=move VALUE=1";
	@tp = grep(/^<!-Top: (\d+)-!>/, @main);
	foreach $tp (@tp) {
		$tp =~ m|<A HREF="(.*)/messages/(\d+)/(\d+).$ext|;
		$old_html_url = $1;
		last if $old_html_url eq "";
	}
	print " CHECKED" if $html_url ne $old_html_url;
	print "><FONT SIZE=1>Check this box if you are moving from one server to another</FONT><BR>\n";
	print "&nbsp;&nbsp;&nbsp;Old URL: </FONT><INPUT TYPE=TEXT NAME=old_html_url SIZE=50 VALUE='$old_html_url'>$fs<P>\n";
	print "<INPUT TYPE=SUBMIT NAME=submit VALUE=\"Regenerate Pages\" onClick=\"return confirm('Are you sure you want to regenerate your pages?')\">\n";
	print "</UL><P>\n";
	print "<INPUT NAME=action TYPE=hidden value=\"templates\">\n";
	print "<INPUT NAME=username TYPE=hidden value=\"$FORM{'username'}\">\n";
	print "</TD></TR></TABLE>\n";
	print "</FORM>\n";
	print "</BODY></HTML>\n";
	exit(0);
}

#---SEPARATOR---#
#REQ:get_number
#REQ:new_file
#REQ:topic_format
#REQ:webtags
#REQ:change_about_message
#REQ:change_board_colors

sub add_topic {
	my ($new_topic, $new_topic_group, $privs, $templ, $topic_unformatted, $descr, $descr_format) = @_;
	my ($topic_number,$topic_name,$me_name,$num,$dt,$lm,@main,$group);
	my ($main_line,$str,$time,$posted, $num_local);
	$num_local = &get_number;
	&lock("add_topic", "$admin_dir/posting.txt");
	open (FILE, ">>$admin_dir/posting.txt");
	print FILE "$num_local:", ":$new_topic_group:$new_topic_group:\n" if $privs ne "public";
	print FILE "$num_local:~:$new_topic_group:$new_topic_group:\n" if $privs eq "public";
	close (FILE);
	&unlock("add_topic", "$admin_dir/posting.txt");
	&lock("add_topic", "$admin_dir/security.txt");
	open (FILE, ">>$admin_dir/security.txt");
	print FILE "$num_local:~:::\n";
	close (FILE);
	&unlock("add_topic", "$admin_dir/security.txt");
	$group = $new_topic_group;
	mkdir ("$message_dir/$num_local",oct($perms0777)) || &error_message("Directory Creation Error", "Could not create new directory for this topic! (System returned the error: '$!'.)  If you are running unix, check that permissions on the 'messages' subdirectory are 0777 (rwxrwxrwx).  If you're on NT, the system administrator needs to make the 'messages' directory be writable to the WWW server.");
	chmod (oct($perms0777), "$message_dir/$num_local");
	open (FILE, ">$admin_dir/msg_index/$num_local-tree.txt") || &log_error("src-board-subs-1", "add_topic", "Could not create tree subdirectory [$!]");
	print FILE "0\t$num_local\t$num_local\t0\t", &escape($new_topic), "\tSublist\t$new_topic_group\t0\thidden=0;icons=1\t", time, "\t\t\n" if $templ ne "yes";
	print FILE "0\t$num_local\t$num_local\t0\t", &escape($new_topic), "\tSublistCreateAbout\t$new_topic_group\t0\thidden=0;icons=1\t", time, "\t\t\n" if $templ eq "yes";
	close (FILE);
	chmod (oct($perms0666), "$admin_dir/msg_index/$num_local-tree.txt");
	&lock("add_topic", "$admin_dir/tree.txt");
	open (FILE, ">>$admin_dir/tree.txt");
	print FILE "0\t$num_local\t$num_local\t0\t", &escape($new_topic), "\tSublist\t$new_topic_group\t0\thidden=0;icons=1\t", time, "\t\t\n" if $templ ne "yes";
	print FILE "0\t$num_local\t$num_local\t0\t", &escape($new_topic), "\tSublistCreateAbout\t$new_topic_group\t0\thidden=0;icons=1\t", time, "\t\t\n" if $templ eq "yes";
	close (FILE);
	&unlock("add_topic", "$admin_dir/tree.txt");
	open (LOG, ">$admin_dir/msg_index/$num_local-log.txt") || &error_message("Create Topic Error", "Could not create new log file in $admin_dir/msg_index.");
	close (LOG);
	open (SEARCH, ">$admin_dir/msg_index/$num_local-search.txt") || &error_message("Create Topic Error", "Could not create new search index file in $admin_dir/msg_index.");
	close (SEARCH);
	chmod (oct($perms0666), "$admin_dir/msg_index/$num_local-log.txt");
	chmod (oct($perms0666), "$admin_dir/msg_index/$num_local-search.txt");
	mkdir ("$admin_dir/msg_index/$num_local",oct($perms0777)) || &error_message("Directory Creation Error", "Could not create new directory for this topic! (System returned the error: '$!'.)  If you are running unix, check that permissions on the 'msg_index' subdirectory are 0777 (rwxrwxrwx).  If you're on NT, the system administrator needs to make the 'msg_index' directory writable to your WWW server.");
	$topic_number = $num_local;
	$topic_name = $new_topic;
	$me_name = $new_topic;
	$dt = time;
	&new_file($num_local,$num_local,0,$new_topic_group,$new_topic,"SublistCreateAbout","","icons=1;hidden=0") if $templ eq "yes";
	&new_file($num_local,$num_local,0,$new_topic_group,$new_topic,"Sublist","","icons=1;hidden=0") if $templ ne "yes";
	if ($templ) {
		$message_hold = $L{WELCOME_TO_TOPIC};
		$message_hold =~ s/\%topicname/$topic_unformatted/g;
		$message = &webtags($message_hold);
		&change_about_message("$message_dir/$num_local/$num_local.$ext", $message_hold, $message);
	}
	open (BLANKINDEX, ">$message_dir/$num_local/index.html"); close (BLANKINDEX);
	chmod (oct($perms0666), "$message_dir/$num_local/index.html");
	$url = "$message_url/$num_local/$num_local.$ext";
	$url .= "?$dt" if !$noqm;
	&lock("add_topic", "$message_dir/$board_topics_file");
	open(MAIN_1, "$message_dir/$board_topics_file") || &error_message("File Error", "Could not open main topics file ($board_topics_file).");
	@main = <MAIN_1>;
	close(MAIN_1);
	$posted = 0; $count = 0;
	open(MAIN_1, ">$message_dir/$board_topics_file") || &error_message("File Error", "Could not write main topics file ($board_topics_file).");
	foreach $main_line (@main) {
		if ($main_line =~ /<!-Posting-!>/ && $posted == 0) {
			$posted = 1;
			$str = &topic_format($num_local, $topic_name, $url, time, $new_topic_group, $descr_format, 0, $count-1);
			$main_line = join("", $str, $main_line);
			print MAIN_1 $main_line;
		} elsif ($main_line =~ m|<!-Top: (\d+)-!>|) {
			$count += 1 if $main_line !~ m|<!-- (.*) -->|;
			print MAIN_1 $main_line;
		} elsif ($main_line =~ m|<!-Posting-!>|) {
			next;
		} elsif ($main_line =~ m|<!-End Description Source-!>|) {
			print MAIN_1 "<!-Source: $num_local-!>", &escape($descr), "\n";
			print MAIN_1 $main_line;
		} else {
			print MAIN_1 $main_line;
		}
	}
	close(MAIN_1);
	&unlock("add_topic", "$message_dir/$board_topics_file");
	&change_board_colors("*", "", "", "", "", "", "", "", "", 1);
	return $num_local;
}

#---SEPARATOR---#
#REQ:change_board_colors

sub remove_topic {
	my ($remove_number) = @_;
	my (@lines,$line,$filenumber,$topic_number,%eee,@r);
	@r = split(/,/, $remove_number);
	undef %eee;
	foreach $line (@r) {
		$eee{$line} = 1;
	}
	&lock("remove_topic", "$message_dir/$board_topics_file");
	open(MAIN_1, "$message_dir/$board_topics_file") || &error_message("File Error", "Could not open main topics file ($board_topics_file).");
	@lines = <MAIN_1>;
	close(MAIN_1);
	open(MAIN_1, ">" . "$message_dir/$board_topics_file") || &error_message("File Error", "Could not write main topics file ($board_topics_file).");
	foreach $line (@lines) {
		if ($line =~ /<!-Top: (\d+)-!>/) {
			print MAIN_1 $line if (!$eee{$1});
		} elsif ($line =~ /<!-Description: (\d+)-!>/) {
			print MAIN_1 $line if (!$eee{$1});
		} elsif ($line =~ /<!-Source: (\d+)-!>/) {
			print MAIN_1 $line if (!$eee{$1});
		} else {
			print MAIN_1 $line;
		}
	}
	close (MAIN_1);
	&unlock("remove_topic", "$message_dir/$board_topics_file");
	&change_board_colors("*", "", "", "", "", "", "", "", "", 1);
	undef %nuked;
	foreach $key (keys(%eee)) {
		if (-e "$message_dir/$key") {
			$dir = "$message_dir/$key";
		} else {
			$dir = "$secdir/$key";
		}
		$remove_number = $key;
		if (opendir(DIR, $dir)) {
			while ($f = readdir(DIR)) {
				if ($f !~ m|^(\d+)\.$ext$|) {
					$nuked{$f} = 1;
				}
				unlink ("$dir/$f");
			}
			closedir(DIR);
			rmdir("$dir/$f");
		}
		$dir = "$admin_dir/msg_index/$remove_number";
		opendir(DIR, "$dir");
		while ($f = readdir(DIR)) {
			unlink ("$dir/$f");
		}
		closedir(DIR);
		rmdir("$admin_dir/msg_index/$remove_number");
		unlink("$admin_dir/msg_index/$remove_number-search.txt");
	    unlink("$admin_dir/msg_index/$remove_number-log.txt");
		&lock("remove_topic", "$admin_dir/posting.txt");
		open (POSTING, "$admin_dir/posting.txt"); @posting = <POSTING>; close (POSTING);
		@posting = grep(!/^$remove_number:/, @posting);
		open (POSTING, ">$admin_dir/posting.txt"); print POSTING @posting; close (POSTING);
		&unlock("remove_topic", "$admin_dir/posting.txt");
		&lock("remove_topic", "$admin_dir/postoptions.txt");
		open (POSTING, "$admin_dir/postoptions.txt"); @posting = <POSTING>; close (POSTING);
		@posting = grep(!/^$remove_number:/, @posting);
		open (POSTING, ">$admin_dir/postoptions.txt"); print POSTING @posting; close (POSTING);
		&unlock("remove_topic", "$admin_dir/postoptions.txt");
		&lock("remove_topic", "$admin_dir/security.txt");
		open (READING, "$admin_dir/security.txt"); @reading = <READING>; close (READING);
		@reading = grep(!/^$remove_number:/, @reading);
		open (READING, ">$admin_dir/security.txt"); print READING @reading; close (READING);
		&unlock("remove_topic", "$admin_dir/security.txt");
		undef %posts_nuked;
		unlink("$admin_dir/msg_index/$remove_number-tree.txt");
	}
	&lock("remove_topic", "$admin_dir/tree.txt");
	open (TREE, "$admin_dir/tree.txt");
	@tree = <TREE>;
	close (TREE);
	foreach $line (@tree) {
		@c = split(/\t/, $line);
		$line = "" if $eee{$c[1]} == 1;
	}
	@tree = grep(/\S/, @tree);
	open (TREE, ">$admin_dir/tree.txt");
	print TREE @tree;
	close (TREE);
	&unlock("remove_topic", "$admin_dir/tree.txt");
	&lock("remove_topic", "$admin_dir/msg_index/attach-mgr.txt");
	open (FILE, "$admin_dir/msg_index/attach-mgr.txt"); @file = <FILE>; close (FILE);
	foreach $line (@file) {
		($num, $file) = split(/\s+/, $line);
		$line = "" if $nuked{$file} == 1;
	}
	@file = grep(/\S/, @file);
	open (FILE, ">$admin_dir/msg_index/attach-mgr.txt"); print FILE @file; close (FILE);
	&unlock("remove_topic", "$admin_dir/msg_index/attach-mgr.txt");
}

#---SEPARATOR---#
#REQ:topic_format
#REQ:regenerate_board

sub rename_topic {
	my ($topic_number_in, $newname) = @_;
	my ($line_top,$url,$str,@lines_top);
	&lock("rename_topic", "$admin_dir/msg_index/$topic_number_in-tree.txt");
	open (FILE, "$admin_dir/msg_index/$topic_number_in-tree.txt"); @file = <FILE>; close (FILE);
	foreach $line (@file) {
		@c = split(/\t/, $line);
		if ($c[1] == $topic_number_in && $c[2] == $topic_number_in) {
			$c[4] = &escape($newname);
			$line = join("\t", @c);
			last;
		}
	}
	open (FILE, ">$admin_dir/msg_index/$topic_number_in-tree.txt"); print FILE @file; close (FILE);
	&unlock("rename_topic", "$admin_dir/msg_index/$topic_number_in-tree.txt");
	&lock("rename_topic", "$admin_dir/tree.txt");
	open (FILE, "$admin_dir/tree.txt"); @file = <FILE>; close (FILE);
	foreach $line (@file) {
		@c = split(/\t/, $line);
		if ($c[1] == $topic_number_in && $c[2] == $topic_number_in) {
			$c[4] = &escape($newname);
			$line = join("\t", @c);
			last;
		}
	}
	open (FILE, ">$admin_dir/tree.txt"); print FILE @file; close (FILE);
	&unlock("rename_topic", "$admin_dir/tree.txt");
	$counter = 0;
	&lock("rename_topic", "$message_dir/$board_topics_file");
	open(MAIN_1, "$message_dir/$board_topics_file") || &error_message("File Error", "Could not open main topics file ($board_topics_file).");
	@lines_top = <MAIN_1>;
	close(MAIN_1);
	$count = 0;
	foreach $line (@lines_top) {
		if ($line =~ m|<!-Top: (\d+)-!>|) {
			$count += 1 if $line !~ m|<!-- (.*) -->|;
			if ($1 == $topic_number_in) {
				if ($line =~ m|<!-Descr-!>(.*)<!-/Descr-!>|) {
					$descr = $1;
				} else {
					$descr = "";
				}
				$url = "$message_url/$topic_number_in/$topic_number_in.$ext" if -e "$message_dir/$topic_number_in";
				$url .= "$script_url/board-auth.$cgi_extension?file=/$topic_number_in/$topic_number_in.$ext&lm=$lm" if !-e "$message_dir/$topic_number_in/$topic_number_in.$ext";
				$url .= "?$c[8]" if (!$noqm && -e "$message_dir/$num/$num.$ext");
				$line = &topic_format($topic_number_in, $newname, $url, $c[9], "\u$c[6]", $descr, $c[7], $count);
			}
		}
	}
	open(MAIN_1, ">$message_dir/$board_topics_file") || &error_message("File Error", "Could not write main topics file ($board_topics_file).");
	print MAIN_1 @lines_top;
	close (MAIN_1);
	&unlock("rename_topic", "$message_dir/$board_topics_file");
	&lock("rename_topic", "$message_dir/$topic_number_in/$topic_number_in.$ext");
	my ($head, $color, $lm, $ann, $ann_src, $sublist, $about, $about_src, $message, $message_src, $description_src) = &get_page($topic_number_in, $topic_number_in);
	@hd = split(/\n/, $head);
	foreach $line (@hd) {
		if ($line =~ m|<!--Topic: (\d+)/|) {
			$me_num = $1;
			$line = "<!--Topic: $me_num/$newname-->";
		} elsif ($line =~ m|<!--Me: (\d+)/|) {
			$line = "<!--Me: $1/$newname-->";
		}
	}
	$head = join("\n", @hd);
	&set_page($topic_number_in, $topic_number_in, $head, $color, $lm, $ann, $ann_src, $sublist, $about, $about_src, $message, $message_src, $description_src);
	&unlock("rename_topic", "$message_dir/$topic_number_in/$topic_number_in.$ext");
	&regenerate_board("Renaming Topic", "$cgiurl2?username=$superuser&action=rename_topic_action&topic=$topic_number_in", "$cgiurlm?username=$superuser&cmd=board_mgr", $topic_number_in, 1);
}

#---SEPARATOR---#
#REQ:change_board_colors

sub reorder_topics {
	my ($array) = @_;
	my ($topic_number,@ascending,$line,@lines,%newarray,$flag,$key,%printed);
	@ascending = split(/:/, $array);
	&lock("reorder_topics", "$message_dir/$board_topics_file");
	open(MAIN_1, "$message_dir/$board_topics_file") || &error_message("File Error", "Could not open main topics file ($board_topics_file).");
	@lines = <MAIN_1>;
	close(MAIN_1);
	undef %printed;
	foreach $line (@lines) {
		if ($line =~ /<!-Top: (\d+)-!>/) {
			$newarray{$1} = $line;
			$printed{$1} = 0;
		} elsif ($line =~ m|<!-Description: (\d+)-!>|) {
			$descrarray{$1} = $line;
		}
	}
	open(MAIN_1, ">" . "$message_dir/$board_topics_file") || &error_message("File Error", "Could not write main topics file ($board_topics_file).");
	$flag = 0;
	foreach $line (@lines) {
		if ($line =~ /<!-Top: (\d+)-!>/ && $flag == 0) {
			$flag = 1;
			foreach $key (@ascending) {
				print MAIN_1 $newarray{$key};
				print MAIN_1 $descrarray{$key};
				$printed{$key} = 1;
			}
			foreach $key (keys(%printed)) {
				print MAIN_1 $newarray{$key} if $printed{$key} == 0;
				print MAIN_1 $descrarray{$key} if $printed{$key} == 0;
			}
		} elsif ($line =~ /<!-Posting-!>/) {
			$flag = 0;
			print MAIN_1 $line;
		} elsif ($flag == 0) {
			print MAIN_1 $line;
		}
	}
	close (MAIN_1);
	&unlock("reorder_topics", "$message_dir/$board_topics_file");
	&change_board_colors("*", "", "", "", "", "", "", "", "", 1);
	undef %T_Items;
	&lock("reorder_topics", "$admin_dir/tree.txt");
	open (FILE, "$admin_dir/tree.txt"); @file = <FILE>; close (FILE);
	foreach $line (@file) {
		@c = split(/\t/, $line); $T_Items{$c[1]} .= $line;
	}
	open (FILE, ">$admin_dir/tree.txt");
	foreach $key (@ascending) {
		print FILE $T_Items{$key};
	}
	close (FILE);
	&unlock("reorder_topics", "$admin_dir/tree.txt");
}

#---SEPARATOR---#

sub change_main_message {
	my ($newmessage, $source, $hr) = @_;
	my ($line, @lines,$messageflag, $flag);
	&lock("change_main_message", "$message_dir/$board_topics_file");
	open(MAIN_1, "$message_dir/$board_topics_file") || &error_message("File Error", "Could not open main topics file ($board_topics_file).");
	@lines = <MAIN_1>;
	close(MAIN_1);
	open(MAIN_1, ">$message_dir/$board_topics_file") || &error_message("File Error", "Could not write main topics file ($board_topics_file).");
	$messageflag = 0;
	foreach $line (@lines) {
		if ($line =~ m|<!--Message-->|) {
			$flag = 1;
			print MAIN_1 $line;
			print MAIN_1 "<HR>\n" if $hr;
			print MAIN_1 $newmessage . "\n";
		} elsif ($line =~ m|<!--/Message-->|) {
			print MAIN_1 $line;
			$flag = 0;
		} elsif ($flag == 1) {
			if ($line =~ /<!--Source:/) {
				print MAIN_1 "<!--Source: $source -->\n";
			}
		} else {
			print MAIN_1 $line;
		}
	}
	close (MAIN_1);
	&unlock("change_main_message", "$message_dir/$board_topics_file");
}

#---SEPARATOR---#
#REQ:topic_format
#REQ:regenerate_board
#REQ:change_board_colors

sub change_topic_group {
	my ($topic_number, $new_group, $smart) = @_;
	my ($line, @lines,$old_group);
	@x = split(/,/, $topic_number);
	undef %tn; undef %lin;
	foreach $x (@x) {
		$tn{$x} = 1;
	}
	&lock("change_topic_group", "$admin_dir/tree.txt");
	open (FILE, "$admin_dir/tree.txt"); @file = <FILE>; close (FILE);
	foreach $line (@file) {
		@c = split(/\t/, $line);
		if ($tn{$c[1]} == 1) {
			$c[6] = $new_group;
			$line = join("\t", @c);
			$lin{$c[1]} = $line if ($c[1] == $c[2]);
		}
	}
	open (FILE, ">$admin_dir/tree.txt"); print FILE @file; close (FILE);
	&unlock("change_topic_group", "$admin_dir/tree.txt");
	foreach $topic_number (@x) {
		&lock("change_topic_group", "$admin_dir/msg_index/$topic_number-tree.txt");
		open (FILE, "$admin_dir/msg_index/$topic_number-tree.txt"); @file = <FILE>; close (FILE);
		foreach $line (@file) {
			@c = split(/\t/, $line);
			if ($tn{$c[1]} == 1) {
				if ($c[5] !~ m|^LINK:|) {
					$c[6] = $new_group;
					$line = join("\t", @c);
				}
			}
		}
		open (FILE, ">$admin_dir/msg_index/$topic_number-tree.txt");
		print FILE @file;
		close (FILE);
		&unlock("change_topic_group", "$admin_dir/msg_index/$topic_number-tree.txt");
	}
	&change_board_colors("*", "", "", "", "", "", "", "", "", 1);
	if ($smart) {
		foreach $topic_number (keys(%tn)) {
			&extract("//$topic_number/$topic_number.$ext");
			$oldgroup = $owner;
			@files = ('posting');
			push (@files, 'security') if $pro;
			foreach $f (@files) {
				&lock("change_topic_group", "$admin_dir/$f.txt");
				open (FILE, "$admin_dir/$f.txt"); @file = <FILE>; close (FILE);
				foreach $line (@file) {
					if ($line =~ m|^$topic_number:([^:]*):([^:]*):([^:]*):|) {
						($public, $users, $moderators, $after) = ($1, $2, $3, $');
						@u = split(/,/, $users);
						if (scalar(@u) > 1 && grep(/^$oldgroup$/, @u)) {
							$users .= ",$new_group" if !grep(/^$new_group$/, @u);
						} elsif ($users eq "$oldgroup") {
							$users = "$new_group";
						}
						@u = split(/,/, $moderators);
						if (scalar(@u) > 1 && grep(/^$oldgroup$/, @u)) {
							$moderators .= ",$new_group" if !grep(/^$new_group$/, @u);
						} elsif ($moderators eq "$oldgroup") {
							$moderators = "$new_group";
						}
						$line = join(":", $topic_number, $public, $users, $moderators, $after);
					}
				}
				open (FILE, ">$admin_dir/$f.txt"); print FILE @file; close (FILE);
				&unlock("change_topic_group", "$admin_dir/$f.txt");
			}
		}
	}
	&regenerate_board("Changing Topic Group", "$cgiurl2?username=$superuser&action=change_topic_group_action&topic=" . join(",", keys(%tn)), "$cgiurlm?username=$superuser&cmd=board_mgr", join(",", keys(%tn)), 2, $new_group);
}

#---SEPARATOR---#

sub save_top_meta_tags {
	my ($descr, $keywords, $robots) = @_;
	&lock("save_top_meta_tags", "$message_dir/$board_topics_file");
	open (MAIN, "$message_dir/$board_topics_file");
	@main = <MAIN>;
	close (MAIN);
	$descr =~ s/"//g;
	$keywords =~ s/"//g;
	$robots =~ s/"//g;
	foreach $line (@main) {
		if ($line =~ m|^<META NAME="DESCRIPTION"|) {
			$line = "<META NAME=\"DESCRIPTION\" CONTENT=\"$descr\">\n";
		} elsif ($line =~ m|^<META NAME="KEYWORDS"|) {
			$line = "<META NAME=\"KEYWORDS\" CONTENT=\"$keywords\">\n";
		} elsif ($line =~ m|^<META NAME="ROBOTS"|) {
			$line = "<META NAME=\"ROBOTS\" CONTENT=\"$robots\">\n";
		}
	}
	open (MAIN, ">$message_dir/$board_topics_file");
	print MAIN @main;
	close (MAIN);
	&unlock("save_top_meta_tags", "$message_dir/$board_topics_file");
}

#---SEPARATOR---#
#REQ:regenerate_board

sub save_topic_meta_tags {
	my ($topic, $descr, $keywords, $robots, $flag) = @_;
	$descr =~ s/"//g;
	$keywords =~ s/"//g;
	$robots =~ s/"//g;
	if ($flag == 1) {
		my ($head, $color, $lm, $ann, $ann_src, $sublist, $about, $about_src, $message, $message_src, $description_src) = &get_page($topic, $topic);
		$meta_description = $descr;
		$meta_keywords = $keywords;
		$meta_robots = $robots;
		&set_page($topic, $topic, $head, $color, $lm, $ann, $ann_src, $sublist, $about, $about_src, $message, $message_src, $description_src, $template, $addfile);
		&regenerate_board("Saving META Tags", "$cgiurl2?action=save_specific_meta_tags&username=$superuser&topic=$topic", "$cgiurlm?cmd=board_mgr&username=$superuser", $topic, 3, join("\t", $meta_description, $meta_keywords, $meta_robots));
	} else {
		&regenerate_board("Saving META Tags", "$cgiurl2?action=save_topic_meta&username=$superuser&topic=$topic", "$cgiurlm?cmd=board_mgr&username=$superuser", $topic, 3, join("\t", $descr, $keywords, $robots)) if $flag == 0;
		&regenerate_board("Saving META Tags", "$cgiurl2?action=save_specific_meta_tags&username=$superuser&topic=$topic", "$cgiurlm?cmd=board_mgr&username=$superuser", $topic, 3, join("\t", $descr, $keywords, $robots)) if $flag == 2;
	}
}

#---SEPARATOR---#
#REQ:change_board_colors

sub modify_topic_display {
	my ($topic, $hidden, $icons) = @_;
	my ($topic_name, @tree, $line, $props);
	$topic =~ s/\D//g;
	&error_message("Invalid Topic", "Topic number [$topic] does not appear to exist") if ((!-e "$secdir/$topic" && !-e "$message_dir/$topic") || $topic == 0);
	&lock("modify_topic_display", "//$topic/$topic.$ext");
	my ($head, $color, $lm, $announce, $announce_src, $sublist, $about, $about_src, $message, $message_src, $description_source) = &get_page($topic, $topic);
	$head =~ m|<!--Topic: (\d+)/(.*)-->|;
	$topic_name_hold = $2;
	$hidden =~ s/\D//g;
	$icons =~ s/\D//g;
	$DP{'hidden'} = $hidden;
	$DP{'icons'} = $icons;
	&set_page($topic, $topic, $head, $color, $lm, $announce, $announce_src, $sublist, $about, $about_src, $message, $message_src, $description_source);
	&unlock("modify_topic_display", "//$topic/$topic.$ext");
	&lock("modify_topic_display", "$admin_dir/msg_index/$topic-tree.txt");
	open (TREE, "$admin_dir/msg_index/$topic-tree.txt");
	@tree = <TREE>;
	close (TREE);
	@c = split(/\t/, $tree[0]);
	undef @props;
	foreach $key (keys(%DP)) {
		push (@props, "$key=$DP{$key}");
	}
	$props = join(";", @props);
	$c[8] = $props;
	$tree[0] = join("\t", @c);
	open (TREE, ">$admin_dir/msg_index/$topic-tree.txt");
	print TREE @tree;
	close (TREE);
	&unlock("modify_topic_display", "$admin_dir/msg_index/$topic-tree.txt");
	&lock("modify_topic_display", "$admin_dir/tree.txt");
	open (TREE, "$admin_dir/tree.txt");
	@tree = <TREE>;
	close (TREE);
	foreach $line (@tree) {
		@c = split(/\t/, $line);
		if ($c[1] == $topic) {
			$c[8] = $props;
			$line = join("\t", @c);
			last;
		}
	}
	open (TREE, ">$admin_dir/tree.txt");
	print TREE @tree;
	close (TREE);
	&unlock("modify_topic_display", "$admin_dir/tree.txt");
	&change_board_colors("*", "", "", "", "", "", "", "", "", 1);
	return $topic_name_hold;
}

#---SEPARATOR---#

sub change_title_message {
	my ($newmessage, $source, $hr) = @_;
	my ($line, @lines,$messageflag, $flag);
	&lock("change_title_message", "$message_dir/$board_topics_file");
	open(MAIN_1, "$message_dir/$board_topics_file") || &error_message("File Error", "Could not open main topics file ($board_topics_file).");
	@lines = <MAIN_1>;
	close(MAIN_1);
	open(MAIN_1, ">" . "$message_dir/$board_topics_file") || &error_message("File Error", "Could not write main topics file ($board_topics_file).");
	$messageflag = 0;
	foreach $line (@lines) {
		if ($line =~ m|<!--Title Message-->|) {
			$flag = 1;
			print MAIN_1 $line;
			print MAIN_1 $newmessage . "\n";
		} elsif ($line =~ m|<!--/Title Message-->|) {
			print MAIN_1 "<HR>\n" if $hr;
			print MAIN_1 $line;
			$flag = 0;
		} elsif ($flag == 1) {
			if ($line =~ /<!--Source:/) {
				print MAIN_1 "<!--Source: $source -->\n";
			}
		} else {
			print MAIN_1 $line;
		}
	}
	close (MAIN_1);
	&unlock("change_title_message", "$message_dir/$board_topics_file");
}

#---SEPARATOR---#
#REQ:topic_format
#REQ:change_board_colors

sub save_description {
	my ($topic_number, $formatted, $escaped_source) = @_;
	&lock("save_description", "$message_dir/$board_topics_file");
	open (TOP, "$message_dir/$board_topics_file");
	@top = <TOP>;
	close (TOP);
	$flag1 = 0; $flag2 = 0; $count = 0;
	foreach $line (@top) {
		if ($line =~ m|<!-Description: $topic_number-!>|) {
			$line = "";
		} elsif ($line =~ m|<!-Source: $topic_number-!>|) {
			$line = "<!-Source: $topic_number-!>$escaped_source\n";
			$flag2 = 1;
		} elsif ($line =~ m|<!-Top: (\d+)-!>|) {
			$count += 1;
			if ($1 == $topic_number) {
				undef $found;
				open (FILE, "$admin_dir/tree.txt"); @file = <FILE>; close (FILE);
				foreach $line_tree (@file) {
					@c = split(/\t/, $line_tree);
					if ($c[1] == $topic_number && $c[2] == $topic_number) {
						$found = 1; last;
					}
				}
				if ($found == 0) {
					&extract("//$topic_number/$topic_number.$ext");
					$c[4] = &escape($topic_name);
					$c[6] = $owner;
					$c[7] = "";
				}
				$url = "$message_url/$topic_number/$topic_number.$ext" if -e "$message_dir/$topic_number";
				$url .= "$script_url/board-auth.$cgi_extension?file=/$topic_number/$topic_number.$ext&lm=$lm" if !-e "$message_dir/$topic_number/$topic_number.$ext";
				$url .= "?$lm" if (!$noqm && -e "$message_dir/$num/$num.$ext");
				$line = &topic_format($topic_number, &unescape($c[4]), $url, $c[9], $c[6], $formatted, $c[7], $count);
			}
		}
	}
	if ($flag2 == 0) {
		foreach $line (@top) {
			if ($line =~ m|<!--Description Source:|) {
				$line .= "<!-Source: $topic_number-!>$escaped_source\n";
			}
		}
	}
	open (TOP, ">$message_dir/$board_topics_file") || &error_message("Description Save Error", "Could not write to the <B>$board_topics_file</B> file.");
	print TOP @top;
	close (TOP);
	&unlock("save_description", "$message_dir/$board_topics_file");
	&change_board_colors("*", "", "", "", "", "", "", "", "", 1);
}



# END - FILE IS CORRECTLY UPLOADED #
