#!/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
# Type of OS ( u - Unix, w - Windows)

  


#Walli
#$ostype="w"; 
$ostype="u"; 
#$ostype="t"; 

#Walli
$catheadt="Cut-off machines and tooling";
$catname="marketplace2uus";
$catname2="add";
$catname3="addmsgboard2";
$catname4="add4t";
$ekalippu="F";

$vipalippu="F";
# seuraavalla määritellään max postings per day
# 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/";



if ($ostype eq "w") {
require "/inetpub/scripts/html2.pl";
require "/inetpub/scripts/taulukot.pl";
require "/inetpub/scripts/lajit.pl"; }

if ($ostype ne "w") {
require "/var/www/customers/tubenet/public_html/cgi/html2.pl";
require "/var/www/customers/tubenet/public_html/cgi/taulukot.pl";
require "/var/www/customers/tubenet/public_html/cgi/lajit.pl"; }









# 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 -oi";

#$omaemail = "admin\@tubenet.org";
$omaemail = "leads\@tubenet.org.uk";



# number of Ads will be displays on each page
$hits =1000;
# Set allowing html tags in the ad , 1- yes,  0- no.

# Set max length in brief descriptions
$maxadln=250;
$maxpremadln=800;


 
 
# Set up general html header and footer for all ad categories
$gfoot= <<HTMLF;

<CENTER>
<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
 


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

############################################################
# Congratulations!  You've finished defining the variables.#
############################################################




 
&parse_get;
$ctmd="md";

$alue=$GET{'alue'};
$laji=$GET{'laji'};
$valinta=$GET{'valinta'};
$valinta =~ s/%/ /g;

$time_now=time; chomp($time_now);
$action=$urlbase.$catname.".pl";
$action3=$urlbase.$catname3.".pl";
$action4=$urlbase.$catname4.".pl";

#seuraava siksi jotta menee usa:han jos ei ole mitään parametrejä
$subtitle="Marketplace Messageboard";

if ($alue eq "usa") {$subtitle="USA, Canada &amp; South America";
$wallibase="http://www.tubenet.org";
}
if ($alue eq "eur") {$subtitle="Europe";
$wallibase="http://www.tubenet.org.uk"}

if ($alue eq "asi") {$subtitle="Asia &amp; Australasia";
$wallibase="http://www.tubenet.us";
}
if ($alue eq "afr") {$subtitle="Africa &amp; Middle-East";
$wallibase="http://www.tubenet.org";
}


$catheadt=$lajit{"$laji"};

$namefl=$alue.$laji;

# Names of database files that kept in the same directory
$filename =$basepath.$namefl.".dat";
$bannerfile=$basepath."/ban/".$namefl.".ban"; 
$logfilename =$basepath.$namefl.".log";
$bannerfile2=$basepath."/ban/"."indedit.ba2"; 



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

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



if (($GET{'alue'}) and ($GET{'laji'})) {
&addstart;
exit;
}



#&generalerror;
&virhemessu("general");


exit;



sub welcome
{
$nmax=$count;
$nmin=0;
if ($count>$hits){$nmin=$count-$hits;}
&viewadd;
exit;
}
















sub pagelayout
{

&htmhead2;

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


print "<TD width=90% VALIGN=TOP BGCOLOR=#000050>\n";
print "<BR>\n";
print "<CENTER><B><font FACE=\"ARIAL, HELVETICA\" COLOR=#ffffff size=5> \n";
##Seuraavassa vain se locationin näyttävä alaotsikko poistettu komenttina se jossa se on mukana
print " $catheadt</font></b></CENTER>  <CENTER><font FACE=\"ARIAL, HELVETICA\" COLOR=#ffffff><br>When making a new posting you can now add a picture</font></CENTER><BR>\n";
#print " $catheadt</font></b></CENTER>  <CENTER><font FACE=\"ARIAL, HELVETICA\" COLOR=#ffffff><B>$subtitle</B><br><br>When making a new posting you can now add a picture</font></CENTER><BR>\n";
#print "<font  face=\"Arial, Helvetica\"  size=2 color=#ffff00><B><CENTER>Under testing.  Please, inform me about problems by <a href=\"mailto:admin\@tubenet.org\"><font  face=\"Arial, Helvetica\"  size=2 color=#ffff00>clicking here</font></A>.</CENTER></B></font><br>";

##toi parametri all on turha koska käydään loopissa kuitenkin kaikki rivit läpi. Annoin sen kúitenkin olla.
## siellä banner aliohjelmassa on pantu kommenteiksi ehtolause joka tutkii tuota parametria ja printtaa bannerin jos parametri täsmää
&readbanner2("1");


#print "<BR>\n";
print "</TD></tr><tr><TD> \n";

print "<TABLE BORDER=0 COLS=1 WIDTH=\"100%\" bgcolor=#dddddd bordercolor=#dddddd>\n";
print "<TR>\n";
print "<TD>\n";
print "<CENTER><font FACE=\"ARIAL, HELVETICA\" COLOR=\"BLACK\" size=2>\n";
#print "<a href=\"$action?&alue=usa&laji=$laji\" target=\"_top\">[USA, Canada &amp;  South-America]</A> &nbsp;&nbsp;&nbsp;&nbsp;<a href=\"$action?&alue=eur&laji=$laji\">[Europe]</a> &nbsp;&nbsp;&nbsp;&nbsp;<a href=\"$action?&alue=asi&laji=$laji\">[Asia &amp; Australasia]</a>&nbsp;&nbsp;&nbsp;&nbsp; <a href=\"$action?&alue=afr&laji=$laji\">[Africa &amp; Middle-East]</a><BR>";

#######################################
#laitoin tilapäisesti tämän pois
print "[<a href=\"$action3?$ctmd=confirmaa&alue=$alue&laji=$laji\"  target=\"_top\"><font color=blue>New Posting</font></a>]</center>\n";


print "<br></TD></TR></TABLE>\n";
 
print "$htmads\n";

print "</td></tr></table>\n";
print "<table width=90% bgcolor=#dddddd bordercolor=#dddddd><tr><td>\n";
print "<CENTER><font FACE=\"ARIAL, HELVETICA\" COLOR=#000000 size=2>\n";

###################################################
# laitoin tilapäisesti tämän pois
print "[<a href=\"$action3?$ctmd=confirmaa&alue=$alue&laji=$laji\"  target=\"_top\"><font color=blue>New Posting</font></a>]<BR>\n";

#print "<a href=\"$action?&alue=usa&laji=$laji\" target=\"_top\">[USA, Canada &amp; South-America]</A> &nbsp;&nbsp;&nbsp;&nbsp;<a href=\"$action?&alue=eur&laji=$laji\" target=\"_top\">[Europe]</a> &nbsp;&nbsp;&nbsp;&nbsp;<a href=\"$action?&alue=asi&laji=$laji\" target=\"_top\">[Asia &amp; Australasia]</a>&nbsp;&nbsp;&nbsp;&nbsp; <a href=\"$action?&alue=afr&laji=$laji\" target=\"_top\">[Africa &amp; Middle-East]</a></font></CENTER>";
print "</td></TR></table>\n";


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

print "</TD></TR></TABLE></TD></TR></TBODY></TABLE></td></tr></table></DIV></TD>";
#print "</DIV></TD>";
print "   <TD vAlign=top align=center width=\"200\" bgColor=#000000 height=576>";
&readisobanner;

print "</TD></TR></TABLE></BODY></HTML>";



}












