--- loncom/interface/lonnavmaps.pm 2004/08/20 20:14:27 1.277 +++ loncom/interface/lonnavmaps.pm 2004/09/15 21:10:11 1.290 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.277 2004/08/20 20:14:27 matthew Exp $ +# $Id: lonnavmaps.pm,v 1.290 2004/09/15 21:10:11 matthew 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 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'); @@ -172,6 +191,13 @@ sub real_handler { swmenu.clearTimeout(swmenu.menucltim); $navstatus MENU + } else { + my $nothing = &Apache::lonhtmlcommon::javascript_nothing(); + my $mainwindow='window.open('.$nothing.',"loncapaclient","",false);'; + $menu=(<print(<<"ENDSUBM"); @@ -211,6 +237,7 @@ ENDSUBM # ----------------------------------------------------- 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(). @@ -232,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; @@ -281,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 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); @@ -325,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; @@ -341,15 +369,18 @@ ENDSUBM $filterFunc = sub { my $res = shift; return $res->completable() || $res->is_map(); }; - $r->print("" . - &mt("Show Everything")."    "); + &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"); } my %selected=($ENV{'form.sort'} => 'selected=on'); @@ -365,7 +396,7 @@ ENDSUBM "); # renderer call - my $renderArgs = { 'cols' => [0,2,3], + my $renderArgs = { 'cols' => [0,1,2,3], 'sort' => $ENV{'form.sort'}, 'url' => '/adm/navmaps', 'navmap' => $navmap, @@ -374,7 +405,9 @@ ENDSUBM 'filterFunc' => $filterFunc, 'resource_no_folder_link' => $resource_no_folder_link, 'sort_html'=> $sort_html, - 'r' => $r}; + 'r' => $r, + 'caller' => 'navmapsdisplay', + 'linkitems' => \%toplinkitems}; my $render = render($renderArgs); $navmap->untieHashes(); @@ -646,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; @@ -1495,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(); @@ -1526,22 +1566,41 @@ 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 - } else { - $result .= '
'; } } - if ($args->{'sort_html'}) { $result.=$args->{'sort_html'}; } + if ($args->{'caller'} eq 'navmapsdisplay') { + $result .= ''; + if ($ENV{'environment.remotenavmap'} ne 'on') { + $result .= ''; + } else { + $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) { @@ -1626,7 +1685,12 @@ END return &$oldFilterFunc($res); }; @resources=$navmap->retrieveResources(undef,$filterFunc); - @resources= sort {lc($a->compTitle) cmp lc($b->compTitle)} @resources; + @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(); }); @@ -1852,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; @@ -3802,6 +3905,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 @@ -3848,6 +3961,26 @@ sub countParts { return scalar(@{$parts}); # + $delta; } +sub countResponses { + my $self = shift; + my $count; + foreach my $part ($self->parts()) { + $count+= $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; @@ -3935,6 +4068,7 @@ sub extractParts { } + # These hashes probably do not need names that end with "Hash".... my %responseIdHash; my %responseTypeHash; @@ -3970,17 +4104,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; @@ -4176,6 +4320,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; } 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.