#!/usr/local/bin/perl -w
#$baseurl="http://surveys.roe.ac.uk/wsa/pre/";
$baseurl="http://surveys.roe.ac.uk/wsa/";
$baseurl_jsp="http://surveys.roe.ac.uk:8080/wsa/";
$singleFile="";
$singleFile=$ARGV[0];
$noArgs=scalar @ARGV;
print ": $noArgs \n :";
if ($noArgs > 0 ){
system ("cd /home/mar/wsa; ls $singleFile | grep -v end.ht | grep -v bottom | grep -v top.ht > in.dat");
}
else {
system ("cd /home/mar/wsa; ls *.ht | grep -v end.ht | grep -v bottom | grep -v top.ht > in.dat");
}
$filename="in.dat";
#$installdir="/thoth/www/wsa/release/";
$installdir="/thoth/www/wsa/";
#$installdir="/thoth/www/wsa/pre/";

$top="top.html";
$bottom="bottom.html";
$expand_1="expand_1.ht";
$expand_1_txt="";
open (EXPAND,"<$expand_1");
  $expand_1_txt = do { local $/; <EXPAND> }; 
close (EXPAND);
       $expand_1_txt=~s/\$URL./$baseurl/;
       $expand_1_txt=~s/\$JSP./$baseurl_jsp/;
#print "\n $expand_1_txt";

$end="end.html";
#$baseurl="http://surveys.roe.ac.uk/wsa/release/";
#$baseurl="http://surveys.roe.ac.uk/wsa/";

open (TOP,"<top.ht");
open (TOPOUT, ">top.html");
open (TOPE1, ">top_expand_1.html");

    while (<TOP>){
	$line=$_;
        $line=~s/\$URL./$baseurl/;
        $line=~s/\$JSP./$baseurl_jsp/;
        print TOPOUT $line;
        $line=~s/<!-- \$EXPAND_1 -->/$expand_1_txt/;
        print TOPE1 $line;
    }
close (TOP);
close(TOPOUT);
close(TOPE1);



open (BOT,"<bottom.ht");
open (BOTOUT, ">bottom.html");
    while (<BOT>){
	$line=$_;
        $line=~s/\$URL./$baseurl/;
        $line=~s/\$JSP./$baseurl_jsp/;
        print BOTOUT $line;
    }
close (BOT);
close(BOTOUT);



open (WORK,$filename);

while (<WORK>){
$line=$_;
@fields=split(/&/,$line);
$htfile=$fields[0];
$date=$fields[1];
chomp($htfile);
#chomp($date);
($mdate)=(stat($htfile))[9];
($sec,$min,$hour,$mday,$mon,$year,$a1,$a2,$a3) = localtime ($mdate);
$mon++;#Perl counts months 0-11, so increment for humans
    $year=$year+1900;
$thedate = "$mday/$mon/$year";
$date=$thedate;



print "$htfile $date\n";
$httemp=$htfile."temp";
print "$httemp\n";
$htmlfile="$htfile"."ml";
print "$htmlfile\n";
if ($htfile =~ /crdedits.ht/) {
system("cat top_expand_1.html $htfile > $httemp");
}
else {
system("cat $top $htfile > $httemp");
}
system(" cat $httemp $bottom >$htmlfile");

open (HTMLFILE, ">>$htmlfile");
print HTMLFILE "<br>$date</font></i><p>\n";


#print HTMLFILE "<a href=\"http://www.mirror.ac.uk/services/validator/\"><img border=0 ";
#    print HTMLFILE "SRC=\"http://www-wfau.roe.ac.uk/sss/images/vh40.gif\"";
#    print HTMLFILE " ALT=\"Valid HTML 4.0!\" HEIGHT=31 WIDTH=88></A>";



print HTMLFILE "</center> </table> </BODY> \n";
print HTMLFILE "</html>";


close (HTMLFILE);
system("/usr/local/bin/scp  $htmlfile mar\@thoth:$installdir.");

}

#system("/usr/local/bin/scp  menu.jsp mar\@thoth:/thoth/webapps/wsa/.");
#system("/usr/local/bin/scp  menu1.jsp mar\@thoth:/thoth/webapps/wsa/.");
#system("/usr/local/bin/scp  menu2.jsp mar\@thoth:/thoth/webapps/wsa/.");
if ($noArgs ==0 ){
#system("/usr/local/bin/scp  pixel.jsp mar\@thoth:/thoth/webapps/wsa/.");
system("/usr/local/bin/scp  top.html mar\@thoth:/thoth/webapps/wsa/.");
system("/usr/local/bin/scp  bottom.html mar\@thoth:/thoth/webapps/wsa/.");
#system("/usr/local/bin/scp  top.html mar\@thoth:/thoth/webapps/wsa/top.jsp");
#system("/usr/local/bin/scp  bottom.html mar\@thoth:/thoth/webapps/wsa/bottom.jsp");
system(" cat bottom.html end.ht > bottom_end.html");
system("/usr/local/bin/scp  bottom_end.html mar\@thoth:/thoth/webapps/wsa/.");
system("/usr/local/bin/scp style.css mar\@thoth:/thoth/www/wsa/.");
system("/usr/local/bin/scp configurestyles.js mar\@thoth:$installdir.");
system("/usr/local/bin/scp browserversion.js mar\@thoth:$installdir/.");
system("/usr/local/bin/scp default.css mar\@thoth:$installdir.");
system("/usr/local/bin/scp pubs.html mar\@thoth:$installdir/pubs/ukidss/index.html");

}
close (WORK);
#system("/usr/local/bin/scp -l top.html cosaxp6:public_html/.");
#system("/usr/local/bin/scp -l bottom.html cosaxp6:public_html/.");
#system("/usr/local/bin/scp -l SQL.html cosaxp6:public_html/sql.html");
exit;










