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

print "Content-type: text/html\n\n" unless $ARGV[0] eq "bh";

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

$cookie = $ENV{"HTTP_COOKIE"};
$id = $1 if $cookie =~ m/cpid\=([^;,]+)/;
$subfolder = substr($id,0,1);

$time = time;

mkdir "CPs/$subfolder/$id";

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

$event = param("event");

if ($event eq "makechanges") {
	@targets = param();
	MCLOOP: foreach $target (@targets) {
		next MCLOOP if $target eq "event";
		$value = param($target);
		$value =~ s/\{//gm;
		$info{$target} = $value if $value || $value eq "0";
	}
	open(DATA,">CPs/$subfolder/$id/girl.txt");
	foreach $key (keys(%info)) {
		$value = $info{$key};
		print DATA "$key=$value\n";
	}
	close(DATA);
	if ( param("pw") || param("name") || param("email") ) {
		open(DATA,"CPs/stuff/pws.txt");
		@lines = <DATA>;
		close(DATA);
		open(DATA,">CPs/stuff/pws.txt");
		foreach (@lines) {
			$checkid = "";
			m/^[^~]~\`[^~]~\`([^~])/;
			$checkid = $1;
#print "line is $_<BR>\n";
#print "id is $id and checkid is $checkid<BR>\n";
			#print DATA unless $checkid eq $id;
			print DATA;
		}
		$name = $info{"name"};
		$email = $info{"email"};
		$pw = $info{"pw"};
		print DATA "$pw~`$name~`$id~`$email\n";
		close(DATA);
	}
	if (param("sfbrole")) {
		open(DATA,">>CPs/$subfolder/$id/triggers.txt");
		print DATA "seeing your picture\n";
		close(DATA);
	}
	exec "cp/cgi-bin/main.pl","bh";
}

$name = $info{"name"};
$gender = $info{"gender"};
$age = $info{"age"};

push @togo, qq~This is basic information for you. You can change. This is basic information about your new personality (or the one you are changing).\n~;

push @togo, qq~<form method=post action="/cgi-bin/rare/aboutyou3a.pl">\n~;
push @togo, qq~Name: <input type=text name=name size=20 maxsize=30 value=$name>\n~;

push @togo, qq~<p>Age: <input type=text name=age size=2 maxsize=3 value=$age>\n~;

$fcheck = "checked" if $gender eq "female";
$mcheck = "checked" if $gender eq "male";
$ncheck = "checked" if $gender eq "unspecified";
push @togo, qq~<p>Your gender here is\n~;
push @togo, qq~<div style=left-margin:7><input type=radio name=gender $mcheck value=male> male\n~;
push @togo, qq~<br><input type=radio name=gender value=female $fcheck> female\n~;
push @togo, qq~<br><input type=radio name=gender value=unspecified $ncheck> unspecified or other\n~;

push @togo, qq~<p>You have password. Leave this blank unless you want to change password.\n~ if $info{"pw"};

push @togo, qq~<p>Create password. Choose something that fits new personality? Used for getting back to identity.\n~ unless $info{"pw"};
push @togo, qq~<BR>Password: <input type=text name=pw size=20 maxsize=30>\n~;

$email = $info{"email"};
push @togo, qq~<p>Your email is on file. Use this to change it. This is blank for security reasons.\n~ if $email;
push @togo, qq~<p>An email address is used only if you logout, forget your password, and want your password sent to you.\n~ unless $email;
push @togo, qq~<BR>Email: <input type=text name=email size=30 maxsize=50>\n~;

$birthday = $info{"birthday"};
push @togo, qq~<p>Birthday: <input type=text name=birthday value="$birthday" size=20 maxsize=40>\n~;

push @togo, qq~<input type=hidden name=event value=makechanges><BR><br><INPUT TYPE=SUBMIT VALUE="Enter"></div></form>\n~;


printonblankerpage(@togo);

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;
}

