#!/Perl/5.00502/bin/MSWin32-x86-object/perl
########################################################################
#  PWP
########################################################################
#
# Copyright 1999, 2000, 2001 Peter Wieland.
#
# This file is part of PW_Tools.
#
# PW_Tools is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PW_Tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PW_Tools; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
########################################################################
# CONFIGURATION, HAS TO BE EDITED ...
########################################################################
use File::Copy;

$FORMS="NO"; # YES or NO

$VERBOSE=1;     # 0 is false, 1 is true

$HEADERCOLOR = "#999999";
$HEADERCOLOR = "#99CCCC";
$BODYCOLOR = "#FFFFFF";
$TABLECOLOR= "#FFFFFF";
$PAPERCOLOR = "#33FFCC";
$PRESCOLOR  = "#FFFF99";

#########################################################################
# DO NOT EDIT ABOVE THIS LINE
#########################################################################
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
    localtime(time);
$year += 1900;
$mon++;

$mytime = localtime;

## 
## READ COMPANY INFORMATION----------------------------------------------
##

$InputFile="../PWA/Input/COMPANY.txt";
open (FromFILE,"< $InputFile") or die 
    "Can't open InputFile: $InputFile";
while ( <FromFILE> ){
    chop;
    m/(.*):(.*):(.*):(.*):(.*)/;
    @COMPANIES{$1} = $2;
    @COMPAREA{$1}  = $3;
    @COMPCOUNTRY{$1} = $4;
    @COMPURL{$1} = $5;
}
print "\nInput file: $InputFile COMPANIES\n" if ($VERBOSE);
if ($VERBOSE) {foreach $abbr (keys %COMPANIES){ print "$abbr: $COMPANIES{$abbr}\n"}};
if ($VERBOSE) {foreach $abbr (keys %COMPANIES){ print "$abbr: $COMPAREA{$abbr}\n"}};
if ($VERBOSE) {foreach $abbr (keys %COMPANIES){ print "$abbr: $COMPCOUNTRY{$abbr}\n"}};
if ($VERBOSE) {foreach $abbr (keys %COMPANIES){ print "$abbr: $COMPURL{$abbr}\n"}};
close(FromFILE);

print ".";

print ".";
## 
## READ PERSON INFORMATION----------------------------------------------
##


$InputFile="../PWA/Input/contacts.csv";
open (FromFILE,"< $InputFile") or die 
    "Can't open InputFile: $InputFile";
while ( <FromFILE> ){
    chop;
    ($MCode,$MFIRST,$MSECOND,$MMEMBER,$MPHONE,$MEMAIL,$MAUTEMAIL,$MFAX,
     $MCMP,$MSTREET,$MBOX,$MPOSTCODE,$MCITY,
     $MCOUNTRY,$MTITLE,$MDEPARTMENT,$MPASSWORD) = split(/;/,$_);
    print "$entrinr\n" if ($VERBOSE);
    if (($MCode eq "Code") || (length($MCode) eq 0)){
    } 
    else {
	@PERSONS{$entrynr} = $MCode;
	@FIRST{$MCode} = $MFIRST;
	@SECOND{$MCode} = $MSECOND;
	@FULLNAME{$MCode} = "$MFIRST $MSECOND";
	@MEMBER{$MCode} = $MMEMBER;
	@PHONE{$MCode} = $MPHONE;
	@EMAIL{$MCode} = $MEMAIL;
	@FAX{$MCode} = $MFAX;
	@CMP{$MCode} = $MCMP;
	@STREET{$MCode} = $MSTREET;
	@BOX{$MCode} = $MBOX;
	@POSTCODE{$MCode} = $MPOSTCODE;
	@CITY{$MCode} = $MCITY;
	@COUNTRY{$MCode} = $MCOUNTRY;
	@TITLE{$MCode} = $MTITLE;
	@DEPARTMENT{$MCode} = $MDEPARTMENT;
	@PASSWORD{$MCode} = $MPASSWORD;
	
	$entrynr++;
    }
}
close(FromFILE);

