#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use Fcntl qw(:flock :seek);
use strict;

open(INF,"data.db") or &dienice("Can't open data.db: $! \n");
flock(INF, LOCK_SH);    # shared lock
seek(INF, 0, SEEK_SET); # rewind to beginning
my(@data) = <INF>;
close(INF);

print header;
print start_html("Kite Catalog");

print <<EndHdr;
<h2 align="CENTER">Kite Catalog</h2>
To order, enter the quantity in the input box next to the item.<p>
<form action="order.cgi" method="POST">
EndHdr

foreach my $i (@data) {
   chomp($i);
   my ($stocknum,$name,$status,$price) = split(/\|/,$i);
   if ($status ne "OUT") {
      print qq(<input type="text" name="$stocknum" size=5> $name - \$$price<p>\n);
   }
}

print qq(<input type="submit" value="Order!">\n);

print end_html;

sub dienice {
    my($msg) = @_;
    print "<h2>Error</h2>\n";
    print $msg;
    exit;
}