sub pagelayout2
{

&htmhead2;

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


print "<TD width=90% VALIGN=TOP BGCOLOR=#000050>\n";
print "<BR>\n";
print "<CENTER><B><font FACE=\"ARIAL, HELVETICA\" COLOR=#ffffff size=5> \n";
#seuraavassa vain se pääotsikko
print " $catheadt</font></B></CENTER> <CENTER><font FACE=\"ARIAL, HELVETICA\" COLOR=#ffffff><br>When making a new posting you can now add a picture too</font></CENTER>\n\n";
#print " $catheadt</font></B></CENTER> <CENTER><font FACE=\"ARIAL, HELVETICA\" COLOR=#ffffff><B>$subtitle</B><br><br>When making a new posting you can now add a picture too</font></CENTER>\n\n";
&readbanner("1");
#&readbanner2("2");
#print "<BR>\n";
print "</TD></tr><tr><TD> \n";
print "<table width=\"100%\" bgcolor=#dddddd bordercolor=#dddddd border=1><tr><td>\n";
if ($count < $hits) {$ylaraja=$count} else {$ylaraja = $hits}
$muutettunimi =$fields[12];
$muutettunimi =~ s/ /+/g;
$muutettunimi =~ s/,//g;

print "<b>[<a href=\"$action?$ctmd=viewadd&min=0&max=$ylaraja&alue=$alue&laji=$laji\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><b>Main Page</b></font></A>]</b> &nbsp; &nbsp; &nbsp;\n";
print "<b>[<a href=\"$action3?$ctmd=confirmaa&alue=$alue&laji=$laji\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><b>New message</B></font></a>]</b>&nbsp; &nbsp; &nbsp;<br>\n";
#print "<B>[<a href=\"$action?$ctmd=valinnat&tuho=$fields[0]&firma=$muutettunimi&alue=$alue&laji=$laji&kumpi=edit&min=0&max=$ylaraja\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><b>Change/Renew this message</b></font></a>]</b>&nbsp; \n"; 
print "<B>[<a href=\"$action?$ctmd=valinnat&tuho=$fields[0]&alue=$alue&laji=$laji&kumpi=edit&min=0&max=$fields[0]\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><b>Change/renew this message</b></font></a>]</b>&nbsp; \n"; 
#print "<b>[<a href=\"$action?$ctmd=ededit&tuho=$fields[0]&alue=$alue&laji=$laji&kumpi=press&min=0&max=$fields[0]\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><b>Send Press Release</B></font></a>]</b>\n";

print "</td><td align=right>";
if ($ekalippu ne "T")  {print "[<a href=\"$action?$ctmd=otaprev&alue=$alue&laji=$laji&tietue=$fields[0]\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><B>Previous</B></font></A>]&nbsp;&nbsp;&nbsp;";}
if ($vipalippu ne "T") {print "[<a href=\"$action?$ctmd=otanext&alue=$alue&laji=$laji&tietue=$fields[0]\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><B>Next</B></font></A>]\n";}
print "</td></TR></table>\n";

print "$htmads\n";


print "<table width=100% bgcolor=#dddddd bordercolor=#dddddd border=1><tr><td>\n";
print "<b>[<a href=\"$action?$ctmd=viewadd&min=0&max=$ylaraja&alue=$alue&laji=$laji\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><b>Main Page</b></font></A>]</b> &nbsp; &nbsp; &nbsp;\n";
print "<b>[<a href=\"$action3?$ctmd=confirmaa&alue=$alue&laji=$laji\"  target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue>New message</font></a>]</b>&nbsp; &nbsp; &nbsp;<br>\n";
#print "<b>[<a href=\"$action?$ctmd=valinnat&tuho=$fields[0]&firma=$muutettunimi&alue=$alue&laji=$laji&kumpi=edit\"  target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><b>Change/Renew this message</b></font></a>]</b>&nbsp;\n"; 
print "<b>[<a href=\"$action?$ctmd=valinnat&tuho=$fields[0]&alue=$alue&laji=$laji&kumpi=edit\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><b>Change/Renew this message</b></font></a>]</b>&nbsp;\n"; 
#print "<b>[<a href=\"$action?$ctmd=ededit&tuho=$GET{'tuho'}&alue=$GET{'alue'}&laji=$GET{'laji'}&kumpi=press\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><b>Send Press Release</B></font></a>]</b>\n";

print "</td><td align=right>";
if ($ekalippu ne "T")  {print "[<a href=\"$action?$ctmd=otaprev&alue=$alue&laji=$laji&tietue=$fields[0]\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><B>Previous</B></font></A>]&nbsp;&nbsp;&nbsp;";}
if ($vipalippu ne "T") {print "[<a href=\"$action?$ctmd=otanext&alue=$alue&laji=$laji&tietue=$fields[0]\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=blue><B>Next</B></font></A>]\n";}
print "</td></TR></table>\n";


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




print "$gfoot\n";
#print "</center>\n";
#print "</td></tr></table>";
#print "</center>";
#print "</td></TR></table></center></td></table></body></html>\n";
print "</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></td></tr></table></DIV></TD>";
print "   <TD vAlign=top align=center width=\"200\" bgColor=#000000>";
&readisobanner;
print "</td>";
print "</TR></TBODY></TABLE></BODY></HTML>";

}






sub htmlayout
{
&pagelayout;
}





sub htmlayout2
{
&pagelayout2;
}






sub adlayout
{
$alaraja=$fields[0]-1;
if (($fields[13] eq "United States")  or ($fields[13] eq "USA")){
$valinta =~ s/%/ /g;

if (($valinta eq "") or (($valinta ne "") and ($valinta eq $fields[14]))) {
$maatemp="<a href=\"$action?$ctmd=viewadd&min=0&max=$ylaraja&alue=$alue&laji=$laji&valinta=$fields[14]\" target=\"_top\"><font color=blue>";
$maatemp=$maatemp.$fields[14];
$maatemp=$maatemp."</font></a>";
} 
} 
else {
$valintatmp=$fields[13];
$valintatmp =~ s/ /%/g;

$maatemp="<a href=\"$action?$ctmd=viewadd&min=0&max=$ylaraja&alue=$alue&laji=$laji&valinta=$valintatmp\" target=\"_top\"><font color=blue>";
$maatemp=$maatemp.$fields[13];
$maatemp=$maatemp."</font></a>";
}
$lyhyt=" ".$fields[2];


if (($fields[13] eq "United States")  or ($fields[13] eq "USA")){
if (($valinta eq "") or (($valinta ne "") and ($valinta eq $fields[14]))) {

$htmads=$htmads."<table width=\"100%\"   bgcolor=\"#ffffff\" cellspacing=0 cellpadding=0>";
$nappi=$htmlbase."but21.gif";
$htmads=$htmads."<tr><td align=left valign=top width=25><IMG SRC=\"$nappi\" HEIGHT=16 WIDTH=17></td><td align=left valign=top width=700>";
$htmads=$htmads."<a href=\"$action?$ctmd=viewadd2&min=$alaraja&max=$fields[0]&alue=$alue&laji=$laji&avain=$fields[0]\" target=\"_top\"><font FACE=\"ARIAL, HELVETICA\" size=2 color=blue>";
$htmads=$htmads.$fields[12];
$htmads=$htmads."</font></a>".$lyhyt.", ".$maatemp."<br>";
$htmads=$htmads. "</td></tr></table>\n";
}
}
elsif (($valinta eq "") or (($valinta ne "") and ($valinta eq $fields[13]))) {
$htmads=$htmads."<table width=\"100%\"   bgcolor=\"#ffffff\" cellspacing=0 cellpadding=0>";
$nappi=$htmlbase."but21.gif";
$htmads=$htmads."<tr><td align=left valign=top width=25><IMG SRC=\"$nappi\" HEIGHT=16 WIDTH=17></td><td  align=left valign=top width=700>";
$htmads=$htmads."<a href=\"$action?$ctmd=viewadd2&min=$alaraja&max=$fields[0]&alue=$alue&laji=$laji&avain=$fields[0]\" target=\"_top\"><font FACE=\"ARIAL, HELVETICA\" size=2 color=blue>";
$htmads=$htmads.$fields[12];
$htmads=$htmads."</font></a>".$lyhyt.", ".$maatemp."<br>";
$htmads=$htmads. "</td></tr></table>\n";

}

}

 





  
#sub printad
#{
#&adlayout;
#}



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



