#!/usr/bin/perl
use CGI;

my $q = new CGI();

print $q->header();

my $wid = $q->param('wid');
my $action = $q->param('action');
my $lastname = $q->param('lastname');
my $firstname = $q->param('firstname');
my $service = $q->param('service');
my $company = $q->param('company');
my $position_desc = $q->param('position_desc');
my $address1 = $q->param('address1');
my $address2 = $q->param('address2');
my $city = $q->param('city');
my $state = $q->param('state');
my $zip1 = $q->param('zip1');
my $zip2 = $q->param('zip2');
my $country = $q->param('country');
my $phone = $q->param('phone');
my $email = $q->param('email');

if( $email =~ /.+\@.+/ ) {
$sql_query = "select wanderid,lastname,firstname,service,position_desc,company,city,state,country from userinfo where lower(email)=lower('$email')";
$uline = `/usr/local/bin/psql -t -A -F "	" -d hotel.online -c "$sql_query"`;
chomp $uline;
}

if( $uline ) {
  ($wid,$lastname,$firstname,$service,$position_desc,$company,$city,$state,$country) = split(/\t/,$uline);
}

$lastname =~ s/^(\s+)//;

my $STYLE = &get_style;

print $q->start_html( -title=>'Hotel.Online Email Headline Signup', -style=>"$STYLE");

print <<EOMEOM;
<BODY BGCOLOR="#FFFFFF">
<center>
<img src="/images/logo1.gif" alt="Hotel.Online Logo">
<HR>
<P>
<H2>FREE Email Headline Service Signup</H2>
</center>
EOMEOM

print <<EOMEOM;
<form method=POST action="essubmit.pl">
EOMEOM


print qq~<input type=hidden name="service" value="$service">~;

if( $wid =~ /\d+_\d+/ ) {
  $EX=1;
  print qq~<input type=hidden name="EXISTING" value="1">~;
} else {
  print qq~<input type=hidden name="EXISTING" value="">~;
  my $t = substr(time,0,8);
  my $r = substr(rand(),-6,6);
  $wid = "${t}_$r";
}

print qq~<input type=hidden name="wid" value="$wid">~;

if( $EX && $wid =~ /\d+_\d+/ && $email =~ /.+\@.+/ ) {
  if( $service =~ /^0emsu/i ) {
print qq~
   <b>You're already signed up for this service, but you can use this
  form to cancel your subscription.</b>  Also, if any of your personal
  information has changed, please update it.
~;
  } else {
print qq~
    <b>You're a registered Hotel.Online user!</b>  Make sure your name
  and Email address are correct to receive your free hospitality news
  from Knight-Ridder Tribune Business News Service.
~;
  }
} else {
print qq~
    <b>Welcome to Hotel.Online!</b>  Make sure your name
  and Email address are correct to receive your free hospitality news
  from Knight-Ridder Tribune Business News Service.
~;
}

if( $action eq 'sub' ) {
  $sub_check = 'CHECKED';
} elsif( $action eq 'can' ) {
  $can_check = 'CHECKED';
} else {
  $sub_check = 'CHECKED';
}

print <<EOMEOM;
<b>Please fill out the following form to receive your FREE hospitality
news from Knight-Ridder Tribune Business News Service!</b>

Even though we only require you to fill in the <b>bolded fields</b>,
we would appreciate it if you completed the entire form. Any and all
information about you helps Hotel.Online serve the Hospitality
Industry better.

<P>

Hotel.Online will not retransmit or resell any information entered
here.  You will receive a confirmation Email message after submitting
this form.

<P>
<table cellspacing=0 cellpadding=3>
    <tr><td><b>Action:</b></td><td> <input type="radio" name="action" value="sub" $sub_check> SUBSCRIBE to Email headline service</td></tr>
            <tr><td>&nbsp;</td><td><input type="radio" name="action" value="can" $can_check> CANCEL my subscription</td></tr>

<tr><td><b>First Name:</b></td><td> <input name="firstname" value="$firstname" size=30 maxlength=30></td></tr>
 <tr><td><b>Last Name:</b></td><td> <input name="lastname" value="$lastname" size=30 maxlength=30></td></tr>
     <tr><td><b>Email:</b></td><td> <input name="email" value="$email" size=30 maxlength=128></td></tr>
  <tr><td>Position:</td><td> <input name="position_desc" value="$position_desc" size=30 maxlength=50></td></tr>
   <tr><td>Company:</td><td> <input name="company" value="$company" size=30 maxlength=100></td></tr>
      <tr><td>City:</td><td> <input name="city" value="$city" size=30 maxlength=40></td></tr>
     <tr><td>State:</td><td> <input name="state" value="$state" size=30 maxlength=20></td></tr>
   <tr><td>Country:</td><td> <input name="country" value="$country" size=30 maxlength=50></td></tr>
</table>

<center>
<input type="submit" value=" SUBMIT ">
</form>
</center>
</BODY>
</HTML>

<P><HR>
<P>
<center>
<a href="/index.php">Home</a> | <a href="http://www.hotel-online.com/latest_news">Hospitality News</a> |
<a href="http://www.hotel-online.com/classifieds">Classifieds</a> |
<a href="http://www.hotel-online.com/media-kit">Media Kit</a> |
<a href="http://www.hotel-online.com/industry_resources">Industry Resources</a> 
<P>
<h5>Please contact <a href=\"mailto:contactus\@hotel-online.com\">Hotel-Online</a> with your comments and suggestions.</h5>
</center>
EOMEOM

sub get_style {
my $STYLE=qq~
font-face {
 font-family: Times New Roman;
 font-style:  normal;
 font-weight: normal;
 font-size:   medium;
}
BODY      {font-family: Times New Roman; font-size: small}
CAPTION   {font-family: Times New Roman; color: #202060; font-size: x-small}
TH        {font-family: Times New Roman; font-size: x-small}
TD        {font-family: Times New Roman; font-size: ${fsize}small }
h2        {font-family: Times New Roman; font-size: medium}
h3        {font-family: Times New Roman; font-size: small}
h4        {font-family: Times New Roman; font-size: x-small}
h5        {font-family: Times New Roman; font-size: xx-small}
tt        {font-family: Times New Roman; font-size: small}
ul        {font-family: Times New Roman; color: #004000; font-size: small}
ol        {font-family: Times New Roman; color: #004000; font-size: small}
li        {font-family: Times New Roman; color: #400000; font-size: small}
center    {font-family: Times New Roman; font-size: small}
pre       {font-family: serif; color: #000000; font-size: small}
A:link    {color: #0000FF; text-decoration: none}
A:visited {color: #FF0000; text-decoration: none}
A:hover   {text-decoration: underline}
.logo   {font-size: xx-large}
.title  {font-size: large}
.header {font-size: medium}
.fine-print {font-size: x-small}
~;
return $STYLE;
}

