--- loncom/interface/lonnavmaps.pm 2004/07/27 23:35:34 1.273 +++ loncom/interface/lonnavmaps.pm 2004/09/21 19:12:59 1.295 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.273 2004/07/27 23:35:34 www Exp $ +# $Id: lonnavmaps.pm,v 1.295 2004/09/21 19:12:59 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -84,7 +84,7 @@ my %colormap = my $hurryUpColor = "#FF0000"; sub launch_win { - my ($mode,$script)=@_; + my ($mode,$script,$toplinkitems)=@_; my $result; if ($script ne 'no') { $result.=''; } if ($mode eq 'link') { - $result.='' - .&mt("Launch navigation in separate window")." "; + &add_linkitem($toplinkitems,'launchnav','launch_navmapwin()', + "Launch navigation window"); } return $result; } @@ -119,6 +119,23 @@ window.status='Done.'; ENDCLOSE } +sub nav_control_js { + my $nav=($ENV{'environment.remotenavmap'} eq 'on'); + return (<send_http_header; + my %toplinkitems=(); + if ($ENV{QUERY_STRING} eq 'collapseExternal') { &Apache::lonnet::put('environment',{'remotenavmap' => 'off'}); &Apache::lonnet::appenv('environment.remotenavmap' => 'off'); + my $menu=&Apache::lonmenu::reopenmenu(); + my $navstatus=&Apache::lonmenu::get_nav_status(); + if ($menu) { + $menu=(<print(<<"ENDSUBM"); @@ -195,11 +232,12 @@ ENDSUBM $r->print("\n"); $r->print("".&mt('Navigate Course Contents').""); # ------------------------------------------------------------ Get query string - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register','sort']); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register','sort','showOnlyHomework']); # ----------------------------------------------------- Force menu registration my $addentries=''; my $more_unload; + my $body_only=''; if ($ENV{'environment.remotenavmap'} eq 'on') { $r->print(''); # FIXME need to be smarter to only catch window close events # $more_unload="collapse()" + $body_only=1; } if ($ENV{'form.register'}) { $addentries=' onLoad="'.&Apache::lonmenu::loadevents(). @@ -221,14 +260,15 @@ ENDSUBM # Header $r->print(''. &Apache::loncommon::bodytag('Navigate Course Contents','', - $addentries,'','',$ENV{'form.register'})); - $r->print(''. - &Apache::loncommon::help_open_menu('','Navigation Screen','Navigation_Screen','',undef,'RAT')); + $addentries,$body_only,'', + $ENV{'form.register'})); + $r->print(''); $r->rflush(); # Check that it's defined if (!($navmap->courseMapDefined())) { + $r->print(&Apache::loncommon::help_open_menu('','Navigation Screen','Navigation_Screen','',undef,'RAT')); $r->print('Coursemap undefined.' . ''); return OK; @@ -270,18 +310,16 @@ ENDSUBM } if ($ENV{'environment.remotenavmap'} ne 'on') { - $r->print(&launch_win('link','yes')); + $r->print(&launch_win('link','yes',\%toplinkitems)); } if ($ENV{'environment.remotenavmap'} eq 'on') { -# $r->print("" . - $r->print("" . - &mt("Close separate navigation window"). - "    "); + &add_linkitem(\%toplinkitems,'closenav','collapse()', + "Close navigation window"); } my $jumpToFirstHomework = 0; # Check to see if the student is jumping to next open, do-able problem - if ($ENV{QUERY_STRING} eq 'jumpToFirstHomework') { + if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) { $jumpToFirstHomework = 1; # Find the next homework problem that they can do. my $iterator = $navmap->getIterator(undef, undef, undef, 1); @@ -314,8 +352,9 @@ ENDSUBM $r->print("All homework assignments have been completed.

"); } } else { - $r->print("" . - &mt("Go To My First Homework Problem")."    "); + &add_linkitem(\%toplinkitems,'firsthomework', + 'location.href="navmaps?jumpToFirstHomework"', + "Show Me My First Homework Problem"); } my $suppressEmptySequences = 0; @@ -324,34 +363,40 @@ ENDSUBM # Display only due homework. my $showOnlyHomework = 0; - if ($ENV{QUERY_STRING} eq 'showOnlyHomework') { + if ($ENV{'form.showOnlyHomework'} eq "1") { $showOnlyHomework = 1; $suppressEmptySequences = 1; $filterFunc = sub { my $res = shift; return $res->completable() || $res->is_map(); }; + &add_linkitem(\%toplinkitems,'everything', + 'location.href="locatnavmaps?sort='.$ENV{'form.sort'}.'"', + "Show Everything"); $r->print("