sub htmend2
{

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

print " </td></tr></table></center></div></td>";

print "   <TD vAlign=top align=center width=\"200\" bgColor=#000000>";
&readisobanner;
print "</td>";

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







 

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

 


sub viewadd
{

&viewadde;
&htmlayout;
exit;
}




sub viewadd2
{
&readdata;
$ekarinki=0;
$vipavert=$count - 1;

foreach $line (@lines)
{
($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, $line);

if ($luku eq $nmax)  {
   @fields=split(/\s*\|\s*/,$line);
	if ($ekarinki eq 0) {$ekalippu="T"};
   if ($ekarinki eq $vipavert) {$vipalippu="T"};
} 
$ekarinki++;
}




$subact=$action."?$ctmd=mailaa&alue=$alue&laji=$laji&tietue=$fields[0]";
if (($fields[13] eq "United States")  or ($fields[13] eq "USA")){$viesti="$fields[14], $fields[13]"} 
else {$viesti="$fields[13]"}


$alaraja=$fields[0]-1;
$htmads=$htmads.<<HTMLF;
 

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


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

<table cellspacing=0 cellpadding=0 height=40><tr VALIGN=top>
<td valign=top width=100% >

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

</td></tr></table>
HTMLF

#$htmads=$htmads."<td width=100% align=right>";
#if ($fields[10] eq "2") {$htmads=$htmads."<FONT  COLOR=#ff0000 FACE=\"HELVETICA, ARIAL\" size=4><B>Premium<br>tration</B></font>"}
#$htmads=$htmads."</td></tr></table><P>";

 $htmads=$htmads."<table height=50 width=100%><tr><td valign=top><font FACE=\"ARIAL, HELVETICA\"  size=2><b>";

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

#@brf=split(/%-%%/,$brief);
#foreach $brf1 (@brf)
#{
$tamapview=date_format($fields[3]);

$htmads=$htmads."<br>Posted: ".$tamapview."<P>";
$htmads=$htmads."$fields[7]";

#$tamapview=date_format($fields[3]);

$htmads=$htmads."<p>Posted: ".$tamapview;


#}




$htmads=$htmads."</B></font></td>";

#seuraavalla laitetaan se kuva jos on annettu
if  ($fields[23] ne "") {$htmads=$htmads." <td valign=top><center><img src=\"$fields[23]\" border=\"0\"></center></td>"; }

$htmads=$htmads."</TR></table><p><HR>\n";





$htmads=$htmads."<center><table height=10><tr valign=bottom><td valign=bottom><form action=\"$subact\" method=\"POST\" TARGET=\"_blank\">";
#$htmads=$htmads."<input TYPE=\"hidden\" NAME=\"osoite\" value=\"$fields[4]\">";
$htmads=$htmads."<input TYPE=\"hidden\" NAME=\"firma\" value=\"$fields[12]\">";
#$htmads=$htmads."<input TYPE=\"hidden\" NAME=\"osoite2\" value=\"$fields[21]\">";
$htmads=$htmads."<input TYPE=\"hidden\" NAME=\"mikarivi2\" value=\"$fields[0]\">";
$htmads=$htmads."<input TYPE=\"hidden\" NAME=\"aluelaji\" value=\"$alue$laji\">";
$htmads=$htmads."<input TYPE=\"hidden\" NAME=\"expaika\" value=\"$fields[5]\">";
$nappitemp=$htmlbase."button2.gif";

#alla se alkuperäinen rivi
#if (($fields[5] > "965000000") or ($fields[5] == 870003720)) {if ($fields[4] ne "") {$htmads=$htmads." <input type=image src=\"$nappitemp\" width=\"103\" height=\"23\" border=0>&nbsp; "; }
if  ($fields[4] ne "") {$htmads=$htmads." <input type=image src=\"$nappitemp\" width=\"103\" height=\"23\" border=0>&nbsp; "; }
 
$nappitemp=$htmlbase."button1.gif";

$mjlength= length($fields[6]);
if (($fields[6] =~ /^http/) and ($mjlength < 12)) {$fields[6] = ""};

#alla se alkuperiäinen rivi
#if  (($fields[5] > "965000000") or ($fields[5] == 870003720)) {if  (($fields[6] =~ /^http/)  and ($fields[6] ne ""))
if  (($fields[6] =~ /^http/)  and ($fields[6] ne ""))
{
$htmads=$htmads. "<a href=\"$fields[6]\" target=\"_blank\" target=\"_top\"><font FACE=\"ARIAL, HELVETICA\" size=2 color=#aa0000>";
$htmads=$htmads. "<img src=\"$nappitemp\" width=\"82\" height=\"24\" border=\"0\"></font></a>&nbsp;&nbsp; ";
}
 
 
if ($fields[16] ne "") 
{$htmads=$htmads. "<font FACE=\"ARIAL, HELVETICA\"  size=2 color=#aa0000><B>Tel: </B></font><font FACE=\"ARIAL, HELVETICA\"  size=2><B>$fields[16]</B></font>&nbsp;&nbsp; ";}
if ($fields[17] ne "") 
{$htmads=$htmads. "<font  FACE=\"ARIAL, HELVETICA\" size=2 color=#aa0000><B>Fax: </B></font><font FACE=\"ARIAL, HELVETICA\"  size=2><B>$fields[17]</B></font>";}

#if ($fields[5] eq "1") {$htmads=$htmads."<BR><font FACE=\"ARIAL, HELVETICA\"  size=2 color=#aa0000>Website / email links are supported with valid registrations only</font>"}

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



&htmlayout2;
exit;
}

 






 
sub viewadde
{
&readdata;

$premiumlippu = "0";
$kertavain = "0";
$basiclippu = "0";
$ilmainenlippu="0";

$alue=$GET{'alue'};
$laji=$GET{'laji'};
$valinta=$GET{'valinta'};
$valinta =~ s/%/ /g;

if ($count < $hits) {$ylaraja=$count} else {$ylaraja = $hits}
$nmax=$ylaraja;



while ($nmin<$nmax) 

{ 
@fields=split(/\s*\|\s*/,$lines[$nmin] );
$nmin++;


if (($valinta eq "") or (($valinta ne "") and ($valinta eq $fields[14])) or (($valinta ne "") and ($valinta eq $fields[13])) ) {

  if (($fields[10] eq "2") and ($premiumlippu eq "0")) {
     $premiumlippu="1"; 
  }

}

if (($valinta eq "") or (($valinta ne "") and ($valinta eq $fields[14])) or (($valinta ne "") and ($valinta eq $fields[13])) ) {
if (($fields[10] eq "1") and ($basiclippu eq "0")) {
  $basiclippu="1"; 
  if ($premiumlippu eq "1") {$htmads=$htmads."<BR>"} 
}
}


if (($nmin > $hits) and ($kertavain eq "0")) {
    $kertavain = "1"; 
    $htmads=$htmads."<table width=\"100%\" bgcolor=#dddddd bordercolor=#dddddd><tr><td><FONT size=2  COLOR=#ff0000 FACE=\"HELVETICA,ARIAL\">";
    $htmads=$htmads."<HR><center><B>TubeNet Basic Listing</B></center></font></td></tr></table>"
}
#&printad;
# kokeillaan seuraavalla jos toi olis tu
&adlayout;
 }
}





sub readdata
{

  open(file, "$filename");
&lock(file);
  @lines=<file>;
$count = $#lines+1;
&unlock(file);
  close(file);
}

 


sub readbanner
{
my ($mikabanner) = @_;
$time_nyt=time; chomp($time_nyt);

#print "Haloo $exptime ja $time_nyt ja $fields[5]";

if ($fields[5] < $time_nyt) {
 open (banfile,"$bannerfile");
  &lock(banfile);
  @banner=<banfile>;
  &unlock(banfile);
  close(banfile);
  foreach $alkio (@banner) {
   	($paikka,$imgurl) = split(/\s*\|\s*/, $alkio);
#  if ($paikka eq $mikabanner) {print "<center>$imgurl</center>"}
 print "<center>$imgurl &nbsp;&nbsp;&nbsp;<A HREF=\"http://www.tubenet.org.uk/removebanner.html\" target=\"_blank\"><font  face=\"Arial, Helvetica\"  size=2 color=#ffff00>How to remove this banner</font></a></center>";
}
}
else 
{
print "<BR>";
# open (banfile,"$bannerfile");
#  &lock(banfile);
#  @banner=<banfile>;
#  &unlock(banfile);
#  close(banfile);
#  foreach $alkio (@banner) {
#   	($paikka,$imgurl,$banfirma) = split(/\s*\|\s*/, $alkio);
# print "<center><font size=2 FACE=\"ARIAL, HELVETICA\" COLOR=#ffffff>TubeNet sponsor in this category: <font color=#ffff00>$banfirma</font></font></center>";
#}
}
}
 

sub readbanner2
{
 my ($mikabanner) = @_;
 open (banfile,"$bannerfile");
  &lock(banfile);
  @banner=<banfile>;
  &unlock(banfile);
  close(banfile);
  foreach $alkio (@banner) {
   	($paikka,$imgurl, $jokin) = split(/\s*\|\s*/, $alkio);
#  if ($paikka eq $mikabanner) {print "<center>$imgurl</center>"}
 print "<center>$imgurl</center>";

}
} 









 


 


##########################
# 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 "otaprev") {&otaprev;}
    if ($GET{'md'} eq "otanext") {&otanext;}
    if ($GET{'md'} eq "addform") {&addform("Add");}
    if ($GET{'md'} eq "editform") {&addform("Edit");}
    if ($GET{'md'} eq "payform") {&addform("pay");}
    if ($GET{'md'} eq "ededit") {  &ededit;}
    if ($GET{'md'} eq "valinnat") {  &valinnat;}
    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 "loged") {&loged;}
     
    &welcome;
    exit;
}


 

