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