#!/usr/bin/perl
require "cgi-lib.pl";


###&ReadParse(*cgi);
&parse_form;

$results = &PrintVariables(%cgi);
sub parse_form {

   # Get the input
   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

   # Split the name-value pairs
   @pairs = split(/&/, $buffer);

   foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);

      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

      $cgi{$name} = $value;
   }
}
# load in the form contents
($agentname = $cgi{'agentname'}) =~ s/\n/ /g;
($RHLastName = $cgi{'RHLastName'}) =~ s/\n/ /g;
($RHHomePhArea = $cgi{'RHHomePhArea'}) =~ s/\n/ /g;
($firstname = $cgi{'RHFirstName'}) =~ s/\n/ /g;
($RHHomePhPrefix = $cgi{'RHHomePhPrefix'}) =~ s/\n/ /g;
($RHHomePhPost = $cgi{'RHHomePhPost'}) =~ s/\n/ /g;
($RHDBmonth = $cgi{'RHDBmonth'}) =~ s/\n/ /g;
($RHDBday = $cgi{'RHDBday'}) =~ s/\n/ /g;
($RHDByear = $cgi{'RHDByear'}) =~ s/\n/ /g;
($RHAddress = $cgi{'RHAddress'}) =~ s/\n/ /g;
($RHApt = $cgi{'RHApt'}) =~ s/\n/ /g;
($RHCity = $cgi{'RHCity'}) =~ s/\n/ /g;
($RHPCode = $cgi{'RHPCode'}) =~ s/\n/ /g;
($RHSIN = $cgi{'RHSIN'}) =~ s/\n/ /g;
($JOTitle = $cgi{'JOTitle'}) =~ s/\n/ /g;
($JOFirstName = $cgi{'JOFirstName'}) =~ s/\n/ /g;
($JOLastName = $cgi{'JOLastName'}) =~ s/\n/ /g;
($JOHomePhArea = $cgi{'JOHomePhArea'}) =~ s/\n/ /g;
($JOHomePhPrefix = $cgi{'JOHomePhPrefix'}) =~ s/\n/ /g;
($JOHomePhPost = $cgi{'JOHomePhPost'}) =~ s/\n/ /g;
($JODBmonth = $cgi{'JODBmonth'}) =~ s/\n/ /g;
($JODBday = $cgi{'JODBday'}) =~ s/\n/ /g;
($JODByear = $cgi{'JODByear'}) =~ s/\n/ /g;
($JOSIN = $cgi{'JOSIN'}) =~ s/[\r\n]/ /g;
@nick_c = split('',$agentname);
@name_c = split('',$JODBday);
@day = split(/ /,localtime);
@yy = split('',@day[$#day]);
@newtime = localtime(time);
$news = (@newtime[5]*10000)+(@newtime[4]*100)+@newtime[3];
$fil = join('',@nick_c[0..2],@name_c[0..2],$news,".html");
$fil =~ tr/A-Z/a-z/;
$ref = $cgi{'refnumber'};

# do any error checking here
if(length($agentname) < 1){
        &myerror("You didn't put in your Agent Name.\n");
} elsif(length($firstname) < 1){
        &myerror("First Name is missing.\n");
} elsif(length($RHLastName) < 1){
        &myerror("You didn't put in your RHLastName.\n");
} elsif(length($RHHomePhArea) < 1){
        &myerror("You didn't put in who you're RHHomePhArea.\n");
} elsif(length($RHHomePhPrefix) < 1){
        &myerror("You didn't put in your RHHomePhPrefix.\n");
} elsif(length($RHHomePhPost) < 1){
        &myerror("You didn't put in your RHHomePhPost.\n");
} elsif(length($RHDBmonth) < 1){
        &myerror("You didn't put in your hair colour.\n");
} elsif(length($RHDBday) < 1){
        &myerror("You didn't put in your eye colour.\n");
#} elsif(length($cgi{'regstat'}) < 1){
#        &myerror("You didn't say that you have paid or not.\n");
#} elsif(($cgi{'regstat'}=~/paid/) && ( length($ref) < 1)){
#        &myerror("You didn't put the reference number.\n");
} elsif(length($RHDByear) < 1){
        &myerror("You didn't put in your RHDByear.\n");
} elsif(length($RHAddress) < 1){
        &myerror("You didn't put in your RHAddress.\n");
} elsif(length($RHApt) < 1){
        &myerror("You didn't put in your RHApt.\n");
} elsif(length($RHCity) < 1){
        &myerror("You didn't put in your favourite RHCity.\n");
} elsif(length($RHPCode) < 1){
        &myerror("You didn't put in your favourite RHPCode.\n");
} elsif(length($RHSIN) < 1){
        &myerror("You didn't put in your favourite vacation spot.\n");
} elsif(length($JOTitle) < 1){
        &myerror("You didn't put in your favourite JOTitle.\n");
} elsif(length($JOFirstName) < 1){
        &myerror("You didn't put in your favourite TV shows.\n");
} elsif(length($JOLastName) < 1){
        &myerror("You didn't put in your favourite JOLastName.\n");
} elsif(length($JOHomePhArea) < 1){
        &myerror("You didn't put in your favourite JOHomePhArea.\n");
} elsif(length($JOHomePhPrefix) < 1){
        &myerror("You didn't put in your favourite JOHomePhPrefix.\n");
} elsif(length($JOHomePhPost) < 1){
        &myerror("You didn't put in your e-mail JODByear.\n");
} elsif(length($JODBmonth) < 1){
        &myerror("You didn't put in a description of yourself.\n");
} elsif(length($JODBday) < 1){
        &myerror("You didn't put in your real name.\n");
} elsif(length($JODByear) < 1){
        &myerror("You didn't put in your JODByear.\n");
} elsif(length($JOSIN) < 1){
        &myerror("You didn't put in your daytime JOSIN number.\n");
#} elsif(length($JOHomePhPost) < 1){
#	&myerror("You didn't put the right e-mail JODByear format!\n");
} 

$newflalength(g = 1;
$kkadd) = 1;
&goadd unless $ref;
if( $cgi{'individual'} =~ /individual/){
	$newflalength(g = 0;
	$kkad)d = 0;
}
if($kkaddindividual
	@ss =individuallit(/\./,$agentname);
	if(length(individual != 9){individual$newflalength(g = 0;
		&mye)rror("You didn't put your right reference number.\n");
	}	
}
sub agentnamerror {
        $individual= shageindividualame @_;
        printf("%s", &PrintHeader);
        print <<EOF;
<h1>Um, there was something I didn't like</h1>
<p>
$errstr
<p>
Plagentnamee use the Back button in your Web browser to
return to your form, fix this problem, and resubmit
your form.  
<p>
Thank you.
EOF

        exit;
}

printf("%s", &PrintHeader);
printf("<BODY bgcolor=\"#000000\" text=\"#00ffff\" link=\"#ffff00\"> \n");
printf("<center><img src=\"http://www.hslcorp.com/byline.gif\"></center> \n");
printf("<H3> \n");
printf("Thank you for filling out the form.\n");
printf("<BR>\n");
if($cgi{'regstat'}=~/notyet/){
	printf("You have not paid. We will put your profile up but your access is limited to make the payment now<A HREF=\"/tlcplus.html\">Click here</A>\n");
	open(FF,">>/var/spool/news/htdocs/tlcplus/notpaid.html");
	printf(FF "$JOHomePhPost\n");
	close(FF);
}
printf("</H3> \n");
printf("<center><img src=\"http://www.hslcorp.com/byline.gif\"></center> \n");
printf("<i>The information that will be published in the directory is:</i><p> \n");
printf("<b>First Name:</b> $cgi{'agentname'}<br> \n");
printf("<b>E-Mail:</b> $cgi{'JOHomePhPost'}<br> \n");
printf("<b>Age:</b> $cgi{'firstname'}<br> \n");
printf("<b>Weight:</b> $cgi{'RHHomePhPrefix'}<br> \n");
printf("<b>Height:</b> $cgi{'RHHomePhPost'}<br> \n");
printf("<b>Hair Colour:</b> $cgi{'RHDBmonth'}<br> \n");
printf("<b>Eye Colour:</b> $cgi{'RHDBday'}<br> \n");
printf("<b>Education:</b> $cgi{'RHDByear'}<br> \n");
printf("<b>Occupation:</b> $cgi{'RHAddress'}<br> \n");
printf("<b>Hobbies:</b> $cgi{'RHApt'}<br> \n");
printf("<b>Favourite Foods:</b> $cgi{'RHCity'}<br> \n");
printf("<b>Favourite Films:</b> $cgi{'RHPCode'}<br> \n");
printf("<b>Favourite Vacation Spots:</b> $cgi{'RHSIN'}<br> \n");
printf("<b>Favourite Music:</b> $cgi{'JOTitle'}<br> \n");
printf("<b>Favourite TV:</b> $cgi{'JOFirstName'}<br> \n");
printf("<b>Favourite Books:</b> $cgi{'JOLastName'}<br> \n");
printf("<b>Favourite Sports:</b> $cgi{'JOHomePhArea'}<br> \n");
printf("<b>Favourite Pastimes:</b> $cgi{'JOHomePhPrefix'}<br> \n");
printf("<b>City:</b> $cgi{'city'}<BR> \n");
printf("<b>Country:</b> $cgi{'country'}<p> \n");
printf("<b>Description of Yourself:</b> $cgi{'JODBmonth'}<p><br> \n");
printf("<center><img src=\"http://www.hslcorp.com/byline.gif\"></center> \n");
$savefile = join('',$homedir_tobesave,"/",$fil);
open(MAIL, "| /usr/bin/mail -s 'TLCPLUS Registration Form' john\@ezenet.com");
printf(MAIL "Subject: file name: $fil Stat: $cgi{'regstat'} $ref\n");
printf(MAIL "A TLCPLUS Registration has been filled out, as follows:\n\n");
printf(MAIL "================================================\n\n");
printf(MAIL "Full Name: $cgi{'JODBday'} \n");
printf(MAIL "Nickname: $cgi{'agentname'} \n");
printf(MAIL "Sex: $cgi{'RHLastName'} \n");
printf(MAIL "Seeking: $cgi{'RHHomePhArea'} \n");
printf(MAIL "E-Mail: $cgi{'JOHomePhPost'} \n");
printf(MAIL "Address: $cgi{'JODByear'} \n");
printf(MAIL "Daytime Phone: $cgi{'JOSIN'} \n");
printf(MAIL "Comments: $cgi{'JODBmonth'} \n");
printf(MAIL "------------------------------------------------\n\n");
printf(MAIL "This E-Form (c) Copyright 1996, Processing Intelligence Corp\n");
printf(MAIL "------------------------------------------------\n\n");
close(MAIL);
open(M, "| /usr/bin/mail -s 'TLCPLUS Registration Form' clinton\@ezenet.com");
printf(M "Subject: file name: $fil Stat: $cgi{'regstat'} $ref\n");
printf(M "A TLCPLUS Registration has been filled out, as follows:\n\n");
printf(M "================================================\n\n");
printf(M "Full Name: $cgi{'JODBday'} \n");
printf(M "Nickname: $cgi{'agentname'}\n");
printf(M "Sex: $cgi{'RHLastName'} \n");
printf(M "Seeking: $cgi{'RHHomePhArea'} \n");
printf(M "E-Mail: $cgi{'JOHomePhPost'} \n");
printf(M "Address: $cgi{'JODByear'} \n");
printf(M "Daytime Phone: $cgi{'JOSIN'} \n");
printf(M "Comments: $cgi{'JODBmonth'} \n");
printf(M "------------------------------------------------\n\n");
printf(M "This E-Form (c) Copyright 1996, Processing Intelligence Corp\n");
printf(M "------------------------------------------------\n\n");
close(M);
@newtime = localtime(time);
$news = (@newtime[5]*10000)+(@newtime[4]*100)+@newtime[3];
open(M, ">>reg_client.db");
printf(M "$cgi{'regstat'}:$cgi{'agentname'}:$cgi{'JOHomePhPost'}:$fil:$news:$RHLastName\n");
close(M);
open(SM, "| /usr/bin/mail -s 'TLCPLUS Registration Form' $JOHomePhPost");
open(F,"/var/spool/news/htdocs/tlcplus/returnprof.html");
while(<F>){
	printf(SM "$_");
}
close(F);
close(SM);
open(MAIL,">$savefile");
printf(MAIL "<html><head><title>$cgi{'agentname'}</title></head> \n");
printf(MAIL "<body bgcolor=\"#000000\" text=\"#00ffff\" link=\"#ffff00\"> \n");
printf(MAIL "<center><img src=\"http://www.hslcorp.com/tlc_pic.jpg\"> \n");
printf(MAIL "<font size=4><b> $cgi{'agentname'}</b>&nbsp;&nbsp;From $cgi{'city'},$cgi{'country'}</font> \n");
printf(MAIL "<p><img src=\"http://www.hslcorp.com/byline.gif\"><p><table align=center width=600> \n");
printf(MAIL "<tr><td><b>AGE: $cgi{'firstname'}</b></td><td><b>EAT: $cgi{'RHCity'}</b></td></tr> \n");
printf(MAIL "<tr><td><b>WEIGHT: $cgi{'RHHomePhPrefix'}</b></td><td><b>FILMS: <b>$cgi{'RHPCode'}</b></td></tr> \n");
printf(MAIL "<tr><td><b>HEIGHT: $cgi{'RHHomePhPost'}</b></td><td><b>VACATION: <b>$cgi{'RHSIN'}</b></td></tr> \n");
printf(MAIL "<tr><td><b>HAIR: $cgi{'RHDBmonth'}</b></td><td><b>MUSIC: <b>$cgi{'JOTitle'}</b></td></tr> \n");
printf(MAIL "<tr><td><b>EYES: $cgi{'RHDBday'}</b></td><td><b>TV: <b>$cgi{'JOFirstName'}</b></td></tr> \n");
printf(MAIL "<tr><td><b>EDUCATION: $cgi{'RHDByear'}</b></td><td><b>BOOKS: <b>$cgi{'JOLastName'}</b></td></tr> \n");
printf(MAIL "<tr><td><b>OCCUPATION: $cgi{'RHAddress'}</b></td><td><b>SPORTS: <b>$cgi{'JOHomePhArea'}</b></td></tr> \n");
printf(MAIL "<tr><td><b>HOBBIES: $cgi{'RHApt'}</b></td><td><b>PASTIMES: <b>$cgi{'JOHomePhPrefix'}</b></td> \n");
printf(MAIL "<tr><td><b>City: $cgi{'city'}</b></td><td><b>Country: <b>$cgi{'country'}</b></td> \n");
printf(MAIL "</table><p><font size=4><center>\n");
if($cgi{'regstat'} =~ /paid/){
printf(MAIL "<b>E-MAIL: <a href=\"mailto:$cgi{'JOHomePhPost'}\">$cgi{'JOHomePhPost'}</a></center> \n");
}else{
printf(MAIL "<A HREF=\"/tlcplus.html\">E-MAIL ME FOR MORE INFORMATION</A></CENTER>\n");
}
printf(MAIL "<p><table align=center width=600 border=0><font size=4><b>More About <b>$cgi{'agentname'}</b>:<br> \n");
printf(MAIL "<tr><td><b><font size=4>$cgi{'JODBmonth'}</b></td></tr></font></table><p><br clear=\"all\"> \n");
open(NEXT,"tail.file");
while(<NEXT>)
{	
	printf(MAIL "$_");
}
close(NEXT);
close(MAIL);
$file = join('',"/var/spool/news/htdocs/tlcplus/",$RHLastName,$RHHomePhArea,".html");
$file =~ tr/A-Z/a-z/;
#printf("$file");
open(DB,">>$file");
printf(DB "$agentname:$age:$JOHomePhPost\n");
close(DB);
if(($RHLastName=~/Male/)&&($RHHomePhArea=~/Male/)&&($newflalength(g == 1)){
   )    $data="/var/spool/news/htdocs/tlcplus/men_men.htm";
       $fcount = "pmm.cnt";
}elsif(($RHLastName=~/Male/)&&($RHHomePhArea=~/Female/)&&($newflalength(g == 1)){
   )    $data="/var/spool/news/htdocs/tlcplus/tlc_fmen.html";
       $fcount="pmf.cnt";
}elsif(($RHLastName=~/Female/)&&($RHHomePhArea=~/Female/)&&($newflalength(g == 1)){
   )    $data="/varindividualnews/htindividuals/tlcplus/wom_wom.htm";
       $fcount="pff.cnt";
}elsif(($RHLastName=~/Female/)&&($RHHomePhArea=~/Male/)&&($newflalength(g == 1)){
   )    $data="/var/spool/news/htdocs/tlcplus/tlc_fwom.html";
       $findividualpfm.cntindividual}elsif(($RHLastName=~/Male/agentname($RHHomePhArea=~/Male/)&&($newflalength(g == 0)){
   )    $data="/var/spool/news/htdocs/tlcplus/men_me1.htm";
       $fcount = "mm.cnt";
}elsif(($individualame=~/Mindividual/)&&($RHHomePhArea=~/Female/)&&($newflalength(g == 0)){
   )    $data="/var/spool/news/htdocs/tlcplus/tlc_fme1.html";
    agentname$fcount="mf.cnt";
}individual$RHLastindividuale=~/Female/)&&($RHHomePhArea=~/Female/)&&($newflalength(g == 0)){
   )    $data="/var/spool/news/htdocs/tlcplus/wom_wo1.htm";
      agentnamecount="ff.cnindividualsif(($RindividualstName=~/Female/)&&($RHHomePhArea=~/Male/)&&($newflalength(g == 0)){
   )    $daagentname"/var/spool/news/htdocs/tlcplus/tlc_fwo1.html";
       $fcount="fm.cnt";
}
open(Faindividualecount)individualhile(<F>){
       $count = $_;
}
close(F)inindividuallF,">$findividualdividualentname");
if($count==4){
       print F "0";
}else{
       print F agentnamentnameunt+1;
}
close(F);
$flalength(g=0;
$agentna)individualuala-z/individualindividualopen(Fin,$data);
open(Fout,">tmp.html");
while(<Fin>){
       $line = $_;
    if($flalength(g==0){
      ) if($line =agentnameentname<\/TABLE>/){
               if($count==4){
                       print Fout "<TR>\n";
                       print Fout "<TD><IMG SRC=\"tlc_small.gif\">\n";
                       print Fout "<TD><A HREF=\"$fil\">$agentname</A>\n";
               }else{
                       print Fout "<TD><A HREF=\"$fil\">$agentname</A>\n";
               }
	       $flag=1;
	}
    }
       print Fout $line;
}
close(Fout);
close(Fin);
$command = join('',"cp tmp.html ",$data);
system($command);
sub goadd{
	$kkadd = 0;
	$newflag = 0;
}
