--- loncom/interface/lonwhatsnew.pm 2005/12/06 16:37:28 1.36 +++ loncom/interface/lonwhatsnew.pm 2005/12/22 22:39:49 1.38.2.2 @@ -1,5 +1,5 @@ # -# $Id: lonwhatsnew.pm,v 1.36 2005/12/06 16:37:28 raeburn Exp $ +# $Id: lonwhatsnew.pm,v 1.38.2.2 2005/12/22 22:39:49 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -109,7 +109,9 @@ sub handler { sub display_main_box { my ($r,$command,$checkallowed) = @_; my $domain=&Apache::loncommon::determinedomain(); - my $tabbg=&Apache::loncommon::designparm('coordinator.tabbg',$domain); + my $function = &Apache::loncommon::get_users_function(); + my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain); + $r->print(''); + ''); + if ($countunread) { + $r->print(''. + ''); + } else { + $r->print(''); + } + $r->print("\n"); @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) } @{$newdiscussions}; my $rowNum = 0; @@ -1095,17 +1133,23 @@ sub display_coursediscussion { if ($feedurl =~ /bulletinboard/) { $type = 'Bulletin Board'; } - my $unreadnum = keys(%{$$unread{$ressymb}}); - $unreadnum = $unreadnum - 2; - if ($unreadnum > 0) { - if ($rowNum %2 == 1) { - $rowColor = $rowColor1; - } else { - $rowColor = $rowColor2; - } - $r->print(''); - $rowNum ++; + if ($rowNum %2 == 1) { + $rowColor = $rowColor1; + } else { + $rowColor = $rowColor2; } + my $lastpost = &Apache::lonnavmaps::timeToHumanString( + $$unread{$ressymb}{'lastpost'}); + $r->print(''); + if ($countunread) { + my $unreadnum = $$unread{$ressymb}{'unreadcount'}; + $r->print(''); + } else { + $r->print(''); + } + $r->print("\n"); + $rowNum ++; } } else { $r->print('
'); my %threshold_titles = ( @@ -136,8 +138,8 @@ sub display_main_box { (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) { &display_interval_config($r,\%interval_titles); } else { - &display_actions_box($r,$command,\%threshold_titles,\%interval_titles, - $cdom,$crs,$checkallowed); + &display_actions_box($r,$tabbg,$command,\%threshold_titles, + \%interval_titles,$cdom,$crs,$checkallowed); } $r->print(< @@ -171,7 +173,10 @@ function change_display(caller,change) { function changeAll(change) { END foreach my $item (keys(%{$checkallowed})) { - $scripttag.='document.visible.display_'.$item.'.value=change'."\n"; + if ($$checkallowed{$item}) { + $scripttag.='document.visible.display_'.$item.'.value=change'. + "\n"; + } } $scripttag.='document.visible.submit(); } @@ -196,8 +201,9 @@ ENDHEAD #------------------------------- sub display_actions_box() { - my ($r,$command,$threshold_titles,$interval_titles,$cdom,$crs, - $checkallowed) = @_; + my ($r,$tabbg,$command,$threshold_titles,$interval_titles, + $cdom,$crs,$checkallowed) = @_; + my $rowColor1 = "#ffffff"; my $rowColor2 = "#eeeeee"; @@ -234,24 +240,12 @@ sub display_actions_box() { my $needitems = 0; my $boxcount = 0; - my $domain=&Apache::loncommon::determinedomain(); - my $function; - if ($env{'request.role'}=~/^(cc|in|ta|ep)/) { - $function='coordinator'; - } - if ($env{'request.role'}=~/^(su|dc|ad|li)/) { - $function='admin'; - } - my %threshold = ( av_attempts => 2, degdiff => 0.5, numstudents => 2, ); - my $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain); - my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain); - unless ($cid) { $r->print('
'.$lt{'yacc'}.'


