#!/usr/bin/perl

# Set short name of category (not more 8 characters)
# Short name must be the same as name of this .pl file
# e.g. file name is health.pl, short name is health
$wallibase="http://www.tubenet.org.uk";

#$ostype="w"; 
$ostype="u"; 
#$ostype="t"; 
if ($ostype ne "w") {
require "/var/www/customers/tubenet/public_html/cgi/htmlt.pl";
 }

#Walli
$catheadt="Wanted: Tube & Pipe Machinery ";
$catname="wantmachines";

# Setting up Classified Ads options:
# seuraavalla määritellään max postings per day
$sallittu=1;

# Set the URL of the  cgi directory where script is placed
#walli
if ($ostype ne "w") {$urlbase="http://www.tubenet.org.uk/cgi/"}
if ($ostype eq "w") {$urlbase="http://k2/scripts/"}
$htmlbase="http://www.tubenet.org.uk/";

# Set the base of the path of the directory where
# all database  files will be kept.
#walli
if ($ostype ne "w") {$basepath="/var/www/customers/tubenet/public_html/cgi/datat/"}
if ($ostype eq "w") {$basepath="/inetpub/wwwroot/"}

$mailprogram = "/usr/sbin/sendmail -t";

$omaemail = "admin\@tubenet.org";


# Set expiration period ( in days)
#$exp_period="5";
$exptime=1;
$erotin="|";  
# number of Ads will be displays on each page
$hits =10;
$flflfl=1;
# Set allowing html tags in the ad , 1- yes,  0- no.
$htmltag=0;

# Set max length in brief descriptions
$maxadln=2500;

 
#How much seconds ads pages will be in cache
# You can also add to this string others tags such as 
# <meta keyword> and <title>
$scache="<meta http-equiv=\"Expires\" content=\"3000\">";
 
# Set up general html header and footer for all ad categories
$ghead=" ";
$gfoot= <<HTMLF;
<P><HR WIDTH="100%">
<CENTER><A HREF="mailto:info\@tubenet.org">email: info\@tubenet.org</A>
<BR><FONT SIZE="-1">Copyright &copy; Juha Haapala. All rights reserved.</FONT></CENTER>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<BR><BR><BR><BR><BR><BR><BR><BR><BR>.
HTMLF
 
# Type of OS ( u - Unix, w - Windows)
#Walli


# Using local time (local) or GMT time (gmt)
$localgmt="local";
 

############################################################
# Congratulations!  You've finished defining the variables.#
############################################################
&startsub;


sub pagelayout
{


&htmhead2;

print "<center>\n";
print "<TABLE WIDTH=\"510\" border=0  cellpadding=0 ><TR>\n";


print "<TD width=\"510\" VALIGN=TOP BGCOLOR=#000050 cellspacing=20>\n";
print "<BR><B>\n";
print "<font FACE=\"ARIAL, HELVETICA\" COLOR=#ffffff size=\"+2\"> \n";
print " <CENTER>$catheadt</CENTER></font>  </b>\n";
print "<BR>\n";
print "</TD></tr><tr><TD> \n";
print "<table width=\"100%\" bgcolor=#dddddd ><tr><td>\n";
print "<font FACE=\"ARIAL, HELVETICA\" COLOR=\"BLACK\"> <font size=-1>\n";
print "<b>[<a href=\"http://www.tubenet.org.uk/cgi/addmsgboard.pl?md=confirmaa&alue=usa&laji=srcm\" >Submit New Message - Click here</a>]</b>\n";
 


print "</font></font>\n";
print "</td></tr></table>\n";

print "<TABLE BORDER=0 COLS=1 WIDTH=\"100%\" bgcolor=#dddddd>\n";
print "<TR>\n";
print "<TD>\n";
print "<font FACE=\"ARIAL, HELVETICA\" COLOR=\"BLACK\" size=\"-1\">\n";
print "<b> $count Messages </b> &nbsp; &nbsp; &nbsp;\n";

print "<b>Message pages: $pagenum </B>\n";

print "</font></TD></TR></TABLE>\n";
 
#print "<TABLE COLS=2 cellspacing=5 WIDTH=\"100%\">\n";
print "$htmads\n";
#print "</td></tr></table>\n";

#print "</td></tr></table>\n";
print "</td></tr></table>\n";
print "<table width=\"510\" bgcolor=#dddddd ><tr><td>\n";
print "<font FACE=\"ARIAL, HELVETICA\" COLOR=#000000 size=\"-1\">\n";
print "<CENTER><B>Listing: $pagenum </B></CENTER>\n";
print "</font>\n";
print "</td></TR></table>\n";

 

print "$gfoot\n";
print "</center>\n";
print "</td></tr></table>";
print "</center>";
print "</td></TR></table></body></html>\n";


}

sub htmlayout
{

 
&print2;
 

$fbuff="";
&pagelayout;

}

sub adlayout
{
$htmads=$htmads.<<HTMLF;
$prior_title 

<table width="100%"   bgcolor="#ffffff" cellspacing=0 cellpadding=3>
<tr><td>
<table width="100%" border=0 cellspacing=0 cellpadding=0>
<tr><td>
<table width="100%" border=0 cellspacing=0 cellpadding=1>
<tr>
 <td bgcolor="#000050">


<B><font FACE="ARIAL, HELVETICA" size="-1" color="#ffffff"><B>
 $fields[2]$fields[14], $fields[13]</B><font color=#000050>.</font></font></B>
</td>
</tr>
</table>

<table cellspacing=0 cellpadding=0><tr VALIGN=top><td width=50 VALIGN=top>

<font FACE="ARIAL, HELVETICA" color="#aa0000" size=-2><B>ID#:</B></font>
<font FACE="ARIAL, HELVETICA"  size=-1><B>$fields[0]</B></font>


</td><td width=180 valign=top> 


<font FACE="ARIAL, HELVETICA" color="#aa0000" size=-2><B>Date posted:</B> </font> 
<font FACE="ARIAL, HELVETICA"  size=-1><B>$adf{'date'}</B></font><BR>

<font FACE="ARIAL, HELVETICA" color="#aa0000" size=-2><B>Expire date:</B> </font>
<font FACE="ARIAL, HELVETICA"  size=-1><B>$adf{'expdate'}</B></font>

</td><td valign=top>

<font FACE="ARIAL, HELVETICA" color="#aa0000" size=-2><B>Company: </B></font>
<font FACE="ARIAL, HELVETICA"  size=-1><B>$fields[12]</B></font><BR>
<font FACE="ARIAL, HELVETICA" color="#aa0000" size=-2><B>Attn:</B> </font>
<font FACE="ARIAL, HELVETICA"  size=-1><B>$fields[15]</B></font>


</td></tr></table>
 
 
<P>
<font FACE="ARIAL, HELVETICA"  size=-1>
HTMLF

$brief=$fields[7];
@brf=$brief;

#@brf=split(/%-%%/,$brief);
foreach $brf1 (@brf)
{
 if ($brf1 eq $brf[0]) {$htmads=$htmads."$brf1";}
 else {$htmads=$htmads."$brf1";}
}

$htmads=$htmads."</font><p>\n";
$htmads=$htmads. "[<a href=\"$action?$ctmd=eddelet&tuho=$fields[0]&firma=$fields[12]&\"><font size=-2 FACE=\"ARIAL, HELVETICA\"><B>Delete this Ad</B></font></a>]&nbsp; \n"; 
if ($fields[4] ne "") {$htmads=$htmads."[<a href=\"$action?$ctmd=mailaa&tietue=$fields[0]&\"  TARGET=\"_blank\"><font FACE=\"ARIAL, HELVETICA\"  size=-2 color=#aa0000><B>Email</B></font></a>]&nbsp;  \n"; }
if (($fields[6] ne "http://") && ($fields[6] ne ""))
{$htmads=$htmads. "[<a href=\"$fields[6]\"><font FACE=\"ARIAL, HELVETICA\" size=-2 color=#aa0000><B>Home</B></font></a>]&nbsp;&nbsp; \n";}
if ($fields[16] ne "") 
{$htmads=$htmads. "<font FACE=\"ARIAL, HELVETICA\"  size=-2 color=#aa0000><B>Tel:</B></font><font FACE=\"ARIAL, HELVETICA\"  size=-1><B>$fields[16]</B></font>&nbsp;&nbsp;\n";}
if ($fields[17] ne "") 
{$htmads=$htmads. "<font  FACE=\"ARIAL, HELVETICA\" size=-2 color=#aa0000><B>Fax:</B></font><font FACE=\"ARIAL, HELVETICA\"  size=-1><B>$fields[17]</B></font>\n";}

$htmads=$htmads. "</td></tr></table>\n";
$htmads=$htmads. "</td></tr></table>\n";

}

 

sub prformad
{
# Set format for two ads in the row (2) or one ads (1) in the row
$adformat=1;


if ($adformat==2)
{
if($s35 ne "1")
         {$s35="1";
      $htmads=$htmads."<TR><TD width=\"50%\" bgcolor=\"#ffffff\" VALIGN=TOP>\n";
          &printad;
          $htmads=$htmads."</TD>\n";
          }
          else
         {$s35="0";
          $htmads=$htmads."<TD width=\"50%\" bgcolor=\"#ffffff\" VALIGN=TOP>\n";
          &printad;
          $htmads=$htmads."</TD></TR>\n";
      }
}
else {&printad;}      
  }
  
sub printad
{

$idnum=$fields[0];
$adf{'title'}=$fields[2];
$adf{'date'}=date_format($fields[3]);
$adf{'email'}=$fields[4];
$adf{'expdate'}=date_format($fields[5]);
$adf{'urlpage'}=$fields[6];
$adf{'brief'}=$fields[7];
$adf{'brief'}=~ s/%-%%/ /g;
$ik=11;
if ($fields[13] ne "USA") {$fields[14]=""} else {$fields[14] = ", $fields[14]"}
&adlayout;
# tämä ei auttanu mitään print "</td></tr></table>";
}

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

sub htmend2
{

print "</td></tr></table></center>\n";

print <<HTMLF;
$stat{'blinkf'} 

$gfoot
HTMLF
print " </tr></table></body></html>\n";
}

