#!/usr/bin/perl
use CGI qw(:standard);
unless (defined($ARGV[0]) ) {
	print <<eND;
Content-type: text/html

eND
}

chdir("/home12c/sub007/sc13648-GPVH/") || print "Couldn't change directory $!<BR>\n";
$mainloc = "at";

########### second screen (deactivated)
$cookieid = "atid";
$cookie = $ENV{"HTTP_COOKIE"};

$cookie =~ m/$cookieid\=([^;]+)/;
$id = $1;

$time = time;

$subfolder = substr($id,0,3);

open(DATA,"ids/$subfolder/$id/main.txt");
while ($_ = <DATA>) {
	$info{$1} = $2 if m/^([^=]+)\=(.+)/;
}
close(DATA);

if (defined($ARGV[1]) ) {
	$target = $ARGV[1];
	$nextfile = $ARGV[0];
}
else {
	$target=param("target");
	$nextfile=param("nextfile");
}
$value = $info{lc($target)};

chdir("/home12c/sub007/sc13648-GPVH/$mainloc");
open(DATA,$nextfile) || open(DATA,$nextfile) || print "There was a problem reading $fl";
@lines = <DATA>;
close(DATA);
foreach (@lines) {
	s/$target/$value/og;
	print;
}
exit;





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


sub basicheader {
	print <<eND;
Content-type: text/html

eND
	return;
}


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

sub printpage {
	my ($fl,$insert) = @_;
	chdir("/home12c/sub007/sc13648-GPVH/$mainloc");
	open(DATA,"$fl") || open(DATA,"$fl") || gracefulend("There was a problem reading $fl");
	@lines = <DATA>;
	close(DATA);
	foreach (@lines) {
		s/INSERT/$insert/o;
		print;
	}
	exit;
}


