--- loncom/homework/structuretags.pm 2004/11/11 23:45:35 1.272 +++ loncom/homework/structuretags.pm 2007/10/31 01:37:52 1.408 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.272 2004/11/11 23:45:35 albertel Exp $ +# $Id: structuretags.pm,v 1.408 2007/10/31 01:37:52 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,16 +36,30 @@ use Apache::File(); use Apache::lonmenu; use Apache::lonlocal; use Apache::lonxml; +use Apache::lonenc(); use Time::HiRes qw( gettimeofday tv_interval ); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + BEGIN { - &Apache::lonxml::register('Apache::structuretags',('block','languageblock','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startouttext','endouttext','simpleeditbutton','definetag')); + &Apache::lonxml::register('Apache::structuretags',('block','languageblock','translated','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startouttext','endouttext','simpleeditbutton','definetag')); } sub start_web { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - my $bodytext=&Apache::lonxml::get_all_text("/web",$parser); - if ($target eq 'web') { - return $bodytext; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + if ($target ne 'edit' && $target ne 'modified') { + my $bodytext=&Apache::lonxml::get_all_text("/web",$parser,$style); + if ($target eq 'web' || $target eq 'webgrade') { + return $bodytext; + } + } elsif ($target eq "edit" ) { + my $bodytext = + &Apache::lonxml::get_all_text_unbalanced("/web",$parser); + my $result = &Apache::edit::tag_start($target,$token); + $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1); + return $result; + } elsif ( $target eq "modified" ) { + return $token->[4].&Apache::edit::modifiedfield("/web",$parser); } return ''; } @@ -55,11 +69,21 @@ sub end_web { } sub start_tex { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; - my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser); - if ($target eq 'tex') { - return $bodytext.' '; + if ($target ne 'edit' && $target ne 'modified') { + my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser,$style); + if ($target eq 'tex') { + return $bodytext.' '; + } + } elsif ($target eq "edit" ) { + my $bodytext = + &Apache::lonxml::get_all_text_unbalanced("/tex",$parser); + my $result = &Apache::edit::tag_start($target,$token); + $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1); + return $result; + } elsif ( $target eq "modified" ) { + return $token->[4].&Apache::edit::modifiedfield("/tex",$parser); } return $result;; } @@ -68,8 +92,34 @@ sub end_tex { return ''; } +sub homework_js { + return &Apache::loncommon::resize_textarea_js(). + <<'JS'; + +JS +} + sub page_start { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name, + $extra_head)=@_; my %found; foreach my $taginside (@$tagstack) { foreach my $taglookedfor ('html','body','form') { @@ -77,107 +127,159 @@ sub page_start { } } - my $result; - my $head_tag_start; - if (!defined($found{'html'})) { - $result=&Apache::londefdef::start_html($target,$token,$tagstack, - $parstack,$parser,$safeeval); - $head_tag_start=''.&Apache::lonmenu::registerurl(undef,$target). - &Apache::lonhtmlcommon::htmlareaheaders(). - &Apache::lonhtmlcommon::spellheader(). - &Apache::lonxml::fontsettings(); - } - my $body_tag_start; - if (!defined($found{'body'}) && $ENV{'request.state'} eq 'construct' - && $ENV{'environment.remote'} eq 'off') { - $body_tag_start=&Apache::loncommon::bodytag(); + if ($target eq 'tex') { + return + &Apache::londefdef::start_html($target,$token,$tagstack, + $parstack,$parser,$safeeval); + } + + $extra_head .= &homework_js(); + + my %body_args; + if (defined($found{'html'})) { + $body_args{'skip_phases'}{'head'}=1; + } else { + + $extra_head .= &Apache::lonhtmlcommon::spellheader(); + + $extra_head .= &Apache::londefdef::generate_css_links(); + + if ($env{'request.state'} eq 'construct') { + $extra_head.=&Apache::edit::js_change_detection(). + "\n"; + } + } + + if (defined($found{'body'})) { + $body_args{'skip_phases'}{'body'}=1; + } elsif (!defined($found{'body'}) + && $env{'request.state'} eq 'construct') { + if ($target eq 'web' || $target eq 'edit') { + if ($env{'environment.remote'} ne 'off') { + $body_args{'only_body'} = 1; + } + } } elsif (!defined($found{'body'})) { - $body_tag_start='"; - $body_tag_start.=$help; - } + } + $body_args{'no_auto_mt_title'} = 1; + my $page_start = &Apache::loncommon::start_page($name,$extra_head, + \%body_args); + + if (!defined($found{'body'}) + && $env{'request.state'} ne 'construct' + && ($target eq 'web' || $target eq 'webgrade')) { + + my ($symb,undef,undef,undef,$publicuser)= &Apache::lonnet::whichuser(); + if ($symb eq '' && !$publicuser) { + my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference"); + $help=&mt("Browsing resource, all submissions are temporary.")."
"; + $page_start .= $help; } - $body_tag_start.=&Apache::lonxml::message_location(); } + + if (!defined($found{'body'})) { + $page_start .= &Apache::lonxml::message_location(); + } + my $form_tag_start; if (!defined($found{'form'})) { - $form_tag_start='
'; + $form_tag_start=''."\n"; + } } - return ($result,$head_tag_start,$body_tag_start,$form_tag_start); + return ($page_start,$form_tag_start); } #use Time::HiRes(); sub get_resource_name { my ($parstack,$safeeval)=@_; + my $name; if (defined($Apache::lonhomework::name)) { - return $Apache::lonhomework::name; - } - my $name=&Apache::lonnet::gettitle(); - if ($name eq '') { - $name=&Apache::lonnet::EXT('resource.title'); - if ($name eq 'con_lost') { $name = ''; } - } - if ($name!~/\S+/) { - $name=$ENV{'request.uri'}; - $name=~s-.*/([^/]+)$-$1-; + $name = $Apache::lonhomework::name; + } else { + my ($symb)=&Apache::lonnet::whichuser(); + $name=&Apache::lonnet::gettitle($symb); + if ($name eq '') { + $name=&Apache::lonnet::EXT('resource.title'); + if ($name eq 'con_lost') { $name = ''; } + } + if ($name!~/\S+/) { + $name=$env{'request.uri'}; + $name=~s-.*/([^/]+)$-$1-; + } + # The name has had html tags escaped: + + $name=~s/<//gs; + + $Apache::lonhomework::name=$name; } - $Apache::lonhomework::name=$name; return $name; } sub setup_rndseed { my ($safeeval)=@_; my $rndseed; - my ($symb)=&Apache::lonxml::whichuser(); - if ($ENV{'request.state'} eq "construct" || $symb eq '' || - $Apache::lonhomework::history{'resource.CODE'}) { - $rndseed=$ENV{'form.rndseed'}; + my ($symb)=&Apache::lonnet::whichuser(); + if ($env{'request.state'} eq "construct" + || $symb eq '' + || $Apache::lonhomework::type eq 'practice' + || $Apache::lonhomework::history{'resource.CODE'}) { + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['rndseed']); + $rndseed=$env{'form.rndseed'}; if (!$rndseed) { $rndseed=$Apache::lonhomework::history{'rndseed'}; if (!$rndseed) { $rndseed=time; } - $ENV{'form.rndseed'}=$rndseed; + $env{'form.rndseed'}=$rndseed; } - if ($ENV{'form.resetdata'} eq &mt('New Problem Variation') || - $ENV{'form.newrandomization'} eq &mt('New Randomization')) { + if ( ($env{'form.resetdata'} eq &mt('New Problem Variation') + && $env{'form.submitted'} eq 'yes') || + $env{'form.newrandomization'} eq &mt('New Randomization')) { srand(time); $rndseed=int(rand(2100000000)); - $ENV{'form.rndseed'}=$rndseed; - delete($ENV{'form.resetdata'}); - delete($ENV{'form.newrandomization'}); + $env{'form.rndseed'}=$rndseed; + delete($env{'form.resetdata'}); + delete($env{'form.newrandomization'}); } if (defined($rndseed) && $rndseed ne int($rndseed)) { - $rndseed=join(',',&Math::Random::random_seed_from_phrase($rndseed)); + $rndseed=join(':',&Apache::lonnet::digest($rndseed)); } if ($Apache::lonhomework::history{'resource.CODE'}) { $rndseed=&Apache::lonnet::rndseed(); @@ -192,36 +294,45 @@ sub setup_rndseed { sub remember_problem_state { return ' - - - '; + + + '; } sub problem_edit_header { return ''. &Apache::structuretags::remember_problem_state().' +
+
+'.&mt('Problem Editing').&Apache::loncommon::help_open_menu('Problem Editing','Problem_Editor_XML_Index',5,'Authoring').' +
+
- -
- -
'. - &Apache::loncommon::help_open_menu('','Problem Editing Help','Problem_Editor_XML_Index','',5,'Authoring',undef,undef,undef,'Problem Editing Help') - .'
'. - '
'; + + + +
+ + +
+
+ +'. + '
'; } sub problem_edit_footer { return '

'. - &Apache::lonhtmlcommon::htmlareaselectactive(@Apache::lonxml::htmlareafields). - "\n\n\n"; + &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()). + "\n\n".&Apache::loncommon::end_page(); } sub option { my ($value,$name) = @_; my $result ="
'.$skip.'
'; return $result; } @@ -788,10 +1167,10 @@ sub start_block { my $result; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $code = $token->[2]->{'condition'}; - if (defined($code)) { + if (defined($code) && $code ne '') { if (!$Apache::lonxml::default_homework_loaded) { &Apache::lonxml::default_homework_load($safeeval); } @@ -832,23 +1211,42 @@ sub start_languageblock { my $result; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { 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'; } - } - } + my @preferred_languages=&Apache::loncommon::preferred_languages(); +# This should not even happen, since we should at least have the server language + if (!$preferred_languages[0]) { $preferred_languages[0]='en'; } +# Now loop over all languages in order of preference + foreach my $preferred_language (@preferred_languages) { +# If the languageblock has no arguments, show the contents + $result=1; + my $found=0; +# Do we have an include argument? + if ($include) { +# If include is specified, by default, don't render the block + $result=0; + foreach my $included_language (split(/\,/,$include)) { +# ... but if my preferred language is included, render it + if ($included_language eq $preferred_language) { + $result=1; + $found=1; + } + } + } +# Do we have an exclude argument? + if ($exclude) { + $result=1; + foreach my $excluded_language (split(/\,/,$exclude)) { + if ($excluded_language eq $preferred_language) { + $result=0; + $found=1; + } + } + } + if ($found) { last; } + } if ( ! $result ) { my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser, $style); @@ -880,15 +1278,65 @@ sub end_languageblock { return $result; } +{ + my %available_texts; + sub start_translated { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + &Apache::lonxml::register('Apache::structuretags',('lang')); + undef(%available_texts); + } + + sub end_translated { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + my $result; + #show the translation on viewable targets + if ($target eq 'web' || $target eq 'tex' || $target eq 'webgrade'|| + # or non-viewable targets, if it's embedded in something that + # wants the output + (($target eq 'answer' || $target eq 'analyze'|| $target eq 'grade') + && &Apache::lonxml::in_redirection() ) ) { + my @possibilities = keys(%available_texts); + my $which = + &Apache::loncommon::languages(\@possibilities) || 'default'; + $result = $available_texts{$which}; + } + undef(%available_texts); + &Apache::lonxml::deregister('Apache::structuretags',('lang')); + return $result; + } + + + sub start_lang { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { + &Apache::lonxml::startredirection(); + } + return ''; + } + + sub end_lang { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { + my $result = &Apache::lonxml::endredirection(); + my $which = &Apache::lonxml::get_param('which',$parstack, + $safeeval); + $available_texts{$which} = $result; + } + return ''; + } +} + sub start_instructorcomment { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; 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) or ($ENV{'form.instructor_comments'} eq 'hide')) { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { + $result=($env{'request.role'}=~/^(in|cc|au|ca|li)/); + if ( (! $result) or ($env{'form.instructor_comments'} eq 'hide')) { my $skip=&Apache::lonxml::get_all_text("/instructorcomment", $parser,$style); &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]"); @@ -911,11 +1359,11 @@ sub end_instructorcomment { } sub start_while { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $code = $token->[2]->{'condition'}; push( @Apache::structuretags::whileconds, $code); @@ -923,7 +1371,7 @@ sub start_while { &Apache::lonxml::default_homework_load($safeeval); } my $result = &Apache::run::run($code,$safeeval); - my $bodytext=&Apache::lonxml::get_all_text("/while",$parser); + my $bodytext=&Apache::lonxml::get_all_text("/while",$parser,$style); push( @Apache::structuretags::whilebody, $bodytext); push( @Apache::structuretags::whileline, $token->[5]); &Apache::lonxml::debug("s code $code got -$result-"); @@ -947,8 +1395,8 @@ sub end_while { 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') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $code = pop(@Apache::structuretags::whileconds); my $bodytext = pop(@Apache::structuretags::whilebody); my $line = pop(@Apache::structuretags::whileline); @@ -958,9 +1406,16 @@ sub end_while { while ($return) { if (time-$starttime > $Apache::lonnet::perlvar{'lonScriptTimeout'}) { - #$return = 0; $error=1; next; + $return = 0; $error=1; next; } $result.=&Apache::scripttag::xmlparse($bodytext); + if ($target eq 'grade' || $target eq 'answer' || + $target eq 'analyze') { + # grade/answer/analyze should produce no output but if we + # are redirecting, the redirecter should know what to do + # with the output + if (!$Apache::lonxml::redirection) { undef($result); } + } $return = &Apache::run::run($code,$safeeval); } if ($error) { @@ -979,12 +1434,14 @@ sub end_while { # ... # sub start_randomlist { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result; - if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $body= &Apache::lonxml::get_all_text("/randomlist",$parser); - my $b_parser= HTML::TokeParser->new(\$body); + my $b_parser= HTML::LCParser->new(\$body); + $b_parser->xml_mode(1); + $b_parser->marked_sections(1); my $b_tok; my @randomlist; my $list_item; @@ -1008,17 +1465,19 @@ sub start_randomlist { # print "END-TAG $b_tok->[1]
"; # } } - my @idx_arr = (0 .. $#randomlist); - &Apache::structuretags::shuffle(\@idx_arr); - my $bodytext = ''; - my $show=$#randomlist; - my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval); - $showarg--; - if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; } - for(0 .. $show) { - $bodytext .= "$randomlist[ $idx_arr[$_] ]"; + if (@randomlist) { + my @idx_arr = (0 .. $#randomlist); + &Apache::structuretags::shuffle(\@idx_arr); + my $bodytext = ''; + my $show=$#randomlist; + my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval); + $showarg--; + if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; } + for(0 .. $show) { + $bodytext .= "$randomlist[ $idx_arr[$_] ]"; + } + &Apache::lonxml::newparser($parser,\$bodytext); } - &Apache::lonxml::newparser($parser,\$bodytext); } elsif ($target eq 'edit' ) { $result .=&Apache::edit::tag_start($target,$token); $result .=&Apache::edit::text_arg('Maximum Tags to Show:','show', @@ -1035,7 +1494,7 @@ sub start_randomlist { sub shuffle { my $a=shift; my $i; - if (defined(@$a)) { + if (ref($a) eq 'ARRAY' && @$a) { &Apache::response::pushrandomnumber(); for($i=@$a;--$i;) { my $j=int(&Math::Random::random_uniform() * ($i+1)); @@ -1056,21 +1515,37 @@ sub end_randomlist { return $result; } +sub ordered_show_check { + my $last_part=$Apache::inputtags::partlist[-2]; + my $in_order= + &Apache::lonnet::EXT('resource.'.$Apache::inputtags::part.'.ordered'); + my $in_order_show=1; + if ($last_part ne '0' && lc($in_order) eq 'yes') { + $in_order_show=&Apache::response::check_status($last_part); + } + return $in_order_show; +} + sub start_part { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + if (!$Apache::lonxml::metamode) { + &Apache::lonxml::startredirection(); # we'll use redirection to fix up + # duedates. + } my $result=''; - my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval); - if ($id eq '') { $id = $Apache::lonxml::curdepth; } + my $id= &Apache::lonxml::get_id($parstack,$safeeval); $Apache::inputtags::part=$id; push(@Apache::inputtags::partlist,$id); @Apache::inputtags::response=(); @Apache::inputtags::previous=(); @Apache::inputtags::previous_version=(); - $Apache::lonhomework::problemstatus=&get_problem_status($id); + &Apache::lonhomework::set_show_problem_status(&get_problem_status($id)); + &Apache::response::reset_params(); + my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part); my $newtype=&Apache::lonnet::EXT("resource.$id.type"); if ($newtype) { $Apache::lonhomework::type=$newtype; } - + my $in_order_show=&ordered_show_check(); my $expression='$external::part=\''.$Apache::inputtags::part.'\';'; $expression.='$external::type=\''.$Apache::lonhomework::type.'\';'; &Apache::run::run($expression,$safeeval); @@ -1081,15 +1556,15 @@ sub start_part { &Apache::response::meta_parameter_write('display','string',$display,'Part Description'); } elsif ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { - if ($hidden) { - my $bodytext=&Apache::lonxml::get_all_text("/part",$parser); + if ($hidden || !$in_order_show) { + my $bodytext=&Apache::lonxml::get_all_text("/part",$parser,$style); } else { my ($status,$accessmsg) = &Apache::lonhomework::check_access($id); push (@Apache::inputtags::status,$status); my $expression='$external::datestatus="'.$status.'";'; $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";'; &Apache::run::run($expression,$safeeval); - if ($ENV{'request.state'} eq 'construct') { + if ($env{'request.state'} eq 'construct') { &set_problem_state($Apache::inputtags::part); } if (( $status eq 'CLOSED' ) || @@ -1098,11 +1573,12 @@ sub start_part { ( $status eq 'BANNED') || ( $status eq 'UNAVAILABLE') || ( $status eq 'INVALID_ACCESS')) { - my $bodytext=&Apache::lonxml::get_all_text("/part",$parser); + my $bodytext=&Apache::lonxml::get_all_text("/part",$parser, + $style); if ( $target eq "web" ) { $result="
".&mt('Part is not open to be viewed. It')." $accessmsg
"; } elsif ( $target eq 'tex' ) { - if (not $ENV{'form.problem_split'}=~/yes/) { + if (not $env{'form.problem_split'}=~/yes/) { $result="\\end{minipage}\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\\\begin{minipage}{\\textwidth}"; } else { $result="\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\"; @@ -1110,15 +1586,15 @@ sub start_part { } } else { if ($target eq 'tex') { - if (not $ENV{'form.problem_split'}=~/yes/) { + if (not $env{'form.problem_split'}=~/yes/) { if ($$tagstack[-2] eq 'td') { - $result.='\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent'; + $result.='\noindent \begin{minipage}{\textwidth}\noindent'; } else { $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent'; } } my $weight = &Apache::lonnet::EXT("resource.$id.weight"); - my $allkeys=&Apache::lonnet::metadata($ENV{'request.uri'},'packages'); + my $allkeys=&Apache::lonnet::metadata($env{'request.uri'},'packages'); my @allkeys = split /,/,$allkeys; my $allow_print_points = 0; foreach my $partial_key (@allkeys) { @@ -1126,9 +1602,17 @@ sub start_part { if ($1 ne '0') {$allow_print_points=1;} } } + my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries"); + if (defined($maxtries) && $maxtries < 0) { + $allow_print_points=0; + } + if (lc($env{'course.'.$env{'request.course.id'}. + '.disableexampointprint'}) eq 'yes') { + $allow_print_points=0; + } if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { $result .= '\fbox{\textit{'.$weight.' pt}}';} } elsif ($target eq 'web') { - $result.=''; + $result.=''; } } } @@ -1146,7 +1630,6 @@ sub start_part { #limiting ids to only letters numbers, and space $token->[2]->{'id'}=~s/[^A-Za-z0-9 ]//gs; $result = &Apache::edit::rebuild_tag($token); - $result.=&Apache::edit::handle_insert(); } } return $result; @@ -1157,41 +1640,50 @@ sub end_part { &Apache::lonxml::debug("in end_part $target "); my $status=$Apache::inputtags::status['-1']; my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part); - my $result=''; - if ( $target eq 'meta' ) { - $result=''; - } elsif ($target eq 'grade') { + my $in_order_show=&ordered_show_check(); + my $result; + if (!$Apache::lonxml::metamode) { + $result = &Apache::lonxml::endredirection(); # started in &start_part + $Apache::lonxml::post_evaluate=0; + } + if ($target eq 'grade') { if (($status eq 'CAN_ANSWER' || $Apache::lonhomework::scantronmode) && - !$hidden) { - $result=&Apache::inputtags::grade; + !$hidden && $in_order_show) { + $result.=&Apache::inputtags::grade; } else { # move any submission data to .hidden &Apache::inputtags::hidealldata($Apache::inputtags::part); } - } elsif (($target eq 'web' || $target eq 'tex') && !$hidden ) { + } elsif (($target eq 'web' || $target eq 'tex') && + !$hidden && $in_order_show) { my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part, $target); if ($Apache::lonhomework::type eq 'exam' && $target eq 'tex') { $gradestatus=''; } - $result=$gradestatus; + $result.=$gradestatus; if ($$tagstack[-2] eq 'td' and $target eq 'tex') {$result.='\end{minipage}';} } elsif ($target eq 'edit') { - $result=&Apache::edit::end_table(); + $result.=&Apache::edit::end_table(); + } elsif ($target eq 'modified') { + $result .= $token->[2]; } pop @Apache::inputtags::status; $Apache::inputtags::part=''; + $Apache::lonhomework::type = $Apache::lonhomework::default_type; return $result; } sub start_preduedate { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'webgrade') { &Apache::lonxml::debug("State in preduedate is ". $Apache::inputtags::status['-1']); - if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' && + if (!$Apache::lonhomework::scantronmode && + $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' && $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') { &Apache::lonxml::debug("Wha? ". ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER')); - &Apache::lonxml::get_all_text("/preduedate",$parser); + &Apache::lonxml::get_all_text("/preduedate",$parser,$style); } } return ''; @@ -1201,14 +1693,21 @@ sub end_preduedate { return ''; } +# In all the modes where text is +# displayable, all we do is eat up the text between the start/stop +# tags if the conditions are not right to display it. sub start_postanswerdate { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - if ($target eq 'web' || $target eq 'grade') { - if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') { - &Apache::lonxml::get_all_text("/postanswerdate",$parser); + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + my $pav = &Apache::lonnet::allowed('pav', $env{'request.course.id'}) || + &Apache::lonnet::allowed('pav', + $env{'request.course.id'}.'/'.$env{'request.course.sec'}); + if ($target eq 'web' || $target eq 'grade' || $target eq 'webgrade' || + $target eq 'tex' ) { + if ($Apache::lonhomework::scantronmode || + $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER' || + (($target eq 'tex') && !$pav)) { + &Apache::lonxml::get_all_text("/postanswerdate",$parser,$style); } - } elsif ($target eq 'tex') { - &Apache::lonxml::get_all_text("/postanswerdate",$parser); } return ''; } @@ -1218,15 +1717,15 @@ sub end_postanswerdate { } sub start_notsolved { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex') { + $target eq 'tex' || $target eq 'webgrade') { my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"}; &Apache::lonxml::debug("not solved has :$gradestatus:"); if ($gradestatus =~ /^correct/ && &Apache::response::show_answer()) { &Apache::lonxml::debug("skipping"); - &Apache::lonxml::get_all_text("/notsolved",$parser); + &Apache::lonxml::get_all_text("/notsolved",$parser,$style); } } return ''; @@ -1237,13 +1736,13 @@ sub end_notsolved { } sub start_solved { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"}; if ($gradestatus !~ /^correct/ || !&Apache::response::show_answer()) { - &Apache::lonxml::get_all_text("/solved",$parser); + &Apache::lonxml::get_all_text("/solved",$parser,$style); } } return ''; @@ -1254,10 +1753,10 @@ sub end_solved { } sub start_problemtype { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $mode=lc(&Apache::lonxml::get_param('mode',$parstack,$safeeval)); if (!defined($mode)) { $mode='show'; } my $for=&Apache::lonxml::get_param('for',$parstack,$safeeval); @@ -1266,10 +1765,10 @@ sub start_problemtype { if ($Apache::lonhomework::type eq lc($type)) { $found=1; } } if ($mode eq 'show' && !$found) { - &Apache::lonxml::get_all_text("/problemtype",$parser); + &Apache::lonxml::get_all_text("/problemtype",$parser,$style); } if ($mode eq 'hide' && $found) { - &Apache::lonxml::get_all_text("/problemtype",$parser); + &Apache::lonxml::get_all_text("/problemtype",$parser,$style); } } elsif ($target eq 'edit') { $result .=&Apache::edit::tag_start($target,$token); @@ -1299,25 +1798,33 @@ sub start_startouttext { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my @result=(''.''); if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); } + + my $nesting = + &Apache::lonxml::set_state('outtext', + &Apache::lonxml::get_state('outtext')+1); + if ($nesting > 1 && $env{'request.state'} eq 'construct') { + &Apache::lonxml::error("Nesting of <startouttext /> not allowed, on line ".$token->[5]); + } return (@result); } sub end_startouttext { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; my $text=''; if ($target eq 'edit') { - $text=&Apache::lonxml::get_all_text("endouttext",$parser); + $text=&Apache::lonxml::get_all_text("endouttext",$parser,$style); $result.=&Apache::edit::start_table($token)."".&mt('Text Block')." ".&mt('Delete:'). &Apache::edit::deletelist($target,$token) ." ". &Apache::edit::insertlist($target,$token). + '' . + &Apache::loncommon::helpLatexCheatsheet(). &Apache::edit::end_row(). - &Apache::edit::start_spanning_row()."\n" - . &Apache::loncommon::helpLatexCheatsheet () . + &Apache::edit::start_spanning_row()."\n". &Apache::edit::editfield($token->[1],$text,"",80,8,1); } if ($target eq 'modified') { @@ -1335,7 +1842,16 @@ sub start_endouttext { if ($target eq "edit" ) { $result="".&Apache::edit::end_table()."\n"; } if ($target eq "modified") { $result=''. - &Apache::edit::handle_insertafter('startouttext'); } + &Apache::edit::handle_insertafter('startouttext'); + } + + my $nesting = + &Apache::lonxml::set_state('outtext', + &Apache::lonxml::get_state('outtext')-1); + if ($nesting < 0 && $env{'request.state'} eq 'construct') { + &Apache::lonxml::error(" Extraneous <endouttext /> not allowed on line ".$token->[5]); + &Apache::lonxml::set_state('outtext', 0); + } return $result; } @@ -1347,8 +1863,8 @@ sub end_endouttext { } sub delete_startouttext { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - # my $text=&Apache::lonxml::get_all_text("endouttext",$parser); + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + # my $text=&Apache::lonxml::get_all_text("endouttext",$parser,$style); my $text=$$parser['-1']->get_text("/endouttext"); my $ntoken=$$parser['-1']->get_token(); &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext"); @@ -1363,12 +1879,14 @@ sub delete_startouttext { sub start_simpleeditbutton { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result=''; - if (($target eq 'web') && - (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { - my $url=$ENV{'request.noversionuri'}; + if (($env{'form.simple_edit_button'} ne 'off') && + ($target eq 'web') && + (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) { + my $url=$env{'request.noversionuri'}; $url=~s/\?.*$//; + my ($symb) = &Apache::lonnet::whichuser(); $result='
'. - ''.&mt('Simple Problem Editor').' - '.&mt('Note: it can take up to 10 minutes for changes to take effect for all users.'). + ''.&mt('Edit').' - '.&mt('Note: it can take up to 10 minutes for changes to take effect for all users.'). &Apache::loncommon::help_open_topic('Caching').'

'; } return $result;