--- loncom/homework/structuretags.pm 2002/08/20 14:42:22 1.104 +++ loncom/homework/structuretags.pm 2002/08/23 21:17:16 1.105 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.104 2002/08/20 14:42:22 sakharuk Exp $ +# $Id: structuretags.pm,v 1.105 2002/08/23 21:17:16 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -101,7 +101,68 @@ sub page_start { } $body_tag_start.='>'; } - return ($result,$head_tag_start,$body_tag_start); + my $form_tag_start; + if (!defined($found{'form'})) { + $form_tag_start='
'; + } + return ($result,$head_tag_start,$body_tag_start,$form_tag_start); +} + +sub get_resource_name { + my ($parstack,$safeeval)=@_; + my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval); + if ($name eq '') { + $name=&Apache::lonnet::EXT('resource.title'); + if ($name eq 'con_lost') { $name = ''; } + } + $Apache::lonhomework::name=$name; + return $name; +} + +sub setup_rndseed { + my ($safeeval)=@_; + my $rndseed; + if ($ENV{'request.state'} eq "construct") { + $rndseed=$ENV{'form.rndseed'}; + if (!$rndseed) { + $rndseed=time; + $ENV{'form.rndseed'}=$rndseed; + } + &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval); + } + return $rndseed; +} + +sub problem_edit_header { + return ' + + + +
+ +
+ '; +} + +sub problem_edit_footer { + return '
+ '; +} + +sub problem_web_to_edit_header { + my ($rndseed)=@_; + my $result.=' + + + Random Seed: + + + or the neccesary stuff to start XML/MathML - my ($result,$head_tag_start,$body_tag_start)= + my ($result,$head_tag_start,$body_tag_start,$form_tag_start)= &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval); if ($target eq 'tex' and $ENV{'request.symb'} =~ m/\.page_/) { $result = '';} @@ -216,15 +277,7 @@ sub start_problem { } #handle rand seed in construction space - my $rndseed; - if ($ENV{'request.state'} eq "construct") { - $rndseed=$ENV{'form.rndseed'}; - if (!$rndseed) { - $rndseed=time; - $ENV{'form.rndseed'}=$rndseed; - } - &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval); - } + my $rndseed=&setup_rndseed($safeeval); ($status,$accessmsg) = &Apache::lonhomework::check_access('0'); push (@Apache::inputtags::status,$status); my $expression='$external::datestatus="'.$status.'";'; @@ -246,31 +299,14 @@ sub start_problem { $result.=$msg.'
'; } } elsif ($target eq 'web') { - my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval); - if ($name eq '') { - $name=&Apache::lonnet::EXT('resource.title'); - if ($name eq 'con_lost') { $name = ''; } - } - $Apache::lonhomework::name=$name; + my $name= &get_resource_name($parstack,$safeeval); if ($status eq 'CAN_ANSWER') { # create a page header and exit - $result.="$head_tag_start$name\n - $body_tag_start\n - ". + $result.="$head_tag_start$name + $body_tag_start \n $form_tag_start". ''; if ($ENV{'request.state'} eq "construct") { - $result.= - ' - - - Random Seed: - - - ".$body_tag_start. - ' - - - - -
- -
- '; + $result.=$head_tag_start."".$body_tag_start.$form_tag_start. + &problem_edit_header(); my $temp=&Apache::edit::insertlist($target,$token); $result.=$temp; } elsif ($target eq 'modified') { @@ -384,8 +411,7 @@ sub end_problem { } } elsif ($target eq 'edit') { &Apache::lonxml::debug("in end_problem with $target, edit"); - $result ='
'; - $result.=''; + $result = &problem_edit_footer(); } elsif ($target eq 'tex') { $result .= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}'; if (not $ENV{'request.symb'} =~ m/\.page_/) { @@ -399,33 +425,34 @@ sub end_problem { sub start_library { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - my ($result,$head_tag_start,$body_tag_start)= + my ($result,$head_tag_start,$body_tag_start,$form_tag_start)= &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval); if ($target eq 'edit') { - $result.=$head_tag_start."".$body_tag_start. - ' - - - -
- '; + $result.=$head_tag_start."".$body_tag_start.$form_tag_start. + &problem_edit_header(); my $temp=&Apache::edit::insertlist($target,$token); $result.=$temp; - return $result; - } - if ($target eq 'modified') { + } elsif ($target eq 'modified') { $result=$token->[4]; $result.=&Apache::edit::handle_insert(); - return $result; + } elsif ($target eq 'web' && $ENV{'request.state'} eq "construct" ) { + my $name=&get_resource_name($parstack,$safeeval); + my $rndseed=&setup_rndseed($safeeval); + $result.="$head_tag_start$name + $body_tag_start \n $form_tag_start". + ''; + $result.=&problem_web_to_edit_header($rndseed); } - return ''; + return $result; } sub end_library { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result=''; if ($target eq 'edit') { - $result='
'; + $result=&problem_edit_footer(); + } elsif ($target eq 'web' && $ENV{'request.state'} eq "construct") { + $result.='
'.&Apache::lonxml::xmlend(); } return $result; }