[LON-CAPA-cvs] cvs: loncom /interface lonwhatsnew.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Wed, 30 Apr 2008 23:52:04 -0000


This is a MIME encoded message

--raeburn1209599524
Content-Type: text/plain

raeburn		Wed Apr 30 19:52:04 2008 EDT

  Modified files:              
    /loncom/interface	lonwhatsnew.pm 
  Log:
  Bug 5176. Record of role changes in a course in nohist_rolelog.db
  - Display roles which became active in a course during a specified time interval.
  - Display roles which expired in a course during a specified time interval.
  - Some wording changes for "version changes" display/interval setting.
  - Replace partial phrases with complete phrases to aid internationalization.
  - Number of boxes displayed in left column fixed (at four).    
  
  
--raeburn1209599524
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080430195204.txt"

Index: loncom/interface/lonwhatsnew.pm
diff -u loncom/interface/lonwhatsnew.pm:1.76 loncom/interface/lonwhatsnew.pm:1.77
--- loncom/interface/lonwhatsnew.pm:1.76	Tue Mar 18 18:00:28 2008
+++ loncom/interface/lonwhatsnew.pm	Wed Apr 30 19:52:00 2008
@@ -1,5 +1,5 @@
 #
-# $Id: lonwhatsnew.pm,v 1.76 2008/03/18 22:00:28 raeburn Exp $
+# $Id: lonwhatsnew.pm,v 1.77 2008/04/30 23:52:00 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,6 +36,7 @@
 use Apache::loncoursedata();
 use Apache::lonnavmaps();
 use Apache::lonuserstate;
+use Apache::lonuserutils; 
 use Apache::Constants qw(:common :http);
 use Time::Local;
 use GDBM_File;
@@ -68,6 +69,8 @@
 			    ['vgr','abovethreshold',1],
 			    ['opa','haserrors',1],
 			    ['mdc','versionchanges',0],
