#!/bin/sh

# Enforce a hierarchy of country, state, city on valid REQUEST_URIs - must look like .../country/state/city?parameters
dir=`echo $REQUEST_URI | sed -e 's/%20/ /g' -e 's:/?.*::' -e 's:/$::' -e 's:/index.cgi.*::'`
city=`basename "$dir" | sed -e 's/?.*//'`
dir=`dirname "$dir"`
state=`basename "$dir"`
dir=`dirname "$dir"`
country=`basename "$dir"`
[ -z "$state" ] && cat invalidurl && exit -1
[ -z "$city" ] && cat invalidurl && exit -1
[ -z "$country" ] && cat invalidurl && exit -1
btype=$QUERY_STRING
lstate=`grep $state ../../states | sed -e 's/[A-Z][A-Z] \(.*\)/\1/'`
#ad='Ad goes here'

# Punt if doing test execution and all parameters are not specified
[ -z "$UNIQUE_ID" ] && echo No UNIQUE_ID && exit -1

# Compute some more parameters
datafile=$UNIQUE_ID
av_height=500
av_width=700
export city datafile btype state country av_height av_width
[ -n "$DOCUMENT_ROOT" ] && cd $DOCUMENT_ROOT/../etc/workarea

# Show top level page for a city
[ -z "$btype" ] && (
echo 'Content-Type: text/html'
echo
echo '<HTML><HEAD><TITLE>Business Travellers Guide to '$city, $state'</TITLE>'
echo '<META NAME="DESCRIPTION" CONTENT="Information for the business traveller - airport services, restaurants, gas stations">'
echo '<META NAME="KEYWORDS" CONTENT="Business traveller, restaurants, hotels, gas stations, access numbers, airport">'
echo '<META NAME="Robots" CONTENT="index,follow">'
echo '<META NAME="GOOGLEBOT" CONTENT="INDEX, FOLLOW">'
echo '</HEAD>'
echo '<BODY bgcolor=lightgreen>'
echo '<table width=100% border=0>'
echo '<tr><td align=right colspan=2><H1>'$city, $state'</H1>'
echo '<tr><td valign=top><br><br><br>'
echo '<H2>Information for the Business Traveller </H2>'
echo '<A href=food.htm>Restaurants-2005 list</a><br>'
echo '<br>'
#echo '<A href="?GAS">Gas Stations</a><br>'
#echo '<A href="?Lodging">Hotels, Motels and other lodging</a><br>'
echo '<A href="?RST%">Restaurants</A><br>'
echo '<br>'
[ -n "$lstate" ] && echo '<A href="http://www.city-data.com/city/'$city'-'$lstate'.html">Other Information</A>'
echo '</td>'
echo '<TD WIDTH=120 ALIGN=RIGHT valign=top>'
echo '<script type="text/javascript"><!--'
echo 'google_ad_client = "pub-0652362529605596";'
echo 'google_alternate_color = "99ddff";'
echo 'google_ad_width = 120;'
echo 'google_ad_height = 600;'
echo 'google_ad_format = "120x600_as";'
echo 'google_ad_channel ="";'
echo 'google_color_border = "2D5893";'
echo 'google_color_bg = "99AACC";'
echo 'google_color_link = "000000";'
echo 'google_color_url = "000099";'
echo 'google_color_text = "003366";'
echo '//--></script>'
echo '<script type="text/javascript"'
echo '  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">'
echo '</script>'
echo '</td>'
echo '</TABLE>'
echo '<center>'
echo '<b>Copyright &copy; 2005 biz-traveller.com</b><br>'
echo '<font size=-1>'
echo 'You may not copy the content, the software, or the look and feel of this site without permission.<br>'
echo 'Permission is granted to use the &quot;Make Available Offline&quot; feature of your browser on any individual page.'
echo '</font><br>'
echo '</center>'
echo '</BODY></HTML>'
) 
[ -z "$btype" ] && exit

echo 'Content-Type: text/html'
echo
echo '<html>'
echo '<head>'
echo '<title>'
echo $city, $state
echo '</title>'
echo '<meta type=description content="Business traveller information for '$city, $state'"></meta>'
echo '<meta type=keyword content="Business traveller information, '$city, $state'"></meta>'
echo '<META NAME="Robots" CONTENT="noindex,nofollow">'
echo '<META NAME="Googlebot" CONTENT="NOINDEX, NOFOLLOW">'
echo '<META NAME="Slurp" CONTENT="NOINDEX, NOFOLLOW">'
echo '<script type=text/javascript src=/scripts/plot.js></script>'
echo '</head>'
echo '<body bgcolor=lightgreen>'
echo '<table width=100% border=0>'
echo '<td height='$av_height' id=maparea></td> '
echo '<td align=right valign=top>'
echo '<H1>'$city, $state'</H1>'
echo '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" height=21>'
echo '<input type="hidden" name="cmd" value="_s-xclick">'
echo '<input type="hidden" name="hosted_button_id" value="6UMD63CT6MJZN">'
echo '<a href=javascript:resizemap() border=0 ><img src=/images/resize.bmp border=0 ></a>'
echo '<a href=javascript:showform() border=0><img src=/images/search.bmp border=0></a>'
echo '<a href=/help.htm border=0><img src=/images/help.bmp border=0></a>'
echo '<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" >'
echo '<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">'
echo '</form>'
[ -z "$ad" ] || echo "$ad"
[ -n "$ad" ] || (
echo '<script type="text/javascript"><!--'
echo 'google_ad_client = "pub-0652362529605596";'
echo 'google_alternate_color = "99ddff";'
echo 'google_ad_width = 120;'
echo 'google_ad_height = 600;'
echo 'google_ad_format = "120x600_as";'
echo 'google_ad_channel ="";'
echo 'google_color_border = "2D5893";'
echo 'google_color_bg = "99AACC";'
echo 'google_color_link = "000000";'
echo 'google_color_url = "000099";'
echo 'google_color_text = "003366";'
echo '//--></script>'
echo '<script type="text/javascript"'
  echo 'src="http://pagead2.googlesyndication.com/pagead/show_ads.js">'
echo '</script>'
)
echo '</td>'
echo '<tr>'
echo '</table>'
echo ''

echo '<b>Copyright &copy; 2005-2010 biz-traveller.com</b><br>'
echo '<font size=-1>'
echo 'You may not copy the content, the software, or the look and feel of this site without permission.<br>'
echo 'Permission is granted to use the &quot;Make Available Offline&quot; feature of your browser on'
echo 'a few pages for private personal use.'
echo '</font><br>'
# Generate the list of points to show
# echo sh genset.sh $city $state $av_height $av_width $btype
sh genset.sh "$city" "$state" $av_height $av_width "$btype"

echo '<pre>'
#env
echo '</pre>'

echo '</body>'
echo '</script>'
echo '</html>'
