Diff for /loncom/interface/lonwhatsnew.pm between versions 1.76 and 1.77

version 1.76, 2008/03/18 22:00:28 version 1.77, 2008/04/30 23:52:00
Line 36  use Apache::lonlocal; Line 36  use Apache::lonlocal;
 use Apache::loncoursedata();  use Apache::loncoursedata();
 use Apache::lonnavmaps();  use Apache::lonnavmaps();
 use Apache::lonuserstate;  use Apache::lonuserstate;
   use Apache::lonuserutils; 
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
 use Time::Local;  use Time::Local;
 use GDBM_File;  use GDBM_File;
Line 68  sub handler { Line 69  sub handler {
     ['vgr','abovethreshold',1],      ['vgr','abovethreshold',1],
     ['opa','haserrors',1],      ['opa','haserrors',1],
     ['mdc','versionchanges',0],      ['mdc','versionchanges',0],
                               ['vcl','newroles',1],
                               ['vcl','oldroles',1],
     ) {      ) {
  my ($perm,$key,$check_section) = @{ $perm_check };   my ($perm,$key,$check_section) = @{ $perm_check };
  my $scope = $env{'request.course.id'};   my $scope = $env{'request.course.id'};
Line 125  sub handler { Line 128  sub handler {
         $r->print(&Apache::lonhtmlcommon::breadcrumbs          $r->print(&Apache::lonhtmlcommon::breadcrumbs
             ("What's New?",#'Course_Action_Items_Initialization'              ("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 {      } else {
         $r->print(&Apache::lonhtmlcommon::breadcrumbs          $r->print(&Apache::lonhtmlcommon::breadcrumbs
             ("What's New?",#'Course_Action_Items_Display'              ("What's New?",#'Course_Action_Items_Display'
Line 152  sub display_main_box { Line 169  sub display_main_box {
                          degdiff => 'Degree of difficulty',                           degdiff => 'Degree of difficulty',
                          numstudents => 'Total number of students with submissions',                           numstudents => 'Total number of students with submissions',
     );      );
       my %versions = &Apache::lonlocal::texthash (
     my %interval_titles = &Apache::lonlocal::texthash (                         -1 => "version changes since start of $lctype",
                             -1 => "since start of $lctype",                    2592000 => 'version changes since last month',
                        2592000 => 'since last month',                     604800 => 'version changes since last week',
                         604800 => 'since last week',                      86400 => 'version changes since yesterday',
                          86400 => '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 (      my %initpage = &Apache::lonlocal::texthash (
                      firstres => "first resource in the $lctype",                       firstres => "first resource in the $lctype",
                      whatsnew => "what's new? page",                       whatsnew => "what's new? page",
Line 175  sub display_main_box { Line 207  sub display_main_box {
                                                                    $cdom,$crs);                                                                     $cdom,$crs);
     } elsif (($command eq 'chginterval')       } elsif (($command eq 'chginterval') 
      && $checkallowed->{'versionchanges'}) {       && $checkallowed->{'versionchanges'}) {
         &display_interval_config($r,$refpage,\%interval_titles);          &display_interval_config($r,$refpage,\%interval_titles,'versions');
     } elsif (($command eq 'chgdisc')       } elsif (($command eq 'chgdisc') 
      && $checkallowed->{'coursediscussion'}) {       && $checkallowed->{'coursediscussion'}) {
         &display_discussion_config($r,$refpage);          &display_discussion_config($r,$refpage);
     } elsif ($command eq 'courseinit') {      } elsif ($command eq 'courseinit') {
         &courseinit_config($r,$refpage,\%initpage);          &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 {      } else {
         &display_actions_box($r,$command,$refpage,\%threshold_titles,          &display_actions_box($r,$command,$refpage,\%threshold_titles,
                         \%interval_titles,\%initpage,$cdom,$crs,$checkallowed);                          \%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
Line 205  sub display_header { Line 243  sub display_header {
     my ($command,$checkallowed) = @_;      my ($command,$checkallowed) = @_;
           
     my $scripttag;      my $scripttag;
     unless ($command eq 'chgthreshold' || $command eq 'chginterval') {      unless ($command eq 'chgthreshold' || $command eq 'chginterval' || 
               $command eq 'chgoldroleinterval' || $command eq 'chgnewroleinterval') {
        $scripttag = <<"END";         $scripttag = <<"END";
 <script type="text/javascript">  <script type="text/javascript">
 function change_display(caller,change) {  function change_display(caller,change) {
     caller.value = change;      caller.value = change;
     document.visible.submit();       document.visible.submit();
 }  }
   
 function changeAll(change) {  function changeAll(change) {
Line 271  sub display_actions_box { Line 310  sub display_actions_box {
     my @warnings = ();      my @warnings = ();
     my $msgcount = 0;      my $msgcount = 0;
     my $critmsgcount = 0;      my $critmsgcount = 0;
       my $expirecount;
       my %expired;
       my $activecount;
       my %activated;
     my %res_title = ();      my %res_title = ();
     my %show = ();      my %show = ();
     my $needitems = 0;      my $needitems = 0;
Line 345  sub display_actions_box { Line 387  sub display_actions_box {
     }      }
     $r->rflush();      $r->rflush();
   
       my (%timediff,%interval);
     my %display_settings = &get_display_settings($uname,$udom,$cid);      my %display_settings = &get_display_settings($uname,$udom,$cid);
     my $timediff = $display_settings{$cid.':interval'};      $timediff{'versions'} = $display_settings{$cid.':interval'};
     unless (defined($timediff)) { $timediff = 604800; }       unless (defined($timediff{'versions'})) { $timediff{'versions'} = 604800; } 
     my $now = time;      $interval{'versions'} = $interval_titles->{'versions'}->{$timediff{'versions'}};
     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';  
     }  
   
     my %headings = &Apache::lonlocal::texthash(      my %headings = &Apache::lonlocal::texthash(
                 coursediscussion =>  'Unread '.$lctype.' discussion posts',                  coursediscussion => 'Unread '.$lctype.' discussion posts',
                 handgrading =>  'Problems requiring handgrading',                  handgrading      => 'Problems requiring handgrading',
                 haserrors => 'Problems with errors',                  haserrors        => 'Problems with errors',
                 versionchanges => 'Resources in '.$lctype.' with version changes '.$interval,  
                 coursenormalmail => 'New '.$lctype.' messages',                  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'}) {      if ($$checkallowed{'abovethreshold'}) {
         &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);          &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
     }      }
Line 378  sub display_actions_box { Line 468  sub display_actions_box {
     $threshold{'av_attempts'},$threshold{'degdiff'},      $threshold{'av_attempts'},$threshold{'degdiff'},
     $threshold{'numstudents'});      $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})) {      foreach my $key (keys(%{$checkallowed})) {
  if ($key =~ /_section$/) { next; }   if ($key =~ /_section$/) { next; }
Line 391  sub display_actions_box { Line 481  sub display_actions_box {
     }      }
   
     foreach my $item (@actionorder) {      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}) {              if ($show{$item}) {
                 $needitems = 1;                  $needitems = 1;
                 last;                  last;
Line 408  sub display_actions_box { Line 499  sub display_actions_box {
     if ($show{'coursecritmail'}) {      if ($show{'coursecritmail'}) {
         $critmsgcount = &getcritmail(\@critmsgs);          $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>      $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
      &nbsp;&nbsp;<a href="javascript:changeAll('show');">$lt{'shal'}</a>       &nbsp;&nbsp;<a href="javascript:changeAll('show');">$lt{'shal'}</a>
      <form method="post" name="visible" action="/adm/whatsnew">\n|);       <form method="post" name="visible" action="/adm/whatsnew">\n|);
Line 430  sub display_actions_box { Line 526  sub display_actions_box {
             $totalboxes ++;              $totalboxes ++;
         }          }
     }      }
     my $halfway = int($totalboxes/2) + $totalboxes%2;      my $halfway = 4;
   #    my $halfway = int($totalboxes/2) + $totalboxes%2;
     foreach my $actionitem (@actionorder) {      foreach my $actionitem (@actionorder) {
         if ($$checkallowed{$actionitem}) {          if ($$checkallowed{$actionitem}) {
             if ($displayed == $halfway) {              if ($displayed == $halfway) {
                 $r->print('</td><td>&nbsp;</td><td class="LC_right_col" >');                  $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 ++;               $displayed ++; 
         }          }
     }      }
Line 510  sub display_threshold_config { Line 607  sub display_threshold_config {
 #-------------------------------  #-------------------------------
                                                                                                                                                                         
 sub display_interval_config {  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 $lctype = lc(&Apache::loncommon::course_type());
     my $current = &get_current($env{'user.name'},$env{'user.domain'},      my $current = &get_current($env{'user.name'},$env{'user.domain'},
                                 $env{'request.course.id'},'interval');                                  $env{'request.course.id'},$setting);
     $r->print('<br />'.&mt('Choose the time window to use for display of version changes for resources in the '.$lctype.'.').'<br />');      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 '') {      unless ($current eq '') {
         $r->print(' '.&mt('Current value is [_1].','<b>'.          if (ref($interval_titles->{$context}) eq 'HASH') {
                   $$interval_titles{$current}.'</b>'));              $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">  <form method="post" name="intervalswitch" action="/adm/whatsnew">
 <input type="hidden" name="command" value="newinterval" />  <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">  <select name="interval">
   <option value="" selected="selected">Select</option>
 ');  ');
     foreach my $key (reverse sort ({$a cmp $b} (keys(%{$interval_titles})))) {      if (ref($interval_titles) eq 'HASH') {
         $r->print('<option value="'.$key.'">'.&mt('Version changes').' '.$$interval_titles{$key}.          if (ref($interval_titles->{$context}) eq 'HASH') {
                   '</option>'."\n");              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;      $r->print('</select>&nbsp;&nbsp;
                <input type="submit" name="display" value="'.                 <input type="submit" name="display" value="'.
Line 661  sub display_launcher { Line 779  sub display_launcher {
     my ($r,$action,$refpage,$checkallowed,$show,$headings,$res_title,      my ($r,$action,$refpage,$checkallowed,$show,$headings,$res_title,
         $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered,          $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered,
         $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs,          $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs,
         $interval,$countunread) = @_;          $interval,$countunread,$expired,$expirecount,$activated,$activecount,
           $crstype) = @_;
   
     if ($$checkallowed{$action}) {      if ($$checkallowed{$action}) {
         &start_box($r,$show,$headings,$action,$refpage,$action);          &start_box($r,$show,$headings,$action,$refpage,$action);
Line 671  sub display_launcher { Line 790  sub display_launcher {
             } elsif ($action eq 'haserrors') { # BOMBS              } elsif ($action eq 'haserrors') { # BOMBS
                 &display_haserrors($r,$bombs,$bombed,$res_title);                  &display_haserrors($r,$bombs,$bombed,$res_title);
             } elsif ($action eq 'versionchanges') { # VERSION CHANGES              } 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              } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
                 &display_abovethreshold($r,$refpage,$warnings,$triggered,                  &display_abovethreshold($r,$refpage,$warnings,$triggered,
  $res_title);   $res_title);
Line 682  sub display_launcher { Line 801  sub display_launcher {
                 &display_coursenormalmail($r,$msgcount,$newmsgs);                  &display_coursenormalmail($r,$msgcount,$newmsgs);
             } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES              } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
                 &display_coursecritmail($r,$critmsgcount,$critmsgs);                  &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);          &end_box($r);
Line 1074  sub getcritmail { Line 1199  sub getcritmail {
     return $critmsgcount;      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 {  sub checkversions {
     my ($cdom,$crs,$navmap,$changed,$starttime) = @_;      my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
Line 1239  sub display_versionchanges { Line 1563  sub display_versionchanges {
         'revd' => 'Last revised',          'revd' => 'Last revised',
         'newv' => 'New version',          'newv' => 'New version',
         'veru' => 'Version used',          'veru' => 'Version used',
         'noup' => 'No updated versions',           'noup' => 'No', 
     );      );
     if (keys(%{$changed}) > 0) {      if (keys(%{$changed}) > 0) {
         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.          $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
Line 1267  sub display_versionchanges { Line 1591  sub display_versionchanges {
     }      }
     return;      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 {  sub display_coursediscussion {
     my ($r,$newdiscussions,$unread,$countunread,$res_title) = @_;      my ($r,$newdiscussions,$unread,$countunread,$res_title) = @_;
Line 1420  sub store_interval_setting { Line 1802  sub store_interval_setting {
     my ($uname,$udom,$cid,$interval_titles) = @_;      my ($uname,$udom,$cid,$interval_titles) = @_;
     my %interval_settings = ();      my %interval_settings = ();
     my $result;      my $result;
     if (defined($env{'form.interval'})) {      my $context = $env{'form.intervaltype'};
         $interval_settings{$cid.':interval'} = $env{'form.interval'};      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',          my $outcome = &Apache::lonnet::put('nohist_whatsnew',
                                              \%interval_settings,$udom,$uname);                                               \%interval_settings,$udom,$uname);
         if ($outcome eq 'ok') {          if ($outcome eq 'ok') {
             $result = &mt('Interval set to version changes [_1]',              if (ref($interval_titles->{$context}) eq 'HASH') {
                   '<b>'.$$interval_titles{$env{'form.interval'}}.'</b>').'<br />';                  $result = &mt('New filter setting: [_1].','<b>'. 
                                 $interval_titles->{$context}->{$env{'form.interval'}}.'</b>').'<br />';
               }
         } else {          } else {
     my $lctype = lc(&Apache::loncommon::course_type());      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);                  ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
             $result = &mt('Unable to set interval to [_1] due to [_2].',              $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 />');                           '<tt>'.$outcome.'</tt>.<br />');
         }          }
     }      }
Line 1556  sub start_box { Line 1946  sub start_box {
                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>                  <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
               </tr>');                </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('      $r->print('
               <tr>                <tr>

Removed from v.1.76  
changed lines
  Added in v.1.77


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>