'); return; @@ -300,13 +294,14 @@ sub display_actions_box() { $timediff = time; } my $starttime = $now - $timediff; + my $countunread = 1; my %headings = &Apache::lonlocal::texthash( coursediscussion => 'Unread course discussion posts', handgrading => 'Problems requiring handgrading', haserrors => 'Problems with errors', versionchanges => 'Resources in course with version changes '.$interval, - coursenormalmail => 'New course message', + coursenormalmail => 'New course messages', coursecritmail => 'New critical messages in course', ); @@ -337,7 +332,7 @@ sub display_actions_box() { } if ($needitems) { - &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime); + &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread); } if ($show{'coursenormalmail'}) { &getnormalmail(\@newmsgs); @@ -365,7 +360,7 @@ sub display_actions_box() { if ($displayed == $halfway) { $r->print('
 '); } - &display_launcher($r,$actionitem,$checkallowed,$tabbg,$rowColor1,$rowColor2,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,$interval); + &display_launcher($r,$actionitem,$checkallowed,$tabbg,$rowColor1,$rowColor2,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,$interval,$countunread); $displayed ++; } } @@ -481,7 +476,7 @@ sub display_launcher { my ($r,$action,$checkallowed,$tabbg,$rowColor1,$rowColor2,$show, $headings,$res_title,$tograde,$ungraded,$bombs,$bombed,$changed, $warnings,$triggered,$newdiscussions,$unread,$msgcount,$newmsgs, - $critmsgcount,$critmsgs,$interval) = @_; + $critmsgcount,$critmsgs,$interval,$countunread) = @_; if ($$checkallowed{$action}) { &start_box($r,$tabbg,$show,$headings,$action); @@ -501,7 +496,7 @@ sub display_launcher { $rowColor1,$rowColor2); } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION &display_coursediscussion($r,$newdiscussions,$unread, - $res_title,$rowColor1,$rowColor2); + $countunread,$res_title,$rowColor1,$rowColor2); } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES &display_coursenormalmail($r,$msgcount,$newmsgs,$rowColor1, $rowColor2); @@ -518,19 +513,21 @@ sub display_launcher { sub getitems { my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions, $tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs, - $res_title,$show,$starttime) = @_; + $res_title,$show,$starttime,$countunread) = @_; my $navmap = Apache::lonnavmaps::navmap->new(); # force retrieve Resource to seed the part id cache we'll need it later - my @allres=$navmap->retrieveResources(undef,sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;}); + my @allres=$navmap->retrieveResources(undef, + sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;}); my %lastreadtime; my %resourcetracker; + my $discussiontime; # Resource version changes if ($$show{'versionchanges'}) { &checkversions($cdom,$crs,$navmap,$changed,$starttime); } - if ($$show{'coursediscussions'}) { + if ($$show{'coursediscussion'}) { my %lastread = &Apache::lonnet::dump('nohist_'. $env{'request.course.id'}.'_discuss', $env{'user.domain'},$env{'user.name'},'lastread'); @@ -559,10 +556,10 @@ sub getitems { $$res_title{$symb} = $title; my $ressymb = $resource->wrap_symb(); -# Check for unread discussion postings +# Check if there are unread discussion postings if ($$show{'coursediscussion'}) { &check_discussions($cdom,$crs,$resource,$symb,$ressymb,$title, - $newdiscussions,$unread,\%lastreadtime); + $newdiscussions,$unread); } # Check for ungraded problems @@ -585,38 +582,73 @@ sub getitems { } } + my $hasdiscussion = @{$newdiscussions}; + if ($$show{'coursediscussion'} && $hasdiscussion) { # Get time of last post; + $discussiontime = $navmap->{DISCUSSION_TIME}; + foreach my $ressymb (@{$newdiscussions}) { + $$unread{$ressymb}{'lastpost'} = $$discussiontime{$ressymb}; + } + if ($countunread) { #Get count of unread postings for each resource + my $discussiondata = $navmap->get_discussion_data(); + foreach my $ressymb (@{$newdiscussions}) { + &get_discussions($cdom,$crs,$discussiondata,$ressymb, + $unread,\%lastreadtime); + } + } + } } sub check_discussions { - my ($cdom,$crs,$resource,$symb,$ressymb,$title,$newdiscussions,$unread, - $lastreadtime) = @_; -# Check for unread discussion postings + my ($cdom,$crs,$resource,$symb,$ressymb,$title,$newdiscussions, + $unread) = @_; if ($resource->hasDiscussion()) { - my $prevread = 0; - my $unreadcount = 0; %{$$unread{$ressymb}} = (); $$unread{$ressymb}{'title'} = $title; $$unread{$ressymb}{'symb'} = $symb; - if (defined($$lastreadtime{$ressymb})) { - $prevread = $$lastreadtime{$ressymb}; - } - my %contrib = &Apache::lonnet::restore($ressymb, - $env{'request.course.id'},$cdom,$crs); - if ($contrib{'version'}) { - for (my $id=1;$id<=$contrib{'version'};$id++) { - unless (($contrib{'hidden'}=~/\.$id\./) || - ($contrib{'deleted'}=~/\.$id\./)) { - if ($prevread <$contrib{$id.':timestamp'}) { - $$unread{$ressymb}{$unreadcount} = $id.': '.$contrib{$id.':subject'}; + push(@{$newdiscussions}, $ressymb); + } +} + +sub get_discussions { + my ($cdom,$crs,$discussiondata,$ressymb,$unread,$lastreadtime) = @_; + my $prevread = 0; + my $unreadcount = 0; + if (defined($$lastreadtime{$ressymb})) { + $prevread = $$lastreadtime{$ressymb}; + } + my $version = $$discussiondata{'version:'.$ressymb}; + if ($version) { + my $hiddenflag = 0; + my $deletedflag = 0; + my ($hidden,$deleted); + for (my $id=$version; $id>0; $id--) { + my $vkeys=$$discussiondata{$id.':keys:'.$ressymb}; + my @keys=split(/:/,$vkeys); + if (grep/^hidden$/,@keys) { + unless ($hiddenflag) { + $hidden = $$discussiondata{$id.':'.$ressymb.':hidden'}; + $hiddenflag = 1; + } + } elsif (grep/^deleted$/,@keys) { + unless ($deletedflag) { + $deleted = $$discussiondata{$id.':'.$ressymb.':deleted'}; + $deletedflag = 1; + } + } else { + unless (($hidden =~/\.$id\./) || ($deleted =~/\.$id\./)) { + if ($prevread <$$discussiondata{$id.':'.$ressymb.':timestamp'}) { $unreadcount ++; + $$unread{$ressymb}{$unreadcount} = $id.': '. + $$discussiondata{$id.':'.$ressymb.':subject'}; } } } } - if ($unreadcount) { push(@{$newdiscussions}, $ressymb); } + $$unread{$ressymb}{'unreadcount'} = $unreadcount; } } + sub check_handgraded { my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_; if ($resource->is_problem()) { @@ -756,9 +788,8 @@ sub get_curr_interval { my $interval; my %settings = &Apache::lonnet::dump('nohist_whatsnew',$uname,$udom,$cid,':interval'); my ($tmp) = %settings; - if ($tmp =~ /^Error/) { - &logthis(); - } else { + + unless ($tmp =~ /^(con_lost|error|no_such_host)/i) { $interval = $settings{$cid.':interval'}; } return $interval; @@ -899,11 +930,8 @@ sub checkversions { my ($cdom,$crs,$navmap,$changed,$starttime) = @_; my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs); my ($tmp) = keys(%changes); - if ($tmp =~/^error\:/) { - &Apache::lonnet::logthis('Error retrieving version update information: '. - $tmp.' for '.$cdom.'_'.$crs.' in whatsnew'); - } else { - if (keys(%changes) > 0) { + unless ($tmp =~ /^(con_lost|error|no_such_host)/i) { + if (keys(%changes) > 0) { foreach my $key (sort(keys(%changes))) { if ($changes{$key} > $starttime) { my $version; @@ -1072,19 +1100,29 @@ sub display_versionchanges { } sub display_coursediscussion { - my ($r,$newdiscussions,$unread,$res_title,$rowColor1,$rowColor2) = @_; + my ($r,$newdiscussions,$unread,$countunread,$res_title,$rowColor1, + $rowColor2) = @_; my %lt = &Apache::lonlocal::texthash( 'loca' => 'Location', 'type' => 'Type', 'numn' => 'Number of new posts', 'noun' => 'No unread posts in course discussions', + 'tmlp' => 'Time of last post', ); my $rowColor; if (@{$newdiscussions} > 0) { $r->print('
'.$lt{'loca'}. ''.$lt{'type'}. - ''.$lt{'numn'}. - '
'.$lt{'tmlp'}.''.$lt{'numn'}. + ''.$lt{'tmlp'}. + '
'.$forum_title.' '.$type.''.$unreadnum.' 
'.$forum_title.' '.$type.' '.$lastpost.''. + '',$unreadnum.' '.$lastpost.'

 '. @@ -1169,12 +1213,14 @@ sub get_display_settings { my ($uname,$udom,$cid) = @_; my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid); my ($tmp) = keys(%settings); - if ($tmp=~/^error:/) { + if ($tmp=~/^(con_lost|error|no_such_host)/i) { %settings = (); - unless ($tmp eq 'error: 2 tie(GDBM) Failed while attempting dump') { - &logthis('Error retrieving whatsnew settings: '.$tmp.' for '. - $uname.':'.$udom.' for course: '.$cid); - } + unless ($tmp =~ /^error: 2 /) { + &Apache::lonnet::logthis('Error retrieving whatsnew settings: '. + $tmp.' for '.$uname.':'.$udom. + ' for course: '.$cid); + + } } return %settings; }