#!/usr/bin/perl
use CGI qw(:standard);

print <<eND;
Content-type: text/html

eND

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


$time = time;
$cookieid = "cpid";

$cookie = $ENV{"HTTP_COOKIE"};
$cookie =~ m/$cookieid\=([^;]+)/;
$id = $1;
exit unless $id;



open(DATA,"cp/conversations/gcommlist.txt") || open(DATA,"conversations/gcommlist.txt") || print "Problem with geading gcommlist: $!<BR>\n";
$i = 0;
while ($id[$i] = <DATA>) {
	chomp($id[$i]);
	$found = "yes" if $id[$i] eq $id;
	$name[$i] = <DATA>;
	chomp($name[$i]);
	$house[$i] = <DATA>;
	$i++;
}
close(DATA);
unless ($found eq "yes") {
	push @togo, qq~<br><a href=/conversations/cgi-bin/gcommenroll.pl?id=$id>Enroll in New HouseMail</a>~;
	printonblankerpage(@togo);
}

if (param("event") eq "some") {
	push @togo, qq~<form method=post action=gcommstart.pl>~;
	push @togo, qq~Click on the people you want to include in your housemail.<table>~;
	PUBLISHLOOP2: for ($i=0;$i < @house;$i++) {
		$name = $name[$i];
		push @togo, qq~<input type=checkbox name=$id[$i]> $name<br>~;
	}
	push @togo, qq~<input type=hidden name=id value=some><input type=hidden name=name value=some><input type=submit value="start housemail"></form>~;
	printonblankerpage(@togo);
}

push @togo, qq~Click on a name to start a conversation.~;
push @togo, qq~<br><a href="gcommstart.pl?id=all;name=all">all (everyone)</a>~;
push @togo, qq~<br><a href="gcommmenu.pl?event=some">some (more than one person but not everyone)</a><br>~;
PUBLISHLOOP: for ($i=0;$i < @house;$i++) {
	$name = $name[$i];
	push @togo, qq~<br><a href="gcommstart.pl?id=$id[$i];name=$name">$name</a>~;
}

push @togo, qq~<BR><BR><BR><img src=http://attractiontraining.com/images/paintrainbow2.jpg></body>\n<HEAD><META HTTP-EQUIV="Pragma" CONTENT="no-cache"></HEAD>\n~;

printonblankerpage(@togo);
exit;

sub printonblankerpage {
	@toprint = @_;
	chdir("/home12c/sub007/sc13648-GPVH/cp");
	open(DATA,"cgi-bin/shells/startshell.htm") || open(DATA,"cgi-bin/shells/startshell.htm")  || print "There was a problem reading shellpage: $!";
	@lines = <DATA>;
	close(DATA);
	$contentmarker = "<!--content-->";

	foreach (@lines) {
		if (m/$contentmarker/o) {
			print @toprint;
		}
		else {
			print;
		}
	}
	exit;
}

