#!c:/sambar51/perl/bin/perl.exe
use vars qw(%config %category %form $i);
use strict;
#-###########################################################################
# EveryAuction Release Version 1.51 (5/13/00)
# Copyright (C) 2000 EverySoft
# http://www.everysoft.com/
#
#  EZAUCTNIE SINGLE VERSION 2.0
#  Created by Ivana Erney
#  http://www.webgalactic.com/ivana/
#  Original Addons Created For This Script Are:
#  PayPal Pay Now Button, PayPal Icon, BillPoint Pay Button Request Invoice,
#  BillPoint Icon, Yahoo PayDirect Request Invoice, Yahoo PayDirect Icon,
#  Auction Layout Differently
#-###########################################################################

#-#############################################
# Configuration Section
# Edit these variables!
local %config;

# Get form variables
local %form = &get_form_data;


# The Base Directory.  We need an
# absolute path for the base directory.
# Include the trailing slash.  THIS SHOULD
# NOT BE WEB-ACCESSIBLE!

$config{'basepath'} = "c:/sambar51/cgi-bin/ez/";

# Closed Auction Directory
# This is where closed auction items are stored.
# Leave this blank if you don't want to store
# closed auctions.  It can potentially take
# up quite a bit of disk space.

$config{'closedir'} = 'closed';

# User Registration Directory
# This is where user registrations are stored.
# Leave this blank if you don't want to
# require registration.  It can potentially
# take up quite a bit of disk space.

$config{'regdir'} = 'reg';

# Directory where the newmember.dat file will
# be stored
$config{'newestmember'} = 'nm';

# List each directory and its associated
# category name.  These directories should
# be subdirectories of the base directory.

%category = (
            Gold => 'Gold Gemstones',
        Books => 'New Used and Rare Books',
        Equip => 'New and Used Prospecting Equipment',
        Tools => 'Tools Generators Winches',
        Veh => 'Trucks Rvs Atvs',
        Trail => 'Trailers Utility Rv',
        Maps => 'Maps and Topos',
        Software => 'Mapping Software and Data Cds',
        Comp => 'Computers Parts and Accessories',
        Mov => 'Movies DVDs Videos Music Cds',
        Photo => 'New and Old Photographs Paintings',
        Serv => 'Small Engines and Services',
        Vital => 'Historical Records',
        Parts => 'Parts and Mining Supplies',
        Direct => 'City and State Mining Directories',
        Camp => 'Camping Equipment New and Used',
        Access => 'Accessories',
        other => 'Other items',
        Toy => 'Toys Childrens Games',
);

# This is the password for deleting auction
# items.  To run a server this might not allow
# your users to delete auctions.  Set it to a
# password you choose, if it doesn't work delete it.

$config{'adminpass'} = 'eng300';

# You need to assign either a mail program or
# a mail host so confirmation e-mails can
# be sent out.
# Leave one commented and one uncommented.
#
# YOU NEED EITHER A MAIL PROGRAM
$config{'mailprog'} = 'c:/sendmail/sendmail -t';
#
# OR YOU NEED A MAIL HOST (SMTP)

# $config{'mailhost'} = 'localhost';

# This line should be your e-mail address

$config{'admin_address'} = 'ggpa@nuggethunters.com';

# This line should point to the URL of
# your server.  It will be used for sending
# "you have been outbid" e-mail.  The script
# name and auction will be appended to the
# end automatically, so DO NOT use a trailing
# slash.  If you do not want to send outbid
# e-mail, leave this blank.

$config{'scripturl'} = 'http://www.nuggethunters.com';

# This will let you define colors for the
# tables that are generated and the
# other page colors.  The default colors
# create a nice "professional" look.  Must
# be in hex format.
# DO NOT EDIT THESE BELOW OR YOU WILL HAVE
# WEIRD COLORING FOR YOUR AUCTION SERVICE
# AND USERS WILL NOT BE ABLE TO SET THEIR
# OWN COLORS.

$config{'colortablehead'} = '#FFBC61';
$config{'colortablebody'} = '#003333';

# Set your HTML Background and font attributes
$config{'BGCOLOR'} = '#003333';
$config{'text'} = '#FFBC61';
$config{'link'} = '#DDDDDD';
$config{'vlink'} = '#C0C0C0';
$config{'alink'} = '#DDDDDD';

# Set the url to your logo
$config{'yourlogo'} = 'http://www.nuggethunters.com/banners/ggpabanner3.gif';

# Site Name (will appear at the top of each page)

$config{'sitename'} = 'Nuggethunters OutDoor Network Auction Site';


# Sniper Protection...  How many minutes
# past last bid to hold auction.  If auctions
# should close at exactly closing time, set
# to zero.

$config{'aftermin'} = 5;

# File locking enabled?  Should be 1 (yes)
# for most systems, but set to 0 (no) if you
# are getting flock errors or the script
# crashes.

$config{'flock'} = 1;

# User Posting Enabled- 1=yes 0=no

$config{'newokay'} = 1;

$config{'goinghours'} = 3;
$config{'newdays'} = 1;

# You can configure your own header which will
# be appended to the top of each page.

$config{'header'} =<<"EOF";
<html>
<head>
<title>$config{'sitename'} GGPA Online Auction</title>
<style type=text/css>A:hover {
        BACKGROUND-COLOR: $config{'colortablehead'}; COLOR: $config{'colortablebody'}; TEXT-DECORATION: none
}
</style>
</head>
<body BGCOLOR=$config{'BGCOLOR'} text=$config{'text'} link=$config{'link'} vlink=$config{'vlink'} alink=$config{'alink'}>
<div align=center>
  <center>
<table border=0 width=99%
    cellspacing=0 cellpadding=0 style="border-collapse: collapse">
      <tr>
        <td bgcolor="$config{'colortablehead'}"><div align="center"><center>
          <table border="0" width="100%"
        cellspacing="0" style="border-collapse: collapse" cellpadding="0">
          <tr>
            <td width="50%" bgcolor="$config{'colortablebody'}"><p align="left">
            <img src="$config{'yourlogo'}"></td>
            <td width="50%" bgcolor="$config{'colortablebody'}">
            <form ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>
  <input type=hidden name=action value=search><div align=center><center><p><b>
    <font face="Arial" size="2">Search Auction For:</font></b><font face="Arial" style="font-size: smaller">
    </font><small><font face=Arial>
    <input
  TYPE=TEXT NAME=searchstring size=20> <input TYPE=SUBMIT VALUE=Search><br>
    <input
  TYPE=RADIO NAME=searchtype VALUE=keyword CHECKED>Keyword <input TYPE=RADIO
  NAME=searchtype VALUE=username>Username</font></small></p>
  </center></div>
</form></td>
          </tr>
        </table>
        </center></div></td>
      </tr>
    </table></center>
</div>
<table border=0 width=100%>
  <tr>
    <td width=78% valign=top><div align=center><center><table border=0 width=100%
    cellspacing=0 bgcolor=#003333>
      <tr>
        <td width=100%><p align=center><font face=Verdana color=#FFFFFF><small><a
        STYLE=color:#FFFFFF href=http://www.nuggethunters.com/cgi-bin/pop/thinmailer.cgi>Check
        Mail</a> | <a
        STYLE=color:#FFFFFF href=http://www.gold-prospecting.com>Gen
        Directory</a> | <a
        STYLE=color:#FFFFFF href=http://www.nuggethunters.org>GGPA
        </a> | <a
        STYLE=color:#FFFFFF href=http://www.nuggethunters.com/cgi-bin/blah/blah.pl>
        Query Forums</a> | <a STYLE=color:#FFFFFF href=http://www.rootssearch.net/cgi-bin/dclinks/dclinks.cgi>Downloads</a>
        | <a
        STYLE=color:#FFFFFF href=http://www.wildmans-civilwar-surplus.com>Book
        Store</a> | <a
        STYLE=color:#FFFFFF href=http://www.pcshoppers.net>Shopping
        Resources</a> | <a
        STYLE=color:#FFFFFF href=http://www.nuggethunters.com/HISTORY.html>
        Articles</a></small></font></td>
      </tr>
    </table>
    </center></div></td>
  </tr>
</table>
    <P>
EOF

# You can configure your own footer which will
# be appended to the bottom of each page.
# Although not required, a link back to
# everysoft.com will help to support future
# development.

$config{'footer'} =<<"EOF";
<BR><BR>
<div align="center"><center>

<table border="0" width="99%" cellspacing="0" bgcolor="#003333">
  <tr>
    <td width="100%"><div align="center"><center><table border="0" width="100%"
    cellpadding="2" cellspacing="0">
      <tr>
        <td width="100%" bgcolor="#003333"><p align="center"><small><font face="Arial"><a
        href="http://www.nuggethunters.com/cgi-bin/search/search.pl?Mode=AnonAdd">Add a Site</a>
        | <a
        href="http://www.nuggethunters.com/about.html">About</a> | <a
        href="http://www.gold-prospecting.com/add.htm">Advertise</a> | <a
        href="http://www.f-1group.com">Webmasters</a> |</font>
        <font
        face="Arial"><a href="http://www.nuggethunters.com/contact.html">Contact</a> | <a
        href="http://www.nuggethunters.com">Make Nuggethunters Your Start Page</a></font></small><font
        face="Verdana"><br>
        </font><font face="Arial"><small><a href="http://www.gold-prospecting.com">Nuggethunters OutDoor Network</a>
        is © 1998-2002.&nbsp; All rights reserved.</small></font></td>
      </tr>
    </table>
    </center></div></td>
  </tr>
</table>
</center></div>
</BODY>
</HTML>
EOF

#-#############################################
# Main Program
# You do not need to edit anything below this
# line.

#-#############################################
# Print The Page Header
#
print "Content-type: text/html\n\n";
print $config{'header'};
#
#-#############################################

if ($form{'action'} eq 'new') { &new; }
elsif ($form{'action'} eq 'repost') { &new; }
elsif ($form{'action'} eq 'procnew') { &procnew; }
elsif ($form{'action'} eq 'procbid') { &procbid; }
elsif ($form{'action'} eq 'reg') { &reg; }
elsif ($form{'action'} eq 'procreg') { &procreg; }
elsif ($form{'action'} eq 'creg') { &creg; }
elsif ($form{'action'} eq 'proccreg') { &proccreg; }
elsif ($form{'action'} eq 'closed') { &viewclosed1; }
elsif ($form{'action'} eq 'closed2') { &viewclosed2; }
elsif ($form{'action'} eq 'closed3') { &viewclosed3; }
elsif ($form{'action'} eq 'buyitnow') { &dispbuy; }
elsif ($form{'action'} eq 'procbuy') { &procbuy; }
elsif ($form{'action'} eq 'admin') { &admin; }
elsif ($form{'action'} eq 'procadmin') { &procadmin; }
elsif ($form{'action'} eq 'lp') { &lp; }
elsif ($form{'action'} eq 'lp2') { &lp2; }
elsif ($form{'action'} eq 'la') { &la; }
elsif ($form{'action'} eq 'la2') { &la2; }
elsif ($form{'action'} eq 'referafriend') { &referafriend; }
elsif ($form{'action'} eq 'referafriend2') { &referafriend2; }
elsif ($form{'action'} eq 'emailusers') { &emailusers; }
elsif ($form{'action'} eq 'emailusersadmin') { &emailusersadmin; }
elsif ($form{'action'} eq 'suggest') { &suggest; }
elsif ($form{'action'} eq 'procsuggest') { &procsuggest; }
elsif ($form{'action'} eq 'all') { &view_all; }
elsif ($form{'action'} eq 'allclosed') { &view_all_closed; }
elsif ($form{'action'} eq 'search') { &procsearch; }
elsif ($form{'item'} eq int($form{'item'}) and $category{$form{'category'}}) { &dispitem; }
elsif ($category{$form{'category'}} and $form{'listtype'} eq 'current') { &displist; }
elsif ($category{$form{'category'}} and $form{'listtype'} eq 'new') { &displistnew; }
elsif ($category{$form{'category'}} and $form{'listtype'} eq 'gone') { &displistgone; }
elsif ($category{$form{'category'}} and $form{'listtype'} eq 'close') { &displistclose; }
else { &dispcat; }

#-#############################################
# Print The Page Footer
#
print "<P><P ALIGN=CENTER><FONT SIZE=2 FACE=Arial>[ <A HREF=$ENV{'SCRIPT_NAME'}>Categories</A> ]";
print " [ <A HREF=$ENV{'SCRIPT_NAME'}?action=all>All Items</A> ]";
print " [ <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=new>New</A> ]";
print " [ <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=close>Closing</a> ]";
print " [ <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=gone>Going, Gone!</a> ]";
print " [ <A HREF=$ENV{'SCRIPT_NAME'}?action=allclosed>All Closed</A> ]";
print " [ <A HREF=$ENV{'SCRIPT_NAME'}?action=new>Post Item</A> ]" if ($config{'newokay'});
print " [ <A HREF=$ENV{'SCRIPT_NAME'}?action=reg>Register</A> ]";
print " [ <A HREF=$ENV{'SCRIPT_NAME'}?action=closed>My Auction</A> ]" if ($config{'regdir'}) and ($config{'closedir'});
print " <BR>[ <a href=javascript:newWin=void(window.open('$config{'scripturl'}/helppost.html','newWin','scrollbars=1,width=300,height=400'))>Help Posting</a> ]";
print " [ <A HREF=$ENV{'SCRIPT_NAME'}?action=suggest>Suggest A Category</a> ]";
print " [ <A HREF=$ENV{'SCRIPT_NAME'}?action=creg>Change Registration</A> ]" if ($config{'regdir'});
print " [ <A HREF=$ENV{'SCRIPT_NAME'}?action=lp>Lost Password</a> ]";
print " [ <A HREF=$ENV{'SCRIPT_NAME'}?action=la>Lost Login</a> ]";
print " [ <A HREF=$ENV{'SCRIPT_NAME'}?action=referafriend>Tell A Friend</A> ]";
print " [ <A HREF=http://www.gold-prospecting.com>Home</a> ]";
print " </FONT></P>\n";
print $config{'footer'};
#
#-#############################################

#-#############################################
# Sub: Display List Of Categories
# This creates a "nice" list of categories.

sub dispcat {
&chkclose;
    print "<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablebody'}><font color=$config{'colortablehead'}>";
    print "<center><IMG SRC=$config{'scripturl'}/categoryhead.gif></center>";
        print "</font></td></tr></table>";
    print "<div align=center><center><TABLE WIDTH=80\% BORDER=1>\n";
    print "<TR><TD ALIGN=CENTER BGCOLOR=$config{'colortablebody'}><font FACE=Arial color=$config{'colortablehead'}><small><B></B></small></font></TD>";
    my $key;
    foreach $key (sort keys %category) {
        umask(000);  # UNIX file permission junk
        mkdir("$config{'basepath'}$key", 0777) unless (-d "$config{'basepath'}$key");
        opendir DIR, "$config{'basepath'}$key" or &oops("Category directory $key could not be opened.");
        my $numfiles = scalar(grep -T, map "$config{'basepath'}$key/$_", readdir DIR);
        closedir DIR;
        print "<TR><TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$key\&listtype=current><font face=Arial><small>$category{$key}</A><B> \($numfiles\)</B></font></small></TD></TR>";
    }
    print "</TABLE>\n";
        &stats;
        &welcome_msg
}

#-#############################################
# Sub: Display List Of Items
# This creates a "nice" list of items in a
# category.

sub displist {
    print "<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablebody'}><font color=$config{'colortablehead'}>";
    print "<font face=Arial><I><B><center>$category{$form{'category'}}</B></I></center><BR>\n";
        print "<small><IMG SRC=$config{'scripturl'}/cats.gif> <A HREF=$ENV{'SCRIPT_NAME'}>Categories</A> ";
        print "   <IMG SRC=$config{'scripturl'}/all.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=all>All Items</A> ";
        print "   <IMG SRC=$config{'scripturl'}/new.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=new>New</A> ";
        print "   <IMG SRC=$config{'scripturl'}/closing.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=close>Closing</a> ";
        print "   <IMG SRC=$config{'scripturl'}/ending.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=gone>Going, Gone!</a> ";
        print "   <IMG SRC=$config{'scripturl'}/allclosed.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=allclosed>All Closed</A> ";
        print "   <IMG SRC=$config{'scripturl'}/post.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=new>Post Item</A> ";
        print "   <IMG SRC=$config{'scripturl'}/register.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=reg>Register</A> ";
        print "   <IMG SRC=$config{'scripturl'}/myauction.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=closed>My Auction</A></small></font> ";
        print "</font></td></tr></table>";
    print "<TABLE BORDER=0 WIDTH=80\%>\n";
    print "<TR><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Number</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Item</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Closes</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><B><small>Num Bids</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><B><small>High Bid</B></small></font></TD></TR>\n";
    opendir THEDIR, "$config{'basepath'}$form{'category'}" or &oops("Category directory $form{'category'} could not be opened.");
    my @allfiles = grep -T, map "$config{'basepath'}$form{'category'}/$_", sort { int($a) <=> int($b) } (readdir THEDIR);
    closedir THEDIR;
    my $file;
    my $pagebreak = int $form{pb} || 10;
        my ($icount, $pcount) = (0,0);
        foreach $file (@allfiles) {
                if(++$icount > $pagebreak){$icount=1; $pcount++}
                next if $pcount != $form{page};
        $file =~ s/^$config{'basepath'}$form{'category'}\///;
        $file =~ s/\.dat$//;
        my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = &read_item_file($form{'category'},$file);
        if ($title ne '') {
            my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]);
            my @closetime = localtime($file);
            $closetime[4]++;
                        my $timeremain = time_remain($file);
                        if ((time > $file) && (time > (60 * $config{'aftermin'} + $time))) {
                        &closeit($form{'category'},$file);
                        }
            print "<TR><TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file><font face=Arial><small>$file</small></A></TD>";
                        print "<TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file><font face=Arial><small>$title</font></small></A>";
            print " <img src=$config{'scripturl'}/cam2.gif>" if ($image);
                        print " <img src=$config{'scripturl'}/buyit.gif>" if ($buyit);
                        print " <img src=$config{'scripturl'}/paypalicon.gif>" if ($paypal);
                        print " <img src=$config{'scripturl'}/billpointicon.gif>" if ($billpoint);
                        print " <img src=$config{'scripturl'}/yahooicon.gif>" if ($yahoo);
            print "</TD><TD BGCOLOR=$config{'colortablebody'} align=center><font face=Arial><small>$timeremain</small></font></TD><TD BGCOLOR=$config{'colortablebody'} align=center><font face=Arial><small>$#bids</font></small></TD><TD BGCOLOR=$config{'colortablebody'} align=center><font face=Arial><small>\$$bid</small></font></TD></TR>\n";
        }
    }
    print "</TABLE><P><font face=Arial><small>\n";
        pagebreak($pcount,$pagebreak);
}

