#!/usr/local/bin/perl
#!C:\bin\perl\bin\perl.exe
#!/usr/bin/perl/
# use one of the above lines to set the path to perl on your server
##########################################################################################

#####################################################################
# get parameters from the file
open(PAR,"<param14.dat");
@params = <PAR>;
close(PAR);
foreach $line (@params) {
	@option = split(/"/,$line);
	if (@option[0] =~ 'method') {$method = @option[1]}

	if (@option[0] =~ 'colortx') {$colortx = @option[1]}
	if (@option[0] =~ 'colorbg') {$colorbg = @option[1]}
	if (@option[0] =~ 'coloral') {$coloral = @option[1]}
	if (@option[0] =~ 'colorvl') {$colorvl = @option[1]}
	if (@option[0] =~ 'sizetx') {$sizetx = @option[1]}
	if (@option[0] =~ 'nametx') {$nametx = @option[1]}
	if (@option[0] =~ 'pathcgi') {$pathcgi = @option[1]}
	if (@option[0] =~ 'pathdata') {$pathdata = @option[1]}
	if (@option[0] =~ 'pathmail') {$pathmail = @option[1]}
	if (@option[0] =~ 'urlcgi') {$urlcgi = @option[1]}
	if (@option[0] =~ 'urldata') {$urldata = @option[1]}
	if (@option[0] =~ 'htmlfoot') {$htmlfoot = @option[1]}
	if (@option[0] =~ 'htmlhead') {$htmlhead = @option[1]}
	if (@option[0] =~ 'title') {$title = @option[1]}
	if (@option[0] =~ 'welcome') {$welcome = @option[1]}
	if (@option[0] =~ 'confirm') {$confirm = @option[1]}
	if (@option[0] =~ 'emailstep') {$emailstep = @option[1]}
	if (@option[0] =~ 'emailsent') {$emailsent = @option[1]}
	if (@option[0] =~ 'hellotext') {$hellotext = @option[1]}

	if (@option[0] =~ 'priority') {$priority = @option[1]}
	if (@option[0] =~ 'status') {$status = @option[1]}
	if (@option[0] =~ 'category') {$category = @option[1]}
	if (@option[0] =~ 'products') {$products = @option[1]}
	if (@option[0] =~ 'message') {$message = @option[1]}

	if (@option[0] =~ 'submit') {$submit = @option[1]}
	if (@option[0] =~ 'mailto') {$mailto = @option[1]}
	if (@option[0] =~ 'subject') {$subject = @option[1]}

	if (@option[0] =~ 'showip') {$showip = @option[1]}
}


#####################################################################
# get user-defined html for header footer and message
open(HD,"<$htmlhead");
@head = <HD>;
close(HD);
open(FT,"<$htmlfoot");
@foot = <FT>;
close(FT);
open(HE,"<$hellotext");
@hello = <HE>;
close(HE);

$ft = "<FONT FACE=\"$nametx\" COLOR=\"$colortx\" SIZE=\"$sizetx\">";

##########################################################################################
# print the support form

print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>\n";
print " $title\n";
print "</TITLE>\n";
print "</HEAD>\n";

#print header
foreach $linehd (@head) {
	print "$linehd\n";
}


print "<BODY BGCOLOR=\"$colorbg\">\n";
print "$ft\n";

print " <P ALIGN=\"left\">\n";


##########################################################################################

&date;

read(STDIN, $input,$ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $input);
foreach $pair (@pairs) {
	($name, $value) = split(/=/, $pair);
	$name =~ tr/+/ /;
	$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	$value =~ tr/+/ /;
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	$IN{$name} = $value;
}

if ($IN{'inc_who'} eq '') {
	print "You left the <I>Your Name</I> field blank. Click BACK on your browser and try again.<BR><BR>\n";
	#print footer
	foreach $lineft (@foot) {
		print "$lineft\n";
	}
	print "</BODY>\n</HTML>\n";
	exit;
}
if ($IN{'inc_com'} eq '') {
	print "You left the <I>Your Company</I> field blank. Click BACK on your browser and try again.<BR><BR>\n";
	#print footer
	foreach $lineft (@foot) {
		print "$lineft\n";
	}
	print "</BODY>\n</HTML>\n";
	exit;
}
if ($IN{'inc_pho'} eq '') {
	print "You left the <I>Your Telephone</I> field blank. Click BACK on your browser and try again.<BR><BR>\n";
	#print footer
	foreach $lineft (@foot) {
		print "$lineft\n";
	}
	print "</BODY>\n</HTML>\n";
	exit;
}
if ($IN{'inc_mai'} eq '') {
	print "You left the <I>Your E-Mail</I> field blank. Click BACK on your browser and try again.<BR><BR>\n";
	#print footer
	foreach $lineft (@foot) {
		print "$lineft\n";
	}
	print "</BODY>\n</HTML>\n";
	exit;
}
if ($IN{'inc_reg'} eq '' || $IN{'inc_reg'} eq '--- Select A Category ---') {
	print "You left the <I>Regarding</I> field blank. Click BACK on your browser and try again.<BR><BR>\n";
	#print footer
	foreach $lineft (@foot) {
		print "$lineft\n";
	}
	print "</BODY>\n</HTML>\n";
	exit;
}
if ($IN{'inc_des'} eq '') {
	print "You left the <I>Message</I> field blank. Click BACK on your browser and try again.<BR><BR>\n";
	#print footer
	foreach $lineft (@foot) {
		print "$lineft\n";
	}
	print "</BODY>\n</HTML>\n";
	exit;
}


#####################################################################
# log it
unless ($IN{'inc_mai'} =~ /^[\w-.]+\@[\w-.]+$/) {
	print "\"$IN{'inc_mai'}\" is not a valid e-mail address. Please go BACK and try again.<BR><BR>\n";
	exit;
}
$time = localtime;
$date;
open(NUMR,"<$pathdata/tracking.txt");
$lognumber = <NUMR>;
close(NUMR);
$lognumber++;
open(NUMW,">$pathdata/tracking.txt");
print NUMW "$lognumber";
close(NUMW);

print "$ft\n";
print "<B><I>LOG NUMBER</B></I><BR><BR>\n";
print "Your tracking number for this request is <B>$lognumber.</B>\n";
print "Please refer to this number if you contact us regarding this request.<BR><BR><HR>\n";

if ($submit eq 'file' || $submit eq 'both') {
	open(XL,">>$pathdata/support.txt");
	print XL "$lognumber~|";
	print XL "$IN{'inc_who'} |$IN{'inc_com'} |$IN{'inc_pho'} |$IN{'inc_mai'} |";
	print XL "$IN{'inc_reg'} |$IN{'inc_des'} |";
	print XL "$IN{'inc_sta'} |$IN{'inc_pri'} |$IN{'inc_cat'} |$ENV{'REMOTE_ADDR'} |";
	print XL "$date |\n";
	close(XL);


	print "<B><I>WEB FORM LOGGED</B></I><BR><BR>\n";
	print "$confirm<BR><BR>\n";
	$confirm = "";

	if ($submit eq 'file') {
		#print footer
		foreach $lineft (@foot) {
			print "$lineft\n";
		}
		print "</BODY>\n</HTML>\n";
		exit;
	}
}

if ($submit eq 'mail' || $submit eq 'both') {
	
	print "<HR>\n";
	if ($method eq 'wsendmail' || $method eq 'formmail') {
		print "$ft\n";
		print "<B><I>SEND EMAIL</B></I><BR><BR>\n";
		print "$emailstep\n";
		print "<br>\n";
		print "</FONT>\n";
	}
	#unix sendmail method fields
	if ($method eq 'sendmail') {
		open (MAIL, "| $pathmail") || print "Can't open $pathmail\n";
		print MAIL "To: $mailto\n";
		print MAIL "From: $IN{'inc_mai'}\n";
		print MAIL "cc: $IN{'inc_mai'}\n";
		print MAIL "Subject: $subject \#$lognumber\n";
		foreach $linehe (@hello) {
			print MAIL "$linehe\n";
			}
		print MAIL "Reported By: $IN{'inc_who'} ($ENV{'REMOTE_ADDR'} $time)\n";
		print MAIL "E-Mail: $IN{'inc_mai'}\n";
		print MAIL "Phone: $IN{'inc_pho'}\n";
		print MAIL "Organization: $IN{'inc_com'}\n\n";
		print MAIL "Status: $IN{'inc_sta'}\n";
		print MAIL "Priority: $IN{'inc_pri'}\n";
		print MAIL "Category: $IN{'inc_cat'}\n\n";
		print MAIL "Message: $IN{'inc_des'}\n\n";
		close (MAIL);

		print "<B><I>EMAIL MESSAGE SENT</B></I><BR><BR>\n";
		print "$emailsent\n";
		print "<BR>\n";
  	}
	print "<BR>\n";
	print "<TABLE>\n";
	print " <TR>\n";
	print "  <TD>\n";
	print "   $ft\n";
	print "    To:\n";
	print "   </FONT>\n";
	print "  </TD>\n";
	print "  <TD>\n";
	print "   $ft\n";
	print "    $mailto\n";
	print "   </FONT>\n";
	print "  </TD>\n";
	print " </TR>\n";
	print " <TR>\n";
	print "  <TD>\n";
	print "   $ft\n";
	print "    cc:\n";
	print "   </FONT>\n";
	print "  </TD>\n";
	print "  <TD>\n";
	print "   $ft\n";
	print "    $IN{'inc_mai'}\n";
	print "   </FONT>\n";
	print "  </TD>\n";
	print " </TR>\n";
	print " <TR>\n";
	print "  <TD>\n";
	print "   $ft\n";
	print "    From:\n";
	print "   </FONT>\n";
	print "  </TD>\n";
	print "  <TD>\n";
	print "   $ft\n";
	print "    $IN{'inc_mai'}\n";
	print "   </FONT>\n";
	print "  </TD>\n";
	print " </TR>\n";
	print " <TR>\n";
	print "  <TD>\n";
	print "   $ft\n";
	print "    Subject:\n";
	print "   </FONT>\n";
	print "  </TD>\n";
	print "  <TD>\n";
	print "   $ft\n";
	print "    $subject \#$lognumber\n";
	print "   </FONT>\n";
	print "  </TD>\n";
	print " </TR>\n";

	print " <TR>\n";
	print "  <TD>\n";
	print "   $ft\n";
	print "    Message:\n";
	print "   </FONT>\n";
	print "  </TD>\n";
	print "  <TD>\n";
	print "   $ft\n";
	print "    $IN{'inc_des'}\n\n";
	print "   </FONT>\n";
	print "  </TD>\n";
	print " </TR>\n";

	print " </TR>\n";
	print "</TABLE><BR>\n";

	#windows wsendmail method fields
	if ($method eq 'wsendmail') {
		print "<FORM METHOD=\"POST\" ACTION=\"$pathmail\">\n";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"RCPT\" VALUE=\"$mailto\">\n";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"from\" VALUE=\"$IN{'inc_mai'}\">\n";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"subject\" VALUE=\"$subject \#$lognumber\">\n";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Hello $IN{'inc_who'}\" VALUE=\"@hello\">\n";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"CONTENTS\" VALUE=\"$IN{'inc_des'}\">\n";

		print " <INPUT TYPE=\"HIDDEN\" NAME=\"FORM FIELDS\" VALUE=\" \">";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Reported By\" VALUE=\"$IN{'inc_who'} ($ENV{'REMOTE_ADDR'} $time)\"\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"E-Mail\" VALUE=\"$IN{'inc_mai'}\"\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Phone\" VALUE=\"$IN{'inc_pho'}\"\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Organization\" VALUE=\"$IN{'inc_com'}\"\n\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Status\" VALUE=\"$IN{'inc_sta'}\"\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Priority\" VALUE=\"$IN{'inc_pri'}\"\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Category\" VALUE=\"$IN{'inc_cat'}\"\n\n>";

		#button
		print " <INPUT TYPE=\"SUBMIT\" VALUE=\"Send Email\">\n";
		print "</FORM>\n";
		print "<BR>\n";
	}
	#unix formmail method fields
	if ($method eq 'formmail') {
		print "<FORM METHOD=\"POST\" ACTION=\"$pathmail\">\n";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"recipient\" VALUE=\"$mailto\">\n";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"email\" VALUE=\"$IN{'inc_mai'}\">\n";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"realname\" VALUE=\"$IN{'inc_who'}\">\n";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"subject\" VALUE=\"$subject \#$lognumber\">\n";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"CONTENTS\" VALUE=\"$IN{'inc_des'}\">\n";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"redirect\" VALUE=\"$urlcgi/red14.pl\">\n";

		print " <INPUT TYPE=\"HIDDEN\" NAME=\"FORM FIELDS\" VALUE=\" \">";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Reported By\" VALUE=\"$IN{'inc_who'} ($ENV{'REMOTE_ADDR'} $time)\"\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"E-Mail\" VALUE=\"$IN{'inc_mai'}\"\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Phone\" VALUE=\"$IN{'inc_pho'}\"\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Organization\" VALUE=\"$IN{'inc_com'}\"\n\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Status\" VALUE=\"$IN{'inc_sta'}\"\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Priority\" VALUE=\"$IN{'inc_pri'}\"\n>";
		print " <INPUT TYPE=\"HIDDEN\" NAME=\"Category\" VALUE=\"$IN{'inc_cat'}\"\n\n>";

		#button
		print " <INPUT TYPE=\"SUBMIT\" VALUE=\"Send Email\">\n";
		print "</FORM>\n";
		print "<BR>\n";
	}

	print "<HR>\n";

}

# beg ad tag
print "$ft\n";
print " <small class=small>\n";
print "  <BR>\n";
print "  Form and scripts provided by <a href=\"http://www.softopia.com\">www.softopia.com</a>.<br>\n";
print "  iTrack v1.4 copyright © 1996-2000\n";
print "  <BR>\n";
print " </small>\n";
print "</FONT>\n";
# end ad tag
foreach $lineft (@foot) {
	print "$lineft\n";
}
print "</BODY>\n</HTML>\n";



#####################################################################
# get the time
sub date {
   ($sec,$min,$hour,$mday,$month,$year) = localtime(time);

   if ($sec < 10) {
      $sec = "0$sec";
   }
   if ($min < 10) {
      $min = "0$min";
   }
   if ($hour < 10) {
      $hour = "0$hour";
   }

   $year = $year + 1900;
   $month = $month + 1;
   $date = "$month-$mday-$year $hour\:$min\:$sec";
   chop($date) if ($date =~ /\n$/);

   $time = time();
   
}
