--- loncom/interface/statistics/lonstathelpers.pm 2006/02/14 16:05:46 1.52 +++ loncom/interface/statistics/lonstathelpers.pm 2011/11/18 22:35:33 1.59.12.2 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstathelpers.pm,v 1.52 2006/02/14 16:05:46 albertel Exp $ +# $Id: lonstathelpers.pm,v 1.59.12.2 2011/11/18 22:35:33 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,6 +60,9 @@ use Time::Local(); use Spreadsheet::WriteExcel(); use GDBM_File; use Storable qw(freeze thaw); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + #################################################### #################################################### @@ -83,7 +86,7 @@ sub render_resource { ## Render the problem my ($base) = ($resource->src =~ m|^(.*/)[^/]*$|); $base="http://".$ENV{'SERVER_NAME'}.$base; - my ($src,$symb)=($resource->src,&Apache::lonnet::escape($resource->symb)); + my ($src,$symb)=($resource->link,&escape($resource->shown_symb)); my $rendered_problem = &Apache::lonnet::ssi_body($src.'?symb='.$symb); $rendered_problem =~ s/<\s*form\s*/)|<\/nop>|g; @@ -155,23 +158,22 @@ sub problem_selector { resptype=>$resptype}); my $checked = ''; if ($env{'form.problemchoice'} eq $value) { - $checked = 'checked '; + $checked = ' checked="checked"'; } my $title = $res->compTitle; if (! defined($title) || $title eq '') { ($title) = ($res->src =~ m:/([^/]*)$:); } $seq_str .= ''. - qq{}. + qq{}. ''. ''; if (scalar(@response_ids) > 1) { $seq_str .= &mt('response').' '.$respid; } - my $link = $res->src.'?symb='. - &Apache::lonnet::escape($res->symb); + my $link = $res->link.'?symb='.&escape($res->shown_symb); $seq_str .= (' 'x2). - qq{view}; + ''.&mt('view').''; $seq_str .= "\n"; $rb_count++; } @@ -179,12 +181,12 @@ sub problem_selector { } } if ($seq_str ne '') { - $Str .= ' '. + $Str .= ' '. ''.$seq->compTitle.''. "\n".$seq_str; if (defined($sequence_addendum)) { $Str .= ''. - (' 'x2). + (' 'x2). ''.$sequence_addendum.''. "\n"; } @@ -227,20 +229,41 @@ sub MultipleProblemSelector { if (! defined($navmap)) { $navmap = Apache::lonnavmaps::navmap->new(); if (! defined($navmap)) { - $Str .= - '

'.&mt('Error: cannot process course structure').'

