--- loncom/homework/structuretags.pm 2005/04/07 06:56:22 1.284 +++ loncom/homework/structuretags.pm 2005/11/03 11:10:25 1.308 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.284 2005/04/07 06:56:22 albertel Exp $ +# $Id: structuretags.pm,v 1.308 2005/11/03 11:10:25 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -68,6 +68,33 @@ sub end_tex { return ''; } +sub body_tag_start { + my ($target,$background,$bgcolor)=@_; + my $body_tag_start=''."\n"; - } - if ($target eq 'web' && $env{'request.state'} ne 'construct') { + my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack, + $safeeval); + $body_tag_start=&body_tag_start($target,$background,$bgcolor); + if ( ($target eq 'web' || $target eq 'webgrade') + && $env{'request.state'} ne 'construct') { my ($symb,undef,undef,undef,$publicuser)= &Apache::lonxml::whichuser(); if ($symb eq '' && !$publicuser) { @@ -185,7 +192,7 @@ sub setup_rndseed { 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(); @@ -317,10 +324,11 @@ sub initialize_storage { # Stores away the result has to a student's environment # checks form.grade_ for specific values, other wises stores # to the running users environment +# Will increment totals for attempts, students, and corrects +# if running user has student role. sub finalize_storage { my $result; - my ($temp) = keys %Apache::lonhomework::results; - if ( $temp ne '' ) { + if (%Apache::lonhomework::results) { my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); if ($env{'request.state'} eq 'construct' || $symb eq '') { $Apache::lonhomework::results{'rndseed'}=$env{'form.rndseed'}; @@ -331,10 +339,54 @@ sub finalize_storage { $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results, $symb,$courseid,$domain,$name); &Apache::lonxml::debug('Store return message:'.$result); + if ($env{'request.role'} =~/^st/) { + &store_aggregates($symb,$courseid); + } } } return $result; } +use Data::Dumper; + +# -------------------------------------------------------------store_aggregates +# Sends hash of values to be incremented in nohist_resourcetracker.db +# for the course. Increments total number of attempts, unique students +# and corrects for each part for an instance of a problem, as appropriate. +sub store_aggregates { + my ($symb,$courseid) = @_; + my %aggregate; + my @parts; + my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cname = $env{'course.'.$env{'request.course.id'}.'.num'}; + foreach my $key (keys(%Apache::lonhomework::results)) { + if ($key =~ /resource\.([^\.]+)\.tries/) { + push(@parts, $1); + } + } + foreach my $part (@parts) { + if ($Apache::lonhomework::results{'resource.'.$part.'.award'} + eq 'APPROX_ANS' || + $Apache::lonhomework::results{'resource.'.$part.'.award'} + eq 'EXACT_ANS') { + $aggregate{$symb."\0".$part."\0correct"} = 1; + } + if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) { + $aggregate{$symb."\0".$part."\0users"} = 1; + } else { + my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]); + if ($last_reset) { + if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) { + $aggregate{$symb."\0".$part."\0users"} = 1; + } + } + } + $aggregate{$symb."\0".$part."\0attempts"} = 1; + } + if (keys (%aggregate) > 0) { + &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate, + $cdomain,$cname); + } +} sub checkout_msg { my %lt=&Apache::lonlocal::texthash( @@ -370,19 +422,33 @@ sub firstaccess_msg { ENDCHECKOUT } +# initializes the problem globals across the inputtags, lonhomework, and +# structuretags modules. +# +# sub init_problem_globals { my ($type)=@_; #initialize globals + # For problems, we start out in part 0 (outside a tag). + # and part 0 is used to describe the main body of the + # if ($type eq 'problem') { $Apache::inputtags::part='0'; @Apache::inputtags::partlist=('0'); $Apache::lonhomework::problemstatus=&get_problem_status('0'); $Apache::lonhomework::ignore_response_errors=0; + } elsif ($type eq 'library') { $Apache::inputtags::part=''; @Apache::inputtags::partlist=(); $Apache::lonhomework::problemstatus=''; $Apache::lonhomework::ignore_response_errors=1; + + } elsif ($type eq 'Task') { + $Apache::inputtags::part='0'; + @Apache::inputtags::partlist=('0'); + $Apache::lonhomework::problemstatus=''; + $Apache::lonhomework::ignore_response_errors=1; } @Apache::inputtags::responselist = (); @Apache::inputtags::importlist = (); @@ -433,6 +499,9 @@ sub get_problem_status { sub start_problem { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + # Problems don't nest and we don't allow more than one in + # a .problem file. + # if ( $Apache::inputtags::part ne '' || $Apache::lonhomework::parsing_a_problem) { &Apache::lonxml::error('Only one <problem> allowed in a .problem file'); @@ -470,6 +539,7 @@ sub start_problem { &Apache::lonxml::debug("Using default type, problem, :$uri:"); } } + $Apache::lonhomework::default_type = $Apache::lonhomework::type; #added vars to the scripting enviroment my $expression='$external::part=\''.$Apache::inputtags::part.'\';'; @@ -512,11 +582,12 @@ sub start_problem { value="'.$env{'form.username'}.'" />'; if ($env{'user.adv'}) { $form_tag_start.= - ' '; } $form_tag_start.='
'; } @@ -590,27 +661,47 @@ sub start_problem { } my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries"); if (defined($maxtries) && $maxtries < 0) { $allow_print_points=0; } - my $duedate = &Apache::lonnet::EXT("resource.$id.duedate"); - $duedate = POSIX::strftime("%c",localtime($duedate)); + if (lc($env{'course.'.$env{'request.course.id'}. + '.disableexampointprint'}) eq 'yes') { + $allow_print_points=0; + } + my $name_of_resourse= &Apache::lonxml::latex_special_symbols(&get_resource_name($parstack,$safeeval),'header'); + my $begin_doc='\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource

"'.$name_of_resourse.'"

located in
'.$env{'request.uri'}.'
STAMPOFPASSEDRESOURCEEND} \noindent '; + my $toc_line='\vskip 1 mm\noindent '.$startminipage. + '\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}'; + + # Figure out what the due date is and if we need to print it in the problem header. + # We have been logging the last due date written to file. + # + + + my $duetime = &Apache::lonnet::EXT("resource.$id.duedate"); + my $duedate = POSIX::strftime("%c",localtime($duetime)); my $temp_file; my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due"; + + # Figure out what the last printed due date is or set it to the epoch if no duedates + # have been printed. + + my $due_file_content = 0; # If the file does not yet exist, time is the epoch. if (-e $filename) { $temp_file = Apache::File->new($filename); - } else { - $temp_file = Apache::File->new('>>'.$filename); - } - my @due_file_content = <$temp_file>; - my $due_file_content = $due_file_content[$#due_file_content]; - chomp $due_file_content; - my $name_of_resourse= &Apache::lonxml::latex_special_symbols(&get_resource_name($parstack,$safeeval),'header'); - if ($due_file_content ne $duedate) { + my @due_file = <$temp_file>; + $due_file_content = $due_file[$#due_file]; + chomp $due_file_content; + } + # The big change; Due do the comparison on + # the absolute time rather than textual time since that is format independent. + # + if ($due_file_content ne $duetime) { $temp_file = Apache::File->new('>'.$filename); - print $temp_file "$duedate\n"; + print $temp_file "$duetime\n"; if (not $env{'request.symb'} =~ m/\.page_/) { if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') { - $result .= '\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource

"'.$name_of_resourse.'"

located in
'.$env{'request.uri'}.'
STAMPOFPASSEDRESOURCEEND} \noindent\textit{Due date: '.$duedate.'} \vskip 1 mm\noindent '.$startminipage.'\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}'; + $result .= $begin_doc. + '\textit{Due date: '.$duedate.'} '.$toc_line; } else { - $result .= '\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource

"'.$name_of_resourse.'"

located in
'.$env{'request.uri'}.'
STAMPOFPASSEDRESOURCEEND} \noindent \vskip 1 mm \noindent'.$startminipage.'\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}'; + $result .= $begin_doc.$toc_line; if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $result .= '\fbox{\textit{'.$weight.' pt}}';} } } else { @@ -618,7 +709,7 @@ sub start_problem { } } else { if (not $env{'request.symb'} =~ m/\.page_/) { - $result .= '\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource

"'.$name_of_resourse.'"

located in
'.$env{'request.uri'}.'
STAMPOFPASSEDRESOURCEEND} \noindent \vskip 1 mm\noindent'.$startminipage.'\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}'; + $result .= $begin_doc.$toc_line; if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { $result .= '\fbox{\textit{'.$weight.' pt}}';} } else { $result .= '\vskip 1mm \\\\\\\\'; @@ -699,7 +790,8 @@ sub end_problem { } if ($target eq 'answer' && ($env{'request.state'} eq 'construct') && $env{'form.answer_output_mode'} ne 'tex') { - $result.=''; # normally we get it from xmlend, but in CSTR + $result.=&Apache::lonxml::xmlend().''; + # normally we get it from above, but in CSTR # we always show answer mode too. } } elsif ($target eq 'meta') { @@ -994,7 +1086,9 @@ sub start_randomlist { if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' || $target eq 'tex' || $target eq 'analyze') { 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; @@ -1018,17 +1112,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', @@ -1045,7 +1141,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)); @@ -1081,7 +1177,7 @@ sub start_part { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result=''; my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval); - if ($id eq '') { $id = $Apache::lonxml::curdepth; } + if ($id =~ /^\s*$/) { $id = $Apache::lonxml::curdepth; } $Apache::inputtags::part=$id; push(@Apache::inputtags::partlist,$id); @Apache::inputtags::response=(); @@ -1151,6 +1247,10 @@ sub start_part { 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.=''; @@ -1208,6 +1308,7 @@ sub end_part { } pop @Apache::inputtags::status; $Apache::inputtags::part=''; + $Apache::lonhomework::type = $Apache::lonhomework::default_type; return $result; } @@ -1215,7 +1316,8 @@ sub start_preduedate { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { &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); @@ -1231,7 +1333,8 @@ sub end_preduedate { 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') { + if ($Apache::lonhomework::scantronmode || + $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') { &Apache::lonxml::get_all_text("/postanswerdate",$parser); } } elsif ($target eq 'tex') {