".&mt("Uncompleted Homework")."

"); $ENV{'form.filter'} = ''; $ENV{'form.condition'} = 1; $resource_no_folder_link = 1; } else { - $r->print("" . - &mt("Show Only Uncompleted Homework")."    "); + &add_linkitem(\%toplinkitems,'uncompleted', + 'location.href="navmaps?sort='.$ENV{'form.sort'}. + '&showOnlyHomework=1"', + "Show Only Uncompleted Homework"); } - $r->print("
+ my %selected=($ENV{'form.sort'} => 'selected=on'); + my $sort_html=(" - Sort by: + + -
"); # renderer call - my $renderArgs = { 'cols' => [0,2,3], + my $renderArgs = { 'cols' => [0,1,2,3], 'sort' => $ENV{'form.sort'}, 'url' => '/adm/navmaps', 'navmap' => $navmap, @@ -359,7 +404,10 @@ ENDSUBM 'suppressEmptySequences' => $suppressEmptySequences, 'filterFunc' => $filterFunc, 'resource_no_folder_link' => $resource_no_folder_link, - 'r' => $r}; + 'sort_html'=> $sort_html, + 'r' => $r, + 'caller' => 'navmapsdisplay', + 'linkitems' => \%toplinkitems}; my $render = render($renderArgs); $navmap->untieHashes(); @@ -631,7 +679,7 @@ sub timeToHumanString { } # Not this year, so show the year - my $timeStr = strftime("on %A, %b %e %G at %I:%M %P", localtime($time)); + my $timeStr = strftime("on %A, %b %e %Y at %I:%M %P", localtime($time)); $timeStr =~ s/12:00 am/00:00/; $timeStr =~ s/12:00 pm/noon/; return $timeStr; @@ -1077,9 +1125,7 @@ sub render_resource { if ($resource->is_problem() && $part ne '0' && !$params->{'condensed'}) { - my $displaypart=&Apache::lonnet::EXT('resource.'.$part.'.display', - $resource->symb()); - unless ($displaypart) { $displaypart=$part; } + my $displaypart=$resource->part_display($part); $partLabel = " (Part: $displaypart)"; $link.='#'.&Apache::lonnet::escape($part); $title = ""; @@ -1372,10 +1418,7 @@ sub render { #$currenturl=~s/^[^\/]+//; $here = $jump = &Apache::lonnet::symbread($currenturl); - } else { - &Apache::lonnet::logthis("Hrrm,"); - - } + } # Step three: Ensure the folders are open my $mapIterator = $navmap->getIterator(undef, undef, undef, 1); @@ -1385,7 +1428,7 @@ sub render { # We only need to do this if we need to open the maps to show the # current position. This will change the counter so we can't count # for the jump marker with this loop. - while (($curRes = $mapIterator->next()) && !$found) { + while ($here && ($curRes = $mapIterator->next()) && !$found) { if (ref($curRes) && $curRes->symb() eq $here) { my $mapStack = $mapIterator->getStack(); @@ -1485,20 +1528,27 @@ sub render { } if ($printCloseAll && !$args->{'resource_no_folder_link'}) { + my ($link,$text); if ($condition) { - $result.="".&mt('Close All Folders').""; + $link='"navmaps?condition=0&filter=&'.$queryString. + '&here='.&Apache::lonnet::escape($here).'"'; + $text='Close All Folders'; } else { - $result.="".&mt('Open All Folders').""; - } + $link='"navmaps?condition=1&filter=&'.$queryString. + '&here='.&Apache::lonnet::escape($here).'"'; + $text='Open All Folders'; + } + if ($args->{'caller'} eq 'navmapsdisplay') { + &add_linkitem($args->{'linkitems'},'changefolder', + 'location.href='.$link,$text); + } else { + $result.=''.&mt($text).''; + } $result .= "\n"; } # Check for any unread discussions in all resources. - if (!$args->{'resource_no_folder_link'}) { + if ($args->{'caller'} eq 'navmapsdisplay') { my $totdisc = 0; my $haveDisc = ''; my @allres=$navmap->retrieveResources(); @@ -1516,20 +1566,42 @@ sub render { } if ($totdisc > 0) { $haveDisc =~ s/:$//; - my %lt = &Apache::lonlocal::texthash( - 'mapr' => 'Mark all posts read', - ); - $result .= (<$lt{'mapr'} (Help: NavMaps_MarkPostsLink) + my $navurl = $ENV{'QUERY_STRING'}; + &add_linkitem($args->{'linkitems'},'clearbubbles', + 'document.clearbubbles.submit()', + 'Mark all posts read'); + $result .= (< END + } + } + + if ($args->{'caller'} eq 'navmapsdisplay') { + $result .= ''; + if ($ENV{'environment.remotenavmap'} ne 'on') { + $result .= ''; } else { - $result .= '
'; + $result .= ''; + } + $result.=&show_linkitems($args->{'linkitems'}); + if ($args->{'sort_html'}) { + if ($ENV{'environment.remotenavmap'} ne 'on') { + $result.=''. + ''; + } else { + $result.=''; + } } + $result .= '
'. + &Apache::loncommon::help_open_menu('','Navigation Screen','Navigation_Screen','',undef,'RAT').' 
   '.$args->{'sort_html'}.'

'. + $args->{'sort_html'}.'
'; + } elsif ($args->{'sort_html'}) { + $result.=$args->{'sort_html'}; } + $result .= "
\n"; if ($r) { $r->print($result); @@ -1605,9 +1677,20 @@ END my @resources; my $code='';# sub { !(shift->is_map();) }; if ($args->{'sort'} eq 'title') { - @resources=$navmap->retrieveResources(undef, - sub { !shift->is_map(); }); - @resources= sort {lc($a->compTitle) cmp lc($b->compTitle)} @resources; + my $oldFilterFunc = $filterFunc; + my $filterFunc= + sub { + my ($res)=@_; + if ($res->is_map()) { return 0;} + return &$oldFilterFunc($res); + }; + @resources=$navmap->retrieveResources(undef,$filterFunc); + @resources= sort { + my ($atitle,$btitle) = (lc($a->compTitle),lc($b->compTitle)); + $atitle=~s/^\s*//; + $btitle=~s/^\s*//; + return $atitle cmp $btitle + } @resources; } elsif ($args->{'sort'} eq 'duedate') { @resources=$navmap->retrieveResources(undef, sub { shift->is_problem(); }); @@ -1619,8 +1702,12 @@ END lc($a->compTitle) cmp lc($b->compTitle) } } @resources; + } else { + #unknow sort mechanism or default + undef($args->{'sort'}); } + while (1) { if ($args->{'sort'}) { $curRes = shift(@resources); @@ -1829,6 +1916,45 @@ if (location.href.indexOf('#curloc')==-1 return $result; } +sub add_linkitem { + my ($linkitems,$name,$cmd,$text)=@_; + $$linkitems{$name}{'cmd'}=$cmd; + $$linkitems{$name}{'text'}=&mt($text); +} + +sub show_linkitems { + my ($linkitems)=@_; + my @linkorder = ("launchnav","closenav","firsthomework","everything", + "uncompleted","changefolder","clearbubbles"); + + my $result .= (< + +
+   +
'."\n"; + return $result; +} + 1; package Apache::lonnavmaps::navmap; @@ -2035,17 +2161,11 @@ sub generate_email_discuss_status { foreach my $msgid (split(/\&/, $keys)) { $msgid=&Apache::lonnet::unescape($msgid); - my $plain=&Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid)); - if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) { - my ($what,$url)=($1,$2); - my %status= - &Apache::lonnet::get('email_status',[$msgid]); - if ($status{$msgid}=~/^error\:/) { - $status{$msgid}=''; - } - - if (($status{$msgid} eq 'new') || - (!$status{$msgid})) { + if ((!$emailstatus{$msgid}) || ($emailstatus{$msgid} eq 'new')) { + my $plain= + &Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid)); + if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) { + my ($what,$url)=($1,$2); if ($what eq 'Error') { $error{$url}.=','.$msgid; } else { @@ -2055,8 +2175,10 @@ sub generate_email_discuss_status { } } + #url's of resources that have feedbacks $self->{FEEDBACK} = \%feedback; - $self->{ERROR_MSG} = \%error; # what is this? JB + #or errors + $self->{ERROR_MSG} = \%error; $self->{DISCUSSION_TIME} = \%discussiontime; $self->{EMAIL_STATUS} = \%emailstatus; $self->{LAST_READ} = \%lastreadtime; @@ -2213,9 +2335,14 @@ sub getById { sub getBySymb { my $self = shift; my $symb = shift; + my ($mapUrl, $id, $filename) = &Apache::lonnet::decode_symb($symb); my $map = $self->getResourceByUrl($mapUrl); - return $self->getById($map->map_pc() . '.' . $id); + my $returnvalue = undef; + if (ref($map)) { + $returnvalue = $self->getById($map->map_pc() .'.'.$id); + } + return $returnvalue; } sub getByMapPc { @@ -2409,6 +2536,7 @@ in the filter function. =cut + sub getResourceByUrl { my $self = shift; my $resUrl = shift; @@ -3674,7 +3802,16 @@ sub weight { $self->symb(), $ENV{'user.domain'}, $ENV{'user.name'}, $ENV{'request.course.sec'}); - +} +sub part_display { + my $self= shift(); my $partID = shift(); + if (! defined($partID)) { $partID = '0'; } + my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display', + $self->symb); + if (! defined($display) || $display eq '') { + $display = $partID; + } + return $display; } # Multiple things need this @@ -3764,6 +3901,16 @@ Returns the number of parts of the probl for single part problems, returns 1. For multipart, it returns the number of parts in the problem, not including psuedo-part 0. +=item * B(): + +Returns the total number of responses in the problem a student can answer. + +=item * B(): + +Returns a hash whose keys are the response types. The values are the number +of times each response type is used. This is for the I problem, not +just a single part. + =item * B(): Returns true if the problem is multipart, false otherwise. Use this instead @@ -3810,6 +3957,26 @@ sub countParts { return scalar(@{$parts}); # + $delta; } +sub countResponses { + my $self = shift; + my $count; + foreach my $part (@{$self->parts()}) { + $count+= scalar($self->responseIds($part)); + } + return $count; +} + +sub responseTypes { + my $self = shift; + my %responses; + foreach my $part ($self->parts()) { + foreach my $responsetype ($self->responseType($part)) { + $responses{$responsetype}++ if (defined($responsetype)); + } + } + return %responses; +} + sub multipart { my $self = shift; return $self->countParts() > 1; @@ -3897,6 +4064,7 @@ sub extractParts { } + # These hashes probably do not need names that end with "Hash".... my %responseIdHash; my %responseTypeHash; @@ -3932,17 +4100,27 @@ sub extractParts { } } my $resorder = &Apache::lonnet::metadata($self->src(),'responseorder'); + # + # Reorder the arrays in the %responseIdHash and %responseTypeHash if ($resorder) { my @resorder=split(/,/,$resorder); foreach my $part (keys(%responseIdHash)) { - my %resids = map { ($_,1) } @{ $responseIdHash{$part} }; + my $i=0; + my %resids = map { ($_,$i++) } @{ $responseIdHash{$part} }; my @neworder; foreach my $possibleid (@resorder) { if (exists($resids{$possibleid})) { - push(@neworder,$possibleid); + push(@neworder,$resids{$possibleid}); } } - $responseIdHash{$part}=\@neworder; + my @ids; + my @type; + foreach my $element (@neworder) { + push (@ids,$responseIdHash{$part}->[$element]); + push (@type,$responseTypeHash{$part}->[$element]); + } + $responseIdHash{$part}=\@ids; + $responseTypeHash{$part}=\@type; } } $self->{RESPONSE_IDS} = \%responseIdHash; @@ -4138,6 +4316,7 @@ sub getCompletionStatus { # Left as separate if statements in case we ever do more with this if ($status eq 'correct_by_student') {return $self->CORRECT;} + if ($status eq 'correct_by_scantron') {return $self->CORRECT;} if ($status eq 'correct_by_override') {return $self->CORRECT_BY_OVERRIDE; } if ($status eq 'incorrect_attempted') {return $self->INCORRECT; } if ($status eq 'incorrect_by_override') {return $self->INCORRECT_BY_OVERRIDE; }