sub addad
{

#&parse_form;

$FORM{'passw'} =~ s/^\s+// ;
$FORM{'passw'} =~ s/\s+$// ;
$FORM{'email'} =~ s/^\s+// ;
$FORM{'email'} =~ s/\s+$// ;
$FORM{'email2'} =~ s/^\s+// ;
$FORM{'email2'} =~ s/\s+$// ;

 if (($FORM{'passw'} eq "") || ($FORM{'title'} eq "") || ($FORM{'brief'} eq "") || ($FORM{'firma'} eq "")  ||  ($FORM{'paiva'} eq "00") ||  ($FORM{'attn'} eq "") || ($FORM{'email'} eq "") || (($GET{'mako'} ne "T") and ($FORM{'email2'} eq "")) ) {
 &htmhead2;
 print"<P><BR>";
 &omahead;
 print "<P>";
 print "<font  face=\"Arial, Helvetica\"  color=#ffffff size=5> <B>Missing information</B></font><HR><font  face=\"Arial, Helvetica\"  size=2 color=#ffffff><B>Check out below what fields you need to fill up.</B></font><P>";
 print "<table><tr><TD><font  face=\"Arial, Helvetica\"  size=2 color=#ffffff><b><UL>";
 if ($FORM{'title'} eq "") {print "<LI>Short description <br>" }
 if ($FORM{'brief'} eq "") {print "<LI>Long description<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>Primary email address<br>" }
# if ($FORM{'email2'} eq "") {print "<LI>Secondary email address<br>" }
 if (($GET{'mako'} ne "T") and ($FORM{'email2'} eq "")) {print "<LI>Secondary email address<br>" }
 if ($FORM{'passw'} eq "") {print "<LI>Password<br>" }

 print "</UL></b></font></TD></TR></Table> <P><font size=2 color=#ffff00  face=\"Arial, Helvetica\" ><B>Click your browser's Back-button</B></font><P><BR>";

 &omaend;
 &htmend2;
 exit;
}




use Time::Local;
$evuosi=$FORM{'evuosi'}-1900;
#kirjoitafileen("\nvuosi: $evuosi\n");
$ekuu=$FORM{'ekuu'}-1;
#kirjoitafileen("kuukausi: $ekuu\n");
$epaiva=$FORM{'epaiva'};
#kirjoitafileen("paiva: $epaiva");

$exptime=timelocal(0,0,0,$epaiva,$ekuu,$evuosi); 
if ($exptime < "979999999") {$exptime = "850000000"}
if  ($GET{'mako'} eq "T"){
if (($FORM{'evuosi'} eq "1997") and ($FORM{'ekuu'} eq "7") and ($FORM{'epaiva'} eq "27")) {$exptime = "870003720"}
}
&getrecord;

if ($FORM{kumpi} eq "Edit") {
 open(file, "$filename");
 &lock(file);
 @kaikki=<file>;
 &unlock(file);
 close(file);
 open(file,">$filename");
 &lock(file);
 foreach $alkio (@kaikki) {
 	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, $alkio);
   if ($FORM{'numero'} eq $luku)  {print file "$record\n"} else {print file "$alkio";}
 }
 &unlock(file);
 close(file);

###### kirjoitetaan muutos logiin
#kirjoitafileen("record: $record\n");
                      
 open(file,">>$logfilename");
 &lock(file);
 print file "$record\n";
 &unlock(file);
 close(file);

}


#Ad has been added successfuly
&message12;
&htmend2;
exit;
}

 

 

 
sub getrecord
{

$ipadd=$ENV{'REMOTE_ADDR'};


$FORM{'brief'}  = 	siivoa_kommentit(\$FORM{'brief'});
$emailbrief=$FORM{'brief'};
$brief=$FORM{'brief'};

$FORM{'title'}  = 	siivoa_kommentit(\$FORM{'title'});

$FORM{'firma'}  = siivoa_otsikot(\$FORM{'firma'});
$FORM{'firma'}  = 	siivoa_kommentit(\$FORM{'firma'});

$FORM{'puhelin'}  = siivoa_otsikot(\$FORM{'puhelin'});
$FORM{'puhelin'}  = 	siivoa_kommentit(\$FORM{'puhelin'});

$FORM{'fax'}  = siivoa_otsikot(\$FORM{'fax'});
$FORM{'fax'}  = 	siivoa_kommentit(\$FORM{'fax'});

$FORM{'attn'}  = siivoa_otsikot(\$FORM{'attn'});
$FORM{'attn'}  = 	siivoa_kommentit(\$FORM{'attn'});



&somecheck;


$idmodd="";
$mjlength= length($FORM{'urlpage'});
if (($FORM{'urlpage'} =~ /^http/) and ($mjlength < 12)) {$FORM{'urlpage'} = ""};


$time_now=time;
if ($exptime == 0) {$exptime=$time_now+15724800}
$tamapv=date_format($time_now);

$record=$FORM{'numero'}."|".$FORM{'passw'}."|".$FORM{'title'}."|".$time_now."|".$FORM{'email'};
$record=$record."|".$exptime."|".$FORM{'urlpage'}."|".$brief;
$record=$record."|".$ipadd."|".$namefl."|2|".$idmodd;
$record=$record."|".$FORM{'firma'}."|".$FORM{'maa'}."|".$FORM{'osavaltio'};
$record=$record."|".$FORM{'attn'}."|".$FORM{'puhelin'}."|".$FORM{'fax'}."|".$FORM{'paiva'}."|".$FORM{'kuu'}."|".$FORM{'vuosi'}."|".$FORM{'email2'}."|".$FORM{'category'}."|".$FORM{'url'}."|";


$erapaiva=date_format($exptime);

          $viesti = "* * * * * Please save this message for future use. * * * * * \n\n";
$viesti=$viesti."Thank you for keeping your details accurate on TubeNet. \n";
$viesti=$viesti."This is your confirmation about successful change of your  \n";
$viesti=$viesti."Marketplace message to TubeNet.\n\n";

$viesti=$viesti."Below, please find some of your message details.\n";
$viesti=$viesti."-------------------------------------------------------------------------------------\n";
#$viesti=$viesti."Message ID# : ".$idnum."\n";
$viesti=$viesti."Your password : ".$FORM{'passw'}."\n";
$viesti=$viesti."Date posted : ".$tamapv."\n";

#if ($exptime > $time_now) {
$viesti=$viesti."Expiry date : ".$erapaiva."\n"; 
$viesti=$viesti."Primary email address : ".$FORM{'email'}."\n";
$viesti=$viesti."Secondary email address : ".$FORM{'email2'}."\n";  
$viesti=$viesti."Web site : ".$FORM{'urlpage'}."\n";
$viesti=$viesti."Contact person : ".$FORM{'attn'}."\n";

#}
#else {
#$viesti=$viesti."Expiry date : Expired. \n";
#$viesti=$viesti."Primary email address : Not enabled.\n";
#$viesti=$viesti."Secondary email address : Not enabled.\n";  
#$viesti=$viesti."Web site hot link: Not enabled.\n";
#}
$viesti=$viesti."Category : ".$catheadt."\n";
$viesti=$viesti."Your IP address recorded : ".$ipadd."\n";
#$viesti=$viesti."Company name : ".$FORM{'firma'}."\n";
$viesti=$viesti."Country : ".$FORM{'maa'}."\n";
if (($FORM{'maa'} eq "USA") or ($FORM{'maa'} eq "United States")) {$viesti=$viesti."State : ".$FORM{'osavaltio'}."\n"};

#$viestij="Expiry date : ".$erapaiva."\n"; 
#$viestij=$viestij."Primary email address : ".$FORM{'email'}."\n";
#$viestij=$viestij."Secondary email address : ".$FORM{'email2'}."\n";  
#$viestij=$viestij."Web site : ".$FORM{'urlpage'}."\n";

#$viestij=$viestij."Contact person : ".$FORM{'attn'}."\n";
#$viestij=$viestij."Short description : ".$FORM{'title'}."\n";
#$viesti=$viesti."Long description :\n\n";
#$viesti=$viesti.$emailbrief;
#$viesti=$viesti."\n\nBest regards,\nJuha Haapala";
$viesti=$viesti."---------------------------------------------------\n";
$viesti=$viesti."TubeNet - The Site for Tube and Pipe Industries\n";
$viesti=$viesti."US site: www.tubenet.org  Mirrors: Europe and Asia\n";
$viesti=$viesti."E-mail: info\@tubenet.org\n";
$viesti=$viesti."---------------------------------------------------\n";
#if (($ostype eq "u") and ($GET{'mako'} ne "T")){
if ($ostype eq "u") {


open (MAIL,"|$mailprogram");
   print MAIL "To: $FORM{'email'}\n";
   print MAIL "From: $omaemail\n";
   print MAIL "Subject: Your TubeNet Marketplace\n";
   print MAIL "$viesti\n$viestij";
  close (MAIL);


#open (MAIL,"|$mailprogram");
#   print MAIL "To: $FORM{'email2'}\n";
#   print MAIL "From: $omaemail\n";
#   print MAIL "Subject: Your TubeNet Marketplace message\n";
#   print MAIL "$viesti\n$viestij";
#  close (MAIL);


open (MAIL,"|$mailprogram");
   print MAIL "To: $omaemail\n";
   print MAIL "From: $omaemail\n";
   print MAIL "Subject: TubeNet Message board  muutos tehty\n";
   print MAIL "$viesti\n";
  close (MAIL);
}

}

 

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 addform
{
my ($kumpi) = @_;

#tällä mennään suoraan uuden lisäämiseen jos kyse ei ole editoinnista, mikä tarkistetaan tossa alapuolella
$olioikia=1;
$rivijemma="";

if (($kumpi eq "Edit") or ($kumpi eq "pay")) {
  $olioikia=0;
  open(file, "$filename");
  &lock(file);
  while ($line = <file>) {
	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, $line);

$FORM{'passw'} =~ s/^\s+// ;
$FORM{'passw'} =~ s/\s+$// ;

  if ((($luku eq $FORM{'numero'}) and  ($pass eq $FORM{'passw'})) || (($luku eq $FORM{'numero'}) and  ($FORM{'passw'} eq "5188"))) {$olioikia=1;$rivijemma=$line} 
  }
  &unlock(file);
  close file;

  if ($olioikia eq 1) {
  ($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, $rivijemma);
 $brief =~ s/<BR>/\n/g;

  }
  else {
($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, $rivijemma);
  &htmhead2;
  &omahead;
  print "<BR>";
  print "    <font  face=\"Arial, Helvetica\"  color=#ffffff size=5> <B>Invalid Password</font><HR>";
#  print "<FONT SIZE=\"-1\">Click back to Main Page :Se eka: $pass  Se toka:$FORM{'passw'}   numero:$FORM{'numero'} $title</font><P><BR>";
  print "<FONT size=2 color=#ffff00  face=\"Arial, Helvetica\" ><B><BR><P><font size=2 color=#ffff00><B>Click your browser's Back-button</B></font><P><BR></B></font><P><BR>";
  &omaend; 
  &htmend2;
  exit;
  }





if ($kumpi eq "pay") {

&maksa;
exit;


} #if pay

} # if edit