+                            ['vcl','newroles',1],
+                            ['vcl','oldroles',1],
 			    ) {
 	my ($perm,$key,$check_section) = @{ $perm_check };
 	my $scope = $env{'request.course.id'};
@@ -125,6 +128,20 @@
         $r->print(&Apache::lonhtmlcommon::breadcrumbs
             ("What's New?",#'Course_Action_Items_Initialization'
 	     ));
+    } elsif ($command eq 'chgoldroleinterval' && $checkallowed{'oldroles'}) {
+        &Apache::lonhtmlcommon::add_breadcrumb
+            ({href=>'/adm/whatsnew?command=chgoldroleinterval&refpage='.$refpage,
+              text=>"Change interval"});
+        $r->print(&Apache::lonhtmlcommon::breadcrumbs
+            ("What's New?",#'Course_Action_Items_Intervals'
+             ));
+    } elsif ($command eq 'chgnewroleinterval' && $checkallowed{'newroles'}) {
+        &Apache::lonhtmlcommon::add_breadcrumb
+            ({href=>'/adm/whatsnew?command=chgnewroleinterval&refpage='.$refpage,
+              text=>"Change interval"});
+        $r->print(&Apache::lonhtmlcommon::breadcrumbs
+            ("What's New?",#'Course_Action_Items_Intervals'
+             ));
     } else {
         $r->print(&Apache::lonhtmlcommon::breadcrumbs
             ("What's New?",#'Course_Action_Items_Display'
@@ -152,14 +169,29 @@
                          degdiff => 'Degree of difficulty',
                          numstudents => 'Total number of students with submissions',
     );
-
-    my %interval_titles = &Apache::lonlocal::texthash (
-                            -1 => "since start of $lctype",
-                       2592000 => 'since last month',
-                        604800 => 'since last week',
-                         86400 => 'since yesterday',
+    my %versions = &Apache::lonlocal::texthash (
+                       -1 => "version changes since start of $lctype",
+                  2592000 => 'version changes since last month',
+                   604800 => 'version changes since last week',
+                    86400 => 'version changes since yesterday',
+                   );
+    my %newroles = &Apache::lonlocal::texthash (
+                       -1 => "roles which have become active since start of $lctype",
+                  2592000 => 'roles which have become active since last month',
+                   604800 => 'roles which have become active since last week',
+                    86400 => 'roles which have become active since yesterday',
+                   );
+    my %oldroles = &Apache::lonlocal::texthash (
+                       -1 => "roles which expired since start of $lctype",
+                  2592000 => 'roles which expired since last month',
+                   604800 => 'roles which expired since last week',
+                    86400 => 'roles which expired since yesterday',
+                   );
+    my %interval_titles = (
+        versions => \%versions,
+        newroles => \%newroles,
+        oldroles => \%oldroles,
     );
-
     my %initpage = &Apache::lonlocal::texthash (
                      firstres => "first resource in the $lctype",
                      whatsnew => "what's new? page",
@@ -175,12 +207,18 @@
                                                                    $cdom,$crs);
     } elsif (($command eq 'chginterval') 
 	     && $checkallowed->{'versionchanges'}) {
-        &display_interval_config($r,$refpage,\%interval_titles);
+        &display_interval_config($r,$refpage,\%interval_titles,'versions');
     } elsif (($command eq 'chgdisc') 
 	     && $checkallowed->{'coursediscussion'}) {
         &display_discussion_config($r,$refpage);
     } elsif ($command eq 'courseinit') {
         &courseinit_config($r,$refpage,\%initpage);
+    } elsif (($command eq 'chgnewroleinterval')
+             && $checkallowed->{'newroles'}) {
+        &display_interval_config($r,$refpage,\%interval_titles,'newroles');
+    } elsif (($command eq 'chgoldroleinterval')
+             && $checkallowed->{'oldroles'}) {
+        &display_interval_config($r,$refpage,\%interval_titles,'oldroles');
     } else {
         &display_actions_box($r,$command,$refpage,\%threshold_titles,
                         \%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
@@ -205,12 +243,13 @@
     my ($command,$checkallowed) = @_;
     
     my $scripttag;
-    unless ($command eq 'chgthreshold' || $command eq 'chginterval') {
+    unless ($command eq 'chgthreshold' || $command eq 'chginterval' || 
+            $command eq 'chgoldroleinterval' || $command eq 'chgnewroleinterval') {
        $scripttag = <<"END";
 <script type="text/javascript">
 function change_display(caller,change) {
     caller.value = change;
-    document.visible.submit(); 
+    document.visible.submit();
 }
 
 function changeAll(change) {
@@ -271,7 +310,10 @@
     my @warnings = ();
     my $msgcount = 0;
     my $critmsgcount = 0;
-
+    my $expirecount;
+    my %expired;
+    my $activecount;
+    my %activated;
     my %res_title = ();
     my %show = ();
     my $needitems = 0;
@@ -345,30 +387,78 @@
     }
     $r->rflush();
 
-
+    my (%timediff,%interval);
     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 $countunread = $display_settings{$cid.':countunread'};
-    unless (defined($countunread)) {
-        $countunread = 'on';
-    }
+    $timediff{'versions'} = $display_settings{$cid.':interval'};
+    unless (defined($timediff{'versions'})) { $timediff{'versions'} = 604800; } 
+    $interval{'versions'} = $interval_titles->{'versions'}->{$timediff{'versions'}};
 
     my %headings = &Apache::lonlocal::texthash(
-                coursediscussion =>  'Unread '.$lctype.' discussion posts',
-                handgrading =>  'Problems requiring handgrading',
-                haserrors => 'Problems with errors',
-                versionchanges => 'Resources in '.$lctype.' with version changes '.$interval,
+                coursediscussion => 'Unread '.$lctype.' discussion posts',
+                handgrading      => 'Problems requiring handgrading',
+                haserrors        => 'Problems with errors',
                 coursenormalmail => 'New '.$lctype.' messages',
-                coursecritmail => 'New critical messages in '.$lctype,
+                coursecritmail   => 'New critical messages in '.$lctype,
     );
 
+    if ($timediff{'versions'} == -1) {
+        $headings{'versionchanges'} = 'Resources in '.$lctype.' with version changes since start of '.$lctype;
+    } elsif ($timediff{'versions'} == 2592000) {
+        $headings{'versionchanges'} = 'Resources in '.$lctype.' with version changes since last month';
+    } elsif ($timediff{'versions'} == 604800) {
+        $headings{'versionchanges'} = 'Resources in '.$lctype.' with version changes since last week';
+    } elsif ($timediff{'versions'} == 86400) {
+        $headings{'versionchanges'} = 'Resources in '.$lctype.' with version changes since yesterday';
+    }
+
+    $timediff{'oldroles'} = $display_settings{$cid.':oldroleinterval'};
+    unless (defined($timediff{'oldroles'})) { $timediff{'oldroles'} = 604800; }
+    $interval{'oldroles'} = $interval_titles->{'oldroles'}->{$timediff{'oldroles'}};
+
+    if ($timediff{'oldroles'} == -1) {
+        $headings{'oldroles'} = 'Roles for which access to '.$lctype.' has expired since start of '.$lctype;
+    } elsif ($timediff{'oldroles'} == 2592000) {
+        $headings{'oldroles'} = 'Roles for which access to '.$lctype.' has expired since last month';
+    } elsif ($timediff{'oldroles'} == 604800) {
+        $headings{'oldroles'} = 'Roles for which access to '.$lctype.' has expired since last week';
+    } elsif ($timediff{'oldroles'} == 86400) {
+        $headings{'oldroles'} = 'Roles for which access to '.$lctype.' has expired since yesterday';
+    }
+
+    $timediff{'newroles'} = $display_settings{$cid.':newroleinterval'};
+    unless (defined($timediff{'newroles'})) { $timediff{'newroles'} = 604800; }
+    $interval{'newroles'} = $interval_titles->{'newroles'}->{$timediff{'newroles'}};
+
+    if ($timediff{'newroles'} == -1) {
+        $headings{'newroles'} = 'Roles for which access to '.$lctype.' has become available since start of '.$lctype;
+    } elsif ($timediff{'newroles'} == 2592000) {
+        $headings{'newroles'} = 'Roles for which access to '.$lctype.' has become available since last month';
+    } elsif ($timediff{'newroles'} == 604800) {
+        $headings{'newroles'} = 'Roles for which access to '.$lctype.' has become available since last week';
+    } elsif ($timediff{'newroles'} == 86400) {
+        $headings{'newroles'} = 'Roles for which access to '.$lctype.' has become available since yesterday';
+    }
+
+    my $now = time;
+    if ($timediff{'versions'} == -1) {
+        $timediff{'versions'} = time;
+    }
+    my $starttime = $now - $timediff{'versions'};
+
+    if ($timediff{'newroles'} == -1) {
+        $timediff{'newroles'} = time;
+    }
+    my $activatedstart = $now - $timediff{'newroles'};
+
+    if ($timediff{'oldroles'} == -1) {
+        $timediff{'oldroles'} = time;
+    }
+    my $expiredstart = $now - $timediff{'oldroles'};
+
+    my $countunread = $display_settings{$cid.':countunread'};
+    unless (defined($countunread)) {
+        $countunread = 'on';
+    }
     if ($$checkallowed{'abovethreshold'}) {
         &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
     }
@@ -378,7 +468,7 @@
 	    $threshold{'av_attempts'},$threshold{'degdiff'},
 	    $threshold{'numstudents'});
 
-    my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail');
+    my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles');
 
     foreach my $key (keys(%{$checkallowed})) {
 	if ($key =~ /_section$/) { next; }
@@ -391,7 +481,8 @@
     }
 
     foreach my $item (@actionorder) {
-        unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail') {
+        unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail' ||
+                $item eq 'newroles' || $item eq 'oldroles') {
             if ($show{$item}) {
                 $needitems = 1;
                 last;
@@ -408,7 +499,12 @@
     if ($show{'coursecritmail'}) {
         $critmsgcount = &getcritmail(\@critmsgs);
     }
-
+    if ($show{'oldroles'}) {
+        $expirecount = &getexpired(\%expired,$expiredstart,'previous');
+    }
+    if ($show{'newroles'}) {
+        $activecount = &getactivated(\%activated,$activatedstart,'active');
+    }
     $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
      &nbsp;&nbsp;<a href="javascript:changeAll('show');">$lt{'shal'}</a>
      <form method="post" name="visible" action="/adm/whatsnew">\n|);
@@ -430,13 +526,14 @@
             $totalboxes ++;
         }
     }
-    my $halfway = int($totalboxes/2) + $totalboxes%2;
+    my $halfway = 4;
+#    my $halfway = int($totalboxes/2) + $totalboxes%2;
     foreach my $actionitem (@actionorder) {
         if ($$checkallowed{$actionitem}) {
             if ($displayed == $halfway) {
                 $r->print('</td><td>&nbsp;</td><td class="LC_right_col" >');
             }
-            &display_launcher($r,$actionitem,$refpage,$checkallowed,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,$interval,$countunread);
+            &display_launcher($r,$actionitem,$refpage,$checkallowed,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,\%interval,$countunread,\%expired,$expirecount,\%activated,$activecount,$crstype);
             $displayed ++; 
         }
     }
@@ -510,24 +607,45 @@
 #-------------------------------
                                                                                    
 sub display_interval_config {
-    my ($r,$refpage,$interval_titles) = @_;
+    my ($r,$refpage,$interval_titles,$context) = @_;
+    my $setting = 'interval';
+    if ($context eq 'oldroles') {
+        $setting = 'oldroleinterval';
+    } elsif ($context eq 'newroles') {
+        $setting = 'newroleinterval'; 
+    }
     my $lctype = lc(&Apache::loncommon::course_type());
     my $current = &get_current($env{'user.name'},$env{'user.domain'},
-                                $env{'request.course.id'},'interval');
-    $r->print('<br />'.&mt('Choose the time window to use for display of version changes for resources in the '.$lctype.'.').'<br />');
+                                $env{'request.course.id'},$setting);
+    if ($context eq 'oldroles') {
+        $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' expired.').'<br />');
+    } elsif ($context eq 'newroles') {
+        $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' became available.').'<br />');
+    } else {
+        $r->print('<br />'.&mt('Choose the time window to use to display resources in the '.$lctype.' with version changes.').'<br />');
+    }
     unless ($current eq '') {
-        $r->print(' '.&mt('Current value is [_1].','<b>'.
-                  $$interval_titles{$current}.'</b>'));
+        if (ref($interval_titles->{$context}) eq 'HASH') {
+            $r->print(' '.&mt('Current value is "[_1]".','<b>'.
+                      $interval_titles->{$context}->{$current}.'</b>').'<br />');
+        }
     }