sub welcome
{
$stat{'blinkh'}=$stat{'blinkhfr'};
$stat{'blinkf'}=$stat{'blinkffr'};
if ($GET{'md'} eq ""){&visit;}
&readcount;
$nmax=$count;
$nmin=0;
if ($count>$hits){$nmin=$count-$hits;}
&viewadd;
exit;
}

sub startsub
{

 
$stat{'expperiod'}=$exp_period;
&parse_get;
$ctmd="md";

$time_now=time; chomp($time_now);
$date_now=date_format($time_now);
$action=$urlbase.$catname.".pl";
 
$namefl=$catname;
# Names of database files that kept in the same directory
$filename =$basepath.$namefl.".dat";
$filecount =$basepath.$namefl.".cnt" ;
$filevisit =$basepath.$namefl.".cnv" ;
$temppi=$basepath.$namefl.".tmp"; 

$docpath =$photopath.$namefl;
$docurl =$photourl.$namefl;

&checkdate;
#&check_exp_date;
 
 
&refres;

&parse_form;
   
if ($GET{'md'} eq "viewadd")
{$nocache="";
$nmin=$GET{'min'};
$nmax=$GET{'max'};
&viewadd;
}

if (($GET{'md'} eq "") || ($GET{'md'} eq "md") ){ 
if ($catname eq "admin"){ return;}
&welcome; exit;}
&addstart;
}

 

sub printheader
{
print "Content-type: text/html\n\n";
}

 


sub print2
{
&readcount;
$count2=$count;
$pagenum="";
if (($stat{'adorder'} eq "1") || ($stat{'adorder'} eq "2"))
{
$pi=1;
$count1=0;
while ($count1 < $count2)
{
$idmin=$count1;
$cnt=0;
while($cnt<$hits)
{
$cnt++;
if ($count1 < $count2 ) {$count1++;}
}
$idmax=$count1;
$subinfo=$idmin." - ".$idmax;
$pagein=$pi;
if ($prst eq "prn")
{
$fact=$baseurl.$catname.+"_$pi".".html";
}
else{
$fact="$action?$ctmd=viewadd&min=$idmin&max=$idmax&";
}
$pagenum=$pagenum."<b>[<a href=\"$fact\" >-$pagein-</a>]</b>\n";
 $pi++;
}
}
else{
######################## on todennäköistä jotta se alkaa vasta täältä sillä adorderia ei taida olla määritelty yläpuolella
$pi=1;
while ($count2>=1)
{
$idmax=$count2;
$cnt=0;


while($cnt<$hits)
{
$cnt++;
if ($count2>=1) {$count2--;}
}
$idmin=$count2;
$subinfo=$idmin." - ".$idmax;
$pagein=$pi;

if ($prst eq "prn")
{
$fact=$baseurl.$catname.+"_$pi".".html";
}
else{
######################## on todennäköistä jotta se alkaa vasta täältä sillä prn ei taida olla määritelty yläpuolella

$fact="$action?$ctmd=viewadd&min=$idmin&max=$idmax&";
}
$pagenum=$pagenum."<b>[<a href=\"$fact\" >-$pagein-</a>]</b>\n";

 $pi++;
}
}
}

 
sub viewadd
{

 &viewadde;

&htmlayout;
#&printheader;
print $fbuff ;
exit;
}

 
sub viewadde
{
&readdata;
&readcount;

# seuraava on alkuperäinen rivi jonka korjasin koska toiseksi viimeisen sivun 
# viimeinen posting oli sama kuin orpona olevan viimeisen sivun.   
##while (($nmin<$nmax) || ($nmax==1))
while ($nmin<$nmax) 

{ 
$nmax--;
@fields=split(/\s*\|\s*/,$lines[$nmax] );
&prformad;
  }
}

 

sub readdata
{
  open(file, "$filename");
&lock(file);
  @lines=<file>;
&unlock(file);
  close(file);
}

 
sub refres
{
$refr=time;
 
}

 

sub readcount
{
  open (flc,"$filecount");
  &lock(flc);
  $lnc=<flc>;
  &unlock(flc);
  close(flc);
  @fdc=split(/\s*\|\s*/,$lnc);
  $count=$fdc[0];
  $idcount=$fdc[1];
  open (flc,"$filevisit");
  &lock(flc);
  $nvisit=<flc>;
  &unlock(flc);
  close(flc);
  }

sub savecnt
{
$filecount_b=$filecount."b";
open(flc, ">$filecount_b");
&lock(flc);
$reccnt=$count."|".$idcount."|";
print flc "$reccnt";
&unlock(flc);
close(flc);
unlink($filecount);
rename($filecount_b,$filecount);
}

sub writecount
{
&readcount;
$count++;
&savecnt;
}

sub writeidcount
{
&readcount;
$idcount++;
&savecnt;
}

sub delcount
{
&readcount;
#print "Laskuri on: $count";
$count--;
&savecnt;
}

sub visit
{
open (flc,"$filevisit");
  &lock(flc);
  $nvisit=<flc>;
  &unlock(flc);
  close(flc);
  $nvisit++;
  open (flc,">$filevisit");
  &lock(flc);
  print flc $nvisit;
  &unlock(flc);
  close(flc);
}

 sub lock {
$LOCK_EX=2;
  local($file)=@_;
 if ($ostype ne "w") { flock($file, $LOCK_EX); }
}


sub unlock {

$LOCK_UN=8;
  local($file)=@_;
 if ($ostype ne "w") { flock($file, $LOCK_UN); }
}

 
sub date_format
{
local(@arr1, $months);
local($year, $month, $date_f, $time1, $v1);

@months = ('January', 'February', 'March', 'April', 'May', 'June',  
		           'July', 'August', 'September', 'October', 'November',
		           'December');
$time1=$_[0];
if ($localgmt eq "local") 
{ @arr1=localtime($time1);}
else {@arr1=gmtime($time1);}
$v1=$arr1[4];
$month=$months[$v1];
if ( $arr1[5] < 90 )
{
$year=2000 + $arr1[5];
} 
else
{
$year=1900 + $arr1[5];
} 
$date_f="$month $arr1[3], $year";
return $date_f;
}


sub checkdate
{
$fldateff =$basepath.$namefl.".dtf" ;
$date_now=date_format($time_now);
open(fl2,"$fldateff");
&lock(fl2);
$dateff=<fl2>;
chomp($dateff);
&unlock(fl2);
close(fl2);
if( $dateff ne $date_now)
{
open(fl2, ">$fldateff");
&lock(fl2);
print fl2 $date_now;
&unlock(fl2);
close(fl2);
#&check_exp_date;
}
 
}

 
sub parse_get {
   # Split the name-value pairs
   @pairs = split(/&/, $ENV{'QUERY_STRING'});

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

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

      $GET{$name} = $value;

   }
}

 

sub parse_form {

   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

   @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;

      $FORM{$name} = $value;
   }
}

##########################
# Add
sub addstart
{
 
    if ($GET{'md'} eq "addad") {&addad;}
    if ($GET{'md'} eq "forget") {&forget;}
    if ($GET{'md'} eq "tarkistapvm") {&tarkistapvm;}

      
    if ($GET{'md'} eq "addform") {&addform;}
    if ($GET{'md'} eq "confirmaa") {&confirmaa;}
    if ($GET{'md'} eq "confirmaa2") {&confirmaa2;}
    if ($GET{'md'} eq "eddelet") {  &eddelet;}
   if ($GET{'md'} eq "delrecord") {&delrecord;}
   if ($GET{'md'} eq "mailaa") {&mailaa;}
 
    if ($GET{'md'} eq "edit") {&edit;}
    if ($GET{'md'} eq "editform") {&editform;}
    if ($GET{'md'} eq "loged") {&loged;}
     
    &welcome;
    exit;
}

sub check_exp_date
{
$namefl=$catname;
$filename =$basepath.$namefl.".dat";
&readcount;

#&readdata;
#$filename_b=$filename."b";
#open(file, ">$filename_b");
#&lock(file);
#foreach $line (@lines)
#{
#@fields=split(/\s*\|\s*/,$line );
#if ($fields[3] < $fields[5] ) { print file $line; }
#}
#&unlock(file);
#close(file);
#unlink($filename);
#rename($filename_b,$filename);
#&corrcount;
#$chexp1="1";
#&htmhead2;
#print"Laskuri ennen silmukkaa $count<P><BR>";

$lokaika=time;
open(file, "$filename");
&lock(file);
$nimi="temp2.txt";
open(file2, ">$nimi");
&lock(file2);


while ($line = <file>) {
	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$numcomm,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi) = split(/\s*\|\s*/, $line);
if ($lokaika lt $exptime)  {print file2 $line} else {&laheta_viesti;&delcount}
#print   "Aika nyt on $time_now eräpäivä on $exptime ja se periodi on $exp_period  ja localiaika: $lokaika<BR>";
}
&unlock(file);
close file;
&unlock(file2);
close file2;
rename($nimi,$filename);
$namefl=$catname;

}

 

