--- loncom/interface/lonwhatsnew.pm 2005/12/02 23:17:47 1.33 +++ loncom/interface/lonwhatsnew.pm 2005/12/06 16:37:28 1.36 @@ -1,5 +1,5 @@ # -# $Id: lonwhatsnew.pm,v 1.33 2005/12/02 23:17:47 raeburn Exp $ +# $Id: lonwhatsnew.pm,v 1.36 2005/12/06 16:37:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -54,39 +54,49 @@ sub handler { } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['command']); - my $command; - if ($env{'form.action'} eq 'reset') { - $command = 'reset'; - } elsif ($env{'form.action'} eq 'update') { - $command = 'update'; - } else { - $command = $env{'form.command'}; - } + my $command = $env{'form.command'}; &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - $r->print(&display_header($command)); if (! (($env{'request.course.fn'}) && (&Apache::lonnet::allowed('bre',$env{'request.course.id'})))) { # Not in a course, or not allowed to view action items $env{'user.error.msg'}="/adm/whatsnew:bre:0:0:Cannot display what's new screen"; return HTTP_NOT_ACCEPTABLE; } + my %checkallowed = ( + coursediscussion => &Apache::lonnet::allowed('pch',$env{'request.course.id'}), + handgrading => &Apache::lonnet::allowed('mgr',$env{'request.course.id'}), + abovethreshold => &Apache::lonnet::allowed('vgr',$env{'request.course.id'}), + haserrors => &Apache::lonnet::allowed('opa',$env{'request.course.id'}), + versionchanges => &Apache::lonnet::allowed('opa',$env{'request.course.id'}), + coursenormalmail => 1, + coursecritmail => 1, + ); + + $r->print(&display_header($command,\%checkallowed)); + &Apache::lonhtmlcommon::clear_breadcrumbs(); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>'/adm/whatsnew', + text=>"Display Action Items"}); if (($command eq 'chgthreshold') && (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) { &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/whatsnew?command=threshold', + ({href=>'/adm/whatsnew?command=chgthreshold', text=>"Change thresholds"}); $r->print(&Apache::lonhtmlcommon::breadcrumbs (undef,'Course Action Items','Course_Action_Items_Thresholds')); - } else { + } elsif (($command eq 'chginterval') && (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) { &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/whatsnew', - text=>"Display Action Items"}); + ({href=>'/adm/whatsnew?command=chginterval', + text=>"Change interval"}); + $r->print(&Apache::lonhtmlcommon::breadcrumbs + (undef,'Course Action Items','Course_Action_Items_Intervals')); + } else { $r->print(&Apache::lonhtmlcommon::breadcrumbs (undef,'Course Action Items','Course_Action_Items_Display')); } - &display_main_box($r,$command); + &display_main_box($r,$command,\%checkallowed); return OK; } @@ -97,7 +107,7 @@ sub handler { #------------------------------ sub display_main_box { - my ($r,$command) = @_; + my ($r,$command,$checkallowed) = @_; my $domain=&Apache::loncommon::determinedomain(); my $tabbg=&Apache::loncommon::designparm('coordinator.tabbg',$domain); $r->print('
'); @@ -107,13 +117,27 @@ sub display_main_box { degdiff => 'Degree of difficulty', numstudents => 'Total number of students with submissions', ); + + my %interval_titles = ( + -1 => 'since start of course', + 2592000 => 'since last month', + 604800 => 'since last week', + 86400 => 'since yesterday', + ); + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; - if (($command eq 'chgthreshold') && (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) { - &display_config_box($r,$command,$tabbg,\%threshold_titles,$cdom,$crs); + if (($command eq 'chgthreshold') && + (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) { + &display_threshold_config($r,$command,$tabbg,\%threshold_titles, + $cdom,$crs); + } elsif (($command eq 'chginterval') && + (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) { + &display_interval_config($r,\%interval_titles); } else { - &display_actions_box($r,$command,\%threshold_titles,$cdom,$crs); + &display_actions_box($r,$command,\%threshold_titles,\%interval_titles, + $cdom,$crs,$checkallowed); } $r->print(< @@ -132,12 +156,33 @@ END_OF_BLOCK #------------------------------- sub display_header{ + my ($command,$checkallowed) = @_; my $html=&Apache::lonxml::xmlbegin(); my $bodytag=&Apache::loncommon::bodytag('Course Action Items'); + my $scripttag; + unless ($command eq 'chgthreshold' || $command eq 'chginterval') { + $scripttag = <<"END"; + +'; + } return(< Course Action Items +$scripttag $bodytag ENDHEAD @@ -151,11 +196,25 @@ ENDHEAD #------------------------------- sub display_actions_box() { - my ($r,$command,$threshold_titles,$cdom,$crs) = @_; - + my ($r,$command,$threshold_titles,$interval_titles,$cdom,$crs, + $checkallowed) = @_; my $rowColor1 = "#ffffff"; my $rowColor2 = "#eeeeee"; + my $udom = $env{'user.domain'}; + my $uname = $env{'user.name'}; + my $cid = $env{'request.course.id'}; + + my %lt = &Apache::lonlocal::texthash( + 'yacc' => 'You are accessing an invalid course.', + 'gtfr' => 'Go to first resource', + 'chyp' => 'Change your preferences', + 'tsup' => 'to suppress display of this screen when accessing'. + ' this course in the future.', + 'hial' => 'Hide all', + 'shal' => 'Show all', + ); + my %unread = (); my %ungraded = (); my %bombed = (); @@ -193,31 +252,54 @@ sub display_actions_box() { my $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain); my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain); - unless ($env{'request.course.id'}) { - $r->print('
You are accessing an invalid course.


'); + unless ($cid) { + $r->print('
'.$lt{'yacc'}.'


'); return; } - my %checkallowed = ( - coursediscussion => &Apache::lonnet::allowed('pch',$env{'request.course.id'}), - handgrading => &Apache::lonnet::allowed('mgr',$env{'request.course.id'}), - abovethreshold => &Apache::lonnet::allowed('vgr',$env{'request.course.id'}), - haserrors => &Apache::lonnet::allowed('opa',$env{'request.course.id'}), - versionchanges => &Apache::lonnet::allowed('opa',$env{'request.course.id'}), - coursenormalmail => 1, - coursecritmail => 1, - ); + if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db', + &GDBM_READER(),0640)) { + my $furl=$bighash{'first_url'}; + $r->print(''.$lt{'gtfr'}. + ''. + '
'.$lt{'chyp'}.'
'.$lt{'tsup'}.'

'); + untie(%bighash); + } + + my $result; + + if ($command eq 'reset') { + $result = &process_reset($cdom,$crs); + } elsif ($command eq 'update') { + $result = &process_update($cdom,$crs,$threshold_titles); + } elsif ($command eq 'newinterval') { + $result = &store_interval_setting($uname,$udom,$cid,$interval_titles); + } - my %display_settings = &get_display_settings(); - my $starttime = 86400; - my %intervals = ( - all => 'since resource creation', - -1 => 'since start of course', - 2592000 => 'since last month', - 604800 => 'since last week', - 86400 => 'since yesterday', - ); - my $interval = $intervals{$starttime}; + my $store_result=&store_display_settings($uname,$udom,$cid,$checkallowed); + + unless ($store_result eq 'ok') { + &Apache::lonnet::logthis('Error storing whatsnew settings: '. + $store_result.' for '.'user '.$uname.':'.$udom.' in course '.$cid); + $result .= &mt('Unable to store visibility settings due to [_1]', + $store_result); + } + + if ($result) { + $r->print($result.'
'); + } + $r->rflush(); + + + my %display_settings = &get_display_settings($uname,$udom,$cid); + my $timediff = $display_settings{$cid.':interval'}; + unless (defined($timediff)) { $timediff = 604800; } + my $now = time; + my $interval = $$interval_titles{$timediff}; + if ($timediff == -1) { + $timediff = time; + } + my $starttime = $now - $timediff; my %headings = &Apache::lonlocal::texthash( coursediscussion => 'Unread course discussion posts', @@ -228,7 +310,7 @@ sub display_actions_box() { coursecritmail => 'New critical messages in course', ); - if ($checkallowed{'abovethreshold'}) { + if ($$checkallowed{'abovethreshold'}) { &get_curr_thresholds(\%threshold,$cdom,$crs); } @@ -236,10 +318,10 @@ sub display_actions_box() { my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail'); - foreach my $key (keys(%checkallowed)) { + foreach my $key (keys(%{$checkallowed})) { $show{$key} = 0; - if ($checkallowed{$key}) { - unless ($display_settings{$key} eq 'off') { + if ($$checkallowed{$key}) { + unless ($display_settings{$cid.':'.$key} eq 'hide') { $show{$key} = 1; } } @@ -254,26 +336,6 @@ sub display_actions_box() { } } - - if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db', - &GDBM_READER(),0640)) { - my $furl=$bighash{'first_url'}; - $r->print('Go to first resource
Change your preferences
to suppress display of this screen when accessing courses as Course Coordinator in the future.

'); - untie(%bighash); - } - - my $result; - - if ($command eq 'reset') { - $result = &process_reset($cdom,$crs); - } elsif ($command eq 'update') { - $result = &process_update($cdom,$crs,$threshold_titles); - } - if ($result) { - $r->print($result.'
'); - } - $r->rflush(); - if ($needitems) { &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime); } @@ -284,19 +346,26 @@ sub display_actions_box() { &getcritmail(\@critmsgs); } - $r->print(qq|Hide All  Show All|); + $r->print(qq|$lt{'hial'} +   $lt{'shal'} +
\n|); + foreach my $item (keys(%{$checkallowed})) { + if ($$checkallowed{$item}) { + $r->print(''."\n"); + } + } - $r->print('
'); + $r->print('
'); foreach my $res (@{$warnings}) { if ($warningnum %2 == 1) { @@ -914,7 +1030,7 @@ sub display_abovethreshold { $r->print(''.$$triggered{$res}{text}); $warningnum ++; } - $r->print(''); } @@ -1050,9 +1166,7 @@ sub cmp_title { } sub get_display_settings { - my $udom = $env{'user.domain'}; - my $uname = $env{'user.name'}; - my $cid = $env{'request.course.id'}; + my ($uname,$udom,$cid) = @_; my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid); my ($tmp) = keys(%settings); if ($tmp=~/^error:/) { @@ -1065,6 +1179,49 @@ sub get_display_settings { return %settings; } +sub store_display_settings { + my ($uname,$udom,$cid,$checkallowed) = @_; + my %whatsnew_settings; + my $result; + foreach my $key (keys(%{$checkallowed})) { + if (exists($env{'form.display_'.$key})) { + unless ($env{'form.display_'.$key} eq '') { + $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key}; + } + } + } + if (keys(%whatsnew_settings)) { + $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings, + $udom,$uname); + } else { + $result = 'ok'; + } + return $result; +} + +sub store_interval_setting { + my ($uname,$udom,$cid,$interval_titles) = @_; + my %interval_settings = (); + my $result; + if (defined($env{'form.interval'})) { + $interval_settings{$cid.':interval'} = $env{'form.interval'}; + my $outcome = &Apache::lonnet::put('nohist_whatsnew', + \%interval_settings,$udom,$uname); + if ($outcome eq 'ok') { + $result = &mt('Interval set to version changes [_1]', + ''.$$interval_titles{$env{'form.interval'}}.'
'); + + } else { + &Apache::lonnet::logthis('Error storing whatsnew interval setting'. + ' '.$outcome.' for '.$uname.':'.$udom.' in course '.$cid); + $result = &mt('Unable to set interval to [_1] due to [_2].', + ''.$$interval_titles{$env{'form.interval'}}.'', + ''.$outcome.'.
'); + } + } + return $result; +} + sub start_box { my ($r,$tabbg,$show,$heading,$caller) = @_; my %lt = &Apache::lonlocal::texthash( @@ -1073,12 +1230,12 @@ sub start_box { ); my $showhide; if ($$show{$caller}) { - $showhide = 'Hide'; + $showhide = 'Hide'; } else { - $showhide = 'Show'; + $showhide = 'Show'; } $r->print('
'); my $displayed = 0; - my $totalboxes = keys(%checkallowed); + my $totalboxes = keys(%{$checkallowed}); my $halfway = int($totalboxes/2) + $totalboxes%2; foreach my $actionitem (@actionorder) { - if ($checkallowed{$actionitem}) { + if ($$checkallowed{$actionitem}) { 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); $displayed ++; } } @@ -311,13 +380,13 @@ sub display_actions_box() { } #------------------------------- -# display_config_box +# display_threshold_config # # Display the threshold setting screen # #------------------------------- -sub display_config_box() { +sub display_threshold_config { my ($r,$command,$tabbg,$threshold_titles,$cdom,$crs) = @_; my %threshold = (); my $rowColor1 = "#ffffff"; @@ -332,7 +401,10 @@ sub display_config_box() { ); &get_curr_thresholds(\%threshold,$cdom,$crs); - $r->print('
+ $r->print('
+ + +
@@ -371,10 +443,40 @@ sub display_config_box() { } $r->print('

- +
'); } +#------------------------------- +# display_interval_config +# +# Display the interval setting screen +# +#------------------------------- + +sub display_interval_config { + my ($r,$interval_titles) = @_; + my $current = &get_curr_interval($env{'user.name'}, + $env{'user.domain'},$env{'request.course.id'}); + $r->print('
'.&mt('Choose the time window to use for display of version changes for resources in the course.')); + unless ($current eq '') { + $r->print(' '.&mt('Current value is ').$$interval_titles{$current}.'

'); + } + $r->print('

+
+ +   +
'); + return; +} + sub display_launcher { my ($r,$action,$checkallowed,$tabbg,$rowColor1,$rowColor2,$show, $headings,$res_title,$tograde,$ungraded,$bombs,$bombed,$changed, @@ -399,7 +501,7 @@ sub display_launcher { $rowColor1,$rowColor2); } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION &display_coursediscussion($r,$newdiscussions,$unread, - $res_title); + $res_title,$rowColor1,$rowColor2); } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES &display_coursenormalmail($r,$msgcount,$newmsgs,$rowColor1, $rowColor2); @@ -460,7 +562,7 @@ sub getitems { # Check for unread discussion postings if ($$show{'coursediscussion'}) { &check_discussions($cdom,$crs,$resource,$symb,$ressymb,$title, - $newdiscussions,$unread,\&lastreadtime); + $newdiscussions,$unread,\%lastreadtime); } # Check for ungraded problems @@ -527,7 +629,7 @@ sub check_handgraded { } } if ($handgradeable) { - my @ungraded = &Apache::bridgetask::get_users_in_queue( + my @ungraded = &Apache::bridgetask::get_queue_symb_status( 'gradingqueue',$symb,$cdom,$cnum); if (@ungraded > 0) { $$ungraded{$symb}{count} = scalar(@ungraded); @@ -598,7 +700,7 @@ sub check_thresholds { } } if ($warning) { - if ($$warningnum %2 == 1) { + if ($warningnum %2 == 1) { $rowColor = $rowColor1; } else { $rowColor = $rowColor2; @@ -629,7 +731,7 @@ sub check_thresholds { } } push(@{$warnings},$symb); - $$warningnum ++; + $warningnum ++; } } @@ -649,6 +751,19 @@ sub get_curr_thresholds { } } +sub get_curr_interval { + my ($uname,$udom,$cid); + my $interval; + my %settings = &Apache::lonnet::dump('nohist_whatsnew',$uname,$udom,$cid,':interval'); + my ($tmp) = %settings; + if ($tmp =~ /^Error/) { + &logthis(); + } else { + $interval = $settings{$cid.':interval'}; + } + return $interval; +} + sub process_reset { my ($dom,$crs) = @_; my $result = 'Counters reset for following problems (and parts):
'; @@ -797,7 +912,6 @@ sub checkversions { my $revdate = &Apache::lonnet::metadata($root.'.'.$extension, 'lastrevisiondate'); - print STDERR "revdate for $root and $extension is $revdate\n"; $revdate = &Apache::lonlocal::locallocaltime($revdate); my $linkurl=&Apache::lonnet::clutter($key); my $usedversion=$navmap->usedVersion('version_'.$linkurl); @@ -808,12 +922,14 @@ sub checkversions { $version = $currentversion; } foreach my $res (@resources) { - my $symb = $res->symb(); - %{$$changed{$symb}} = ( + if (ref($res) eq 'Apache::lonnavmaps::resource') { + my $symb = $res->symb(); + %{$$changed{$symb}} = ( current => $currentversion, version => $version, revdate => $revdate, - ); + ); + } } } } @@ -895,8 +1011,8 @@ sub display_abovethreshold { my $warningnum = 0; if (@{$warnings} > 0) { @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings}; - $r->print('
'. - ' '."\n"); + $r->print(''. + ' '."\n"); $r->print('
'.$lt{'reso'}.''.$lt{'part'}.''.$lt{'nust'}.''.$lt{'avat'}.''.$lt{'dedi'}.''.$lt{'lare'}.''.$lt{'reco'}.'
'.$$triggered{$res}{title}.'


'); } else { $r->print('

'.$lt{'nopr'}.'