#!/usr/bin/perl --

###############################################################################
# Setup.pl                                                                    #
###############################################################################
# YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2 RC 1                                                 #
# Released:       December 27, 2004                                           #
# Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== #
# Copyright (c) 2000-2005 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by: The YaBB Development Team                                      #
#              with assistance from the YaBB community.                       #
# Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com            #
###############################################################################

$setupplver = 'YaBB 2 RC 1 $Revision: 1.51 $';

push(@INC, "./Modules");

if (-e "Paths.pl") { require "Paths.pl"; }
else {
	if (-e "Sources/Subs.pl"){ $sourcedir = "./Sources"; }
	if (-e("Members/admin.vars") || -e("Members/admin.dat")){ $memberdir = "./Members";}
}

if(!-e "$vardir/Setup.lock") {
	&BrdInstall;
	&MemInstall;
	&MesInstall;
}

if(!-e "Settings.pl") {
	&SetInstall;
}

require "Settings.pl";

if(!-e "$vardir/Setup.lock") {
	&VarInstall;
}

require "$sourcedir/Subs.pl";
require "$sourcedir/System.pl";
require "$sourcedir/Load.pl";
require "$sourcedir/DateTime.pl";


if(!-e "$vardir/Setup.lock") {
	&RunSetup;
}

$NavItem0 = "nav-item";
$NavItem1 = "nav-item";
$NavItem2 = "nav-item";
$NavItem3 = "nav-item";
$NavItem4 = "nav-item";
$NavItem5 = "nav-item";
$NavItem6 = "nav-item";

$NavLink0 = qq~ReadMe~;
$NavLink1 = qq~<a href="$boardurl/Setup.pl?action=cats">Step 1</a>~;
$NavLink2 = qq~<a href="$boardurl/Setup.pl?action=members">Step 2</a>~;
$NavLink3 = qq~<a href="$boardurl/Setup.pl?action=messages">Step 3</a>~;
$NavLink4 = qq~<a href="$boardurl/Setup.pl?action=dates">Step 4</a>~;
$NavLink5 = qq~<a href="$boardurl/Setup.pl?action=cleanup">Step 5</a>~;
$NavLink6 = qq~<a href="$boardurl/YaBB.$yyext?action=login">Login</a>~;


if ($INFO{'action'} eq "") {

if(-e "$vardir/Converter.lock") {
	&FoundLock;
}

  $yymain = qq~Please proceed through the following steps to convert YaBB SP1.3.x to YaBB2! Please read the following instructions:
  <br />
  <br />
  <b>1.</b> Make sure your YaBB 2 installation is running, and has all the correct paths etc<br />
  <b>2.</b> Copy the /Boards /Members /Messages folders from your YaBB SP1.3.x installation, to your YaBB 2 installation<br />
  <b>3.</b> Copy /Variables/cat.txt from your SP1.3.x installation, to the /Varaibles directory of your YaBB 2 installation<br />
  <b>4.</b> Proceed to step 1 of the converter<br />
  <br />
  <span class="warn-text">IMPORTANT: Conversion is irreversable, please backup your YaBB SP1.3.x installation before converting. Conversion can take a long time (30+ seconds) - in this time it may look like your browser has frozen, but please BE PATIENT</span>
  ~;

  $NavItem0 = "nav-item-highlight";
  $NavLink2 = qq~Step 2~;
  $NavLink3 = qq~Step 3~;
  $NavLink4 = qq~Step 4~;
  $NavLink5 = qq~Step 5~;
  $NavLink6 = qq~Login~;
  &Output;
}

if ($INFO{'action'} eq "cats") {

if(-e "$vardir/Converter.lock") {
	&FoundLock;
}

&PrepareConv;
&GetCats;
&CreateControl;

  $NavItem1 = "nav-item-highlight";
  $NavLink1 = qq~Step 1~;
  $NavLink3 = qq~Step 3~;
  $NavLink4 = qq~Step 4~;
  $NavLink5 = qq~Step 5~;
  $NavLink6 = qq~Login~;

$yymain = qq~
<span class="warn-text">Step 1: Board and Category Conversion Complete.</span><br />
<span class="grayed-text">Step 2: Member Conversion.</span><br />
<span class="grayed-text">Step 3: Message Conversion.</span><br />
<span class="grayed-text">Step 4: Date/time Conversion.</span><br />
<span class="grayed-text">Step 5: Final Cleanup.</span><br />
<div class="desc-container">
New forum.master file has been created. All useless files in /Boards have been cleaned up.<br />
New forum.control file has been created. All useless files in /Messages have been cleaned up. All dates in files have been converted to timestamps.
</div>
~;
  &Output;
}

if ($INFO{'action'} eq "members") {

if(-e "$vardir/Converter.lock") {
	&FoundLock;
}

    &ConvertMembers;
  $NavItem2 = "nav-item-highlight";
  $NavLink1 = qq~Step 1~;
  $NavLink2 = qq~Step 2~;
  $NavLink4 = qq~Step 4~;
  $NavLink5 = qq~Step 5~;
  $NavLink6 = qq~Login~;

$yymain = qq~
<span class="warn-text">Step 1: Board and Category Conversion Complete.</span><br />
<span class="warn-text">Step 2: Member Conversion Complete.</span><br />
<span class="grayed-text">Step 3: Message Conversion.</span><br />
<span class="grayed-text">Step 4: Date/time Conversion.</span><br />
<span class="grayed-text">Step 5: Final Cleanup.</span><br />
<div class="desc-container">
New User.vars files have been created. All useless files in /Members have been cleaned up. Password encrpytion is done of the first login of the user.
</div>
~;
  &Output;
}

if ($INFO{'action'} eq "members2") {

if(-e "$vardir/Converter.lock") {
	&FoundLock;
}

  $NavItem2 = "nav-item-highlight";
  $NavLink1 = qq~Step 1~;
  $NavLink2 = qq~Step 2~;
  $NavLink3 = qq~Step 3~;
  $NavLink4 = qq~Step 4~;
  $NavLink5 = qq~Step 5~;
  $NavLink6 = qq~Login~;

$yymain = qq~
<span class="warn-text">Step 1: Board and Category Conversion Complete.</span><br />
<span class="warn-text">Step 2: Member Conversion continue.</span><br />
<span class="grayed-text">Step 3: Message Conversion.</span><br />
<span class="grayed-text">Step 4: Date/time Conversion.</span><br />
<span class="grayed-text">Step 5: Final Cleanup.</span><br />
<div id="memcontinued" class="desc-container">
To prevent server time-out due to the amount of members, conversion is split into more steps.<br /><br />
There are <b>$INFO{'memleft'}</b> left to convert. <a href="$boardurl/Setup.pl?action=members" onclick="clearMeminfo();">Continue...</a>
</div>
<script type="text/javascript" language="JavaScript">
<!--
	var convtext = 'Converting - please wait\!';
	function clearMeminfo() {
		document.getElementById("memcontinued").innerHTML = convtext;
	}
// -->
</script>
~;

  &Output;
}

if ($INFO{'action'} eq "messages") {

if(-e "$vardir/Converter.lock") {
	&FoundLock;
}

    &ConvertMessages;
  $NavItem3 = "nav-item-highlight";
  $NavLink1 = qq~Step 1~;
  $NavLink2 = qq~Step 2~;
  $NavLink3 = qq~Step 3~;
  $NavLink5 = qq~Step 5~;
  $NavLink6 = qq~Login~;

$yymain = qq~
<span class="warn-text">Step 1: Board and Category Conversion Complete.</span><br />
<span class="warn-text">Step 2: Member Conversion Complete.</span><br />
<span class="warn-text">Step 3: Message Conversion Complete.</span><br />
<span class="grayed-text">Step 4: Date/time Conversion.</span><br />
<span class="grayed-text">Step 5: Final Cleanup.</span><br />
<div class="desc-container">
New style message files have been created. all useless files have been cleaned up from  /Messages.
</div>
~;
  &Output;
}

if ($INFO{'action'} eq "dates") {

if(-e "$vardir/Converter.lock") {
	&FoundLock;
}

    &ConvertTimeToString;
  $NavItem4 = "nav-item-highlight";
  $NavLink1 = qq~Step 1~;
  $NavLink2 = qq~Step 2~;
  $NavLink3 = qq~Step 3~;
  $NavLink4 = qq~Step 4~;
  $NavLink6 = qq~Login~;

$yymain = qq~
<span class="warn-text">Step 1: Board and Category Conversion Complete.</span><br />
<span class="warn-text">Step 2: Member Conversion Complete.</span><br />
<span class="warn-text">Step 3: Message Conversion Complete.</span><br />
<span class="warn-text">Step 4: Date/time Conversion Complete.</span><br />
<span class="grayed-text">Step 5: Final Cleanup.</span><br />
<div class="desc-container">
New style timestamps have been created throughout the board. All old style dates have been converted.
</div>
~;
  &Output;
}

if ($INFO{'action'} eq "cleanup") {

if(-e "$vardir/Converter.lock") {
	&FoundLock;
}

  require "$sourcedir/System.pl";
  require "$boardsdir/forum.master";
  &MyThreadRecount;
  foreach (keys %board) {
      &MyReCountTotals($_);
  }
  &CleanUpBoardsAgain;
  # Rebuild Memberlist
  &MyMemberIndex;
  $NavItem5 = "nav-item-highlight";
  $NavLink1 = qq~Step 1~;
  $NavLink2 = qq~Step 2~;
  $NavLink3 = qq~Step 3~;
  $NavLink4 = qq~Step 4~;
  $NavLink5 = qq~Step 5~;

$yymain = qq~
<span class="warn-text">Step 1: Board and Category Conversion Complete.</span><br />
<span class="warn-text">Step 2: Member Conversion Complete.</span><br />
<span class="warn-text">Step 3: Message Conversion Complete.</span><br />
<span class="warn-text">Step 4: Date/time Conversion Complete.</span><br />
<span class="warn-text">Step 5: Final Cleanup Complete.</span><br /><br />
<div class="desc-container">
We reccomend you delete the file "Setup.pl" in the main YaBB Directory. This is to prevent someone else running the converter, and damaging your files.<br /><br />
You may now login to your forum - Enjoy using YaBB 2!
</div>
~;
  &CreateLock;
  &Output;
}


sub Output2 {

if($yySetCookies1 || $yySetCookies2 || $yySetCookies3) {

$yycharset = "iso-8859-1";

print header(
	-status=>'200 OK',
	-cookie=>[$yySetCookies1,$yySetCookies2,$yySetCookies3],
	-charset=>$yycharset
	);
} else {
print header(
	-status=>'200 OK',
	-charset=>$yycharset
	);
}

print qq~
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>YaBB 2 Setup</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>

<!-- Main Content -->
<div style="height: 130px;">&nbsp;</div>
$yymain<br />


</body>
</html>
~;
exit;
}

sub Output {

if($yySetCookies1 || $yySetCookies2 || $yySetCookies3) {

$yycharset = "iso-8859-1";

print header(
	-status=>'200 OK',
	-cookie=>[$yySetCookies1,$yySetCookies2,$yySetCookies3],
	-charset=>$yycharset
	);
} else {
print header(
    -status=>'200 OK',
    -charset=>$yycharset
    );
}

print qq~
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>YaBB 2 Converter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<style type="text/css">
<!--
body {
	height: auto;
	background-color: #DEDEDE;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	margin-left: 0px;
	margin-right: 0px;
	margin-top: 0px;
	margin-bottom: 0px;
}

a {
	color : #3333CC;
	text-decoration: none;
}

a:hover {
	color: #CC3333;
	text-decoration: none;
}

.container {
	position:absolute;
	font-family: Arial, Helvetica, sans-serif;
	text-align: center;
	top: 50px;
	left: 50%;
	width: 601px;
	margin-top: 110px;
	margin-left: -306px;
	height: 300px;
	padding: 0px;
	border: 1px;
	border-style: solid;
	border-color: #333333;
	background-color: #FAFAFA;
}

.titlebg {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	color: #FFFFFF;
	font-weight: bold;
	text-align: left;
	width: auto;
	padding: 6px;
	padding-left: 8px;
	border: 1px;
	border-bottom-style: solid;
	border-bottom-color: #333333;
	background-color: #5488BA;
}

.maintext {
	font-family: Arial, Helvetica, sans-serif;
	text-align: left;
	width: auto;
	padding: 8px;
	border: 1px;
	background-color: #FAFAFA;
	margin-bottom: 60px;
}

.warn-text {
	font-weight: bold;
	color: #FF3333;
}

.grayed-text {
	font-weight: bold;
	color: #bbbbbb;
}

.desc-container {
	position: absolute;
	background-color: #EEEEEE;
	border: 1px #333333 solid;
	padding: 8px;
	top: 40px;
	right: 10px;
	width: 250px;
}

.nav-container {
	position: absolute;
	background-color: #EEEEEE;
	border-top-width: 1px;
	border-top-style: solid;
	border-top-color: #333333;
	border-left-width: 1px;
	border-left-style: solid;
	border-left-color: #333333;
	right: -1px;
	bottom: 0px;
	width: 427px;
}

.nav-item {
	position: relative;
	float: left;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11px;
	font-weight: bold;
	border-right-width: 1px;
	border-right-style: solid;
	border-right-color: #333333;
	padding: 5px;
	right: 0px;
	bottom: 0px;
	width: 50px;
}

.nav-item-highlight {
	position: relative;
	float: left;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11px;
	font-weight: bold;
	border-right-width: 1px;
	border-right-style: solid;
	border-right-color: #333333;
	background-color: #5488BA;
	color: #FFFFFF;
	padding: 5px;
	right: 0px;
	bottom: 0px;
	width: 50px;
}

-->
</style>

</head>
<body>

<div class="container">
  <div class="titlebg">
    This is the YaBB 2 Converter Script
  </div>

  <div class="maintext">
      $yymain<br />
  </div>

  <div class="nav-container">
	<div class="$NavItem0">$NavLink0</div>
	<div class="$NavItem1">$NavLink1</div>
	<div class="$NavItem2">$NavLink2</div>
	<div class="$NavItem3">$NavLink3</div>
	<div class="$NavItem4">$NavLink4</div>
	<div class="$NavItem5">$NavLink5</div>
	<div class="$NavItem6">$NavLink6</div>
  </div>

</div>

</body>
</html>
~;
exit;
}