#-#############################################
# Sub: Display Item
# This displays a particular item, its
# description, and its associated bids.

sub dispitem {
    my ($alias, $email, $bid, $time, $add1, $add2, $add3);
    my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = &read_item_file($form{'category'},$form{'item'});
    &oops("Item $form{'item'} could not be opened.  If this item is closed, you can view statistics and bid history using our <A HREF=$ENV{'SCRIPT_NAME'}\?action=closed>closed item viewer</A>.") if $title eq '';
    my $nowtime = localtime(time);
    my $closetime = localtime($form{'item'});
        my $timeremain = time_remain($form{item});
    print "<div align=center><center><table border=0 width=800><tr><td width=100% bgcolor=$config{'colortablehead'}><p align=center><big><font face=Arial color=$config{'colortablebody'}>$title</font></big></td></tr><tr>";
        print "<td width=100%><BR><font face=Arial size=2><b><p align=center>Category:&nbsp;<A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}>$category{$form{'category'}}</A>&nbsp; Current Time: $nowtime</b>";
        # either the item is closed or we will display a bid form
    ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]); # read the last bid
    if ((time > int($form{'item'})) && (time > (60 * $config{'aftermin'} + $time))) {
        print "<B><BIG><font color=red>BIDDING IS NOW CLOSED</BIG></font></B><BR>";
        &closeit($form{'category'},$form{'item'});
    }
        print "</font><BR></td></tr><tr>";
        print "<td width=100%><BR><p align=center><IMG SRC=$image><BR></TD>" if ($image);
        print "</font></td></tr><tr><td width=100% valign=top><div align=center><center><table border=0 width=800 cellspacing=10 cellpadding=2><tr><td width=32% valign=top bgcolor=$config{'colortablehead'}><font face=Arial color=$config{'colortablebody'}><center><strong>Information</strong></font></center></td><td width=68% valign=top bgcolor=$config{'colortablehead'}><center><strong><font face=Arial color=$config{'colortablebody'}>Description</center></font></strong></td></tr><tr>";
        print "<td width=32% valign=top><font face=Arial><small>";
        ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[0]); # read first bid
        print "<B>Closes:</B> <font color=red>$timeremain</font><BR><BR><B>Number of Bids:</B> $#bids";
        print "<BR><BR><B>Offered By:</B> <A HREF=mailto:$email>$alias</A><BR>";
        print "<A HREF=$ENV{'SCRIPT_NAME'}\?action=search\&searchstring=$alias\&searchtype=username><IMG src=$config{'scripturl'}/view.gif border=0> Sellers Other Auctions</A><BR>";
        print "<A HREF=mailto:$email><IMG src=$config{'scripturl'}/ask.gif border=0> Contact $alias</A><BR>";
        print "<A HREF=$mysite target=_blank><IMG src=$config{'scripturl'}/home.gif border=0> Sellers Website</A>" if ($mysite);
        print "<BR>" if ($mysite);
        ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]); # read last bid
        print "<BR><B>Last Bid:</B> \$$bid ";
        print "<br>(reserve price not yet met)" if ($bid < $reserve);
    print "<br>(reserve price met)" if (($bid >= $reserve) and ($reserve > 0));
        print "<BR><A HREF=$ENV{'SCRIPT_NAME'}\?action=buyitnow&category=$form{'category'}&item=$form{'item'}><img src=$config{'scripturl'}/buyit.gif border=0> this item now for</a> <b>\$$buyit</b>" if ($buyit);
    print "<BR><BR><B>Bid History:</B><br>\n";
    my $lowest_new_bid;
    # Lines commented out are removing the feedback feature.
        # if ($#bids) {
    #         for (my $i=1; $i<scalar(@bids); $i++) {
    #                my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$i]);
    #                my $bidderfeed = &feedback($alias,2);
    #                my $bidtime = localtime($time);
    #                print "$bidderfeed - \$$bid<BR>";
    #        }
    #        $lowest_new_bid = &parsebid($bid+$inc);
    # }
        if ($#bids) {
         for (my $i=1; $i<scalar(@bids); $i++) {
                my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$i]);
                 my $bidtime = localtime($time);
                print "<FONT SIZE=-1>$alias - \$$bid</FONT><BR>";
        }
         $lowest_new_bid = &parsebid($bid+$inc);
 }
    else {
        print "No bids yet...<BR>";
        $lowest_new_bid = (&read_bid($bids[0]))[2];
    }
    # either the item is closed or we will display a bid form
    ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]); # read the last bid
    if ((time > int($form{'item'})) && (time > (60 * $config{'aftermin'} + $time))) {
        print "<B><BIG><font color=red>BIDDING IS NOW CLOSED</BIG></font></B><BR>";
        &closeit($form{'category'},$form{'item'});
    }
    else {
         print "<BR><font color=$config{'colortablehead'}><B>Item Condition</B></font><BR>";
         print "<font face=Arial>$itmcond</font><BR><BR>";
         print "<font face=Arial color=$config{'colortablehead'}><B>Shipping Method</B></font><BR>";
         print "<font face=Arial>$ship </font><BR>";
         print "<BR><font face=Arial color=$config{'colortablehead'}><B>Payment Method</B></font><BR><font face=Arial>";
         print " $pay0," if $pay0 ne "" ;
         print " $pay1," if $pay1 ne "" ;
         print " $pay2," if $pay2 ne "" ;
         print " $pay3," if $pay3 ne "" ;
         print " $pay4," if $pay4 ne "" ;
         print " $pay5," if $pay5 ne "" ;
         print " $pay6," if $pay6 ne "" ;
         print " $pay7," if $pay7 ne "" ;
         print " $pay8" if $pay8 ne "" ;
         print "<BR><BR><A HREF=https://www.paypal.com/affil/pal=$paypal target=_blank><img src=$config{'scripturl'}/paypalpaynow.gif border=0>" if ($paypal);
         print "</A>" if ($paypal);
         print "<BR><BR><A HREF=mailto:$billpoint><img src=$config{'scripturl'}/billpointpayments.gif border=0>" if ($billpoint);
         print "<BR>Request An Invoice</A>" if ($billpoint);
         print "<BR><BR><A HREF=mailto:$yahoo><img src=$config{'scripturl'}/yahoopaydirect.gif border=0>" if ($yahoo);
         print "<BR>Request An Invoice</A>" if ($yahoo);

         print "</td><td width=68% valign=top><p align=right><A HREF=javascript:window.print()>Print This Page</a>";
         print "<p align=left>$desc ";
         print <<"EOF";
<br><br><div align=center><center><table border=0 width=100%><tr><td width=100% bgcolor=$config{'colortablehead'}><p align=center><big><font face=Arial color=$config{'colortablebody'}>BID NOW</font></big></td></tr></table></center></div>
<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>
</small><IMG src=$config{'scripturl'}/bid.gif>
<FONT color=$config{'colortablehead'} face=Arial><BIG><B>Place A Bid</B></BIG></font><BR><font face=Arial><small>
<INPUT TYPE=HIDDEN NAME=action VALUE=procbid>
<INPUT TYPE=HIDDEN NAME=ITEM VALUE="$form{'item'}">
<INPUT TYPE=HIDDEN NAME=CATEGORY VALUE="$form{'category'}">
<B>The High Bid Is:</B><font color=red> \$$bid
</font><BR><B>The Lowest You May Bid Is:</B><font color=red> \$$lowest_new_bid
</font><BR>
EOF

        if ($config{'regdir'}) {
            print <<"EOF";
<P><B><A HREF=$ENV{'SCRIPT_NAME'}?action=reg>Registration</A> is required to post or bid!</B>
<BR><B>Your Handle/Alias:</B> <INPUT NAME=ALIAS TYPE=TEXT SIZE=30 MAXLENGTH=30> (used to track your bid)
<BR><B>Your Password:</B> <INPUT NAME=PASSWORD TYPE=PASSWORD SIZE=30> (must be valid)
<BR><B>Your Bid:</B> \$<INPUT NAME=BID TYPE=TEXT SIZE=7 VALUE="$lowest_new_bid">
EOF
        }
        else {
            print <<"EOF";
<P><B>Your Handle/Alias:</B> <INPUT NAME=ALIAS TYPE=TEXT SIZE=30 MAXLENGTH=30> (used to track your bid)
<BR><B>Your E-Mail Address:</B> <INPUT NAME=EMAIL TYPE=TEXT SIZE=30> (must be valid)
<BR><B>Your Bid:</B> \$<INPUT NAME=BID TYPE=TEXT SIZE=7 VALUE="$lowest_new_bid">
<P><B>Contact Information:</B> (will be given out only to the seller)<BR>
Full Name: <BR><INPUT NAME=ADDRESS1 TYPE=TEXT SIZE=30><BR>
Street Address: <BR><INPUT NAME=ADDRESS2 TYPE=TEXT SIZE=30><BR>
City, State, ZIP: <BR><INPUT NAME=ADDRESS3 TYPE=TEXT SIZE=30><P>
EOF
        }
        print <<"EOF";
<INPUT TYPE=SUBMIT VALUE="Place Bid">
EOF
    }
         print "</font></center></P></td></tr></table></center></div></td></tr></table></center></div>\n";
}

#-#############################################
# Sub: Add New Item
# This allows a new item to be put up for sale

sub new {
    my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids);
    $inc = '1.00'; # default increment
    if ($form{'REPOST'}) {
        $form{'REPOST'} =~ s/\W//g;
        if (-T "$config{'basepath'}$config{'closedir'}/$form{'REPOST'}.dat") {
            open THEFILE, "$config{'basepath'}$config{'closedir'}/$form{'REPOST'}.dat";
            ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = <THEFILE>;
            close THEFILE;
            chomp($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids);
            $title =~ s/\"//g;  # quotes cause problems for a text input field
        }
    }
    print <<"EOF";
<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>
<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablehead'}><font color=$config{'colortablebody'}>
<font face=Arial><I><B><center>Post A New Item</I></B></center></font>
</font></td></tr></table>
<div align=center><center><TABLE WIDTH=80% BORDER=0 BGCOLOR=$config{'colortablebody'}>
<INPUT TYPE=HIDDEN NAME=action VALUE=procnew>
<TR><TD VALIGN=TOP><font FACE=Arial><B>Title/Item Name:<BR></B>No HTML</TD><TD><INPUT NAME=TITLE VALUE=\"$title\" TYPE=TEXT SIZE=50 MAXLENGTH=50></TD></TR>
<TR><TD VALIGN=TOP><B>Category:<BR></B>Select One</TD><TD><SELECT NAME=CATEGORY>
<OPTION SELECTED></OPTION>
EOF
    my $key;
    foreach $key (sort keys %category) {
        print "<OPTION VALUE=\"$key\">$category{$key}</OPTION>\n";
    }
    print <<"EOF";
</SELECT></TD></TR>
<TR><TD VALIGN=TOP><font FACE=Arial><B>Image URL:<BR></B>Optional, should be no larger than 200x200</TD><TD><INPUT NAME=IMAGE VALUE=\"http://\" TYPE=TEXT SIZE=50></TD></TR>
<TR><TD VALIGN=TOP><B>Days Until Close:<BR></B>1-14</TD><TD><INPUT NAME=DAYS TYPE=TEXT SIZE=2 MAXLENGTH=2></TD></TR>
<TR><TD VALIGN=TOP><B>Item Condition:</B></TD>
<TD><select name="ITMCOND" value=$itmcond>
        <option selected>See Description
            <option>Excellent
        <option>Very Good
            <option>Good
        <option>Fair
        <option>Poor
        </select></TD></TR>
        <TR><TD VALIGN=TOP><B>Shipping Method:</B></TD>
<TD><select name="SHIP" value=$ship>
    <option selected>See Description
        <option>Download
            <option>Fed-Ex
        <option>UPS
        <option>Priority Mail
        <option>U.S. Mail
        <option>Pick-Up
        <option>Truck
</select></TD></TR>
<TR><TD VALIGN=TOP colspan=2><B>Payment Method(s):</B><br> Choose all payment methods you will accept.</TD><tr>
<TR><TD colspan=2 VALIGN=TOP align=center>
<table width=500 border=0><tr>
       <td width=150><input name="PAY0" type="radio" value="See Description">See Description</td>
       <td width=150><input name="PAY1" type="radio" value="Cash">Cash</td>
       <td width=200><input name="PAY2" type="radio" value="Check">Check</td>
</tr><tr>
       <td width=150><input name="PAY3" type="radio" value="Money Order">Money Order</td>
       <td width=150><input name="PAY4" type="radio" value="Visa">Visa</td>
       <td width=200><input name="PAY5" type="radio" value="Mastercard">Mastercard</td>
</tr><tr>
       <td width=150><input name="PAY6" type="radio" value="Discover">Discover</td>
       <td width=150><input name="PAY7" type="radio" value="Other">Other</td>
       <td width=200><input name="PAY8" type="radio" value="Online Payment service">Online Payment service</td>
</tr></table></TD><tr>
<TR><TD VALIGN=TOP><B>Description:<BR></B>May include HTML - This should include the condition of the item, payment and shipping information, and
any other information the buyer should know.  To use html for paragraph space put Open tag of [P]Your Text here and closing tag[/P] at the end.  Replace the [] with < and >.</TD><TD><TEXTAREA NAME=DESC ROWS=5 COLS=45>$desc</TEXTAREA></TD></TR>
<TR><TD COLSPAN=2 VALIGN=TOP>Please note that by placing an item up for bid you are making a contract between you and the buyer.
Once you place an item, you may not retract it and you must sell it for the highest bid.
In other words, if you don't want to sell it, don't place it up for bid!
<TR><TD VALIGN=TOP><B>Visit My Site:<BR></B>Optional, Add a link to your site.</TD><TD><INPUT NAME=MYSITE VALUE="$mysite" TYPE=TEXT SIZE=50 VALUE="http://"><BR>http://www.YourSiteName.com</TD></TR>
<TR><TD VALIGN=TOP><B>PayPal Pay Now:<BR></B>Optional, Add a Paypal Pay Now Button.</TD><TD><INPUT NAME=PAYPAL VALUE="$paypal" TYPE=TEXT SIZE=50><BR>ENTER YOU PAYPAL EMAIL ACCOUNT</TD></TR>
<TR><TD VALIGN=TOP><B>BillPoint Payments:<BR></B>Optional, Add a BillPoint Request Invoice Button.</TD><TD><INPUT NAME=BILLPOINT VALUE="$billpoint" TYPE=TEXT SIZE=50><BR>ENTER THE EMAIL ADDRESS YOU WISH TO BE CONTACTED AT TO RECEIVE NOTIFICATION OF AN INVOICE REQUEST</TD></TR>
<TR><TD VALIGN=TOP><B>Yahoo PayDirect Payments:<BR></B>Optional, Add a Yahoo Request Invoice Button.</TD><TD><INPUT NAME=YAHOO VALUE="$yahoo" TYPE=TEXT SIZE=50><BR>ENTER THE EMAIL ADDRESS YOU WISH TO BE CONTACTED AT TO RECEIVE NOTIFICATION OF AN INVOICE REQUEST</TD></TR>
EOF

    if ($config{'regdir'}) {
        print <<"EOF";
<P><B><font FACE=Arial><A HREF="$ENV{'SCRIPT_NAME'}?action=reg">Registration</A> is required to post or bid!</B></TD></TR>
<TR><TD VALIGN=TOP><B>Your Handle/Alias:<BR></B>Used to track your post</TD><TD><INPUT NAME=ALIAS TYPE=TEXT SIZE=30 MAXLENGTH=30>
<TR><TD VALIGN=TOP><B>Your Password:<BR></B>Must be valid</TD><TD><INPUT NAME=PASSWORD TYPE=PASSWORD SIZE=30>
<TR><TD VALIGN=TOP><B>Your Starting Bid:</B></TD><TD>\$<INPUT NAME=BID TYPE=TEXT SIZE=7 VALUE=0>
<TR><TD VALIGN=TOP><B>Your Reserve Price:<BR></B>You are not obligated to sell below this price.  Leave blank if none.</TD><TD>\$<INPUT NAME=RESERVE TYPE=TEXT SIZE=7 VALUE=0>
<TR><TD VALIGN=TOP><B>Buy It Now Price:</B><BR>Optional, if you want to set an Immediate sale Price. Enter the amount here and Bidder will have the Option to buy this item before the Auction Closes</TD><TD>\$<INPUT NAME=BUYIT TYPE=TEXT SIZE=7></TD></TR>
<TR><TD VALIGN=TOP><B>Bid Increment:</B></TD><TD>\$<INPUT NAME=INC TYPE=TEXT SIZE=7 VALUE="$inc"></TD></TR></TABLE>
EOF
    }
    else {
        print <<"EOF";
</TD></TR>
<TR><TD VALIGN=TOP><B><font FACE=Arial>Your Handle/Alias:<BR></B>Used to track your post</TD><TD><INPUT NAME=ALIAS TYPE=TEXT SIZE=30 MAXLENGTH=30>
<TR><TD VALIGN=TOP><B>Your E-Mail Address:<BR></B>Must be valid</TD><TD><INPUT NAME=EMAIL TYPE=TEXT SIZE=30>
<TR><TD VALIGN=TOP><B>Your Starting Bid:</B></TD><TD>\$<INPUT NAME=BID TYPE=TEXT SIZE=7 VALUE=0>
<TR><TD VALIGN=TOP><B>Your Reserve Price:<BR></B>You are not obligated to sell below this price.  Leave blank if none.</TD><TD>\$<INPUT NAME=RESERVE TYPE=TEXT SIZE=7 VALUE=0>
<TR><TD VALIGN=TOP><B>Bid Increment:</B></TD><TD>\$<INPUT NAME=INC TYPE=TEXT SIZE=7 VALUE="$inc">
<TR><TD VALIGN=TOP><B>Contact Information:<BR></B>Will be given out only to the buyer</TD><TD>
<TT>Full Name: </TT><BR><INPUT NAME=ADDRESS1 TYPE=TEXT SIZE=30><BR>
<TT>Street Address: </TT><BR><INPUT NAME=ADDRESS2 TYPE=TEXT SIZE=30><BR>
<TT>City, State, ZIP: </TT><BR><INPUT NAME=ADDRESS3 TYPE=TEXT SIZE=30></TD></TR></TABLE>
EOF
    }
    print <<"EOF";