sub addad
{

 if (($FORM{'passw'} eq "") || ($FORM{'title'} eq "") || ($FORM{'brief'} eq "") || ($FORM{'firma'} eq "")  ||  ($FORM{'paiva'} eq "00") ||  ($FORM{'attn'} eq "") || ($FORM{'email'} eq "")) {

 &htmhead2;
 print"<P><BR>";
 &omahead;
 print "<P><center>";
 print "<h3> Missing information</h3><HR>Check out below what fields you need to fill up.<P>";
 print "<table><tr><TD><font color=ffffff><B><UL>";
 if ($FORM{'title'} eq "") {print "<LI>Title for your article <br>" }
 if ($FORM{'brief'} eq "") {print "<LI>Your message<br>" }
 if ($FORM{'firma'} eq "") {print "<LI>Company name<br>" }
 if ($FORM{'attn'} eq "") {print "<LI>Contact person<br>" }
 if ($FORM{'email'} eq "") {print "<LI>Email address<br>" }
 if ($FORM{'passw'} eq "") {print "<LI>Password<br>" }
 if ($FORM{'paiva'} eq "00") {print "<LI>Your birthday<br>" }

 print "</UL></b></font></TD></TR></Table> <font size=-1 color=#ffff00><B>Click your browser's Back-button</B></font><P><BR>";
 print "</center>";

 &omaend;
 &htmend2;
 exit;
}

if ($FORM{'passw'} ne $FORM{'pass2'}) {
&htmhead2;
print"<P><BR>";
&omahead;
print "<P><center>";
print "<h3> The password you gave didn't match <BR>with the re-typed password. </h3><HR><P>";
print " <font size=-1 color=#ffff00><B>Click your browser's Back-button</B></font><P><BR>";
print "</center>";
&omaend;
&htmend2;
exit;
}



$ipadd2=$ENV{'REMOTE_ADDR'};
$kaynnit=0;
$lokaika=time;
open(file, "$filename");
&lock(file);
###&htmhead2;
###print   "<font color=000000>Aika nyt on $time_now lokaika on $lokaika ja se Ipnyt $ipadd2 ja tiedoston $ipadd</font><BR>";

while ($line = <file>) {
	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$numcomm,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi) = split(/\s*\|\s*/, $line);
####print   "Aika nyt on $time_now lokaika on $lokaika ja se Ipnyt $ipadd2 ja tiedoston $ipadd<BR>\n";
###################
if  (($lokaika lt $time_now+86400) and ($ipadd2 eq $ipadd)) {$kaynnit=$numcomm} 
if ($kaynnit gt $sallittu)  {close file; &message31} 
# muissa on vain tuo seuraava rivi. Tässä koitetaan tehdä mahdolliseksi enempi käyntejä kuin yksi 
#if (($lokaika lt $time_now+86400) and ($ipadd2 eq $ipadd))  {close file; &message31} 
}
###&htmend2;
&unlock(file);
close file;




# tässä alla se vanhempi mutta topimiva..perustuu vain yhteen kayntiin päivässä
#$ipadd2=$ENV{'REMOTE_ADDR'};
#
#$lokaika=time;
#open(file, "$filename");
#&lock(file);
##&htmhead2;
##print   "<font color=000000>Aika nyt on $time_now lokaika on $lokaika ja se Ipnyt $ipadd2 ja tiedoston $ipadd</font><BR>";
#
#while ($line = <file>) {
#	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$numcomm,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi) = split(/\s*\|\s*/, $line);
##print   "Aika nyt on $time_now lokaika on $lokaika ja se Ipnyt $ipadd2 ja tiedoston $ipadd<BR>\n";
#if (($lokaika lt $time_now+86400) and ($ipadd2 eq $ipadd))  {close file; &message31} 
#}
##&htmend2;
#&unlock(file);
#close file;
#








 
if ($stat{'moderat'} eq "yes"){
$filename=$moderfl;
$mad="yy";
}

if ($stat{'oneperday'} eq "yes"){&oneperday;}
 
 
&readcount;
################koitetaan vietä laskuri get recording jälkeen jos noi numerot ei kasvais niin nopeaan. Nämä siis oli ennen gettiä
#if ($stat{'moderat'} ne "yes") {&writecount;}
#&writeidcount;

#ja tähän listään yksi. Aluperäisessä ei ollu tota lisäystä.
#$idnum=$idcount;
$idnum=$idcount+1;

#$FORM{'numcomm'}=0;
$kaynnit=$kaynnit+1;

&getrecord;

&writeidcount;
if ($stat{'moderat'} ne "yes") {&writecount;}

open(file,">>$filename");
&lock(file);
print file "$record\n";
&unlock(file);
close(file);

 
&corrcount;

if ($lgfl==1){&writelog("Add New Ad<br> $FORM{'brief'}");}

if (($stat{'moderat'} ne "yes") && ($maillist==1) && ($stat{'send_each'} eq "yes")) 
{ require "a601_ml.pl"; &sendlist;}
if ($FORM{'phmore'} eq "yes")
{$aded="ad"; &photoform;}
else{
if ($stat{'moderat'} eq "yes")
{
$filecount =$basepath.$namefl.".cnt" ;
&htmhead2;
#Your ad will appears in index as soon as possible
&message40;
&printad3;
&htmend2;
} else{
#Ad has been added successfuly
&message12;
#&printad3;
 
&htmend2;

}

}
exit;
}

sub corrcount
{

$filename =$basepath.$namefl.".dat";
$filecount =$basepath.$namefl.".cnt" ;
&readdata;
&readcount;
$count=0;
foreach $line (@lines){$count++;}
&savecnt;
}

 

 

sub printad3
{
&readdata;
&readcount;
foreach $line (@lines)
{
@fields=split(/\s*\|\s*/,$line);
if ($idnum eq $fields[0]) {
print "<center> <p> <table border=\"1\"> <tr><td>\n";
&prtadinfo;
print "</td></tr></table><p></center>";
}
}
}

sub prtadinfo
{
print <<HTMLF;
<table cellpadding="6">
<tr><td>
<font FACE="ARIAL, HELVETICA"  size=-1 >
<b> title: </b>
</td><td>
 $fields[2]
 </td></tr><tr><td>
<b>ID# :</b></td><td> $fields[0]
</td></tr> 
 
HTMLF
  

print <<HTMLF;
<tr>
<!-- <td><b>
Brief description:
</b></td>
 -->
<td>
HTMLF

$brief=$fields[7];
#siivoa_kommentit(\$brief);

@brf=split(/%-%%/,$brief);
foreach $brf1 (@brf)
{
 if ($brf1 eq $brf[0]) {print "<dd>$brf1";}
 else {print  "$brf1";}
}
print "</td></tr><tr><td>\n";
 
print "<br><b> e-mail : </b> <a href=\"mailto:$fields[4]\"> $fields[4] </a>\n";
print "<br><b> Home Page : </b><a href=\"$fields[6]\"> $fields[6] </a>\n";
print "<br><b> Phone : </b> $fields[16] \n";
print "<br><b> Fax : </b> $fields[17] \n";
print "<br><b> Attn : </b>$fields[15] </font>\n";

print "</td></tr></table>\n";

}
 
sub getrecord
{
$brief=$FORM{'brief'};
$emailbrief=$brief;
#$brief=~ s/\n/%-%%/g;
$ipadd=$ENV{'REMOTE_ADDR'};
$brief=~ s/|//g;
	siivoa_kommentit(\$brief);

$idmodd="";

$time_now=time;
$exptime=$time_now + $FORM{'erapaiva'}*86400;
#$exptime=$time_now + 86400;
$tamapv=date_format($time_now);
$erapaiva=date_format($exptime);

if (($stat{'moderat'} eq "yes") && ($mad eq "yy")) {&idmdd;}
$record=$idnum."|".$FORM{'passw'}."|".$FORM{'title'}."|".$time_now."|".$FORM{'email'};
$record=$record."|".$exptime."|".$FORM{'urlpage'}."|".$brief;
$record=$record."|".$ipadd."|".$namefl."|".$kaynnit."|".$idmodd;
$record=$record."|".$FORM{'firma'}."|".$FORM{'maa'}."|".$FORM{'osavaltio'};
$record=$record."|".$FORM{'attn'}."|".$FORM{'puhelin'}."|".$FORM{'fax'}."|".$FORM{'paiva'}."|".$FORM{'kuu'}."|".$FORM{'vuosi'};




foreach $key (sort keys(%deffld))
{
$nam3=$deffld{$key}[1];
$record=$record."|".$FORM{$nam3};
}
$record=$record."|";
if ($prioryesno eq "yes") {$record=$record.$prior."|";}

&somecheck;


$viesti = "Please save this message for future use.\n";
$viesti=$viesti."This is your confirmation about successful posting to the TubeNet Message Board.\n";
$viesti=$viesti."Below please find the details of your posting.\n";
$viesti=$viesti."\n---------------------------------------------------\n";
$viesti=$viesti."Message ID# : ".$idnum."\n";
$viesti=$viesti."Your password : ".$FORM{'passw'}."\n";
$viesti=$viesti."Your birthday : ".$FORM{'paiva'}."-".$FORM{'kuu'}."-".$FORM{'vuosi'}."\n";
$viesti=$viesti."Date posted : ".$tamapv."\n";
$viesti=$viesti."Expiry date : ".$erapaiva."\n";
$viesti=$viesti."Email address : ".$FORM{'email'}."\n";
$viesti=$viesti."Web site : ".$FORM{'urlpage'}."\n";
$viesti=$viesti."Your IP address recorded : ".$ipadd."\n";
$viesti=$viesti."Company name : ".$FORM{'firma'}."\n";
$viesti=$viesti."Country : ".$FORM{'maa'}."\n";
$viesti=$viesti."State : ".$FORM{'osavaltio'}."\n";
$viesti=$viesti."Contact person : ".$FORM{'attn'}."\n";
$viesti=$viesti."Phone : ".$FORM{'puhelin'}."\n";
$viesti=$viesti."Fax : ".$FORM{'fax'}."\n\n";
$viesti=$viesti."Message title : ".$FORM{'title'}."\n";
$viesti=$viesti."Message below:\n\n";
$viesti=$viesti.$emailbrief;
$viesti=$viesti."\n---------------------------------------------------\n";
$viesti=$viesti."TubeNet - The Site for Tube and Pipe Industries\n";
$viesti=$viesti."US site: www.tubenet.org  Asia site: www.tubenet.us\n";
$viesti=$viesti."E-mail: info\@tubenet.org\n";
$viesti=$viesti."Fax: +31-20-5241239 (to Netherlands)\n";
$viesti=$viesti."Addr: Kanervatie 3, 66400 Laihia, Finland\n";
$viesti=$viesti."---------------------------------------------------\n";
#Walli
if ($ostype eq "u") {
 open (MAIL,"|$mailprogram");
   print MAIL "To: $FORM{'email'}\n";
#   print MAIL "To:  $omaemail\n";
   print MAIL "From: $omaemail\n";
   print MAIL "Subject: Your TubeNet Message Board Posting\n";
   print MAIL "$viesti\n";
  close (MAIL);

open (MAIL,"|$mailprogram");
   print MAIL "To: $omaemail\n";
   print MAIL "From: $omaemail\n";
   print MAIL "Subject: Message Board Posting\n";
   print MAIL "$viesti\n";
  close (MAIL);
}

}










sub laheta_viesti {
	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$numcomm,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi) = split(/\s*\|\s*/, $line);

