#!/usr/bin/perl

use		CGI qw(:standard);
use		CGI::Carp(fatalsToBrowser);

BEGIN {
	if ($ENV{"SERVER_NAME"} =~ m"localhost") {
		unshift @INC, "c:/prog/perl/elsnet/cgi-bin/lib";
	} else {
		unshift @INC, "lib";
	}
	require SSI2;
	require Date;
	require paths2;
	require Elsnet::Subs;
	import SSI2;
	import Date;
	import paths2;
	import Elsnet::Subs;
}

&checkQUERY();

print header();

my @names			=	param();
my %param			=	();
foreach (@names) {	$param{$_}	=	param($_); }

my $show_event			=	"$cgi_directory/html/show_event.html";
my $file				=	"$events_directory/$param{file}";

open(FILE,$file) || &cgiDie("$0: Couldn't open $file: $!");

while ($line = <FILE>) {
	if ($line =~ s/<!-- (.*?) -->\n/$1/) {;
		($key,$value) = split /\t/, $line;
		$info{$key} = $value;
	} else {
		$filetext	=	$line;
		last;
	}
	
}
$filetext	.=	join "", <FILE>;
$filetext 	=	vet($filetext,$param{"operands"});

close FILE;

$data{subject}	=	$info{Subject};
$data{category}	=	$info{Category};
$data{from}		=	$info{From};
$data{email}	=	$info{Email};
$data{received}	=	$info{"Date received"};
$data{deadline}	=	$info{Deadline} || "-";
$data{startdate}=	$info{"Start date"} || "-";
$data{text}		=	$filetext;

print ssi($show_event, $root_directory, \%data);

sub vet {
	my ($file,$operands) = @_;
	my @operands	=	split /--/, $operands;
	$file =~ s/</&\*&&&</g;		# trucje om html-code te splitten
	$file =~ s/>/>&\*&&&/g;		# idem
	@arr = split /&\*&&&/, $file;	# huub huub barbatruc!
	for (@arr) {
		if (length($_) > 0) {	# geen lege array-elementen
			if (/<.*?>/s) { push @arr2, $_ }	#zoek HTML-code
			else { push @arr2, split /(\s+)/, $_ }	# zoek woorden
		}
	}
	for (@arr2) {				# het eigenlijke vetmaken
		if (/<\s?\/?a\s?.*>/si) { s/.*//s; }	# wis alle links 
		unless (/<.*>/s) {
			for $zoekstr (@operands) {
				s#^(\W*)($zoekstr)#$1<b>$2</b>#i;
			}
		}
	}
	$file = join "", @arr2;
	return $file;
}