delete @PERSONS{keys %PERSONS};
$entrynr=1000;
foreach $person (sort keys %FIRST){ 
    @PERSONS{$entrynr} = $person;
$entrynr++;

};

		   
print "\nInput file: $InputFile \n" if ($VERBOSE);
if ($VERBOSE) {foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $FIRST{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $SECOND{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $PHONE{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $EMAIL{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $FAX{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $CMP{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $STREET{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $BOX{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $POSTCODE{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $CITY{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $COUNTRY{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $TITLE{$PERSONS{$abbr}}\n"};
	       print "\n";
	       foreach $abbr (keys %PERSONS){ print "$PERSONS{$abbr}: $DEPARTMENT{$PERSONS{$abbr}}\n"};
	       print "\n";}


print ".";
## 
## READ Exploitation INFORMATION -----------------------------------------------
##

$InputFile="../PWP/Input/projects.txt";
open (FromFILE,"< $InputFile") or die 
    "Can't open InputFile: $InputFile";

$entrycnt=0;
while ( <FromFILE> ){
    $WholeLine=$_;
    if (m/(.*);(.*);(.*);(.*);(.*);(.*)/){
	$act_key = $1;
	@RESPONSIBLE{$act_key} = $2;
	@NAME{$act_key} = $3;
	@URL_INTER{$act_key} = $5;
	@PASS{$act_key} = $6;
	@KIND{$act_key} = $4;
	$entrycnt++;
    }
    else {
	if (length($_) > 2) {print "Error in line: $_"};
    }

}

close(FromFILE);


delete @CONFERENCES{keys %CONFERENCES};
$entrynr=1000;
foreach $activity (sort { $NAME{$a} cmp $NAME{$b}}keys %NAME){ 
    @PROJECTS{$entrynr} = $activity;
    $entrynr++;

};

if ($VERBOSE) {foreach $activity (keys %CONFERENCES){ 
    print "$CONFERENCES{$activity}\n";
    print "$CONFERENCE{$CONFERENCES{$activity}}\n";
    print "DATE: $DATE{$CONFERENCES{$activity}}\n";
    print "RESP: $RESPONSIBLE{$CONFERENCES{$activity}}\n";
    print "URL:  $CPMPURL{$CONFERENCES{$activity}}\n";
    print "_$COMPURL{activity_key}_\n";
}
	   };


print ".";
## 
## MAKE TABULAR CONFERENCE HTML PAGES ----------------------------------------------
##

$PersonFile="../PWP/projects.htm";

open (OUTFILE,"> $PersonFile") or die 
    "Can't open PersonFile: $PersonFile";    

$HeaderFile="../Input/header.html";
$PAGE_LEVEL="../..";
open (HEADERFILE,"< $HeaderFile") or die 
    "Can't open HeaderFile: $HeaderFile";
while ( <HEADERFILE> ){
    s/PAGE_LEVEL/$PAGE_LEVEL/g;
    print OUTFILE"$_";
}
close (HEADERFILE);


print OUTFILE"<H2>Sites using PW_Tools</h2>\n";

print OUTFILE"<p>Sites listed here are informed about newest updates</b>.</p>\n";


print OUTFILE"<table bgcolor=\"$TABLECOLOR\" border=\"1\">\n";
#print OUTFILE"<tr>\n";

print OUTFILE"<tr>\n";
print OUTFILE"<td bgcolor=\"$PAPERCOLOR\"><b>Title</b></td>\n";
print OUTFILE"<td bgcolor=\"$PAPERCOLOR\"><b>Manager</b></td>\n";
print OUTFILE"<td bgcolor=\"$PAPERCOLOR\"><b>Web</b></td>\n";
print OUTFILE"</tr> \n";

$num_of = 0;
foreach $activity (sort keys %PROJECTS){ 
    $activity_key = $PROJECTS{$activity};
    print OUTFILE"<tr>\n";
    
    if (length($URL_INTRA{$activity_key}) > 0) {
	print OUTFILE"<td><a href=\"$URL_INTRA{$activity_key}\">";
        print OUTFILE"$NAME{$activity_key}</a></td>\n";     
} 
    else { 
	print OUTFILE"<td>$NAME{$activity_key}</td>\n";
    }
    
    print OUTFILE"<td><a href=\"../PWA/Profiles/$RESPONSIBLE{$activity_key}.html\">";
    print OUTFILE"$FULLNAME{$RESPONSIBLE{$activity_key}}</a></td>\n";


if (length($URL_INTER{$activity_key}) > 0) {
    if (length($PASS{$activity_key}) > 0) {
	print OUTFILE"<td><a href=\"$URL_INTER{$activity_key}\">";
        print OUTFILE"$KIND{$activity_key}</a> <b>(*)</b></td>\n";     
    } 
    else { 
	print OUTFILE"<td><a href=\"$URL_INTER{$activity_key}\">";
	print OUTFILE"$KIND{$activity_key}</a></td>\n";
    }}
    else { 
	print OUTFILE"<td align=\"center\">-</td>\n";
    }
    
    print OUTFILE"</tr> \n";
}
print OUTFILE"</table>\n";

print OUTFILE"<br><b>(*)</b>: Password protected site, please contact project manager for access.";


print OUTFILE"<br><hr>Editor: <a href=\"PW_Tools/PWA/Profiles/PWi.html\">Peter Wieland (DNV)</a>";
print OUTFILE"<br><hr>Generated: <b>$mytime</b> by PWP.pl";
print OUTFILE"</body>\n";
close(OUTFILE);    