<P><CENTER><INPUT TYPE=SUBMIT VALUE=Preview></CENTER></font>
EOF
}

#-#############################################
# Sub: Process New Item
# This processes new item to be put up for
# sale from a posted form

sub procnew {
    my ($password, @userbids);
    if ($config{'regdir'} ne "") {
        &oops('Your alias could not be found!') unless ($password, $form{'EMAIL'}, $form{'ADDRESS1'}, $form{'ADDRESS2'}, $form{'ADDRESS3'}, @userbids) = &read_reg_file($form{'ALIAS'});
        $form{'ALIAS'} = ucfirst(lc($form{'ALIAS'}));
        &oops('Your password is incorrect.') unless ((lc $password) eq (lc $form{'PASSWORD'}));
    }
    &oops('You must have an item title that is up to 50 characters.') unless ($form{'TITLE'} && (length($form{'TITLE'}) < 51));
    $form{'TITLE'} =~ s/\</\&lt\;/g;
    $form{'TITLE'} =~ s/\>/\&gt\;/g;
        &oops('You must select a valid category.') unless (-d "$config{'basepath'}$form{'CATEGORY'}" and $category{$form{'CATEGORY'}});
    $form{'IMAGE'} = "" if ($form{'IMAGE'} eq "http://");
        $form{'MYSITE'} = "" if ($form{'MYSITE'} eq "http://");
    &oops('You must enter the number of days your auction should run, from 1 to 14.') unless (($form{'DAYS'} > 0) and ($form{'DAYS'} < 15));
    &oops('You must enter an item description.') unless ($form{'DESC'});
    &oops('You must enter an alias to track your item.') unless ($form{'ALIAS'});
    &oops('You must enter a valid e-mail address.') unless ($form{'EMAIL'} =~ /^.+\@.+\..+$/);
    &oops('You must enter a valid starting bid.') unless ($form{'BID'} =~ /^(\d+\.?\d*|\.\d+)$/);
    &oops('You must enter a valid bid increment.') unless (($form{'INC'} =~ /^(\d+\.?\d*|\.\d+)$/) and ($form{'INC'} >= .01));
    $form{'INC'} = &parsebid($form{'INC'});
    $form{'RESERVE'} = &parsebid($form{'RESERVE'});
    &oops('You must enter your full name.') unless ($form{'ADDRESS1'});
    &oops('You must enter your street address.') unless ($form{'ADDRESS2'});
    &oops('You must enter your city, state, and zip code.') unless ($form{'ADDRESS3'});
    my $item_number = ($form{'DAYS'} * 86400 + time);
    $item_number = ($form{'DAYS'} * 86400 + time) until (!(-f "$config{'basepath'}$form{'CATEGORY'}/$item_number.dat"));
    if ($form{'FROMPREVIEW'}) {
        my $key;
        foreach $key (keys %form) {
            $form{$key} =~ s/\[greaterthansign\]/\>/gs;
            $form{$key} =~ s/\[lessthansign\]/\</gs;
            $form{$key} =~ s/\[quotes\]/\"/gs;
        }
        &oops('We are unable to post your item.  This could be a write permissions problem.') unless (open (NEW, ">$config{'basepath'}$form{'CATEGORY'}/$item_number.dat"));
        print NEW "$form{'TITLE'}\n$form{'MYSITE'}\n$form{'PAYPAL'}\n$form{'BILLPOINT'}\n$form{'YAHOO'}\n$form{'RESERVE'}\n$form{'INC'}\n$form{'DESC'}\n$form{'IMAGE'}\n$form{'ITMCOND'}\n$form{'SHIP'}\n$form{'PAY0'}\n$form{'PAY1'}\n$form{'PAY2'}\n$form{'PAY3'}\n$form{'PAY4'}\n$form{'PAY5'}\n$form{'PAY6'}\n$form{'PAY7'}\n$form{'PAY8'}\n$form{'BUYIT'}\n$form{'DAYS'}\n$form{'BID'}\n$form{'CATEGORY'}\n$form{'ALIAS'}\[\]$form{'EMAIL'}\[\]".&parsebid($form{'BID'})."\[\]".time."\[\]$form{'ADDRESS1'}\[\]$form{'ADDRESS2'}\[\]$form{'ADDRESS3'}";
        close NEW;
        if ($config{'regdir'} ne "") {
            &oops('We could not open the registration file.  This could be a server write issue.') unless (open(REGFILE, ">>$config{'basepath'}$config{'regdir'}/$form{'ALIAS'}.dat"));
            print REGFILE "\n$form{'CATEGORY'}$item_number";
            close REGFILE;
        }
        print "<B><center>$form{'TITLE'} was posted under $category{$form{'CATEGORY'}}...</B>.<BR>You may want to go to <A HREF=\"$ENV{'SCRIPT_NAME'}\?category=$form{'CATEGORY'}\&item=$item_number\">the item</A> to confirm placement.</center>\n\n";
                # COMMENT THIS LINE OUT BELOW IF YOU DO NOT WISH TO BE NOTIFIED OF NEW POSTED ITEMS
                &sendemail($config{'admin_address'}, $config{'admin_address'}, 'New Item Listed', "NOTE TO THE ADMINISTRATOR : New Item Posting on $config{'sitename'}!\r\n\r\nALIAS: $form{'ALIAS'}\r\n\r\nITEM:$form{'TITLE'} was posted under $category{$form{'CATEGORY'}}\r\n\r\nClick on $config{'scripturl'}$ENV{'SCRIPT_NAME'}\?category=$form{'CATEGORY'}\&item=$item_number to view the item");
    }
    else {
        my $nowtime = localtime(time);
        my $closetime = localtime($item_number);
        print "<div align=center><table width=80\% border=0><tr><td bgcolor=$config{'colortablehead'}><font color=$config{'colortablebody'}>";
        print "<H2>$form{'TITLE'} PREVIEW</H2></font></td></tr></table><HR><FONT SIZE=+1 color=$config{'colortablehead'}><B>Information</B></FONT><HR>\n";
        print "<div align=center><center><TABLE WIDTH=80\%><TR>";
        print "<TD BGCOLOR=$config{'colortablebody'}><IMG SRC=$form{'IMAGE'}></TD>" if ($form{'IMAGE'});
        print "<TD><TABLE BORDER=0><TR><TD BGCOLOR=$config{'colortablehead'}><font color=$config{'colortablebody'}><B>$form{'TITLE'}</B></font></TD></TR><TR><TD BGCOLOR=$config{'colortablebody'}><B>Category:</B> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'CATEGORY'}>$category{$form{'CATEGORY'}}</A></TD></TR><TR><TD BGCOLOR=$config{'colortablebody'}><B>Offered By:</B> <A HREF=mailto:$form{'EMAIL'}>$form{'ALIAS'}</A></TR></TD>\n";
                print "<TR><TD><A HREF=$form{'MYSITE'}><B>Visit My Site</A></TR></TD>" if ($form{'MYSITE'});
                print "<TR><TD><A HREF=$form{'PAYPAL'}><B>WINNING BIDDER PAY NOW!</A></TR></TD>" if ($form{'PAYPAL'});
                print "<TR><TD><A HREF=$form{'BILLPOINT'}><B>REQUEST A BILLPOINT INVOICE</A></TR></TD>" if ($form{'BILLPOINT'});
                print "<TR><TD><A HREF=$form{'YAHOO'}><B>REQUEST A YAHOO INVOICE</A></TR></TD>" if ($form{'YAHOO'});
                print "<TR><TD BGCOLOR=$config{'colortablebody'}><B>Current Time:</B> $nowtime</TD></TR><TR><TD BGCOLOR=$config{'colortablebody'}><B>Closes:</B> $closetime<BR><FONT SIZE=-2>Or $config{'aftermin'} minutes after last bid...</FONT></TD></TR><TR><TD BGCOLOR=$config{'colortablebody'}><B>Number of Bids:</B> 0</TD></TR><TR><TD BGCOLOR=$config{'colortablebody'}><B>Last Bid:</B> \$$form{'BID'}</TD></TR></TABLE></TD></TR></TABLE>\n";
        print "<HR><FONT SIZE=+1 color=$config{'colortablehead'}><B>Description</B></FONT><HR>$form{'DESC'}</FONT></FONT></B></I></U></H1></H2></H3></H4></H5>";
        print "<HR><B><FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>If this looks good, hit <INPUT TYPE=SUBMIT VALUE=\"Post Item\">, else hit the back button on your browser to edit the item.<BR><BR><font color=red>NOTE THIS IS ONLY A PREVIEW IT DOES NOT DISPLAY HOW THE PAGE WILL LOOK</font><INPUT TYPE=HIDDEN NAME=FROMPREVIEW VALUE=1></B>\n";
        my $key;
        foreach $key (keys %form) {
            $form{$key} =~ s/\>/\[greaterthansign\]/gs;
            $form{$key} =~ s/\</\[lessthansign\]/gs;
            $form{$key} =~ s/\"/\[quotes\]/gs;
            print "<INPUT TYPE=hidden NAME=\"$key\" VALUE=\"$form{$key}\">\n";
        }
        print "</FORM>\n";
    }
}

#-#############################################
# Sub: Process Bid
# This processes new bids from a posted form