$time_now=time;
$tamapaiva=date_format($time_now);
$erapaiva=date_format($exptime);
$viesti = "\n";
#$viesti =$viesti."Dear Sir/Madam,\n\n";
$viesti=$viesti."\n\nDear Sir/Madam,\n\nYour message to TubeNet Message Board has been expired \n";
$viesti=$viesti."based on the given expiry date. The summary of the message  \n";
$viesti=$viesti."can be seen below. Should you like to make a new posting,  \n";
$viesti=$viesti."please feel free to use the new and fully automatic TubeNet  \n";
$viesti=$viesti."Message Board System at: http://www.tubenet.org/marketgo.html \n\n";
$viesti=$viesti."Below the Message Summary. \n";
$viesti=$viesti."\n---------------------------------------------------\n";
$viesti=$viesti."Message ID# : ".$luku."\n";
#$viesti=$viesti."Your password : ".$pass."\n";
#$viesti=$viesti."Your birthday : ".$paiva."-".$kuu."-".$vuosi."\n";
$viesti=$viesti."Date posted : ".$tamapaiva."\n";
$viesti=$viesti."Expiry date : ".$erapaiva."\n";
$viesti=$viesti."Email address : ".$email."\n";
$viesti=$viesti."Web site : ".$urlpage."\n";
#$viesti=$viesti."Your IP address recorded : ".$ipadd."\n";
$viesti=$viesti."Company name : ".$firma."\n";
$viesti=$viesti."Country : ".$maa."\n";
$viesti=$viesti."State : ".$osavaltio."\n";
$viesti=$viesti."Contact person : ".$attn."\n";
$viesti=$viesti."Phone : ".$puhelin."\n";
$viesti=$viesti."Fax : ".$fax."\n\n";
$viesti=$viesti."Message title : ".$title."\n";
$viesti=$viesti."\n---------------------------------------------------\n";
$viesti=$viesti."TubeNet - The Site for Tube and Pipe Industries\n";
$viesti=$viesti."US site: www.tubenet.org  Asia site: www.tubenet.us\n";
$viesti=$viesti."E-mail: info\@tubenet.org\n";
$viesti=$viesti."Fax: +31-20-5241239 (to Netherlands)\n";
$viesti=$viesti."Addr: Kanervatie 3, 66400 Laihia, Finland\n";
$viesti=$viesti."---------------------------------------------------\n";
#Walli
#print $viesti;
if ($ostype eq "u") {
 open (MAIL,"|$mailprogram");
   print MAIL "To: $FORM{'email'}\n";
#   print MAIL "To:  $omaemail\n";
   print MAIL "From: $omaemail\n";
   print MAIL "Subject: Your TubeNet Message Board Posting\n";
   print MAIL "$viesti\n";
  close (MAIL);

open (MAIL,"|$mailprogram");
   print MAIL "To: $omaemail\n";
   print MAIL "From: $omaemail\n";
   print MAIL "Subject: Message Board Posting\n";
   print MAIL "$viesti\n";
  close (MAIL);
}

}






