#!/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.21 $';

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 "Settings.pl") { require "Settings.pl"; }

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=boards">Step 2</a>~;
$NavLink3 = qq~<a href="$boardurl/Setup.pl?action=members">Step 3</a>~;
$NavLink4 = qq~<a href="$boardurl/Setup.pl?action=messages">Step 4</a>~;
$NavLink5 = qq~<a href="$boardurl/Setup.pl?action=dates">Step 5</a>~;
$NavLink6 = qq~<a href="$boardurl/Setup.pl?action=cleanup">Step 6</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 2 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~Step 6~;
  &Output;
}

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

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

    &GetCats;
  $NavItem1 = "nav-item-highlight";
  $NavLink1 = qq~Step 1~;
  $NavLink3 = qq~Step 3~;
  $NavLink4 = qq~Step 4~;
  $NavLink5 = qq~Step 5~;
  $NavLink6 = qq~Step 6~;
  $yymain = qq~New forum.master file has been created. All useless files in /Boards have been cleaned up<br /><br />
<span class="warn-text">Category Conversion Complete.</span>
  ~;
  &Output;
}

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

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

    &CreateControl;
  $NavItem2 = "nav-item-highlight";
  $NavLink1 = qq~Step 1~;
  $NavLink2 = qq~Step 2~;
  $NavLink4 = qq~Step 4~;
  $NavLink5 = qq~Step 5~;
  $NavLink6 = qq~Step 6~;
  $yymain = qq~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.<br /><br />
<span class="warn-text">Board Conversion Complete.</span>
  ~;
  &Output;
}

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

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

    &ConvertMembers;
  $NavItem3 = "nav-item-highlight";
  $NavLink1 = qq~Step 1~;
  $NavLink2 = qq~Step 2~;
  $NavLink3 = qq~Step 3~;
  $NavLink5 = qq~Step 5~;
  $NavLink6 = qq~Step 6~;
  $yymain = qq~New User.vars files have been created. All useless files in /Members have been cleaned up. Password encrpytion is done of the fist login of the user.<br /><br />
<span class="warn-text">Member Conversion Complete.</span>
  ~;
  &Output;
}

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

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

    &ConvertMessages;
  $NavItem4 = "nav-item-highlight";
  $NavLink1 = qq~Step 1~;
  $NavLink2 = qq~Step 2~;
  $NavLink3 = qq~Step 3~;
  $NavLink4 = qq~Step 4~;
  $NavLink6 = qq~Step 6~;
  $yymain = qq~New style message files have been created. all useless files have been cleaned up from  /Messages<br /><br />
<span class="warn-text">Message Conversion Complete.</span>
  ~;
  &Output;
}

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

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

    &ConvertTimeToString;
  $NavItem5 = "nav-item-highlight";  $NavLink1 = "Step 1";
  $NavLink2 = qq~Step 2~;
  $NavLink3 = qq~Step 3~;
  $NavLink4 = qq~Step 4~;
  $NavLink5 = qq~Step 5~;
  $yymain = qq~New style timestamps have been created throughout the board. All old style dates have been converted.<br /><br />
<span class="warn-text">Date Conversion Complete.</span>
  ~;
  &Output;
}

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

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

  require "$sourcedir/System.pl";
  require "$boardsdir/forum.master"; 
  &ThreadRecount;
	foreach (keys %board) {
		&MyReCountTotals($_);
	}
  &MembershipCountTotal;
  &CleanUpBoardsAgain;

  $NavItem6 = "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~Step 6~;
  $yymain = qq~Board totals have been recounted, memberlist has been rebuilt<br /><br />
<span class="warn-text">Final Cleanup Complete.</span><br /><br />
We reccomend you delete the file "Setup.pl" in the main YaBB Directory, and the directory "ConverterHTML" in the yabbfiles directory. This is to prevent someone else running the converter, and damaging your files.<br /><br /><br />
You may now proceed to your forum <a href="$boardurl/YaBB.$yyext?action=login" />Here</a> - Enjoy using YaBB 2!
  ~;

  &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 Converter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="$html_root/ConverterHTML/style.css" rel="stylesheet" type="text/css" />
</head>
<body>

<!-- Header -->
<div class="header-style" id="header">&nbsp;</div>


<!-- 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" />
<link href="$html_root/ConverterHTML/style.css" rel="stylesheet" type="text/css" />
</head>
<body>

<!-- Header -->
<div class="header-style" id="header">&nbsp;</div>


