| 1 | #!/usr/local/bin/perl |
| 2 | |
| 3 | use CGI qw(:standard :html3); |
| 4 | |
| 5 | # Some constants to use in our form. |
| 6 | @colors=qw/aqua black blue fuschia gray green lime maroon navy olive |
| 7 | purple red silver teal white yellow/; |
| 8 | @sizes=("<default>",1..7); |
| 9 | |
| 10 | # recover the "preferences" cookie. |
| 11 | %preferences = cookie('preferences'); |
| 12 | |
| 13 | # If the user wants to change the background color or her |
| 14 | # name, they will appear among our CGI parameters. |
| 15 | foreach ('text','background','name','size') { |
| 16 | $preferences{$_} = param($_) || $preferences{$_}; |
| 17 | } |
| 18 | |
| 19 | # Set some defaults |
| 20 | $preferences{'background'} = $preferences{'background'} || 'silver'; |
| 21 | $preferences{'text'} = $preferences{'text'} || 'black'; |
| 22 | |
| 23 | # Refresh the cookie so that it doesn't expire. This also |
| 24 | # makes any changes the user made permanent. |
| 25 | $the_cookie = cookie(-name=>'preferences', |
| 26 | -value=>\%preferences, |
| 27 | -expires=>'+30d'); |
| 28 | print header(-cookie=>$the_cookie); |
| 29 | |
| 30 | # Adjust the title to incorporate the user's name, if provided. |
| 31 | $title = $preferences{'name'} ? |
| 32 | "Welcome back, $preferences{name}!" : "Customizable Page"; |
| 33 | |
| 34 | # Create the HTML page. We use several of Netscape's |
| 35 | # extended tags to control the background color and the |
| 36 | # font size. It's safe to use Netscape features here because |
| 37 | # cookies don't work anywhere else anyway. |
| 38 | print start_html(-title=>$title, |
| 39 | -bgcolor=>$preferences{'background'}, |
| 40 | -text=>$preferences{'text'} |
| 41 | ); |
| 42 | |
| 43 | print basefont({SIZE=>$preferences{size}}) if $preferences{'size'} > 0; |
| 44 | |
| 45 | print h1($title),<<END; |
| 46 | You can change the appearance of this page by submitting |
| 47 | the fill-out form below. If you return to this page any time |
| 48 | within 30 days, your preferences will be restored. |
| 49 | END |
| 50 | ; |
| 51 | |
| 52 | # Create the form |
| 53 | print hr(), |
| 54 | start_form, |
| 55 | |
| 56 | "Your first name: ", |
| 57 | textfield(-name=>'name', |
| 58 | -default=>$preferences{'name'}, |
| 59 | -size=>30),br, |
| 60 | |
| 61 | table( |
| 62 | TR( |
| 63 | td("Preferred"), |
| 64 | td("Page color:"), |
| 65 | td(popup_menu(-name=>'background', |
| 66 | -values=>\@colors, |
| 67 | -default=>$preferences{'background'}) |
| 68 | ), |
| 69 | ), |
| 70 | TR( |
| 71 | td(''), |
| 72 | td("Text color:"), |
| 73 | td(popup_menu(-name=>'text', |
| 74 | -values=>\@colors, |
| 75 | -default=>$preferences{'text'}) |
| 76 | ) |
| 77 | ), |
| 78 | TR( |
| 79 | td(''), |
| 80 | td("Font size:"), |
| 81 | td(popup_menu(-name=>'size', |
| 82 | -values=>\@sizes, |
| 83 | -default=>$preferences{'size'}) |
| 84 | ) |
| 85 | ) |
| 86 | ), |
| 87 | |
| 88 | submit(-label=>'Set preferences'), |
| 89 | hr; |
| 90 | |
| 91 | print a({HREF=>"/"},'Go to the home page'); |
| 92 | print end_html; |