#!/usr/bin/perl -w

use strict;
use DBI;
use DateTime;
use CGI qw(:cgi-lib :standard);
use CGI::Carp qw/fatalsToBrowser/; 

use lib '/web/apps/executive/lib/';
require 'database.pl';

use HTML::Template;
my $template = '/web/apps/executive/lib/templatenewpurple.tmpl';
my $cgi = new CGI;
my %formdata = $cgi->Vars();
my $text;

my $dt = DateTime->now();
my $today_date = $dt->ymd;
my $id = $formdata{id};

my $record = &record("id", "=", $id);
my $event_dt;

if ( $record ) {
    my ( $year, $month, $day ) = split( /-/, $record->{event_date} );
    $event_dt = DateTime->new( year=>$year, month=>$month, day=>$day);
}

print "Content-type: text/html \n\n";

if ( $id eq 71 ) {
    $text = "Due to inclement weather, our February 10, 2010 Information Session has been canceled.  Please return to the Information <a href=\"http://emba.stern.nyu.edu/infosession\">Information Session sign-up page</a> to register for our next event.";
} elsif ( $id == 112 ) {
    $text = "The September 15th, 2012 Information Session has reached its capacity, we are sorry for any inconvenience.\&nbsp\; Please feel free to return to the the Information Session page to register for future week night events, or email us at <a href=\"mailto:executive\@stern.nyu.edu\">executive\@stern.nyu.edu</a> to be notified about future Saturday Information Sessions.";
} elsif ( !$record || DateTime->compare( $event_dt, $dt ) < 0 ) {
    $text = "You have attempted to register for an event that has passed.  Please visit our <a href=\"http://emba.stern.nyu.edu/infosession\">Information Session registration page</a> again to select an upcoming event.";

} elsif ( DateTime->compare( $event_dt, $dt ) == 0 ) {
    $text = "Online registration for this event has closed.  However, all interested candidates are welcome to register at the event.  We hope to see you there!";

} else {

$text = <<HTMLCODE;
<form action="submit.cgi" method="POST" name="form1" onSubmit="return validateForm(this)" >
<table border="0" cellspacing="0" cellpadding="0" width="100%">
  <tr>
    <td colspan="2"><br><h1 align="center">Information Session Registration</h1>
      <h2 align="center">A confirmation will be sent to the email address you provide below. </h2>
    </td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <input type="hidden" name="event" value="$id">
  <tr>
    <td width="45%" align="right">Salutation &nbsp; </td>
    <td><SELECT name=sal>
    <OPTION value ="Mr.">Mr</OPTION>
    <OPTION value ="Ms.">Ms</OPTION>
    <OPTION value ="Mrs.">Mrs</OPTION>
    <OPTION value ="Dr.">Dr</OPTION>
    </SELECT>
    </tr>
  <tr>
    <td width="45%" align="right">First<font color="red">*</font> &nbsp; </td>
    <td width="55%"><input type="text" name="first_name"></td>
    </tr>
  <tr>
    <td align="right">Last<font color="red">*</font> &nbsp; </td>
    <td><input type="text" name="last_name"></td>
    </tr>
  <tr>
    <td align="right">Company &nbsp; </td>
    <td><input type="text" name="company"></td>
    </tr>
  <tr>
    <td align="right">Telephone<font color="red">*</font> &nbsp; </td>
    <td><input type="text" name="phone"></td>
    </tr>
  <tr>
    <td align="right">E-mail<font color="red">*</font> &nbsp; </td>
    <td><input type="text" name="email"></td>
    </tr>
  <tr>
    <td align="right"><font color="red">*required</font> &nbsp; </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2"><center>
      <p><input name="Submit2" type="submit" value="Submit">
              </p>
        </center></td>
  </tr>
</table>
</form>
HTMLCODE
} 

my $tmpl = new HTML::Template ( filename => $template );

my $jscode = qq|<SCRIPT language='JavaScript1.1' SRC="http://action.mathtag.com/cnt?id=10288"></SCRIPT>|;
my $jscode2 = qq|<!-- "NYU Stern Executive MBA" c/o "Barker/DZP",  conversion: 'NYU Stern_Conversion_Unsecure' - DO NOT MODIFY THIS PIXEL IN ANY WAY -->

<img width="1" height="1" style="border:0" src="HTTP://bs.servingsys.com/BurstingPipe/ActivityServer.bs?cn=as&amp;ActivityID=155779&amp;ns=1"/>
</noscript>

<img src="http://www.googleadservices.com/pagead/conversion/1032222048/?label=6kDCCMyO3QEQ4OqZ7AM&amp;guid=ON&amp;script=0">

<IMG SRC="http://bp.specificclick.net?pixid=99061271" width="0" height="0" border="0">|;


my $jscode3 = qq|<script type='text/javascript'>
// Conversion Name: EMBA-Information Session-Submit
// INSTRUCTIONS
// The Conversion Tags should be placed at the top of the <BODY> section of the HTML page.
// In case you want to ensure that the full page loads as a prerequisite for a conversion
// being recorded, place the tag at the bottom of the page. Note, however, that this may
// skew the data in the case of slow-loading pages and in general not recommended.
//
// NOTE: It is possible to test if the tags are working correctly before campaign launch
// as follows: Browse to http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=at, which is
// a page that lets you set your local machine to 'testing' mode. In this mode, when
// visiting a page that includes an conversion tag, a new window will open, showing you
// the data sent by the conversion tag to the MediaMind servers.
//
// END of instructions (These instruction lines can be deleted from the actual HTML)
var ebRand = Math.random()+'';
ebRand = ebRand * 1000000;
//<![CDATA[
document.write('<scr'+'ipt src="HTTP://bs.servingsys.
com/BurstingPipe/ActivityServer.bs?cn=as&amp;ActivityID=155779&amp;rnd=' + ebRand + '"></scr' +
	       'ipt>');
//]]>
</script>
<noscript>
<img width="1" height="1" style="border:0" src="HTTP://bs.servingsys.
com/BurstingPipe/ActivityServer.bs?cn=as&amp;ActivityID=155779&amp;ns=1"/>
</noscript>|;

$tmpl->param ( text => $text );
if($id eq 100) {
   $tmpl->param ( jscode3 => $jscode3 );
}
print $tmpl->output;