-    $r->print('<br /><br />
+    $r->print('<br />
 <form method="post" name="intervalswitch" action="/adm/whatsnew">
 <input type="hidden" name="command" value="newinterval" />
-<input type="hidden" name="refpage" value="'.$refpage.'" />
+<input type="hidden" name="intervaltype" value="'.$context.'" />
+<input type="hidden" name="refpage" value="'.$refpage.'" />'.
+&mt('Display:').' 
 <select name="interval">
+<option value="" selected="selected">Select</option>
 ');
-    foreach my $key (reverse sort ({$a cmp $b} (keys(%{$interval_titles})))) {
-        $r->print('<option value="'.$key.'">'.&mt('Version changes').' '.$$interval_titles{$key}.
-                  '</option>'."\n");
+    if (ref($interval_titles) eq 'HASH') {
+        if (ref($interval_titles->{$context}) eq 'HASH') {
+            foreach my $key (reverse sort ({$a cmp $b} (keys(%{$interval_titles->{$context}})))) {
+                $r->print('<option value="'.$key.'">'.$interval_titles->{$context}->{$key}.
+                          '</option>'."\n");
+            }
+        }
     }
     $r->print('</select>&nbsp;&nbsp;
                <input type="submit" name="display" value="'.
@@ -661,7 +779,8 @@
     my ($r,$action,$refpage,$checkallowed,$show,$headings,$res_title,
         $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered,
         $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs,
-        $interval,$countunread) = @_;
+        $interval,$countunread,$expired,$expirecount,$activated,$activecount,
+        $crstype) = @_;
 
     if ($$checkallowed{$action}) {
         &start_box($r,$show,$headings,$action,$refpage,$action);
@@ -671,7 +790,7 @@
             } elsif ($action eq 'haserrors') { # BOMBS
                 &display_haserrors($r,$bombs,$bombed,$res_title);
             } elsif ($action eq 'versionchanges') { # VERSION CHANGES
-                &display_versionchanges($r,$changed,$res_title,$interval);
+                &display_versionchanges($r,$changed,$res_title,$interval->{'versions'});
             } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
                 &display_abovethreshold($r,$refpage,$warnings,$triggered,
 					$res_title);
@@ -682,6 +801,12 @@
                 &display_coursenormalmail($r,$msgcount,$newmsgs);
             } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
                 &display_coursecritmail($r,$critmsgcount,$critmsgs);
+            } elsif ($action eq 'newroles') { # ACTIVATED ROLES
+                &display_rolechanges($r,$activecount,$activated,$interval->{'newroles'},
+                                     $crstype);
+            } elsif ($action eq 'oldroles') { # EXPIRED ROLES
+                &display_rolechanges($r,$expirecount,$expired,$interval->{'oldroles'},
+                                     $crstype);
             }
         }
         &end_box($r);
