#!/usr/bin/perl

unless ($ARGV[0] eq "bh") {
	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;
printpage("t/atwork/nocookie.htm") unless $cookie;

%targetnames = ("none","whatever you are training to be attracted to","women_feet","women showing foot","women_nft","women not including a foot","feet","just a woman's foot","np","just the female nipple","breast","just the female breast","puck", "the female nipple puckered","mg","the Glands of Montgomery","npuck", "the female nipple unpuckered","nmg","no Glands of Montgomery","women_nipples","women showing their nipples","women_nipples_less","women showing their nipples (less attractive)","women_hidebr","women not showing their nipples","person","some person","notfeet","something other than feet","ct","just the female cunt","clit","the clitoris","hood","the clitoral hood","inner","the inner labia","nclit","no clitoris","nhood","no clitoral hood","ninner","no inner labia","women_ct","women showing their cunt","women_nct","women not showing their cunt");

$time = time;
$tab = "&nbsp;&nbsp;&nbsp;&nbsp;";

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

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


push @togo, qq~<center><h2><span style="font-family:Book Antiqua">Your Training</span></h2></center>\n~;



$r = substr($time,4,1);
$r = 1 if $r eq "0";
$r = int($r/3) + 1;
$r = 1 if $r > 3;
push @togo, qq~<img src=/images/cupid$r.jpg align=right>\n~;

$igattname = $igatt;
$igattname = "trying all" if $igatt == 100;

push @togo, qq~<a href=/knowmore.htm><span style="font-family:Book Antiqua">&rarr; Information</span></a>\n~;

push @togo, qq~<BR>The submissive options should be available now. Click ont the information for submissives on the information page. Thank you for noting that problem.<BR>\n~ if $id eq "1275335890482";


if ($picloc) {
	push @togo, qq~<br><br>Training Choices:<ul style=margin-left:12;padding-top:0>\n~;
	if ($info{"picloc"} ne "you" && $info{"piclocn"} ne "you") {
		$program = "atsextr";
	}
	else {
		$program = "aasxtraining";
		$tt = ";tt=" . time();
	}
	push @togo, qq~<li><a href=/cgi-bin/$program.pl?start=start1;tl=1>Beginning Training</a>&nbsp;&nbsp;<font size=-1><a href=/t/atwork/explainphase1.htm>(explain)</a></font>\n~ if $igatt == 1 || ! $igatt || ($igatt == 100 && "topic" ne "nipples");

	if ($igatt >= 2) {
		push @togo, qq~</li><li><a href=/cgi-bin/$program.pl?fl=train.txt;tl=2$tt>Normal Training</a>&nbsp;&nbsp;<font size=-1><a href=/t/atwork/explainphase2.htm>(explain)</a></font>\n~;
		($phrases = $info{"phrases"}) || ($phrases = "no");
		if ($phrases ne "no") {
			push @togo, qq~<BR> $tab <span style=font-size:12pt>(includes phrases <font size=-1><a href=/t/atwork2/explainphrases.htm>(change/explain)</a></font>)</span>\n~;
		}
		else {
			push @togo, qq~<BR> $tab <span style=font-size:12pt>Your "Normal Training" will not include any phrases <font size=-1><a href=/t/atwork2/explainphrases.htm>(change/explain)</a></font></span>\n~;
		}
	}

	push @togo, qq~</li><li><a href=/cgi-bin/$program.pl?fl=train.txt;tl=3>Attentional Training</a>&nbsp;&nbsp;<font size=-1><a href=/t/atwork/explainphase3.htm>(explain)</a></font>\n~ if $igatt >= 3;
	push @togo, qq~</li><li><a href=/cgi-bin/$program.pl?fl=train.txt;tl=4>Breakdown Training</a>&nbsp;&nbsp;<font size=-1><a href=/t/atwork/explainphase4.htm>(explain)</a></font>\n~ if $igatt >= 4;
	push @togo, qq~</li><li><a href=/cgi-bin/$program.pl?fl=train.txt;tl=5>Breakdown Training II</a>&nbsp;&nbsp;<font size=-1><a href=/t/atwork/explainphase4.htm>(explain)</a></font>\n~ if $igatt >= 4 && $topic =~ m/(feet|ct|nipples)/;
	push @togo, qq~</li><li><a href=/cgi-bin/$program.pl?fl=train.txt;tl=6>Breakdown Training III</a>\n~ if $igatt >= 4 && $topic =~ m/(feet|ct|nipples)/;

	push @togo, qq~</li><li><a href=/cgi-bin/$program.pl?fl=train.txt;tl=10;phr=service>Service Training</a>&nbsp;&nbsp;<font size=-1><a href=/t/atwork/expsvtr.htm>(explain)</a></font>\n~ if $info{"svtrain"} eq "yes";

	push @togo, qq~</li></ul>\n~;
}
else {
	push @togo, qq~<p>You do not have any training options until you choose target pictures (or probably a topic)~;
}

push @togo, qq~<p><span style="font-family:Book Antiqua;font-weight:bold">Training Level:</span> $igattname  <font size=-1><a href=/t/atwork/changeigatt.htm>(change/explain)</a></font>\n~;

($topic = $info{"topic"}) || ($topic = "none");
%topicnames = ("none","whatever you are training to be attracted to","feet","the female foot","nipples","the female nipple","person","some person","notfeet","something other than feet","ct","the female cunt");
$topicname = $topicnames{$topic};
if ($topic eq "person" && ($personname = $info{"igname"}) ) {
	$topicname = $personname;
}

push @togo, qq~<p><span style="font-family:Book Antiqua;font-weight:bold">General Topic:</span> <font size=-1><a href=/t/atwork/changetopic.htm>(change/explain)</a></font><BR>$tab $topicname~;

push @togo, qq~ <font size=-1><a href=/t/atwork/changeigname.htm>(add or change name)</a></font>~ if $topic eq "person";

push @togo, qq~<p><span style="font-family:Book Antiqua;font-weight:bold">Target Pictures:</span> ~;
$picloc = $info{"picloc"};
if ($picloc eq "you") {
	push @togo, qq~<font size=-1><a href=/t/atwork/changepicloc.htm>(change/explain)</a></font>~;
	push @togo, qq~<BR>$tab Pictures stored on your computer <font size=-1><a href=/t/atwork/changenpics.htm>(change/explain)</a></font><BR>\n~;
	($prfxy = $info{"prfxy"}) || ($prfxy = "y");
	push @togo, qq~$tab $tab Starting with the letter $prfxy<BR>~;
	($starty = $info{"starty"}) || ($starty = "1");
	($endy = $info{"endy"}) || ($endy = "3");
	push @togo, qq~$tab followed by the numbers $starty to $endy<BR>\n~;
	#if ($igname = $info{"igname"} ) {
		#push @togo, qq~<li>Name: $igname <font size=-1><a href=/t/atwork/changeigname.htm>(change/explain)</a></font></li>\n~;
	#}	
	if ($iggender = $info{"iggender"}) {
		push @togo, qq~<li>Gender: ~;
		if ($iggender eq "m") {
			push @togo, qq~male~;
		}
		else { 
			push @togo, qq~female~;
		}
		push @togo, qq~ <font size=-1><a href=/t/atwork/changeiggender.htm>(change)</a></font></li>\n~;
	}
}
else {
	if ($topic eq "nipples") {
		$sfx = "br";
	}
	elsif ($topic eq "ct") {
		$sfx = "ct";
	}
	elsif ($topic eq "feet") {
		$sfx = "ft";
	}
	else {
		$sfx= "";
	}
	push @togo, qq~<font size=-1><a href=/t/atwork/changepicloc$sfx.htm>(change/explain)</a></font>~;
	($piclocname = $targetnames{$picloc}) || ($piclocname = $picloc);
	$piclocname =~ s/_/ /g;
	push @togo, qq~<BR>$tab $piclocname\n~;
}	


push @togo, qq~<p><span style="font-family:Book Antiqua;font-weight:bold">"Distractor" Pictures:</span>~;


if ($info{"disconnect"} eq "yes") {
	$sfx = "";
}
elsif ($topic eq "nipples") {
	$sfx = "br";
}
elsif ($topic eq "ct") {
	$sfx = "ct";
}
elsif ($topic eq "feet") {
	$sfx = "ft";
}
elsif ($topic eq "person") {
	$sfx = "person";
}

else {
	$sfx= "";
}
if ($piclocn eq "you") {
	push @togo, qq~ <font size=-1><a href=/t/atwork/changepiclocn$sfx.htm>(change/explain)</a></font>~;
	push @togo, qq~<BR>$tab Pictures stored on your computer<BR>\n~;
	($prfxn = $info{"prfxn"}) || ($prfxn = "n");
	push @togo, qq~$tab $tab Starting with the letter $prfxn<BR>~;
	($startn = $info{"startn"}) || ($startn = "1");
	($endn = $info{"endn"}) || ($endn = "3");
	push @togo, qq~$tab followed by the numbers $startn to $endn<BR>\n~;
}
else {
	push @togo, qq~ <font size=-1><a href=/t/atwork/changepiclocn$sfx.htm>(change/explain)</a></font>~;
	($piclocname = $targetnames{$piclocn}) || ($piclocname = $piclocn);
	$piclocname =~ s/_/ /g;
	push @togo, qq~<BR>$tab $piclocname\n~;
	if ($info{"disconnect"} eq "yes") {
		push @togo, qq~<BR>$tab <span style=font-size:12pt>Your distractor pictures are disconnected from your target pictures <font size=-1><a href=/t/atwork2/explainconnect.htm>(change/explain)</a></font></span>\n~;
	}
	else {
		push @togo, qq~<BR>$tab <span style=font-size:12pt>Your distractor pictures contrast to your target pictures. This is normal. <font size=-1><a href=/t/atwork2/explainconnect.htm>(change/explain)</a></font></span>\n~;
	}
}

push @togo, qq~<p><a href=/t/atwork2/suboptions.htm style=text-decoration:none;border:0;padding:0>Submissive Options</a>~ if $info{"submissive"} eq "yes";

push @togo, qq~<p><a href=/cgi-bin/obtrain.pl>Obedience Training</a>\n~ if $info{"obtrain"} eq "yes" || $id eq "1275110327934";

push @togo, qq~</td>~;

#push @togo, qq~<td><a href=/t/atwork/helper.htm style=text-decoration:none;border:0;padding:0><img src=/images/helpericon1.jpg style=text-decoration:none;border:0 title="report problems"></a></td>~;


#################### not used after this?


#push @togo, qq~<p><a href=/cgi-bin/printpage.pl?target=IGNAME;nextfile=t/atwork/trainneed.htm>Need Training (air)</a>&nbsp;&nbsp;<font size=-1><a href=/t/atwork/expair.htm>(explain)</a></font>\n~ if $info{"ndtrain"} eq "yes" || ($info{"topic"} eq "person" && $picloc eq "you");

if ($info{"picloc"} ne "you") {
	push @togo, qq~<p><a href=/cgi-bin/printpage.pl?target=IGNAME;nextfile=t/atwork/foodtr.htm>Need Training (food)&nbsp;&nbsp;<font size=-1><a href=/t/atwork/expfood.htm>(explain)</a></font>\n~ if $info{"ndtrain"} eq "yes";
	#push @togo, qq~<p><a href=/cgi-bin/obtrain.pl>Obedience Training</a>\n~ if $info{"obtrain"} eq "yes";
	#push @togo, qq~<p><a href=/t/lamallya3/bathtr.htm>Bathroom Permission</a>\n~ if $info{"typetrain"} eq "domme";
	push @togo, qq~<p><a href=/cgi-bin/creatorh.pl?fl=atscript.txt;start=comfort>Comfort</a>&nbsp;&nbsp;<font size=-1><a href=/t/atwork/expcomfort.htm>(explain)</a></font>\n~ if $info{"comforttrain"} eq "yes";
}
else {
	#push @togo, qq~<p><a href=/cgi-bin/foodtraining.pl>Need Training (food)</a>&nbsp;&nbsp;<font size=-1><a href=/t/atwork/expfood.htm>(explain)</a></font>\n~;
	#push @togo, qq~<p><a href=/cgi-bin/comfort.pl>Comfort</a>&nbsp;&nbsp;<font size=-1><a href=/t/atwork/expcomfort.htm>(explain)</a></font>\n~;
}



push @togo, qq~</td></tr></table><BR><BR><BR><center><table width=600><tr><td align=left><a href=/t/atwork2/login.htm>login </a><font size=-1><a href=/t/atwork2/pwlog.htm> (change/explain password)</a></font><br><a href=/t/atwork2/logoutstart.htm>logout</a></td><td align=right>~;

push @togo, qq~<a href=/t/atwork/feedback.htm style=text-decoration:none;border:0;padding:0><img src=/images/feedbackicon1.jpg style=text-decoration:none;border:0 title="help,comments,feedback"></td></tr></table></center>~;

push @togo, qq~<div style=font-size:12pt>~;
push @togo, qq~<a href=/cgi-bin/veryrare/chr.pl>Inductions<BR>\n~ if $id eq "1272988346758" && $picloc eq "Jane";
push @togo, qq~<a href=/cgi-bin/veryrare/chrv.pl>Inductions2<BR>\n~ if $id eq "1272988346758";

push @togo, qq~<a href=/cgi-bin/veryrare/checkinfo.pl>Check info<BR>\n~ if $id eq "1272988346758";

push @togo, qq~<a href=/cgi-bin/mine/editor.pl>Editor\n~ if $id eq "1272988346758";

push @togo, qq~</div>~;

push @togo, "<p><a href=/t/lamallya3/disob.htm>Tell $igname you were disobedient</a><BR>" if $info{"pun"} eq "yes";

#$pw = passwd("help","sa");
#print "pw is $pw<BR>\n";

printonblankerpage(@togo);
exit;


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

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


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

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