else
{
$rivijemma="";
($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, $rivijemma)
}



if ($kumpi eq "Add") {$urlpage = "http://"}
$mako="";
if ($FORM{'passw'} eq "5188") {  $mako="T" }

$subact=$action."?$ctmd=addad&alue=$alue&laji=$laji&mako=$mako";
$nocashe="";
&htmhead2;


($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)= localtime(time) ;
($sec,$min,$hour,$epaiva,$ekuu,$evuosi,$wday,$yday,$isdst)= localtime($exptime) ;

#   $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;

$time_now=time;
#if ($exptime == 0) {$exptime=$time_now+15724800}
 


  print <<HTMLF;


<form action="$subact" method="POST" target=\"_top\">


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


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

#if ($time_now > $exptime) { print "<font  face=\"Arial, Helvetica\"  size=2 color=#ffff00><B>This registration is expired.  Only every second inquiry will be forwarded to you.</B></font>";}

print <<HTMLF;

<BR></CENTER>
</td></tr></table>


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

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

<tr bgcolor=#000050><td valign="top"><font  face="Arial, Helvetica"  size=2 color=#ffffff>
<B>Company Name </B></font><font size="+1"  color=#ffff00><B>*</B></font></td><td bgcolor=#000050><font  face="Arial, Helvetica"  size=2>
<INPUT TYPE=text NAME=firma SIZE=30 MAXLENGTH="45" value="$firma"></font></td></tr>
HTMLF
;


print "<tr bgcolor=#000050><td valign=\"top\"><font  face=\"Arial, Helvetica\"  size=2 color=#ffffff>";
print "<B>Country</B></font><font size=\"+1\"  color=#ffff00><B>*</B></font></td><td bgcolor=#000050><font  face=\"Arial, Helvetica\"  size=2>";
print "<Select Name=\"maa\">\n";

foreach $alkio (@maataulu) {
print "<OPTION ";
if (($kumpi eq "Add") and (($alkio eq "United States") or ($alkio eq "USA"))) {print "SELECTED "}
if ($maa eq "USA") { $maa = "United States"}
if (($kumpi eq "Edit") and ($alkio eq $maa)) {print "SELECTED "}
print " VALUE=\"$alkio\">$alkio\n";
}

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



if (($kumpi eq "Edit") and ($maa eq "United States")) {
print "<tr bgcolor=#000050><td valign=\"top\"><font  face=\"Arial, Helvetica\"  size=2 color=#ffffff>";

print "<B>State</B></font><font size=\"+1\"  color=#ffff00><B>*</B></font><FONT color=#ffffff  face=\"Arial, Helvetica\"  SIZE=\"-2\"><B>(Needed only if you are from US)</B></FONT></td><td bgcolor=#000050>";
print "<font  face=\"Arial, Helvetica\"  size=2><Select  Name=\"osavaltio\">";
foreach $alkio (@osavaltiotaulu) {
print "<OPTION ";
if (($kumpi eq "Edit") and (($maa eq "United States") or ($maa eq "USA")) and ($alkio eq $osavaltio)) {print "SELECTED "}
print " VALUE=\"$alkio\">$alkio";
}
print "</SELECT></font> ";
print "</td></tr>";
}
 print <<HTMLF;





<tr bgcolor=#000050><td valign="top"><font  face="Arial, Helvetica"  size=2 color=#ffffff>
<B>Contact person</B></font><font size="+1"  color=#ffff00><B>*</B></font></td><td bgcolor=#000050><font  face="Arial, Helvetica"  size=2><INPUT TYPE=text NAME=attn SIZE=50 MAXLENGTH="50" value="$attn"></font></td></tr>

<tr bgcolor=#000050><td valign="top"><font  face="Arial, Helvetica"  size=2 color=#ffffff>
<B>Email 1</B></font><font size="+1"  color=#ffff00><B>*</B><FONT color=#ffffff  face="Arial, Helvetica"  SIZE=\"-2\"><b>(Only one address please)</B></FONT></font></td><td bgcolor=#000050><font  face="Arial, Helvetica"  size=2><INPUT TYPE=text NAME=email SIZE=30 MAXLENGTH="50" value="$email"></font></td></tr>

<tr bgcolor=#000050><td valign="top"><font  face="Arial, Helvetica"  size=2 color=#ffffff>
<B>Email 2</B></font><font size="+1"  color=#ffff00><B>*</B><FONT color=#ffffff  face="Arial, Helvetica"  SIZE=\"-2\"><b>(Important! This will be used for reporting <BR>about possible problems with  the above email address)</B></FONT></font></td><td bgcolor=#000050><font  face="Arial, Helvetica"  size=2><INPUT TYPE=text NAME=email2 SIZE=30 MAXLENGTH="50" value="$email2"></font>


<INPUT TYPE="hidden" NAME="category" value=$alue$laji>
</td></tr>


<tr bgcolor=#000050><td valign="top"><font  face="Arial, Helvetica"  size=2 color=#ffffff>
<B>Phone</B></font></td><td bgcolor=#000050><font  face="Arial, Helvetica"  size=2><INPUT TYPE=text NAME=puhelin SIZE=30 MAXLENGTH="25" value="$puhelin"></font></td></tr>

<tr bgcolor=#000050><td valign="top"><font  face="Arial, Helvetica"  size=2 color=#ffffff>
<B>Fax</B></font></td><td bgcolor=#000050><font  face="Arial, Helvetica"  size=2><INPUT TYPE=text NAME=fax SIZE=30 MAXLENGTH="25" value="$fax"></font></td></tr>

<tr bgcolor=#000050><td valign="top"><font  face="Arial, Helvetica"  size=2 color=#ffffff>
<B>WEB-Site</B></font></td><td bgcolor=#000050><font  face="Arial, Helvetica"  size=2><INPUT TYPE=text NAME=urlpage SIZE=30 MAXLENGTH="50"  value="$urlpage"></font></td></tr>

