#!/usr/bin/perl

$admin = 'tomr@aceldama.com';
$me = 'western.cgi';

%fields = ();

if (!defined $ENV{'REQUEST_METHOD'} or $ENV{'REQUEST_METHOD'} eq 'GET') {

        print <<"EOF";
Content-type: text/html

<html>
<head>
<title>Mad's All Inclusive Do-it-yourself Country &amp; Western song</title>
</head>

<body>
<h1>All Inclusive Do-it-yourself Country &amp; Western song</h1><hr>

<p>Mad's All Inclusive Do-It-Yourself Country-Western Song is from MAD No. 233,
September 1982, pp. 14-15. Written by Frank Jacobs.</p>

<p>The "Title" section was added by Tom Rathborne.</p>

<p>
<h2>Good Ol' Noise Dept.</h2>

<p>One of the biggest items in Pop Music today is the Country Western song. In
case you've ever had the wish to write ne, it's really not that difficult. In
fact, as you'll find out below, it's a snap. Simply fill in the numbered blanks
from the corresponding numbered lists, and you have<br>
<b>MAD'S ALL INCLUSIVE DO-IT-YOURSELF COUNTRY WESTERN SONG!</b></p>

<hr>

<form method="POST" action="$me">
<h2>Title:</h2>
<p align="left"><b>The <select name="T1">
<option>Girl
<option>Woman
<option>Goddess
<option>Chyk
<option>Pop star
<option>Messiah
<option>She-male
<option>Borg
<option>Texan
<option>Buffalo
<option>Waitress
</select>who<select name="T2">
<option>crushed
<option>stole
<option>ate
<option>bought
<option>destroyed
<option>analyzed
<option>assimilated
<option>teased
<option>digested
<option>scorched
<option>resented
</select>my<select name="T3">
<option>aching
<option>throbbing
<option>lonely
<option>scarred
<option>torn
<option>loving
<option>beating
<option>external
<option>enviable
<option>forlorn
<option>pining
</select><select name="T4">
<option>heart
<option>finger
<option>member
<option>feelings
<option>piercing
<option>embryo
<option>flavour
<option>saddle
<option>stirrups
<option>bullwhip
<option>anger
</select>
</b></p>

<p align="left">I met her
<select name="1">
<option>on the highway
<option>in Sheboygan
<option>outside Fresno
<option>at a truck stop
<option>on probation
<option>in a jail cell
<option>in a nightmare
<option>in the Stone Age
<option>in a treehouse
<option>in a gay bar
</select> 
<select name="2">
<option>in September
<option>at McDonald's
<option>ridin' shotgun
<option>wrestlin' gators
<option>all hunched over
<option>poppin' uppers
<option>sort of pregnant
<option>with joggers
<option>stoned on oatmeal
<option>with Merv Griffin
<option>dead all over
</select>
;<br>I can still recall
<select name="3">
<option>that purple dress
<option>that little hat
<option>that burlap bra
<option>those training pants
<option>the stolen goods
<option>that plastic nose
<option>the Stassin pin
<option>the neon sign
<option>that creepy smile
<option>the hearing aid
<option>the boxer shorts
</select>
she wore;<br>She was
<select name="4">
<option>sobbin' at the toll booth
<option>drinkin' Dr. Pepper
<option>weighted down with Twinkies
<option>breakin' out with acne
<option>crawlin' through the prairie
<option>smellin' kind of funny
<option>crashin' through the guardrail
<option>chewin' on a hangnail
<option>talkin' in Swahili
<option>drownin' in the quicksand
<option>slurpin' up linguine
</select>
<select name="5">
<option>in the twilight
<option>but I loved her
<option>by the off-ramp
<option>near Poughkeepsie
<option>with her cobra
<option>when she shot me
<option>on her elbows
<option>with Led-Zeppelin
<option>with Miss Piggy
<option>with a wetback
<option>in her muu-muu
</select>
<br>and I knew
<select name="6">
<option>no guy would ever love her more
<option>that she would be an easy score
<option>she'd bought her dentures in a store
<option>the she would be a crashing bore
<option>I'd never rate her more than "4"
<option>they'd hate her guts in Baltimore
<option>it was a raven, nothing more
<option>we really lost the last World War
<option>I'd have to scrape her off the floor
<option>what strong deodorants were for
<option>that I would upchuck on the floor
</select>
;<br>
<select name="7">
<option>I promised her
<option>I knew deep down
<option>She asked me if
<option>I told her shrink
<option>The judge declared
<option>My Pooh Bear said
<option>I shrieked in pain
<option>The painters knew
<option>A Klingon said
<option>My hamster thought
<option>My blood test showed
<option>Her rabbi said
</select>
I'd
<select name="8">
<option>stay with her
<option>warp her mind
<option>swear off booze
<option>change my sex
<option>punch her out
<option>live off her
<option>have my rash
<option>stay a dwarf
<option>hate her dog
<option>pick my nose
<option>play "Go Fish"
<option>salivate
</select>
forever.<br>She said to me
<select name="9">
<option>our love would never die
<option>there was no other guy
<option>man wasn't meant to fly
<option>that Nixon didn't lie
<option>her basset hound was shy
<option>that Rolaids made her high
<option>she'd have a swiss on rye
<option>she loved my one blue eye
<option>her brother's name was Hy
<option>she liked "Spy vs. Spy"
<option>that birthdays made her cry
<option>she couldn't stand my tie
</select>
;<br>But who'd have thought she'd
<select name="10">
<option>run off
<option>wind up
<option>boogie
<option>yodel
<option>sky dive
<option>turn green
<option>freak out
<option>blast off
<option>make it
<option>black out
<option>bobsled
<option>grovel
</select>
<select name="11">
<option>with my best friend
<option>in my Edsel
<option>on a surfboard
<option>on "The Gong Show"
<option>with her dentist
<option>on her "Workmate"
<option>with a robot
<option>with no clothes on
<option>at her health club
<option>in her Maytag
<option>with her guru
<option>while in labor
</select>
;
<select name="12">
<option>You'd think at least that she'd have said
<option>I never had the chance to say
<option>She told her fat friend Grace to say
<option>I now can kiss my credit cards
<option>I guess I was too smashed to say
<option>I watched her melt away and sobbed
<option>She fell beneath the wheels and cried
<option>She sent a hired thug to say
<option>She freaked out on the lawn and screamed
<option>I pushed her off the bridge and waved
<option>But that's the way that pygmies say
<option>She sealed me in the vault and smirked
</select>
goodbye.</p>

<p align="left"><input type="submit" value=" Assemble song ">
<input type="reset" value=" Reset song "></p>

</form>
<hr><address><a href="mailto:$admin">$admin</a></address>
</body></html>
EOF
    exit;

# just printed form.

} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {

# split input into $fields.

    read(STDIN, $query, $ENV{'CONTENT_LENGTH'});
    @F = split(/\&/, $query);

    foreach $f (@F) {
        ($n, $v) = split(/=/,$f);
        $v =~ s#\+# #g;
        $v =~ s#%([0-9a-fA-F][0-9a-fA-F])#sprintf("%c",hex($1))#eg;
        $fields{$n} = $v;
    }

    print <<"EOF";
Content-type: text/html

<html>
<head><title>Your Country &amp; Western song</title></head>
<body><h1>Your Country &amp; Western song</h1><hr>
<h2>The $fields{'T1'} who $fields{'T2'} my $fields{'T3'} $fields{'T4'}</h2>

<p align="left">I met her $fields{'1'} $fields{'2'};<br>
I can still recall $fields{'3'} she wore;<br>
She was $fields{'4'} $fields{'5'}<br>
and I knew $fields{'6'};<br>
$fields{'7'} I'd $fields{'8'} forever.<br>
She said to me $fields{'9'};<br>
But who'd have thought she'd $fields{'10'} $fields{'11'}<br>
$fields{'12'} goodbye.</p>

<hr>Created by <a href="$ENV{'HTTP_REFERER'}">$ENV{'HTTP_REFERER'}</a><hr>
<address><a href="mailto:$admin">$admin</a></address>
</body>
</html>
EOF

# just printed results.

} else {

    print <<"EOF";
Content-type: text/html

<html>
<head><title>Error!</title></head>
<body><h1>Submission Error!</h1><hr>
<h2>Invalid REQUEST_METHOD served.</h2>
<p>Something bad (and unspecified!) has happened.
E-mail $admin if you have any more problems. Thanks.</p>
<hr><address><a href="mailto:$admin">$admin</a></address>
</body></html>
EOF
}

