#!/usr/bin/perl

# edits
# 03-06-2009  dcc;  created.

# disable print buffering.
$| = 1;

#`echo "entering vhosts/from-door-to-door.com/secure-cgi-bin/admin.pl" >> /tmp/admin.debug`;

require ("/var/www/vhosts/from-door-to-door.com/secure-cgi-bin/includes/define_initial_parameters.pl");

$network_type = $ENV{'HTTP_X_NETWORK_TYPE'};

if ($ENV{'REQUEST_URI'}) {

   $command_line_args = (split (/\?/, $ENV{'REQUEST_URI'}))[1];

   foreach $command_line_arg (split (/\+/, $command_line_args)) {

      ($command_line_arg_type, $command_line_arg_data) = split (/\:/, $command_line_arg);

      $$command_line_arg_type = $command_line_arg_data;

   }

} else {

   $command_line_args = $#ARGV + 1;

   foreach $command_line_arg (0 .. $#ARGV) {

      ($command_line_arg_type, $command_line_arg_data) = split (/\:/, $ARGV[$command_line_arg]);

      $$command_line_arg_type = $command_line_arg_data;

   }

}

if (! $save_as_spreadsheet) {

   $save_as_spreadsheet = "no";

}


if (! $module) {

   $module = "main_menu";

}

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

print "<html>\n";

if ($module eq "main_menu") {

   print "<title>From Door to Door Main Menu</title>\n";

} else {

   print "<title>From Door to Door $module_titles{$module}</title>\n";

}

print "<head>\n";

print "<link rel=\"stylesheet\" href=\"http://from-door-to-door.com/css/main.css\"  type=\"text/css\" />\n";

print "</head>\n";

print "<body bgcolor=white>\n";

if (! $ih) {

   $ih = "yes";

}

if ($ih eq "yes") {

   print "<div class=\"header\" style=\"background-image: url('http://from-door-to-door.com/img/header_background.jpg'); opacity: 0.75;\"><table width=100%><td style=\"text-align: left;\"><font style=\"color: #330000; font-weight: bold; font-size: 36; font-family: perpetua; font-variant: small-caps;\">From Door to Door</font><font style=\"color: #ffffcc; font-weight: bold; font-size: 20;\">Door Restoration and Refinishing Specialists</font><br><font style=\"color: #ffffcc; font-weight: bold; font-size: 20;\">19 Oak Grove Way, Slidell, LA 70458</font></td><td style=\"text-align: right;\"><font style=\"color: #ffffcc; font-weight: bold; font-size:24;\">Phone 985.643.8355<br>Cell 985.710.0700</font></td></tr></table></div>\n";

   chop ($date = `date '+%A %B %e, %Y'`);

   print "<div class=\"navigation\"><table width=100% cellpadding=0><td style=\"vertical-align: middle; text-align: left;\"><b>&nbsp;Welcome ${user_full_name}</b></td><td style=\"vertical-align: middle; text-align: right;\"><b>$date</b>&nbsp;</td><tr></table></div>\n";

}

#`echo "module: $module" >> /tmp/admin.debug`;

#`echo "user_id: $user_id" >> /tmp/admin.debug`;

if ($module eq "main_menu") {

   #print "<div class=\"navigation\" style=\"background-image: url('/images/from-door-to-door_body_background.jpg'); background-repeat: repeat;\">\n";

   `echo "parent_dir: $parent_dir" >> /tmp/admin.debug`;

   if ($user_id eq "hradmin") {

      if ($utility_option) {

         $default_utility_option_clause = "<option value=$utility_option selected>$utility_options{$utility_option}";

      } else {

         $default_utility_option_clause = "<option value=null>Choose Utility";

      }

      print "<table align=center cellspacing=20><tr><td><a href=/secure-cgi-bin/admin.pl?module:update_customers_form><b>CUSTOMERS</b></a></td><td><a href=/secure-cgi-bin/admin.pl?module:customer_inquiries><b>CUSTOMER-INQUIRIES</b></a></td><td><form enctype=multipart/form-data action=/secure-cgi-bin/admin.pl?module:utilities method=post><select name=utility_option onChange=\"submit();\">$default_utility_option_clause$utility_options</select></form></td></tr></table>\n";

   } else {

       print "<table align=center><tr><td><b>MY SERVICES</b></td></tr></table>\n";

   }

   print "</div>\n";

} elsif ($module eq "customer_inquiries") {

   require ("$parent_dir/secure-cgi-bin/modules/customer_inquiries.pl");

} elsif ($module eq "update_customer_inquiries") {

   require ("$parent_dir/secure-cgi-bin/modules/update_customer_inquiries.pl");

} elsif ($module eq "update_customers_form") {

   require ("$parent_dir/secure-cgi-bin/modules/update_customers_form.pl");

} elsif ($module eq "update_customers") {

   require ("$parent_dir/secure-cgi-bin/modules/update_customers.pl");

} elsif ($module eq "update_customer_events_form") {

   require ("$parent_dir/secure-cgi-bin/modules/update_customer_events_form.pl");

} elsif ($module eq "update_customer_events") {

   require ("$parent_dir/secure-cgi-bin/modules/update_customer_events.pl");

} elsif ($module eq "manage_invoice") {

   require ("$parent_dir/secure-cgi-bin/modules/manage_invoice.pl");

} elsif ($module eq "create_new_invoice") {

   require ("$parent_dir/secure-cgi-bin/modules/create_new_invoice.pl");

} elsif ($module eq "update_invoice") {

   require ("$parent_dir/secure-cgi-bin/modules/update_invoice.pl");

} elsif ($module eq "utilities") {

   require ("$parent_dir/secure-cgi-bin/modules/utilities.pl");

}

print "</html>\n";