'; + $Str .= '
' + .&mt('Error: cannot process course structure') + .'
'; return $Str; } } my $selected = {map { ($_,1) } (&get_selected_symbs($inputname))}; # Header $Str .= <<"END"; - END $Str .= - ''.&mt('Select All').''. + ''. (' 'x4). - ''.&mt('Unselect All').''; + ''; $Str .= $/.''.$/; - my $iterator = $navmap->getIterator(undef, undef, undef, 1); - my $sequence_string; + my ($iterator,$sequence_string,@Accumulator); my $seq_id = 0; - my @Accumulator = (&new_accumulator($env{'course.'.$cid.'.description'}, - '', - '', - $seq_id++, - $inputname)); + if (&Apache::loncommon::needs_gci_custom()) { + my $cdom = $env{'course.'.$cid.'.domain'}; + my $cnum = $env{'course.'.$cid.'.num'}; + my $mapurl = "/uploaded/$cdom/$cnum/default_1261144274.sequence"; + my $map = $navmap->getResourceByUrl($mapurl); + my $firstResource = $map->map_start(); + my $lastResource = $map->map_finish(); + $iterator = $navmap->getIterator($firstResource,$lastResource,sub { $_[0]->is_problem() },1); + @Accumulator = (&new_accumulator($map->compTitle, + $map->src, + $map->symb, + $seq_id++, + $inputname)); + } else { + $iterator = $navmap->getIterator(undef, undef, undef, 1); + @Accumulator = (&new_accumulator($env{'course.'.$cid.'.description'}, + '', + '', + $seq_id++, + $inputname)); + } my @Sequence_Data; while (my $curRes = $iterator->next()) { if ($curRes == $iterator->END_MAP) { @@ -285,9 +323,12 @@ END $seq_id++, $inputname)); } elsif ($curRes->is_problem) { + my $is_selected; + if (($env{'form.allproblems'}) || (exists($selected->{$curRes->symb}))) { + $is_selected = 1; + } if (@Accumulator && $Accumulator[-1] ne '') { - &{$Accumulator[-1]}($curRes, - exists($selected->{$curRes->symb})); + &{$Accumulator[-1]}($curRes,$is_selected); } } } @@ -319,15 +360,15 @@ sub new_accumulator { $target.=''.$/; } else { if (defined($target)) { @@ -346,7 +387,7 @@ sub get_selected_symbs { my ($inputfield) = @_; my $field = 'form.'.$inputfield; my @symbs = (map { - &Apache::lonnet::unescape($_); + &unescape($_); } &Apache::loncommon::get_env_multiple($field)); return @symbs; } @@ -373,10 +414,10 @@ Used by Apache::lonstathelpers::ProblemS #################################################### sub make_target_id { my ($target) = @_; - my $id = &Apache::lonnet::escape($target->{'symb'}).':'. - &Apache::lonnet::escape($target->{'part'}).':'. - &Apache::lonnet::escape($target->{'respid'}).':'. - &Apache::lonnet::escape($target->{'resptype'}); + my $id = &escape($target->{'symb'}).':'. + &escape($target->{'part'}).':'. + &escape($target->{'respid'}).':'. + &escape($target->{'resptype'}); return $id; } @@ -401,18 +442,18 @@ sub get_target_from_id { my ($id) = @_; if (! ref($id)) { my ($symb,$part,$respid,$resptype) = split(':',$id); - return ({ symb => &Apache::lonnet::unescape($symb), - part => &Apache::lonnet::unescape($part), - respid => &Apache::lonnet::unescape($respid), - resptype => &Apache::lonnet::unescape($resptype)}); + return ({ symb => &unescape($symb), + part => &unescape($part), + respid => &unescape($respid), + resptype => &unescape($resptype)}); } elsif (ref($id) eq 'ARRAY') { my @Return; foreach my $selected (@$id) { my ($symb,$part,$respid,$resptype) = split(':',$selected); - push(@Return,{ symb => &Apache::lonnet::unescape($symb), - part => &Apache::lonnet::unescape($part), - respid => &Apache::lonnet::unescape($respid), - resptype => &Apache::lonnet::unescape($resptype)}); + push(@Return,{ symb => &unescape($symb), + part => &unescape($part), + respid => &unescape($respid), + resptype => &unescape($resptype)}); } return \@Return; } @@ -733,11 +774,16 @@ sub get_answer { my ($prefix,$key,%Answer) = @_; my $returnvalue; if (exists($Answer{$key})) { - my $student_answer = $Answer{$key}->[0]; - if (! defined($student_answer)) { - $student_answer = $Answer{$key}->[1]; - } - $returnvalue = $student_answer; + if (ref($Answer{$key}) eq 'HASH') { + my $which = 'INTERNAL'; + if (!exists($Answer{$key}{$which})) { + $which = (sort(keys(%{ $Answer{$key} })))[0]; + } + my $student_answer = $Answer{$key}{$which}[0][0]; + $returnvalue = $student_answer; + } else { + &Apache::lonnet::logthis("error analyzing problem. got a answer of type ".ref($Answer{$key})); + } } else { if (exists($Answer{$prefix.'.shown'})) { # The response has foils @@ -795,7 +841,7 @@ sub load_analysis_cache { my $storedstring; my %cache_db; if (tie(%cache_db,'GDBM_File',$cache_filename,&GDBM_READER(),0640)) { - $storedstring = $cache_db{&Apache::lonnet::escape($symb)}; + $storedstring = $cache_db{&escape($symb)}; untie(%cache_db); } if (defined($storedstring)) { @@ -847,7 +893,7 @@ Writes the in memory cache to disk so th sub write_analysis_cache { return if (! defined($current_symb) || ! defined($cache_filename)); my %cache_db; - my $key = &Apache::lonnet::escape($current_symb); + my $key = &escape($current_symb); if (tie(%cache_db,'GDBM_File',$cache_filename,&GDBM_WRCREAT(),0640)) { my $storestring = freeze(\%cache); $cache_db{$key}=$storestring; @@ -1247,7 +1293,7 @@ sub limit_by_time_form { my $enddateform = &Apache::lonhtmlcommon::date_setter ('Statistics','limitby_enddate',$endtime,undef,undef,$state); my $Str; - $Str .= ''. ''.
'. (' 'x2).'view'. + 'href="'.$res->link.'?symb='. + &escape($res->shown_symb).'">'.&mt('view').''. '