sub procbid {
    my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = &read_item_file($form{'CATEGORY'},$form{'ITEM'}); # Info on Item
        my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[0]);                          # Info on Poster
        &oops('You cannot bid on items you posted.') if ((lc $form{'ALIAS'}) eq (lc $alias));                 # Same Person?
        my ($password, @userbids);
    if ($config{'regdir'} ne "") {
        &oops('Your alias could not be found!') unless ($password, $form{'EMAIL'}, $form{'ADDRESS1'}, $form{'ADDRESS2'}, $form{'ADDRESS3'}, @userbids) = &read_reg_file($form{'ALIAS'});
        $form{'ALIAS'} = ucfirst(lc($form{'ALIAS'}));
        &oops('Your password is incorrect.') unless ((lc $password) eq (lc $form{'PASSWORD'}));
    }
    &oops('You must enter an alias to track your item.') unless ($form{'ALIAS'});
    &oops('You must enter a valid e-mail address.') unless ($form{'EMAIL'} =~ /^.+\@.+\..+$/);
    &oops('You must enter a valid bid amount.') unless ($form{'BID'} =~ /^(\d+\.?\d*|\.\d+)$/);
    $form{'BID'} = &parsebid($form{'BID'});
    &oops('You must enter your full name.') unless ($form{'ADDRESS1'});
    &oops('You must enter your street address.') unless ($form{'ADDRESS2'});
    &oops('You must enter you city, state, and zip.') unless ($form{'ADDRESS3'});
    my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = &read_item_file($form{'CATEGORY'},$form{'ITEM'});
    &oops('The item number you entered cannot be found.  Maybe it has closed or it was moved since you last loaded the page.') if $title eq '';
    my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]);
    if ((time <= $form{'ITEM'}) or (time <= (60 * $config{'aftermin'} + $time))) {
        &oops('Your bid is too low.  Sorry.') if ($form{'BID'} < ($bid+$inc) and ($#bids)) or ($form{'BID'} < $bid);
        &oops('We are unable to append your bid to the auction item.  It appears to be a file write problem.') unless (open NEW, ">>$config{'basepath'}$form{'CATEGORY'}/$form{'ITEM'}.dat");
        if ($config{'flock'}) {
            flock(NEW, 2);
            seek(NEW, 0, 2);
        }
        print NEW "\n$form{'ALIAS'}\[\]$form{'EMAIL'}\[\]$form{'BID'}\[\]".time."\[\]$form{'ADDRESS1'}\[\]$form{'ADDRESS2'}\[\]$form{'ADDRESS3'}";
        close NEW;
        print "<font face=Arial><center><B>$form{'ALIAS'}, your bid has been placed on item number $form{'ITEM'} for \$$form{'BID'} on ".scalar(localtime(time)).".</B><BR>You may want to print this notice as confirmation of your bid.<P>Go <A HREF=\"$ENV{'SCRIPT_NAME'}\?category=$form{'CATEGORY'}\&item=$form{'ITEM'}\">back to the item</A></font></center>\n";
        my $flag=0;
        my $userbid;
        foreach $userbid (@userbids) {
            $flag=1 if ("$form{'CATEGORY'}$form{'ITEM'}" eq $userbid);
        }
        if ($flag==0 && $config{'regdir'} ne "") {
            &oops('We could not open the registration file.  This could be a server write issue.') unless (open(REGFILE, ">>$config{'basepath'}$config{'regdir'}/$form{'ALIAS'}.dat"));
            print REGFILE "\n$form{'CATEGORY'}$form{'ITEM'}";
            close REGFILE;
        }
        &sendemail($email, $config{'admin_address'}, 'You\'ve been outbid!', "You have been outbid on $title\!  If you want to place a higher bid, please visit\:\r\n\r\n\thttp://$config{'scripturl'}$ENV{'SCRIPT_NAME'}\?category=$form{'CATEGORY'}\&item=$form{'ITEM'}\r\n\r\nThe current high bid is \$$form{'BID'}.") if ($config{'scripturl'} and $#bids);
                # NEXT TWO LINES BELOW SENDS THE SELLER AN EMAIL WHEN A BID HAS BEEN MADE
                my ($alias, $email, $bid, $time, $add1, $add2, $add3, $comment) = &read_bid($bids[0]);
                &sendemail($email, $config{'admin_address'}, "You received a bid on $title!", "$form{'ALIAS'} placed a bid on your item\!\r\n\r\n Item: $form{'ITEM'}\r\n\r\nThe current high bid is \$$form{'BID'}.\r\n\r\To see your auction go to http://$config{'scripturl'}$ENV{'SCRIPT_NAME'}\?category=$form{'CATEGORY'}\&item=$form{'ITEM'}") if ($config{'scripturl'} and $#bids);
    }
    else {
        print "<font face=Arial><center>Item number $form{'ITEM'} in category $form{'CATEGORY'} is now closed!<BR>Sorry...</font></center>\n";
    }
}

#-#############################################
# Sub: Process Search
# This displays search results

sub procsearch {
    print "<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablehead'}><font color=$config{'colortablebody'}>";
    print "<font face=Arial><I><B><center>Search Results - $form{'searchstring'}</I></B></center></font>\n";
    print "</font></td></tr></table>";
    print "<TABLE BORDER=0 WIDTH=80\%>\n";
    print "<TR><font FACE=Arial><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font color=$config{'colortablebody'}><font FACE=Arial><small><B>Number</B></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font color=$config{'colortablebody'}><B><font FACE=Arial><small>Item</small></B></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font color=$config{'colortablebody'}><font FACE=Arial><B><small>Closes</small></B></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font color=$config{'colortablebody'}><font FACE=Arial><B><small>Num Bids</small></B></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font color=$config{'colortablebody'}><font FACE=Arial><B><small>High Bid</small></B></font></TD></TR>\n";
    my $key;
    foreach $key (sort keys %category) {
        opendir THEDIR, "$config{'basepath'}$key" or &oops("Category directory $key could not be opened.");
        my @allfiles = grep -T, map "$config{'basepath'}$key/$_", sort { int($a) <=> int($b) } (readdir THEDIR);
        closedir THEDIR;
        my $file;
        foreach $file (@allfiles) {
            $file =~ s/^$config{'basepath'}$key\///;
            $file =~ s/\.dat$//;
            my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = &read_item_file($key,$file);
            if ($title ne '') {
                my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]);
                my @closetime = localtime($file);
                $closetime[4]++;
                                my $timeremain = time_remain($file);
                if($form{'searchtype'} eq 'keyword' and ($title =~ /$form{'searchstring'}/i) || ($desc =~ /$form{'searchstring'}/i)) {
                    print "<TR><TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file><font face=Arial><small>$file</small></A></TD>";
                                        print "<TD BGCOLOR=$config{'colortablebody'}><font FACE=Arial><small><A HREF=$ENV{'SCRIPT_NAME'}\?category=$key\&item=$file>$title</A>";
                    print " <img src=$config{'scripturl'}/cam2.gif>" if ($image);
                                        print " <img src=$config{'scripturl'}/buyit.gif>" if ($buyit);
                    print "</TD><TD BGCOLOR=$config{'colortablebody'}><font FACE=Arial><small>$timeremain</TD><TD BGCOLOR=$config{'colortablebody'}><small>$#bids</TD><TD BGCOLOR=$config{'colortablebody'}>\$$bid</TD></TR>\n";
                }
                elsif($form{'searchtype'} eq 'username' and join(' ',@bids) =~ /$form{'searchstring'}/i) {
                    print "<TR><TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file><font face=Arial><small>$file</small></A></TD>";
                                        print "<TD BGCOLOR=$config{'colortablebody'}><font FACE=Arial><A HREF=$ENV{'SCRIPT_NAME'}\?category=$key\&item=$file><small>$title</small></A>";
                    print " <font FACE=Arial><img src=$config{'scripturl'}/cam2.gif>" if ($image);
                                        print " <img src=$config{'scripturl'}/buyit.gif>" if ($buyit);
                                        print " <img src=$config{'scripturl'}/paypalicon.gif>" if ($paypal);
                                        print " <img src=$config{'scripturl'}/billpointicon.gif>" if ($billpoint);
                                        print " <img src=$config{'scripturl'}/yahooicon.gif>" if ($yahoo);
                    print "</TD><TD BGCOLOR=$config{'colortablebody'}><font FACE=Arial><center>$timeremain</TD><TD BGCOLOR=$config{'colortablebody'}><center>$#bids</TD><TD BGCOLOR=$config{'colortablebody'}><center>\$$bid</TD></TR></small></center>\n";
                }
            }
        }
    }
    print "</TABLE>\n";
}

#-#############################################
# Sub: Change Registration
# This allows a user to change information

sub creg {
    print <<"EOF";
<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>
<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablehead'}><font color=$config{'colortablebody'}>
<font face=Arial><I><B><center>Change Street Address and/or Password</I></B></center></font>
</font></td></tr></table>
<div align=center><center><TABLE WIDTH=80% BORDER=0 BGCOLOR=$config{'colortablebody'}>
<INPUT TYPE=HIDDEN NAME=action VALUE=proccreg>
<TR><TD COLSPAN=2 VALIGN=TOP> <font FACE=Arial>This form will allow you to change your
street address and/or password.
</TD></TR>
<TR><TD VALIGN=TOP><B>Your Handle/Alias:<BR></B>Required for verification</TD><TD><INPUT NAME=ALIAS TYPE=TEXT SIZE=30 MAXLENGTH=30>
<TR><TD VALIGN=TOP><B>Your Current Password:<BR></B>Required for verification</TD><TD><INPUT NAME=OLDPASS TYPE=PASSWORD SIZE=30>
<TR><TD VALIGN=TOP><B>Your New Password:<BR></B>Leave blank if unchanged</TD><TD><INPUT NAME=NEWPASS1 TYPE=PASSWORD SIZE=30>
<TR><TD VALIGN=TOP><B>Your New Password Again:<BR></B>Leave blank if unchanged</TD><TD><INPUT NAME=NEWPASS2 TYPE=PASSWORD SIZE=30>
<TR><TD VALIGN=TOP><B>New E-Mail Adress:<BR></B>Leave blank if unchanged</TD><TD><INPUT NAME=EMAIL TYPE=TEXT SIZE=30>
<TR><TD VALIGN=TOP><B>Contact Information:<BR></B>Leave blank if unchanged</TD><TD>
<TT>Full Name: </TT><BR><INPUT NAME=ADDRESS1 TYPE=TEXT SIZE=30><BR>
<TT>Street Address: </TT><BR><INPUT NAME=ADDRESS2 TYPE=TEXT SIZE=30><BR>
<TT>City, State, ZIP: </TT><BR><INPUT NAME=ADDRESS3 TYPE=TEXT SIZE=30></TD></TR></TABLE>
<CENTER><INPUT TYPE=SUBMIT VALUE="Change Registration"></CENTER>
EOF
}

#-#############################################
# Sub: Process Changed Registration
# This modifies an account

sub proccreg {
    my ($password,$email,$add1,$add2,$add3,@past_bids);
    if ($config{'regdir'}) {
        &oops('You must enter your alias so we can validate your account.') unless ($form{'ALIAS'});
        &oops('You must enter your old password so we can validate your account.') unless ($form{'OLDPASS'});
        if ($form{'EMAIL'}) {
                                &oops('You must enter a valid e-mail address.') unless ($form{'EMAIL'} =~ /^.+\@.+\..+$/);

                }
                if ($form{'ADDRESS1'}) {
            &oops('You must enter all of your contact information.  Please enter your street address.') unless ($form{'ADDRESS2'});
            &oops('You must enter all of your contact information.  Please enter your city, state, and zip.') unless ($form{'ADDRESS3'});
        }
        if ($form{'NEWPASS1'}) {
            &oops('Your new passwords do not match.') unless ($form{'NEWPASS2'} eq $form{'NEWPASS1'});
        }
        if (($password,$email,$add1,$add2,$add3,@past_bids) = &read_reg_file($form{'ALIAS'})) {
            $form{'ALIAS'} = ucfirst(lc($form{'ALIAS'}));
            &oops('Your old password does not match up.') unless ((lc $password) eq (lc $form{'OLDPASS'}));
            $form{'NEWPASS1'} = $password if !($form{'NEWPASS1'});
                        $form{'EMAIL'} = $add1 if !($form{'EMAIL'});
            $form{'ADDRESS1'} = $add1 if !($form{'ADDRESS1'});
            $form{'ADDRESS2'} = $add2 if !($form{'ADDRESS2'});
            $form{'ADDRESS3'} = $add3 if !($form{'ADDRESS3'});
            &oops('We cannot open your account.  This could be a server data write issue.') unless (open NEWREG, ">$config{'basepath'}$config{'regdir'}/$form{'ALIAS'}.dat");
            print NEWREG "$form{'NEWPASS1'}\n$email\n$form{'ADDRESS1'}\n$form{'ADDRESS2'}\n$form{'ADDRESS3'}";
            my $bid;
            foreach $bid (@past_bids) {
                print NEWREG "\n$bid";
            }
            close NEWREG;
            print "<font face=Arial><center>$form{'ALIAS'}, your information has been successfully changed.</font></center>\n";
                        &sendemail($config{'admin_address'}, $config{'admin_address'}, ' User changed Registration', "NOTE TO THE ADMINISTRATOR : A User changed his Registration \n Alias: $form{'ALIAS'}\n New E-Mail: $form{'EMAIL'}\n$form{'ADDRESS1'}\n$form{'ADDRESS2'}\n$form{'ADDRESS3'}\n Password:$form{'NEWPASS1'}\n" );
        }
        else {
            print "<font face=Arial><center>Sorry...  That Username is not valid.  If you do not have an alias (or cannot remember it) you should create a <A HREF=$ENV{'SCRIPT_NAME'}?action=reg>new account</A>.</font></center>\n";
        }
    }
    else {
        print "<font face=Arial><center>User Registration is Not Implemented on This Server!  The System Administrator Did Not Specify a Registration Directory...</font></center>\n";
    }
}

#-#############################################
# Sub: New Registration
# This creates a form for registration

sub reg {
    print <<"EOF";
<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>
<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablehead'}><font color=$config{'colortablebody'}>
<font face=Arial><I><B><center>New User Registration</I></B></center></font>
</font></td></tr></table>
<div align=center><center><TABLE WIDTH=80% BORDER=0 BGCOLOR=$config{'colortablebody'}>
<INPUT TYPE=HIDDEN NAME=action VALUE=procreg>
<TR><TD COLSPAN=2 VALIGN=TOP><font FACE=Arial>This form will allow you to register to buy or sell
auction items.  You must enter accurate data, and your new password will be e-mailed
to you.  Please be patient after hitting the submit button.  Registration may take
a few seconds.</TD></TR>
<TR><TD VALIGN=TOP><B>Your Handle/Alias:<BR></B>Used to track your post</TD><TD><INPUT NAME=ALIAS TYPE=TEXT SIZE=30 MAXLENGTH=30>
<TR><TD VALIGN=TOP><B>Your Password   :<BR></B></TD><TD><INPUT NAME=PASSWD TYPE=PASSWORD SIZE=30 MAXLENGTH=30></TD></TR>
<TR><TD VALIGN=TOP><B>Confirm Password:<BR></B></TD><TD><INPUT NAME=CONPASS TYPE=PASSWORD SIZE=30 MAXLENGTH=30></TD></TR>
<TR><TD VALIGN=TOP><B>Your E-Mail Address:<BR></B>Must be valid</TD><TD><INPUT NAME=EMAIL TYPE=TEXT SIZE=30><BR>This email address must not be from a free email service.
<TR><TD VALIGN=TOP><B>Contact Information:<BR></B>Will be given out only to the buyer or seller</TD><TD>
<TT>Full Name: </TT><BR><INPUT NAME=ADDRESS1 TYPE=TEXT SIZE=30><BR>
<TT>Street Address: </TT><BR><INPUT NAME=ADDRESS2 TYPE=TEXT SIZE=30><BR>
<TT>City, State, ZIP: </TT><BR><INPUT NAME=ADDRESS3 TYPE=TEXT SIZE=30></TD></TR></TABLE>
<p align=center><font face=Arial><big><strong>User Agreement between YOU and
$config{'sitename'}</strong></big></font></p>
<div align="center"><center>
<table border="0" width="80%">
  <tr>
    <td width="100%" bgcolor="$config{'colortablehead'}"><p align="center"><small><font
    face="Arial" color=$config{'colortablebody'}><b>THE FOLLOWING IS THE USER AGREEMENT AS PRESENTED BY $config{'sitename'}.
    YOU MUST AGREE TO THESE TERMS BEFORE YOU WILL BE ABLE TO POST ITEMS, OR BID ON THEM. IF
    YOU DO NOT ACCEPT THESE TERMS, PLEASE, DO NOT USE OUR SERVICES. ONCE YOU CLICK THE
    REGISTER ME BUTTON BELOW, YOU AGREE TO THESE SAID TERMS OF THE USER AGREEMENT BELOW.</b></font></small></p>
    <p align="left"><small><font face="Arial" color=$config{'colortablebody'}><b>Article 1.</b> Eligibility of membership -
    This auction site is only available to people who are legally able to form binding
    contracts with you and the seller/buyer of an auction item. People who are of under age of
    18 are not eligible for membership due to security precautions that can result as of those
    members. If you do not meet these requirements, you are not eligible to use these auction
    services.</font></small></p>
    <p align="left"><small><font face="Arial" color=$config{'colortablebody'}><b>Article 2.</b> $config{'sitename'} is only
    providing auction services to people interested in selling and buying
    merchandise via Internet auction. We do not have control over the items that are posted in
    the auction site, and cannot guarantee the authenticity and quality of a said product. We
    are not responsible for the actions the sellers takes, before, during, and after the
    auction, typographical errors, misprints, loss of merchandise/money, damage or failure of
    equipment, due to your visit to this auction site. Use of this site is at your own risk,
    and content is presented 'As-Is'.</font></small></p>
    <p align="left"><small><font face="Arial" color=$config{'colortablebody'}><b>Article 3.</b> Bidding and Selling - As a
    user, you may bid and/or sell merchandise over $config{'sitename'}. As
    a bidder, you know that placing a bid is a binding contract with you and the seller, and
    the bid cannot be retracted unless due to fault by the seller of typographical error, or
    other error, due to human error on the seller's part. Once you place a bid, and if you
    win, you will be obligated to buy the product at the said price you indicated as your bid.
    Placing a bid on this auction site, and winning, then not paying for the product is
    illegal in most states, and prosecution can result to you. As a seller, the item that you
    place up for bids must be real. Pre-sales are accepted. Once a bid has been placed for
    your item, you are being placed in a binding contract with the potential buyer of the
    product, if that bid shall be the highest bid. Once the auction is over, if over reserve
    price, you are obligated to sell to the potential buyer which is the highest bidder in
    your auction. If, reserve price was not met, you are not obligated in any way to sell this
    item at all. As a seller, you are not in any way to bid on your own items. If reported,
    your auction will be deleted.</font></small></p>
    <p align="left"><small><font face="Arial" color=$config{'colortablebody'}><b>Article 4.</b> Posting Items - As a user, you
    are welcome to post items up for sale in the $config{'sitename'}. We
    do have restrictions on what items you may sell, and what you may not sell. You may not
    sell illegal merchandise, including pirated software and music, firearms, adult videos, or
    anything that is affiliated with pornography, etc. Items that are up to bids are subject
    to review by the staff of $config{'sitename'}, and my be removed without prior notice, if
    in violation with the User Agreement.</font></small></p>
    <p align="left"><small><font face="Arial" color=$config{'colortablebody'}><b>Article 5.</b> Charges - Posting an item up
    for bid, bidding on an item, and registering are free on this server. Do not abuse this
    privilege.</font></small></p>
    <p align="left"><small><font face="Arial" color=$config{'colortablebody'}><b>Article 6.</b> Privacy - We gather your
    information so that other people will have it on hand when they win your auction, or you
    win their auction. Personal information is not sold, rented, without your permission.
    Personal information sent to a user regarding a product bought or sold on the auction is
    not to be used for any other purpose, except for communication with the auction item.</font></small></p>
    <p align="left"><small><font face="Arial" color=$config{'colortablebody'}><b>Article 7.</b> Warranty - $config{'sitename'}
    provide this web site in an 'as-is' condition, without a warranty or
    condition. $config{'sitename'} is not liable for any damages resulting in an auction, or
    your visit to the site.</font></small></td>
  </tr>
</table>
</center></div>
<p align="center"><font face="Arial" COLOR="red"><b><small>By Pressing Register Me You
Agree to these terms listed above.</small></b></font></p>
<CENTER><INPUT TYPE=SUBMIT VALUE="Register Me"></CENTER>
EOF
}

#-#############################################
# Sub: Process Registration
# This adds new accounts to the database

sub procreg {
    if ($config{'regdir'}) {
        umask(000);  # UNIX file permission junk
        mkdir("$config{'basepath'}$config{'regdir'}", 0777) unless (-d "$config{'basepath'}$config{'regdir'}");
        mkdir("$config{'basepath'}$config{'newestmember'}", 0777) unless (-d "$config{'basepath'}$config{'newestmember'}");
                &oops('You must enter an alias that consists of alphanumeric characters.') if $form{'ALIAS'} =~ /\W/ or !($form{'ALIAS'});
        if ($form{'PASSWD'}) {
                        &oops('Your passwords do not match.') unless ($form{'CONPASS'} eq $form{'PASSWD'});
                }
            else {
                  &oops('You must enter your password.')
            }
                &oops('You must enter a valid e-mail address.') unless ($form{'EMAIL'} =~ /^.+\@.+\..+$/);
        &oops('You must enter your full name so buyers or sellers may contact you.') unless ($form{'ADDRESS1'});
        &oops('You must enter a valid street address so buyers or sellers can contact you.') unless ($form{'ADDRESS2'});
        &oops('You must enter a valid city, state, and zip code so buyers or sellers can contact you.') unless ($form{'ADDRESS3'});
        $form{'ALIAS'} = ucfirst(lc($form{'ALIAS'}));
        if (!(-f "$config{'basepath'}$config{'regdir'}/$form{'ALIAS'}.dat")) {
            &oops('We were unable to write to the user directory.') unless (open NEWREG, ">$config{'basepath'}$config{'regdir'}/$form{'ALIAS'}.dat");

            print NEWREG "$form{'PASSWD'}\n$form{'EMAIL'}\n$form{'ADDRESS1'}\n$form{'ADDRESS2'}\n$form{'ADDRESS3'}";
            close NEWREG;
                        &oops('We were unable to write to the user directory.') unless (open NEWMEMBER, ">$config{'basepath'}$config{'newestmember'}/newmember.dat");
                        print NEWMEMBER "$form{'ALIAS'}\n$form{'EMAIL'}";
                        close NEWMEMBER;
                        print "<P><center><font face=Arial>$form{'ALIAS'}, Thank you for registering with $config{'sitename'} Auction.  You will recieve an email to $form{'EMAIL'} in a few minutes.  It will contain your password and username for a reminder incase you forget your information. Your password is: $form{'PASSWD'}</center></font>\n";
                        &sendemail($form{'EMAIL'}, $config{'admin_address'}, "$config{'sitename'} Info Reminder", "PLEASE DO NOT REPLY TO THIS E-MAIL.\r\n\r\nThank you for registering to use the online auctions at $config{'sitename'}!\r\n\r\nYour password is: $form{'PASSWD'}\r\nYour User Name (as you entered it) is: $form{'ALIAS'}\r\n\r\nThank you for visiting!");
        }
        else {
            print "<font face=Arial><center><BIG>Sorry...  that alias is taken.  Hit back to try again!</font></center></BIG>\n";
        }
    }
    else {
        print "<font face=Arial><center>User Registration is Not Implemented on This Server!  The System Administrator Did Not Specify a Registration Directory...</font></center>\n";
    }
}

#-#############################################
# Sub: Closed items 1
# This displays closed items

sub viewclosed1 {
    print <<"EOF";
<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>
<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablehead'}><font color=$config{'colortablebody'}>
<font face=Arial><I><B><center>My Auction</I></B></center></font>
</font></td></tr></table>
<div align=center><center><TABLE WIDTH=80% BORDER=0 BGCOLOR=$config{'colortablebody'}>
<INPUT TYPE=HIDDEN NAME=action VALUE=closed2>
<TR><TD COLSPAN=2 VALIGN=TOP> <font FACE=Arial>This form will allow you to view the
status and contact information for closed auction items you bid on or listed for auction.
</TD></TR>
<TR><TD VALIGN=TOP><B>Your Username:<BR></B>Required for verification</TD><TD><INPUT NAME=ALIAS TYPE=TEXT SIZE=30 MAXLENGTH=30>
<TR><TD VALIGN=TOP><B>Your Password:<BR></B>Required for verification</TD><TD><INPUT NAME=PASSWORD TYPE=PASSWORD SIZE=30>
</TD></TR></TABLE>
<CENTER><INPUT TYPE=SUBMIT VALUE="View Closed Items"></CENTER>
EOF
}

#-#############################################
# Sub: Closed items 2
# This displays closed items

sub viewclosed2 {
        &oops('Your alias could not be found!') unless my ($password,$email,$add1,$add2,$add3,@past_bids) = &read_reg_file($form{'ALIAS'});
        &oops('Your password is incorrect.') unless ((lc $password) eq (lc $form{'PASSWORD'}));
        &oops('PASSWORD') unless ((lc $password) eq (lc $form{'PASSWORD'}));
        print "<center>";
        print "<FORM METHOD=POST ACTION=\"$ENV{'SCRIPT_NAME'}\">\n";
        print "<INPUT TYPE=HIDDEN NAME=action VALUE=closed3><INPUT TYPE=HIDDEN NAME=ALIAS VALUE=\"$form{'ALIAS'}\">";
        print"<TABLE WIDTH=600 BORDER=1 BGCOLOR=$config{'colortablebody'}>\n";
        my $bid;
        foreach $bid (@past_bids) {
                if (-T "$config{'basepath'}$config{'closedir'}/$bid.dat") {
                        open THEFILE, "$config{'basepath'}$config{'closedir'}/$bid.dat";
                        my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, $days, $sbid, $category, @bids) = <THEFILE>;
                        close THEFILE;
                        chomp($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, $days, $sbid, $category, @bids);

                        print "<TR><TD width=50 align=center><input name=\"BIDTOVIEW\" type=\"radio\" value=\"$bid\"></TD><TD width=550>&nbsp;&nbsp; $bid: &nbsp;&nbsp;&nbsp;&nbsp; $title</TD></TR>\n";
                }
        }
        print "</TABLE><INPUT TYPE=SUBMIT VALUE=\"View My Status\"></FORM>\n";
}