<tr bgcolor=#000050><td><font  face="Arial, 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="Arial, Helvetica"  size=2> <INPUT TYPE=text NAME=passw SIZE=30  MAXLENGTH="10" value="$pass"></font></td></tr>

<tr bgcolor=#000050><td valign="top"><font  face="Arial, 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="Arial, Helvetica"  size=2><INPUT TYPE=text NAME=pass2 SIZE=30  MAXLENGTH="10" value="$pass"></font>



HTMLF
;

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




 print <<HTMLF;

<table border=1 cellspacing=0 bgcolor=#000050 width=100%><tr bgcolor=#505070><td  bgcolor=#000050><font  face="Arial, Helvetica"  size=2 color=#ffffff>
<B>Short description </B></font><font size="+1" color=#ffff00><B>*</B></font></td></tr><tr><td><font  face="Arial, Helvetica"   size=-1>
<INPUT TYPE="text" NAME="title" SIZE="60" MAXLENGTH="60" value="$title"></font></td></tr></table>


<table border=1 cellspacing=0 bgcolor=#000050 width=100%><tr bgcolor=#505070><td  bgcolor=#000050><font  face="Arial, Helvetica"  size=2 color=#ffffff>
<B>Long description below.  </B></font><font size="+1"  color=#ffff00><B>*</B></font></td></tr><tr><td><font  face="Arial, Helvetica"   size=-1>
HTMLF
;
 

print "<TEXTAREA NAME=\"brief\" ROWS=\"4\" COLS=\"60\">";

##$brief =~ s/<br>//g;
##$brief =~ s/\n//g;
##print "$brief";
#$laskija=50;
#$alku=0;
#$eka=substr($brief,$alku,$laskija);
#print "$eka";
#
#while ($laskija < length($brief)) {
#$toka=substr($brief,$laskija,50);
#$paikka=index($toka, " ");
#$toka_alku=substr($toka,0,$paikka);
#$toka_loppu=substr($toka,$paikka,50);
#$toka_loppu =~ s/^\s*//;
#print "$toka_alku \n";
#print "$toka_loppu";
#$alku=$laskija;
#$laskija=$laskija+50;
#}

print "$brief";

print "</TEXTAREA>";

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

print "<table border=1 cellspacing=0 bgcolor=#000050 width=100%><tr bgcolor=#505070><td  bgcolor=#000050>";
print" <font face=\"Arial, Helvetica\" size=2 color=#ffffff>";
print "<B>Picture URL </B></font><FONT color=#ffffff  face=\"Arial, Helvetica\"  SIZE=\"-2\">";
print "<b>(If you have a picture on your website, you can enter it's address here and it will show with the message)</B></font>";
print "</td></tr><tr><td><font  face=\"Arial, Helvetica\"   size=-1>";
print "<INPUT TYPE=\"text\" NAME=\"url\" SIZE=\"60\"  value=\"$url\"></font></td></tr></table>";


print"<INPUT TYPE=\"hidden\" NAME=\"kumpirek\" VALUE=\"2\">";

$erapaiva=date_format($exptime);
$ekuu++;
$evuosi=1900+$evuosi;
$mako="";
if ($FORM{'passw'} eq "5188") {
  $mako="T";
  print "<INPUT TYPE=text NAME=epaiva SIZE=2 MAXLENGTH=\"2\"  value=\"$epaiva\">";
  print "<INPUT TYPE=text NAME=ekuu SIZE=2 MAXLENGTH=\"2\"  value=\"$ekuu\">";
  print "<INPUT TYPE=text NAME=evuosi SIZE=4 MAXLENGTH=\"4\"  value=\"$evuosi\">";
}
else {
  print "<INPUT TYPE=hidden NAME=epaiva  value=\"$epaiva\">";
  print "<INPUT TYPE=hidden NAME=ekuu   value=\"$ekuu\">";
  print "<INPUT TYPE=hidden NAME=evuosi    value=\"$evuosi\">";
}






 print <<HTMLF;


<!--  </TABLE> 
 -->

<table border=1 width=100%><tr bgcolor=#000050><td valign="top">
<CENTER><FONT  face="Arial, 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 Message board message to TubeNet"> <BR>
<B>Click only once. This may take some time.</B></FONT>
</CENTER></TD></TR>
</TABLE>

</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%>";
print "<tr>";
print "<td>";
print "<table border=0 cellspacing=20   bgcolor=#000050 width=100%><tr bgcolor=#505070><td bgcolor=#000050 align=left>";
print "<BR>";
print "    <CENTER><font color=#ffffff  size=+2 FACE=\"ARIAL, HELVETICA\">Delete message board message</Font><BR><HR><BR> ";
print "<FONT SIZE=\"-1\" color=#ffffff FACE=\"ARIAL, HELVETICA\">Message will be deleted only if you enter<br> the same Password  <BR> that was given when the<br> message was made.<br><br>Please enter the Password below and click <BR>\"Remove\" button.";
print "</FONT></center></td></tr></table>";

$subact=$action."?$ctmd=delrecord&alue=$alue&laji=$laji";
print "<form action=\"$subact\" method=\"POST\" target=\"_top\">";
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="Arial, Helvetica"  size=2 color=#ffffff>
<B>Password:</B>
</font>
<font  face="Arial, Helvetica"  size=2> 
<INPUT TYPE=text 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>
<CENTER>
<font  face="Arial, Helvetica"   color=#ffffff SIZE="-1"><BR>
<INPUT TYPE="submit" value="Remove"> <BR>
</FONT>
</CENTER></TD></TR>
</TABLE>
</FORM>
HTMLF

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

<form action="$subact" method="POST" target=\"_top\">
<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>
<CENTER> <font  face="Arial, Helvetica"   color=#ffffff SIZE="-1"><BR>
<INPUT TYPE="submit" value="Forget password? Click here"> <BR>
</FONT>
</CENTER></TD></TR>
</TABLE>
</FORM>


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

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

&htmend2;
exit;
}
 



sub ededit
{
$nocashe="";
&htmhead2;
#&parse_form;


print "<center>";
print "<table border=1 cellspacing=0  bgcolor=#000050 width=70%>";
print "<tr>";
print "<td>";
print "<table border=0 cellspacing=20   bgcolor=#000050 width=100%><tr bgcolor=#505070><td bgcolor=#000050 align=left>";
print "<BR>";
print "    <CENTER><font color=#ffffff  size=+2 FACE=\"ARIAL, HELVETICA\"><B>Password Check</B></font><BR><HR><BR> ";
print "<FONT color=#ffffff  size=2 FACE=\"ARIAL, HELVETICA\">If you have got your password already, please enter it below<br>and click \"Send Password\" button in order to continue.<br><BR>";

if ($GET{'kumpi'} eq "uusinta") {$subact=$action."?$ctmd=payform&alue=$alue&laji=$laji"}
if ($GET{'kumpi'} eq "edit") {$subact=$action."?$ctmd=editform&alue=$alue&laji=$laji"}
if ($GET{'kumpi'} eq "press") {$subact=$action4."?$ctmd=confirmaa&alue=$alue&laji=$laji"}
print "<form action=\"$subact\" method=\"POST\" target=\"_top\">";
print "<INPUT TYPE=\"hidden\" NAME=\"numero\" value=$GET{'tuho'}>";

print <<HTMLF;

<font  face="Arial, Helvetica"  size=2 color=#ffffff>
<B>Password:</B>
</font>
<font  face="Arial, Helvetica"  size=2> 
<INPUT TYPE=text NAME=passw SIZE=20> 
</font>

<INPUT TYPE="submit" value="Send Password"> </form><BR><br>
HTMLF
$subact=$action."?$ctmd=forget&alue=$alue&laji=$laji";
print "<form action=\"$subact\" method=\"POST\" target=\"_top\">";
print "<INPUT TYPE=\"hidden\" NAME=\"numero\" value=$GET{'tuho'}>";
print "Forget password?  <INPUT TYPE=\"submit\" value=\"Please check this first\"> <BR></FORM>";
$subact=$action."?$ctmd=mailaa&alue=$alue&laji=$laji&oma=oma";
print "<form action=\"$subact\" method=\"POST\" target=\"_top\">";
print "<INPUT TYPE=\"hidden\" NAME=oma value=oma>";
print "Never received one?  <INPUT TYPE=\"submit\" value=\"Click here and we will send you\"></form>";
print <<HTMLF;

</FONT>
</CENTER></TD></TR>
</TABLE>


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


HTMLF

&htmend2;
exit;
}
 