sub somecheck
{
$reclength=length($FORM{'brief'});
if ($reclength > $maxadln){
# Too large your information that it is allowed
&message29;
exit;
}


if (($FORM{'brief'} =~ /[A-Z]{7}/ ) || ($FORM{'title'} =~ /[A-Z]{7}/ ) || ($FORM{'firma'} =~ /[A-Z]{7}/ ) || ($FORM{'attn'} =~ /[A-Z]{7}/ ) ) {
# liikaa kapitaaleja
&message30;
exit;
}

if ($FORM{'email'}) { 
        unless ($FORM{'email'} =~ /[ |\t|\r|\n]*\"?([^\"]+\"?@[^ <>\t]+\.[^ <>\t][^ <>\t]+)[ |\t|\r|\n]*/) 
{
# liikaa kapitaaleja
&email30;
exit;
} }


}



sub date_format2
{
local(@arr1, $months);
local($year, $month, $date_f, $time1, $v1);

$time1=$_[0];
if ($localgmt eq "local") 
{ @arr1=localtime($time1);}
else {@arr1=gmtime($time1);}
 
$date_f="$arr1[4] arr1[5]";
return $date_f;
}



sub confirmaa
{
$ipadd=$ENV{'REMOTE_ADDR'};

$subact=$action."?$ctmd=confirmaa2";
&htmhead2;
&omahead;

print <<HTMLF;
<center><table border=0 width=400><tr><td><font face=verdana  color=ffffff>
<CENTER><B>Please read this agreement<BR> before continuing</B></CENTER><br>

<FONT SIZE="-1">
The use of TubeNet Marketplace Message Board is designed for professional
use only. All spamming and misbehave will be noticed and if necessary,
actions will be taken to eliminate any kind of misuse of this service. Therefore
please note the following:
<ol>
<li>You can post your messages free of charges until something else will be stated.
HTMLF
print "<li>You can post only $sallittu message";
if ($sallittu gt "1") {print "s"}
print " per day. ";
print "<li>Messages can be removed at any time. For security reasons, you need to enter a <font color=#ffff00> password </font> and your <font color=#ffff00>birthday</font>. ";
print "<li>Be extra careful with spelling of your <font color=#ffff00>email address</font>. Wrong email address will bring you nothing. After you have completed your message, the system will automatically send you a confirmation message by email. In case you don't receive this email, it's a sign that you have given wrong email address.";
print "<li>For protection against misuse and spamming, your server's IP address (<font color=#ffff00>$ipadd</font>) will be recorded.";
print "</ol><P>";
print "<center>Do you agree ?</center> </FONT>";
print "<center>";
print "<form action=\"$subact\" method=\"post\"><INPUT TYPE=\"submit\" value=\"Yes, I agree\"></FORM>";

$subact=$action."?$ctmd=md&$refr";
print <<HTMLF;

<form action="$subact" method="post"><INPUT TYPE="submit" value="No, I want to go back"></form>
<FONT SIZE="-1"><B>Click only once. This may take some time.</B></font><P><BR></center>
</font></TD></TR>
</TABLE></center>

HTMLF

&omaend;
&htmend2;
exit;
}






sub confirmaa2
{
$ipadd=$ENV{'REMOTE_ADDR'};

$subact=$action."?$ctmd=addform";
&htmhead2;
&omahead;

print <<HTMLF;
<center><table border=0 width=400><tr><td><font face=verdana  color=ffffff>
<CENTER><B>Tube & Pipe Producers and <BR>Machine Manufacturers</B></CENTER><br>

<FONT SIZE="-1">
<CENTER><P>Don't advertise here. <p>TubeNet Marketplace is not a place for<BR> promoting new products. Instead, you can<BR> 
 use TubeNet's Registers for <a href="http://www.tubenet.org.uk/info2_f.html"><font color=#ffff00>Tube Suppliers</font></a> <BR>and 
<a href="http://www.tubenet.org.uk/info1_f.html"><font color=#ffff00>Machine Manufacturers</font></A>.</CENTER> <P>
<!-- If you do, it only shows that you are <U>just nothing but a trouble for everyone</U> 
and something that cannot be taken seriously. <P>
 --><center>Do you agree ?</center> </FONT>
<center>
<form action="$subact" method="post"><INPUT TYPE="submit" value="Yes, I agree"></FORM>
HTMLF

$subact=$action."?$ctmd=md&$refr";
print <<HTMLF;

<form action="$subact" method="post"><INPUT TYPE="submit" value="No, I want to go back"></form>
<FONT SIZE="-1"><B>Click only once. This may take some time.</B></font><P><BR></center>
</font></TD></TR>
</TABLE></center>

HTMLF

&omaend;
&htmend2;
exit;
}












 
sub addform
{
if ($stat{'addad'} eq "members") {&addpassw;}
if ($stat{'oneperday'} eq "yes"){&oneperday;}
$subact=$action."?$ctmd=addad";
$nocashe="";
&htmhead2;


($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)= localtime(time) ;
#   $sec = "0$sec" if ($sec < 10);
#  $min = "0$min" if ($min < 10);
#   $hour = "0$hour" if ($hour < 10);
$day = "0$day" if ($day < 10);
#$month = "0$month" if ($month < 10);

$ppaiva=$day;
$pmon=$mon;
$pyear=$year;

#$exp_dt= $time_now + $stat{'expperiod'}*86400;
#$exp_date=date_format($exp_dt);
 


  print <<HTMLF;


<form action="$subact" method="post">


<center>
<table border=1 cellspacing=0  bgcolor=000050 width=70% UNITS="relative">
<tr>
<td>


<table border=1 cellspacing=0   bgcolor=000050 width=100%><tr bgcolor=505070><td bgcolor=000050 align=left><font face=verdana  color=ffffff>
<BR>
    <CENTER><font size=+2><B>Message Submit Form</B></font><BR>
<font face=helvetica size=+1 color=#ffff00><B>*</B></font> <font face=helvetica size=2 color=ffffff><B>Required information</B></font><br><BR></CENTER></font>
</td></tr></table>


<INPUT TYPE="hidden" NAME="numero" value=$luku>

<table border=1 cellspacing=0   bgcolor=000050 width=100%>

<tr bgcolor=505070><td  bgcolor=000050><font face=helvetica size=2 color=ffffff>
<B>Title for your message </B></font><font size="+1" color=#ffff00><B>*</B></font></td></tr><tr><td><font face=verdana  size=-1>
<INPUT TYPE="text" NAME="title" SIZE="60" MAXLENGTH="60"></font></td></tr></table>

<table border=1 cellspacing=0 bgcolor=000050 width=100%><tr bgcolor=505070><td  bgcolor=000050><font face=helvetica size=2 color=ffffff>
<B>Your message below.  You can "copy-paste" it from your word processing program </B></font><font size="+1"  color=#ffff00><B>*</B></font></td></tr><tr><td><font face=verdana size=-1>
<TEXTAREA NAME="brief" ROWS="8" COLS="70"></TEXTAREA>
</font></td></tr></table>




<table border=1 cellspacing=0 bgcolor=000050 width=100%>



<tr bgcolor=000050><td valign="top"><font face=helvetica size=2 color=ffffff>
<B>Company Name </B></font><font size="+1"  color=#ffff00><B>*</B></font></td><td bgcolor=000050><font face=verdana size=2><INPUT TYPE=text NAME=firma SIZE=30 MAXLENGTH="45"></font></td></tr>


<tr bgcolor=000050><td valign="top"><font face=helvetica size=2 color=ffffff>
<B>Country</B></font><font size="+1"  color=#ffff00><B>*</B></font></td><td bgcolor=000050><font face=verdana size=2><Select Value="United States" Name="maa"><OPTION VALUE="Afghanistan">Afghanistan<OPTION VALUE="Albania">Albania<OPTION VALUE="Algeria">Algeria<OPTION VALUE="American Samoa">American Samoa<OPTION VALUE="Andorra">Andorra<OPTION VALUE="Angola">Angola<OPTION VALUE="Anguilla">Anguilla<OPTION VALUE="Antarctica">Antarctica<OPTION VALUE="Antigua And Barbuda">Antigua And Barbuda<OPTION VALUE="Argentina">Argentina<OPTION VALUE="Armenia">Armenia<OPTION VALUE="Aruba">Aruba<OPTION VALUE="Australia">Australia<OPTION VALUE="Austria">Austria<OPTION VALUE="Azerbaijan">Azerbaijan<OPTION VALUE="Bahamas">Bahamas<OPTION VALUE="Bahrain">Bahrain<OPTION VALUE="Bangladesh">Bangladesh<OPTION VALUE="Barbados">Barbados<OPTION VALUE="Belarus">Belarus<OPTION VALUE="Belgium">Belgium<OPTION VALUE="Belize">Belize<OPTION VALUE="Benin">Benin<OPTION VALUE="Bermuda">Bermuda<OPTION VALUE="Bhutan">Bhutan<OPTION VALUE="Bolivia">Bolivia<OPTION VALUE="Bosnia And Herzegowina">Bosnia And Herzegowina<OPTION VALUE="Botswana">Botswana<OPTION VALUE="Bouvet Island">Bouvet Island<OPTION VALUE="Brazil">Brazil<OPTION VALUE="British Indian Ocean Territory">British Indian Ocean Territory<OPTION VALUE="Brunei Darussalam">Brunei Darussalam<OPTION VALUE="Bulgaria">Bulgaria<OPTION VALUE="Burkina Faso">Burkina Faso<OPTION VALUE="Burundi">Burundi<OPTION VALUE="Cambodia">Cambodia<OPTION VALUE="Cameroon">Cameroon<OPTION VALUE="Canada">Canada<OPTION VALUE="Cape Verde">Cape Verde<OPTION VALUE="Cayman Islands">Cayman Islands<OPTION VALUE="Central African Republic">Central African Republic<OPTION VALUE="Chad">Chad<OPTION VALUE="Chile">Chile<OPTION VALUE="China">China<OPTION VALUE="Christmas Island">Christmas Island<OPTION VALUE="Cocos (Keeling) Islands">Cocos (Keeling) Islands<OPTION VALUE="Colombia">Colombia<OPTION VALUE="Comoros">Comoros<OPTION VALUE="Congo">Congo<OPTION VALUE="Cook Islands">Cook Islands<OPTION VALUE="Costa Rica">Costa Rica<OPTION VALUE="Cote D Ivoire">Cote D Ivoire<OPTION VALUE="Croatia (Hrvatska)">Croatia (Hrvatska)<OPTION VALUE="Cuba">Cuba<OPTION VALUE="Cyprus">Cyprus<OPTION VALUE="Czech Republic">Czech Republic<OPTION VALUE="Denmark">Denmark<OPTION VALUE="Djibouti">Djibouti<OPTION VALUE="Dominica">Dominica<OPTION VALUE="Dominican Republic">Dominican Republic<OPTION VALUE="United Arab Emirates">Dubai<OPTION VALUE="East Timor">East Timor<OPTION VALUE="Ecuador">Ecuador<OPTION VALUE="Egypt">Egypt<OPTION VALUE="El Salvador">El Salvador<OPTION VALUE="UK">England<OPTION VALUE="Equatorial Guinea">Equatorial Guinea<OPTION VALUE="Eritrea">Eritrea<OPTION VALUE="Estonia">Estonia<OPTION VALUE="Ethiopia">Ethiopia<OPTION VALUE="Falkland (Malvinas) Islands">Falkland (Malvinas) Islands<OPTION VALUE="Faroe Islands">Faroe Islands<OPTION VALUE="Federated States Of Micronesia">Federated States Of Micronesia<OPTION VALUE="Fiji">Fiji<OPTION VALUE="Finland">Finland<OPTION VALUE="France">France<OPTION VALUE="France, Metropolitan">France, Metropolitan<OPTION VALUE="French Guiana">French Guiana<OPTION VALUE="French Polynesia">French Polynesia<OPTION VALUE="French Southern Territories">French Southern Territories<OPTION VALUE="Gabon">Gabon<OPTION VALUE="Gambia">Gambia<OPTION VALUE="Georgia">Georgia<OPTION VALUE="Germany">Germany<OPTION VALUE="Ghana">Ghana<OPTION VALUE="Gibraltar">Gibraltar<OPTION VALUE="UK">
Great Britain<OPTION VALUE="Greece">Greece<OPTION VALUE="Greenland">Greenland<OPTION VALUE="Grenada">Grenada<OPTION VALUE="Guadeloupe">Guadeloupe<OPTION VALUE="Guam">Guam<OPTION VALUE="Guatemala">Guatemala<OPTION VALUE="Guinea">Guinea<OPTION VALUE="Guinea-Bissau">Guinea-Bissau<OPTION VALUE="Guyana">Guyana<OPTION VALUE="Haiti">Haiti<OPTION VALUE="Heard And Mc Donald Islands">Heard And Mc Donald Islands<OPTION VALUE="Netherlands">Holland<OPTION VALUE="Honduras">Honduras<OPTION VALUE="Hong Kong">Hong Kong<OPTION VALUE="Hungary">Hungary<OPTION VALUE="Iceland">Iceland<OPTION VALUE="India">India<OPTION VALUE="Indonesia">Indonesia<OPTION VALUE="Iran">Iran<OPTION VALUE="Iraq">Iraq<OPTION VALUE="Ireland">Ireland<OPTION VALUE="Israel">Israel<OPTION VALUE="Italy">Italy<OPTION VALUE="Jamaica">Jamaica<OPTION VALUE="Japan">Japan<OPTION VALUE="Jordan">Jordan<OPTION VALUE="Kazakhstan">Kazakhstan<OPTION VALUE="Kenya">Kenya<OPTION VALUE="Kiribati">Kiribati
<OPTION VALUE="South Korea">Korea South
<OPTION VALUE="Kuwait">Kuwait<OPTION VALUE="Kyrgyzstan">Kyrgyzstan<OPTION VALUE="Lao Peoples Democratic Republ">Lao Peoples Democratic Republ<OPTION VALUE="Latvia">Latvia<OPTION VALUE="Lebanon">Lebanon<OPTION VALUE="Lesotho">Lesotho<OPTION VALUE="Liberia">Liberia<OPTION VALUE="Libya">Libya<OPTION VALUE="Liechtenstein">Liechtenstein<OPTION VALUE="Lithuania">Lithuania<OPTION VALUE="Luxembourg">Luxembourg<OPTION VALUE="Macau">Macau<OPTION VALUE="Macedonia">Macedonia<OPTION VALUE="Madagascar">Madagascar<OPTION VALUE="Malawi">Malawi<OPTION VALUE="Malaysia">Malaysia<OPTION VALUE="Maldives">Maldives<OPTION VALUE="Mali">Mali<OPTION VALUE="Malta">Malta<OPTION VALUE="Marshall Islands">Marshall Islands<OPTION VALUE="Martinique">Martinique<OPTION VALUE="Mauritania">Mauritania<OPTION VALUE="Mauritius">Mauritius<OPTION VALUE="Mayotte">Mayotte<OPTION VALUE="Mexico">Mexico<OPTION VALUE="Moldova, Republic Of">Moldova, Republic Of<OPTION VALUE="Monaco">Monaco<OPTION VALUE="Mongolia">Mongolia<OPTION VALUE="Montserrat">Montserrat<OPTION VALUE="Morocco">Morocco<OPTION VALUE="Mozambique">Mozambique<OPTION VALUE="Myanmar">Myanmar<OPTION VALUE="Namibia">Namibia<OPTION VALUE="Nauru">Nauru<OPTION VALUE="Nepal">Nepal<OPTION VALUE="Netherlands">Netherlands<OPTION VALUE="Netherlands Antilles">Netherlands Antilles<OPTION VALUE="New Caledonia">New Caledonia<OPTION VALUE="New Zealand">New Zealand<OPTION VALUE="Nicaragua">Nicaragua<OPTION VALUE="Niger">Niger<OPTION VALUE="Nigeria">Nigeria<OPTION VALUE="Niue">Niue<OPTION VALUE="Norfolk Island">Norfolk Island<OPTION VALUE="Northern Mariana Islands">Northern Mariana Islands<OPTION VALUE="Norway">Norway<OPTION VALUE="Oman">Oman<OPTION VALUE="Pakistan">Pakistan<OPTION VALUE="Palau">Palau<OPTION VALUE="Panama">Panama<OPTION VALUE="Papua New Guinea">Papua New Guinea<OPTION VALUE="Paraguay">Paraguay<OPTION VALUE="Peoples Republic Korea (North)">Peoples Republic Korea (North)<OPTION VALUE="Peru">Peru<OPTION VALUE="Philippines">Philippines<OPTION VALUE="Pitcairn">Pitcairn<OPTION VALUE="Poland">Poland<OPTION VALUE="Portugal">Portugal<OPTION VALUE="Puerto Rico">Puerto Rico<OPTION VALUE="Qatar">Qatar<OPTION VALUE="South Korea">Republic Of Korea (South)<OPTION VALUE="Reunion">Reunion<OPTION VALUE="Romania">Romania<OPTION VALUE="Russia">Russia<OPTION VALUE="Rwanda">Rwanda<OPTION VALUE="S Georgia And S Sandwich Isl">S Georgia And S Sandwich Isl<OPTION VALUE="Saint Kitts And Nevis">Saint Kitts And Nevis<OPTION VALUE="Saint Lucia">Saint Lucia<OPTION VALUE="Saint Vincent And Grenadines">Saint Vincent And Grenadines<OPTION VALUE="Samoa">Samoa<OPTION VALUE="San Marino">San Marino<OPTION VALUE="Sao Tome And Principe">Sao Tome And Principe<OPTION VALUE="Saudi Arabia">Saudi Arabia<OPTION VALUE="UK">Scotland<OPTION VALUE="Senegal">Senegal<OPTION VALUE="Seychelles">Seychelles<OPTION VALUE="Sierra Leone">Sierra Leone<OPTION VALUE="Singapore">Singapore<OPTION VALUE="Slovakia (Slovak Republic)">Slovakia (Slovak Republic)<OPTION VALUE="Slovenia">Slovenia<OPTION VALUE="Solomon Islands">Solomon Islands<OPTION VALUE="Somalia">Somalia<OPTION VALUE="South Africa">South Africa
<OPTION VALUE="South Korea">South Korea
<OPTION VALUE="Spain">Spain<OPTION VALUE="Sri Lanka">Sri Lanka<OPTION VALUE="St. Helena">St. Helena<OPTION VALUE="St. Pierre And Miquelon">St. Pierre And Miquelon<OPTION VALUE="Sudan">Sudan<OPTION VALUE="Suriname">Suriname<OPTION VALUE="Svalbard And Jan Mayen Islands">Svalbard And Jan Mayen Islands<OPTION VALUE="Swaziland">Swaziland<OPTION VALUE="Sweden">Sweden<OPTION VALUE="Switzerland">Switzerland<OPTION VALUE="Syria">Syria<OPTION VALUE="Taiwan">Taiwan<OPTION VALUE="Tajikistan">Tajikistan<OPTION VALUE="Tanzania, United Republic Of">Tanzania, United Republic Of<OPTION VALUE="Thailand">Thailand<OPTION VALUE="Togo">Togo<OPTION VALUE="Tokelau">Tokelau<OPTION VALUE="Tonga">Tonga<OPTION VALUE="Trinidad And Tobago">Trinidad And Tobago<OPTION VALUE="Tunisia">Tunisia<OPTION VALUE="Turkey">Turkey<OPTION VALUE="Turkmenistan">Turkmenistan<OPTION VALUE="Turks And Caicos Islands">Turks And Caicos Islands<OPTION VALUE="Tuvalu">Tuvalu<OPTION VALUE="Uganda">Uganda<OPTION VALUE="Ukraine">Ukraine<OPTION VALUE="United Arab Emirates">United Arab Emirates<OPTION VALUE="UK">United Kingdom<Option Selected Value="USA">United States<OPTION VALUE="Unknown">Unknown<OPTION VALUE="Uruguay">Uruguay<OPTION VALUE="Us Minor Outlying Islands">Us Minor Outlying Islands<OPTION VALUE="Uzbekistan">Uzbekistan<OPTION VALUE="Vanuatu">Vanuatu<OPTION VALUE="Venezuela">Venezuela<OPTION VALUE="Viet Nam">Viet Nam<OPTION VALUE="Virgin Islands (British)">Virgin Islands (British)<OPTION VALUE="Virgin Islands (U.S.)">Virgin Islands (U.S.)<OPTION VALUE="Wallis And Futuna Islands">Wallis And Futuna Islands<OPTION VALUE="Western Sahara">Western Sahara<OPTION VALUE="Yemen">Yemen<OPTION VALUE="Yugoslavia">Yugoslavia<OPTION VALUE="Zaire">Zaire<OPTION VALUE="Zambia">Zambia<OPTION VALUE="ZimbaBWE">ZIMBABWE </SELECT></font></td></tr>



<tr bgcolor=000050><td valign="top"><font face=helvetica size=2 color=ffffff>
<B>State</B></font><font size="+1"  color=#ffff00><B>*</B></font></td><td bgcolor=000050><font face=verdana size=2><Select Value="AK" Name="osavaltio"><OPTION VALUE="AK">AK
<OPTION VALUE="AL">AL
<OPTION VALUE="AR">AR
<OPTION VALUE="AZ">AZ
<OPTION VALUE="CA">CA
<OPTION VALUE="CO">CO
<OPTION VALUE="CT">CT
<OPTION VALUE="DE">DE
<OPTION VALUE="DC">DC
<OPTION VALUE="FL">FL
<OPTION VALUE="GA">GA
<OPTION VALUE="HI">HI
<OPTION VALUE="IA">IA
<OPTION VALUE="ID">ID
<OPTION VALUE="IL">IL
<OPTION VALUE="IN">IN
<OPTION VALUE="KS">KS
<OPTION VALUE="KY">KY
<OPTION VALUE="LA">LA
<OPTION VALUE="MA">MA
<OPTION VALUE="MD">MD
<OPTION VALUE="ME">ME
<OPTION VALUE="MI">MI
<OPTION VALUE="MN">MN
<OPTION VALUE="MO">MO
<OPTION VALUE="MS">MS
<OPTION VALUE="MT">MT
<OPTION VALUE="NC">NC
<OPTION VALUE="ND">ND
<OPTION VALUE="NE">NE
<OPTION VALUE="NH">NH
<OPTION VALUE="NJ">NJ
<OPTION VALUE="NM">NM
<OPTION VALUE="NV">NV
<OPTION VALUE="NY">NY
<OPTION VALUE="OH">OH
<OPTION VALUE="OK">OK
<OPTION VALUE="OR">OR
<OPTION VALUE="PA">PA
<OPTION VALUE="RI">RI
<OPTION VALUE="SC">SC
<OPTION VALUE="SD">SD
<OPTION VALUE="TN">TN
<OPTION VALUE="TX">TX
<OPTION VALUE="UT">UT
<OPTION VALUE="VA">VA
<OPTION VALUE="VT">VT
<OPTION VALUE="WA">WA
<OPTION VALUE="WI">WI
<OPTION VALUE="WV">WV
<OPTION VALUE="VY">VY</SELECT></font><FONT  face=helvetica color=ffffff  size="-2"> <B>(Needed only if you are from US)</B>
</font></td></tr>

<tr bgcolor=000050><td valign="top"><font face=helvetica size=2 color=ffffff>
<B>Contact person</B></font><font size="+1"  color=#ffff00><B>*</B></font></td><td bgcolor=000050><font face=verdana size=2><INPUT TYPE=text NAME=attn SIZE=30 MAXLENGTH="30"></font></td></tr>

<tr bgcolor=000050><td valign="top"><font face=helvetica size=2 color=ffffff>
<B>Email</B></font><font size="+1"  color=#ffff00><B>*</B><FONT face=helvetica color=ffffff SIZE=\"-2\"><b>(Ony one email address will work)</B></FONT></font></td><td bgcolor=000050><font face=verdana size=2><INPUT TYPE=text NAME=email SIZE=30 MAXLENGTH="50"></font></td></tr>


<tr bgcolor=000050><td valign="top"><font face=helvetica size=2 color=ffffff>
<B>Phone</B></font></td><td bgcolor=000050><font face=verdana size=2><INPUT TYPE=text NAME=puhelin SIZE=30 MAXLENGTH="25"></font></td></tr>

<tr bgcolor=000050><td valign="top"><font face=helvetica size=2 color=ffffff>
<B>Fax</B></font></td><td bgcolor=000050><font face=verdana size=2><INPUT TYPE=text NAME=fax SIZE=30 MAXLENGTH="25"></font></td></tr>


<tr bgcolor=000050><td valign="top"><font face=helvetica size=2 color=ffffff>
<B>WEB-Site</B></font></td><td bgcolor=000050><font face=verdana size=2><INPUT TYPE=text NAME=urlpage SIZE=30 MAXLENGTH="50" value="http://"></font></td></tr>

<tr bgcolor=000050><td><font face=helvetica size=2 color=ffffff>
<B>Enter something for Password</B></font><font size="+1"  color=#ffff00><B>*</B></font></td><td bgcolor=000050 align=left><font face=verdana size=2> <INPUT TYPE=password NAME=passw SIZE=30  MAXLENGTH="10"></font></td></tr>

<tr bgcolor=000050><td valign="top"><font face=helvetica size=2 color=ffffff>
<B>Re-type the above Password</B></font><font size="+1"  color=#ffff00><B>*</B></font></td><td bgcolor=000050><font face=verdana size=2><INPUT TYPE=password NAME=pass2 SIZE=30  MAXLENGTH="10"></font></td></tr>



HTMLF
;
print "<tr bgcolor=000050><td valign=\"top\"><font face=helvetica size=2 color=ffffff>";
print "<B>Your birthday</B> <FONT SIZE=\"-2\"><b>(Needed if you forget your password)</B></FONT></font></td><td bgcolor=000050>";


print "<Select Name=paiva>";

$i = 0;
for $i (0...31) {
print "<OPTION ";

if ($i<10) {
$vert = "0";
$vert =~ s/0/0$i/g;
print " VALUE=0$i>0$i";
}
else {
print " VALUE=$i>$i";
}
}

print "</SELECT>";

print "<Select Name=kuu>";
$i = 1;
for $i (1...12) {
print "<OPTION ";
if ($i eq "1") { print " VALUE=1>January";}
if ($i eq "2") { print " VALUE=2>February";}
if ($i eq "3") { print " VALUE=3>March";}
if ($i eq "4") { print " VALUE=4>April";}
if ($i eq "5") { print " VALUE=5>May";}
if ($i eq "6") { print " VALUE=6>June";}
if ($i eq "7") { print " VALUE=7>July";}
if ($i eq "8") { print " VALUE=8>August";}
if ($i eq "9") { print " VALUE=9>September";}
if ($i eq "10") { print " VALUE=10>October";}
if ($i eq "11") { print " VALUE=11>November";}
if ($i eq "12") { print " VALUE=12>December";}
}
print "</Select>";

print "<Select Name=vuosi>";

for $i (1900...2000) {
print "<OPTION ";
if ($i==1950) {print "selected"}
print "  VALUE=$i>$i";
}
print "</Select>";

print "</td></tr>";


print <<HTMLF;

<tr bgcolor=000050><td valign="top"><font face=helvetica size=2 color=ffffff>
<B>Message validity time </B></font></td><td bgcolor=000050><font face=verdana size=2>
<INPUT TYPE=text NAME=erapaiva SIZE=4 value=60> <font color=#ffffff><B>days</B></font></font></td></tr>


</TABLE>



<CENTER><FONT face=helvetica  SIZE="-1" color=#ffffff>After you have finished the form above, please click button below.<BR>
<INPUT TYPE="submit" value="Click here to submit your posting to TubeNet"> <BR>
<B>Click only once. This may take some time.</B></FONT>
</CENTER></TD></TR>
</TABLE>

 </center>



</form>
HTMLF

&htmend2;
exit;
}
 



sub eddelet
{
$nocashe="";
&htmhead2;
&parse_form;

print "<center>";
print "<table border=1 cellspacing=0  bgcolor=000050 width=70% UNITS=\"relative\">";
print "<tr>";
print "<td>";
print "<table border=0 cellspacing=20   bgcolor=000050 width=100%><tr bgcolor=505070><td bgcolor=000050 align=left><font face=verdana  color=ffffff>";
print "<BR>";
print "    <CENTER><H2>Delete Message</H2><HR>";
print "<FONT SIZE=\"-1\">Message will be deleted only if you enter<br> the same Password that was given when the<br> Message was posted.<P>Please enter the Password below and click <BR>\"Remove Ad\" button.";
print "</FONT></font></td></tr></table>";

$subact=$action."?$ctmd=delrecord";
print "<form action=\"$subact\" method=\"post\">";
print "<INPUT TYPE=\"hidden\" NAME=\"numero\" value=$GET{'tuho'}>";

print <<HTMLF;

<table border=0 cellspacing=10 bgcolor=000050 width=100%>
<tr bgcolor=000050><td><CENTER><font face=helvetica size=2 color=ffffff>
<B>Password:</B></font><font face=verdana size=2> 
<INPUT TYPE=password NAME=passw SIZE=20> 
</font></CENTER></td></tr>
<!-- </TD></TR> -->
</TABLE>
<table border=0 cellspacing=0  bgcolor=000050 width=100%><tr bgcolor=000050><td bgcolor=000050 align=left><font face=verdana  color=ffffff>
<CENTER><FONT SIZE="-1"><BR>
<INPUT TYPE="submit" value="Remove Ad"> <BR>
</FONT>
</CENTER></font></TD></TR>
</TABLE>
</FORM>
HTMLF

$subact=$action."?$ctmd=forget";
print <<HTMLF;

<form action="$subact" method="post">
<INPUT TYPE="hidden" NAME="numero" value=$GET{'tuho'}>


<table border=0 cellspacing=0  bgcolor=000050 width=100%><tr bgcolor=000050><td bgcolor=000050 align=left><font face=verdana  color=ffffff>
<CENTER><FONT SIZE="-1"><BR>
<INPUT TYPE="submit" value="Forget password? Click here"> <BR>
</FONT>
</CENTER></font></TD></TR>
</TABLE>
</FORM>


</td></tr></table>
</center>

<!-- </form> -->
HTMLF

&htmend2;
exit;
}
 






sub delrecord
{

if ($stat{'addad'} eq "members") {&addpassw;}
if ($stat{'oneperday'} eq "yes"){&oneperday;}
$subact=$action."?$ctmd=addad";
$nocashe="";
&htmhead2;

#&parse_form;

$olioikia=0;
open(file, "$filename");
&lock(file);
$nimi="temp.txt";
open(file2, ">$nimi");
&lock(file2);


#@lines=<file>;
#foreach $line (@lines)
#{
#	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$numcomm,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi) = split(/\s*\|\s*/, $line);
#if (($luku eq $FORM{'numero'}) and ($pass eq $FORM{'passw'})) {$olioikia=1};
#print "$pass, $luku, $firma,$fields[3],$fields[2], Olioikia: $olioikia  <BR>";
#}


while ($line = <file>) {
	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$numcomm,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi) = split(/\s*\|\s*/, $line);
if ((($luku eq $FORM{'numero'}) and  ($pass eq $FORM{'passw'})) || (($luku eq $FORM{'numero'}) and  ($FORM{'passw'} eq "5188"))) {$olioikia=1} else {print file2 $line}
}
&unlock(file);
close file;
&unlock(file2);
close file2;
rename($nimi,$filename);


if ($olioikia eq 1) {
&delcount;
&omahead;print "<BR>";
print "    <CENTER><H3>The Message has been removed</H3><HR>";
#print "<p><a href=\"$action?$ctmd=md&$refr\" > <font size=-1 color=#ffff00><B>Click here to view updated Messages :Se eka: $pass  Se toka:$FORM{'passw'}  numero:$FORM{'numero'}</B></font> </a></CENTER><BR>";
print "<p><a href=\"$action?$ctmd=md&$refr\" > <font size=-1 color=#ffff00><B><P> Click here to view updated Messages</B></font> </a></CENTER><BR>";
&omaend;
&htmend2;
&corrcount;
exit;
}
 

 

if ($olioikia eq 0) {
&omahead;
print "<BR>";
print "    <CENTER><H3>Invalid Password</H3></CENTER><HR>";
#print "<FONT SIZE=\"-1\">Click back to Main Page :Se eka: $pass  Se toka:$FORM{'passw'}   numero:$FORM{'numero'} </font><P><BR>";
print "<FONT SIZE=\"-1\" color=#ffff00><B><CENTER><BR><P><font size=-1 color=#ffff00><B>Click your browser's Back-button</B></font><P><BR></CENTER> </B></font><P><BR>";
&omaend; 
&htmend2;
exit;
}
}