<!-- Main Content -->
<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>~;

  $NavItem0 = "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~Step 6~;

  &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;
}


# Category Conversion #########################################################

sub GetCats {
	## converting message files
	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);
}

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



# Board Conversion ############################################################

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

	foreach $foundboard(@boardfiles) {
		chomp $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 message files
	opendir("DATADIR", $datadir);
	  @messages = grep {/\.txt$/} readdir("DATADIR");
	closedir("DATADIR");
	foreach $file(@messages) {
		chomp $file;
		$file = substr($file,0, length($file)-4);
		push(@msgfiles,$file);
	}


	foreach $foundfile (@msgfiles) {
		chomp $foundfile;
		fopen("MSGFILE", "$datadir/$foundfile.txt") || &fatal_error("$maintxt{'23'} $foundfile", 1);
		@messagefile = <MSGFILE>;
		fclose("MSGFILE");
		fopen("MSGFILE", ">$datadir/$foundfile.txt") || &fatal_error("$maintxt{'23'} $foundfile", 1);

		foreach my $line (@messagefile){
			chomp $line;
			$buffer = $line;
			my( $subject,$name,$email,$mdate,$username,$icon,$dummy,$user_ip,$message,$ns );
			($subject,$name,$email,$mdate,$username,$icon,$dummy,$user_ip,$message,$ns) = split(/\|/,$buffer);
			if($mdate =~ /$maintxt{'107'}/){
				$mdate = stringtotime($mdate);
			}
			print MSGFILE "$subject|$name|$email|$mdate|$username|$icon|$dummy|$user_ip|$message|$ns|\n";
		}
		fclose(MSGFILE);
	}
	## converting board files and totals
	fopen("DATADIR", "$boardsdir/sticky.stk");
	  @stickies = <DATADIR>;
	fclose("DATADIR");

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

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

	foreach $file(@boards_ttl) {
		chomp $file;
		$file = substr($file,0, length($file)-4);
		push(@boardttl,$file);
	}


	foreach $foundfile(@boardfiles) {
		chomp $foundfile;
		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;
			$buffer = $line;
			my( $mnum, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate );
			($mnum, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate) = split(/\|/,$buffer);
			if($mdate =~ /$maintxt{'107'}/){
				$mdate = stringtotime($mdate);
			}
			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);
	}
	foreach $foundfile(@boardttl) {
		chomp $foundfile;
		fopen("BOARDTTL", "$boardsdir/$foundfile.txt") || &fatal_error("$maintxt{'23'} $foundfile", 1);
		$boardttl = <BOARDTTL>;
		fclose("BOARDTTL");
		fopen("BOARDTTL", ">$boardsdir/$foundfile.txt") || &fatal_error("$maintxt{'23'} $foundfile", 1);
		chomp $boardttl;
		$buffer = $boardttl;
		my( $dummy1, $dummy2, $mdate, $dummy3);
		($dummy1, $dummy2, $mdate, $dummy3) = split(/\|/,$buffer);
		if($mdate =~ /$maintxt{'107'}/){
			$mdate = stringtotime($mdate);
		}
		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 Conversion ##########################################################



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

sub ConvertMembers {
	## member online, post and im logdates
	opendir(MEMDIR, $memberdir);
	@memlist =  grep {/\.dat$/} readdir(MEMDIR);
	closedir(MEMDIR);
	foreach $file(@memlist) {
		chomp $file;
		$file = substr($file,0, length($file)-4);
		push(@members,$file);
	}
	foreach $uname (@members){
		chomp $uname;
		&UserCheck($uname,"all");
		&UpdateMember($uname);
		my @xtn = qw(da2 ll om yam title mute ybl prolock ign txt bio siz imconfig dat);
		for(my $cnt; $cnt< @xtn; $cnt++){
			if (-e "$memberdir/$uname.$xtn[$cnt]"){unlink "$memberdir/$uname.$xtn[$cnt]";}
		}
	}
}


sub UpdateMember {
	my ($user,@pars) = @_;
#using sequential tag writing as hashes do no sort the way we like them to ##

	my @tags = qw(password realname email webtitle weburl signature postcount position iqc aim yim gender usertext userpic regdate location bday timeselect timeoffset hidemail msn template language lastonline lastpost lastim im_ignorelist im_notify im_popup im_imspop);

	fopen("USER", ">$memberdir/$user.dat");
		for( my $cnt = 0; $cnt < @tags; $cnt++ ) {
			print USER "$usercheck{$tags[$cnt]}\n";
		}
	fclose("USER");
}

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



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

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

sub ConvertMessages {

	## converting message files
	opendir("BOARDSDIR", $boardsdir);
	  @messages = readdir("BOARDSDIR");
	closedir("BOARDSDIR");
	foreach $file (@messages) {
		chomp $file;
		($name, $ext) = split(/\./, $file);
		if($ext eq 'txt') {
			push(@msgfiles,$name);
		}
	}

	foreach $foundfile(@msgfiles) {
		chomp $foundfile;
		fopen("MSGFILE", "$boardsdir/$foundfile.txt") || &fatal_error("$maintxt{'23'} $foundfile", 1);
		@messagefile = <MSGFILE>;
		fclose("MSGFILE");

		foreach my $line (@messagefile){
			chomp $line;
			$buffer = $line;
			my ($thread,$dummy);
			($thread,$dummy,$dummy,$dummy,$dummy,$dummy,$dummy,$dummy,$dummy,$dummy) = split(/\|/,$buffer);

			if (-e "$datadir/$thread.txt"){
				fopen("CTBFILE", ">$datadir/$thread.ctb") || &fatal_error("$maintxt{'23'} $thread", 1);
				print CTBFILE "$foundfile\n";
				fclose("CTBFILE");
			}
		}
	}
}

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



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

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

$at_var = "at";

sub ConvertTimeToString {
	## converting message files
	opendir("DATADIR", $datadir);
	  @messages = readdir("DATADIR");
	closedir("DATADIR");
	foreach $file(@messages) {
		chomp $file;
		($name, $ext) = split(/\./, $file);
		if($ext eq 'txt') {
			push(@msgfiles,$file);
		}
	}
	foreach $foundfile(@msgfiles) {
		chomp $foundfile;
		fopen("MSGFILE", "$datadir/$foundfile") || &fatal_error("$maintxt{'23'} $foundfile", 1);
		@messagefile = <MSGFILE>;
		fclose("MSGFILE");

		fopen("MSGFILE", ">$datadir/$foundfile") || &fatal_error("$maintxt{'23'} $foundfile", 1);

		foreach my $line (@messagefile){
			chomp $line;
			$buffer = $line;
			my( $subject,$name,$email,$mdate,$username,$icon,$dummy,$user_ip,$message,$ns );
			($subject,$name,$email,$mdate,$username,$icon,$dummy,$user_ip,$message,$ns) = split(/\|/,$buffer);

			$message =~ s~\[quote(\s+author=(.*?)link=(.*?)\s+date=(.*?)\s*)?\]\n*(.*?)\n*\[/quote\]~&QuoteFix($2,$3,$4,$5)~eisg;
			print MSGFILE "$subject|$name|$email|$mdate|$username|$icon|$dummy|$user_ip|$message|$ns|\n";
		}
		fclose("BOARDFILE");
	}

	## converting board files and totals
	opendir("DATADIR", $boardsdir);
	@boards = readdir("DATADIR");
	closedir("DATADIR");

	foreach $file(@boards) {
		chomp $file;
		($name, $ext) = split(/\./, $file);
		if($ext eq 'ttl') {
			push(@boardttl,$file);
		}
	}

	foreach $foundfile(@boardttl) {
		chomp $foundfile;
		fopen("BOARDTTL", "$boardsdir/$foundfile") || &fatal_error("$maintxt{'23'} $foundfile", 1);
		$boardttl = <BOARDTTL>;
		fclose("BOARDTTL");
		fopen("BOARDTTL", ">$boardsdir/$foundfile") || &fatal_error("$maintxt{'23'} $foundfile", 1);
		chomp $boardttl;
		$buffer = $boardttl;
		my( $dummy1, $dummy2, $mdate, $dummy3);
		($dummy1, $dummy2, $mdate, $dummy3) = split(/\|/,$buffer);
		if($mdate =~ /$at_var/){
			$mdate = stringtotime($mdate);
		}
		print BOARDTTL "$dummy1|$dummy2|$mdate|$dummy3\n";
		fclose("BOARDTTL");
	}
}

sub QuoteFix {
	my( $qauthor, $qlink, $qdate, $qmessage ) = @_;
	$qdate = &stringtotime($qdate);
	$_ = qq~[quote author=AUTHOR link=QUOTELINK date=DATE]QUOTE[/quote]~;
	$_ =~ s~AUTHOR~$qauthor~g;
	$_ =~ s~QUOTELINK~$qlink~g;
	$_ =~ s~DATE~$qdate~g;
	$_ =~ s~QUOTE~$qmessage~g;
	return $_;
}


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


# Cleanup #####################################################################
 
sub ThreadRecount {
	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; }
	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("convert",$cntboard);
	${$uid.$cntboard}{'threadcount'}  = $threadcount ;
	${$uid.$cntboard}{'messagecount'} = $messagecount ;
	&BoardTotals("update",$cntboard);
	&BoardSetLastInfo($cntboard);
}