#-#############################################
# Sub: Closed items 3
# This displays closed items

sub viewclosed3 {
    my ($alias, $email, $bid, $time, $add1, $add2, $add3);
    $form{'BIDTOVIEW'} =~ s/\W//g;
    open (THEFILE, "$config{'basepath'}$config{'closedir'}/$form{'BIDTOVIEW'}.dat") or &oops('We cannot open the item you are looking for.  This could be a server read issue.');
    my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = <THEFILE>;
    close THEFILE;
    chomp($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids);
    print "<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablehead'}><font color=$config{'colortablebody'}>";
    print "<font face=Arial><I><B><center>$title</I></B></center></font>\n";
    print "</font></td></tr></table>";
    print "<HR><FONT SIZE=+1 color=$config{'colortablehead'}><B>Description</B></FONT><HR>$desc</FONT></FONT></B></I></U></H1></H2></H3></H4></H5>";
    print "<HR><FONT SIZE=+1 color=$config{'colortablehead'}><B>Bid History</B></FONT><HR>\n";
    if ($#bids) {
        for (my $i=1; $i<scalar(@bids); $i++) {
            ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$i]);
            my $bidtime = localtime($time);
            print "<FONT SIZE=-1>$alias \($bidtime\) - \$$bid</FONT><BR>";
        }
    }
    else {
        print "<FONT SIZE=-1>No bids were placed...</FONT><BR>";
    }
    print "<P>Reserve was: \$$reserve<BR>\n";
    print "<HR><FONT SIZE=+1><B>Contact Information</B></FONT><HR>\n";
    if (ucfirst(lc($form{'ALIAS'})) eq (&read_bid($bids[0]))[0]) {
        print "You were the seller...<P>\n";
        if ($#bids) {
            ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]);
            print "<B>Buyer Information:</B><BR><I>Alias</I>: $alias<BR><I>E-Mail</I>: $email<BR><I>Address</I>: $add1<BR>$add2<BR>$add3<P><B>High Bid:</B> \$$bid\n";
            print "<P><B>Bidder Contact Info:</B><BR>\n";
            for (my $i=1; $i<scalar(@bids); $i++) {
                ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$i]);
                print "<FONT SIZE=-1>$alias - <A HREF=\"mailto:$email\">$email</A></FONT><BR>\n";
            }
        }
                print "<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>You may repost this item if you want to: <INPUT TYPE=SUBMIT VALUE=\"Repost\"><INPUT TYPE=HIDDEN NAME=action VALUE=\"repost\"><INPUT TYPE=HIDDEN NAME=REPOST VALUE=\"$form{'BIDTOVIEW'}\"></FORM>\n";
                                print "<br><br>\n";
                              print "<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>\n";
                              print "<center><TABLE WIDTH=80% cellpadding=4 cellspacing=1><tr><td align=center>\n";
                              print "<font size=\"+1\">Repost Your Item without changes</font></td></tr>\n";
                print "<tr><td>\n";
                print "<font size=\"-1\"><b>Enter Your Username and Password to Repost this item without changes</b></font>\n";
                print "<input type=hidden name=action value=\"procnew\">\n";
                print "<input type=hidden name=TITLE value=\"$title\">\n";
                print "<input type=hidden name=CATEGORY value=\"$category\">\n";
                print "<input type=hidden name=DAYS value=\"$days\">\n";
                print "<input type=hidden name=BID value=\"$sbid\">\n";
                print "<input type=hidden name=DESC value=\"$desc\">\n<br>\n";
                print "Username <input name=ALIAS type=text size=30 maxlength=30><br>\n";
                print "Password <input name=PASSWORD type=password size=30><br>\n";
                print "<input type=hidden NAME=RESERVE VALUE=$reserve>\n";
                print "<input type=hidden NAME=INC VALUE=$inc>\n";
                print "<CENTER><INPUT TYPE=SUBMIT VALUE=Preview></CENTER>\n";
                print "</td></tr></TABLE>\n";
                print "</form>\n";
    }
    elsif (ucfirst(lc($form{'ALIAS'})) eq (&read_bid($bids[$#bids]))[0]) {
        print "You were a high bidder...<P>\n";
        ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[0]);
        print "<B>Seller Information:</B><BR><I>Alias</I>: $alias<BR><I>E-Mail</I>: $email<BR><I>Address</I>: $add1<BR>$add2<BR>$add3<P>";
        ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]);
        print "<B>Your High Bid:</B> \$$bid<P>\n";
        print "<I>Remember, the seller is not required to sell unless your bid price was above the reserve price...</I>";
    }
    else {
        print "You were not a winner...  No further contact information is available.\n";
    }
}

#-#############################################
# Sub: Admin
# Allows the administrator to delete items.

sub admin {
        print <<"EOF";
<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>
<H2>Delete Items</H2>
<TABLE WIDTH=100% BORDER=1 BGCOLOR=$config{'colortablebody'}>
<INPUT TYPE=HIDDEN NAME=action VALUE=procadmin>
<TR><TD COLSPAN=2 VALIGN=TOP> This form will allow you to delete an item.  You will need the
administrator password that should be configured in the script.
</TD></TR>
<TR><TD VALIGN=TOP><B>Category:<BR></B>Select One</TD><TD><SELECT NAME=CATEGORY>
<OPTION SELECTED></OPTION>
EOF
        my $key;
        foreach $key (sort keys %category) {
                print "<OPTION VALUE=\"$key\">$category{$key}</OPTION>\n";
        }
        print <<"EOF";
</SELECT></TD></TR>
<TR><TD VALIGN=TOP><B>Item Number:<BR></B></TD><TD><INPUT NAME=ITEM TYPE=TEXT SIZE=30 MAXLENGTH=30>
<TR><TD VALIGN=TOP><B>Administrator Password:<BR></B>Required for verification</TD><TD><INPUT NAME=PASSWORD TYPE=PASSWORD SIZE=30>
</TD></TR></TABLE>
<CENTER><INPUT TYPE=SUBMIT VALUE="Delete Item"></CENTER>
EOF
}

#-#############################################
# Sub: Process Admin
# Allows the administrator to delete items.

sub procadmin {
        if (lc($form{'PASSWORD'}) eq lc($config{'adminpass'})) {
                &oops('Bad Item Category or Number!') unless &read_item_file($form{'CATEGORY'},$form{'ITEM'});
                if (unlink("$config{'basepath'}$form{'CATEGORY'}/$form{'ITEM'}.dat")) {
                        print "File Successfully Removed!\n";
                }
                else {
                        print "File Could Not Be Removed!\n";
                }
        }
        else {
                print "Sorry...  Incorrect administrator password for delete!\n";
        }
}

#-#############################################
# Sub: Close Auction
# This sets an item's status to closed.