sub delrecord
{

$subact=$action."?$ctmd=addad&alue=$alue&laji=$laji";
$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,$passw,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = 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,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, $line);
$FORM{'passw'} =~ s/^\s+// ;
$FORM{'passw'} =~ s/\s+$// ;

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;


if ($olioikia eq 1) {
rename($nimi,$filename);

&omahead;

print "<BR>";
print " <font  face=\"Arial, Helvetica\"  color=#ffffff size=5> <B>The entry has been removed</font><HR>";
#print "<p><a href=\"$action?$ctmd=md&alue=$alue&laji=$laji\"  target=\"_top\"> <font size=2  face=\"Arial, Helvetica\"  color=#ffff00><B>Click here to view updated Messages :Se eka: $pass  Se toka:$FORM{'passw'}  numero:$FORM{'numero'}</B></font> </a><BR>";
print "<p><a href=\"$action?$ctmd=md&alue=$alue&laji=$laji\" target=\"_top\" > <font size=2   face=\"Arial, Helvetica\" color=#ffff00><B><P> Click here to view updated messages</B></font> </a><BR><br>";
&omaend;
&htmend2;
exit;
}
 

 

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




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







sub omahead
{
print "<center>";
print "<table border=1 cellspacing=0  bgcolor=#000050 width=70%>";
print "<tr>";
print "<td>";
print "<table border=1 cellspacing=0   bgcolor=#000050 width=100%><tr bgcolor=#505070><td bgcolor=#000050 align=left>";
print "<center>";
print "<BR>";
}










 




 



sub mailaa {

#&parse_form;

$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\"  target=\"_top\"\n";
print "  action=\"http://www.tubenet.org.uk/cgi/bend2bc.cgi\">\n";

#if ($FORM{'osoite'} eq "") {
#print "<INPUT type=\"hidden\" name=\"ID\" value=\"admin\@tubenet.org\">\n";
#}
#else
#{
#print "<INPUT type=\"hidden\" name=\"ID\" value=\"$FORM{'osoite'}\">\n";
#print "<INPUT type=\"hidden\" name=\"ID2\" value=\"$FORM{'osoite2'}\">\n";
print "<INPUT type=\"hidden\" name=\"mikarivi2\" value=\"$FORM{'mikarivi2'}\">\n";
print "<INPUT type=\"hidden\" name=\"aluelaji\" value=\"$FORM{'aluelaji'}\">\n";
#}

# seuraavilla 3:lla rivillä saadaan aikaan se että emailiin tulee mukaan ilmoitus että rekisteröinti on erääntynyt
# se toii yhdessä bend2bc.cgi n kanssa jossa tutkitaanonko exp arvo asetettu
#if (($FORM{'expaika'} < $time_now) or ($FORM{'expaika'} == 870003720)) {
#    print "<INPUT type=\"hidden\" name=\"EXP\" value=\"\">\n";
#}

print "<INPUT type=\"hidden\" name=\"CATEGORIA\" value=\"$catheadt\">\n";
print "<INPUT type=\"hidden\" name=\"FIRMA\" value=\"$FORM{'firma'}\">\n";


print "<center><table  width=\"70%\"><tr><td>\n";
print "<center><FONT  face=\"Arial, Helvetica\"  size=5><B> \n";
print " TubeNet Email forwarding Service</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 "<TABLE>\n";
print "<TR>\n";
print "<TD valign=\"top\" width=150>\n";

#if ($FORM{'osoite'} eq "") {
#print "<B>Send email to:</B> </TD><TD>TubeNet</TD>\n";
#}
#else {
print "<B>Send email to:</B> </TD><TD>$FORM{'firma'}</TD>\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  face=\"Arial, Helvetica\"  size=2 COLOR=\"#ff0000\">\n";
print "Attention. Please make sure that your email address has correct spelling. \n";
print " <B>You will not get any reply if this goes wrong. </B>\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\">\n";
print "<BR>\n";
print "<P>\n";
print "<B>Your Message\:</B><BR>\n";

#if ($FORM{'osoite'} eq "") {
#print "<TEXTAREA NAME=\"BODY\" ROWS=\"15\" COLS=\"60\">[$GET{'alue'}$GET{'laji'}] \nEnter your company name and your own name below\n";
#print "------------------------------------------------------------------------------------------------------------------\n";
#}
#else {

$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;
#$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";

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


#print "<TEXTAREA NAME=\"BODY\" ROWS=\"15\" COLS=\"60\">$viesti</TEXTAREA>\n";
print "<TEXTAREA NAME=\"BODY\" ROWS=\"15\" COLS=\"60\">$viesti</TEXTAREA>\n";
print "<BR>--------------------------------------------------------------------\n<br>";

print "<INPUT TYPE=\"hidden\" NAME=\"kysymys\" VALUE=\"$viesti2\">\n";
#print "<BR>\n<br>";
#print "$brief";

#}
print "</TEXTAREA>\n";
print "<BR>\n";
print "<P>\n";
print "<table><tr><td valign=top>Type the alphabets shown below:<br><img src=\"kirjainkuva.jpg\" width=\"160\" height=\"25\"> \n";
print "</td><td valign=top><INPUT TYPE=\"text\"  name=\"kirjaimet\" SIZE=\"40\"></td></tr>\n";
print "</TABLE>\n";
print "<INPUT TYPE=\"submit\"  value=\"Send this email to ";

#if ($FORM{'osoite'} eq "") {
#print "TubeNet\">  <BR>\n"; }
#else {
print "$FORM{'firma'}\">  <BR>\n"; 
#}

print "</td></TR></table></center>\n";
print "</FORM>\n";
print "<P><BR>\n";
&htmend2;

exit;
}
}
}


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

print "<form action=\"$subact\" method=\"POST\" target=\"_top\">";
print "<center>";
print "<table border=1 cellspacing=0  bgcolor=#000050 width=70% >";
print "<tr>";
print "<td>";
print "<table border=0 cellspacing=20   bgcolor=#000050 width=100%><tr bgcolor=#505070><td bgcolor=#000050 align=left><font  face=\"Arial, Helvetica\"   size=2 color=#ffffff>";
print "<BR>";

$iposoite=$ENV{'REMOTE_ADDR'};

print "    <CENTER><font  face=\"Arial, Helvetica\"  color=#ffffff size=5>Password assistant</font><HR>";
print "<FONT  face=\"Arial, Helvetica\"  size=2>The password will be sent to the email address<br>that appears only your registration at TubeNet.<P>";
print "<FONT  face=\"Arial, Helvetica\"  size=2>Your IP-Address there now is: <font color=\"#ffff00\">$iposoite</font><br>";
print "<FONT  face=\"Arial, Helvetica\"  size=2>For security purposes, it will be recorded.<P>";
print "<FONT  face=\"Arial, Helvetica\"  size=2>Please enter your name below";

print "</FONT></CENTER></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="Arial, Helvetica"  size=2 color=#ffffff>
</font><font  face="Arial, Helvetica"  size=2> 
HTMLF

print "<INPUT TYPE=\"text\" NAME=\"vertailuemail\" SIZE=\"40\">";


print <<HTMLF;

</font></CENTER>


<table border=0 cellspacing=0  bgcolor=#000050 width=100%><tr bgcolor=#000050><td bgcolor=#000050 align=left><font  face="Arial, Helvetica"   color=#ffffff>

<CENTER><FONT  face="Arial, Helvetica"  size=2><BR>
<INPUT TYPE="submit" value="Click here for sending your password"> <BR>
<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;

# otetaan pois se emailien vertaus ja siksi seuraava rivi laitetaan ykköseksi. SE oli nolla aiemmin ennen tutkimuksia.
$oliemail= "0";
$oliemail2= "0";

open(file, "$filename");
&lock(file);



  @rivit=<file>;

&unlock(file);
close file;

  foreach $line (@rivit) {



#while ($line = <file>) {
	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$mainpagetitle,$url) = split(/\s*\|\s*/, $line);

if ($luku eq $FORM{'numero2'})  {
   if ($email)  {$oliemail= "1"; $kelle=$email; $psw=$pass} 
   if ($email2)  {$oliemail2= "1"; $kelle2=$email2} 
}
} #while


$viestix ="This inquiry was made by: $FORM{'vertailuemail'}\n\n";
$viestix = $viestix."\nHere is the requested password:\n\n";
$viestix = $viestix."- Password: $psw\n";
$viestix = $viestix."- Category: $lajit{$laji}\n";
$viestix = $viestix."- Location: $alueet{$alue}\n";
if ($oliemail eq "1") {$viestix = $viestix."- Email: $kelle\n";}
if ($oliemail2 eq "1") {$viestix = $viestix."- Email2: $kelle2\n\n";}
$viestix = $viestix."Sincerely,\nThe TubeNet Team\n\n";
$viestix = $viestix."P.S. If you have received this email in error, please contact us\nat admin\@tubenet.org. We apologize for the inconvenience.\n";


