1N/A#!/usr/local/bin/perl
1N/A
1N/Ause CGI qw(:standard :html3);
1N/A
1N/A# Some constants to use in our form.
1N/A@colors=qw/aqua black blue fuschia gray green lime maroon navy olive
1N/A purple red silver teal white yellow/;
1N/A@sizes=("<default>",1..7);
1N/A
1N/A# recover the "preferences" cookie.
1N/A%preferences = cookie('preferences');
1N/A
1N/A# If the user wants to change the background color or her
1N/A# name, they will appear among our CGI parameters.
1N/Aforeach ('text','background','name','size') {
1N/A $preferences{$_} = param($_) || $preferences{$_};
1N/A}
1N/A
1N/A# Set some defaults
1N/A$preferences{'background'} = $preferences{'background'} || 'silver';
1N/A$preferences{'text'} = $preferences{'text'} || 'black';
1N/A
1N/A# Refresh the cookie so that it doesn't expire. This also
1N/A# makes any changes the user made permanent.
1N/A$the_cookie = cookie(-name=>'preferences',
1N/A -value=>\%preferences,
1N/A -expires=>'+30d');
1N/Aprint header(-cookie=>$the_cookie);
1N/A
1N/A# Adjust the title to incorporate the user's name, if provided.
1N/A$title = $preferences{'name'} ?
1N/A "Welcome back, $preferences{name}!" : "Customizable Page";
1N/A
1N/A# Create the HTML page. We use several of Netscape's
1N/A# extended tags to control the background color and the
1N/A# font size. It's safe to use Netscape features here because
1N/A# cookies don't work anywhere else anyway.
1N/Aprint start_html(-title=>$title,
1N/A -bgcolor=>$preferences{'background'},
1N/A -text=>$preferences{'text'}
1N/A );
1N/A
1N/Aprint basefont({SIZE=>$preferences{size}}) if $preferences{'size'} > 0;
1N/A
1N/Aprint h1($title),<<END;
1N/AYou can change the appearance of this page by submitting
1N/Athe fill-out form below. If you return to this page any time
1N/Awithin 30 days, your preferences will be restored.
1N/AEND
1N/A ;
1N/A
1N/A# Create the form
1N/Aprint hr(),
1N/A start_form,
1N/A
1N/A "Your first name: ",
1N/A textfield(-name=>'name',
1N/A -default=>$preferences{'name'},
1N/A -size=>30),br,
1N/A
1N/A table(
1N/A TR(
1N/A td("Preferred"),
1N/A td("Page color:"),
1N/A td(popup_menu(-name=>'background',
1N/A -values=>\@colors,
1N/A -default=>$preferences{'background'})
1N/A ),
1N/A ),
1N/A TR(
1N/A td(''),
1N/A td("Text color:"),
1N/A td(popup_menu(-name=>'text',
1N/A -values=>\@colors,
1N/A -default=>$preferences{'text'})
1N/A )
1N/A ),
1N/A TR(
1N/A td(''),
1N/A td("Font size:"),
1N/A td(popup_menu(-name=>'size',
1N/A -values=>\@sizes,
1N/A -default=>$preferences{'size'})
1N/A )
1N/A )
1N/A ),
1N/A
1N/A submit(-label=>'Set preferences'),
1N/A hr;
1N/A
1N/Aprint a({HREF=>"/"},'Go to the home page');
1N/Aprint end_html;