[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface lonwhatsnew.pm
raeburn
raeburn at source.lon-capa.org
Mon Mar 30 07:15:09 EDT 2020
raeburn Mon Mar 30 11:15:09 2020 EDT
Modified files: (Branch: version_2_11_X)
/loncom/interface lonwhatsnew.pm
Log:
- For 2.11
- Baclport 1.126
-------------- next part --------------
Index: loncom/interface/lonwhatsnew.pm
diff -u loncom/interface/lonwhatsnew.pm:1.105.2.15 loncom/interface/lonwhatsnew.pm:1.105.2.16
--- loncom/interface/lonwhatsnew.pm:1.105.2.15 Wed Sep 13 23:54:07 2017
+++ loncom/interface/lonwhatsnew.pm Mon Mar 30 11:15:09 2020
@@ -1,5 +1,5 @@
#
-# $Id: lonwhatsnew.pm,v 1.105.2.15 2017/09/13 23:54:07 raeburn Exp $
+# $Id: lonwhatsnew.pm,v 1.105.2.16 2020/03/30 11:15:09 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -91,6 +91,7 @@
['vcl','newroles',1],
['vcl','oldroles',1],
['whn','crslogin',1],
+ ['vcl','sessions',1],
['mgr','resetcounters',1],
) {
my ($perm,$key,$check_section) = @{ $perm_check };
@@ -170,6 +171,13 @@
$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'
@@ -221,11 +229,19 @@
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",
@@ -254,6 +270,9 @@
} 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);
@@ -298,7 +317,8 @@
"\n";
}
}
- $scripttag.='document.visible.submit();
+ $scripttag.=<<"ENDTOGG";
+ document.visible.submit();
}
function thresholdreset() {
@@ -306,45 +326,45 @@
document.visible.submit();
}
-function togglelogins() {
- var total = document.visible.logincount.value;
- var sumrow = document.visible.loginrow.value;
+function toggledetails(prefix) {
+ var total = document.visible[prefix+'count'].value;
+ var sumrow = document.visible[prefix+'row'].value;
if (total == 0) {
return;
}
- var showlogindetails = 0;
- for (var i=0; i<document.visible.logindetails.length; i++) {
- if (document.visible.logindetails[i].checked) {
- showlogindetails = document.visible.logindetails[i].value;
+ var showdetails = 0;
+ for (var i=0; i<document.visible[prefix+'details'].length; i++) {
+ if (document.visible[prefix+'details'][i].checked) {
+ showdetails = document.visible[prefix+'details'][i].value;
}
}
var detval = "none";
var sumval = "";
- if (showlogindetails == 1) {
+ if (showdetails == 1) {
detval = "";
sumval = "none";
}
for (var j=0; j<total; j++) {
var counter = j+1;
- var itemid = "logindet_"+counter;
+ var itemid = prefix+"det_"+counter;
personele = document.getElementById(itemid);
if (personele != null) {
personele.style.display = detval;
}
}
- var detheaderele = document.getElementById("logintitledet");
+ var detheaderele = document.getElementById(prefix+"titledet");
if (detheaderele != null) {
detheaderele.style.display = detval;
}
for (var k=0; k<sumrow; k++) {
var counter = k+1;
- var itemid = "loginsum_"+counter;
- logincatele = document.getElementById(itemid);
- if (logincatele != null) {
- logincatele.style.display = sumval;
+ var itemid = prefix+"sum_"+counter;
+ catele = document.getElementById(itemid);
+ if (catele != null) {
+ catele.style.display = sumval;
}
}
- var sumheaderele = document.getElementById("logintitlesum");
+ var sumheaderele = document.getElementById(prefix+"titlesum");
if (sumheaderele != null) {
sumheaderele.style.display = sumval;
}
@@ -352,7 +372,7 @@
}
// ]]>
</script>
-';
+ENDTOGG
}
my $course_type=&Apache::loncommon::course_type();
return &Apache::loncommon::start_page("What's New?",
@@ -404,6 +424,8 @@
my %activated;
my %loggedin;
my $logincount;
+ my %sessions;
+ my $sessioncount;
my %res_title = ();
my %show = ();
my $needitems = 0;
@@ -548,6 +570,22 @@
$headings{'crslogin'} = &mt('Last login for users in last 24 hours');
}
+ $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;
@@ -588,7 +626,7 @@
$threshold{'av_attempts'},$threshold{'degdiff'},
'<br />',$threshold{'numstudents'});
- my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles','crslogin');
+ my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles','crslogin','sessions');
my %actioncolumn = (
handgrading => 'left',
haserrors => 'left',
@@ -600,6 +638,7 @@
newroles => 'right',
oldroles => 'right',
crslogin => 'right',
+ sessions => 'right',
);
foreach my $key (keys(%{$checkallowed})) {
@@ -627,7 +666,7 @@
$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'}) {
+ if ($show{'oldroles'} || $show{'newroles'} || $show{'crslogin'} || $show{'sessions'}) {
$classlist = &Apache::loncoursedata::get_classlist();
}
if ($show{'coursenormalmail'}) {
@@ -645,6 +684,9 @@
if ($show{'crslogin'}) {
$logincount = &getloggedin($cdom,$crs,\%loggedin,$crsloginstart);
}
+ if ($show{'sessions'}) {
+ $sessioncount = &getsessions($cdom,$crs,\%sessions,$timediff{'sessions'},$classlist);
+ }
$r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
<a href="javascript:changeAll('show');">$lt{'shal'}</a>
<form method="post" name="visible" action="/adm/whatsnew">\n|);
@@ -670,11 +712,11 @@
# my $halfway = int($totalboxes/2) + $totalboxes%2;
foreach my $actionitem (@actionorder) {
if ($checkallowed->{$actionitem}) {
- if (($actioncolumn{$actionitem} eq 'right') && ($currcolumn eq 'left')) {
+ if (($actioncolumn{$actionitem} eq 'right') && ($currcolumn eq 'left')) {
$r->print('</td><td> </td><td class="LC_right_col" >');
$currcolumn = 'right';
}
- &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,$itemserror,\%loggedin,$logincount,$classlist);
+ &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,$itemserror,\%loggedin,$logincount,\%sessions,$sessioncount,$classlist);
$displayed ++;
}
}
@@ -755,6 +797,8 @@
$setting = 'oldroleinterval';
} elsif ($context eq 'newroles') {
$setting = 'newroleinterval';
+ } elsif ($context eq 'sessions') {
+ $setting = 'sessionactivity';
}
my $lctype = lc(&Apache::loncommon::course_type());
my $current = &get_current($env{'user.name'},$env{'user.domain'},
@@ -765,6 +809,8 @@
$r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' became available.').'<br />');
} elsif ($context eq 'crslogin') {
$r->print('<br />'.&mt('Choose the time window to use to display the last login by a user in the '.$lctype).'<br />');
+ } elsif ($context eq 'sessions') {
+ $r->print('<br />'.&mt('Choose the time limit to use to display active user sessions in the '.$lctype.'.').'<br />');
} else {
$r->print('<br />'.&mt('Choose the time window to use to display resources in the '.$lctype.' with version changes.').'<br />');
}
@@ -785,7 +831,14 @@
');
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('<option value="'.$key.'">'.&mt($interval_titles->{$context}->{$key}).
'</option>'."\n");
}
@@ -930,7 +983,8 @@
$tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered,
$newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs,
$interval,$countunread,$expired,$expirecount,$activated,$activecount,
- $crstype,$itemserror,$loggedin,$logincount,$classlist) = @_;
+ $crstype,$itemserror,$loggedin,$logincount,$sessions,$sessioncount,
+ $classlist) = @_;
if ($$checkallowed{$action}) {
&start_box($r,$show,$headings,$action,$refpage);
@@ -958,8 +1012,11 @@
&display_rolechanges($r,$expirecount,$expired,$interval->{'oldroles'},
$crstype,$classlist);
} elsif ($action eq 'crslogin') { #LAST LOGIN
- &display_crslogins($r,$logincount,$loggedin,$interval->{'crslogin'},
+ &display_activity($r,'logins',$logincount,$loggedin,$interval->{'crslogin'},
$crstype,$classlist);
+ } elsif ($action eq 'sessions') { #ACTIVE SESSIONS
+ &display_activity($r,'sessions',$sessioncount,$sessions,$interval->{'sessions'},
+ $crstype,$classlist);
}
}
&end_box($r);
@@ -1033,7 +1090,6 @@
$triggered,$threshold,$warnings,
$checkallowed);
}
-
}
return;
}
@@ -1616,6 +1672,78 @@
return $logincount;
}
+sub getsessions {
+ my ($cdom,$cnum,$sessions,$lastactive,$classlist) = @_;
+ my $context = 'course';
+ my ($permission,$allowed) =
+ &Apache::lonuserutils::get_permission($context);
+ my %crs_sessions = &Apache::lonnet::get_course_sessions($cnum,$cdom,$lastactive);
+ my $sessioncount = 0;
+ if (keys(%crs_sessions) > 0) {
+ if (ref($classlist) eq 'HASH') {
+ my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
+ my $secidx = &Apache::loncoursedata::CL_SECTION();
+ my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'_'.$cnum,1);
+ my %personnel;
+ foreach my $role (sort(keys(%coursepersonnel))) {
+ my ($rolecode,$section);
+ if ($role =~ /:/) {
+ ($rolecode,$section) = split(/:/,$role);
+ } else {
+ $rolecode = $role;
+ }
+ if ($viewablesec ne '') {
+ next if ($viewablesec ne $section);
+ }
+ foreach my $user (split(/\,/,$coursepersonnel{$role})) {
+ push(@{$personnel{$user}{$rolecode}},$section);
+ }
+ }
+ foreach my $key (keys(%crs_sessions)) {
+ if (exists($classlist->{$key})) {
+ my $student = $classlist->{$key};
+ my $section = $student->[$secidx];
+ my $lastaccess = $crs_sessions{$key};
+ if ($viewablesec ne '') {
+ next if ($viewablesec ne $section);
+ }
+ my ($stuname,$studom) = split(/:/,$key);
+ my %info = (
+ 'section' => $section,
+ 'role' => 'st',
+ 'uname' => $stuname,
+ 'udom' => $studom,
+ );
+ $sessioncount ++;
+ push(@{$sessions->{$lastaccess}},\%info);
+ } elsif (exists($personnel{$key})) {
+ my $lastaccess = $crs_sessions{$key};
+ my ($uname,$udom) = split(/:/,$key);
+ if (ref($personnel{$key}) eq 'HASH') {
+ my ($showrole,$showsec);
+ foreach my $possrole ('cc','co','in','ta','ep','ad','st') {
+ if (exists($personnel{$key}{$possrole})) {
+ $showrole = $possrole;
+ $showsec = join(', ',@{$personnel{$key}{$possrole}});
+ last;
+ }
+ }
+ my %info = (
+ 'section' => $showsec,
+ 'role' => $showrole,
+ 'uname' => $uname,
+ 'udom' => $udom,
+ );
+ $sessioncount ++;
+ push(@{$sessions->{$lastaccess}},\%info);
+ }
+ }
+ }
+ }
+ }
+ return $sessioncount;
+}
+
sub checkversions {
my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
@@ -1882,8 +2010,8 @@
return;
}
-sub display_crslogins {
- my ($r,$logincount,$loggedin,$interval,$crstype,$classlist) = @_;
+sub display_activity {
+ my ($r,$context,$count,$details,$interval,$crstype,$classlist) = @_;
return unless (ref($classlist) eq 'HASH');
my %lt = &Apache::lonlocal::texthash(
'user' => 'User',
@@ -1891,29 +2019,38 @@
'sec' => 'Section',
'number' => 'Total number of logins',
);
- if ($logincount) {
+ 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 = '<tr class="LC_info_row" style="display:none" id="logintitledet">'.
+ my $hdr = '<tr class="LC_info_row" style="display:none" id="'.$prefix.'titledet">'.
'<td class="LC_left_item">'.$lt{'user'}.'</td>'.
'<td class="LC_left_item">'.$lt{'role'}.'</td>'.
- '<td class="LC_left_item">'.$lt{'sec'}.'</td></tr>'.
- '<tr class="LC_info_row" id="logintitlesum">'.
- '<td class="LC_left_item">'.$lt{'number'}.'</td>'.
- '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
- '<td class="LC_left_item">'.$lt{'sec'};
+ '<td class="LC_left_item">'.$lt{'sec'}.'</td>';
+ if ($context eq 'sessions') {
+ $hdr .= '<td class="LC_left_item">'.$lt{'active'}.'</td>';
+ }
+ $hdr .= '</tr>'."\n".
+ '<tr class="LC_info_row" id="'.$prefix.'titlesum">'.
+ '<td class="LC_left_item">'.$lt{'number'}.'</td>'.
+ '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
+ '<td class="LC_left_item">'.$lt{'sec'};
my (%bylastname,%counts);
- if (ref($loggedin) eq 'HASH') {
- my @logins = sort { $b <=> $a } (keys(%{$loggedin}));
- my $numlogin = 0;
+ if (ref($details) eq 'HASH') {
+ my @items = sort { $b <=> $a } (keys(%{$details}));
+ my $num = 0;
my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
- foreach my $item (@logins) {
- if (ref($loggedin->{$item}) eq 'ARRAY') {
- foreach my $user (@{$loggedin->{$item}}) {
+ 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 {
@@ -1930,10 +2067,13 @@
}
my $link =
&Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
- push(@{$bylastname{$fullname}},
- '<td>'.$link.'</td>'.
- '<td>'.$role.'</td>'.
- '<td>'.$section.'</td>');
+ my $entry = '<td>'.$link.'</td>'.
+ '<td>'.$role.'</td>'.
+ '<td>'.$section.'</td>';
+ if ($context eq 'sessions') {
+ $entry .= '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>';
+ }
+ push(@{$bylastname{$fullname}},$entry);
}
}
}
@@ -1942,9 +2082,9 @@
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 .= '<tr'.$css_class.' style="display:none;" id="logindet_'.$numlogin.'">'.$item.'</tr>';
+ $num ++;
+ my $css_class = $num%2?' class="LC_odd_row"':'';
+ $table .= '<tr'.$css_class.' style="display:none;" id="'.$prefix.'det_'.$num.'">'.$item.'</tr>';
}
}
}
@@ -1955,21 +2095,21 @@
foreach my $sec (sort { $b <=> $a } (keys(%{$counts{$role}}))) {
$numrow ++;
my $css_class = $numrow%2?' class="LC_odd_row"':'';
- $table .= '<tr '.$css_class.' id="loginsum_'.$numrow.'">'.
+ $table .= '<tr '.$css_class.' id="'.$prefix.'sum_'.$numrow.'">'.
'<td>'.$counts{$role}{$sec}.'</td>'.
'<td>'.$showrole.'</td>'.
'<td>'.$sec.'</td></tr>';
}
}
}
- $r->print($hdr.'<input type="hidden" name="logincount" value="'.$numlogin.
- '" /><input type="hidden" name="loginrow" value="'.$numrow.
+ $r->print($hdr.'<input type="hidden" name="'.$prefix.'count" value="'.$num.
+ '" /><input type="hidden" name="'.$prefix.'row" value="'.$numrow.
'" /></td></tr>'.$table);
}
} else {
$r->print('<tr class="LC_empty_row"><td>'.
&mt('There are no '.$interval).
- '<input type="hidden" name="logincount" value="'.$logincount.
+ '<input type="hidden" name="'.$prefix.'count" value="'.$count.
'." /></td></tr>');
}
return;
@@ -2137,6 +2277,8 @@
$interval_settings{$cid.':newroleinterval'} = $env{'form.interval'};
} elsif ($context eq 'crslogin') {
$interval_settings{$cid.':crslogininterval'} = $env{'form.interval'};
+ } elsif ($context eq 'sessions') {
+ $interval_settings{$cid.':sessionactivity'} = $env{'form.interval'};
} else {
$interval_settings{$cid.':interval'} = $env{'form.interval'};
}
@@ -2295,11 +2437,17 @@
if ($$show{$caller}) {
$r->print('
<tr>
- <td class="LC_subheader" align="left"><span class="LC_nobreak"><label><input type="radio" name="logindetails" value="0" checked="checked" onclick="javascript:togglelogins();" /> '.&mt('Summary').'</label><label><input type="radio" name="logindetails" value="1" onclick="javascript:togglelogins();" /> '.&mt('Details').'</label></span></td><td class="LC_subheader"><a href="/adm/whatsnew?command=chgcrslogininterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+ <td class="LC_subheader" align="left"><span class="LC_nobreak"><label><input type="radio" name="logindetails" value="0" checked="checked" onclick="javascript:toggledetails('."'login'".');" /> '.&mt('Summary').'</label><label><input type="radio" name="logindetails" value="1" onclick="javascript:toggledetails('."'login'".');" /> '.&mt('Details').'</label></span></td><td class="LC_subheader"><a href="/adm/whatsnew?command=chgcrslogininterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+ </tr>');
+ }
+ } elsif (($caller eq 'sessions') && ($$show{$caller})) {
+ if ($$show{$caller}) {
+ $r->print('
+ <tr>
+ <td class="LC_subheader" align="left"><span class="LC_nobreak"><label><input type="radio" name="sessiondetails" value="0" checked="checked" onclick="javascript:toggledetails('."'session'".');" /> '.&mt('Summary').'</label><label><input type="radio" name="sessiondetails" value="1" onclick="javascript:toggledetails('."'session'".');" /> '.&mt('Details').'</label></span></td><td class="LC_subheader"><a href="/adm/whatsnew?command=chgsessionlimit&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
</tr>');
}
}
-
$r->print('
<tr>
<td colspan="2">
More information about the LON-CAPA-cvs
mailing list