sub CreateLock {
  fopen("LOCKFILE", ">$vardir/Converter.lock");
    print LOCKFILE q~This is a lockfile for the Converter.\n~;
    print LOCKFILE q~It prevents it being run again after it has been run once.\n~;
    print LOCKFILE q~Delete this file if you want to run the Converter again.~;

  fclose("LOCKFILE");
}

sub CreateLock2 {
  fopen("LOCKFILE", ">$vardir/Setup.lock");
    print LOCKFILE q~This is a lockfile for the Setup Utility.\n~;
    print LOCKFILE q~It prevents it being run again after it has been run once.\n~;
    print LOCKFILE q~Delete this file if you want to run the Setup Utility again.~;

  fclose("LOCKFILE");
}

sub FoundLock {
  $yymain = qq~
  <span class="warn-text">The Converter has already been run, attempting to run the converter will cause damage to your files.<br /><br />
To run the converter again, remove the files "$vardir/Setup.lock", and "$vardir/Converter.lock" - and re-visit this page.</span>~;

  $NavLink0 = qq~ReadMe~;
  $NavLink1 = qq~Step 1~;
  $NavLink2 = qq~Step 2~;
  $NavLink3 = qq~Step 3~;
  $NavLink4 = qq~Step 4~;
  $NavLink5 = qq~Step 5~;
  $NavLink6 = qq~Login~;

&Output;
}

sub FoundLock2 {
  $yymain = qq~
  <span class="warn-text">The Converter has already been run, attempting to run the converter will cause damage to your files.<br /><br />
To run the converter again, remove the files "$vardir/Setup.lock", and "$vardir/Converter.lock" - and re-visit this page.</span>~;

&Output2;
}

# Prepare Conversion #########################################################

sub PrepareConv {
	if (-e "$memberdir/admin.vars"){unlink "$memberdir/admin.vars";}
	if (-e "$memberdir/memberlist.txt"){unlink "$memberdir/memberlist.txt";}
	if (-e "$memberdir/members.ttl"){unlink "$memberdir/members.ttl";}
	if (-e "$datadir/1105634410.ctb"){unlink "$datadir/1105634410.ctb"; unlink "$datadir/1105634410.txt";}
	if (-e "$boardsdir/generely2rc1.txt"){unlink "$boardsdir/generely2rc1.txt";}
	if (-e "$boardsdir/forum.master"){unlink "$boardsdir/forum.master";}
	if (-e "$boardsdir/forum.control"){unlink "$boardsdir/forum.control";}
	if (-e "$boardsdir/forum.totals"){unlink "$boardsdir/forum.totals";}
}

# / Prepare Conversion ##########################################################


# Board/Category Conversion #########################################################

my (@categoryorder, @catboards, @catdata, @boarddata, @allboards);
my (%catinfo, %cat, %board, %boarddata);
my ($catfile, $boardfile, $key, $value, $cnt);

sub GetCats {

	fopen(VDIR, "$vardir/cat.txt");
	@categoryorder = <VDIR>;
	fclose(VDIR);
	my @allboards;
	foreach $fcat(@categoryorder){
		chomp $fcat;
		my @catboards;
		fopen (VCAT,"$boardsdir/$fcat.cat");
		@catdata = <VCAT>;
		fclose (VCAT);
		chomp $catdata[0];
		chomp $catdata[1];
		$catinfo {$fcat} = qq~$catdata[0]|$catdata[1]|1~;
		for ($cnt=2; $cnt <= $#catdata; $cnt++){
			chomp $catdata[$cnt];
			unless (!$catdata[$cnt]){
				push (@catboards,$catdata[$cnt]);
				push (@allboards,$catdata[$cnt]);
			}
		}
		$cat{$fcat} = join(',', @catboards);
	}
	foreach $fboard(@allboards){
		chomp $fboard;
		fopen(VBRD,"$boardsdir/$fboard.dat");
		@bdata = <VBRD>;
		fclose (VBRD);
		chomp $bdata[0];
		$board {$fboard} = qq~$bdata[0]||~;
	}

	&writemaster;
}


sub writemaster {
	fopen(FILE, ">$boardsdir/forum.master", 1);	
		print FILE qq~\$mloaded = 1;\n~;
		print FILE qq~\@categoryorder = qw(@categoryorder);\n~;
    		while (($key, $value) = each(%cat)){
        		print FILE qq~\$cat{'$key'} = "$value";\n~;
    		}
    		while (($key, $value) = each(%catinfo)){
        		print FILE qq~\$catinfo{'$key'} = "$value";\n~;
    		}
    		while (($key, $value) = each(%board)){
        		print FILE qq~\$board{'$key'} = "$value";\n~;
    		}
    		print FILE qq~\n1;~;
	fclose(FILE);
}


sub CreateControl {
	opendir("BDIR", $boardsdir);
	@boardlist = grep {/\.dat$/} readdir("BDIR");
	closedir("BDIR");
	foreach $file (@boardlist) {
		chomp $file;
		$foundboard = substr($file,0, length($file)-4);

		push(@boardfiles,$foundboard);

		# get category
		fopen("CINFO", "$boardsdir/$foundboard.ctb");
		@category = <CINFO>;
		fclose("CINFO");
		chomp $category[0];
		$cntcat = $category[0];

		# get boardinfo
		fopen ("BINFO", "$boardsdir/$foundboard.dat");
		@boardinfo = <BINFO>;
		fclose ("BINFO");
		chomp ($boardinfo[0], $boardinfo[1], $boardinfo[2], $boardinfo[3]);

		$boardinfo[2] =~ /^\|(.*?)\|$/;
  	      $boardinfo[2] =~ s/\|(\S?)/,$1/g;
		$cntpic = "";
		$cntdescription = $boardinfo[1];
		$cntmods = $boardinfo[2];
		$cntmodgroups = $boardinfo[3];

		# get board access data
		fopen ("PERMS", "$boardsdir/$foundboard.mbo");
		@permissions = <PERMS>;
		fclose ("PERMS");
		chomp @permissions;

		$cntstartperms = $permissions[0];
		$cntreplyperms = $permissions[1];
		$cntpollperms = $permissions[2];
		$cntstartperms =~ s/ //g;
		$cntreplyperms =~ s/ //g;
		$cntpollperms =~ s/ //g;
		$cntzero = $permissions[3];
		$cntpassword = "";
		$cnttotals = "";
		$cntattperms = "";
		$spare = "";
		push(@boardcontrol,"$cntcat|$foundboard|$cntpic|$cntdescription|$cntmods|$cntmodgroups|$cnttopicperms|$cntreplyperms|$cntpollperms|$cntzero|$cntpassword|$cnttotals|$cntattperms|$spare\n");
		## clean up ##
	}
	fopen("CONTROL", ">$boardsdir/forum.control");
	@boardcontrol = sort(@boardcontrol);
	print CONTROL @boardcontrol;
	fclose("CONTROL");

	&ConvertBoards;
	&CleanUpBoards;
}

sub ConvertBoards {
	## converting board files and totals
	fopen("DATADIR", "$boardsdir/sticky.stk");
	@stickies = <DATADIR>;
	fclose("DATADIR");

	opendir("DATADIR", $boardsdir);
	@boards = grep {/\.txt$/} readdir("DATADIR");
	closedir("DATADIR");

	foreach $file(@boards) {
		chomp $file;
		$foundfile = substr($file,0, length($file)-4);

		fopen(BOARDFILE, "$boardsdir/$foundfile.txt") || &fatal_error("$maintxt{'23'} $foundfile.txt", 1);
		@boardfile = <BOARDFILE>;
		fclose(BOARDFILE);

		fopen(BOARDFILE, ">$boardsdir/$foundfile.txt") || &fatal_error("$maintxt{'23'} $foundfile.txt", 1);
		foreach my $line (@boardfile){
			chomp $line;
			my ($mnum, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate) = split(/\|/,$line);
			$mdate =~ s~(\d{2}\/\d{2}\/\d{2}).*?(\d{2}\:\d{2}\:\d{2})~&stringtotime("$1 at $2")~eis;
			foreach $sticky(@stickies){
				chomp $sticky;
				if ($sticky eq $mnum){$mstate .="s"; last;}
			}
			$mstate =~ s/1/l/g;
			print BOARDFILE "$mnum|$msub|$mname|$memail|$mdate|$mreplies|$musername|$micon|$mstate\n";
		}
		fclose(BOARDFILE);

		fopen(BOARDTTL, "$boardsdir/$foundfile.ttl") || &fatal_error("$maintxt{'23'} $foundfile.ttl", 1);
		$boardttl = <BOARDTTL>;
		fclose(BOARDTTL);
		chomp $boardttl;
		my($dummy1, $dummy2, $mdate, $dummy3) = split(/\|/,$boardttl);
		$mdate =~ s~(\d{2}\/\d{2}\/\d{2}).*?(\d{2}\:\d{2}\:\d{2})~&stringtotime("$1 at $2")~eis;

		fopen(BOARDTTL, ">$boardsdir/$foundfile.ttl") || &fatal_error("$maintxt{'23'} $foundfile.ttl", 1);
		print BOARDTTL "$dummy1|$dummy2|$mdate|$dummy3\n";
		fclose(BOARDTTL);
	}
}


sub CleanUpBoards {
	foreach $cleanfile (@boardfiles) {
		chomp $cleanfile;
		my @xtn = qw(mbo dat);

		for(my $cnt; $cnt< @xtn; $cnt++){
			if (-e "$boardsdir/$cleanfile.$xtn[$cnt]"){unlink "$boardsdir/$cleanfile.$xtn[$cnt]";}
		}
	}
}

# / Board/Category Conversion ##########################################################


# Member Conversion ###########################################################