@@ -1074,6 +1199,205 @@
     return $critmsgcount;
 }
 
+sub getexpired {
+    my ($rolechgs,$rolechgtime,$status) = @_;
+    my $expirecount = &getrolechanges($rolechgs,$rolechgtime,$status);
+    return $expirecount;
+}
+
+sub getactivated {
+    my ($rolechgs,$rolechgtime,$status) = @_;
+    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+    my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+    my $now = time();
+    my $context = 'course';
+    my ($permission,$allowed) =
+        &Apache::lonuserutils::get_permission($context);
+    my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
+    my %changes=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
+    my (%stucounted,%advcounted);
+    my $activatedcount = 0;
+    if (keys(%changes) > 0) {
+        foreach my $chg (sort { $b <=> $a } (keys(%changes))) {
+            if (ref($changes{$chg}) eq 'HASH') {
+                my $timestamp = $changes{$chg}{'exe_time'};
+                if ($timestamp) {
+                    if ($rolechgtime > -1) {
+                        if ($now - $rolechgtime < $timestamp) {
+                            last;
+                        }
+                    }
+                    if (ref($changes{$chg}{'logentry'}) eq 'HASH') {
+                        next if ($changes{$chg}{'delflag'});
+                        my $start = $changes{$chg}{'logentry'}{'start'};
+                        my $end = $changes{$chg}{'logentry'}{'end'};
+                        my $section = $changes{$chg}{'logentry'}{'section'};
+                        my $role = $changes{$chg}{'logentry'}{'role'};
+                        my $uname = $changes{$chg}{'uname'};
+                        my $udom = $changes{$chg}{'udom'};
+                        next if ($end && $end <= $now);
+                        if (($viewablesec ne '') && ($section ne '')) {
+                            next if ($viewablesec ne $section);
+                        }
+                        next if ($start >= $timestamp);
+                        if ($role eq 'st') {
+                            $stucounted{$uname.':'.$udom.':'.$section} = $start.':'.$end;
+                        } else {
+                            $advcounted{$uname.':'.$udom.':'.$role.':'.$section} = $start.':'.$end;
+                        }
+                        my %chginfo = (
+                                       'section' => $section,
+                                       'uname'   => $uname,
+                                       'udom'    => $udom,
+                                       'role'    => $role,
+                                       'status'  => $status,
+                        );
+                        $activatedcount ++;
+                        push (@{$rolechgs->{$timestamp}},\%chginfo);
+                    }
+                }
+            }
+        }
+    }
+    $activatedcount += &getrolechanges($rolechgs,$rolechgtime,$status,\%stucounted,\%advcounted);
+    return $activatedcount;
+}
+
+sub getrolechanges {
+    my ($rolechgs,$rolechgtime,$status,$stucountref,$advcountref) = @_;
+    my (%stucounted,%advcounted);
+    if (ref($stucountref) eq 'HASH') {
+        %stucounted = %{$stucountref};
+    }
+    if (ref($advcountref) eq 'HASH') {
+        %advcounted = %{$advcountref};
+    }
+    my $withsec = 1;
+    my $hidepriv = 1;
+    my $context = 'course';
+    my @statuses = ($status);
+    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+    my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+    my $now = time();
+    my ($permission,$allowed) =
+        &Apache::lonuserutils::get_permission($context);
+    my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
+    my $classlist = &Apache::loncoursedata::get_classlist();
+    my $secidx = &Apache::loncoursedata::CL_SECTION();
+    my $startidx = &Apache::loncoursedata::CL_START();
+    my $endidx = &Apache::loncoursedata::CL_END();
+    my $rolechgcount = 0;
+    foreach my $key (keys(%{$classlist})) {
+        my ($userstatus,$eventtime);   
+        my $student = $classlist->{$key};
+        if (ref($student) eq 'ARRAY') {
+            my $start = $student->[$startidx];
+            my $end = $student->[$endidx];
+            my $sec = $student->[$secidx]; 
+            my ($stuname,$studom) = split(/:/,$key);
+            if ($status eq 'active') {
+                if (exists($stucounted{$key.':'.$sec})) {
+                    next;
+                }
+            }
+            if (($end == 0) || ($end > $start)) {
+                if ($start <= $now) {
+                    if ($end && $end < $now) {
+                        if ($rolechgtime > 0) {
+                            if ($end > $rolechgtime) {
+                                $userstatus = 'previous';
+                            }
+                        } else {
+                            $userstatus = 'previous';
+                        }
+                    } else {
+                        if ($rolechgtime > 0) {
+                            if ($start >= $rolechgtime) {
+                                $userstatus = 'active';
+                            }
+                        } else {
+                            $userstatus = 'active';
+                        }
+                    }
+                }
+            }
+            next if ($userstatus ne $status);
+            if ($status eq 'active') {
+                $eventtime = $start;
+            } else {
+                $eventtime = $end;
+            }
+            if (($viewablesec ne '') && ($sec ne '')) {
+                next if ($viewablesec ne $sec);
+            }
+            my %chginfo = (
+                            'section' => $sec,
+                            'uname'   => $stuname,
+                            'udom'    => $studom,
+                            'role'    => 'st', 
+                            'status'  => $userstatus,
+                          );
+            $rolechgcount ++;
+            push (@{$rolechgs->{$eventtime}},\%chginfo);
+        }
+    }
+    my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
+                              \@statuses,undef,undef,$withsec,$hidepriv);
+    foreach my $item (keys(%advrolehash)) {
+        my ($userstatus,$eventtime);
+        my ($uname,$udom,$role,$section) = split(/:/,$item,-1);
+        my ($start,$end) = split(/:/,$advrolehash{$item});
+        if ($start eq '-1' && $end eq '-1') {
+            next;
+        } else {
+            if ($status eq 'active') {
+                if (exists($advcounted{$item})) {
+                    next;
+                }
+            }
+            if (($end == 0) || ($end > $start)) {
+                if ($start <= $now) {
+                    if ($end && $end < $now) {
+                        if ($rolechgtime > 0) {
+                            if ($end > $rolechgtime) {
+                                $userstatus = 'previous';
+                            }
+                        } else {
+                            $userstatus = 'previous';
+                        }
+                    } else {
+                        if ($rolechgtime > 0) {
+                            if ($start >= $rolechgtime) {
+                                $userstatus = 'active';
+                            }
+                        } else {
+                            $userstatus = 'active';
+                        }
+                    }
+                }
+            }
+            next if ($userstatus ne $status);
+            if ($status eq 'active') {
+                $eventtime = $start;
+            } else {
+                $eventtime = $end;
+            }
+        }
+        if (($viewablesec ne '') && ($section ne '')) {
+            next if ($viewablesec ne $section);
+        }
+        my %chginfo = ( 
+                        'section' => $section,
+                        'uname'   => $uname,
+                        'udom'    => $udom,
+                        'role'    => $role,
+                        'status'  => $userstatus,    
+                      );
+        $rolechgcount ++; 
+        push (@{$rolechgs->{$eventtime}},\%chginfo); 
+    }
+    return $rolechgcount;
+}
 
 sub checkversions {
     my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
@@ -1239,7 +1563,7 @@
         'revd' => 'Last revised',
         'newv' => 'New version',
         'veru' => 'Version used',
-        'noup' => 'No updated versions', 
+        'noup' => 'No', 
     );
     if (keys(%{$changed}) > 0) {
         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
@@ -1267,6 +1591,64 @@
     }
     return;
 }
