--- loncom/interface/lonnavmaps.pm 2004/02/24 16:09:30 1.248
+++ loncom/interface/lonnavmaps.pm 2004/07/26 22:30:15 1.272
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.248 2004/02/24 16:09:30 www Exp $
+# $Id: lonnavmaps.pm,v 1.272 2004/07/26 22:30:15 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -83,6 +83,56 @@ my %colormap =
# is not yet done and due in less then 24 hours
my $hurryUpColor = "#FF0000";
+sub launch_win {
+ my ($mode,$script)=@_;
+ my $result;
+ if ($script ne 'no') {
+ $result.='';
+ }
+ if ($mode eq 'link') {
+ $result.=''
+ .&mt("Launch Navmaps in seperate window")." ";
+ }
+ return $result;
+}
+
+sub close {
+ if ($ENV{'environment.remotenavmap'} ne 'on') { return ''; }
+ return(<
+window.status='Accessing Nav Control';
+menu=window.open("/adm/rat/empty.html","loncapanav",
+ "height=600,width=400,scrollbars=1");
+window.status='Closing Nav Control';
+menu.close();
+window.status='Done.';
+
+ENDCLOSE
+}
+
+sub update {
+ if ($ENV{'environment.remotenavmap'} ne 'on') { return ''; }
+ if (!$ENV{'request.course.id'}) { return ''; }
+ if ($ENV{'REQUEST_URI'}=~m|^/adm/navmaps|) { return ''; }
+ return(<
+
+ENDUPDATE
+}
+
sub handler {
my $r = shift;
real_handler($r);
@@ -111,6 +161,28 @@ sub real_handler {
&Apache::loncommon::no_cache($r);
$r->send_http_header;
+ if ($ENV{QUERY_STRING} eq 'collapseExternal') {
+ &Apache::lonnet::put('environment',{'remotenavmap' => 'off'});
+ &Apache::lonnet::appenv('environment.remotenavmap' => 'off');
+ $r->print(<<"ENDSUBM");
+
+
+
+
+
+
+ENDSUBM
+ return;
+ }
+ if ($ENV{QUERY_STRING} eq 'launchExternal') {
+ &Apache::lonnet::put('environment',{'remotenavmap' => 'on'});
+ &Apache::lonnet::appenv('environment.remotenavmap' => 'on');
+ }
+
# Create the nav map
my $navmap = Apache::lonnavmaps::navmap->new();
@@ -123,22 +195,36 @@ sub real_handler {
$r->print("\n");
$r->print("".&mt('Navigate Course Contents')."");
# ------------------------------------------------------------ Get query string
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register']);
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register','sort']);
# ----------------------------------------------------- Force menu registration
my $addentries='';
+ my $more_unload;
+ if ($ENV{'environment.remotenavmap'} eq 'on') {
+ $r->print('');
+# FIXME need to be smarter to only catch window close events
+# $more_unload="collapse()"
+ }
if ($ENV{'form.register'}) {
- $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
- '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
- $r->print(&Apache::lonmenu::registerurl(1));
+ $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
+ '" onUnload="'.&Apache::lonmenu::unloadevents().';'.
+ $more_unload.'"';
+ $r->print(&Apache::lonmenu::registerurl(1));
+ } else {
+ $addentries=' onUnload="'.$more_unload.'"';
}
# Header
$r->print(''.
&Apache::loncommon::bodytag('Navigate Course Contents','',
$addentries,'','',$ENV{'form.register'}));
- $r->print('');
-
+ $r->print(''.
+ &Apache::loncommon::help_open_menu('','Navigation Screen','Navigation_Screen','',undef,'RAT'));
+
$r->rflush();
# Check that it's defined
@@ -172,6 +258,27 @@ sub real_handler {
}
}
+ if ($ENV{QUERY_STRING} eq 'launchExternal') {
+ $r->print('
+ ');
+ $r->print('
+ ');
+ }
+
+ if ($ENV{'environment.remotenavmap'} ne 'on') {
+ $r->print(&launch_win('link','yes'));
+ }
+ if ($ENV{'environment.remotenavmap'} eq 'on') {
+# $r->print("" .
+ $r->print("" .
+ &mt("Close external navmaps").
+ " ");
+ }
+
my $jumpToFirstHomework = 0;
# Check to see if the student is jumping to next open, do-able problem
if ($ENV{QUERY_STRING} eq 'jumpToFirstHomework') {
@@ -232,8 +339,20 @@ sub real_handler {
&mt("Show Only Uncompleted Homework")." ");
}
+ $r->print("");
# renderer call
- my $renderArgs = { 'cols' => [0,1,2,3],
+ my $renderArgs = { 'cols' => [0,2,3],
+ 'sort' => $ENV{'form.sort'},
'url' => '/adm/navmaps',
'navmap' => $navmap,
'suppressNavmap' => 1,
@@ -297,7 +416,8 @@ sub getLinkForResource {
# in case folder was skipped over as "only sequence"
my ($map,$id,$src)=&Apache::lonnet::decode_symb($res->symb());
if ($map=~/\.page$/) {
- return &Apache::lonnet::clutter($map);
+ return &Apache::lonnet::clutter($map).'#'.
+ &Apache::lonnet::escape(&Apache::lonnet::declutter($src));
}
}
}
@@ -313,9 +433,9 @@ sub getLinkForResource {
return $res->src();
}
-# Convenience function: This seperates the logic of how to create
+# Convenience function: This separates the logic of how to create
# the problem text strings ("Due: DATE", "Open: DATE", "Not yet assigned",
-# etc.) into a seperate function. It takes a resource object as the
+# etc.) into a separate function. It takes a resource object as the
# first parameter, and the part number of the resource as the second.
# It's basically a big switch statement on the status of the resource.
@@ -380,7 +500,7 @@ sub getDescription {
# Convenience function, so others can use it: Is the problem due in less then
# 24 hours, and still can be done?
-sub dueInLessThen24Hours {
+sub dueInLessThan24Hours {
my $res = shift;
my $part = shift;
my $status = $res->status($part);
@@ -863,10 +983,7 @@ sub render_resource {
my $filter = $it->{FILTER};
my $title = $resource->compTitle();
- if ($src =~ /^\/uploaded\//) {
- $nonLinkedText=$title;
- $title = '';
- }
+
my $partLabel = "";
my $newBranchText = "";
@@ -972,9 +1089,12 @@ sub render_resource {
$nonLinkedText .= ' (' . $resource->countParts() . ' parts)';
}
- if (!$params->{'resource_nolink'} && $src !~ /^\/uploaded\// &&
- !$resource->is_sequence()) {
- $result .= " $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText";
+ my $target;
+ if ($ENV{'environment.remotenavmap'} eq 'on') {
+ $target=' target="loncapaclient" ';
+ }
+ if (!$params->{'resource_nolink'} && !$resource->is_sequence() && !$resource->is_empty_sequence) {
+ $result .= " $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText";
} else {
$result .= " $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText";
}
@@ -1010,8 +1130,11 @@ sub render_communication_status {
if ($resource->getErrors()) {
my $errors = $resource->getErrors();
+ my $errorcount = 0;
foreach (split(/,/, $errors)) {
+ last if ($errorcount>=10); # Only output 10 bombs maximum
if ($_) {
+ $errorcount++;
$errorHTML .= ' '
. 'is_problem()) {
$color = $colormap{$resource->status};
- if (dueInLessThen24Hours($resource, $part) ||
+ if (dueInLessThan24Hours($resource, $part) ||
lastTry($resource, $part)) {
$color = $hurryUpColor;
}
@@ -1115,35 +1238,53 @@ my @statuses = ($resObj->CORRECT, $resOb
use Data::Dumper;
sub render_parts_summary_status {
my ($resource, $part, $params) = @_;
- if (!$resource->is_problem()) { return ' | '; }
+ if (!$resource->is_problem() && !$resource->contains_problem) { return ' | '; }
if ($params->{showParts}) {
return ' | ';
}
my $td = "\n";
my $endtd = " | \n";
+ my @probs;
- # If there is a single part, just show the simple status
- if ($resource->singlepart()) {
- my $status = $resource->simpleStatus('0');
- return $td . ""
- . $statusStrings{$status} . "" . $endtd;
- }
-
- # Now we can be sure the $part doesn't really matter.
- my $statusCount = $resource->simpleStatusCount();
- my @counts;
- foreach my $status(@statuses) {
- # decouple display order from the simpleStatusCount order
- my $slot = Apache::lonnavmaps::resource::statusToSlot($status);
- if ($statusCount->[$slot]) {
- push @counts, "" . $statusCount->[$slot] . ' '
+ if ($resource->contains_problem) {
+ @probs=$resource->retrieveResources($resource,sub { $_[0]->is_problem() },1,0);
+ } else {
+ @probs=($resource);
+ }
+ my $return;
+ my %overallstatus;
+ my $totalParts;
+ foreach my $resource (@probs) {
+ # If there is a single part, just show the simple status
+ if ($resource->singlepart()) {
+ my $status = $resource->simpleStatus(${$resource->parts}[0]);
+ $overallstatus{$status}++;
+ $totalParts++;
+ next;
+ }
+ # Now we can be sure the $part doesn't really matter.
+ my $statusCount = $resource->simpleStatusCount();
+ my @counts;
+ foreach my $status (@statuses) {
+ # decouple display order from the simpleStatusCount order
+ my $slot = Apache::lonnavmaps::resource::statusToSlot($status);
+ if ($statusCount->[$slot]) {
+ $overallstatus{$status}+=$statusCount->[$slot];
+ $totalParts+=$statusCount->[$slot];
+ }
+ }
+ }
+ $return.= $td . $totalParts . ' parts: ';
+ foreach my $status (@statuses) {
+ if ($overallstatus{$status}) {
+ $return.="" . $overallstatus{$status} . ' '
. $statusStrings{$status} . "";
}
}
-
- return $td . $resource->countParts() . ' parts: ' . join (', ', @counts) . $endtd;
+ $return.= $endtd;
+ return $return;
}
my @preparedColumns = (\&render_resource, \&render_communication_status,
@@ -1178,6 +1319,7 @@ sub render {
my $jump = $args->{'jump'};
my $here = $args->{'here'};
my $suppressNavmap = setDefault($args->{'suppressNavmap'}, 0);
+ my $closeAllPages = setDefault($args->{'closeAllPages'}, 0);
my $currentJumpDelta = 2; # change this to change how many resources are displayed
# before the current resource when using #current
@@ -1230,7 +1372,10 @@ 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);
@@ -1286,7 +1431,7 @@ sub render {
$args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition);
}
}
-
+
# (re-)Locate the jump point, if any
# Note this does not take filtering or hidden into account... need
# to be fixed?
@@ -1349,9 +1494,43 @@ sub render {
"&here=" . Apache::lonnet::escape($here) .
"\">".&mt('Open All Folders')."";
}
- $result .= "
\n";
- }
+ $result .= "\n";
+ }
+ # Check for any unread discussions in all resources.
+ if (!$args->{'resource_no_folder_link'}) {
+ my $totdisc = 0;
+ my $haveDisc = '';
+ my @allres=$navmap->retrieveResources();
+ foreach my $resource (@allres) {
+ if ($resource->hasDiscussion()) {
+ my $ressymb;
+ if ($resource->symb() =~ m-(___adm/\w+/\w+)/(\d+)/bulletinboard$-) {
+ $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
+ } else {
+ $ressymb = $resource->symb();
+ }
+ $haveDisc .= $ressymb.':';
+ $totdisc ++;
+ }
+ }
+ if ($totdisc > 0) {
+ $haveDisc =~ s/:$//;
+ my %lt = &Apache::lonlocal::texthash(
+ 'mapr' => 'Mark all posts read',
+ );
+ $result .= (<$lt{'mapr'}
+
+END
+ } else {
+ $result .= '
';
+ }
+ }
+ $result .= "
\n";
if ($r) {
$r->print($result);
$r->rflush();
@@ -1423,7 +1602,33 @@ sub render {
$args->{'here'} = $here;
$args->{'indentLevel'} = -1; # first BEGIN_MAP takes this to 0
- while ($curRes = $it->next()) {
+ 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;
+ } elsif ($args->{'sort'} eq 'duedate') {
+ @resources=$navmap->retrieveResources(undef,
+ sub { shift->is_problem(); });
+ @resources= sort
+ {
+ if ($a->duedate ne $b->duedate) {
+ return $a->duedate cmp $b->duedate;
+ } else {
+ lc($a->compTitle) cmp lc($b->compTitle)
+ }
+ } @resources;
+ }
+
+ while (1) {
+ if ($args->{'sort'}) {
+ $curRes = shift(@resources);
+ } else {
+ $curRes = $it->next($closeAllPages);
+ }
+ if (!$curRes) { last; }
+
# Maintain indentation level.
if ($curRes == $it->BEGIN_MAP() ||
$curRes == $it->BEGIN_BRANCH() ) {
@@ -1537,14 +1742,23 @@ sub render {
# Set up some data about the parts that the cols might want
my $filter = $it->{FILTER};
- my $stack = $it->getStack();
- my $src = getLinkForResource($stack);
-
+ my $src;
+ if ($args->{'sort'}) {
+ $src = $curRes->src(); # FIXME this is wrong for .pages
+ } else {
+ my $stack = $it->getStack();
+ $src=getLinkForResource($stack);
+ }
+ my $anchor='';
+ if ($src=~s/(\#.*)$//) {
+ $anchor=$1;
+ }
my $srcHasQuestion = $src =~ /\?/;
$args->{"resourceLink"} = $src.
($srcHasQuestion?'&':'?') .
- 'symb=' . &Apache::lonnet::escape($curRes->symb());
-
+ 'symb=' . &Apache::lonnet::escape($curRes->symb()).
+ $anchor;
+
# Now, display each column.
foreach my $col (@$cols) {
my $colHTML = '';
@@ -1790,6 +2004,7 @@ sub generate_course_user_opt {
sub generate_email_discuss_status {
my $self = shift;
+ my $symb = shift;
if ($self->{EMAIL_DISCUSS_GENERATED}) { return; }
my $cid=$ENV{'request.course.id'};
@@ -1802,6 +2017,15 @@ sub generate_email_discuss_status {
$courseLeaveTime : $logoutTime);
my %discussiontime = &Apache::lonnet::dump('discussiontimes',
$cdom, $cnum);
+ my %lastread = &Apache::lonnet::dump('nohist_'.$cid.'_discuss',
+ $ENV{'user.domain'},$ENV{'user.name'},'lastread');
+ my %lastreadtime = ();
+ foreach (keys %lastread) {
+ my $key = $_;
+ $key =~ s/_lastread$//;
+ $lastreadtime{$key} = $lastread{$_};
+ }
+
my %feedback=();
my %error=();
my $keys = &Apache::lonnet::reply('keys:'.
@@ -1835,6 +2059,7 @@ sub generate_email_discuss_status {
$self->{ERROR_MSG} = \%error; # what is this? JB
$self->{DISCUSSION_TIME} = \%discussiontime;
$self->{EMAIL_STATUS} = \%emailstatus;
+ $self->{LAST_READ} = \%lastreadtime;
$self->{EMAIL_DISCUSS_GENERATED} = 1;
}
@@ -1903,8 +2128,21 @@ sub hasDiscussion {
if (!defined($self->{DISCUSSION_TIME})) { return 0; }
#return defined($self->{DISCUSSION_TIME}->{$symb});
- return $self->{DISCUSSION_TIME}->{$symb} >
- $self->{LAST_CHECK};
+
+# backward compatibility (bulletin boards used to be 'wrapped')
+ my $ressymb = $symb;
+ if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {
+ unless ($ressymb =~ m|adm/wrapper/adm|) {
+ $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
+ }
+ }
+
+ if ( defined ( $self->{LAST_READ}->{$ressymb} ) ) {
+ return $self->{DISCUSSION_TIME}->{$ressymb} > $self->{LAST_READ}->{$ressymb};
+ } else {
+# return $self->{DISCUSSION_TIME}->{$ressymb} > $self->{LAST_CHECK}; # v.1.1 behavior
+ return $self->{DISCUSSION_TIME}->{$ressymb} > 0; # in 1.2 will display speech bubble icons for all items with posts until marked as read (even if read in v 1.1).
+ }
}
# Private method: Does the given resource (as a symb string) have
@@ -2160,7 +2398,7 @@ want to know is if I resources matc
parameter will allow you to avoid potentially expensive enumeration of
all matching resources.
-=item * B(map, filterFunc, recursive):
+=item * B(map, filterFunc, recursive):
Convience method for
@@ -2506,7 +2744,7 @@ sub new {
}
# Check: Was this only one resource, a map?
- if ($resourceCount == 1 && $resource->is_map() && !$self->{FORCE_TOP}) {
+ if ($resourceCount == 1 && $resource->is_sequence() && !$self->{FORCE_TOP}) {
my $firstResource = $resource->map_start();
my $finishResource = $resource->map_finish();
return
@@ -2539,7 +2777,7 @@ sub new {
sub next {
my $self = shift;
-
+ my $closeAllPages=shift;
if ($self->{FINISHED}) {
return END_ITERATOR();
}
@@ -2553,7 +2791,7 @@ sub next {
if ($self->{RECURSIVE_ITERATOR_FLAG}) {
# grab the next from the recursive iterator
- my $next = $self->{RECURSIVE_ITERATOR}->next();
+ my $next = $self->{RECURSIVE_ITERATOR}->next($closeAllPages);
# is it a begin or end map? If so, update the depth
if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
@@ -2667,7 +2905,7 @@ sub next {
# That ends the main iterator logic. Now, do we want to recurse
# down this map (if this resource is a map)?
- if ($self->{HERE}->is_map() &&
+ if ( ($self->{HERE}->is_sequence() || (!$closeAllPages && $self->{HERE}->is_page())) &&
(defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) {
$self->{RECURSIVE_ITERATOR_FLAG} = 1;
my $firstResource = $self->{HERE}->map_start();
@@ -2685,7 +2923,7 @@ sub next {
my $browsePriv = $self->{HERE}->browsePriv();
if (!$self->{HERE}->src() ||
(!($browsePriv eq 'F') && !($browsePriv eq '2')) ) {
- return $self->next();
+ return $self->next($closeAllPages);
}
return $self->{HERE};
@@ -2737,7 +2975,7 @@ package Apache::lonnavmaps::DFSiterator;
# useful for pre-processing of some kind, and is in fact used by the main
# iterator that way, but that's about it.
# One could imagine merging this into the init routine of the main iterator,
-# but this might as well be left seperate, since it is possible some other
+# but this might as well be left separate, since it is possible some other
# use might be found for it. - Jeremy
# Unlike the main iterator, this DOES return all resources, even blank ones.
@@ -3154,6 +3392,15 @@ Returns true if the resource is a sequen
=cut
+sub hasResource {
+ my $self = shift;
+ return $self->{NAV_MAP}->hasResource(@_);
+}
+
+sub retrieveResources {
+ my $self = shift;
+ return $self->{NAV_MAP}->retrieveResources(@_);
+}
sub is_html {
my $self=shift;
@@ -3170,7 +3417,15 @@ sub is_page {
sub is_problem {
my $self=shift;
my $src = $self->src();
- return ($src =~ /problem$/);
+ return ($src =~ /\.(problem|exam|quiz|assess|survey|form|library)$/)
+}
+sub contains_problem {
+ my $self=shift;
+ if ($self->is_page()) {
+ my $hasProblem=$self->hasResource($self,sub { $_[0]->is_problem() },1);
+ return $hasProblem;
+ }
+ return 0;
}
sub is_sequence {
my $self=shift;
@@ -3178,6 +3433,23 @@ sub is_sequence {
return $self->navHash("is_map_", 1) &&
$self->navHash("map_type_" . $self->map_pc()) eq 'sequence';
}
+sub is_survey {
+ my $self = shift();
+ my $part = shift();
+ if ($self->parmval('type',$part) eq 'survey') {
+ return 1;
+ }
+ if ($self->src() =~ /\.(survey)$/) {
+ return 1;
+ }
+ return 0;
+}
+
+sub is_empty_sequence {
+ my $self=shift;
+ my $src = $self->src();
+ return !$self->is_page() && $self->navHash("is_map_", 1) && !$self->navHash("map_type_" . $self->map_pc());
+}
# Private method: Shells out to the parmval in the nav map, handler parts.
sub parmval {
@@ -3354,6 +3626,11 @@ sub awarded {
}
sub duedate {
(my $self, my $part) = @_;
+ my $interval=$self->parmval("interval", $part);
+ if ($interval) {
+ my $first_access=&Apache::lonnet::get_first_access('map',$self->symb);
+ if ($first_access) { return ($first_access+$interval); }
+ }
return $self->parmval("duedate", $part);
}
sub maxtries {
@@ -3654,6 +3931,20 @@ sub extractParts {
}
}
}
+ my $resorder = &Apache::lonnet::metadata($self->src(),'responseorder');
+ if ($resorder) {
+ my @resorder=split(/,/,$resorder);
+ foreach my $part (keys(%responseIdHash)) {
+ my %resids = map { ($_,1) } @{ $responseIdHash{$part} };
+ my @neworder;
+ foreach my $possibleid (@resorder) {
+ if (exists($resids{$possibleid})) {
+ push(@neworder,$possibleid);
+ }
+ }
+ $responseIdHash{$part}=\@neworder;
+ }
+ }
$self->{RESPONSE_IDS} = \%responseIdHash;
$self->{RESPONSE_TYPES} = \%responseTypeHash;
}
@@ -3845,7 +4136,7 @@ sub getCompletionStatus {
my $status = $self->queryRestoreHash('solved', shift);
- # Left as seperate if statements in case we ever do more with this
+ # 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_override') {return $self->CORRECT_BY_OVERRIDE; }
if ($status eq 'incorrect_attempted') {return $self->INCORRECT; }
@@ -3997,7 +4288,7 @@ sub status {
if ($dateStatus == PAST_DUE_ANSWER_LATER ||
$dateStatus == PAST_DUE_NO_ANSWER ) {
- return $dateStatus;
+ return $suppressFeedback ? ANSWER_SUBMITTED : $dateStatus;
}
if ($dateStatus == ANSWER_OPEN) {