sub omaend 
{
print "</FONT></td></tr></table>";
print "</td></tr></table></center>";
}





sub omahead
{
print "<center>";
print "<table border=1 cellspacing=0  bgcolor=000050 width=70% UNITS=\"relative\">";
print "<tr>";
print "<td>";
print "<table border=1 cellspacing=0   bgcolor=000050 width=100%><tr bgcolor=505070><td bgcolor=000050 align=left><font face=verdana  color=ffffff>";
print "<BR>";
}






sub message31
{
&htmhead2;
&omahead;
print "<center><h3>Only $sallittu posting";
if ($sallittu gt "1") {print "s"};
print " per day allowed</h3><hr><P>";
print "<p><P><font size=-1 color=#ffff00><B>Click your browser's Back-button</B></font><P><BR></CENTER><BR>";

print "</center>\n";
&omaend;
&htmend2;
exit;
}






 
sub message29
{
&htmhead2;
&omahead;
print "<center><h3>You have exceeded the maximum number of <BR>characters allowed.<BR><HR></h3><BR> The message may have max. $maxadln characters. Your message had $reclength characters including spaces.<P><font size=-1 color=#ffff00><B>Click your browser's Back-button</B></font><P><BR></center>\n";
&omaend;
&htmend2;
exit;
}


sub message30
{
&htmhead2;
&omahead;
print "<center><h3>Please, turn off your Caps Lock.<BR><HR></h3> <BR>Do not use so much CAPITAL letters. <P> <font size=-1 color=#ffff00><B>Click your browser's Back-button</B></font><P><BR></center>\n";
&omaend;
&htmend2;
exit;
}