sub ConvertMembers {
	opendir(MEMDIR, $memberdir);
	@memlist = grep {/\.dat$/} readdir(MEMDIR);
	closedir(MEMDIR);
	$prcontinue = 0;
	if($#memlist > 3000) { $prstep = 3000; $prcontinue = 1; }
	else { $prstep = $#memlist; }

	for($i=0; $i<=$prstep; $i++) {
		$file = $memlist[$i];
		chomp $file;
		($uname, $ext) = split(/\./, $file);
		&MyUpdateUser($uname);
		my @xtn = qw(da2 ll om yam gbs gst bud mim pop siz title mute ybl prolock ign txt bio siz imconfig);
		for(my $cnt; $cnt < @xtn; $cnt++){
			if (-e "$memberdir/$uname.$xtn[$cnt]"){unlink "$memberdir/$uname.$xtn[$cnt]";}
		}
	}
	$memleft = $#memlist - $prstep;
	if($prcontinue) {
		$yySetLocation = qq~Setup.pl?action=members2;memleft=$memleft~;
		&redirectexit;
	}
}

sub MyUpdateUser {
	my $user = $_[0];
	fopen(LOADOLDUSER, "$memberdir/$user.dat");
	my @settings=<LOADOLDUSER>;
	fclose(LOADOLDUSER);
	for( my $cnt = 0; $cnt < @settings; $cnt++ ) {
		$settings[$cnt] =~ s/[\r\n]//g;
		chomp $settings[$cnt];
	}
	%{$uid.$user}=(
		'password' => "$settings[0]",
		'realname' => "$settings[1]",
		'email' => "$settings[2]",
		'webtitle' => "$settings[3]",
		'weburl' => "$settings[4]",
		'signature' => "$settings[5]",
		'postcount' => "$settings[6]",
		'position' => "$settings[7]",
		'icq' => "$settings[8]",
		'aim' => "$settings[9]",
		'yim' => "$settings[10]",
		'gender' => "$settings[11]",
		'usertext' => "$settings[12]",
		'userpic' => "$settings[13]",
		'regdate' => "$settings[14]",
		'location' => "$settings[15]",
		'bday' => "$settings[16]",
		'timeselect' => "$settings[17]",
		'timeoffset' => "$settings[18]",
		'hidemail' => "$settings[19]",
		'msn' => "$settings[20]",
		'template' => "default",
		'language' => "$settings[22]",
		'lastonline' => "$settings[23]",
		'lastpost' => "$settings[24]",
		'lastim' => "$settings[25]",
		'im_ignorelist' => "$settings[26]",
		'im_notify' => "$settings[27]",
		'im_popup' => "$settings[28]",
		'im_imspop' => "$settings[29]",
		'cathide' => "$settings[30]",
		'postlayout' => "$settings[31]",
		'pageindex' => "1|1|1"
	);

	my @tags = qw(password realname email webtitle weburl signature postcount position addgroups icq aim yim gender usertext userpic regdate location bday timeselect timeoffset timeformat hidemail msn template language lastonline lastpost lastim im_ignorelist im_notify im_popup im_imspop cathide postlayout session sesquest sesanswer favorites dsttimeoffset pageindex);
	fopen(UPDATEUSER, ">$memberdir/$user.vars");
		print UPDATEUSER "### User variables for ID: $user ###\n\n";
		for( my $cnt = 0; $cnt < @tags; $cnt++ ) {
			print UPDATEUSER "\'$tags[$cnt]\'\,\"${$uid.$user}{$tags[$cnt]}\"\n";
		}
	fclose(UPDATEUSER);
	unlink "$memberdir/$user.dat";

}

# / Member Conversion #########################################################


# Message Conversion ##########################################################

sub ConvertMessages {

	## converting message files

	opendir("BOARDSDIR", $boardsdir);
	@messages =  grep {/\.txt$/} readdir(BOARDSDIR);
	closedir("BOARDSDIR");
	foreach $file (@messages) {
		chomp $file;
		($foundfile, $ext) = split(/\./, $file);
		fopen("BRDFILE", "$boardsdir/$foundfile.txt");
		@messagefile = <BRDFILE>;
		fclose("BRDFILE");

		foreach my $line (@messagefile){
			chomp $line;
			my ($thread,$dummy) = split(/\|/,$line,2);
			if (-e "$datadir/$thread.txt"){
				$views = 1;
				$lastposter = "";

				if (-e "$datadir/$thread.data"){
					fopen(DATA, "$datadir/$thread.data");
					$data = <DATA>;
					fclose(DATA);
					chomp $data;
					($views,$lastposter) = split(/\|/,$data);
				}

				fopen(CTB, ">$datadir/$thread.ctb");
				print CTB "$foundfile\n\n";
				print CTB "$views\n";
				print CTB "$lastposter\n";
				fclose(CTB);
				unlink "$datadir/$thread.data";

				fopen("MSGFILE", "$datadir/$thread.txt");
				@messagelines = <MSGFILE>;
				fclose("MSGFILE");

				fopen("MSGFILE", ">$datadir/$thread.txt");
				foreach my $msgline (@messagelines){
					chomp $msgline;
					my ($subject,$name,$email,$mdate,$username,$icon,$dummy,$user_ip,$message,$ns,$editdate,$editby) = split(/\|/,$msgline);
					$message =~ s~\[quote(\s+author=(.*?)link=(.*?)\s+date=(.*?)\s*)?\]\n*(.*?)\n*\[/quote\]~&QuoteFix($2,$3,$4,$5)~eisg;
					$mdate =~ s~(\d{2}\/\d{2}\/\d{2}).*?(\d{2}\:\d{2}\:\d{2})~&stringtotime("$1 at $2")~eis;
					$editdate =~ s~(\d{2}\/\d{2}\/\d{2}).*?(\d{2}\:\d{2}\:\d{2})~&stringtotime("$1 at $2")~eis;
					chomp $editdate;
					print MSGFILE "$subject|$name|$email|$mdate|$username|$icon|$dummy|$user_ip|$message|$ns|$editdate|$editby\n";
				}
				fclose("MSGFILE");

			}
		}
	}
}

# / Message Conversion ########################################################


# Date Conversion #############################################################

sub ConvertTimeToString {

	# Convert Dates in IM's
	# Start with the inbox...
	opendir(MEMDIR, $memberdir);
	@inboxlist =  grep {/\.msg$/} readdir(MEMDIR);
	closedir(MEMDIR);
	foreach $file(@inboxlist) {
		chomp $file;
		fopen("INBOX", "$memberdir/$file") || &fatal_error("$maintxt{'23'} $file", 1);
		@messagefile = <INBOX>;
		fclose("INBOX");

		fopen("INBOX", ">$memberdir/$file") || &fatal_error("$maintxt{'23'} $file", 1);

		foreach $line (@messagefile){
			chomp $line;
			($name,$subject,$date,$message,$id,$ip) = split(/\|/,$line);
			$date =~ s~(\d{2}\/\d{2}\/\d{2}).*?(\d{2}\:\d{2}\:\d{2})~&stringtotime("$1 at $2")~eis;
			print INBOX "$name|$subject|$date|$message|$id|$ip\n";
		}
		fclose("INBOX");
	}

	# Now do the outbox..
	opendir(MEMDIR, $memberdir);
	@outboxlist =  grep {/\.outbox$/} readdir(MEMDIR);
	closedir(MEMDIR);
	foreach $file(@outboxlist) {
		chomp $file;
		fopen("OUTBOX", "$memberdir/$file") || &fatal_error("$maintxt{'23'} $file", 1);
		@messagefile = <OUTBOX>;
		fclose("OUTBOX");

		fopen("OUTBOX", ">$memberdir/$file") || &fatal_error("$maintxt{'23'} $file", 1);

		foreach $line (@messagefile){
			chomp $line;
			($name,$subject,$date,$message,$id,$ip,$read_flag) = split(/\|/,$line);
			$date =~ s~(\d{2}\/\d{2}\/\d{2}).*?(\d{2}\:\d{2}\:\d{2})~&stringtotime("$1 at $2")~eis;
			print OUTBOX "$name|$subject|$date|$message|$id|$ip|$read_flag\n";
		}
		fclose("OUTBOX");
	}

	#...and the Polls
	opendir("DATADIR", $datadir);
	@polls =  grep {/\.poll$/} readdir(DATADIR);
	closedir("DATADIR");
	foreach $file(@polls) {
		chomp $file;
		fopen("POLLFILE", "$datadir/$file") || &fatal_error("$maintxt{'23'} $file", 1);
		@pollsfile = <POLLFILE>;
		fclose("POLLFILE");
		fopen("POLLFILE", ">$datadir/$file") || &fatal_error("$maintxt{'23'} $file", 1);
		chomp $pollsfile[0];
		my ($dummy1,$dummy2,$dummy3,$dummy4,$dummy5,$pdate,$dummy6,$dummy7,$dummy8,$epdate,$dummy10,$dummy11) = split(/\|/,$pollsfile[0]);
		$pdate =~ s~(\d{2}\/\d{2}\/\d{2}).*?(\d{2}\:\d{2}\:\d{2})~&stringtotime("$1 at $2")~eis;
		$epdate =~ s~(\d{2}\/\d{2}\/\d{2}).*?(\d{2}\:\d{2}\:\d{2})~&stringtotime("$1 at $2")~eis;
		chomp $epdate;
		print POLLFILE "$dummy1|$dummy2|$dummy3|$dummy4|$dummy5|$pdate|$dummy6|$dummy7|$dummy8|$epdate|$dummy10|$dummy11\n";
		for($i=1; $i<@pollsfile; $i++) {
			chomp $pollsfile[$i];
			print POLLFILE "$pollsfile[$i]\n";
		}
		fclose("POLLFILE");
	}
	opendir("DATADIR", $datadir);
	@polled =  grep {/\.polled$/} readdir(DATADIR);
	closedir("DATADIR");
	foreach $file(@polled) {
		chomp $file;
		fopen("POLLEDFILE", "$datadir/$file") || &fatal_error("$maintxt{'23'} $file", 1);
		@polledfile = <POLLEDFILE>;
		fclose("POLLEDFILE");
		fopen("POLLEDFILE", ">$datadir/$file") || &fatal_error("$maintxt{'23'} $file", 1);
		foreach $line (@polledfile){
			chomp $line;
			my ($dummy1,$dummy2,$dummy3,$pdate) = split(/\|/,$line);
			$pdate =~ s~(\d{2}\/\d{2}\/\d{2}).*?(\d{2}\:\d{2}\:\d{2})~&stringtotime("$1 at $2")~eis;
			print POLLEDFILE "$dummy1|$dummy2|$dummy3|$pdate\n";
		}
		fclose("POLLEDFILE");
	}


}

sub QuoteFix {
	my( $qauthor, $qlink, $qdate, $qmessage ) = @_;
	if ($qauthor eq "" || $qlink eq "" || $qdate eq ""){
		$_ = qq~[quote]QUOTE[/quote]~;
	}
	else {
		$qdate = &stringtotime($qdate);
		($dummy, $threadlink, $start) = split(/\;/, $qlink);
		($dummy, $start) = split(/=/, $start);
		($dummy, $num) = split(/=/, $threadlink);
		$_ = qq~[quote author=AUTHOR link=QUOTELINK date=DATE]QUOTE[/quote]~;
	}
	$_ =~ s~AUTHOR~$qauthor~g;
	$_ =~ s~QUOTELINK~$num/$start~g;
	$_ =~ s~DATE~$qdate~g;
	$_ =~ s~QUOTE~$qmessage~g;
	return $_;
}


# / Date Conversion ###########################################################


# Cleanup #####################################################################

sub MyMemberIndex {
	opendir(MEMBERS, $memberdir);
	@contents = grep {/\.vars$/} readdir(MEMBERS);
	closedir(MEMBERS);
	$countnoregtime=0;
	$regcounter=0;
	foreach $member (@contents){
 		$member =~ s/\.vars$//g;
		if ($member) { 
			chomp $member;
			&UserCheck($member,"realname+email+regdate");
			$email{$member} = $usercheck{'email'};
			$realname{$member} = $usercheck{'realname'};
			if ($usercheck{'regdate'}) {
 				$regtime = stringtotime($usercheck{'regdate'});
 				while ( $members{$regtime} ) { $regtime++; } #check same registered date/time
  				$members{$regtime} = $member;
 			} else {
 				$membersnoregtime[$countnoregtime] = $member;
 				$countnoregtime++;
 			} 	$regcounter++;
		} 		}
 	@num = sort {$a <=> $b } keys %members;
	fopen(MEMLIST, ">$memberdir/memberlist.txt", 1);
	if ($countnoregtime>0) {
		foreach $member (@membersnoregtime){
			chomp $member;
			print MEMLIST "$member\|$email{$member}\|$realname{$member}\n";
		}
	}
	for ($i=0; $i<@num; $i++) {
		print MEMLIST  "$members{$num[$i]}\|$email{$members{$num[$i]}}\|$realname{$members{$num[$i]}}\n";
	}
	fclose(MEMLIST);
	&MembershipCountTotal;
	return 0;
}

sub MyThreadRecount {
	opendir (DIRECTORY,"$datadir");
	while ( $file = readdir(DIRECTORY)) {
		next unless grep {/\.txt$/} $file;
		($filename, $fileext) = split(/\./, $file);
		fopen(MSG,"$datadir/$filename.txt");
		@messages = <MSG>;
		fclose (MSG);
		@lastmessage = split( /\|/, $messages[$#messages]);
		&MessageTotals("load",$filename);
		${$filename}{'replies'} = $#messages;
		${$filename}{'lastposter'} = $lastmessage[4] eq "Guest" ? qq~Guest-$lastmessage[1]~ : $lastmessage[4];
		&MessageTotals("update",$filename);
	} 
	closedir (DIRECTORY);
}


sub MyReCountTotals {
	my $cntboard = $_[0];
	unless( $cntboard ) { return undef; }
	&BoardTotals("convert",$cntboard);
	my( @threads, $threadcount, $messagecount, $i, $threadline );

	fopen(BOARD, "$boardsdir/$cntboard.txt");
	@threads = <BOARD>;
	fclose(BOARD);
	$threadcount = @threads;
	$messagecount = $threadcount;
	if ($threadcount) {
		for ($i = 0; $i < @threads; $i++) {
			@threadline= split(/\|/,$threads[$i]);
			$messagecount += $threadline[5];
		}
	}
	&BoardTotals("load",$cntboard);
	${$uid.$cntboard}{'threadcount'}  = $threadcount ;
	${$uid.$cntboard}{'messagecount'} = $messagecount ;
	&BoardTotals("update",$cntboard);
	&BoardSetLastInfo($cntboard);
}


sub CleanUpBoardsAgain {
    opendir(BOARDS, "$boardsdir");
      @cleanfiles =  grep {/\.ttl$/ || /\.poster$/ || /\.stk$/ || /\.ctb$/ || /\.cat$/} readdir(BOARDS);
    closedir(BOARDS);

	foreach $cleanfile (@cleanfiles) {
		chomp $cleanfile;
		if (-e "$boardsdir/$cleanfile"){
          unlink "$boardsdir/$cleanfile";
        }
	}
}

# / Cleanup ###################################################################



sub RunSetup {

if( $ENV{'SERVER_SOFTWARE'} =~ /IIS/ ) { 
      $yyIIS = 1; 
      $0 =~ m~(.*)(\\|/)~; 
      $yypath = $1; 
      $yypath =~ s~\\~/~g; 
      chdir($yypath); 
      push(@INC,$yypath); 
}

$yycharset = "ISO-8859-1";
$cookieusername = "YaBBsetupusername";                                  # Name of the username cookie
$cookiepassword = "YaBBsetuppassword";                                  # Name of the password cookie
@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
@months = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

$windowbg="#FAFAFA";
$header="#5488BA";
$catbg="#DDDDDD";
$boarddir =".";

if(!$action){&CheckInstall;}
if($action eq "adminlogin"){&adminlogin;}
if($action eq "adminlogin2"){&adminlogin2;}
if($action eq "setup1"){&autoconfig;}
if($action eq "setup2"){&save_settings;}
if($action eq "test"){&test_who;}
if($action eq "ready"){&ready;}

$yymain = "End of script reached without action: $action";
&Output2;
exit;


}


# Setup Subs ##################################################################

sub adminlogin {

  if(-e "$vardir/Setup.lock") {
      &FoundLock2;
  }

	$yymain .= qq~
	<br /><br /><br /><form action="Setup.pl?action=adminlogin2" method="post"><center>
	<table width="20%" border="0" bgcolor= "#000000" cellspacing="1" cellpadding="0">
	<tr><td>
	<table width="100%" border="0" bgcolor= "$windowbg" cellspacing="1" cellpadding="3">
	<tr>
		<td width="100%" align="center">
		<font face="Arial" size="2" color="#000000">
		Enter the password for user <b>admin</b><br />to gain access to the Setup Utility
		</font>
		</td>
	</tr>
	<tr>
		<td width="100%" align="center">
		<font face="Arial" size="2" color="#000000">
		<input type="password" size="30" name="password" />
		<input type="hidden" name="username" value="admin" />
		<input type="hidden" name="cookielength" value="1500" />
		</font>
		</td>
	</tr>
	<tr>
		<td width="100%" align="center">
		<font face="Arial" size="2" color="#000000">
		<input type="submit" value="Submit" />
		</font>
		</td>
	</tr>
	</table>
	</td></tr></table></center></form>
	~;
	&Output2;
	exit;
}


sub adminlogin2 {

  if(-e "$vardir/Setup.lock") {
      &FoundLock2;
  }

	if($FORM{'password'} eq ""){$yymain="Setup Error: You should fill out your password!";&Output2; }
	$username = $FORM{'username'};
	if(-e("$memberdir/$username.dat") || -e("$memberdir/$username.vars")) {
		&LoadUser($username);
		my $spass = ${$uid.$username}{'password'};
		$cryptpass = &encode_password($FORM{'password'});
		if($spass ne $cryptpass && $spass ne $FORM{'password'}) { $yymain="Setup Error: Login Failed!"; &Output2; }

	} else { $yymain="Setup Error: Could not find the admin data file! Please check your access rights"; &Output2; }


	if($FORM{'cookielength'} < 1 || $FORM{'cookielength'} > 9999) { $FORM{'cookielength'} = $Cookie_Length; }
	if(!$FORM{'cookieneverexp'}) { $ck{'len'} = "\+$FORM{'cookielength'}m"; }
	else { $ck{'len'} = 'Sunday, 17-Jan-2038 00:00:00 GMT'; }
	$password = &encode_password("$FORM{'password'}");
	${$uid.$username}{'session'} = &encode_password($user_ip);
	chomp ${$uid.$username}{'session'};

&UpdateCookie("write","$username","$password","${$uid.$username}{'session'}","/","$ck{'len'}");
	&LoadUserSettings;
	$yymain .= qq~
	<br /><br /><br /><form action="Setup.pl?action=setup1" method="post"><center>
	<table width="50%" border="0" bgcolor= "#000000" cellspacing="1" cellpadding="0">
	<tr><td>
	<table width="100%" border="0" bgcolor= "$windowbg" cellspacing="1" cellpadding="3">
	<tr>
		<td width="100%" align="center">
		<font face="Arial" size="2" color="#000000">
		You are now Logged In $settings[1]!<br />Click Continue to proceed with the Setup.
		</font>
		</td>
	</tr>
	<tr>
		<td width="100%" align="center">
		<font face="Arial" size="2" color="#000000">
		<input type="submit" value="Continue Set Up" />
		</font>
		</td>
	</tr>
	</table>
	</td></tr></table></center></form>
	~;

	&Output2;
	exit;
}



sub autoconfig {

  if(-e "$vardir/Setup.lock") {
      &FoundLock2;
  }

&LoadCookie;		# Load the user's cookie (or set to guest)
&LoadUserSettings;	# Load user settings
if (!$iamadmin){ $yymain="Setup Error: You have no access rights to this function, only user admin has if logged in !"; &Output2; }
## do some fancy auto sensing ##
	$template = "default";
	$forumstyle = "Forum";
	$adminstyle = "Admin";

	## find the script url ##
	## Getting the last known url one way or another
	if($ENV{HTTP_REFERER}){ 
		$tempboardurl = $ENV{HTTP_REFERER};
	} 
	elsif($ENV{HTTP_HOST}&& $ENV{REQUEST_URI}){
		$tempboardurl = qq~http://$ENV{HTTP_HOST}$ENV{REQUEST_URI}~;
	}
	$lastslash = rindex($tempboardurl,"/");
	$foundboardurl = substr($tempboardurl,0,$lastslash);

	## find the webroot ##
	if( $ENV{'SERVER_SOFTWARE'} =~ /IIS/ ) {
		$this_script = "$ENV{'SCRIPT_NAME'}";
		$_ = $0;
		s#\\#/#g;
		s#$this_script##;
		$searchroot= $_ . '/';
	} else {
 		$searchroot = $ENV{'DOCUMENT_ROOT'};
	}
	$firstslash = index($tempboardurl,"/",8);
	$html_baseurl = substr($tempboardurl,0,$firstslash);

	## try to find the yabb html basedir directly ##
	if (-d "$searchroot/yabbfiles"){
		$fnd_html_root = "$html_baseurl/yabbfiles";
		$fnd_htmldir = "$searchroot/yabbfiles";
		$fnd_htmldir =~ s~//~/~g;
		opendir(HTMLDIR, "$fnd_htmldir");
			@contents = readdir(HTMLDIR);
		closedir(HTML);
		foreach $name(@contents) {
			chomp $name;
			if(lc($name) eq "avatars" && (-d "$fnd_htmldir/$name")) { $fnd_facesdir = "$fnd_htmldir/$name"; $fnd_facesurl = "$fnd_html_root/$name";}
			if(lc($name) eq "modimages" && (-d "$fnd_htmldir/$name")) { $fnd_modimgdir = "$fnd_htmldir/$name"; $fnd_modimgurl = "$fnd_html_root/$name";}
			if(lc($name) eq "templates" && (-d "$fnd_htmldir/$name/$forumstyle")) { $fnd_forumstylesdir = "$fnd_htmldir/$name/$forumstyle"; $fnd_forumstylesurl = "$fnd_html_root/$name/$forumstyle";}
			if(lc($name) eq "templates" && (-d "$fnd_htmldir/$name/$adminstyle")) { $fnd_adminstylesdir = "$fnd_htmldir/$name/$adminstyle"; $fnd_adminstylesurl = "$fnd_html_root/$name/$adminstyle";}
	    		if(lc($name) eq "smilies" && (-d "$fnd_htmldir/$name")) { $fnd_smiliesdir = "$fnd_htmldir/$name"; $fnd_smiliesurl = "$fnd_html_root/$name";}
			if(lc($name) eq "attachments" && (-d "$fnd_htmldir/$name")) { $fnd_uploaddir = "$fnd_htmldir/$name"; $fnd_uploadurl = "$fnd_html_root/$name";}
			if (-d "$fnd_forumstylesdir/$template"){$fnd_imagesdir = "$fnd_forumstylesurl/$template"; }
			if (-e "$fnd_htmldir/ubbc.js") {$fnd_ubbcjspath = "$fnd_html_root/ubbc.js"; }
			if (-e "$fnd_htmldir/fader.js") {$fnd_faderpath = "$fnd_html_root/fader.js"; }
			if (-e "$fnd_htmldir/yabbc.js") {$fnd_yabbcjspath = "$fnd_html_root/yabbc.js"; }
			if (-e "$fnd_htmldir/post.js") {$fnd_postjspath = "$fnd_html_root/post.js"; }
		}
	} else {
		$fnd_html_root = "$html_baseurl/yabbfiles";
		opendir(HTMLDIR, "$searchroot");
			@contents = readdir(HTMLDIR);
		closedir(HTML);
		foreach $name(@contents) {
			chomp $name;
			if (-d "$searchroot/$name"){
				opendir(HTMLDIR, "$searchroot/$name");
					@subcontents = readdir(HTMLDIR);
				closedir(HTML);
				foreach $subname(@subcontents) {
					chomp $subname;
					if(lc($subname) eq "yabbfiles" && (-d "$searchroot/$name/$subname")) {
						$fnd_htmldir = "$searchroot/$name/$subname";
						$fnd_htmldir =~ s~//~/~g;
					}
				}
			}
		}
		opendir(HTMLDIR, "$fnd_htmldir");
			@tcontents = readdir(HTMLDIR);
		closedir(HTML);
		foreach $tname(@tcontents) {
			chomp $tname;
			if(lc($tname) eq "avatars" && (-d "$fnd_htmldir/$tname")) { $fnd_facesdir = "$fnd_htmldir/$tname"; $fnd_facesurl = "$fnd_html_root/$tname";}
			if(lc($tname) eq "modimages" && (-d "$fnd_htmldir/$tname")) { $fnd_modimgdir = "$fnd_htmldir/$tname"; $fnd_modimgurl = "$fnd_html_root/$tname";}
			if(lc($tname) eq "templates" && (-d "$fnd_htmldir/$tname/$forumstyle")) { $fnd_forumstylesdir = "$fnd_htmldir/$tname/$forumstyle"; $fnd_forumstylesurl = "$fnd_html_root/$tname/$forumstyle";}
			if(lc($tname) eq "templates" && (-d "$fnd_htmldir/$tname/$adminstyle")) { $fnd_adminstylesdir = "$fnd_htmldir/$tname/$adminstyle"; $fnd_adminstylesurl = "$fnd_html_root/$tname/$adminstyle";}
	    		if(lc($tname) eq "smilies" && (-d "$fnd_htmldir/$tname")) { $fnd_smiliesdir = "$fnd_htmldir/$tname"; $fnd_smiliesurl = "$fnd_html_root/$tname";}
	    		if(lc($tname) eq "attachments" && (-d "$fnd_htmldir/$tname")) { $fnd_uploaddir = "$fnd_htmldir/$tname"; $fnd_uploadurl = "$fnd_html_root/$tname";}
			if (-d "$fnd_forumstylesdir/$template"){$fnd_imagesdir = "$fnd_forumstylesurl/$template"; }
			if (-e "$fnd_htmldir/ubbc.js") {$fnd_ubbcjspath = "$fnd_html_root/ubbc.js"; }
			if (-e "$fnd_htmldir/fader.js") {$fnd_faderpath = "$fnd_html_root/fader.js"; }
			if (-e "$fnd_htmldir/yabbc.js") {$fnd_yabbcjspath = "$fnd_html_root/yabbc.js"; }
			if (-e "$fnd_htmldir/post.js") {$fnd_postjspath = "$fnd_html_root/post.js"; }
		}
	}
	$fnd_boardurl = $foundboardurl;
	$fnd_boarddir = ".";
	if(-d "$fnd_boarddir/Boards"){$fnd_boardsdir = "$fnd_boarddir/Boards";}
	if(-d "$fnd_boarddir/Messages"){$fnd_datadir = "$fnd_boarddir/Messages";}
	if(-d "$fnd_boarddir/Members"){$fnd_memberdir = "$fnd_boarddir/Members";}
	if(-d "$fnd_boarddir/Sources"){$fnd_sourcedir = "$fnd_boarddir/Sources";}
	if(-d "$fnd_boarddir/Admin"){$fnd_admindir = "$fnd_boarddir/Admin";}
	if(-d "$fnd_boarddir/Variables"){$fnd_vardir = "$fnd_boarddir/Variables";}
	if(-d "$fnd_boarddir/Languages"){$fnd_langdir = "$fnd_boarddir/Languages";}
	if(-d "$fnd_boarddir/Help"){$fnd_helpfile = "$fnd_boarddir/Help";}
	if(-d "$fnd_boarddir/Templates"){$fnd_templatesdir = "$fnd_boarddir/Templates";}

	if(-e "Paths.pl"){
		require "Paths.pl";
	} else {
		$boardurl = $fnd_boardurl;
		$boarddir = $fnd_boarddir;
		$datadir = $fnd_datadir;
		$boardsdir = $fnd_boardsdir;
		$htmldir = $fnd_htmldir;
		$html_root = $fnd_html_root;
		$memberdir = $fnd_memberdir;
		$sourcedir = $fnd_sourcedir;
		$admindir = $fnd_admindir;
		$vardir = $fnd_vardir;
		$langdir = $fnd_langdir;
		$helpfile = $fnd_helpfile;		
		$templatesdir = $fnd_templatesdir;
		$forumstylesdir = $fnd_forumstylesdir;
		$forumstylesurl = $fnd_forumstylesurl;
		$adminstylesdir = $fnd_adminstylesdir;
		$adminstylesurl = $fnd_adminstylesurl;
		$facesdir = $fnd_facesdir;
		$facesurl = $fnd_facesurl;
		$smiliesdir = $fnd_smiliesdir;
		$smiliesurl = $fnd_smiliesurl;
		$modimgdir = $fnd_modimgdir;
		$modimgurl = $fnd_modimgurl;
		$uploaddir = $fnd_uploaddir;
		$uploadurl = $fnd_uploadurl;
		$ubbcjspath = $fnd_ubbcjspath;
		$faderpath = $fnd_faderpath;
		$yabbcjspath = $fnd_yabbcjspath;
		$postjspath = $fnd_postjspath;
	}
	
## Generate Screen
$mylastdate = &timeformat($lastdate);
	$yymain .= qq~
	<form action="Setup.pl?action=setup2" method="post" name="auto_settings"><center>
	<table width="60%" border="0" bgcolor= "#000000" cellspacing="0" cellpadding="0">
	<tr><td>
	<table width="100%" border="0" cellspacing="1" cellpadding="3">
	<tr>
		<td width="20%" bgcolor= "$header" align="left"><font face="Arial" size="2" color="#000000">User Logged In: $realname<br /></font>
		<input type="hidden" name="lastsaved" value="$realname"><input type="hidden" name="lastdate" value="$date"></td>
		<td colspan="3" bgcolor= "$header" width="100%" align="center">
		<font face="Arial" size="3" color="#000000">
		<b>These are the found settings on your server and the last saved Settings.</b>
		</font>
		</td>
	</tr>
	<tr>
		<td colspan="3" bgcolor= "$header" width="100%" align="left">
		<font face="Arial" size="2" color="#000000">
		<b>CGI-BIN Settings</b>
		</font>
		</td>
		<td width="35%" rowspan="2" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Last Saved Settings by: <b>$lastsaved</b><br />Save on Date/Time: <b>$mylastdate</b></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">&nbsp;</font></td>
		<td width="35%" bgcolor= "$catbg" align="center"><font face="Arial" size="2" color="#000000"><b>Detected Values</b></font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><font face="Arial" size="2" color="#000000"><b>Transfer</b></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Board URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_boardurl</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.boardurl.value = '$fnd_boardurl';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="boardurl" value="$boardurl" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Main Script Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_boarddir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.boarddir.value = '$fnd_boarddir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="boarddir" value="$boarddir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Boards Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_boardsdir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.boardsdir.value = '$fnd_boardsdir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="boardsdir" value="$boardsdir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Message Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_datadir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.datadir.value = '$fnd_datadir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="datadir" value="$datadir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Member Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_memberdir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.memberdir.value = '$fnd_memberdir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="memberdir" value="$memberdir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Sources Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_sourcedir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.sourcedir.value = '$fnd_sourcedir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="sourcedir" value="$sourcedir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Admin Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_admindir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.admindir.value = '$fnd_admindir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="admindir" value="$admindir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Variables Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_vardir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.vardir.value = '$fnd_vardir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="vardir" value="$vardir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Languages Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_langdir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.langdir.value = '$fnd_langdir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="langdir" value="$langdir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Template Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_templatesdir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.templatesdir.value = '$fnd_templatesdir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="templatesdir" value="$templatesdir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Help Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_helpfile</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.helpfile.value = '$fnd_helpfile';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="helpfile" value="$helpfile" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Attachment Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_uploaddir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.uploaddir.value = '$fnd_uploaddir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="uploaddir" value="$uploaddir" /></font></td>
	</tr>
	<tr>
		<td colspan="4" bgcolor= "$header" width="100%" align="left">
		<font face="Arial" size="2" color="#000000">
		<b>HTML Settings</b>
		</font>
		</td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">HTML Root Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_htmldir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.htmldir.value = '$fnd_htmldir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="htmldir" value="$htmldir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Forum Style Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_forumstylesdir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.forumstylesdir.value = '$fnd_forumstylesdir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="forumstylesdir" value="$forumstylesdir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Admin Style Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_adminstylesdir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.adminstylesdir.value = '$fnd_adminstylesdir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="adminstylesdir" value="$adminstylesdir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">HTML Root URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_html_root</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.html_root.value = '$fnd_html_root';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="html_root" value="$html_root" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Forum Style URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_forumstylesurl</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.forumstylesurl.value = '$fnd_forumstylesurl';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="forumstylesurl" value="$forumstylesurl" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Admin Style URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_adminstylesurl</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.adminstylesurl.value = '$fnd_adminstylesurl';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="adminstylesurl" value="$adminstylesurl" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Attachment URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_uploadurl</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.uploadurl.value = '$fnd_uploadurl';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="uploadurl" value="$uploadurl" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">UBBC URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_ubbcjspath</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.ubbcjspath.value = '$fnd_ubbcjspath';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="ubbcjspath" value="$ubbcjspath" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Newsfader URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_faderpath</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.faderpath.value = '$fnd_faderpath';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="faderpath" value="$faderpath" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">YaBBC.js URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_yabbcjspath</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.yabbcjspath.value = '$fnd_yabbcjspath';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="yabbcjspath" value="$yabbcjspath" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Post.js URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_postjspath</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.postjspath.value = '$fnd_postjspath';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="postjspath" value="$postjspath" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Avatar Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_facesdir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.facesdir.value = '$fnd_facesdir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="facesdir" value="$facesdir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Avatar URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_facesurl</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.facesurl.value = '$fnd_facesurl';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="facesurl" value="$facesurl" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Smilies Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_smiliesdir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.smiliesdir.value = '$fnd_smiliesdir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="smiliesdir" value="$smiliesdir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Smilies URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_smiliesurl</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.smiliesurl.value = '$fnd_smiliesurl';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="smiliesurl" value="$smiliesurl" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Mod Images Directory:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_modimgdir</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.modimgdir.value = '$fnd_modimgdir';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="modimgdir" value="$modimgdir" /></font></td>
	</tr>
	<tr>
		<td width="20%" bgcolor= "$catbg" align="left"><font face="Arial" size="2" color="#000000">Mod Images URL:</font></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000">$fnd_modimgurl</font></td>
		<td width="1%" bgcolor= "$catbg" align="center"><input type="button" OnClick="javascript: document.auto_settings.modimgurl.value = '$fnd_modimgurl';return false;" value="->" /></td>
		<td width="35%" bgcolor= "$windowbg" align="left"><font face="Arial" size="2" color="#000000"><input type="text" size="40" name ="modimgurl" value="$modimgurl" /></font></td>
	</tr>
	<tr>
		<td colspan="4" bgcolor= "$header" width="100%" align="center">
		<font face="Arial" size="2" color="#000000">
		<input type="submit" value="Save Settings" />
		</font>
		</td>
	</tr>
	</table>
	</td></tr></table></center></form>
	~;
	$yytitle = "Results of Auto Sensing";
	&Output2;
	exit;
}

sub save_settings {

  if(-e "$vardir/Setup.lock") {
      &FoundLock2;
  }


&LoadCookie;		# Load the user's cookie (or set to guest)
&LoadUserSettings;	# Load user settings
if (!$iamadmin){ $yymain="Setup Error: You have no access rights to this function, only user admin has if logged in !"; &Output2; }

	$lastsaved = $FORM{'lastsaved'};
	$lastdate = $FORM{'lastdate'};
	$boardurl = $FORM{'boardurl'};
	$boarddir = $FORM{'boarddir'};
	$htmldir = $FORM{'htmldir'};
	$uploaddir = $FORM{'uploaddir'};
	$uploadurl = $FORM{'uploadurl'};
	$html_root = $FORM{'html_root'};
	$datadir = $FORM{'datadir'};
	$boardsdir = $FORM{'boardsdir'};
	$memberdir = $FORM{'memberdir'};
	$sourcedir = $FORM{'sourcedir'};
	$admindir = $FORM{'admindir'};
	$vardir = $FORM{'vardir'};
	$langdir = $FORM{'langdir'};
	$helpfile = $FORM{'helpfile'};
	$templatesdir = $FORM{'templatesdir'};
	$forumstylesdir = $FORM{'forumstylesdir'};
	$forumstylesurl = $FORM{'forumstylesurl'};
	$adminstylesdir = $FORM{'adminstylesdir'};
	$adminstylesurl = $FORM{'adminstylesurl'};
	$facesdir = $FORM{'facesdir'};
	$facesurl = $FORM{'facesurl'};
	$smiliesdir = $FORM{'smiliesdir'};
	$smiliesurl = $FORM{'smiliesurl'};
	$modimgdir = $FORM{'modimgdir'};
	$modimgurl = $FORM{'modimgurl'};
	$ubbcjspath = $FORM{'ubbcjspath'};
	$faderpath = $FORM{'faderpath'};
	$yabbcjspath = $FORM{'yabbcjspath'};
	$postjspath = $FORM{'postjspath'};

	my $filler = q~                                                                               ~;
	my $setfile = << "EOF";
###############################################################################
# Paths.pl                                                                    #
###############################################################################
# YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               #
# Version:        YaBB 1 - SP 2 Beta                                          #
# Released:       July 21, 2003                                               #
# Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== #
# Copyright (c) 2000-2003 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by: The YaBB Development Team                                      #
#              with assistance from the YaBB community.                       #
# Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com            #
###############################################################################

\$lastsaved = "$lastsaved";
\$lastdate = "$lastdate";

########## Directories ##########

\$boardurl = "$boardurl";                              		# URL of your board's folder (without trailing '/')
\$boarddir = "$boarddir";                                       # The server path to the board's folder (usually can be left as '.')
\$boardsdir = "$boardsdir";                                     # Directory with board data files
\$datadir = "$datadir";                                         # Directory with messages
\$memberdir = "$memberdir";                                     # Directory with member files
\$sourcedir = "$sourcedir";                                     # Directory with YaBB source files
\$admindir = "$admindir";                                       # Directory with YaBB admin source files
\$vardir = "$vardir";                                           # Directory with variable files
\$langdir = "$langdir";                                         # Directory with Language files and folders
\$helpfile = "$helpfile";									# Directory with Help files and folders
\$templatesdir = "$templatesdir";                               # Directory with template files and folders
\$forumstylesdir = "$forumstylesdir";                               # Directory with forum style files and folders
\$adminstylesdir = "$adminstylesdir";                               # Directory with admin style files and folders
\$htmldir = "$htmldir";                              		# Base Path for all html/css files and folders
\$facesdir = "$facesdir";                              		# Base Path for all avatar files
\$smiliesdir = "$smiliesdir";                              	# Base Path for all smilie files
\$modimgdir = "$modimgdir";                              	# Base Path for all mod images
\$uploaddir = "$uploaddir";                              	# Base Path for all attachment files

########## URL's ##########

\$forumstylesurl = "$forumstylesurl";			  	# Default Forum Style Directory
\$adminstylesurl = "$adminstylesurl";			  	# Default Admin Style Directory
\$ubbcjspath = "$ubbcjspath";			  		# Default Location for the ubbc.js file
\$faderpath = "$faderpath";			  		# Default Location for the fader.js file
\$yabbcjspath = "$yabbcjspath";			 	# Default Location for the yabbc.js file
\$postjspath = "$postjspath";			  		# Default Location for the post.js file
\$html_root = "$html_root";                            		# Base URL for all html/css files and folders
\$facesurl = "$facesurl";                              		# Base URL for all avatar files
\$smiliesurl = "$smiliesurl";                            	# Base URL for all smilie files
\$modimgurl = "$modimgurl";                            	# Base URL for all mod images
\$uploadurl = "$uploadurl";        	                    	# Base URL for all attachment files

1;
EOF

	$setfile =~ s~(.+\;)\s+(\#.+$)~$1 . substr( $filler, 0, (70-(length $1)) ) . $2 ~gem;
	$setfile =~ s~(.{64,}\;)\s+(\#.+$)~$1 . "\n   " . $2~gem;
	$setfile =~ s~^\s\s\s+(\#.+$)~substr( $filler, 0, 70 ) . $1~gem;

	fopen(FILE, ">$boarddir/Paths.pl");
	print FILE $setfile;
	fclose(FILE);

	$yySetLocation = qq~Setup.pl?action=ready~;
	&redirectexit;
}

sub test_who {
  if(-e "$vardir/Setup.lock") {
      &FoundLock2;
  }


	if($os =~ /nix/ig){
		&testConfigUnix;
	} else {
		&testConfigWin;
	}
}

sub testConfigWin {

  if(-e "$vardir/Setup.lock") {
      &FoundLock2;
  }


	require "Paths.pl";
	# test read from $smiliesdir, $facesdir, $modimgdir, $htmldir, $templatesdir, $langdir, $vardir, $admindir, $sourcedir, $memberdir
	# $datadir, $boardsdir
	$smiliesdir_status = "Good";
	opendir DH, $smiliesdir or $smiliesdir_status = "Cannot open $smiliesdir: $!";
	closedir DH;

	$yymain .= qq~~;
	$yytitle = "Results of Win32 permission test";
	&Output2;

}

sub ready {

  if(-e "$vardir/Setup.lock") {
      &FoundLock2;
  }
&LoadCookie;		# Load the user's cookie (or set to guest)
&LoadUserSettings;	# Load user settings
if (!$iamadmin){ $yymain="Setup Error: You have no access rights to this function, only user admin has if logged in !"; &Output2; }
if(-e "YaBB.pl"){$start = "YaBB.pl";} else {$start = "YaBB.cgi";}

	$yymain .= qq~
	<br /><br /><br /><form action="$start?action=login" method="post"><center>
	<table width="50%" border="0" bgcolor= "#000000" cellspacing="1" cellpadding="0">
	<tr><td>
	<table width="100%" border="0" bgcolor= "$windowbg" cellspacing="1" cellpadding="3">
	<tr>
		<td width="100%" align="center">
		<font face="Arial" size="2" color="#000000">
		You have succesfully completed the Setup $realname!<br />Click Log In to enter your board.
		</font>
		</td>
	</tr>
	<tr>
		<td width="100%" align="center">
		<font face="Arial" size="2" color="#000000">
		<input type="submit" value="Log In" />
		</font>
		</td>
	</tr>
	</table>
	</td></tr></table></center></form>
	~;
	&CreateLock2;
	&Output2;
	exit;
}

sub BrdInstall {

my $boarddir = "./Boards";
$no_brddir = 0;

if (!-d "$boarddir") {$no_brddir = "1"; return 1; }

}

sub MesInstall {

my $messagedir = "./Messages";
$no_mesdir = 0;

if (!-d "$messagedir") {$no_mesdir = "1"; return 1; }

}

sub MemInstall {

my $memberdir = "./Members";
$no_memdir = 0;

if (!-d "$memberdir") {$no_memdir = "1"; return 1; }

}

sub SetInstall {

	my $boarddir = ".";

	my $filler = q~                                                                               ~;
	my $setfile = << "EOF";
###############################################################################
# Settings.pl                                                                 #
###############################################################################
# YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2 RC 1                                                 #
# Released:       December 27, 2004                                           #
# Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== #
# Copyright (c) 2000-2005 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by: The YaBB Development Team                                      #
#              with assistance from the YaBB community.                       #
# Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com            #
#               Your source for web hosting, web design, and domains.         #
###############################################################################

########## Board Info ##########
# Note: these settings must be properly changed for YaBB to work

\$maintenance = 0;				# Set to 1 to enable Maintenance mode
\$guestaccess = 1;				# Set to 0 to disallow guests from doing anything but login or register

\$mbname = q^YaBB 2 RC 1^;					# The name of your YaBB forum
\$forumstart = "01/01/05 at 01:01:01";				# The start date of your YaBB Forum
\$Cookie_Length = 1;			# Default minutes to set login cookies to stay for
\$cookieusername = "YaBB2username";			# Name of the username cookie
\$cookiepassword = "YaBB2password";			# Name of the password cookie

\$RegAgree = 1;					# Set to 1 to display the registration agreement when registering
\$preregister = 0;				# Set to 1 to use pre-registration and account activation
\$preregspan = 24;				# Time span in hours for users to account activation before cleanup.
\$emailpassword = 0;			# 0 - instant registration. 1 - password emailed to new members
\$emailnewpass = 0;				# Set to 1 to email a new password to members if they change their email address
\$emailwelcome = 0;				# Set to 1 to email a welcome message to users even when you have mail password turned off

\$lang = "English";					# Default Forum Language
\$template = "default";				# Default Forum Template

\$mailprog = "/usr/sbin/sendmail";				# Location of your sendmail program
\$smtp_server = "127.0.0.1";				# Address of your SMTP-Server
\$smtp_auth_required = 1;		# Set to 1 if the SMTP server requires Authorisation
\$authuser = q^admin^;				# Username for SMTP authorisation
\$authpass = q^admin^;				# Password for SMTP authorisation
\$webmaster_email = q^webmaster\@your_adress.yabb^;		# Your email address. (eg: \$webmaster_email = q^admin\@host.com^;)
\$mailtype = 0;					# Mail program to use: 0 = sendmail, 1 = SMTP, 2 = Net::SMTP

########## Layout ##########

\$maintenancetext = "We are currently upgrading our forum again. Please check back shortly!";			# User-defined text for Maintenance mode (leave blank for default text)
\$MenuType = 0;					# 1 for text menu or anything else for images menu
\$profilebutton = 0;			# 1 to show view profile button under post, or 0 for blank
\$allow_hide_email = 1;			# Allow users to hide their email from public. Set 0 to disable
\$showlatestmember = 1;			# Set to 1 to display "Welcome Newest Member" on the Board Index
\$shownewsfader = 0;			# 1 to allow or 0 to disallow NewsFader javascript on the Board Index
							# If 0, you'll have no news at all unless you put <yabb news> tag
							# back into template.html!!!
\$Show_RecentBar = 1;			# Set to 1 to display the Recent Post on Board Index
\$showmodify = 1;				# Set to 1 to display "Last modified: Realname - Date" under each message
\$ShowBDescrip = 1;				# Set to 1 to display board descriptions on the topic (message) index for each board
\$showuserpic = 1;				# Set to 1 to display each member's picture in the message view (by the ICQ.. etc.)
\$showusertext = 1;				# Set to 1 to display each member's personal text in the message view (by the ICQ.. etc.)
\$showgenderimage = 1;			# Set to 1 to display each member's gender in the message view (by the ICQ.. etc.)
\$showyabbcbutt = 1;                       # Set to 1 to display the yabbc buttons on Posting and IM Send Pages
\$nestedquotes = 1;                       # Set to 1 to allow quotes within quotes (0 will filter out quotes within a quoted message)
\$parseflash = 0;				# Set to 1 to parse the flash tag
\$enableclicklog = 0;                     # Set to 1 to track stats in Clicklog (this may slow your board down)


########## Feature Settings ##########

\$enable_ubbc = 1;				# Set to 1 if you want to enable UBBC (Uniform Bulletin Board Code)
\$enable_news = 1;				# Set to 1 to turn news on, or 0 to set news off
\$allowpics = 1;				# set to 1 to allow members to choose avatars in their profile
\$enable_guestposting = 0;		# Set to 0 if do not allow 1 is allow.
\$enable_notification = 1;		# Allow e-mail notification
\$autolinkurls = 1;				# Set to 1 to turn URLs into links, or 0 for no auto-linking.

\$timeselected = 4;				# Select your preferred output Format of Time and Date
\$timecorrection = 0;			# Set time correction for server time in seconds
\$timeoffset = 0;				# Time Offset to GMT/UTC (0 for GMT/UTC)
\$dstoffset = 0;				# Time Offset (for daylight savings time, 0 to disable DST)
\$TopAmmount = 15;				# No. of top posters to display on the top members list
\$maxdisplay = 20;				# Maximum of topics to display
\$maxfavs = 20;					# Maximum of favorite topics to save in a profile
\$maxrecentdisplay = 25;			# Maximum of topics to display on recent posts by a user (-1 to disable)
\$maxsearchdisplay = 15;			# Maximum of messages to display in a search query  (-1 to disable search)
\$maxmessagedisplay = 15;		# Maximum of messages to display
\$MaxMessLen = 5500;  				# Maximum Allowed Characters in a Posts
\$fontsizemin = 6;  				# Minimum Allowed Font height in pixels
\$fontsizemax = 32;  				# Maximum Allowed Font height in pixels
\$MaxSigLen = 200;				# Maximum Allowed Characters in Signatures
\$ClickLogTime = 100;				# Time in minutes to log every click to your forum (longer time means larger log file size)
\$max_log_days_old = 30;			# If an entry in the user's log is older than ... days remove it
							# Set to 0 if you want it disabled
\$fadertime = 1000;				# Length in milliseconds to delay between each item in the news fader
\$color{'fadertext'}  = "#000000";		# Color of text in the NewsFader (news color)
\$color{'faderbg'}  = "#ffffff";		# Color of background in the NewsFader (news color)
\$defaultusertxt = qq~I Love YaBB 2!~;			# The dafault usertext visible in users posts
\$timeout = 5;					# Minimum time between 2 postings from the same IP
\$HotTopic = 10;					# Number of posts needed in a topic for it to be classed as "Hot"
\$VeryHotTopic = 25;				# Number of posts needed in a topic for it to be classed as "Very Hot"

\$barmaxdepend = 0;				# Set to 1 to let bar-max-length depend on top poster or 0 to depend on a number of your choise
\$barmaxnumb = 500;				# Select number of post for max. bar-length in memberlist
\$defaultml = "regdate";


########## MemberPic Settings ##########

\$userpic_width = 65;			# Set pixel size to which the selfselected userpics are resized, 0 disables this limit
\$userpic_height = 0;			# Set pixel size to which the selfselected userpics are resized, 0 disables this limit
\$userpic_limits = qq~Please note that your image must be <b>gif</b> or <b>jpg</b> and that it will be resized.~;			# Text To Describe The Limits


########## File Locking ##########

\$gzcomp = 0;					# GZip compression: 0 = No Compression, 1 = External gzip, 2 = Zlib::Compress
\$gzforce = 0;					# Don't try to check whether browser supports GZip
\$use_flock = 1;				# Set to 0 if your server doesn't support file locking,
							# 1 for Unix/Linux and WinNT, and 2 for Windows 95/98/ME

\$faketruncation = 0;			# Enable this option only if YaBB fails with the error:
							# "truncate() function not supported on this platform."
							# 0 to disable, 1 to enable.

\$debug = 0;					# If set to 1 debug info is added to the template
							# tags are <yabb fileactions> and <yabb filenames>
1;
EOF

	$setfile =~ s~(.+\;)\s+(\#.+$)~$1 . substr( $filler, 0, (70-(length $1)) ) . $2 ~gem;
	$setfile =~ s~(.{64,}\;)\s+(\#.+$)~$1 . "\n   " . $2~gem;
	$setfile =~ s~^\s\s\s+(\#.+$)~substr( $filler, 0, 70 ) . $1~gem;

	open(SETTING, ">$boarddir/Settings.pl");
	print SETTING $setfile;
	close(SETTING);
}


sub VarInstall {

my $varsdir = "./Variables";
$no_vardir = 0;

if (!-d "$varsdir") {$no_vardir = "1"; return 1; }

if (!-e "$varsdir/adminlog.txt") {
	open(ADMLOGFILE, ">$varsdir/adminlog.txt");
	print ADMLOGFILE "";
	close(ADMLOGFILE);
}

if (!-e "$varsdir/advsettings.txt") {
	my $filler = q~                                                                               ~;
	my $setfile = << "EOF";
###############################################################################
# advsettings.txt                                                             #
###############################################################################
# YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2 RC 1                                                 #
# Released:       December 27, 2004                                           #
# Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== #
# Copyright (c) 2000-2005 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by: The YaBB Development Team                                      #
#              with assistance from the YaBB community.                       #
# Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com            #
#               Your source for web hosting, web design, and domains.         #
###############################################################################


########## In-Thread Multi Delete ##########

\$mdadmin = 1;
\$mdglobal = 1;
\$mdmod = 1;
\$adminbin = 0;                                                        # Skip recycle bin step for admins and delete directly

########## Moderation Update ##########

\$adminview = 2;                                                       # Multi-admin settings for Administrators: 0=none, 1=icons 2=single checkbox 3=multiple checkboxes
\$gmodview = 2;                                                        # Multi-admin settings for Global Moderators: 0=none, 1=icons 2=single checkbox 3=multiple checkboxes
\$modview = 2;                                                         # Multi-admin settings for Moderators: 0=none, 1=icons 2=single checkbox 3=multiple checkboxes

########## Advanced Memberview Plus ###########

\$showallgroups = 1;
\$OnlineLogTime = 15;                                                  ########## YaBB Security Center ###########

\$regcheck = 1;                                                        # Set to 1 if you want to enable automatic flood protection enabled
\$codemaxchars = 5;                                                    # Set max length of validation code (15 is max)
\$translayer = 0;                                                      # Set to 1 background for validation image should be transparent
\$stealthurl = 0;                                                      # Set to 1 to mask referer url to hosts if a hyperlink is clicked.
\$referersecurity = 0;                                                 # Set to 1 to activate referer security checking.
\$sessions = 1;                                                        # Set to 1 to activate session id protection.
\$show_online_ip_admin = 1;                                            # Set to 1 to show online IP's to admins.
\$show_online_ip_gmod = 1;                                             # Set to 1 to show online IP's to global moderators.

######### Polls ###########

\$numpolloptions = 8;                                                  # Number of poll options
\$maxpq = 60;                                                          # Maximum Allowed Characters in a Poll Qestion?
\$maxpo = 50;                                                          # Maximum Allowed Characters in a Poll Option?
\$maxpc = 0;                                                           # Maximum Allowed Characters in a Poll Comment?
\$useraddpoll = 1;                                                     # Allow users to add polls to existing threads? (1 = yes)
\$ubbcpolls = 1;                                                       # Allow UBBC tags and smilies in polls? (1 = yes)

########## Advanced Instant Message Box ############

\$numposts = 1;                                                        # Number of posts required to send Instant Messages
\$imspam = off;                                                        # Percent of Users a user is a allowed to send a message at once
\$numibox = 20;                                                        # Number of maximum Messages in the IM-Inbox
\$numobox = 20;                                                        # Number of maximum Messages in the IM-Outbox
\$numstore = 20;                                                       # Number of maximum Messages in the Storage box
\$enable_imlimit = 0;                                                  # Set to 1 to enable limitation of incoming and outgoing im messages
\$imtext = qq~Welcome to my boards~;
\$sendname = admin;
\$imsubject = "Hey Hey :)";
\$send_welcomeim = 1;                                                  ######### Topic Summary Cutter #############

\$cutamount  = "15";                                                   # Number of posts to list in topic summary
\$tsreverse = 1;                                                       # Reverse Topic Summaries (So most recent is first

############## Time Lock ###################

\$tlnomodflag = 1;                                                     # Set to 1 limit time users may modify posts
\$tlnomodtime = 1;                                                     # Time limit on modifying posts (days)
\$tlnodelflag = 1;                                                     # Set to 1 limit time users may delete posts
\$tlnodeltime = 5;                                                     # Time limit on deleting posts (days)
\$tllastmodflag = 1;                                                   # Set to 1 allow users to modify posts up to the specified time limit w/o showing "last Edit" message
\$tllastmodtime = 60;                                                  # Time limit to modify posts w/o triggering "last Edit" message (in minutes)

########## File Attachment Settings ##########

\$limit = 250;                                                         # Set to the maximum number of kilobytes an attachment can be. Set to 0 to disable the file size check.
\$dirlimit = 10000;                                                    # Set to the maximum number of kilobytes the attachment directory can hold. Set to 0 to disable the directory size check.
\$overwrite = 0;                                                       # Set to 0 to auto rename attachments if they exist, 1 to overwrite them or 2 to generate an error if the file exists already.
\@ext = qw(jpg jpeg gif png swf zip);                                  # The allowed file extensions for file attachements. Variable should be set in the form of "jpg bmp gif" and so on.
\$checkext = 1;                                                        # Set to 1 to enable file extension checking, set to 0 to allow all file types to be uploaded
\$amdisplaypics = 1;                                                   # Set to 1 to display attached pictures in posts, set to 0 to only show a link to them.
\$allowattach = 1;                                                     # Set to 1 to allow file attaching, set to 0 to disable file attaching.
\$allowguestattach = 0;                                                # Set to 1 to allow guests to upload attachments, 0 to disable guest attachment uploading.

############# Error Logger #################

\$elmax  = "50";                                                       # Max number of log entries before rotation
\$elenable = 1;                                                        # allow for error logging
\$elrotate = 1;                                                        # Allow for log rotation

1;
EOF

	$setfile =~ s~(.+\;)\s+(\#.+$)~$1 . substr( $filler, 0, (70-(length $1)) ) . $2 ~gem;
	$setfile =~ s~(.{64,}\;)\s+(\#.+$)~$1 . "\n   " . $2~gem;
	$setfile =~ s~^\s\s\s+(\#.+$)~substr( $filler, 0, 70 ) . $1~gem;

	open(SETTING, ">$varsdir/advsettings.txt");
	print SETTING $setfile;
	close(SETTING);
}

if (!-e "$varsdir/allowed.txt") {
	open(ALLOWFILE, ">$varsdir/allowed.txt");
	print ALLOWFILE "login\n";
	print ALLOWFILE "logout\n";
	print ALLOWFILE "display\n";
	print ALLOWFILE "messageindex\n";
	print ALLOWFILE "pages\n";
	print ALLOWFILE "profile\n";
	print ALLOWFILE "register\n";
	print ALLOWFILE "resetpass\n";
	print ALLOWFILE "viewprofile";
	close(ALLOWFILE);
}

if (!-e "$varsdir/attachments.txt") {
	open(ATTFILE, ">$varsdir/attachments.txt");
	print ATTFILE "";
	close(ATTFILE);
}

if (!-e "$varsdir/ban.txt") {
	open(BANFILE, ">$varsdir/ban.txt");
	print BANFILE "";
	close(BANFILE);
}

if (!-e "$varsdir/ban_email.txt") {
	open(BANFILE, ">$varsdir/ban_email.txt");
	print BANFILE "";
	close(BANFILE);
}

if (!-e "$varsdir/ban_log.txt") {
	open(BANFILE, ">$varsdir/ban_log.txt");
	print BANFILE "";
	close(BANFILE);
}

if (!-e "$varsdir/ban_memname.txt") {
	open(BANFILE, ">$varsdir/ban_memname.txt");
	print BANFILE "";
	close(BANFILE);
}

if (!-e "$varsdir/cat.txt") {
	open(CATFILE, ">$varsdir/cat.txt");
	print CATFILE "";
	close(CATFILE);
}

if (!-e "$varsdir/clicklog.txt") {
	open(CLICKFILE, ">$varsdir/clicklog.txt");
	print CLICKFILE "";
	close(CLICKFILE);
}

if (!-e "$varsdir/errorlog.txt") {
	open(ERRORFILE, ">$varsdir/errorlog.txt");
	print ERRORFILE "";
	close(ERRORFILE);
}

if (!-e "$varsdir/flood.txt") {
	open(FLOODFILE, ">$varsdir/flood.txt");
	print FLOODFILE "127.0.0.1|1105634410";
	close(FLOODFILE);
}

if (!-e "$varsdir/gmodsettings.txt") {
	my $filler = q~                                                                               ~;
	my $setfile = << "EOF";
### Gmod Releated Setttings ###

\$allow_gmod_admin = "on"; #

### Areas Gmods can Access ### 

\%gmod_access = (
'modsettings',"",
'flood_control',"",
'advsettings',"on",
'smilies',"on",
'helpadmin',"on",
'gmodaccess',"",
'setcensor',"on",
'detailedversion',"on",
'managecats',"",
'manageboards',"",
'editnews',"on",
'modagreement',"on",
'modtemp',"",
'modcss',"",
'referer_control',"",
'viewmembers',"on",
'modmemgr',"",
'mailing',"on",
'ipban',"on",
'setreserve',"on",
'clean_log',"on",
'boardrecount',"",
'membershiprecount',"",
'rebuildmemlist',"",
'deleteoldthreads',"",
'manageattachments',"on",
'stats',"on",
'showclicks',"on",
'errorlog',"on",
'view_reglog',"on",
);

\%gmod_access2 = (
admin => "on",
deleteattachment => "on",
manageattachments2 => "on",
removeoldattachments => "on",
removebigattachments => "on",

delgroup => "",
editgroup => "",
editAddGroup2 => "",
modmemgr2 => "",
assigned => "",
assigned2 => "",

reordercats => "",
modifycatorder => "",
modifycat => "",
createcat => "",
catscreen => "",
reordercats2 => "",
addcat => "",
addcat2 => "",

modifyboard => "",
addboard => "",
addboard2 => "",
reorderboards2 => "",

smilieput => "on",
smilieindex => "on",
smiliemove => "on",
addsmilies => "on",

addmember => "on",
addmember2 => "on",
deletemultimembers => "on",

del_regentry => "on",
clean_reglog => "on",

cleanerrorlog => "on",
deleteerror => "on",

do_clean_log => "on",
modagreement2 => "on",
modsettings2 => "",
advsettings2 => "on",
ml => "on",
referer_control2 => "",
removeoldthreads => "",
ipban2 => "on",
setcensor2 => "on",
setreserve2 => "on",
editnews2 => "on",

flood_control2,"",
);

1;
EOF

	$setfile =~ s~(.+\;)\s+(\#.+$)~$1 . substr( $filler, 0, (70-(length $1)) ) . $2 ~gem;
	$setfile =~ s~(.{64,}\;)\s+(\#.+$)~$1 . "\n   " . $2~gem;
	$setfile =~ s~^\s\s\s+(\#.+$)~substr( $filler, 0, 70 ) . $1~gem;

	open(SETTING, ">$varsdir/gmodsettings.txt");
	print SETTING $setfile;
	close(SETTING);

}

if (!-e "$varsdir/Guardian.banned") {
	my $filler = q~                                                                               ~;
	my $setfile = << "EOF";
\$banned_harvesters = qq~alexibot|asterias|backdoorbot|black.hole|blackwidow|blowfish|botalot|builtbottough|bullseye|bunnyslippers|cegbfeieh|cheesebot|cherrypicker|chinaclaw|copyrightcheck|cosmos |crescent|custo|disco|dittospyder|download demon|ecatch|eirgrabber|emailcollector|emailsiphon|emailwolf|erocrawler|eseek-larbin|express webpictures|extractorpro|eyenetie|fast|flashget|foobot|frontpage|fscrawler|getright|getweb|go!zilla|go-ahead-got-it|grabnet|grafula|gsa-crawler|harvest|hloader|hmview|httplib|httrack|humanlinks|ia_archiver|image stripper|image sucker|indy library|infonavirobot|interget|internet ninja|jennybot|jetcar|joc web spider|kenjin.spider|keyword.density|larbin|leechftp|lexibot|libweb/clshttp|linkextractorpro|linkscan/8.1a.unix|linkwalker|lwp-trivial|mass downloader|mata.hari|microsoft.url|midown tool|miixpc|mister pix|moget|mozilla.*newt|mozilla/3.mozilla/2.01|navroad|nearsite|net vampire|netants|netmechanic|netspider|netzip|nicerspro|npbot|octopus|offline explorer|offline navigator|openfind|pagegrabber|papa foto|pavuk|pcbrowser|propowerbot/2.14|prowebwalker|queryn.metasearch|realdownload|reget|repomonkey|sitesnagger|slysearch|smartdownload|spankbot|spanner |spiderzilla|steeler|superbot|superhttp|surfbot|suzuran|szukacz|takeout|teleport pro|telesoft|the.intraformant|thenomad|tighttwatbot|titan|tocrawl/urldispatcher|true_robot|turingos|turnitinbot|urly.warning|vci|voideye|web image collector|web sucker|web.image.collector|webauto|webbandit|webbandit|webcopier|webemailextrac.*|webenhancer|webfetch|webgo is|webleacher|webmasterworldforumbot|webreaper|websauger|website extractor|website quester|webster.pro|webstripper|webwhacker|webzip|wget|widow|www-collector-e|wwwoffle|xaldon webspider|xenu link sleuth|zeus~;
\$banned_referers = qq~hotsex.com|porn.com~;
\$banned_requests = qq~~;
\$banned_strings = qq~pussy|cunt~;

1;
EOF

	$setfile =~ s~(.+\;)\s+(\#.+$)~$1 . substr( $filler, 0, (70-(length $1)) ) . $2 ~gem;
	$setfile =~ s~(.{64,}\;)\s+(\#.+$)~$1 . "\n   " . $2~gem;
	$setfile =~ s~^\s\s\s+(\#.+$)~substr( $filler, 0, 70 ) . $1~gem;

	open(SETTING, ">$varsdir/Guardian.banned");
	print SETTING $setfile;
	close(SETTING);
}

if (!-e "$varsdir/Guardian.settings") {
	my $filler = q~                                                                               ~;
	my $setfile = << "EOF";
\$disallow_proxy_on = 1;
\$referer_on = 1;
\$harvester_on = 1;
\$request_on = 0;
\$string_on = 1;
\$union_on = 1;
\$clike_on = 1;
\$script_on = 1;

\$disallow_proxy_notify = 1;
\$referer_notify = 0;
\$harvester_notify = 1;
\$request_notify = 0; 
\$string_notify = 1;
\$union_notify = 1;
\$clike_notify = 1;
\$script_notify = 1;

1;
EOF

	$setfile =~ s~(.+\;)\s+(\#.+$)~$1 . substr( $filler, 0, (70-(length $1)) ) . $2 ~gem;
	$setfile =~ s~(.{64,}\;)\s+(\#.+$)~$1 . "\n   " . $2~gem;
	$setfile =~ s~^\s\s\s+(\#.+$)~substr( $filler, 0, 70 ) . $1~gem;

	open(SETTING, ">$varsdir/Guardian.settings");
	print SETTING $setfile;
	close(SETTING);
}

if (!-e "$varsdir/log.txt") {
	open(LOGFILE, ">$varsdir/log.txt");
	print LOGFILE "admin|1105634411|127.0.0.1";
	close(LOGFILE);
}

if (!-e "$varsdir/membergroups.txt") {
	my $filler = q~                                                                               ~;
	my $setfile = << "EOF";
\$Group{'Global Moderator'} = "Global Moderator|5|stargmod.gif|blue";
\$Group{'Administrator'} = "YaBB Administrator|5|staradmin.gif|red";
\$Group{'Moderator'} = "YaBB Moderator|5|starmod.gif|green";
\$Post{'500'} = "God Member|5|starsilver.gif|";
\$Post{'250'} = "Senior Member|4|stargold.gif|";
\$Post{'100'} = "Full Member|2|starblue.gif|";
\$Post{'50'} = "Junior Member|2|stargold.gif|";
\$Post{'-1'} = "YaBB Newbies|1|stargold.gif|";

1;
EOF

	$setfile =~ s~(.+\;)\s+(\#.+$)~$1 . substr( $filler, 0, (70-(length $1)) ) . $2 ~gem;
	$setfile =~ s~(.{64,}\;)\s+(\#.+$)~$1 . "\n   " . $2~gem;
	$setfile =~ s~^\s\s\s+(\#.+$)~substr( $filler, 0, 70 ) . $1~gem;

	open(SETTING, ">$varsdir/membergroups.txt");
	print SETTING $setfile;
	close(SETTING);
}

if (!-e "$varsdir/modlist.txt") {
	open(MODSFILE, ">$varsdir/modlist.txt");
	print MODSFILE "admin\n";
	close(MODSFILE);
}

if (!-e "$varsdir/news.txt") {
	open(NEWSFILE, ">$varsdir/news.txt");
	print NEWSFILE "Welcome to our forum\n";
	print NEWSFILE "We've Upgraded to YaBB 2 RC 1!!!!\n";
	print NEWSFILE "Visit <a href='http://www.yabbforum.com'>YaBB</a> today \;\)\n";
	print NEWSFILE "YaBB is sponsored by <a href='http://www.ximinc.com'>XIMinc</a>!\n";
	print NEWSFILE "Signup for free on our forum and benefit from new features!\n";
	print NEWSFILE "Latest info can be found on the <a href='http://www.yabbforum.com/community/'>YaBB Community</a>.\n";
	close(NEWSFILE);
}

if (!-e "$varsdir/oldestmes.txt") {
	open(OLDFILE, ">$varsdir/oldestmes.txt");
	print OLDFILE "1\n";
	close(OLDFILE);
}

if (!-e "$varsdir/registration.log") {
	open(REGLOG, ">$varsdir/registration.log");
	print REGLOG "";
	close(REGLOG);
}

if (!-e "$varsdir/reserve.txt") {
	open(RESERVEFILE, ">$varsdir/reserve.txt");
	print RESERVEFILE "yabb\n";
	print RESERVEFILE "YaBBadmin\n";
	print RESERVEFILE "administrator\n";
	print RESERVEFILE "admin\n";
	print RESERVEFILE "y2\n";
	print RESERVEFILE "xnull\n";
	print RESERVEFILE "yabb2\n";
	close(RESERVEFILE);
}

if (!-e "$varsdir/reservecfg.txt") {
	open(RESERVEFILE, ">$varsdir/reservecfg.txt");
	print RESERVEFILE "checked\n";
	print RESERVEFILE "\n";
	print RESERVEFILE "checked\n";
	print RESERVEFILE "checked\n";
	close(RESERVEFILE);
}

if (!-e "$varsdir/secsettings.txt") {
	my $filler = q~                                                                               ~;
	my $setfile = << "EOF";
###############################################################################
# SecSettings.txt                                                             #
###############################################################################

\$regcheck = 0;                                                        # Set to 1 if you want to enable automatic flood protection enabled
\$codemaxchars = 6;                                                    # Set max length of validation code (15 is max)
\$translayer = 0;                                                      # Set to 1 background for validation image should be transparent
\$stealthurl = 0;                                                      # Set to 1 to mask referer url to hosts if a hyperlink is clicked.
\$referersecurity = 0;                                                 # Set to 1 to activate referer security checking.
\$sessions = 1;                                                        # Set to 1 to activate session id protection.
\$show_online_ip_admin = 1;                                            # Set to 1 to show online IP's to admins.
\$show_online_ip_gmod = 1;                                             # Set to 1 to show online IP's to global moderators.


1;
EOF

	$setfile =~ s~(.+\;)\s+(\#.+$)~$1 . substr( $filler, 0, (70-(length $1)) ) . $2 ~gem;
	$setfile =~ s~(.{64,}\;)\s+(\#.+$)~$1 . "\n   " . $2~gem;
	$setfile =~ s~^\s\s\s+(\#.+$)~substr( $filler, 0, 70 ) . $1~gem;

	open(SETTING, ">$varsdir/secsettings.txt");
	print SETTING $setfile;
	close(SETTING);
}

if (!-e "$varsdir/Smilies.txt") {
	my $filler = q~                                                                               ~;
	my $setfile = << "EOF";
\$SmilieURL[0] = "exclamation.gif";
\$SmilieCode[0] = ":exclamation";
\$SmilieDescription[0] = "Exclaim";
\$SmilieLinebreak[0] = "";

\$SmilieURL[1] = "question.gif";
\$SmilieCode[1] = ":question";
\$SmilieDescription[1] = "Questioning";
\$SmilieLinebreak[1] = "";

\$smiliestyle = "1";
\$showadded = "2";
\$showsmdir = "2";
\$detachblock = "1";
\$winwidth = "400";
\$winheight = "400";
\$popback = "#FFFFFF";
\$poptext = "#000000";

1;
EOF

	$setfile =~ s~(.+\;)\s+(\#.+$)~$1 . substr( $filler, 0, (70-(length $1)) ) . $2 ~gem;
	$setfile =~ s~(.{64,}\;)\s+(\#.+$)~$1 . "\n   " . $2~gem;
	$setfile =~ s~^\s\s\s+(\#.+$)~substr( $filler, 0, 70 ) . $1~gem;

	open(SETTING, ">$varsdir/Smilies.txt");
	print SETTING $setfile;
	close(SETTING);
}


}

sub CheckInstall {

my $install_error;
$windowbg="#FAFAFA";
$header="#5488BA";
$catbg="#DDDDDD";

my $boarddir = ".";

$set_missing = "";
$set_created = "";
if (!-e "$boarddir/Settings.pl") { $set_missing .= qq~Settings.pl~; } else { $set_created .= qq~Settings.pl~; }

my $boardsdir = "./Boards";

$brd_missing = "";
$brd_created = "";
if (!-e "$boardsdir/forum.control") { $brd_missing .= qq~forum.control, ~; } else { $brd_created .= qq~forum.control, ~; }
if (!-e "$boardsdir/forum.master") { $brd_missing .= qq~forum.master, ~; } else { $brd_created .= qq~forum.master, ~; }
if (!-e "$boardsdir/forum.totals") { $brd_missing .= qq~forum.totals, ~; } else { $brd_created .= qq~forum.totals, ~; }
if (!-e "$boardsdir/generely2rc1.txt") { $brd_missing .= qq~generely2rc1.txt~; } else { $brd_created .= qq~generely2rc1.txt~; }
$brd_missing =~ s/\, \Z//;
$brd_created =~ s/\, \Z//;

my $memberdir = "./Members";

$mem_missing = "";
$mem_created = "";
if (!-e "$memberdir/admin.ims") { $mem_missing .= qq~admin.ims, ~; } else { $mem_created .= qq~admin.ims, ~; }
if (!-e "$memberdir/admin.imstore") { $mem_missing .= qq~admin.imstore, ~; } else { $mem_created .= qq~admin.imstore, ~; }
if (!-e "$memberdir/admin.log") { $mem_missing .= qq~admin.log, ~; } else { $mem_created .= qq~admin.log, ~; }
if (!-e "$memberdir/admin.outbox") { $mem_missing .= qq~admin.outbox, ~; } else { $mem_created .= qq~admin.outbox, ~; }
if (!-e "$memberdir/admin.vars") { $mem_missing .= qq~admin.vars, ~; } else { $mem_created .= qq~admin.vars, ~; }
if (!-e "$memberdir/admin.wlog") { $mem_missing .= qq~admin.wlog, ~; } else { $mem_created .= qq~admin.wlog, ~; }
if (!-e "$memberdir/memberlist.txt") { $mem_missing .= qq~memberlist.txt, ~; } else { $mem_created .= qq~memberlist.txt, ~; }
if (!-e "$memberdir/members.ttl") { $mem_missing .= qq~members.ttl~; } else { $mem_created .= qq~members.ttl~; }
$mem_missing =~ s/\, \Z//;
$mem_created =~ s/\, \Z//;

my $messagedir = "./Messages";

$msg_missing = "";
$msg_created = "";
if (!-e "$messagedir/1105634410.ctb") { $msg_missing .= qq~1105634410.ctb, ~; } else { $msg_created .= qq~1105634410.ctb, ~; }
if (!-e "$messagedir/1105634410.txt") { $msg_missing .= qq~1105634410.txt~; } else { $msg_created .= qq~1105634410.txt~; }
$msg_missing =~ s/\, \Z//;
$msg_created =~ s/\, \Z//;

my $varsdir = "./Variables";

$var_missing = "";
$var_created = "";
if (!-e "$varsdir/adminlog.txt") { $var_missing .= qq~adminlog.txt, ~; } else { $var_created .= qq~adminlog.txt, ~; }
if (!-e "$varsdir/advsettings.txt") { $var_missing .= qq~advsettings.txt, ~; } else { $var_created .= qq~advsettings.txt, ~; }
if (!-e "$varsdir/allowed.txt") { $var_missing .= qq~allowed.txt, ~; } else { $var_created .= qq~allowed.txt, ~; }
if (!-e "$varsdir/attachments.txt") { $var_missing .= qq~attachments.txt, ~; } else { $var_created .= qq~attachments.txt, ~; }
if (!-e "$varsdir/ban.txt") { $var_missing .= qq~ban.txt, ~; } else { $var_created .= qq~ban.txt, ~; }
if (!-e "$varsdir/ban_email.txt") { $var_missing .= qq~ban_email.txt, ~; } else { $var_created .= qq~ban_email.txt, ~; }
if (!-e "$varsdir/ban_log.txt") { $var_missing .= qq~ban_log.txt, ~; } else { $var_created .= qq~ban_log.txt, ~; }
if (!-e "$varsdir/ban_memname.txt") { $var_missing .= qq~ban_memname.txt, ~; } else { $var_created .= qq~ban_memname.txt, ~; }
if (!-e "$varsdir/cat.txt") { $var_missing .= qq~cat.txt, ~; } else { $var_created .= qq~cat.txt, ~; }
if (!-e "$varsdir/clicklog.txt") { $var_missing .= qq~clicklog.txt, ~; } else { $var_created .= qq~clicklog.txt, ~; }
if (!-e "$varsdir/errorlog.txt") { $var_missing .= qq~errorlog.txt, ~; } else { $var_created .= qq~errorlog.txt, ~; }
if (!-e "$varsdir/flood.txt") { $var_missing .= qq~flood.txt, ~; } else { $var_created .= qq~flood.txt, ~; }
if (!-e "$varsdir/gmodsettings.txt") { $var_missing .= qq~gmodsettings.txt, ~; } else { $var_created .= qq~gmodsettings.txt, ~; }
if (!-e "$varsdir/Guardian.banned") { $var_missing .= qq~Guardian.banned, ~; } else { $var_created .= qq~Guardian.banned, ~; }
if (!-e "$varsdir/Guardian.settings") { $var_missing .= qq~Guardian.settings, ~; } else { $var_created .= qq~Guardian.settings, ~; }
if (!-e "$varsdir/log.txt") { $var_missing .= qq~log.txt, ~; } else { $var_created .= qq~log.txt, ~; }
if (!-e "$varsdir/membergroups.txt") { $var_missing .= qq~membergroups.txt, ~; } else { $var_created .= qq~membergroups.txt, ~; }
if (!-e "$varsdir/modlist.txt") { $var_missing .= qq~modlist.txt, ~; } else { $var_created .= qq~modlist.txt, ~; }
if (!-e "$varsdir/news.txt") { $var_missing .= qq~news.txt, ~; } else { $var_created .= qq~news.txt, ~; }
if (!-e "$varsdir/oldestmes.txt") { $var_missing .= qq~oldestmes.txt, ~; } else { $var_created .= qq~oldestmes.txt, ~; }
if (!-e "$varsdir/registration.log") { $var_missing .= qq~registration.log, ~; } else { $var_created .= qq~registration.log, ~; }
if (!-e "$varsdir/reserve.txt") { $var_missing .= qq~reserve.txt, ~; } else { $var_created .= qq~reserve.txt, ~; }
if (!-e "$varsdir/reservecfg.txt") { $var_missing .= qq~reservecfg.txt, ~; } else { $var_created .= qq~reservecfg.txt, ~; }
if (!-e "$varsdir/secsettings.txt") { $var_missing .= qq~secsettings.txt, ~; } else { $var_created .= qq~secsettings.txt, ~; }
if (!-e "$varsdir/Smilies.txt") { $var_missing .= qq~Smilies.txt~; } else { $var_created .= qq~Smilies.txt~; }
$var_missing =~ s/\, \Z//;
$var_created =~ s/\, \Z//;

$yymain .= qq~
<table width="60%" border="0" bgcolor= "#000000" cellspacing="0" cellpadding="0" align="center">
	<tr><td>
	<table width="100%" border="0" cellspacing="1" cellpadding="3">
	<tr><td width="100%" colspan="2" bgcolor="$header" align="left">
	<div style="font-family: verdana; color: #ffffff; font-size: 12px; padding: 2px;"><b>Checking System Files</b></div>
	</td></tr>

	<tr><td width="20%" bgcolor="$windowbg" align="left">
~;
if($set_missing) {
$install_error = 1;
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #bb0000; font-size: 12px; padding: 2px;"><b>A Problem has occurred while creating Settings.pl!</b></div>
~;
}
if($set_created) {
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #000090; font-size: 12px; padding: 2px;"><b>Successfully checked Settings.pl!</b></div>
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>&nbsp;</b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">After finishing the setup procedure you should log in to your forum and go to your Admin Center - Forum Settings and set the options correctly.</div>
~;
}

$yymain .= qq~
	</td></tr>

	<tr><td width="20%" bgcolor="$windowbg" align="left">
~;
if($no_brddir) {
$install_error = 1;
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #bb0000; font-size: 12px; padding: 2px;"><b>A Problem has occurred in the /Boards folder!</b></div>
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>&nbsp;</b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">No /Boards folder available!</div>
~;
}
else {
if($brd_missing) {
$install_error = 1;
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #bb0000; font-size: 12px; padding: 2px;"><b>A Problem has occurred in the /Boards folder!</b></div>
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>Unable to find: </b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">$brd_missing</div>
~;
}
if($brd_created) {
	if(!$brd_missing) {
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #000090; font-size: 12px; padding: 2px;"><b>Successfully checked the /Boards folder!</b></div>
~;
}
$yymain .= qq~
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>Installed: </b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">$brd_created</div>
~;
}
}
$yymain .= qq~
	</td></tr>

	<tr><td width="20%" bgcolor="$windowbg" align="left">
~;

if($no_memdir) {
$install_error = 1;
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #bb0000; font-size: 12px; padding: 2px;"><b>A Problem has occurred in the /Members folder!</b></div>
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>&nbsp;</b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">No /Members folder available!</div>
~;
}
else {
if($mem_missing) {
$install_error = 1;
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #bb0000; font-size: 12px; padding: 2px;"><b>A Problem has occurred in the /Members folder!</b></div>
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>Unable to find: </b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">$mem_missing</div>
~;
}
if($mem_created) {
	if(!$mem_missing) {
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #000090; font-size: 12px; padding: 2px;"><b>Successfully checked the /Members folder!</b></div>
~;
}
$yymain .= qq~
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>Installed: </b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">$mem_created</div>
~;
}
}
$yymain .= qq~
	</td></tr>

	<tr><td width="20%" bgcolor="$windowbg" align="left">
~;

if($no_mesdir) {
$install_error = 1;
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #bb0000; font-size: 12px; padding: 2px;"><b>A Problem has occurred in the /Messages folder!</b></div>
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>&nbsp;</b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">No /Messages folder available!</div>
~;
}
else {
if($msg_missing) {
$install_error = 1;
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #bb0000; font-size: 12px; padding: 2px;"><b>A Problem has occurred in the /Messages folder!</b></div>
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>Unable to find: </b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">$msg_missing</div>
~;
}
if($msg_created) {
	if(!$msg_missing) {
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #000090; font-size: 12px; padding: 2px;"><b>Successfully checked the /Messages folder!</b></div>
~;
}
$yymain .= qq~
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>Installed: </b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">$msg_created</div>
~;
}
}
$yymain .= qq~
	</td></tr>

	<tr><td width="20%" bgcolor="$windowbg" align="left">
~;
if($no_vardir) {
$install_error = 1;
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #bb0000; font-size: 12px; padding: 2px;"><b>A Problem has occurred in the /Variables folder!</b></div>
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>&nbsp;</b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">No /Variables folder available!</div>
~;
}
else {
if($var_missing) {
$install_error = 1;
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #bb0000; font-size: 12px; padding: 2px;"><b>A Problem has occurred in the /Variables folder!</b></div>
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>Unable to install: </b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">$var_missing</div>
~;
}
if($var_created) {
	if(!$var_missing) {
$yymain .= qq~
	<div style="float: left; width: 98%; font-family: verdana; color: #000090; font-size: 12px; padding: 2px;"><b>Successfully checked the /Variables folder!</b></div>
~;
}
$yymain .= qq~
	<div style="float: left; width: 22%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;"><b>Installed: </b></div>
	<div style="float: left; width: 76%; font-family: verdana; color: #000000; font-size: 11px; padding: 2px;">$var_created</div>
~;
}
}
$yymain .= qq~
	</td></tr>
~;

if(!$install_error) {
$yymain .= qq~
	<tr><td width="100%" bgcolor="$catbg" align="center">
	<form action="Setup.pl?action=adminlogin" method="post" style="display: inline;">
		<input type="submit" value="Continue" />
	</form>
	</td></tr>
~;
}
else {
$yymain .= qq~
	<tr><td width="100%" bgcolor="$catbg" align="left">
	<div style="float: left; width: 98%; font-family: verdana; color: #900000; font-size: 11px; padding: 2px;"><b>One or more errors occurred while checking the system files. The problem/s must be solved before you continue.</b></div>
	</td></tr>
~;
}
$yymain .= qq~
	</table>
	</td></tr>
</table>
~;
&Output2;
exit;
}

1;
