--- loncom/homework/structuretags.pm 2003/04/03 14:31:58 1.159 +++ loncom/homework/structuretags.pm 2003/05/13 20:38:55 1.171 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.159 2003/04/03 14:31:58 albertel Exp $ +# $Id: structuretags.pm,v 1.171 2003/05/13 20:38:55 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -38,7 +38,7 @@ use Apache::File(); use Apache::lonmenu; BEGIN { - &Apache::lonxml::register('Apache::structuretags',('block','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','startouttext','endouttext')); + &Apache::lonxml::register('Apache::structuretags',('block','languageblock','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','startouttext','endouttext')); } sub start_web { @@ -104,10 +104,11 @@ sub page_start { } $body_tag_start.='>'.&Apache::lonmenu::menubuttons(undef,$target,1); if ($target eq 'web' && $ENV{'request.state'} ne 'construct') { - my ($symb)=&Apache::lonxml::whichuser(); - if ($symb eq '') { + my ($symb,undef,undef,undef,$publicuser)= + &Apache::lonxml::whichuser(); + if ($symb eq '' && !$publicuser) { my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference"); - $help="Browsing or ambiguous reference, submissions ignored $help
"; + $help="Browsing resource, all submissions are temporary.
"; $body_tag_start.=$help; } } @@ -135,9 +136,17 @@ sub get_resource_name { sub setup_rndseed { my ($safeeval)=@_; my $rndseed; - if ($ENV{'request.state'} eq "construct") { + my ($symb)=&Apache::lonxml::whichuser(); + if ($ENV{'request.state'} eq "construct" || $symb eq '') { $rndseed=$ENV{'form.rndseed'}; if (!$rndseed) { + $rndseed=$Apache::lonhomework::history{'rndseed'}; + if (!$rndseed) { + $rndseed=time; + $ENV{'form.rndseed'}=$rndseed; + } + } + if ($ENV{'form.resetdata'} eq 'New Problem Variation') { $rndseed=time; $ENV{'form.rndseed'}=$rndseed; } @@ -186,8 +195,9 @@ sub problem_web_to_edit_header { sub initialize_storage { %Apache::lonhomework::results=(); + %Apache::lonhomework::history=(); my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); - if ($ENV{'request.state'} eq 'construct') { + if ($ENV{'request.state'} eq 'construct' || $symb eq '') { %Apache::lonhomework::history= &Apache::lonnet::tmprestore($ENV{'request.uri'},'',$domain,$name); my ($temp)=keys %Apache::lonhomework::history ; @@ -210,7 +220,8 @@ sub finalize_storage { my ($temp) = keys %Apache::lonhomework::results; if ( $temp ne '' ) { my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); - if ($ENV{'request.state'} eq 'construct') { + if ($ENV{'request.state'} eq 'construct' || $symb eq '') { + $Apache::lonhomework::results{'rndseed'}=$ENV{'form.rndseed'}; $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results, $ENV{'request.uri'},'',$domain,$name); &Apache::lonxml::debug('Construct Store return message:'.$result); @@ -251,12 +262,23 @@ sub start_problem { my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser); return ''; } -#intialize globals +#initialize globals $Apache::inputtags::part='0'; @Apache::inputtags::responselist = (); @Apache::inputtags::previous=(); @Apache::inputtags::previous_version=(); $Apache::structuretags::printanswer='No'; + @Apache::structuretags::whileconds=(); + @Apache::structuretags::whilebody=(); + @Apache::structuretags::whileline=(); + $Apache::lonhomework::scantronmode=0; + $Apache::lonhomework::problemstatus= + &Apache::lonnet::EXT('resource.0.problemstatus'); + + if (defined($ENV{'scantron.maxquest'})) { + $Apache::lonhomework::scantronmode=1; + } + if ($target ne 'analyze') { &initialize_storage(); if ($target eq 'web') { @@ -265,7 +287,7 @@ sub start_problem { $Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type'); &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:"); } - if ($Apache::lonhomework::type eq '') { + if ($Apache::lonhomework::type eq '' ) { my $uri=$ENV{'request.uri'}; if ($uri=~/\.(\w+)$/) { $Apache::lonhomework::type=$1; @@ -304,6 +326,15 @@ sub start_problem { #handle rand seed in construction space my $rndseed=&setup_rndseed($safeeval); + my ($symb)=&Apache::lonxml::whichuser(); + if ($ENV{'request.state'} ne "construct" && $symb eq '') { + $form_tag_start.=''. + ''. + ''; + } ($status,$accessmsg) = &Apache::lonhomework::check_access('0'); push (@Apache::inputtags::status,$status); my $expression='$external::datestatus="'.$status.'";'; @@ -450,7 +481,7 @@ sub end_problem { ) { if ($status eq 'CAN_ANSWER') { if ($target ne 'tex') { - $result.="\n"; + if ($ENV{'form.print_answer'} ne 'yes') {$result.="\n";} } } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER' || $status eq 'UNCHECKEDOUT' ) { @@ -474,8 +505,10 @@ sub end_problem { &finalize_storage(); } if ($target eq 'answer' && ($ENV{'request.state'} eq 'construct') ) { - $result.=''; #normally we get it from xmlend, but in CSTR - # we always show answer mode too. + if ($ENV{'form.print_answer'} ne 'yes') { + $result.=''; #normally we get it from xmlend, but in CSTR + # we always show answer mode too. + } } } elsif ($target eq 'meta') { if ($Apache::inputtags::part eq '0') { @@ -540,7 +573,7 @@ sub start_block { my $result; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') { my $code = $token->[2]->{'condition'}; if ($code) { @@ -572,45 +605,161 @@ sub start_block { sub end_block { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - my @result=('',''); - if ($target eq "edit" || $target eq 'modified') { @result=('','no'); } - return (@result); + my $result; + if ($target eq "edit") { + $result.= &Apache::edit::tag_end($target,$token,''); + } + return $result; +} + +sub start_languageblock { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + + my $result; + + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze') { + my $include = $token->[2]->{'include'}; + my $exclude = $token->[2]->{'exclude'}; + my %languages=&Apache::loncommon::display_languages(); + $result='1'; + if ($include) { + $result=''; + foreach (split(/\,/,$include)) { + if ($languages{$_}) { $result='1'; } + } + } + if ($exclude) { + foreach (split(/\,/,$exclude)) { + if ($languages{$_}) { $result='0'; } + } + } + if ( ! $result ) { + my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser); + &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]"); + } + $result=''; + } elsif ($target eq 'edit') { + $result .=&Apache::edit::tag_start($target,$token); + $result .=&Apache::edit::text_arg('Include Language:','include', + $token,40); + $result .=&Apache::edit::text_arg('Exclude Language:','exclude', + $token,40); + $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); + } elsif ($target eq 'modified') { + my $constructtag=&Apache::edit::get_new_args($token,$parstack, + $safeeval,'include', + 'exclude'); + if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } + } + return $result; +} + +sub end_languageblock { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my $result; + if ($target eq "edit") { + $result.= &Apache::edit::tag_end($target,$token,''); + } + return $result; +} + +sub start_instructorcomment { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + + my $result; + + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze') { + $result=($ENV{'request.role'}=~/^(in|cc|au|ca|li)/); + if ( ! $result ) { + my $skip=&Apache::lonxml::get_all_text("/instructorcomment",$parser); + &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]"); + } + $result=''; + } elsif ($target eq 'edit') { + $result .=&Apache::edit::tag_start($target,$token); + $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); + } + return $result; +} + +sub end_instructorcomment { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my $result; + if ($target eq "edit") { + $result.= &Apache::edit::tag_end($target,$token,''); + } + return $result; } sub start_while { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - my $code = $token->[2]->{'condition'}; + my $result; + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze') { + my $code = $token->[2]->{'condition'}; - push( @Apache::structuretags::whileconds, $code); - if (!$Apache::lonxml::default_homework_loaded) { - &Apache::lonxml::default_homework_load($safeeval); - } - my $result = &Apache::run::run($code,$safeeval); - my $bodytext=$$parser[$#$parser]->get_text("/while"); - push( @Apache::structuretags::whilebody, $bodytext); - if ( $result ) { - &Apache::lonxml::newparser($parser,\$bodytext); + push( @Apache::structuretags::whileconds, $code); + if (!$Apache::lonxml::default_homework_loaded) { + &Apache::lonxml::default_homework_load($safeeval); + } + my $result = &Apache::run::run($code,$safeeval); + my $bodytext=&Apache::lonxml::get_all_text("/while",$parser); + push( @Apache::structuretags::whilebody, $bodytext); + push( @Apache::structuretags::whileline, $token->[5]); + &Apache::lonxml::debug("s code $code got -$result-"); + if ( $result ) { + &Apache::lonxml::newparser($parser,\$bodytext); + } + } elsif ($target eq 'edit') { + $result .=&Apache::edit::tag_start($target,$token); + $result .=&Apache::edit::text_arg('Test Condition:','condition', + $token,40); + $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); + } elsif ($target eq 'modified') { + my $constructtag=&Apache::edit::get_new_args($token,$parstack, + $safeeval,'condition'); + if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } } - return ""; + return $result; } sub end_while { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - my $code = pop @Apache::structuretags::whileconds; - my $bodytext = pop @Apache::structuretags::whilebody; - my $result = &Apache::run::run($code,$safeeval); - if ( $result ) { - &Apache::lonxml::newparser($parser,\$bodytext); + my $result; + + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze') { + my $code = pop(@Apache::structuretags::whileconds); + my $bodytext = pop(@Apache::structuretags::whilebody); + my $line = pop(@Apache::structuretags::whileline); + my $return = &Apache::run::run($code,$safeeval); + my $starttime=time; + my $error=0; + while ($return) { + if (time-$starttime > + $Apache::lonnet::perlvar{'lonScriptTimeout'}) { + $return = 0; $error=1; next; + } + $result.=&Apache::scripttag::xmlparse($bodytext); + $return = &Apache::run::run($code,$safeeval); + } + if ($error) { + &Apache::lonxml::error('
Code ran too long. It ran for more than '.$Apache::lonnet::perlvar{'lonScriptTimeout'}.' seconds occured while running <while$gt; on line '.$line.'
'); + } + } elsif ($target eq "edit") { + $result.= &Apache::edit::tag_end($target,$token,''); } - return ""; + return $result; } -# +# # .. # .. # .. -# ... +# ... # sub start_randomlist { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; @@ -698,6 +847,8 @@ sub start_part { @Apache::inputtags::responselist = (); @Apache::inputtags::previous=(); @Apache::inputtags::previous_version=(); + $Apache::lonhomework::problemstatus= + &Apache::lonnet::EXT("resource.$id.problemstatus"); my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part); if ($target eq 'meta') {