sub closeit {
    my ($cat,$item) = @_;
    if ($cat ne $config{'closedir'}) {
        my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = &read_item_file($cat,$item);
        my @lastbid = &read_bid($bids[$#bids]);
        my @firstbid =  &read_bid($bids[0]);
        if ($#bids) {
            if ($lastbid[2] >= $reserve) {
                &sendemail($lastbid[1], $firstbid[1], "Auction Close: $title", "Congratulations!  You are the winner of auction number $item.\r\nYour winning bid was \$$lastbid[2].\r\n\r\nPlease contact the seller to make arrangements for payment and shipping:\r\n\r\n$firstbid[4]\r\n$firstbid[5]\r\n$firstbid[6]\r\n$firstbid[1]\r\n\r\nThanks for using $config{'sitename'}!");
            }
            else {
                &sendemail($lastbid[1], $firstbid[1], "Auction Close: $title", "Congratulations!  You were the high bidder on auction number $item.\r\nYour bid was \$$lastbid[2].\r\n\r\nUnfortunately, your bid did not meet the seller\'s reserve price...\r\n\r\nYou may still wish to contact the seller to negotiate a fair price:\r\n\r\n$firstbid[4]\r\n$firstbid[5]\r\n$firstbid[6]\r\n$firstbid[1]\r\n\r\nThanks for using $config{'sitename'}!");
            }
            &sendemail($firstbid[1], $lastbid[1], "Auction Close: $title", "Auction number $item is now closed.\r\nThe high bid was \$$lastbid[2] (your reserve was: \$$reserve).\r\n\r\nPlease contact the high bidder to make any necessary arrangements:\r\n\r\n$lastbid[4]\r\n$lastbid[5]\r\n$lastbid[6]\r\n$lastbid[1]\r\n\r\nThanks for using $config{'sitename'}!");
        }
        else {
            &sendemail($firstbid[1], $config{'admin_address'}, "Auction Close: $title", "Auction number $item is now closed.\r\nThere were no bids on your item.  You may repost your item by using the closed auction manager at http://$config{'scripturl'}$ENV{'SCRIPT_NAME'}.  Thanks for using $config{'sitename'}!");
        }
        if ($config{'closedir'}) {
            umask(000);  # UNIX file permission junk
            mkdir("$config{'basepath'}$config{'closedir'}", 0777) unless (-d "$config{'basepath'}$config{'closedir'}");
            print "Please notify the site admin that this item cannot be copied to the closed directory even though it is closed.\n" unless &movefile("$config{'basepath'}$cat/$item.dat", "$config{'basepath'}$config{'closedir'}/$cat$item.dat");
        }
        else {
            print "Please notify the site admin that this item cannot be removed even though it is closed.\n" unless unlink("$config{'basepath'}$cat/$item.dat");
        }
    }
}

#-#############################################
# SUB: Send E-mail
# This is a real quick-and-dirty mailer that
# should work on any platform.  It is my first
# attempt to work with sockets, so if anyone
# has any suggestions, let me know!
#
# Takes:
# (To, Subject, From, Message)

sub sendemail {
        my ($to,$from,$subject,$message) = @_;
        my $trash;
        if ($config{'mailhost'}) {
        eval('use IO::Socket; 1;') or &oops("IO::Socket could not be loaded by the script.  Please see the script documentation for details.  It looks like this server is using perl version $].  IO::Socket may not be included with versions of perl prior to 5.00404."); # don't cause errors on machines where IO::Socket is not available
                my $remote;
                $remote = IO::Socket::INET->new("$config{'mailhost'}:smtp(25)");
                $remote->autoflush();
                print $remote "HELO\r\n";
                $trash = <$remote>;
                print $remote "MAIL From:<$config{'admin_address'}>\r\n";
                $trash = <$remote>;
                print $remote "RCPT To:<$to>\r\n";
                $trash = <$remote>;
                print $remote "DATA\r\n";
                $trash = <$remote>;
                print $remote "From: <$from>\r\nSubject: $subject\r\n\r\n";
                print $remote $message;
                print $remote "\r\n.\r\n";
                $trash = <$remote>;
                print $remote "QUIT\r\n";
        }
        else {
                open MAIL, "|$config{'mailprog'}";
                print MAIL "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n\r\n$message\r\n\r\n";
                close MAIL;

#                open (MAIL, "|c:\\wsendmail\\wsendmail -CGI -s\"$subject\" -f$from $to");
                open (MAIL, "|c:\\wsendmail\\wsendmail -CGI -s\"$subject\" -f$from juanm\@wellsfargo.com");
                print MAIL "\r\n$message\r\n\r\n";
                close(MAIL);
        }
}

#-#############################################
# Sub: Get Form Data
# This gets data from a post.

sub get_form_data {
        my $temp;
        my $buffer;
        my @data;
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
        foreach $temp (split(/&|=/,$buffer)) {
                $temp =~ tr/+/ /;
                $temp =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
        $temp =~ s/[\r\n]/ /g;
                push @data, $temp;
        }
        foreach $temp (split(/&|=/,$ENV{'QUERY_STRING'})) {
                $temp =~ tr/+/ /;
                $temp =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
        $temp =~ s/[\r\n]/ /g;
                push @data, $temp;
        }
        return @data;
}

#-#############################################
# Sub: Random Password
# This generates psudo-random 8-letter
# passwords

sub randompass {
    srand(time ^ $$);
    my @passset = ('a'..'k', 'm'..'n', 'p'..'z', '2'..'9');
    my $randpass = "";
    for (my $i=0; $i<8; $i++) {
        $randpass .= $passset[int(rand($#passset + 1))];
    }
    return $randpass;
}

#-#############################################
# Sub: parse bid
# This formats a bid amount to look good...
# ie. $###.##

sub parsebid {
    $_[0] =~ s/\,//g;
    my @bidamt = split(/\./, $_[0]);
    $bidamt[0] = "0" if (!($bidamt[0]));
    $bidamt[0] = int($bidamt[0]);
    $bidamt[1] = substr($bidamt[1], 0, 2);
    $bidamt[1] = "00" if (length($bidamt[1]) == 0);
    $bidamt[1] = "$bidamt[1]0" if (length($bidamt[1]) == 1);
    return "$bidamt[0].$bidamt[1]";
}

#-#############################################
# Sub: Oops!
# This generates an error message and dies.

sub oops {
    print "<P><HR SIZE=1 NOSHADE><FONT COLOR=#FF0000><B>Error:</B></FONT><BR>$_[0]<P>Please hit the back browser on your browser to try again or contact <A HREF=\"mailto:$config{'admin_address'}\">the auction administrator</A> if you belive this to be a server problem.<HR SIZE=1 NOSHADE>\n";
    print $config{'footer'};
    die "Error: $_[0]\n";
}

#-#############################################
# Sub: Movefile(file1, file2)
# This moves a file.  Quick and dirty!

sub movefile {
    my ($firstfile, $secondfile) = @_;
    return 0 unless open(FIRSTFILE,$firstfile);
    my @lines=<FIRSTFILE>;
    close FIRSTFILE;
    return 0 unless open(SECONDFILE,">$secondfile");
    my $line;
    foreach $line (@lines) {
        print SECONDFILE $line;
    }
    close SECONDFILE;
    return 0 unless unlink($firstfile);
    return 1;
}

#-#############################################
# Sub: Read Reg File (alias)
# Reads a registration file

sub read_reg_file {
    my $alias = shift;
    return '' unless $alias;
    # verify the user exists
    &oops('Your alias may not contain any non-word characters.') if $alias =~ /\W/;
    $alias = ucfirst(lc($alias));
    return '' unless -r "$config{'basepath'}$config{'regdir'}/$alias.dat" and -T "$config{'basepath'}$config{'regdir'}/$alias.dat";
    open FILE, "$config{'basepath'}$config{'regdir'}/$alias.dat";
    my ($password,$email,$add1,$add2,$add3,@past_bids) = <FILE>;
    close FILE;
    chomp ($password,$email,$add1,$add2,$add3,@past_bids);
    return ($password,$email,$add1,$add2,$add3,@past_bids);
}

#-#############################################
# Sub: Read Item File (cat, item)
# Reads an item file

sub read_item_file {
    my ($cat, $item) = @_;
    # verify the category exists
    return '' unless ($cat) and ($item);
    &oops('The category may not contain any non-word characters.') if $cat =~ /\W/;
    return '' unless $category{$cat};
    # verify the item exists
    &oops('The item number may not contain any non-numeric characters.') if $item =~ /\D/;
    return '' unless (-T "$config{'basepath'}$cat/$item.dat") and (-R "$config{'basepath'}$cat/$item.dat");
    open FILE, "$config{'basepath'}$cat/$item.dat";
    my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = <FILE>;
    close FILE;
    chomp ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids);
    return ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids);
}

#-#############################################
# Sub: Read Bid Information (bid_string)
# Reads an item file

sub read_bid {
    my $bid_string = shift;
    my ($alias, $email, $bid, $time, $add1, $add2, $add3) = split(/\[\]/,$bid_string);
    return ($alias, $email, $bid, $time, $add1, $add2, $add3);
}

#################################################
# Sub: checkclosed
# Checks all of the items, and closes the ones whose ran out of time
# Add the second line in the sub routine:
#   sub dispcat {
#   &chkclose;

# Call it by adding &chkclose;
sub chkclose {
        my $cat;
        foreach $cat (keys %category) {
                opendir THEDIR, "$config{'basepath'}$cat" or next;
                my @allfiles = (readdir THEDIR);
                closedir THEDIR;
                my $file;
                foreach $file (@allfiles) {
                unless ($file eq "." || $file eq "..") {
                        $file =~ s/^$config{'basepath'}$form{'category'}\///;
                        $file =~ s/\.dat$//;
                        if (my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) =
                                &read_item_file($cat,$file)) {
                                my ($alias, $email, $bid, $time, $add1, $add2, $add3) =
                                        &read_bid($bids[$#bids]); # read the last bid
                                if ((time > int($file)) &&
                                        (time > (60 * $config{'aftermin'} + $time))) {
                                        &closeit($cat,$file);
                                        }
                                }
                        }
                }
        }
}

#-#############################################
# Sub: Buy It
# This begins the process of allowing items to be purchased

sub dispbuy {

        &oops("Item $form{'item'} could not be opened.") unless (my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = &read_item_file($form{'category'},$form{'item'}));
        my $nowtime = localtime(time);
        my $closetime = localtime($form{'item'});
        my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[0]); # read first bid
        my $nowtime = localtime;
        my $key;
        my $file;
        $buyit = &parsebid($buyit);
        print <<"EOF";
        <div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablehead'}><font color=$config{'colortablebody'}>
<font face=Arial><I><B><center>Buy It Now Rules and User Agreement</I></B></center></font>
</font></td></tr></table>
<div align=center><center><TABLE WIDTH=80% BORDER=0 BGCOLOR=$config{'colortablebody'}>
<TR><TD COLSPAN=2 VALIGN=TOP><font FACE=Arial>
<center>Current Time:$nowtime</center>
<P><B>By Using our Buy-It Now Feature You agree:<BR></b>
          <ul>
          <li>To Pay the Seller the full Amount of the Buy-It Now Price.</li><br>
          <li>You are positive you Want to purchase the item.</li><br>
          <li>You will respond to the Sellers Contact attempts.</li><br>
          <li>You are able to enter into a Binding legal Contract.</li><br>
          </ul>
          <FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>
         <INPUT TYPE=HIDDEN NAME=action VALUE=procbuy>
         <INPUT TYPE=HIDDEN NAME=ITEM VALUE=\"$form{'item'}\">
        <INPUT TYPE=HIDDEN NAME=CATEGORY VALUE=\"$form{'category'}\">
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Item Title:</b>&nbsp;&nbsp; $title<BR><BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Seller:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> $alias<BR>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><B><A HREF=$ENV{'SCRIPT_NAME'}?action=reg><font color=\"#FF0000\" size=\"-1\">Registration</A> is required!</font></B><BR>
        <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>Your Handle/Alias:&nbsp;</B> <INPUT NAME=ALIAS TYPE=TEXT SIZE=15 MAXLENGTH=30>
        <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>Your Password:&nbsp;</B> <INPUT NAME=PASSWORD TYPE=PASSWORD SIZE=15 MAXLENGTH=30>
        <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>Buy-It Now Price:&nbsp;</B> <B>\$$buyit</B><INPUT NAME=BID TYPE=HIDDEN SIZE=7 VALUE=\"$buyit\"><BR><BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE=SUBMIT VALUE=\"Buy-It Now\"></form>
</TD></TR></table>
EOF
}

#-#############################################
# Sub: Process Buy-It
# This processes Buy-It from a posted form

sub procbuy {
        my $cat;
        my ($password, @userbids);
        if ($config{'regdir'} ne "") {
                &oops('Your alias could not be found!') unless ($password, $form{'EMAIL'}, $form{'ADDRESS1'}, $form{'ADDRESS2'}, $form{'ADDRESS3'}, @userbids) = &read_reg_file($form{'ALIAS'});
                $form{'ALIAS'} = ucfirst(lc($form{'ALIAS'}));
                &oops('Your password is incorrect.') unless ((lc $password) eq (lc $form{'PASSWORD'}));
        }
        &oops('You must enter an alias to track your item.') unless ($form{'ALIAS'});
        &oops('You must enter a valid e-mail address.') unless ($form{'EMAIL'} =~ /^.+\@.+\..+$/);
        &oops('You must enter a valid bid amount.') unless ($form{'BID'} =~ /^(\d+\.?\d*|\.\d+)$/);
        $form{'BID'} = &parsebid($form{'BID'});
        &oops('You must enter your full name.') unless ($form{'ADDRESS1'});
        &oops('You must enter your street address.') unless ($form{'ADDRESS2'});
        &oops('You must enter you city, state, and zip.') unless ($form{'ADDRESS3'});
        &oops('The item number you entered cannot be found.  Maybe it has closed or it was moved since you last loaded the page.') unless my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = &read_item_file($form{'CATEGORY'},$form{'ITEM'});
        my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]);
        if ((time <= $form{'ITEM'}) or (time <= (60 * $config{'aftermin'} + $time))) {
                &oops('Your bid is too low.  Sorry.') if ($form{'BID'} < ($bid+$inc) and ($#bids)) or ($form{'BID'} < $bid);
                &oops('We are unable to append your bid to the auction item.  It appears to be a file write problem.') unless (open NEW, ">>$config{'basepath'}$form{'CATEGORY'}/$form{'ITEM'}.dat");
                if ($config{'flock'}) {
                        flock(NEW, 2);
                        seek(NEW, 0, 2);
                }

                print NEW "\n$form{'ALIAS'}\[\]$form{'EMAIL'}\[\]$form{'BID'}\[\]".time."\[\]$form{'ADDRESS1'}\[\]$form{'ADDRESS2'}\[\]$form{'ADDRESS3'}";
                close NEW;

                print "<center><B>$form{'ALIAS'},$form{'CATEGORY'}$form{'ITEM'} your have Purchased item number $form{'ITEM'} for \$$form{'BID'} on ".scalar(localtime(time)).".</B><BR>You may want to print this notice as confirmation of your Purchase.<P>Please give the seller 24 Hours to contact you.<P>Go <A HREF=\"$ENV{'SCRIPT_NAME'}\?\">back to the Auction</A></center>\n";
                &closeitb($form{'CATEGORY'},$form{'ITEM'});
                #&count_bid;

                my $flag=0;
                my $userbid;
                foreach $userbid (@userbids) {
                        $flag=1 if ("$form{'CATEGORY'}$form{'ITEM'}" eq $userbid);
                }
                if ($flag==0 && $config{'regdir'} ne "") {
                        &oops('We could not open the registration file.  This could be a server write issue.') unless (open(REGFILE, ">>$config{'basepath'}$config{'regdir'}/$form{'ALIAS'}.dat"));
                        print REGFILE "\n$form{'CATEGORY'}$form{'ITEM'}";
                        close REGFILE;

                }
                &sendemail($email, $config{'admin_address'}, 'Item Sold!', "Item : $title\! Has Been Sold Using the Buy-It Button. Please Visit $config{'sitename'} again.") if ($config{'scripturl'} and $#bids);

        }
        else {
                print "Item number $form{'ITEM'} in category $form{'CATEGORY'} is now closed!<BR>Sorry...\n";
        }

}

#-#############################################
# Sub: Close Auction Buy It
# This sets an item's status to closed.

sub closeitb {
        my ($cat,$item) = @_;
        if ($cat ne $config{'closedir'}) {
                my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = &read_item_file($cat,$item);
                my @lastbid = &read_bid($bids[$#bids]);
                my @firstbid =  &read_bid($bids[0]);
                if ($#bids) {
                        if ($lastbid[2] >= $reserve) {
                                &sendemail($lastbid[1], $firstbid[1], "Auction Close: $title", "Congratulations!  You are the winner of auction number $item.\nYour winning bid was \$$lastbid[2].\n\nPlease contact the seller to make arrangements for payment and shipping:\n\n$firstbid[4]\n$firstbid[5]\n$firstbid[6]\n$firstbid[1]\n\nThanks for using $config{'sitename'}!");
                                &sendemail($firstbid[1], $lastbid[1], "Auction Close: $title", "Auction number $item is now closed.\nThe high bid was \$$lastbid[2] (your reserve was: \$$reserve).\n\nPlease contact the high bidder to make any necessary arrangements:\n\n$lastbid[4]\n$lastbid[5]\n$lastbid[6]\n$lastbid[1]\n\nThanks for using $config{'sitename'}!");
                        }
                        else {
                                &sendemail($lastbid[1], $firstbid[1], "Auction Close: $title", "Congratulations!  You were the high bidder on auction number $item.\nYour bid was \$$lastbid[2].\n\nUnfortunately, your bid did not meet the seller\'s reserve price...\n\nYou may still wish to contact the seller to negotiate a fair price:\n\n$firstbid[4]\n$firstbid[5]\n$firstbid[6]\n$firstbid[1]\n\nThanks for using $config{'sitename'}!");
                                &sendemail($firstbid[1], $lastbid[1], "Auction Close: $title", "Auction number $item is now closed.\nThe high bid was \$$lastbid[2] (your reserve was: \$$reserve).\n\nPlease contact the high bidder to make any necessary arrangements:\n\n$lastbid[4]\n$lastbid[5]\n$lastbid[6]\n$lastbid[1]\n\nThanks for using $config{'sitename'}!");
                        }
                        #&sendemail($firstbid[1], $lastbid[1], "Auction Close: $title", "Auction number $item is now closed.\nThe high bid was \$$lastbid[2] (your reserve was: \$$reserve).\n\nPlease contact the high bidder to make any necessary arrangements:\n\n$lastbid[4]\n$lastbid[5]\n$lastbid[6]\n$lastbid[1]\n\nThanks for using $config{'sitename'}!");
                }
                else {
                        &sendemail($firstbid[1], $config{'admin_address'}, "Auction Close: $title", "Auction number $item is now closed.\nThere were no bids on your item.  You may repost your item by using the closed auction manager at http://$config{'scripturl'}$ENV{'SCRIPT_NAME'}.  Thanks for using $config{'sitename'}!");
                }
                if ($config{'closedir'}) {
                        umask(000);  # UNIX file permission junk
                        mkdir("$config{'basepath'}$config{'closedir'}", 0777) unless (-d "$config{'basepath'}$config{'closedir'}");
                        print "Please notify the site admin that this item cannot be copied to the closed directory even though it is closed.\n" unless &movefile("$config{'basepath'}$cat/$item.dat", "$config{'basepath'}$config{'closedir'}/$cat$item.dat");
                }
                else {
                        print "Please notify the site admin that this item cannot be removed even though it is closed.\n" unless unlink("$config{'basepath'}$cat/$item.dat");
                }
        }
}

#######################################
# Stats Addon Users and Number of Auctions
#######################################
sub stats {
# Count Registered Users

my $numusers = 0;
opendir THEDIR, "$config{'basepath'}$config{'regdir'}";
my @allfiles = grep -T, map "$config{'basepath'}$config{'regdir'}/$_", readdir THEDIR;
closedir THEDIR;
my $numusers = $numusers + @allfiles;

# Count Open Auctions

my $key;
my $totalfiles = 0;
foreach $key (sort keys %category) {
opendir THEDIR, "$config{'basepath'}$key" or &oops("Category directory $key could not be opened.");
my @allfiles = grep -T, map "$config{'basepath'}$key/$_", readdir THEDIR;
closedir THEDIR;
$totalfiles = $totalfiles + @allfiles;
}

print "<center><BR><font face=Arial><small>There are currently<FONT color=$config{'colortablehead'}> $numusers</FONT>
registered users and<font color=$config{'colortablehead'}> $totalfiles</font> open auctions.</small></center><br>\n";
}

#-#############################################
# Sub: Time Remain
# Time Display

sub time_remain($){
    my $diff = $_[0] - time;
    if($diff < 0){ return "<font color=red>Closed</font>" }
    my $days  = int ( $diff                                  / 86400);
    my $hours = int (($diff - $days * 86400)                 / 3600 );
    my $mins  = int (($diff - $days * 86400 - $hours * 3600) / 60   );
    if($days > 1){
        return "<nobr>$days Days $hours Hrs+</nobr>";
    }elsif($days == 1){
        return "<nobr>1 Day $hours Hrs+</nobr>";
    }elsif($hours > 12){
        return "<nobr>$hours Hrs $mins Min+</nobr>";
    }elsif($hours > 0){
        return "<nobr><font color=red>$hours Hrs $mins Min+</font></nobr>";
    }else{
        my $secs = int ($diff-($days*86400)-($hours*3600)-($mins*60));
        return "<nobr><font color=red>$mins Min $secs Sec+</font></nobr>";
    }
}

#-#############################################
# Sub: Pagebreak
# This displays pagebreak links

sub pagebreak{
        my $begin = "<center>";
        my $next = "Next Page >>";
        my $nonext = "Next Page >>";
        my $previous = "<< Previous Page";
        my $noprevious = "<< Previous Page";
        my $end = "</center>";

        my $urlfragment;
        foreach(keys %form){
                next if($_ eq 'pb' || $_ eq 'page');
                my $f = $form{$_};
                $f=~s/(\W)/'%'.unpack("H2", $1)/eg;
                $urlfragment.='&' if $urlfragment;
                $urlfragment.="$_=$f";
        }
        my($pcount, $pagebreak) = @_;

        # Print Pagebreak Links
        print $begin;
        if($form{page} > 0){ print " <a href=$ENV{SCRIPT_NAME}?$urlfragment&page=@{[$form{page}-1]}&pb=$form{pb}>$previous</a> " }
        else{ print " $noprevious " }
        print "|";
        for(0..$form{page}-1){ print " <a href=$ENV{'SCRIPT_NAME'}?$urlfragment&page=$_&pb=$form{pb}>@{[$_+1]}</a> " }
        print " <b>", int($form{page})+1, "</b> ";
        for($form{page}+1..$pcount){ print " <a href=$ENV{'SCRIPT_NAME'}?$urlfragment&page=$_&pb=$form{pb}>@{[$_+1]}</a> " }
        if($pcount>0){ print " <a href=$ENV{'SCRIPT_NAME'}?$urlfragment&pb=@{[(1+$pcount)*$pagebreak]}>All</a> " }
        print "|";
        if($form{page} < $pcount){ print " <a href=$ENV{'SCRIPT_NAME'}?$urlfragment&page=@{[$form{page}+1]}&pb=$form{pb}>$next</a></font></small> " }
        else{ print " $nonext " }
        print $end;
}

##############################################
# Sub: Lost password
# form for requesting password

sub lp {
        print <<"EOF";
<center><font size=4 face=Arial>PASSWORD RETRIEVAL</font><BR>
<FORM METHOD=POST ACTION=\"$ENV{'SCRIPT_NAME'}\">
<input name="action" type="hidden" value="lp2">
<font face=Arial><small>
<div align=center><table cellspacing=0 cellpadding=0 border=0 width="50%">
<TR><TD VALIGN=TOP colspan=2 align=center><B>YOUR IP address:<BR></B>Recorded
for security reasons</TD></Tr>
<tr><TD colspan=2 align=center>$ENV{'REMOTE_ADDR'}<INPUT
TYPE=HIDDEN NAME=IP VALUE=$ENV{'REMOTE_ADDR'}>
</td></tr>
<tr>
<td width=100>Alias<br><i>Required</i></td>
<td><input name="ALIAS" type="text" value="" size=25 maxlength=30></td>
</tr>
<tr>
<td width=100>E-Mail<br><i>Required</i></td>
<td><input name="EMAIL" type="text" value="" size=25 maxlength=30><br>Used to verify your alias.</td>
</tr>
</table></small>

<input type="submit" value="Get Password">
</form>


EOF
}


#############################################
# Sub: Process lost password
# processes lost password

sub lp2 {
        &oops('You must enter an alias that consists of alphanumeric characters.') if $form{'ALIAS'} =~ /\W/ or !($form{'ALIAS'});
        &oops('You must enter a valid e-mail address.') unless ($form{'EMAIL'} =~ /^.+\@.+\..+$/);

        $form{'ALIAS'} =~ s/\W//g;
        $form{'ALIAS'} = lc($form{'ALIAS'});
        $form{'ALIAS'} = ucfirst($form{'ALIAS'});
        &oops('Your ALIAS does not exist') unless (open(REGFILE, "$config{'basepath'}$config{'regdir'}/$form{'ALIAS'}.dat"));
        my ($password,$email,$add1,$add2,$add3,@junk) = <REGFILE>;
        chomp($password,$email,$add1,$add2,$add3,@junk);
        close REGFILE;
        &oops('your EMAIL Does not match our records') unless ((lc $email) eq (lc $form{'EMAIL'}));
        &sendemail($email, $config{'admin_address'}, "Auction Password Request", "Our system has received a request for your password from IP address $form{'IP'} due to it being lost.\n\nYour password is: $password \r\n\n   Thanks for using $config{'sitename'}!");

        print "<center><font face=Arial><B><big><BR><BR>$form{'ALIAS'}, You will receive an email shortly. It will contain your password. Your password is: $password</center></B></big></font><BR><BR>\n";


}

##############################################
# Sub: Lost Alias
# form for requesting Alias

sub la {
        print <<"EOF";
<center><font size=4 face=Arial>ALIAS OR HANDLE RETRIEVAL</font><BR>
<FORM METHOD=POST ACTION=\"$ENV{'SCRIPT_NAME'}\">
<input name="action" type="hidden" value="la2">
<div align=center><table cellspacing=0 cellpadding=0 border=0 width="50%">
<tr>
<td width=100><font face=Arial><small>E-Mail<br><i>Required</i></td>
<td><input name="EMAIL" type="text" value="" size=25 maxlength=30><br>Used to verify your alias.</td>
</tr>
</table>

<input type="submit" value="Get Alias">
</form></font></small>


EOF
}


#############################################
# Sub: Process lost Alias
# processes lost Alias

sub la2 {
        my $file;
        &oops('You must enter a valid e-mail address.') unless ($form{'EMAIL'} =~ /^.+\@.+\..+$/);
        $form{'EMAIL'} = lc($form{'EMAIL'});
        opendir THEDIR, "$config{'basepath'}$config{'regdir'}" || die "Unable to open directory: $!";
        my @allfiles = readdir THEDIR;
        closedir THEDIR;
        foreach $file (sort { int($a) <=> int($b) } @allfiles) {
        if ("$config{'basepath'}$config{'regdir'}/$file" =~ /\.dat/) {
        open THEFILE, "$config{'basepath'}$config{'regdir'}/$file";
        my ($password,$email,$add1,$add2,$add3,@junk) = <THEFILE>;
        close THEFILE;
        chomp($password,$email,$add1,$add2,$add3,@junk);
        if ($form{'EMAIL'} =~ /$email/) {
         $file =~ s/\.dat//;
        my $username = $file;
        print "<center><font face=Arial><B><big><BR><BR>The Alias or Handle for: $form{'EMAIL'}, is: <b>$username</b></center></B></big></font><BR><BR>\n";
        }

        }

        }
print "<center> <i>If no Alias is listed the email address you gave is not registered</i></center>";

}

#-#############################################
# Sub: Tell a Friend
# This creates a form for someone to refer a friend to your auction.

sub referafriend {
        print <<"EOF";
<p align="center"><h2 align="center">Tell a Friend</h2></p>
<p align="center"><center>
<table border="0" cellpadding="3" cellspacing="0" width="500">
<FORM METHOD=POST ACTION="$ENV{'SCRIPT_NAME'}\">
<input name="action" type="hidden" value="referafriend2">
    <tr>
        <td align="right" valign="top"><font size="2"
        face="Arial">Your name:</font></td>
        <td valign="top"><input type="text" size="20" name="NAME"></td>
    </tr>
    <tr>
        <td align="right" valign="top"><font size="2"
        face="Arial">Your e-mail address:</font></td>
        <td valign="top"><input type="text" size="20" name="EMAIL"></td>
    </tr>
    <tr>
        <td align="right" valign="top"><font size="2"
        face="Arial">Your friends e-mail address(es):</font><font
        face="Times New Roman"><br>
        </font><font size="1" face="Arial" color="#808080">seperate addresses with,commas.<br>
                ie, address\@domain.com,address2\@domain.com</font></td>
        <td valign="top"><input type="text" size="20" name="EMAILA"><br></td>
    </tr>
    <tr>
        <td align="right" valign="top"><font size="2"
        face="Arial">Personal message:</font><font
        face="Times New Roman"><br>
        </font><font size="1" face="Arial" color="#808080">optional</font></td>
        <td valign="top"><textarea name="MESSAGE" rows="5" cols="20"></textarea></td>
    </tr>
    <tr>
        <td align="right" valign="top">&nbsp;</td>
        <td valign="top"><input type="reset"
        name="B1" value="Reset"> <input type="submit" name="B2"
        value="Submit"></td>
    </tr>
    <tr>
        <td align="right" valign="top"><font size="2"
        face="Arial"></font>&nbsp;</td>
        <td valign="top"><font size="1" face="Arial">press submit
        once only please.</font></td>
    </tr>
</FORM>
</table>
<p align="center">
<table align="center" cellpadding="3" cellspacing="0" width="500">
Your message will look something like this:<br><br>
Hello,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Your friend, Joe Bloggs, thought you might be interested in the $config{'sitename'} Auction site and sent you this e-mail.<br>
Come and check out this top site at <a href="$config{'scripturl'}/cgi-bin/ez/ezauct.pl" target="_blank">$config{'sitename'}</a>
<br><br>Your friend also included the following message:<br>
"Hello,  check this out!"
<br><br>Sincerly,<br>
$config{'sitename'}
</table>
</p>
</center></p>
EOF
}

#############################################
# Sub: Process Tell a Friend
# sends details to refered addresses

sub referafriend2 {
                my $testmail = $form{'EMAIL'};
if ($testmail =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
        $testmail !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
              {
        &oops('You must enter a valid e-mail address.');
        }
        &oops('You must enter your full name.') unless ($form{'NAME'});

        &sendemail($form{'EMAILA'}, $form{'EMAIL'}, "E-mail from $form{'NAME'}", "Hello,\r\n\r     Your friend, $form{'NAME'}, thought you might be interested in the $config{'sitename'} site and sent you this e-mail.\r\nCome and check out this top site at $config{'scripturl'}\n\nYour friend also included the following message:\r\n\"$form{'MESSAGE'}\"\n\nSincerly,\r\n$config{'scripturl'}\n$config{'scripturl'}/cgi-bin/auction/ezauct.pl");

        print "<p><center>Thankyou so much $form{'NAME'} for spreading the word!<BR><BR>An e-mail referring your friend(s) has been sent.</center></p>";
}

###############################################
# Sub: View All Items
# This Displays all Items up for Bid

sub view_all {

                print "<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablebody'}><font color=$config{'colortablehead'}>";
        print "<font face=Arial><I><B><center>$category{$form{'category'}}</B></I></center><BR>\n";
            print "<small><IMG SRC=$config{'scripturl'}/cats.gif> <A HREF=$ENV{'SCRIPT_NAME'}>Categories</A> ";
            print "   <IMG SRC=$config{'scripturl'}/all.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=all>All Items</A> ";
            print "   <IMG SRC=$config{'scripturl'}/new.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=new>New</A> ";
            print "   <IMG SRC=$config{'scripturl'}/closing.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=close>Closing</a> ";
            print "   <IMG SRC=$config{'scripturl'}/ending.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=gone>Going, Gone!</a> ";
                print "   <IMG SRC=$config{'scripturl'}/allclosed.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=allclosed>All Closed</A> ";
            print "   <IMG SRC=$config{'scripturl'}/post.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=new>Post Item</A> ";
            print "   <IMG SRC=$config{'scripturl'}/register.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=reg>Register</A> ";
            print "   <IMG SRC=$config{'scripturl'}/myauction.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=closed>My Auction</A></small></font> ";
                print "</font></td></tr></table>";
                print "<TABLE BORDER=0 BGCOLOR=$config{'colortablebody'} WIDTH=80% CELLSPACING=0 CELLPADDING=0>\n";
                print "<TR><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Number</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Item</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Closes</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><B><small>Num Bids</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><B><small>High Bid</B></small></font></TD></TR>\n";
                my $key;
                foreach $key (sort keys %category) {
                opendir THEDIR, "$config{'basepath'}$key" || die "Unable to open directory: $!";
                my @allfiles = readdir THEDIR;
                closedir THEDIR;
                my $file;
                foreach $file (sort { int($a) <=> int($b) } @allfiles) {
                if (-T "$config{'basepath'}$key/$file") {
                open THEFILE, "$config{'basepath'}$key/$file";
                my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = <THEFILE>;
                close THEFILE;
                chomp($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids);
                my @lastbid = split(/\[\]/,$bids[$#bids]);
                $file =~ s/\.dat//;
                my @closetime = localtime($file);
                $closetime[4]++;
                my $timeremain = time_remain($file);
                print "<TR><TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file><font face=Arial><small>$file</small></A></TD>";
                print "<td><A HREF=$ENV{'SCRIPT_NAME'}\?category=$key\&item=$file>$title</a>";
                print " <img src=$config{'scripturl'}/cam2.gif>" if ($image);
                print " <img src=$config{'scripturl'}/buyit.gif>" if ($buyit);
                print " <img src=$config{'scripturl'}/paypalicon.gif>" if ($paypal);
                print " <img src=$config{'scripturl'}/billpointicon.gif>" if ($billpoint);
                print " <img src=$config{'scripturl'}/yahooicon.gif>" if ($yahoo);
                print "</td> <td ALIGN=CENTER>$timeremain</td> <td ALIGN=CENTER>$#bids </td> <td ALIGN=CENTER>$lastbid[2]</td></tr>";
                }
        }
}
                print "</table>";

}

#-#############################################
# Sub:  Welcome Message
# This will give out a welcome message to
# the newest member; call it everywhere you
# like with &welcome_msg

sub welcome_msg {
        return '' unless -r "$config{'basepath'}$config{'newestmember'}/newmember.dat" and -T "$config{'basepath'}$config{'newestmember'}/newmember.dat";
        open FILE, "$config{'basepath'}$config{'newestmember'}/newmember.dat";
        my ($alias,$email) = <FILE>;
        close FILE;
        chomp ($alias,$email);
        print "<P><small><center>$config{'sitename'} welcomes its newest member <b><a href=mailto:$email>$alias</a></b></center></small></P>";
}

#################################################################
# My History Add-on v1.0
# DynamicEnterprise.com/scripts/my_history.txt
# View Closed 2 Sub

sub viewclosed2 {

  &oops('your screen name could not be found.') unless my ($password, $email, $add1, $add2, $add3, @past_bids) = &read_reg_file($form{'ALIAS'});
  &oops('you must enter an alias that consists of alphanumeric characters.') if $form{'ALIAS'} =~ /\W/ or !($form{'ALIAS'});
  $form{'ALIAS'} = ucfirst(lc($form{'ALIAS'}));
  &oops('your screen name could not be found') unless (open(REGFILE, "$config{'basepath'}$config{'regdir'}/$form{'ALIAS'}.dat"));
  my ($password,$email,$add1,$add2,$add3,$phone1,$phone2,$phone3,@junk) = <REGFILE>;
  chomp($password,$email,$add1,$add2,$add3,$phone1,$phone2,$phone3,@junk);
  close REGFILE;
  &oops('your password is incorrect.') unless ((lc $password) eq (lc $form{'PASSWORD'}));
  print "<H2>My History</H2><HR><FONT SIZE=+1><B>Current Bids</B></FONT>\n";
  print "<P><TABLE BORDER=1 BGCOLOR=$config{'colortablebody'} WIDTH=100\% CELLSPACING=0 CELLPADDING=2>\n";
  print "<TR><TD WIDTH=400 ALIGN=center BGCOLOR=$config{'colortablehead'}><B>Item</B></TD><TD ALIGN=center bgcolor=$config{'colortablehead'}><B>Closes</B></TD><TD ALIGN=center bgcolor=$config{'colortablehead'}><B>Your Bid</B></TD><TD ALIGN=center bgcolor=$config{'colortablehead'}><B>Bid Time</B></TD><TD ALIGN=center bgcolor=$config{'colortablehead'}><B>Status</B></TD></TR>\n";
  my $key;
  foreach $key (sort keys %category) {
    opendir THEDIR, "$config{'basepath'}$key" || die "Unable to open directory: $!";
    my @allfiles = readdir THEDIR;
    closedir THEDIR;
    my $file;
    foreach $file (sort { int($a) <=> int($b) } @allfiles) {
      if (-T "$config{'basepath'}$key/$file") {
        open THEFILE, "$config{'basepath'}$key/$file";
        my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, $days, $sbid, $category, @bids) = <THEFILE>;
        close THEFILE;
        chomp ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, $days, $sbid, $category, @bids);
        my @lastbid = split(/\[\]/,$bids[$#bids]);
        $file =~ s/\.dat//;
        shift @bids;
        foreach my $bid (@bids) {
          my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bid);
          my @closetime = localtime($file);
          $closetime[4]++;
                  my $timeremain = time_remain($file);
          my @firstbid =  &read_bid($bids[0]);
          1 while $lastbid[2] =~ s/(.*\d)(\d\d\d)/$1,$2/;
          1 while $bid =~ s/(.*\d)(\d\d\d)/$1,$2/;
          my $timediff = ($file - time);
          my $bidtime = localtime($time);
          print "<TR><TD><FONT COLOR=\#008000><SMALL><A HREF=$ENV{'SCRIPT_NAME'}\?category=$key\&item=$file>$title</A></SMALL></FONT>" if ($form{'ALIAS'} eq $alias && ($bid eq $lastbid[2]));
          print "<TR><TD><SMALL><A HREF=$ENV{'SCRIPT_NAME'}\?category=$key\&item=$file>$title</A></SMALL>" if ($form{'ALIAS'} eq $alias && ($bid ne $lastbid[2]));
          print "\&nbsp\;$config{'photoicon'}" if ($image && ($form{'ALIAS'} eq $alias));
          print "\&nbsp\;$config{'newicon'} " if (time<($config{'setnew'} * 86400 + $firstbid[3]) && ($form{'ALIAS'} eq $alias)) ;
          print "\&nbsp\;$config{'hoticon'} " if ($config{'sethot'} <= $#bids && ($form{'ALIAS'} eq $alias));
          print "\&nbsp\;$config{'endingicon'} " if ($timediff<($config{'setending'} * 3600) && ($form{'ALIAS'} eq $alias));
          print "</TD><TD ALIGN=center><SMALL>$timeremain</SMALL></TD>" if ($form{'ALIAS'} eq $alias);
          print "<TD ALIGN=center><FONT COLOR=\#008000><SMALL>\$$bid</SMALL></FONT></TD><TD ALIGN=center><SMALL>$bidtime</SMALL></TD>" if ($form{'ALIAS'} eq $alias && ($bid eq $lastbid[2]));
          print "<TD ALIGN=center><SMALL>\$$bid</SMALL></TD><TD align=center><SMALL>$bidtime</SMALL></TD>" if ($form{'ALIAS'} eq $alias && ($bid ne $lastbid[2]));
          print "<TD ALIGN=center><FONT COLOR=\#ff0000><SMALL>High Bid</SMALL></FONT></TD></TR>" if ($form{'ALIAS'} eq $alias && ($bid eq $lastbid[2]));
          print "<TD ALIGN=center><SMALL>Out Bid</SMALL></FONT></TD></TR>" if ($form{'ALIAS'} eq $alias && ($bid ne $lastbid[2]));
        }
      }
    }
  }
  print "</TABLE><P>";
  print "<HR><FONT SIZE=+1><B>Closed Auctions</B></FONT>\n";
  print "<FORM METHOD=POST ACTION=\"$ENV{'SCRIPT_NAME'}\">\n";
  print "<INPUT TYPE=HIDDEN NAME=action VALUE=closed3><INPUT TYPE=HIDDEN NAME=ALIAS VALUE=\"$form{'ALIAS'}\"><SELECT NAME=BIDTOVIEW>\n";
  my $bid;
  foreach $bid (@past_bids) {
    if (-T "$config{'basepath'}$config{'closedir'}/$bid.dat") {
      open THEFILE, "$config{'basepath'}$config{'closedir'}/$bid.dat";
      my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, $days, $sbid, $category, @bids) = <THEFILE>;
      close THEFILE;
      chomp($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, $days, $sbid, $category, @bids);
      print "<OPTION VALUE=\"$bid\">$bid: $title</OPTION>\n";
      }
    }
  print "</SELECT><BR><INPUT TYPE=submit VALUE=\"View My Status\"></FORM>\n";

}

#############################################
# Sub: E-mail All Users Form
# This displays a form to e-mail a message to all users

sub emailusersadmin {
        print <<EOF;
<center><TABLE WIDTH=600 BORDER=0 BGCOLOR=$config{'colortablebody'}>
<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>
<input type=hidden name=action value=emailusers>
<input type=hidden name=GATE value=1>
<TR><TD COLSPAN=2 VALIGN=TOP><center><b><input type=submit value=Email>   Send to All Users!</b>
</TD></TR>
<tr><TD><INPUT NAME="MAILHEAD" VALUE="Message Title Here." TYPE=TEXT SIZE=50 MAXLENGTH=50></TD></tr>
<TD><textarea NAME="MESSAGE1" ROWS="5" COLS="50">Message Text Here.</textarea>
</form></CENTER>
</TD></TR></TABLE>
<br><br>
EOF
}


#############################################
# E-Mail all users!

sub emailusers {
        &oops('You must be admin to send e-mail!.') unless ($form{'GATE'} eq 1);

my $mailit = "Hello, This is a message from: $config{'sitename'}: \r\n\r\n$form{'MESSAGE1'} \r\n\r\nThankyou for using $config{'sitename'}";
        my $file;
        opendir THEDIR, "$config{'basepath'}$config{'regdir'}" || die "Fehler: $!";
        my @allfiles = readdir THEDIR;
        closedir THEDIR;
        foreach $file (sort { int($a) <=> int($b) } @allfiles) {
                if ("$config{'basepath'}$config{'regdir'}/$file" =~ /\.dat/) {
                        open THEFILE, "$config{'basepath'}$config{'regdir'}/$file";
                        my ($password,$email,@junk) = <THEFILE>;
                        close THEFILE;
                        chomp($password,$email,@junk);
                        $file =~ s/\.dat//;
                        my $username = $file;
                        &sendemail($email, $config{'admin_address'}, $form{'MAILHEAD'}, $mailit);
                        print $email;
                }
        }
        print "<br><br><p>Message Transmitted!!";
}

#-#############################################
# Sub: Suggest a Category Form
# This allows a user to suggest a category

sub suggest {
        print <<"EOF";
<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>
<H2>Suggest an Auction Category</H2>
<TABLE WIDTH=100% BORDER=0 BGCOLOR=$config{'colortablebody'}>
<INPUT TYPE=HIDDEN NAME=action VALUE=procsuggest>
<TR><TD COLSPAN=2 VALIGN=TOP> This form will allow you to suggest a category for this auction site.
</TD></TR>
<TR><TD VALIGN=TOP><B>Your Handle/Alias:<BR></B>Required for verification</TD><TD><INPUT NAME=ALIAS TYPE=TEXT SIZE=30 MAXLENGTH=30>
<TR><TD VALIGN=TOP><B>Your Password:<BR></B>Required for verification</TD><TD><INPUT NAME=PASSWORD TYPE=PASSWORD SIZE=30>
<TR><TD VALIGN=TOP><B>Suggested Category:<BR></B></TD><TD><INPUT NAME=SUGGEST TYPE=TEXT SIZE=30></TD></TR></TABLE>
<CENTER><INPUT TYPE=SUBMIT VALUE="Suggest the Category"></CENTER>
EOF
}

#-#############################################
# Sub: Process Category Form
# This process's the form

sub procsuggest {
        if ($config{'regdir'}) {
                &oops('You must enter your alias so we can validate your account.') unless ($form{'ALIAS'});
                &oops('You must enter your password so we can validate your account.') unless ($form{'PASSWORD'});
                if ($form{'SUGGEST'}) {
                        &oops('You must enter a category you wish to suggest.') unless ($form{'SUGGEST'});
                }
                        close NEWREG;
                        print "<center>$form{'ALIAS'}, the Auction Administrator has been notified about your suggested category.\n";
                        &sendemail($config{'admin_address'}, $config{'admin_address'}, ' User has Suggested a New Category', "NOTE TO THE ADMINISTRATOR :\n The User $form{'ALIAS'} has suggested a new category for the auction.\n The Category is $form{'SUGGEST'}\n" );
                }
}

#-#############################################
# Sub: Display List Of NEW Items
# This creates a "nice" list of items in a
# category.

sub displistnew {
        print "<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablebody'}><font color=$config{'colortablehead'}>";
    print "<font face=Arial><I><B><center>$category{$form{'category'}}</B></I></center><BR>\n";
        print "<small><IMG SRC=$config{'scripturl'}/cats.gif> <A HREF=$ENV{'SCRIPT_NAME'}>Categories</A> ";
        print "   <IMG SRC=$config{'scripturl'}/all.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=all>All Items</A> ";
        print "   <IMG SRC=$config{'scripturl'}/new.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=new>New</A> ";
        print "   <IMG SRC=$config{'scripturl'}/closing.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=close>Closing</a> ";
        print "   <IMG SRC=$config{'scripturl'}/ending.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=gone>Going, Gone!</a> ";
        print "   <IMG SRC=$config{'scripturl'}/allclosed.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=allclosed>All Closed</A> ";
        print "   <IMG SRC=$config{'scripturl'}/post.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=new>Post Item</A> ";
        print "   <IMG SRC=$config{'scripturl'}/register.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=reg>Register</A> ";
        print "   <IMG SRC=$config{'scripturl'}/myauction.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=closed>My Auction</A></small></font> ";
        print "</font></td></tr></table>";
        print "<TABLE BORDER=0 WIDTH=80\%>\n";
        print "<TR><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Number</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Item</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Closes</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Num Bids</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>High Bid</B></small></font></TD></TR>\n";
        opendir THEDIR, "$config{'basepath'}$form{'category'}" or &oops("Category directory $form{'category'} could not be opened.");
        my @allfiles = grep -T, map "$config{'basepath'}$form{'category'}/$_", sort { int($a) <=> int($b) } (readdir THEDIR);
        closedir THEDIR;
        my $file;
        foreach $file (@allfiles) {
                $file =~ s/^$config{'basepath'}$form{'category'}\///;
                $file =~ s/\.dat$//;
                if (my ($title, $reserve, $inc, $desc, $image, @bids) = &read_item_file($form{'category'},$file)) {
                        my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]);
                        my ($selleralias, $selleremail, $sellerbid, $sellertime, $selleradd1, $selleradd2, $selleradd3) = &read_bid($bids[0]);
                        if (($sellertime + (86400 * $config{'newdays'})) > time){
                            my @closetime = localtime($file);
                            $closetime[4]++;
                                my $timeremain = time_remain($file);
                            print "<TR><TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file><font face=Arial><small>$file</small></A></TD><TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file>$title</A>";
                            print " <IMG SRC=$config{'scripturl'}/new.gif>" if (($sellertime + (86400 * $config{'newdays'})) > time);
                            print "</TD><TD BGCOLOR=$config{'colortablebody'}>$timeremain</TD><TD BGCOLOR=$config{'colortablebody'}>$#bids</TD><TD BGCOLOR=$config{'colortablebody'}>\$$bid</TD></TR>\n";
                        }
                }
        }
        print "</TABLE>\n";
}

#-#############################################
# Sub: Display List Of Going Items
# This creates a "nice" list of items in a
# category.

sub displistgone {
        print "<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablebody'}><font color=$config{'colortablehead'}>";
    print "<font face=Arial><I><B><center>$category{$form{'category'}}</B></I></center><BR>\n";
        print "<small><IMG SRC=$config{'scripturl'}/cats.gif> <A HREF=$ENV{'SCRIPT_NAME'}>Categories</A> ";
        print "   <IMG SRC=$config{'scripturl'}/all.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=all>All Items</A> ";
        print "   <IMG SRC=$config{'scripturl'}/new.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=new>New</A> ";
        print "   <IMG SRC=$config{'scripturl'}/closing.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=close>Closing</a> ";
        print "   <IMG SRC=$config{'scripturl'}/ending.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=gone>Going, Gone!</a> ";
        print "   <IMG SRC=$config{'scripturl'}/allclosed.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=allclosed>All Closed</A> ";
        print "   <IMG SRC=$config{'scripturl'}/post.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=new>Post Item</A> ";
        print "   <IMG SRC=$config{'scripturl'}/register.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=reg>Register</A> ";
        print "   <IMG SRC=$config{'scripturl'}/myauction.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=closed>My Auction</A></small></font> ";
        print "</font></td></tr></table>";
        print "<TABLE BORDER=0 WIDTH=80\%>\n";
        print "<TR><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Number</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Item</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Closes</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Num Bids</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>High Bid</B></small></font></TD></TR>\n";
        opendir THEDIR, "$config{'basepath'}$form{'category'}" or &oops("Category directory $form{'category'} could not be opened.");
        my @allfiles = grep -T, map "$config{'basepath'}$form{'category'}/$_", sort { int($a) <=> int($b) } (readdir THEDIR);
        closedir THEDIR;
        my $file;
        foreach $file (@allfiles) {
                $file =~ s/^$config{'basepath'}$form{'category'}\///;
                $file =~ s/\.dat$//;
                if ($file < (time + (3600 * $config{'goinghours'}))){
                        if (my ($title, $reserve, $inc, $desc, $image, @bids) = &read_item_file($form{'category'},$file)) {
                                my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]);
                                my ($selleralias, $selleremail, $sellerbid, $sellertime, $selleradd1, $selleradd2, $selleradd3) = &read_bid($bids[0]);
                                my @closetime = localtime($file);
                                $closetime[4]++;
                                my $timeremain = time_remain($file);
                                print "<TR><TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file><font face=Arial><small>$file</small></A></TD><TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file>$title</A>";
                                print " <IMG SRC=$config{'scripturl'}/new.gif>" if (($sellertime + (86400 * $config{'newdays'})) > time);
                                print "</TD><TD BGCOLOR=$config{'colortablebody'}>$timeremain</TD><TD BGCOLOR=$config{'colortablebody'}>$#bids</TD><TD BGCOLOR=$config{'colortablebody'}>\$$bid</TD></TR>\n";
                        }
                }
        }
        print "</TABLE>\n";
}

#-#############################################
# Sub: Display List Of Items Closing Today
# This creates a "nice" list of items in a
# category.

sub displistclose {
        print "<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablebody'}><font color=$config{'colortablehead'}>";
    print "<font face=Arial><I><B><center>$category{$form{'category'}}</B></I></center><BR>\n";
        print "<small><IMG SRC=$config{'scripturl'}/cats.gif> <A HREF=$ENV{'SCRIPT_NAME'}>Categories</A> ";
        print "   <IMG SRC=$config{'scripturl'}/all.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=all>All Items</A> ";
        print "   <IMG SRC=$config{'scripturl'}/new.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=new>New</A> ";
        print "   <IMG SRC=$config{'scripturl'}/closing.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=close>Closing</a> ";
        print "   <IMG SRC=$config{'scripturl'}/ending.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=gone>Going, Gone!</a> ";
        print "   <IMG SRC=$config{'scripturl'}/allclosed.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=allclosed>All Closed</A> ";
        print "   <IMG SRC=$config{'scripturl'}/post.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=new>Post Item</A> ";
        print "   <IMG SRC=$config{'scripturl'}/register.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=reg>Register</A> ";
        print "   <IMG SRC=$config{'scripturl'}/myauction.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=closed>My Auction</A></small></font> ";
        print "</font></td></tr></table>";
        print "<TABLE BORDER=0 WIDTH=80\%>\n";
        print "<TR><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Number</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Item</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Closes</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>Num Bids</B></small></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead'}><font FACE=Arial color=$config{'colortablebody'}><small><B>High Bid</B></small></font></TD></TR>\n";
        opendir THEDIR, "$config{'basepath'}$form{'category'}" or &oops("Category directory $form{'category'} could not be opened.");
        my @allfiles = grep -T, map "$config{'basepath'}$form{'category'}/$_", sort { int($a) <=> int($b) } (readdir THEDIR);
        closedir THEDIR;
        my $file;
        foreach $file (@allfiles) {
                $file =~ s/^$config{'basepath'}$form{'category'}\///;
                $file =~ s/\.dat$//;
                if ($file < (time + 86400)) {
                        if (my ($title, $reserve, $inc, $desc, $image, @bids) = &read_item_file($form{'category'},$file)) {
                            my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bids[$#bids]);
                            my ($selleralias, $selleremail, $sellerbid, $sellertime, $selleradd1, $selleradd2, $selleradd3) = &read_bid($bids[0]);
                            my @closetime = localtime($file);
                            $closetime[4]++;
                                my $timeremain = time_remain($file);
                            print "<TR><TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file><font face=Arial><small>$file</small></A></TD><TD BGCOLOR=$config{'colortablebody'}><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file>$title</A>";
                            print " <IMG SRC=$config{'scripturl'}/new.gif>" if (($sellertime + (86400 * $config{'newdays'})) > time);
                            print "</TD><TD BGCOLOR=$config{'colortablebody'}>$timeremain</TD><TD BGCOLOR=$config{'colortablebody'}>$#bids</TD><TD BGCOLOR=$config{'colortablebody'}>\$$bid</TD></TR>\n";
                        }
                }
        }
        print "</TABLE>\n";
}

###############################################
# Sub: View All Closed Items
# This Displays all Closed Items

sub view_all_closed {

print "<div align=center><center><table width=80\% border=0><tr><td bgcolor=$config{'colortablebody'}><font color=$config{'colortablehead'}>";
    print "<font face=Arial><I><B><center>All Closed Items</B></I></center><BR><BR>\n";
        print "<center><small><I>Closed auctions older than 30 days will be deleted from the server.</I></small></center><BR><BR>\n";
        print "<small><IMG SRC=$config{'scripturl'}/cats.gif> <A HREF=$ENV{'SCRIPT_NAME'}>Categories</A> ";
        print "   <IMG SRC=$config{'scripturl'}/all.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=all>All Items</A> ";
        print "   <IMG SRC=$config{'scripturl'}/new.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=new>New</A> ";
        print "   <IMG SRC=$config{'scripturl'}/closing.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=close>Closing</a> ";
        print "   <IMG SRC=$config{'scripturl'}/ending.gif> <A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&listtype=gone>Going, Gone!</a> ";
        print "   <IMG SRC=$config{'scripturl'}/allclosed.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=allclosed>All Closed</A> ";
        print "   <IMG SRC=$config{'scripturl'}/post.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=new>Post Item</A> ";
        print "   <IMG SRC=$config{'scripturl'}/register.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=reg>Register</A> ";
        print "   <IMG SRC=$config{'scripturl'}/myauction.gif> <A HREF=$ENV{'SCRIPT_NAME'}?action=closed>My Auction</A></small></font> ";
        print "</font></td></tr></table>";
print "<div align=center><TABLE BORDER=0 BGCOLOR=$config{'colortablebody'} WIDTH=80% CELLSPACING=2 CELLPADDING=2>\n";
print "<TR BGCOLOR=$config{'colortablehead'}>
<TD ALIGN=CENTER><font FACE=Arial color=$config{'colortablebody'}><small><B>Number</B></small></font></TD>
<TD ALIGN=CENTER><font FACE=Arial color=$config{'colortablebody'}><small><B>Item</B></small></font></TD>
<TD ALIGN=CENTER><font FACE=Arial color=$config{'colortablebody'}><small><B>Description</B></small></font></TD>
<TD ALIGN=CENTER><font FACE=Arial color=$config{'colortablebody'}><small><B>Closes</B></small></font></TD>
<TD ALIGN=CENTER><font FACE=Arial color=$config{'colortablebody'}><small><B>Num Bids</B></small></font></TD>
<TD ALIGN=CENTER><font FACE=Arial color=$config{'colortablebody'}><small><B>High Bid</B></small></font></TD><TD ALIGN=CENTER><font FACE=Arial color=$config{'colortablebody'}><small><B>Reserve</B></small></font></TD>
<TD ALIGN=CENTER><font FACE=Arial color=$config{'colortablebody'}><small><B>High Bidder</B></small></font></TD></TR>\n";
opendir THEDIR, "$config{'basepath'}$config{'closedir'}" || die "Unable to open directory: $!";
my @allfiles = readdir THEDIR;
closedir THEDIR;
my $file;
foreach $file (sort { int($a) <=> int($b) } @allfiles) {
if (-T "$config{'basepath'}$config{'closedir'}/$file") {
open THEFILE, "$config{'basepath'}$config{'closedir'}/$file";
my ($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids) = <THEFILE>;
close THEFILE;
chomp($title, $mysite, $paypal, $billpoint, $yahoo, $reserve, $inc, $desc, $image, $itmcond, $ship, $pay0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $buyit, $days, $sbid, $category, @bids);
my @lastbid = split(/\[\]/,$bids[$#bids]);
$file =~ s/\.dat//;
$file = substr($file, -10, 10);
my @closetime = localtime($file);
$closetime[4]++;
print "<TR><TD ALIGN=CENTER><font face=Arial><small>$file</small></font></TD>
<TD ALIGN=LEFT><font face=Arial><small>$title</small></font></TD>
<TD ALIGN=LEFT><font face=Arial><small>$desc</small></font></TD>
<TD ALIGN=CENTER><font face=Arial><small>$closetime[4]/$closetime[3]</small></font></TD>
<TD ALIGN=CENTER><font face=Arial><small>$#bids</small></font></TD>
<TD ALIGN=CENTER><font face=Arial><small>$lastbid[2]</small></font></TD>
<TD ALIGN=CENTER><font face=Arial><small>$reserve</small></font></TD>
<TD ALIGN=CENTER><font face=Arial><small>$lastbid[0]</small></font></TD></TR>";
                }
        }
        print "</TABLE>";
}