#&kirjoitafileen("\nkelle: $kelle\n");
#&kirjoitafileen("\nkelle2: $kelle2\n");
$omaemailx="admin\@tubenet.org.uk";

if ($oliemail eq "1") {
&omahead;print "<BR>";
print "    <font  face=\"Arial, Helvetica\"  color=#ffffff size=5> <B>Password has been sent to:<br>";
print "$kelle</b></font><br> ";


$mailprogramx = "/usr/sbin/sendmail -t -oi";

open (MAIL,"|$mailprogramx");
   print MAIL "To: $kelle\n";
   print MAIL "From: $omaemailx\n";
   print MAIL "Subject: Your TubeNet Registration password\n";
   print MAIL "$viestix";
  close (MAIL);
open (MAIL,"|$mailprogramx");
   print MAIL "To: $omaemailx\n";
   print MAIL "From: $omaemailx\n";
   print MAIL "Subject: Joku unohti passwordin\n";
   print MAIL "$viestix\n";
  close (MAIL);
}

if ($oliemail2 eq "1") {
print "   <font  face=\"Arial, Helvetica\"  color=#ffffff size=5> <B>and<br>";
print "$kelle2</b></font><P> ";

open (MAIL,"|$mailprogramx");
   print MAIL "To: $kelle2\n";
   print MAIL "From: $omaemailx\n";
   print MAIL "Subject: Your TubeNet Registration password\n";
   print MAIL "$viestix";
  close (MAIL);
}

if (($oliemail eq "0") and ($oliemail2 eq "0")) {
&omahead;print "<BR>";
print "    <font  face=\"Arial, Helvetica\"  color=#ffffff size=5> <B>There is no email address<br>where to send your password.<p>";
print "Please contact <P>admin\@tubenet.org<P> and ask for it.</b></font><P> ";
}

print "<p> <font size=2  face=\"Arial, Helvetica\" color=#ffff00><B>Click your browser's Back-button</B></font><P><BR>";
&omaend;
&htmend2;
exit;

 

 

if ($olioikia eq 0) {
&omahead;
print "<BR>";
print "    <font  face=\"Arial, Helvetica\"  color=#ffffff size=5>Invalid email address</font><HR>";
#print "<FONT  face=\"Arial, Helvetica\"  size=2>Click back to Main Page :Se eka: $pass  Se toka:$FORM{'passw'}   numero:$FORM{'numero2'} <P><BR>";
print "<p> <font  face=\"Arial, Helvetica\"  size=2 color=#ffff00><B>Click your browser's Back-button</B></font><P><BR>";
&omaend;
&htmend2;
exit;
}
}






sub otaprev
{


$tietue=$GET{'tietue'};

open(file, "$filename");
&lock(file);
@kaikki=<file>;
@nurin=reverse(@kaikki);

($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, @kaikki[0]);
$eka_alkio=$luku;
($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, @nurin[0]);
$vipa_alkio=$luku;
&unlock(file);
close(file);

$loytyi=0;
$rinki=0;
$lask=0;
$ekalippu="F";
$vipalippu="F";

foreach $alkio (@nurin) {
	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, $alkio);
$rinki++;
if ($tietue eq $eka_alkio) {
$loytyi= "1";$nmax=$eka_alkio; $ekalippu="T";
}
elsif ($tietue eq $luku) {
($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, @nurin[$rinki]);
$loytyi= "1";$nmax=$luku;}
}

&viewadd2;


}


sub otanext
{

$tietue=$GET{'tietue'};

open(file, "$filename");
&lock(file);
@kaikki=<file>;
@nurin=reverse(@kaikki);

($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, @kaikki[0]);
$eka_alkio=$luku;
($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, @nurin[0]);
$vipa_alkio=$luku;
&unlock(file);
close(file);

$loytyi=0;
$rinki=0;
$lask=0;
$ekalippu="F";
$vipalippu="F";

foreach $alkio (@kaikki) {
	($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, $alkio);
$rinki++;
if ($tietue eq $vipa_alkio) {
$loytyi= "1";$nmax=$vipa_alkio; $vipalippu="T";
}
elsif ($tietue eq $luku) {
($luku,$pass,$title,$time_now,$email,$exptime,$urlpage,$brief,$ipadd,$namefl,$kumpirek,$idmodd,$firma,$maa,$osavaltio,$attn,$puhelin,$fax,$paiva,$kuu,$vuosi,$email2,$category,$url) = split(/\s*\|\s*/, @kaikki[$rinki]);
$loytyi= "1";$nmax=$luku;}
}

&viewadd2;




}








sub valinnat
{

&htmhead2;
&omahead;
print "<P><BR>";
#print "<font FACE=\"ARIAL, HELVETICA\" >";
print "<b><font  size=5 color=#ffffff FACE=\"ARIAL, HELVETICA\" >Change / Update Message Board Message</font></b><p>\n";
print "<table><tr><td>";
$max=$GET{'max'};
#$gmt =~ s/ /+/g;
#$gmt =~ s/,//g;
print "<a href=\"$action?$ctmd=ededit&tuho=$GET{'tuho'}&alue=$GET{'alue'}&laji=$GET{'laji'}&kumpi=edit\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=#ffff00><B>Change your Message Board message information</b></font></a> <BR>\n"; 
#print "<a href=\"$action?$ctmd=ededit&tuho=$GET{'tuho'}&alue=$GET{'alue'}&laji=$GET{'laji'}&kumpi=uusinta\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=#ffff00><B>Renew tration by paying the fee</b></font> </a><BR>\n"; 
print "<a href=\"$action?$ctmd=eddelet&tuho=$GET{'tuho'}&alue=$GET{'alue'}&laji=$GET{'laji'}\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=#ffff00><B>Delete Message</B></font></a> \n"; 
print "</td></tr></table>";
print "<P>";
print "<b>[<a href=\"$action?$ctmd=viewadd2&min=$alaraja&max=$max&alue=$alue&laji=$laji&avain=$fields[0]\" target=\"_top\"><font size=2 FACE=\"ARIAL, HELVETICA\" color=#ffff00><B>Back</b></font></A>]</b> &nbsp; &nbsp; &nbsp;\n<br>";
print "<BR>";

&omaend;
&htmend2;
exit;
}




sub kirjoitafileen
{
my ($kumpi) = @_;

$file66=$basepath."tsekki.dat";

open(file3, ">>$file66");
&lock(file3);
print file3 "$kumpi\n";
&unlock(file3);
close(file3);
}


sub hae_erapaiva {

print "<table><tr bgcolor=#000050><td valign=\"top\"><font  face=\"Arial, Helvetica\"  size=2 color=#ffffff>";
print "<B>Aseta eräpäivä</B> </td><td bgcolor=#000050>";


print "<Select Name=epaiva>";

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

if ($i<10) {
$vert = "0";
$vert =~ s/0/0$i/g;
if (($kumpi eq "Edit") and ($epaiva eq $vert)) { print " SELECTED "}
print " VALUE=0$i>0$i";
}
else {
if (($kumpi eq "Edit") and ($epaiva eq $i )) { print " SELECTED "}
print " VALUE=$i>$i";
}
}

print "</SELECT>";

print "<Select Name=ekuu>";
$i = 1;
for $i (1...12) {
print "<OPTION ";
if (($kumpi eq "Edit") and ($i eq $ekuu)) { print " SELECTED "}
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=evuosi>";
if ($evuosi eq "") {$evuosi=1950}
for $i (1900...2000) {
print "<OPTION ";
if (($kumpi eq "Add") and ($i==1950)) {print "selected"}
if (($kumpi eq "Edit") and ($i==$evuosi)) {print "selected"}


print "  VALUE=$i>$i";
}
print "</Select>";

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

}

sub readisobanner
{
 open (banfile,"$bannerfile2");
  &lock(banfile);
  @banner=<banfile>;
  &unlock(banfile);
  close(banfile);
$roll = int(rand 7) + 1;
$luku=0;
  foreach $alkio (@banner) {
 $luku++;
   	($numero, $imgurl, $jokin) = split(/\s*\|\s*/, $alkio);

#if ($luku eq $roll) {$htmads=$htmads.$imgurl;}
if ($luku eq $roll) {print "$imgurl"}


}
} 