sub MembershipCountTotal {
	my $membertotal = 0;
	my ($latestmember,$latestrealname);
	fopen(MEMLIST, "$memberdir/memberlist.txt");
	while( <MEMLIST> ) {
		chomp;
		if( $_ ) { 
			($latestmember,$dummy,$latestrealname) = split(/\|/,$_); 
			++$membertotal;
		}
	}
	fclose(MEMLIST);
	fopen(MEMTTL, "+>$memberdir/members.ttl");
	print MEMTTL qq~$membertotal|$latestmember~;
	fclose(MEMTTL);
	if( wantarray() ) {
		return ( $membertotal, $latestmember, $latestrealname );
	}
	else { return $membertotal; }
}


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

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

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



# Shared Subs #################################################################

sub UserCheck {
	my ($user,$pars) = @_;
	%usercheck="";
	$found = 0;
	$pars =~s/ //g;
### Convert user to new file if dat file still exists ###
	if(-e "$memberdir/$user.dat"){
		&LoadUser($user);
		&UserAccount($user,"update");
	}
	@labels = split(/\+/, $pars);
	fopen(CHECKUSER, "$memberdir/$user.vars");
	my @settings=<CHECKUSER>;
	fclose(CHECKUSER);
	foreach my $setting(@settings) {
		chomp $setting;
		$setting =~ s/\'(.+?)\'\,\"(.+?)\"//ig;
		my $tag = $1;
		my $value = $2;
		foreach $label(@labels){
			chomp $label;
			if ($label eq $tag || $label eq "all"){$usercheck{$tag}= $value;}
		}
	}
}


