--- loncom/interface/lonwhatsnew.pm 2009/02/18 19:34:08 1.87
+++ loncom/interface/lonwhatsnew.pm 2020/03/30 11:15:09 1.105.2.16
@@ -1,5 +1,5 @@
#
-# $Id: lonwhatsnew.pm,v 1.87 2009/02/18 19:34:08 schafran Exp $
+# $Id: lonwhatsnew.pm,v 1.105.2.16 2020/03/30 11:15:09 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,6 +42,7 @@ use Time::Local;
use GDBM_File;
use lib '/home/httpd/lib/perl/';
use LONCAPA;
+use HTML::Entities;
#----------------------------
# handler
@@ -61,16 +62,37 @@ sub handler {
my $command = $env{'form.command'};
my $refpage = $env{'form.refpage'};
- my %checkallowed = ( coursenormalmail => 1,
- coursecritmail => 1, );
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+
+ my ($isadhoc,%checkallowed);
+
+ if ($env{'request.role'} =~ m{^(cc|co)/}) {
+ my $rolecode = $1;
+ if ($env{"environment.internal.$cdom.$crs.$env{'request.role'}.adhoc"}) {
+ $isadhoc = 1;
+ }
+ } elsif ($env{'request.role'} =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)\./}) {
+ my $rolename = $1;
+ if ($env{"environment.internal.$cdom.$crs.cr/$cdom/$cdom-domainconfig/$rolename.adhoc"}) {
+ $isadhoc = 1;
+ }
+ }
+ unless ($isadhoc) {
+ %checkallowed = ( coursenormalmail => 1,
+ coursecritmail => 1,);
+ }
foreach my $perm_check (['whn','whatsnew',1],
['pch','coursediscussion',1],
['mgr','handgrading',1],
['vgr','abovethreshold',1],
- ['opa','haserrors',1],
- ['mdc','versionchanges',0],
+ ['vgr','haserrors',1],
+ ['whn','versionchanges',1],
['vcl','newroles',1],
['vcl','oldroles',1],
+ ['whn','crslogin',1],
+ ['vcl','sessions',1],
+ ['mgr','resetcounters',1],
) {
my ($perm,$key,$check_section) = @{ $perm_check };
my $scope = $env{'request.course.id'};
@@ -87,7 +109,7 @@ sub handler {
if ( ! $env{'request.course.fn'} || ! $checkallowed{'whatsnew'}) {
# Not in a course, or no whn priv in course
- $env{'user.error.msg'}="/adm/whatsnew::whn:0:0:Cannot display what's new page";
+ $env{'user.error.msg'}="/adm/whatsnew:whn:0:0:Cannot display what's new page";
return HTTP_NOT_ACCEPTABLE;
}
@@ -99,7 +121,7 @@ sub handler {
&Apache::lonhtmlcommon::clear_breadcrumbs();
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/whatsnew',
- text=>"Display Action Items"});
+ text=>"What's New?"});
if (($command eq 'chgthreshold') && $checkallowed{'abovethreshold'}) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/whatsnew?command=chgthreshold&refpage='.$refpage,
@@ -142,12 +164,26 @@ sub handler {
$r->print(&Apache::lonhtmlcommon::breadcrumbs
("What's New?",#'Course_Action_Items_Intervals'
));
+ } elsif ($command eq 'chgcrslogininterval' && $checkallowed{'crslogin'}) {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/whatsnew?command=chgcrslogininterval&refpage='.$refpage,
+ text=>"Change interval"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs
+ ("What's New?",#'Course_Action_Items_Intervals'
+ ));
+ } elsif ($command eq 'chgsessionlimit' && $checkallowed{'sessions'}) {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/whatsnew?command=chgsessionlimit&refpage='.$refpage,
+ text=>"Change session range"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs
+ ("What's New?",#'Course_Action_Items_Sessions'
+ ));
} else {
$r->print(&Apache::lonhtmlcommon::breadcrumbs
("What's New?",#'Course_Action_Items_Display'
));
}
- &display_main_box($r,$command,$refpage,\%checkallowed);
+ &display_main_box($r,$command,$refpage,\%checkallowed,$cdom,$crs);
return OK;
}
@@ -158,7 +194,7 @@ sub handler {
#------------------------------
sub display_main_box {
- my ($r,$command,$refpage,$checkallowed) = @_;
+ my ($r,$command,$refpage,$checkallowed,$cdom,$crs) = @_;
my $domain=&Apache::loncommon::determinedomain();
my $function = &Apache::loncommon::get_users_function();
my $lctype = lc(&Apache::loncommon::course_type());
@@ -187,24 +223,36 @@ sub display_main_box {
604800 => 'roles which expired since last week',
86400 => 'roles which expired since yesterday',
);
+ my %crslogins = (
+ -1 => 'last logins for anyone who has ever logged in',
+ 2592000 => 'last logins for users in last 30 days',
+ 604800 => 'last logins for users in last 7 days',
+ 86400 => 'last logins for users in last 24 hours',
+ );
+ my %sessions = (
+ 300 => 'course sessions active in the last 5 minutes',
+ 600 => 'course sessions active in the last 10 minutes',
+ 1800 => 'course sessions active in the last 30 minutes',
+ 7200 => 'course sessions active in the last 2 hours',
+ -7200 => 'course sessions with last activity more than 2 hours ago',
+ );
my %interval_titles = (
versions => \%versions,
newroles => \%newroles,
oldroles => \%oldroles,
+ crslogin => \%crslogins,
+ sessions => \%sessions,
);
my %initpage = &Apache::lonlocal::texthash (
firstres => "first resource in the $lctype",
- whatsnew => "what's new? page",
+ whatsnew => "What's New Page",
userpref => 'your general user preferences',
coursespecific => "specific setting for this $lctype",
);
- my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
if (($command eq 'chgthreshold')
&& $checkallowed->{'abovethreshold'}) {
- &display_threshold_config($r,$refpage,\%threshold_titles,
- $cdom,$crs);
+ &display_threshold_config($r,$refpage,\%threshold_titles,$cdom,$crs);
} elsif (($command eq 'chginterval')
&& $checkallowed->{'versionchanges'}) {
&display_interval_config($r,$refpage,\%interval_titles,'versions');
@@ -219,6 +267,12 @@ sub display_main_box {
} elsif (($command eq 'chgoldroleinterval')
&& $checkallowed->{'oldroles'}) {
&display_interval_config($r,$refpage,\%interval_titles,'oldroles');
+ } elsif (($command eq 'chgcrslogininterval')
+ && $checkallowed->{'crslogin'}) {
+ &display_interval_config($r,$refpage,\%interval_titles,'crslogin');
+ } elsif (($command eq 'chgsessionlimit')
+ && $checkallowed->{'sessions'}) {
+ &display_interval_config($r,$refpage,\%interval_titles,'sessions');
} else {
&display_actions_box($r,$command,$refpage,\%threshold_titles,
\%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
@@ -244,9 +298,11 @@ sub display_header {
my $scripttag;
unless ($command eq 'chgthreshold' || $command eq 'chginterval' ||
- $command eq 'chgoldroleinterval' || $command eq 'chgnewroleinterval') {
+ $command eq 'chgoldroleinterval' ||
+ $command eq 'chgnewroleinterval' || $command eq 'chgcrslogininterval') {
$scripttag = <<"END";
-';
+ENDTOGG
}
my $course_type=&Apache::loncommon::course_type();
- return &Apache::loncommon::start_page($course_type.' Action Items',
+ return &Apache::loncommon::start_page("What's New?",
$scripttag);
}
@@ -288,7 +396,7 @@ sub display_actions_box {
my $lctype = lc($crstype);
my %stulabel = (
'Course' => 'students',
- 'Group' => 'members',
+ 'Community' => 'members',
);
my %lt = &Apache::lonlocal::texthash(
'yacc' => 'You are accessing an invalid course',
@@ -314,6 +422,10 @@ sub display_actions_box {
my %expired;
my $activecount;
my %activated;
+ my %loggedin;
+ my $logincount;
+ my %sessions;
+ my $sessioncount;
my %res_title = ();
my %show = ();
my $needitems = 0;
@@ -327,7 +439,7 @@ sub display_actions_box {
my %threshold = ();
my %pagedesc = &Apache::lonlocal::texthash (
firstres => 'First resource',
- whatsnew => "What's New? page",
+ whatsnew => "What's New Page",
userpref => 'user preference',
coursespecific => $lctype.' only',
default => 'default',
@@ -341,30 +453,33 @@ sub display_actions_box {
return;
}
+ my $header = '';
if ($refpage eq 'start') {
if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
&GDBM_READER(),0640)) {
- my $furl=$bighash{'first_url'};
+ my $furl=&HTML::Entities::encode($bighash{'first_url'},'"<>&');
untie(%bighash);
- $r->print(''.$lt{'gtfr'}.
- '
');
+ $header .= ''.$lt{'gtfr'}.
+ '
';
}
}
- $r->print(&mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
+ $header .= &mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
.' '
.&mt('Currently: [_1].',''.$currinit.'')
.' '
- .&mt('[_1]Change[_2] for just [_3]this course[_4] or for all [_5]your courses[_6].'
+ .&mt('[_1]Change[_2] for just [_3]this '.$lctype.'[_4] or for [_5]all your courses/communities[_6].'
,''
,''
,''
,''
,''
,'')
- .'
');
+ $r->print('
'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' expired.').' '); } elsif ($context eq 'newroles') { $r->print(' '.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' became available.').' '); + } elsif ($context eq 'crslogin') { + $r->print(' '.&mt('Choose the time window to use to display the last login by a user in the '.$lctype).' '); + } elsif ($context eq 'sessions') { + $r->print(' '.&mt('Choose the time limit to use to display active user sessions in the '.$lctype.'.').' '); } else { $r->print(' '.&mt('Choose the time window to use to display resources in the '.$lctype.' with version changes.').' '); } @@ -642,7 +831,14 @@ sub display_interval_config { '); 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}})))) { + my @sorted; + if ($context eq 'sessions') { + @sorted = sort { $a <=> $b } (keys(%{$interval_titles->{$context}})); + push(@sorted,shift(@sorted)); + } else { + @sorted = reverse sort ({$a cmp $b} (keys(%{$interval_titles->{$context}}))); + } + foreach my $key (@sorted) { $r->print(''."\n"); } @@ -683,9 +879,9 @@ function toggle_countunread(choice) { $r->print(' ' .&mt('Choose whether or not to display a count of the number of new posts for each resource or discussion board which has unread posts.') .' ' - .&mt("This can increase the time taken to gather data for the 'What's New?' page by a few seconds.") + .&mt("This can increase the time taken to gather data for the [_1]What's New Page[_2] by a few seconds.",'','') .' ' - .&mt('Currently set to [_1].',''.$current.'.') + .&mt('Currently set to [_1].',''.$current.'') ); $r->print(' | ||||||
'.$itemserror.' | ||||||
'.&Apache::lonlocal::locallocaltime($item).' | '. ''.$link.' | '. @@ -1667,6 +2009,111 @@ sub display_rolechanges { } return; } + +sub display_activity { + my ($r,$context,$count,$details,$interval,$crstype,$classlist) = @_; + return unless (ref($classlist) eq 'HASH'); + my %lt = &Apache::lonlocal::texthash( + 'user' => 'User', + 'role' => 'Role', + 'sec' => 'Section', + 'number' => 'Total number of logins', + ); + my $prefix = 'login'; + if ($context eq 'sessions') { + $lt{'number'} = &mt('Total number of active user sessions'); + $lt{'active'} = &mt('Last active'); + $prefix = 'session'; + } + if ($count) { + + my $hdr = '|||||
'.$lt{'number'}.' | '. + ''.$lt{'role'}.' | '. + ''.$lt{'sec'}; + my (%bylastname,%counts); + if (ref($details) eq 'HASH') { + my @items = sort { $b <=> $a } (keys(%{$details})); + my $num = 0; + my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME(); + foreach my $item (@items) { + if (ref($details->{$item}) eq 'ARRAY') { + foreach my $user (@{$details->{$item}}) { + if (ref($user) eq 'HASH') { + my $section; + my $role = + &Apache::lonnet::plaintext($user->{'role'},$crstype); + if ($user->{'section'} eq '') { + $section = &mt('none'); + } else { + $section = $user->{'section'}; + } + $counts{$user->{'role'}}{$section} ++; + my $uname = $user->{'uname'}; + my $udom = $user->{'udom'}; + my $fullname; + if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') { + $fullname = $classlist->{$uname.':'.$udom}->[$fullnameidx]; + } else { + $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname'); + } + my $link = + &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom); + my $entry = ' | '.$link.' | '. + ''.$role.' | '. + ''.$section.' | '; + if ($context eq 'sessions') { + $entry .= ''.&Apache::lonlocal::locallocaltime($item).' | '; + } + push(@{$bylastname{$fullname}},$entry); + } + } + } + } + my $table; + foreach my $person (sort(keys(%bylastname))) { + if (ref($bylastname{$person}) eq 'ARRAY') { + foreach my $item (@{$bylastname{$person}}) { + $num ++; + my $css_class = $num%2?' class="LC_odd_row"':''; + $table .= '
'.$counts{$role}{$sec}.' | '. + ''.$showrole.' | '. + ''.$sec.' | ||||
'. + &mt('There are no '.$interval). + ' | ||||||
'.$lt{'chth'}.' | +'.$lt{'chth'}.' | |||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | |||||
'.$lt{'chop'}.' | +'.$lt{'chop'}.' | |||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | |||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | |||||
'.$lt{'chin'}.' | +||||||
'.$lt{'chin'}.' | +||||||