#!/usr/bin/perl

# compare.cgi - Forwarding Comparison Chart using MySQL

use CGI qw/:standard/;
use DBI;


  print header;

  init();

  &include("../include/header.2017.inc");

  print <<"  EOP";
  <div class="page-content">
  <div class="title">Forwarding Service Comparison</div><p />
  EOP

  $select = qq{
    SELECT service, setup, web, email, total, url
    FROM $table
    ORDER BY $orderby
  };

  $sth = $dbh->prepare($select);
  $sth->execute;

  print <<"  EOP";
  <table border="1" bgcolor="#FCFCE1" 
    width="100%" cellspacing="2" cellpadding="2">
    <tr>
      <th align=center bgcolor="#EDE38C">
        <font  size="-1">Service Name</font></th>
      <th align=center bgcolor="#EDE38C">
        <font size="-1">Setup Fee</font></th>
      <th align=center bgcolor="#EDE38C">
        <font size="-1">Service Fee</font></th>
      <th align=center bgcolor="#EDE38C">
        <font size="-1">E-Mail Forwarding Features</font></th>
      <th align=center bgcolor="#EDE38C">
        <font size="-1">Total Cost*</font></th>
    </tr>
  EOP

  while ( ( $service, $setup, $web, $email, $total, $url )
    = $sth->fetchrow() ) {

  if ($service eq "DNS Central") {
    $bold = "<b>";
    $boldend = "</b>";
  } else {
    $bold = "";
    $boldend = "";
  }

    print <<"    EOP";
      <tr>
        <td align="left" valign="top"><font
          size="-1"> $bold $service $boldend </font></td>
        <td align=left valign=top><font
          size="-1"> $bold $setup $boldend </font></td>
        <td align=left valign=top"><font
          size="-1"> $bold $web $boldend </font></td>
        <td align=left valign=top"><font
          size="-1"> $bold $email $boldend </font></td>
        <td align=left valign=top"><font
          size="-1"> $bold $total $boldend </font></td>
      </tr>
    EOP

  }

print "</table>\n\n";
$dbh->disconnect;

  print <<"  EOP";

<p>Total Cost is based on what it would cost to get the same services that
DNS Central offers in it's basic \$19 a year forwarding service package:
web forwarding and mail forwarding to 10 unique e-mail addresses and one
catch-all address. Total Cost does not reflect one-time setup fees.</p>

<p>All information listed above is believed to be correct as of the date
it was added to the database.</p>

</div>
  EOP

&include("../include/footer.2017.inc");

exit();

# Call as: &include("path/filename");
sub include {
  local ($file) = @_;

  if (-e "$file") {
    open(INCLUDEFILE, "$file");
    while (<INCLUDEFILE>) {
      print $_;
    }
    close(INCLUDEFILE);
  }
} # sub include

sub init {

  $driver   = "mysql";
  $database = "fwd";
  $table    = "compare";
  $orderby  = "service";

  $hostname = "fwddb.daze.net";
  $user     = "fwddb";
  $password = "8Mickey9";

  $dsn = "DBI:$driver:database=$database;$hostname";
  $dbh = DBI->connect($dsn, $user, $password)
    or die "connecting : $DBI::errstr\n";

}