sub FormatUserName {
	my $user = $_[0];
	if( $useraccount{$user}) { return; }
	$useraccount{$user} = $user;
	$useraccount{$user} =~ s~\%~%25~g;
	$useraccount{$user} =~ s~\#~%23~g;
	$useraccount{$user} =~ s~\+~%2B~g;
	$useraccount{$user} =~ s~\,~%2C~g;
	$useraccount{$user} =~ s~\-~%2D~g;
	$useraccount{$user} =~ s~\.~%2E~g;
	$useraccount{$user} =~ s~\@~%40~g;
	$useraccount{$user} =~ s~\^~%5E~g;
}



sub UserAccount {
	my ($user,$action,$pars) = @_;
	@labels = split(/\+/, $pars);
	if (!${$uid.$user}{'password'}){return 0;}
	if (!${$uid.$user}{'timeformat'}){${$uid.$user}{'timeformat'}= qq~MM D+ YYYY @ HH:mm:ss*~;}
	if ($action eq "update"){
		foreach $label(@labels){
			chomp $label;
			${$uid.$user}{$label}=$date;
		}
		$userext = "vars";
	}
	if (!$userext){$userext = "vars";}
#using sequential tag writing as hashes do no sort the way we like them to ##

	my @tags = qw(password realname email webtitle weburl signature postcount position 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.$userext");
		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");
	if(-e "$memberdir/$user.dat"){unlink "$memberdir/$user.dat";}
}


sub LoadUser {
	my $user = $_[0];
	my $setting;
	if (${$uid.$user}{'realname'} ne ""){return 1;}
	if ($user eq ""){return 1;}
	$yyload .= "Loaded $user <br>";
    if (-e "$memberdir/$user.dat") {
		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' => "$settings[21]",
			'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]",
		);
	}
	&FormatUserName($user);
	return 1;
}

# / Shared Subs ###############################################################


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){&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 "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"; }
		}
	} 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/$name";}
			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"; }
		}
	}
	$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;
		$uploaddir = $fnd_uploaddir;
		$uploadurl = $fnd_uploadurl;
		$ubbcjspath = $fnd_ubbcjspath;
		$faderpath = $fnd_faderpath;
	}
	
## 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">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 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'};
	$ubbcjspath = $FORM{'ubbcjspath'};
	$faderpath = $FORM{'faderpath'};

	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
\$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 Ubbc.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
\$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, $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;
}


1;
