--- loncom/interface/lonwhatsnew.pm 2010/09/19 15:05:59 1.98.2.4
+++ loncom/interface/lonwhatsnew.pm 2020/09/01 22:25:27 1.128
@@ -1,5 +1,7 @@
+# The LearningOnline Network
+# What's New in a course
#
-# $Id: lonwhatsnew.pm,v 1.98.2.4 2010/09/19 15:05:59 raeburn Exp $
+# $Id: lonwhatsnew.pm,v 1.128 2020/09/01 22:25:27 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -62,17 +64,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'};
@@ -89,7 +111,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;
}
@@ -151,12 +173,19 @@ sub handler {
$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;
}
@@ -167,7 +196,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());
@@ -202,11 +231,19 @@ sub display_main_box {
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",
@@ -214,13 +251,10 @@ sub display_main_box {
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');
@@ -237,7 +271,10 @@ sub display_main_box {
&display_interval_config($r,$refpage,\%interval_titles,'oldroles');
} elsif (($command eq 'chgcrslogininterval')
&& $checkallowed->{'crslogin'}) {
- &display_interval_config($r,$refpage,\%interval_titles,'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);
@@ -263,7 +300,7 @@ sub display_header {
my $scripttag;
unless ($command eq 'chgthreshold' || $command eq 'chginterval' ||
- $command eq 'chgoldroleinterval' ||
+ $command eq 'chgoldroleinterval' ||
$command eq 'chgnewroleinterval' || $command eq 'chgcrslogininterval') {
$scripttag = <<"END";
-';
+ENDTOGG
}
my $course_type=&Apache::loncommon::course_type();
return &Apache::loncommon::start_page("What's New?",
@@ -348,7 +391,6 @@ function togglelogins() {
sub display_actions_box {
my ($r,$command,$refpage,$threshold_titles,$interval_titles,$initpage,
$cdom,$crs,$checkallowed) = @_;
- my $custommenu = &Apache::loncommon::needs_gci_custom();
my $udom = $env{'user.domain'};
my $uname = $env{'user.name'};
my $cid = $env{'request.course.id'};
@@ -384,6 +426,8 @@ sub display_actions_box {
my %activated;
my %loggedin;
my $logincount;
+ my %sessions;
+ my $sessioncount;
my %res_title = ();
my %show = ();
my $needitems = 0;
@@ -412,7 +456,7 @@ sub display_actions_box {
}
my $header = '';
- if (($refpage eq 'start') && (!$custommenu)) {
+ if ($refpage eq 'start') {
if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
&GDBM_READER(),0640)) {
my $furl=&HTML::Entities::encode($bighash{'first_url'},'"<>&');
@@ -421,8 +465,7 @@ sub display_actions_box {
'
';
}
}
- unless ($custommenu) {
- $header .= &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.'')
.' '
@@ -435,11 +478,10 @@ sub display_actions_box {
,'')
.' ';
- $r->print(&Apache::loncommon::head_subbox($header));
- }
+ $r->print(&Apache::loncommon::head_subbox($header));
if ($command eq 'reset') {
- $result = &process_reset($cdom,$crs);
+ $result = &process_reset($cdom,$crs,$checkallowed);
} elsif ($command eq 'update') {
$result = &process_update($uname,$udom,$threshold_titles);
} elsif ($command eq 'newinterval') {
@@ -530,52 +572,76 @@ sub display_actions_box {
$headings{'crslogin'} = &mt('Last login for users in last 24 hours');
}
- my $now = time;
+ $timediff{'sessions'} = $display_settings{$cid.':sessionactivity'};
+ unless (defined($timediff{'sessions'})) { $timediff{'sessions'} = 7200; }
+ $interval{'sessions'} = $interval_titles->{'sessions'}->{$timediff{'sessions'}};
+
+ if ($timediff{'sessions'} == -7200) {
+ $headings{'sessions'} = &mt('Session with activity more than 2 hours ago');
+ } elsif ($timediff{'sessions'} == 7200) {
+ $headings{'sessions'} = &mt('Session with activity in last 2 hours');
+ } elsif ($timediff{'sessions'} == 1800) {
+ $headings{'sessions'} = &mt('Session with activity in last 30 minutes');
+ } elsif ($timediff{'sessions'} == 600) {
+ $headings{'sessions'} = &mt('Session with activity in last 10 minutes');
+ } elsif ($timediff{'sessions'} == 300) {
+ $headings{'sessions'} = &mt('Session with activity in last 5 minutes');
+ }
+
+ my ($now,$starttime,$activatedstart,$expiredstart,$crsloginstart);
+ $now = time;
+
if ($timediff{'versions'} == -1) {
- $timediff{'versions'} = time;
+ $starttime = 0;
+ } else {
+ $starttime = $now - $timediff{'versions'};
}
- my $starttime = $now - $timediff{'versions'};
if ($timediff{'newroles'} == -1) {
- $timediff{'newroles'} = time;
+ $activatedstart = 0;
+ } else {
+ $activatedstart = $now - $timediff{'newroles'};
}
- my $activatedstart = $now - $timediff{'newroles'};
if ($timediff{'oldroles'} == -1) {
- $timediff{'oldroles'} = time;
+ $expiredstart = 0;
+ } else {
+ $expiredstart = $now - $timediff{'oldroles'};
}
- my $expiredstart = $now - $timediff{'oldroles'};
-
if ($timediff{'crslogin'} == -1) {
- $timediff{'crslogin'} = time;
+ $crsloginstart = 0;
+ } else {
+ $crsloginstart = $now - $timediff{'crslogin'};
}
- my $crsloginstart = $now - $timediff{'crslogin'};
-
my $countunread = $display_settings{$cid.':countunread'};
unless (defined($countunread)) {
$countunread = 'on';
}
if ($$checkallowed{'abovethreshold'}) {
- &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs,$custommenu);
+ &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
}
- if ($custommenu) {
- $headings{'abovethreshold'} = &mt('Questions with submissions');
- } else {
- $headings{'abovethreshold'} =
- &mt('(Problems with av. attempts ≥ [_1] or deg. difficulty ≥ [_2]) [_3] and total number of '.$stulabel{$crstype}.' with submissions ≥ [_4]',
- $threshold{'av_attempts'},$threshold{'degdiff'},
- '
',$threshold{'numstudents'});
- }
-
- my @actionorder;
- if ($custommenu) {
- @actionorder = ('coursenormalmail','coursecritmail','abovethreshold','newroles','oldroles','crslogin');
- } else {
- @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles');
- }
+ $headings{'abovethreshold'} =
+ &mt('(Problems with av. attempts ≥ [_1] or deg. difficulty ≥ [_2]) [_3] and total number of '.$stulabel{$crstype}.' with submissions ≥ [_4]',
+ $threshold{'av_attempts'},$threshold{'degdiff'},
+ '
',$threshold{'numstudents'});
+
+ my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles','crslogin','sessions');
+ my %actioncolumn = (
+ handgrading => 'left',
+ haserrors => 'left',
+ abovethreshold => 'left',
+ versionchanges => 'left',
+ coursediscussion => 'right',
+ coursenormalmail => 'right',
+ coursecritmail => 'right',
+ newroles => 'right',
+ oldroles => 'right',
+ crslogin => 'right',
+ sessions => 'right',
+ );
foreach my $key (keys(%{$checkallowed})) {
if ($key =~ /_section$/) { next; }
@@ -589,7 +655,8 @@ sub display_actions_box {
foreach my $item (@actionorder) {
unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail' ||
- $item eq 'newroles' || $item eq 'oldroles') {
+ $item eq 'newroles' || $item eq 'oldroles' ||
+ $item eq 'crslogin' || $item eq 'sessions') {
if ($show{$item}) {
$needitems = 1;
last;
@@ -599,7 +666,11 @@ sub display_actions_box {
my $itemserror;
if ($needitems) {
- $itemserror = &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread,$custommenu);
+ $itemserror = &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread,$checkallowed);
+ }
+ my $classlist;
+ if ($show{'oldroles'} || $show{'newroles'} || $show{'crslogin'} || $show{'sessions'}) {
+ $classlist = &Apache::loncoursedata::get_classlist();
}
if ($show{'coursenormalmail'}) {
$msgcount = &getnormalmail(\@newmsgs);
@@ -608,15 +679,17 @@ sub display_actions_box {
$critmsgcount = &getcritmail(\@critmsgs);
}
if ($show{'oldroles'}) {
- $expirecount = &getexpired(\%expired,$expiredstart,'previous');
+ $expirecount = &getexpired(\%expired,$expiredstart,'previous',$classlist);
}
if ($show{'newroles'}) {
- $activecount = &getactivated(\%activated,$activatedstart,'active');
+ $activecount = &getactivated(\%activated,$activatedstart,'active',$classlist);
}
if ($show{'crslogin'}) {
$logincount = &getloggedin($cdom,$crs,\%loggedin,$crsloginstart);
}
-
+ if ($show{'sessions'}) {
+ $sessioncount = &getsessions($cdom,$crs,\%sessions,$timediff{'sessions'},$classlist);
+ }
$r->print(qq|$lt{'hial'}
$lt{'shal'}
');
+ $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.').' '); } @@ -765,7 +834,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"); } @@ -796,21 +872,19 @@ sub display_discussion_config { 'off' => 'on', ); $r->print(''); $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 [_1]What's New Page[_2] by a few seconds.",'','') .' ' - .&mt('Currently set to [_1].',''.$current.'.') + .&mt('Currently set to [_1].',''.$current.'') ); $r->print(' '); + if ($checkallowed->{'resetcounters'}) { + $r->print(' | |||||||||
'.$itemserror.' | |||||||||
'.&Apache::lonlocal::locallocaltime($item).' | '. ''.$link.' | '. @@ -1863,36 +2036,47 @@ sub display_rolechanges { return; } -sub display_crslogins { - my ($r,$logincount,$loggedin,$interval,$crstype) = @_; +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', ); - if ($logincount) { - - my $hdr = '||||||||
'.$lt{'number'}.' | '. - ''.$lt{'role'}.' | '. - ''.$lt{'sec'}; + ' | '.$lt{'sec'}.' | '; + if ($context eq 'sessions') { + $hdr .= ''.$lt{'active'}.' | '; + } + $hdr .= '|||||
'.$lt{'number'}.' | '. + ''.$lt{'role'}.' | '. + ''.$lt{'sec'}; my (%bylastname,%counts); - if (ref($loggedin) eq 'HASH') { - my @logins = sort { $b <=> $a } (keys(%{$loggedin})); - my $numlogin = 0; - foreach my $item (@logins) { - if (ref($loggedin->{$item}) eq 'ARRAY') { - foreach my $user (@{$loggedin->{$item}}) { + 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); - my $status = &mt($user->{'status'}); if ($user->{'section'} eq '') { $section = &mt('none'); } else { @@ -1901,54 +2085,62 @@ sub display_crslogins { $counts{$user->{'role'}}{$section} ++; my $uname = $user->{'uname'}; my $udom = $user->{'udom'}; - my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname'); + 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); - push(@{$bylastname{$fullname}}, - ' | '.$link.' | '. - ''.$role.' | '. - ''.$section.' | '); + 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}}) { - $numlogin ++; - my $css_class = $numlogin%2?' class="LC_odd_row"':''; - $table .= '
'.$counts{$role}{$sec}.' | '. ''.$showrole.' | '. ''.$sec.' | |||||||
'. &mt('There are no '.$interval). - ' | '.$showhide.' | '); if (($caller eq 'abovethreshold') && ($$show{$caller})) { - if ($$show{$caller} && !$custommenu) { + if ($$show{$caller}) { $r->print('||||||||
---|---|---|---|---|---|---|---|---|---|
'.$lt{'chth'}.' | @@ -2266,15 +2459,21 @@ sub start_box {'.$lt{'chin'}.' | ||||||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | ||||||||
'.$lt{'chin'}.' | +|||||||||