--- loncom/interface/lonwhatsnew.pm 2008/12/12 10:01:25 1.82
+++ loncom/interface/lonwhatsnew.pm 2016/11/08 23:55:48 1.122
@@ -1,5 +1,5 @@
#
-# $Id: lonwhatsnew.pm,v 1.82 2008/12/12 10:01:25 bisitz Exp $
+# $Id: lonwhatsnew.pm,v 1.122 2016/11/08 23:55:48 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,36 @@ 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],
+ ['mgr','resetcounters',1],
) {
my ($perm,$key,$check_section) = @{ $perm_check };
my $scope = $env{'request.course.id'};
@@ -87,7 +108,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 +120,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 +163,19 @@ 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'
+ ));
} 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 +186,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 +215,28 @@ 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 %interval_titles = (
versions => \%versions,
newroles => \%newroles,
oldroles => \%oldroles,
+ crslogin => \%crslogins,
);
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 +251,9 @@ 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');
} else {
&display_actions_box($r,$command,$refpage,\%threshold_titles,
\%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
@@ -244,9 +279,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";
';
}
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 +376,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 +402,8 @@ sub display_actions_box {
my %expired;
my $activecount;
my %activated;
+ my %loggedin;
+ my $logincount;
my %res_title = ();
my %show = ();
my $needitems = 0;
@@ -327,7 +417,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 +431,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('
+ ' '); @@ -621,6 +763,8 @@ sub display_interval_config { $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).' '); } else { $r->print(' '.&mt('Choose the time window to use to display resources in the '.$lctype.' with version changes.').' '); } @@ -649,7 +793,7 @@ sub display_interval_config { } $r->print(' '); + &mt('Save').'" />'); return; } @@ -680,11 +824,11 @@ 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 bulletin board which has unread posts.') + .&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(' '); @@ -724,7 +868,7 @@ sub courseinit_config { 'anis' => 'and is set to display', 'padc' => 'Page display controlled by', 'chce' => 'Choose '.$lctype.' entry', - 'moce' => 'Modify '.$lctype.' entry', + 'moce' => 'Save', ); $r->print(<<"END"); $lt{'chwp'} @@ -786,33 +930,36 @@ sub display_launcher { $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered, $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs, $interval,$countunread,$expired,$expirecount,$activated,$activecount, - $crstype) = @_; + $crstype,$itemserror,$loggedin,$logincount,$classlist) = @_; if ($$checkallowed{$action}) { - &start_box($r,$show,$headings,$action,$refpage,$action); + &start_box($r,$show,$headings,$action,$refpage); if ($$show{$action}) { if ($action eq 'handgrading') { # UNGRADED ITEMS - &display_handgrade($r,$tograde,$ungraded); + &display_handgrade($r,$tograde,$ungraded,$itemserror); } elsif ($action eq 'haserrors') { # BOMBS - &display_haserrors($r,$bombs,$bombed,$res_title); + &display_haserrors($r,$bombs,$bombed,$res_title,$itemserror); } elsif ($action eq 'versionchanges') { # VERSION CHANGES - &display_versionchanges($r,$changed,$res_title,$interval->{'versions'}); + &display_versionchanges($r,$changed,$res_title,$interval->{'versions'},$itemserror); } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS &display_abovethreshold($r,$refpage,$warnings,$triggered, - $res_title); + $res_title,$itemserror,$checkallowed); } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION &display_coursediscussion($r,$newdiscussions,$unread, - $countunread,$res_title); + $countunread,$res_title,$itemserror); } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES &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); + $crstype,$classlist); } elsif ($action eq 'oldroles') { # EXPIRED ROLES &display_rolechanges($r,$expirecount,$expired,$interval->{'oldroles'}, - $crstype); + $crstype,$classlist); + } elsif ($action eq 'crslogin') { #LAST LOGIN + &display_crslogins($r,$logincount,$loggedin,$interval->{'crslogin'}, + $crstype,$classlist); } } &end_box($r); @@ -823,8 +970,12 @@ sub display_launcher { sub getitems { my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions, $tograde,$bombs,$warnings,$threshold,$cdom,$crs,$res_title,$show, - $starttime,$countunread) = @_; + $starttime,$countunread,$checkallowed) = @_; my $navmap = Apache::lonnavmaps::navmap->new(); + if (!defined($navmap)) { + my $itemserror = ''.&mt('An error occurred retrieving information about the course.').' '.&mt('It is recommended that you [_1]re-select the course[_2].','','').''; + return $itemserror; + } # force retrieve Resource to seed the part id cache we'll need it later my @allres=$navmap->retrieveResources(undef, sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;}); @@ -879,10 +1030,12 @@ sub getitems { # Maxtries and degree of difficulty for problem parts, unless handgradeable if ($$show{'abovethreshold'}) { &check_thresholds($resource,$symb,\%resourcetracker, - $triggered,$threshold,$warnings); + $triggered,$threshold,$warnings, + $checkallowed); } } + return; } sub check_discussions { @@ -952,7 +1105,8 @@ sub check_bombed { } sub check_thresholds { - my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings) = @_; + my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings, + $checkallowed) = @_; # Compile maxtries and degree of difficulty for problem parts, unless handgradeable my @parts = @{$resource->parts()}; my %stats; @@ -962,6 +1116,9 @@ sub check_thresholds { if ($resource->handgrade($part) eq 'yes') { next; } + if ($resource->is_anonsurvey($part)) { + next; + } if ($resource->is_survey($part)) { next; } @@ -984,6 +1141,7 @@ sub check_thresholds { $av_attempts = $attempts/$users; $av_attempts = sprintf("%.2f",$av_attempts); } + &Apache::lonnet::statslog($symb,$part,$users,$av_attempts,$degdiff); if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) { $stats{$part}{degdiff} = $degdiff; $stats{$part}{attempts} = $av_attempts; @@ -1014,8 +1172,12 @@ sub check_thresholds { | '.$stats{$part}{users}.' | '.$stats{$part}{attempts}.' | '.$stats{$part}{degdiff}.' | -'.$lastreset{$part}.' | -'; + | '.$lastreset{$part}.' | '; + if ($checkallowed->{'resetcounters'}) { + $$triggered{$symb}{text}[$partcount] .= + ''. + ' | '; + } $partcount ++; } $$triggered{$symb}{numparts} = $partcount; @@ -1037,7 +1199,7 @@ sub get_curr_thresholds { my $thresholdcount = 0; my ($tmp) = %thresholdsettings; unless ($tmp =~ /^(con_lost|error|no_such_host)/i) { - foreach my $item (keys %{$threshold}) { + foreach my $item (keys(%{$threshold})) { if (exists($thresholdsettings{$cid.':threshold_'.$item})) { $$threshold{$item} = $thresholdsettings{$cid.':threshold_'.$item}; @@ -1052,7 +1214,7 @@ sub get_curr_thresholds { $cdom,$crs,'internal.threshold'); my ($temp) = %coursesettings; unless ($temp =~ /^(con_lost|error|no_such_host)/i) { - foreach my $item (keys %{$threshold}) { + foreach my $item (keys(%{$threshold})) { unless (exists($thresholdsettings{$cid.':threshold_'.$item})) { if (exists($coursesettings{'internal.threshold_'.$item})) { $$threshold{$item} = @@ -1077,7 +1239,11 @@ sub get_current { } sub process_reset { - my ($dom,$crs) = @_; + my ($dom,$crs,$checkallowed) = @_; + if (!$checkallowed->{'resetcounters'}) { + return ''.&mt('You do not the required privileges to reset counters'). + '|||
'.$$ungraded{$res}{title}.' | '.$$ungraded{$res}{count}.' | |||||||||
'.$itemserror.' | ||||||||||
'.$lt{'nopr'}.' | '. $$bombed{$bomb}{errorcount}.' | '); } + } elsif ($itemserror) { + $r->print('|||||||||
'.$itemserror.' | ||||||||||
'.$lt{'noer'}.' | ||||||||||
'.$itemserror.' | ||||||||||
'.$lt{'nopr'}.' | '. $$changed{$item}{'version'}.' | '); } + } elsif ($itemserror) { + $r->print('|||||||||
'.$itemserror.' | ||||||||||
' .&mt('No '.$interval).' | ||||||||||
'.&Apache::lonlocal::locallocaltime($item).' | '. ''.$link.' | '. @@ -1653,9 +1879,102 @@ sub display_rolechanges { } return; } + +sub display_crslogins { + my ($r,$logincount,$loggedin,$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'}; + my (%bylastname,%counts); + if (ref($loggedin) eq 'HASH') { + my @logins = sort { $b <=> $a } (keys(%{$loggedin})); + my $numlogin = 0; + my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME(); + foreach my $item (@logins) { + if (ref($loggedin->{$item}) eq 'ARRAY') { + foreach my $user (@{$loggedin->{$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 { + $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); + push(@{$bylastname{$fullname}}, + ' | '.$link.' | '. + ''.$role.' | '. + ''.$section.' | '); + } + } + } + } + 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). + ' | ||||||||||
'.$itemserror.' | ||||||||||
'.$lt{'noun'}.' | ||||||||||
'.$lt{'chth'}.' | +'.$lt{'chth'}.' | |||||||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | |||||||||
'.$lt{'chop'}.' | +'.$lt{'chop'}.' | |||||||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | |||||||||
'.$lt{'chin'}.' | +'.$lt{'chin'}.' | |||||||||
'.$lt{'chin'}.' | +||||||||||