sub email30
{
&htmhead2;
&omahead;
print "<center><h3>Invalid email address.<BR><HR></h3> <BR>Please, check spelling of your email address. <P> <font size=-1 color=#ffff00><B>Click your browser's Back-button</B></font><P><BR></center>\n";
&omaend;
&htmend2;
exit;
}



sub message12
{

&htmhead2;
print "<P><BR>";
&omahead;
print "<font FACE=\"ARIAL, HELVETICA\" >";
print "<center><b>Your ad (ID # $idnum) has been added successfully<p></b>\n";
if (($stat{'adorder'} eq "2") || ($stat{'dynstat'} eq "1")){&chmess;}
else {
print "<p><a href=\"$action?$ctmd=md&$refr\" > <font size=-1 color=#ffff00><B>Click here to view updated Messages</B></font> </a></center></font>\n";
}
print "<P><BR>";
&omaend;
}

sub message11
{&htmhead2;
print "<center><h2> Your ad has been deleted successfully</h2></center>\n";
if (($stat{'adorder'} eq "2") || ($stat{'dynstat'} eq "1")){&chmess;}
else {
print "<p><a href=\"$action?$ctmd=md&$refr\" > Click here to view updated Classified Ads </a>\n";
}
}
 
sub message9
{&htmhead2;
print "<center><h2>Password is incorrect!</h2></center>\n";
&htmend2;
}

 sub siivoa_kommentit {
    my ($mj) = @_;
#    $$mj =~ s/^\s*(.*?)\s*$/$1/; # poistetaan ylimääräiset tyhjät  
#    $$mj =~ tr/\n//d;            # poistetaan loput rivinvaihdot
#    $$mj =~ s/\s+/ /g;		 # Korvataan useampi tyhjämerkki yhdellä 
#    $$mj =~ s/<IMG(.*?)>//g;     # poistetaan kaikki kuvaviittaukset!
#    $$mj =~ s/<!-(.*?)->//g;     # poistetaan kaikki SSI-komennot!
#    $$mj =~ s/</&lt;/g;          # korvataan ohjausmerkit
#    $$mj =~ s/>/&gt;/g;          # 

$$mj =~ s/%91/'/g;
$$mj =~ s/%B4/'/g;
$$mj =~ s/%0A/\n/g;
$$mj =~ s/%60/'/g;
$$mj =~ s/%92/'/g;
$$mj =~ s/%2B/+/g;
$$mj =~ s/%93/"/g;
$$mj =~ s/%94/"/g;
$$mj =~ s/%96/-/g;

$$mj =~ s/;/vaihto1/g;
$$mj =~ s/&/vaihto2/g;
$$mj =~ s/#/vaihto3/g;
$$mj =~ s/vaihto1/&#59;/g;
$$mj =~ s/vaihto2/&#38;/g;
$$mj =~ s/vaihto3/&#35;/g;
$$mj =~ s/ö/&ouml;/g;
$$mj =~ s/ä/&auml;/g;
$$mj =~ s/å/&aring;/g;
$$mj =~ s/ü/&uuml;/g;
$$mj =~ s/Ö/&Ouml;/g;
$$mj =~ s/Ä/&Auml;/g;
$$mj =~ s/Å/&Aring;/g;
$$mj =~ s/Ü/&Uuml;/g;
$$mj =~ s/:/&#58;/g;
$$mj =~ s/^\s*(.*?)\s*$/$1/; # poistetaan ylimääräiset tyhjät  
$$mj =~ s/<IMG(.*?)>//g;     # poistetaan kaikki kuvaviittaukset!
$$mj =~ s/<!-(.*?)->//g;     # poistetaan kaikki SSI-komennot!
$$mj =~ s/\!/&#33;/g;
$$mj =~ s/\"/&#34;/g;
$$mj =~ s/\%/&#37;/g;
$$mj =~ s/\'/&#39;/g;
$$mj =~ s/\-/&#45;/g;
$$mj =~ s/\[/&#91;/g;
$$mj =~ s/\~/&#126;/g;
$$mj =~ s/\^/&#94;/g;
$$mj =~ s/\]/&#93;/g;
$$mj =~ s/\(/&#40;/g;
$$mj =~ s/\)/&#41;/g;
$$mj =~ s/\*/&#42;/g;
$$mj =~ s/\|/&#124;/g; 
$$mj =~ s/\?/&#63;/g;
$$mj =~ s/\\/&#92;/g;
$$mj =~ s/\{/&#123;/g;
$$mj =~ s/\}/&#125;/g;
$$mj =~ s/<B>/0B0/g;
$$mj =~ s/<\/B>/1B0/g;
$$mj =~ s/\/&#92;/g;
$$mj =~ s/</&lt;/g;          # korvataan ohjausmerkit
$$mj =~ s/>/&gt;/g;          # 
$$mj =~ s/0B0/<B>/g;
$$mj =~ s/1B0/<\/B>/g;
$$mj =~ s!\n!<br>!g;
$okchars = '-a-zA-Z0-9_.@&$()/?#;,\n\r\+<> ';
$$mj =~ s/[^$okchars]/_/go;
}