+
+sub display_rolechanges {
+    my ($r,$chgcount,$changed,$interval,$crstype) = @_;
+    my $now = time();
+    my %lt = &Apache::lonlocal::texthash(
+        'user'  => 'User',
+        'tich'  => 'Time of change',
+        'role'  => 'Role',
+        'sec'   => 'Section',
+        'status'  => 'Status',
+        'norc'  => 'There are no ',
+    );
+    if ($chgcount) {
+        $r->print('<tr class="LC_info_row">'.
+                  '<td class="LC_left_item">'.$lt{'tich'}.'</td>'.
+                  '<td class="LC_left_item">'.$lt{'user'}.'</td>'.
+                  '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
+                  '<td class="LC_left_item">'.$lt{'sec'}.'</td>'.
+                  '<td class="LC_left_item">'.$lt{'status'}.'</td></tr>');
+        if (ref($changed) eq 'HASH') {
+            my @changes = sort { $b <=> $a } (keys(%{$changed}));
+            my $changenum = 0;
+            foreach my $item (@changes) {
+                if (ref($changed->{$item}) eq 'ARRAY') {
+                    foreach my $chg (@{$changed->{$item}}) {
+                        if (ref($chg) eq 'HASH') {
+                            my $section;
+                            my $role = 
+                                &Apache::lonnet::plaintext($chg->{'role'},$crstype);
+                            my $status = &mt($chg->{'status'});
+                            if ($chg->{'section'} eq '') {
+                                $section = &mt('none');
+                            } else {
+                                $section = $chg->{'section'};
+                            }
+                            my $uname = $chg->{'uname'};
+                            my $udom = $chg->{'udom'};
+                            $changenum ++;
+                            my $css_class = $changenum%2?' class="LC_odd_row"':'';
+                            my $link = 
+                                &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
+                            $r->print('<tr'.$css_class.'>'.
+                                      '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
+                                      '<td>'.$link.'</td>'.
+                                      '<td>'.$role.'</td>'.
+                                      '<td>'.$section.'</td>'.
+                                      '<td>'.$status.'</td></tr>');
+                        }
+                    }
+                }
+            }
+        }
+    } else {
+        $r->print('<tr class="LC_empty_row"><td>'.$lt{'norc'}.
+                  ' '.$interval.'</td></tr>');
+    }
+    return;
+}
  
 sub display_coursediscussion {
     my ($r,$newdiscussions,$unread,$countunread,$res_title) = @_;
@@ -1420,20 +1802,28 @@
     my ($uname,$udom,$cid,$interval_titles) = @_;
     my %interval_settings = ();
     my $result;
-    if (defined($env{'form.interval'})) {
-        $interval_settings{$cid.':interval'} = $env{'form.interval'};
+    my $context = $env{'form.intervaltype'};
+    if ($env{'form.interval'} ne '') {
+        if ($context eq 'oldroles') {
+            $interval_settings{$cid.':oldroleinterval'} = $env{'form.interval'};
+        } elsif ($context eq 'newroles') {
+            $interval_settings{$cid.':newroleinterval'} = $env{'form.interval'};
+        } else {
+            $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]',
-                  '<b>'.$$interval_titles{$env{'form.interval'}}.'</b>').'<br />';
-
+            if (ref($interval_titles->{$context}) eq 'HASH') {
+                $result = &mt('New filter setting: [_1].','<b>'. 
+                              $interval_titles->{$context}->{$env{'form.interval'}}.'</b>').'<br />';
+            }
         } else {
 	    my $lctype = lc(&Apache::loncommon::course_type());
-            &Apache::lonnet::logthis('Error saving whatsnew interval setting'.
+            &Apache::lonnet::logthis('Error saving whatsnew '.$context.' interval setting'.
                 ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
             $result = &mt('Unable to set interval to [_1] due to [_2].',
-                         '<b>'.$$interval_titles{$env{'form.interval'}}.'</b>',
+                         '<b>'.$interval_titles->{$context}->{$env{'form.interval'}}.'</b>',
                          '<tt>'.$outcome.'</tt>.<br />');
         }
     }
@@ -1556,6 +1946,20 @@
                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
               </tr>');
          }
+     } elsif (($caller eq 'newroles') && ($$show{$caller})) {
+         if ($$show{$caller}) {
+             $r->print('
+              <tr>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgnewroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+              </tr>');
+         }
+     } elsif (($caller eq 'oldroles') && ($$show{$caller})) {
+         if ($$show{$caller}) {
+             $r->print('
+              <tr>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+              </tr>');
+         }
      }
     $r->print('
               <tr>

--raeburn1209599524--