#!/usr/bin/perl -w
######################################################################
# doorman.pl
######################################################################
# Perl Power! - Michael Schilli 1998
######################################################################

use CGI qw/:standard :html3/;      # standard and tables

if(defined param('go_shopping')) { # "Go shopping" pressed

                                   # form parameters -> cookie
    foreach $key (param()) { $data{$key} = param($key); }

                                   # send header with cookie
    $cookie = cookie(-name   => 'customer', -value => \%data,
                     -expires => "+1y");

    print header(-cookie => $cookie);

                                   # ... and here we go!
    print h1("Welcome to the shopping paradise!");

    # ... here we would proceed ...

} else {                           # obviously the first call
    if(cookie(-name => 'customer')) {          # cookie present?
        %cookie = cookie(-name => 'customer'); # receive cookie
        foreach $key (keys %cookie) {          # preset parameters
            param($key, $cookie{$key});
        }
    }

    print header();                # CGI header
    print_address_form();          # output address form
}

######################################################################
sub print_address_form {
######################################################################
    my $msg = (shift || "");

    print start_html(), 
        tt(CGI::font({color => 'red'}, $msg)),
        start_form(),
        table(
            TR(td("Name:"),       td(textfield(-name => 'name')),
               td("First name:"), td(textfield(-name => 'prename'))),
            TR(td("Address:"),    td(textfield(-name => 'address'))),
            TR(td("City:"),       td(textfield(-name => 'town')),
               td("ZIP code:"),   td(textfield(-name => 'zip'))),
            TR(td("Method of payment"), 
               td(popup_menu(-name =>'pay', 
                             '-values' => ['Bill me later', 'Credit Card',
                                           'Check'])))),
        submit(-name => 'go_shopping', -value => "Go shopping"),
        end_form(), end_html();
}