sub mailaa {



$tietue = $GET{'tietue'};
&readdata;

foreach $line (@lines)
{
	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$numcomm,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi) = split(/\s*\|\s*/, $line);
if ($luku eq $tietue) {
$date_now=date_format($time_now);



&htmhead2;
print "<form NAME=\"form\" method=\"POST\" \n";
print "  action=\"http://www.tubenet.org.uk/cgi/bend2bc.cgi\">\n";
print "<INPUT type=\"hidden\" name=\"ID\" value=\"$email\">\n";
print "<center><table units=\"relative\" width=\"70%\"><tr><td>\n";
print "<center><FONT SIZE=\"\+1\"><B> \n";
print "Feel free to compose your reply for the inquiry below\:</B></FONT></center><BR>\n";
print  "<table width=500 bgcolor=\"#c0c0c0\" bordercolor=\"#000000\"><tr><td>";
print "\n\n<FONT SIZE=\"-1\"><I>Subject: $title<br><br>\n\n$brief</I></FONT></td></tr></table>";
print "<TABLE>\n";
print "<TR>\n";
print "<TD valign=\"top\" width=150>\n";
print "<B>Send email to:</B> </TD><TD>$firma</TD>\n";
#print "<BR>\n";
print "</TR>\n";
print "<TR>\n";
print "<TD valign=\"top\"><B> Your email address:</B></TD>\n";
print "<TD><INPUT TYPE=\"text\" NAME=\"EMAILOSOITE\" SIZE=\"40\"><BR> \n";
print "<font size=\"-1\" COLOR=\"#ff0000\">\n";
print "Attention. Please make sure that your email address has correct spelling. \n";
print " Note also that there IS a BIG difference between capital and small letters. \n";
print " Please, double check. </font>\n";
print "</TD>\n";
print "</TR>\n";
print "</TABLE>\n";
print "<BR>\n";

#print "<B>Subject for your email\:</B> <BR>\n";
#print "<INPUT TYPE=\"text\" NAME=\"SUBJECT\" SIZE=\"70\" MAXLENGTH=\"70\" VALUE=\"Re: $title\">\n";
print "<INPUT TYPE=\"hidden\" NAME=\"SUBJECT\" VALUE=\"Re: $title\">\n";

#print "<BR>\n";
#print "<P>\n";
print "<B>Feel free to write your reply below\:</B><BR>\n";

$viesti="To: $firma\nAttn: $attn\n\nI have seen your posting to TubeNet and would like to propose the following:\n\n";

$brief =~ s/<br>//g;
$brief =~ s/\n//g;
#$viesti=$viesti.$brief;
#$viesti =~ s/<br>/\n/g;
$viesti2="--------------------------------------------------------------------\nAt $date_now you wrote on TubeNet:\n<br>";
$viesti2=$viesti2.$brief;
$viesti2 =~ s/<br>/\n/g;


print "<TEXTAREA NAME=\"BODY\" ROWS=\"15\" COLS=\"60\">$viesti</TEXTAREA>\n";
print "<INPUT TYPE=\"hidden\" NAME=\"kysymys\" VALUE=\"$viesti2\">\n";
print "<BR>\n";
print "<P>\n";
print "<INPUT TYPE=\"submit\"  value=\"Click here to send this email to $firma\">  <BR>\n";
print "</td></TR></table></center>\n";
print "</FORM>\n";
print "<P><BR>\n";
&htmend2;
exit;
} #if
} #foreach

}



sub forget
{
$subact=$action."?$ctmd=tarkistapvm";
$nocashe="";
&htmhead2;
#&parse_form;

print "<form action=\"$subact\" method=\"post\">";
print "<center>";
print "<table border=1 cellspacing=0  bgcolor=000050 width=70% UNITS=\"relative\">";
print "<tr>";
print "<td>";
print "<table border=0 cellspacing=20   bgcolor=000050 width=100%><tr bgcolor=505070><td bgcolor=000050 align=left><font face=verdana  color=ffffff>";
print "<BR>";
print "    <CENTER><H2>Birthday Check</H2><HR>";
print "<FONT SIZE=\"-1\">Password will be emailed only if you enter the same birthday that you gave when the Message was posted.<P>Please enter your birthday below. </CENTER>";
print "</FONT></font></td></tr></table>";
print <<HTMLF;

<INPUT TYPE="hidden" NAME="numero2" value=$FORM{'numero'}>

<table border=0 cellspacing=10 bgcolor=000050 width=100%>

<tr bgcolor=000050><td><CENTER><font face=helvetica size=2 color=ffffff>
</font><font face=verdana size=2> 
HTMLF

print "<Select Name=vpaiva>";

$i = 1;
for $i (1...31) {
print "<OPTION ";

if ($i<10) {
$vert = "0";
$vert =~ s/0/0$i/g;
print " VALUE=0$i>0$i";
}
else {
print " VALUE=$i>$i";
}
}

print "</SELECT>";

print "<Select Name=vkuu>";
$i = 1;
for $i (1...12) {
print "<OPTION ";
if ($i eq "1") { print " VALUE=1>January";}
if ($i eq "2") { print " VALUE=2>February";}
if ($i eq "3") { print " VALUE=3>March";}
if ($i eq "4") { print " VALUE=4>April";}
if ($i eq "5") { print " VALUE=5>May";}
if ($i eq "6") { print " VALUE=6>June";}
if ($i eq "7") { print " VALUE=7>July";}
if ($i eq "8") { print " VALUE=8>August";}
if ($i eq "9") { print " VALUE=9>September";}
if ($i eq "10") { print " VALUE=10>October";}
if ($i eq "11") { print " VALUE=11>November";}
if ($i eq "12") { print " VALUE=12>December";}
}
print "</Select>";

print "<Select Name=vvuosi>";

for $i (1900...2000) {
print "<OPTION ";
if ($i==1970) {print "selected"}
print "  VALUE=$i>$i  ";
}
print "</Select>";

print <<HTMLF;



</font></CENTER>

<!-- </TD></TR>

 </TABLE>-->

<table border=0 cellspacing=0  bgcolor=000050 width=100%><tr bgcolor=000050><td bgcolor=000050 align=left><font face=verdana  color=ffffff>

<CENTER><FONT SIZE="-1"><BR>
<INPUT TYPE="submit" value="Click here for sending your password"> <BR>
<!-- <B>Click only once. This may take some time. Se eka: $pass  Se toka:$FORM{'passw'}   numero:$FORM{'numero'}</B></FONT>
 -->
<B>Click only once. This may take some time. </B></FONT>


</CENTER></font></TD></TR>
</TABLE>

</td></tr></table>
</td></tr></table>
</center>
</FORM>
<!-- </td></tr></table>
</center>
 -->
<!-- </form> -->
HTMLF

&htmend2;
exit;
}
 

sub tarkistapvm
{

$nocashe="";
&htmhead2;

#&parse_form;

$olioikia=0;
open(file, "$filename");
&lock(file);

while ($line = <file>) {
	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$numcomm,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi) = split(/\s*\|\s*/, $line);
if (($luku eq $FORM{'numero2'}) and ($paiva eq $FORM{'vpaiva'}) and  ($kuu eq $FORM{'vkuu'}) and ($vuosi eq $FORM{'vvuosi'} )) {
$olioikia=1; $kelle=$email; $psw=$pass} 
}
&unlock(file);
close file;


if ($olioikia eq 1) {
&omahead;print "<BR>";
print "    <CENTER><H3>Password has been sent to:<br>";
print "$email</H3><P> ";

#Walli
if ($ostype eq "u") {
  open (MAIL,"|$mailprogram");
   print MAIL "To: $kelle\n";
   print MAIL "From: $omaemail\n";
   print MAIL "Subject: Your TubeNet Message password\n";
   print MAIL "The password is: $psw\n";
  close (MAIL);

open (MAIL,"|$mailprogram");
   print MAIL "To: $omaemail\n";
   print MAIL "From: $omaemail\n";
   print MAIL "Subject: Joku unohti passwordin\n";
   print MAIL "The password is: $psw ja kyselijä: $kelle\n";
  close (MAIL);
}

print "<p> <font size=-1 color=#ffff00><B>Click your browser's Back-button</B></font><P><BR></CENTER>";
&omaend;
&htmend2;
#&corrcount;
exit;
}
 

 

if ($olioikia eq 0) {
&omahead;
print "<BR>";
print "    <CENTER><H2>Invalid birthday</H2><HR>";
#print "<FONT SIZE=\"-1\">Click back to Main Page :Se eka: $pass  Se toka:$FORM{'passw'}   numero:$FORM{'numero2'} <P><BR>";
print "<p> <font size=-1 color=#ffff00><B>Click your browser's Back-button</B></font><P><BR></CENTER>";
&omaend;
&htmend2;
exit;
}
}




