File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.129: download - view: text, annotated - select for diffs
Sun Dec 13 02:00:49 2020 UTC (3 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- Make handgrade parameter (default=no) available for custom response items,
  and add customresponse with handgrade=yes in "What's New" handgrading list.

    1: # The LearningOnline Network
    2: # What's New in a course
    3: #
    4: # $Id: lonwhatsnew.pm,v 1.129 2020/12/13 02:00:49 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: 
   30: package Apache::lonwhatsnew;
   31: 
   32: use strict;
   33: use lib qw(/home/httpd/lib/perl);
   34: use Apache::lonnet;
   35: use Apache::loncommon();
   36: use Apache::lonhtmlcommon();
   37: use Apache::lonlocal;
   38: use Apache::loncoursedata();
   39: use Apache::lonnavmaps();
   40: use Apache::lonuserstate;
   41: use Apache::lonuserutils; 
   42: use Apache::Constants qw(:common :http);
   43: use Time::Local;
   44: use GDBM_File;
   45: use lib '/home/httpd/lib/perl/';
   46: use LONCAPA;
   47: use HTML::Entities;
   48: 
   49: #----------------------------
   50: # handler
   51: #
   52: #----------------------------
   53: 
   54: sub handler {
   55:     my $r = shift;
   56:     if ($r->header_only) {
   57:         &Apache::loncommon::content_type($r,'text/html');
   58:         $r->send_http_header;
   59:         return OK;
   60:     }
   61:     &Apache::loncommon::get_unprocessed_cgi(
   62:                                    $ENV{'QUERY_STRING'},['command','refpage']);
   63: 
   64:     my $command = $env{'form.command'};
   65:     my $refpage = $env{'form.refpage'};
   66: 
   67:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
   68:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
   69: 
   70:     my ($isadhoc,%checkallowed);
   71: 
   72:     if ($env{'request.role'} =~ m{^(cc|co)/}) {
   73:         my $rolecode = $1;
   74:         if ($env{"environment.internal.$cdom.$crs.$env{'request.role'}.adhoc"}) {
   75:             $isadhoc = 1;
   76:         }
   77:     } elsif ($env{'request.role'} =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)\./}) {
   78:         my $rolename = $1;
   79:         if ($env{"environment.internal.$cdom.$crs.cr/$cdom/$cdom-domainconfig/$rolename.adhoc"}) {
   80:             $isadhoc = 1;
   81:         }
   82:     }
   83:     unless ($isadhoc) {
   84:         %checkallowed = ( coursenormalmail => 1,
   85: 			  coursecritmail => 1,);
   86:     }
   87:     foreach my $perm_check (['whn','whatsnew',1],
   88: 			    ['pch','coursediscussion',1],
   89: 			    ['mgr','handgrading',1],
   90: 			    ['vgr','abovethreshold',1],
   91: 			    ['vgr','haserrors',1],
   92: 			    ['whn','versionchanges',1],
   93:                             ['vcl','newroles',1],
   94:                             ['vcl','oldroles',1],
   95:                             ['whn','crslogin',1],
   96:                             ['vcl','sessions',1],
   97:                             ['mgr','resetcounters',1],
   98: 			    ) {
   99: 	my ($perm,$key,$check_section) = @{ $perm_check };
  100: 	my $scope = $env{'request.course.id'};
  101: 	if (!($checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope))) {
  102: 	    $scope .= '/'.$env{'request.course.sec'};
  103: 	    if ( $check_section ) {
  104: 		$checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope);
  105: 	    }
  106: 	    if ($checkallowed{$key}) {
  107: 		$checkallowed{$key.'_section'} = $env{'request.course.sec'};
  108: 	    }
  109: 	}
  110:     }
  111: 
  112:     if ( ! $env{'request.course.fn'} || ! $checkallowed{'whatsnew'}) {
  113:         # Not in a course, or no whn priv in course
  114:         $env{'user.error.msg'}="/adm/whatsnew:whn:0:0:Cannot display what's new page";
  115:         return HTTP_NOT_ACCEPTABLE;
  116:     }
  117: 
  118:     &Apache::loncommon::content_type($r,'text/html');
  119:     $r->send_http_header;
  120: 
  121:     $r->print(&display_header($command,\%checkallowed));
  122: 
  123:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  124:     &Apache::lonhtmlcommon::add_breadcrumb
  125:             ({href=>'/adm/whatsnew',
  126:               text=>"What's New?"});
  127:     if (($command eq 'chgthreshold') && $checkallowed{'abovethreshold'}) {
  128:         &Apache::lonhtmlcommon::add_breadcrumb
  129:             ({href=>'/adm/whatsnew?command=chgthreshold&refpage='.$refpage,
  130:               text=>"Change thresholds"});
  131:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  132:             ("What's New?",#'Course_Action_Items_Thresholds'
  133: 	     ));
  134:     } elsif (($command eq 'chginterval') && $checkallowed{'versionchanges'} ) {
  135:         &Apache::lonhtmlcommon::add_breadcrumb
  136:             ({href=>'/adm/whatsnew?command=chginterval&refpage='.$refpage,
  137:               text=>"Change interval"});
  138:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  139:             ("What's New?",#'Course_Action_Items_Intervals'
  140: 	     ));
  141:     } elsif (($command eq 'chgdisc') && $checkallowed{'coursediscussion'}) {
  142:         &Apache::lonhtmlcommon::add_breadcrumb
  143:             ({href=>'/adm/whatsnew?command=chgdisc&refpage='.$refpage,
  144:               text=>"Change discussion display"});
  145:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  146:             ("What's New?",#'Course_Action_Items_Intervals'
  147: 	     ));
  148:     } elsif ($command eq 'courseinit') {
  149:         &Apache::lonhtmlcommon::add_breadcrumb
  150:             ({href=>'/adm/whatsnew?command=courseinit&refpage='.$refpage,
  151:               text=>"Course initialization preference"});
  152:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  153:             ("What's New?",#'Course_Action_Items_Initialization'
  154: 	     ));
  155:     } elsif ($command eq 'chgoldroleinterval' && $checkallowed{'oldroles'}) {
  156:         &Apache::lonhtmlcommon::add_breadcrumb
  157:             ({href=>'/adm/whatsnew?command=chgoldroleinterval&refpage='.$refpage,
  158:               text=>"Change interval"});
  159:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  160:             ("What's New?",#'Course_Action_Items_Intervals'
  161:              ));
  162:     } elsif ($command eq 'chgnewroleinterval' && $checkallowed{'newroles'}) {
  163:         &Apache::lonhtmlcommon::add_breadcrumb
  164:             ({href=>'/adm/whatsnew?command=chgnewroleinterval&refpage='.$refpage,
  165:               text=>"Change interval"});
  166:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  167:             ("What's New?",#'Course_Action_Items_Intervals'
  168:              ));
  169:     } elsif ($command eq 'chgcrslogininterval' && $checkallowed{'crslogin'}) {
  170:         &Apache::lonhtmlcommon::add_breadcrumb
  171:             ({href=>'/adm/whatsnew?command=chgcrslogininterval&refpage='.$refpage,
  172:               text=>"Change interval"});
  173:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  174:             ("What's New?",#'Course_Action_Items_Intervals'
  175:              ));
  176:     } elsif ($command eq 'chgsessionlimit' && $checkallowed{'sessions'}) {
  177:         &Apache::lonhtmlcommon::add_breadcrumb
  178:             ({href=>'/adm/whatsnew?command=chgsessionlimit&refpage='.$refpage,
  179:               text=>"Change session range"});
  180:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  181:             ("What's New?",#'Course_Action_Items_Sessions'
  182:              ));
  183:     } else {
  184:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  185:             ("What's New?",#'Course_Action_Items_Display'
  186: 	     ));
  187:     }
  188:     &display_main_box($r,$command,$refpage,\%checkallowed,$cdom,$crs);
  189:     return OK;
  190: }
  191: 
  192: #------------------------------
  193: # display_main_box
  194: #
  195: # Display all the elements within the main box
  196: #------------------------------
  197:                                                                                 
  198: sub display_main_box {
  199:     my ($r,$command,$refpage,$checkallowed,$cdom,$crs) = @_;
  200:     my $domain=&Apache::loncommon::determinedomain();
  201:     my $function = &Apache::loncommon::get_users_function();
  202:     my $lctype = lc(&Apache::loncommon::course_type());
  203:     $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
  204: 
  205:     my %threshold_titles = &Apache::lonlocal::texthash (
  206:                          av_attempts => 'Average number of attempts',
  207:                          degdiff => 'Degree of difficulty',
  208:                          numstudents => 'Total number of students with submissions',
  209:     );
  210:     my %versions = (
  211:                        -1 => "version changes since start of $lctype",
  212:                   2592000 => 'version changes since last month',
  213:                    604800 => 'version changes since last week',
  214:                     86400 => 'version changes since yesterday',
  215:                    );
  216:     my %newroles = (
  217:                        -1 => "roles which have become active since start of $lctype",
  218:                   2592000 => 'roles which have become active since last month',
  219:                    604800 => 'roles which have become active since last week',
  220:                     86400 => 'roles which have become active since yesterday',
  221:                    );
  222:     my %oldroles = (
  223:                        -1 => "roles which expired since start of $lctype",
  224:                   2592000 => 'roles which expired since last month',
  225:                    604800 => 'roles which expired since last week',
  226:                     86400 => 'roles which expired since yesterday',
  227:                    );
  228:     my %crslogins = (
  229:                        -1 => 'last logins for anyone who has ever logged in',
  230:                   2592000 => 'last logins for users in last 30 days',
  231:                    604800 => 'last logins for users in last 7 days',
  232:                     86400 => 'last logins for users in last 24 hours',
  233:                    );
  234:     my %sessions = (
  235:                      300  => 'course sessions active in the last 5 minutes',
  236:                      600  => 'course sessions active in the last 10 minutes',
  237:                      1800 => 'course sessions active in the last 30 minutes',
  238:                      7200 => 'course sessions active in the last 2 hours',
  239:                     -7200 => 'course sessions with last activity more than 2 hours ago',
  240:                    );
  241:     my %interval_titles = (
  242:         versions => \%versions,
  243:         newroles => \%newroles,
  244:         oldroles => \%oldroles,
  245:         crslogin => \%crslogins,
  246:         sessions => \%sessions,
  247:     );
  248:     my %initpage = &Apache::lonlocal::texthash (
  249:                      firstres => "first resource in the $lctype",
  250:                      whatsnew => "What's New Page",
  251:                      userpref => 'your general user preferences',
  252:                      coursespecific => "specific setting for this $lctype",
  253:                    );
  254: 
  255:     if (($command eq 'chgthreshold') 
  256: 	&& $checkallowed->{'abovethreshold'}) {
  257:         &display_threshold_config($r,$refpage,\%threshold_titles,$cdom,$crs);
  258:     } elsif (($command eq 'chginterval') 
  259: 	     && $checkallowed->{'versionchanges'}) {
  260:         &display_interval_config($r,$refpage,\%interval_titles,'versions');
  261:     } elsif (($command eq 'chgdisc') 
  262: 	     && $checkallowed->{'coursediscussion'}) {
  263:         &display_discussion_config($r,$refpage);
  264:     } elsif ($command eq 'courseinit') {
  265:         &courseinit_config($r,$refpage,\%initpage);
  266:     } elsif (($command eq 'chgnewroleinterval')
  267:              && $checkallowed->{'newroles'}) {
  268:         &display_interval_config($r,$refpage,\%interval_titles,'newroles');
  269:     } elsif (($command eq 'chgoldroleinterval')
  270:              && $checkallowed->{'oldroles'}) {
  271:         &display_interval_config($r,$refpage,\%interval_titles,'oldroles');
  272:     } elsif (($command eq 'chgcrslogininterval')
  273:              && $checkallowed->{'crslogin'}) {
  274:         &display_interval_config($r,$refpage,\%interval_titles,'crslogin');
  275:     } elsif (($command eq 'chgsessionlimit')
  276:              && $checkallowed->{'sessions'}) {
  277:         &display_interval_config($r,$refpage,\%interval_titles,'sessions');
  278:     } else {
  279:         &display_actions_box($r,$command,$refpage,\%threshold_titles,
  280:                         \%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
  281:     }
  282:     my $end_page = &Apache::loncommon::end_page();
  283:     $r->print(<<END_OF_BLOCK);
  284:   </td>
  285:  </tr>
  286: </table><br />
  287: $end_page
  288: END_OF_BLOCK
  289: }
  290: 
  291: #-------------------------------
  292: # display_header
  293: #
  294: # Display the header information and set
  295: # up the HTML
  296: #-------------------------------
  297: 
  298: sub display_header {
  299:     my ($command,$checkallowed) = @_;
  300:     
  301:     my $scripttag;
  302:     unless ($command eq 'chgthreshold' || $command eq 'chginterval' || 
  303:             $command eq 'chgoldroleinterval' ||
  304:             $command eq 'chgnewroleinterval' || $command eq 'chgcrslogininterval') {
  305:        $scripttag = <<"END";
  306: <script type="text/javascript">
  307: // <![CDATA[
  308: function change_display(caller,change) {
  309:     caller.value = change;
  310:     document.visible.submit();
  311: }
  312: 
  313: function changeAll(change) {
  314: END
  315:         foreach my $item (keys(%{$checkallowed})) {
  316: 	    if ($item =~ /_section$/) { next; }
  317:             if ($$checkallowed{$item}) {
  318:                 $scripttag.='document.visible.display_'.$item.'.value=change'.
  319:                             "\n";
  320:             }
  321:         }
  322:         $scripttag.=<<"ENDTOGG";
  323:     document.visible.submit();
  324: }
  325: 
  326: function thresholdreset() {
  327:     document.visible.command.value="reset";
  328:     document.visible.submit();
  329: }
  330: 
  331: function toggledetails(prefix) {
  332:     var total = document.visible[prefix+'count'].value;
  333:     var sumrow = document.visible[prefix+'row'].value;
  334:     if (total == 0) {
  335:         return;
  336:     }
  337:     var showdetails = 0;
  338:     for (var i=0; i<document.visible[prefix+'details'].length; i++) {
  339:         if (document.visible[prefix+'details'][i].checked) {
  340:             showdetails = document.visible[prefix+'details'][i].value;
  341:         }
  342:     }
  343:     var detval = "none";
  344:     var sumval = "";
  345:     if (showdetails == 1) {
  346:         detval = "";
  347:         sumval = "none";
  348:     }
  349:     for (var j=0; j<total; j++) {
  350:         var counter = j+1;
  351:         var itemid = prefix+"det_"+counter;
  352:         personele = document.getElementById(itemid);
  353:         if (personele != null) {
  354:             personele.style.display = detval;
  355:         }
  356:     }
  357:     var detheaderele = document.getElementById(prefix+"titledet");
  358:     if (detheaderele != null) {
  359:         detheaderele.style.display = detval;
  360:     }
  361:     for (var k=0; k<sumrow; k++) {
  362:         var counter = k+1;
  363:         var itemid = prefix+"sum_"+counter;
  364:         catele = document.getElementById(itemid);
  365:         if (catele != null) {
  366:             catele.style.display = sumval;
  367:         }
  368:     }
  369:     var sumheaderele = document.getElementById(prefix+"titlesum");
  370:     if (sumheaderele != null) {
  371:         sumheaderele.style.display = sumval;
  372:     }
  373:     return;
  374: }
  375: // ]]>
  376: </script>
  377: ENDTOGG
  378:     }
  379:     my $course_type=&Apache::loncommon::course_type();
  380:     return &Apache::loncommon::start_page("What's New?",
  381: 					  $scripttag);
  382: }
  383: 
  384: #-------------------------------
  385: # display_actions_box
  386: #
  387: # Display the action items
  388: #
  389: #-------------------------------
  390:                                                                                 
  391: sub display_actions_box {
  392:     my ($r,$command,$refpage,$threshold_titles,$interval_titles,$initpage,
  393:         $cdom,$crs,$checkallowed) = @_;
  394:     my $udom = $env{'user.domain'};
  395:     my $uname = $env{'user.name'};
  396:     my $cid = $env{'request.course.id'};
  397:     my $crstype = &Apache::loncommon::course_type();
  398:     my $lctype = lc($crstype);
  399:     my %stulabel = (
  400:                     'Course' => 'students',
  401:                     'Community' => 'members',
  402:                    );
  403:     my %lt = &Apache::lonlocal::texthash(
  404:                  'yacc' => 'You are accessing an invalid course',
  405:                  'gtfr' => 'Go to first resource',
  406:                  'hial' => 'Hide all',
  407:                  'shal' => 'Show all',
  408:     );
  409: 
  410:     my %unread = ();
  411:     my %ungraded = ();
  412:     my %bombed = ();
  413:     my %triggered = ();
  414:     my %changed = ();
  415:     my @newmsgs = ();
  416:     my @critmsgs = ();
  417:     my @newdiscussions = ();
  418:     my @tograde = ();
  419:     my @bombs = ();
  420:     my @warnings = ();
  421:     my $msgcount = 0;
  422:     my $critmsgcount = 0;
  423:     my $expirecount;
  424:     my %expired;
  425:     my $activecount;
  426:     my %activated;
  427:     my %loggedin;
  428:     my $logincount;
  429:     my %sessions;
  430:     my $sessioncount;
  431:     my %res_title = ();
  432:     my %show = ();
  433:     my $needitems = 0;
  434:     my $boxcount = 0;
  435: 
  436:     my $result;
  437:     if ($command eq 'newcourseinit') {
  438:         $result = &store_courseinit_setting($uname,$udom,$cid,$initpage);
  439:     }
  440: 
  441:     my %threshold = ();
  442:     my %pagedesc = &Apache::lonlocal::texthash (
  443:                      firstres => 'First resource',
  444:                      whatsnew => "What's New Page",
  445:                      userpref => 'user preference',
  446:                      coursespecific => $lctype.' only',
  447:                      default => 'default',
  448:                    );
  449: 
  450:     my ($initcontrol,$initdisp) = &curr_courseinit();
  451:     my $currinit = $pagedesc{$initdisp}.' ('.$pagedesc{$initcontrol}.')';
  452: 
  453:     unless ($cid) {
  454:         $r->print('<p><span style="text-align: center; font-weight: bold;">'.$lt{'yacc'}.'</span></p>');
  455:         return;
  456:     }
  457: 
  458:     my $header = '';
  459:     if ($refpage eq 'start') {
  460:         if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
  461:             &GDBM_READER(),0640)) {
  462:             my $furl=&HTML::Entities::encode($bighash{'first_url'},'"<>&');
  463:             untie(%bighash);
  464:             $header .= '<b><a href="'.$furl.'">'.$lt{'gtfr'}.
  465:                   '</a></b><br />';
  466:         }
  467:     }
  468:     $header .= &mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
  469:               .' <span class="LC_nobreak">'
  470:               .&mt('Currently: [_1].','<i>'.$currinit.'</i>')
  471:               .'&nbsp;&nbsp;'
  472:               .&mt('[_1]Change[_2] for just [_3]this '.$lctype.'[_4] or for [_5]all your courses/communities[_6].'
  473:                   ,'<b>'
  474:                   ,'</b>'
  475:                   ,'<a href="/adm/whatsnew?command=courseinit&amp;refpage='.$refpage.'">'
  476:                   ,'</a>'
  477:                   ,'<a href="/adm/preferences?action=changecourseinit&amp;refpage='.$refpage.'">'
  478:                   ,'</a>')
  479:               .' </span>';
  480: 
  481:     $r->print(&Apache::loncommon::head_subbox($header));
  482: 
  483:     if ($command eq 'reset') {
  484:         $result = &process_reset($cdom,$crs,$checkallowed);
  485:     } elsif ($command eq 'update') {
  486:         $result = &process_update($uname,$udom,$threshold_titles);
  487:     } elsif ($command eq 'newinterval') {
  488:         $result = &store_interval_setting($uname,$udom,$cid,$interval_titles);
  489:     } elsif ($command eq 'newdiscconf') {
  490:         $result = &store_discussion_setting($uname,$udom,$cid);
  491:     }
  492: 
  493:     my $store_result=&store_display_settings($uname,$udom,$cid,$checkallowed);
  494: 
  495:     unless ($store_result eq 'ok') { 
  496:         &Apache::lonnet::logthis('Error saving whatsnew settings: '.
  497:             $store_result.' for '.'user '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
  498:         $result .= '<span class="LC_error">'
  499:                   .&mt('Unable to save visibility settings due to [_1]',
  500:                        $store_result)
  501:                   .'</span>';
  502:     }
  503: 
  504:     if ($result) {
  505:         $r->print($result.'<hr />');
  506:     }
  507:     $r->rflush();
  508: 
  509:     my (%timediff,%interval);
  510:     my %display_settings = &get_display_settings($uname,$udom,$cid);
  511:     $timediff{'versions'} = $display_settings{$cid.':interval'};
  512:     unless (defined($timediff{'versions'})) { $timediff{'versions'} = 604800; } 
  513:     $interval{'versions'} = $interval_titles->{'versions'}->{$timediff{'versions'}};
  514: 
  515:     my %headings = &Apache::lonlocal::texthash(
  516:                 coursediscussion => 'Unread '.$lctype.' discussion posts',
  517:                 handgrading      => 'Problems requiring handgrading',
  518:                 haserrors        => 'Problems with errors',
  519:                 coursenormalmail => 'New '.$lctype.' messages',
  520:                 coursecritmail   => 'New critical messages in '.$lctype,
  521:     );
  522: 
  523:     if ($timediff{'versions'} == -1) {
  524:         $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since start of '.$lctype);
  525:     } elsif ($timediff{'versions'} == 2592000) {
  526:         $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since last month');
  527:     } elsif ($timediff{'versions'} == 604800) {
  528:         $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since last week');
  529:     } elsif ($timediff{'versions'} == 86400) {
  530:         $headings{'versionchanges'} = &mt('Resources in '.$lctype.' with version changes since yesterday');
  531:     }
  532: 
  533:     $timediff{'oldroles'} = $display_settings{$cid.':oldroleinterval'};
  534:     unless (defined($timediff{'oldroles'})) { $timediff{'oldroles'} = 604800; }
  535:     $interval{'oldroles'} = $interval_titles->{'oldroles'}->{$timediff{'oldroles'}};
  536: 
  537:     if ($timediff{'oldroles'} == -1) {
  538:         $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since start of '.$lctype);
  539:     } elsif ($timediff{'oldroles'} == 2592000) {
  540:         $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since last month');
  541:     } elsif ($timediff{'oldroles'} == 604800) {
  542:         $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since last week');
  543:     } elsif ($timediff{'oldroles'} == 86400) {
  544:         $headings{'oldroles'} = &mt('Roles for which access to '.$lctype.' has expired since yesterday');
  545:     }
  546: 
  547:     $timediff{'newroles'} = $display_settings{$cid.':newroleinterval'};
  548:     unless (defined($timediff{'newroles'})) { $timediff{'newroles'} = 604800; }
  549:     $interval{'newroles'} = $interval_titles->{'newroles'}->{$timediff{'newroles'}};
  550: 
  551:     if ($timediff{'newroles'} == -1) {
  552:         $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since start of '.$lctype);
  553:     } elsif ($timediff{'newroles'} == 2592000) {
  554:         $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since last month');
  555:     } elsif ($timediff{'newroles'} == 604800) {
  556:         $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since last week');
  557:     } elsif ($timediff{'newroles'} == 86400) {
  558:         $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since yesterday');
  559:     }
  560: 
  561:     $timediff{'crslogin'} = $display_settings{$cid.':crslogininterval'};
  562:     unless (defined($timediff{'crslogin'})) { $timediff{'crslogin'} = 604800; }
  563:     $interval{'crslogin'} = $interval_titles->{'crslogin'}->{$timediff{'crslogin'}};
  564: 
  565:     if ($timediff{'crslogin'} == -1) {
  566:         $headings{'crslogin'} = &mt('Last login for anyone who has ever logged in');
  567:     } elsif ($timediff{'crslogin'} == 2592000) {
  568:         $headings{'crslogin'} = &mt('Last login for users in last 30 days');
  569:     } elsif ($timediff{'crslogin'} == 604800) {
  570:         $headings{'crslogin'} = &mt('Last login for users in last 7 days');
  571:     } elsif ($timediff{'crslogin'} == 86400) {
  572:         $headings{'crslogin'} = &mt('Last login for users in last 24 hours');
  573:     }
  574: 
  575:     $timediff{'sessions'} = $display_settings{$cid.':sessionactivity'};
  576:     unless (defined($timediff{'sessions'})) { $timediff{'sessions'} = 7200; }
  577:     $interval{'sessions'} = $interval_titles->{'sessions'}->{$timediff{'sessions'}};
  578: 
  579:     if ($timediff{'sessions'} == -7200) {
  580:         $headings{'sessions'} = &mt('Session with activity more than 2 hours ago');
  581:     } elsif ($timediff{'sessions'} == 7200) {
  582:         $headings{'sessions'} = &mt('Session with activity in last 2 hours');
  583:     } elsif ($timediff{'sessions'} == 1800) {
  584:         $headings{'sessions'} = &mt('Session with activity in last 30 minutes');
  585:     } elsif ($timediff{'sessions'} == 600) {
  586:         $headings{'sessions'} = &mt('Session with activity in last 10 minutes');
  587:     } elsif ($timediff{'sessions'} == 300) {
  588:         $headings{'sessions'} = &mt('Session with activity in last 5 minutes');
  589:     }
  590: 
  591:     my ($now,$starttime,$activatedstart,$expiredstart,$crsloginstart);
  592:     $now = time;
  593: 
  594:     if ($timediff{'versions'} == -1) {
  595:         $starttime = 0;
  596:     } else {
  597:         $starttime = $now - $timediff{'versions'};
  598:     }
  599: 
  600:     if ($timediff{'newroles'} == -1) {
  601:         $activatedstart = 0;
  602:     } else {
  603:         $activatedstart = $now - $timediff{'newroles'};
  604:     }
  605: 
  606:     if ($timediff{'oldroles'} == -1) {
  607:         $expiredstart = 0;
  608:     } else {
  609:         $expiredstart = $now - $timediff{'oldroles'};
  610:     }
  611: 
  612:     if ($timediff{'crslogin'} == -1) {
  613:         $crsloginstart = 0;
  614:     } else {
  615:         $crsloginstart = $now - $timediff{'crslogin'};
  616:     }
  617: 
  618:     my $countunread = $display_settings{$cid.':countunread'};
  619:     unless (defined($countunread)) {
  620:         $countunread = 'on';
  621:     }
  622:     if ($$checkallowed{'abovethreshold'}) {
  623:         &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
  624:     }
  625: 
  626:     $headings{'abovethreshold'} = 
  627: 	&mt('(Problems with av. attempts &ge; [_1] or deg. difficulty &ge; [_2]) [_3] and total number of '.$stulabel{$crstype}.' with submissions &ge; [_4]',
  628: 	    $threshold{'av_attempts'},$threshold{'degdiff'},
  629: 	    '<br />',$threshold{'numstudents'});
  630: 
  631:     my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles','crslogin','sessions');
  632:     my %actioncolumn = (
  633:                          handgrading      => 'left',
  634:                          haserrors        => 'left',
  635:                          abovethreshold   => 'left',
  636:                          versionchanges   => 'left',
  637:                          coursediscussion => 'right',
  638:                          coursenormalmail => 'right',
  639:                          coursecritmail   => 'right',
  640:                          newroles         => 'right',
  641:                          oldroles         => 'right',
  642:                          crslogin         => 'right',
  643:                          sessions         => 'right',
  644:                        );
  645: 
  646:     foreach my $key (keys(%{$checkallowed})) {
  647: 	if ($key =~ /_section$/) { next; }
  648:         $show{$key} = 0;
  649:         if ($$checkallowed{$key}) {
  650:             unless ($display_settings{$cid.':'.$key} eq 'hide') {
  651:                 $show{$key} = 1;
  652:             }
  653:         }
  654:     }
  655: 
  656:     foreach my $item (@actionorder) {
  657:         unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail' ||
  658:                 $item eq 'newroles' || $item eq 'oldroles' || 
  659:                 $item eq 'crslogin' || $item eq 'sessions') {
  660:             if ($show{$item}) {
  661:                 $needitems = 1;
  662:                 last;
  663:             }
  664:         }
  665:     }
  666: 
  667:     my $itemserror;
  668:     if ($needitems) {
  669:         $itemserror = &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread,$checkallowed);
  670:     }
  671:     my $classlist;
  672:     if ($show{'oldroles'} || $show{'newroles'} || $show{'crslogin'} || $show{'sessions'}) {
  673:         $classlist = &Apache::loncoursedata::get_classlist();
  674:     }
  675:     if ($show{'coursenormalmail'}) {
  676:         $msgcount = &getnormalmail(\@newmsgs);
  677:     }
  678:     if ($show{'coursecritmail'}) {
  679:         $critmsgcount = &getcritmail(\@critmsgs);
  680:     }
  681:     if ($show{'oldroles'}) {
  682:         $expirecount = &getexpired(\%expired,$expiredstart,'previous',$classlist);
  683:     }
  684:     if ($show{'newroles'}) {
  685:         $activecount = &getactivated(\%activated,$activatedstart,'active',$classlist);
  686:     }
  687:     if ($show{'crslogin'}) {
  688:         $logincount = &getloggedin($cdom,$crs,\%loggedin,$crsloginstart);
  689:     }
  690:     if ($show{'sessions'}) {
  691:         $sessioncount = &getsessions($cdom,$crs,\%sessions,$timediff{'sessions'},$classlist);
  692:     }
  693:     $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
  694:      &nbsp;&nbsp;<a href="javascript:changeAll('show');">$lt{'shal'}</a>
  695:      <form method="post" name="visible" action="/adm/whatsnew">\n|);
  696:     foreach my $item (keys(%{$checkallowed})) {
  697: 	if ($item =~ /_section$/) { next; }
  698:         if ($$checkallowed{$item}) {
  699:             $r->print('<input type="hidden" name="display_'.$item.'" />'."\n");
  700:         }
  701:     }
  702: 
  703:     $r->print('<input type="hidden" name="refpage" value="'.$refpage.'" /><table class="LC_double_column"><tr><td class="LC_left_col">');
  704: 
  705:     my $displayed = 0;
  706:     my $totalboxes = 0;
  707:     foreach my $key (keys(%{$checkallowed})) {
  708: 	if ($key =~ /_section$/) { next; }
  709: 	if ($key eq 'whatsnew' ) { next; } # whatsnew check creates no box
  710:         if ($$checkallowed{$key}) {
  711:             $totalboxes ++;
  712:         }
  713:     }
  714:     my $currcolumn = 'left';
  715: #    my $halfway = int($totalboxes/2) + $totalboxes%2;
  716:     foreach my $actionitem (@actionorder) {
  717:         if ($checkallowed->{$actionitem}) {
  718:             if (($actioncolumn{$actionitem} eq 'right') && ($currcolumn eq 'left')) {
  719:                 $r->print('</td><td>&nbsp;</td><td class="LC_right_col" >');
  720:                 $currcolumn = 'right'; 
  721:             }
  722:             &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);
  723:             $displayed ++; 
  724:         }
  725:     }
  726:     $r->print('
  727:       </td>
  728:     </tr>
  729:    </table>
  730:    </form>
  731: ');
  732: }
  733: 
  734: #-------------------------------
  735: # display_threshold_config
  736: #
  737: # Display the threshold setting screen 
  738: #
  739: #-------------------------------
  740:                                                                                 
  741: sub display_threshold_config {
  742:     my ($r,$refpage,$threshold_titles,$cdom,$crs) = @_;
  743:     my $uname = $env{'user.name'};
  744:     my $udom = $env{'user.dom'};
  745:     my $cid = $env{'request.course.id'};
  746:     my %threshold = ();
  747:     my $rowColor1 = "#ffffff";
  748:     my $rowColor2 = "#eeeeee";
  749:     my $rowColor;
  750: 
  751:     my @thresholditems = ("av_attempts","degdiff","numstudents");
  752:     my %threshold_titles = &Apache::lonlocal::texthash(
  753:                          av_attempts => 'Average number of attempts',
  754:                          degdiff => 'Degree of difficulty',
  755:                          numstudents => 'Total number of students with submissions',
  756:                          );
  757:     &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
  758: 
  759:     $r->print('<br /><form name="thresholdform" method="post" action="/adm/whatsnew">'.
  760:               &Apache::loncommon::start_data_table().
  761:               &Apache::loncommon::start_data_table_header_row().
  762:              '<th>'.&mt('Threshold Name').'</th>'."\n".
  763:              '<th>'.&mt('Current value').'</th>'."\n".
  764:              '<th>'.&mt('Change?').'</th>'."\n".
  765:               &Apache::loncommon::end_data_table_header_row());
  766:     foreach my $type (@thresholditems) {
  767:         my $parameter = $env{'request.course.id'}.':threshold_'.$type;
  768: # onchange is javascript to automatically check the 'Set' button.
  769:         my $onchange = 'onfocus="javascript:window.document.forms'.
  770:               "['thresholdform'].elements['".$parameter."_setparmval']".
  771:               '.checked=true;"';
  772:         $r->print(&Apache::loncommon::start_data_table_row()."\n".
  773:                  '<td>'.$threshold_titles{$type}.'</td>'."\n".
  774:                  '<td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
  775:                                             $threshold{$type},
  776:                                             10,$onchange).'</td>'."\n".
  777:                  '<td>'.
  778:                  &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
  779:                  '</td>'."\n".
  780:                  &Apache::loncommon::end_data_table_row());
  781:     }
  782:     $r->print(&Apache::loncommon::end_data_table()."\n".
  783:           '<br /><input type="submit" name="threshold" value="'.&mt('Save').'" />
  784:                  <input type="hidden" name="command" value="update" />
  785:                  <input type="hidden" name="refpage" value="'.$refpage.'" />
  786:                </form>');
  787: }
  788: 
  789: #-------------------------------
  790: # display_interval_config
  791: #
  792: # Display the interval setting screen
  793: #
  794: #-------------------------------
  795:                                                                                    
  796: sub display_interval_config {
  797:     my ($r,$refpage,$interval_titles,$context) = @_;
  798:     my $setting = 'interval';
  799:     if ($context eq 'oldroles') {
  800:         $setting = 'oldroleinterval';
  801:     } elsif ($context eq 'newroles') {
  802:         $setting = 'newroleinterval'; 
  803:     } elsif ($context eq 'sessions') {
  804:         $setting = 'sessionactivity';
  805:     }
  806:     my $lctype = lc(&Apache::loncommon::course_type());
  807:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  808:                                 $env{'request.course.id'},$setting);
  809:     if ($context eq 'oldroles') {
  810:         $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' expired.').'<br />');
  811:     } elsif ($context eq 'newroles') {
  812:         $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' became available.').'<br />');
  813:     } elsif ($context eq 'crslogin') {
  814:         $r->print('<br />'.&mt('Choose the time window to use to display the last login by a user in the '.$lctype).'<br />');
  815:     } elsif ($context eq 'sessions') {
  816:         $r->print('<br />'.&mt('Choose the time limit to use to display active user sessions in the '.$lctype.'.').'<br />');
  817:     } else {
  818:         $r->print('<br />'.&mt('Choose the time window to use to display resources in the '.$lctype.' with version changes.').'<br />');
  819:     }
  820:     unless ($current eq '') {
  821:         if (ref($interval_titles->{$context}) eq 'HASH') {
  822:             $r->print(' '.&mt('Current value is "[_1]".','<b>'.
  823:                       $interval_titles->{$context}->{$current}.'</b>').'<br />');
  824:         }
  825:     }
  826:     $r->print('<br />
  827: <form method="post" name="intervalswitch" action="/adm/whatsnew">
  828: <input type="hidden" name="command" value="newinterval" />
  829: <input type="hidden" name="intervaltype" value="'.$context.'" />
  830: <input type="hidden" name="refpage" value="'.$refpage.'" />'.
  831: &mt('Display:').' 
  832: <select name="interval">
  833: <option value="" selected="selected">'.&mt('Select').'</option>
  834: ');
  835:     if (ref($interval_titles) eq 'HASH') {
  836:         if (ref($interval_titles->{$context}) eq 'HASH') {
  837:             my @sorted;
  838:             if ($context eq 'sessions') {
  839:                 @sorted = sort { $a <=> $b } (keys(%{$interval_titles->{$context}}));
  840:                 push(@sorted,shift(@sorted));
  841:             } else {
  842:                 @sorted = reverse sort ({$a cmp $b} (keys(%{$interval_titles->{$context}})));
  843:             }
  844:             foreach my $key (@sorted) {
  845:                 $r->print('<option value="'.$key.'">'.&mt($interval_titles->{$context}->{$key}).
  846:                           '</option>'."\n");
  847:             }
  848:         }
  849:     }
  850:     $r->print('</select>&nbsp;&nbsp;
  851:                <input type="submit" name="display" value="'.
  852:                &mt('Save').'" /></form>');
  853:     return;
  854: }
  855: 
  856: #----------------------------------------------
  857: # display_discussion_config
  858: #
  859: # Display the discussion display setting screen
  860: #
  861: #----------------------------------------------
  862:                                                                                   
  863: sub display_discussion_config {
  864:     my ($r,$refpage) = @_;
  865:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  866:                                 $env{'request.course.id'},'countunread');
  867:     if ($current eq '') {
  868:         $current = 'on';
  869:     }
  870:     my %opposite = ( 
  871:                       'on' => 'off',
  872:                       'off' => 'on',
  873:                     );
  874:     $r->print('<script type="text/javascript">
  875: function toggle_countunread(choice) {
  876:     if (choice == "unchanged") {
  877:         document.discussionswitch.command.value = "";
  878:     }
  879:     document.discussionswitch.submit();
  880: }
  881: </script>');
  882:     $r->print('<br />'
  883:              .&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.')
  884:              .'<br />'
  885:              .&mt("This can increase the time taken to gather data for the [_1]What's New Page[_2] by a few seconds.",'<i>','</i>')
  886:              .'&nbsp;&nbsp;'
  887:              .&mt('Currently set to [_1].','<b>'.$current.'</b>')
  888:     );
  889:     $r->print('<br /><br />
  890: <form method="post" name="discussionswitch" action="/adm/whatsnew">
  891: <input type="hidden" name="command" value="newdiscconf" />
  892: <input type="hidden" name="refpage" value="'.$refpage.'" />
  893: <input type="hidden" name="countunread" value="'.$opposite{$current}.'" />
  894: ');
  895:     $r->print('<br/>
  896:                <input type="button" name="display" value="'.
  897:                &mt('Change to [_1]',&mt($opposite{$current})).'" 
  898:                onclick="javascript:toggle_countunread('."'change'".')" />'.
  899:                ('&nbsp;' x7).
  900:                '<input type="button" name="nochange" value="'.
  901:                &mt("No change").'" 
  902:                onclick="javascript:toggle_countunread('."'unchanged'".')" />
  903:                </form>');
  904:     return;
  905: }
  906: 
  907: #---------------------------------------------------
  908: # courseinit_config
  909: #
  910: # Set page displayed when course loads after 
  911: # selecting a role in the course from the roles page. 
  912: #
  913: #---------------------------------------------------
  914: 
  915: sub courseinit_config {
  916:     my ($r,$refpage,$initpage) = @_;
  917:     my ($control,$current) = &curr_courseinit();
  918:     my @chgstate = ('userpref','coursespecific');
  919:     my @chgentry = ('firstres','whatsnew');
  920:     my $lctype = lc(&Apache::loncommon::course_type());
  921:     my %lt = &Apache::lonlocal::texthash(
  922:                              'chwp' => "Choose which page will be displayed when you enter this $lctype after selecting a role.",
  923:                              'cuva' => 'Current value is determined by',
  924:                              'anis' => 'and is set to display',
  925:                              'padc' => 'Page display controlled by',
  926:                              'chce' => 'Choose '.$lctype.' entry',
  927:                              'moce' => 'Save',
  928:     );
  929:     $r->print(<<"END"); 
  930: <br />$lt{'chwp'}
  931: <br />$lt{'cuva'}: <b>
  932: $$initpage{$control}</b> $lt{'anis'} <b>
  933: $$initpage{$current}</b>.<br /><br />
  934: <form method="post" name="courseinitswitch" action="/adm/whatsnew">
  935: <input type="hidden" name="command" value="newcourseinit" />
  936: <input type="hidden" name="refpage" value="$refpage" />
  937: $lt{'padc'}:&nbsp;&nbsp;
  938: END
  939:     foreach my $choice (@chgstate) {
  940:         my $chkstring;
  941:         if ($choice eq $control) {
  942:             $chkstring = ' checked="checked" ';
  943:         }  
  944:         $r->print('<span class="LC_nobreak"><label><input type="radio" name="courseinit_control" value="'.
  945:                    $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
  946:                    '&nbsp;&nbsp;</label></span>');
  947:     }
  948:     $r->print('<br /><br />'.&mt('If').' '.$$initpage{'coursespecific'}.
  949:               ' - <br />'.$lt{'chce'}.": \n");
  950:     foreach my $choice (@chgentry) {
  951:         my $chkstring;
  952:         if (($choice eq $current) && ($control eq 'coursespecific')) {
  953:             $chkstring = ' checked="checked" ';
  954:         }
  955:         $r->print('<span class="LC_nobreak"><label><input type="radio" name="courseinit_page" value="'.
  956:                   $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
  957:                   '&nbsp;&nbsp;</label></span>');
  958:     }
  959:     $r->print('<br /><br /><input type="submit" name="display" value="'.
  960:                $lt{'moce'}.'" /></form>');
  961:     return;
  962: }
  963: 
  964: sub curr_courseinit {
  965:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  966:                                 $env{'request.course.id'},'courseinit');
  967:     my $control;
  968:     if ($current) {
  969:         $control = 'coursespecific';
  970:     } else {
  971:         $control = 'userpref';
  972:         my %userenv = &Apache::lonnet::get('environment',
  973:                                                       ['course_init_display']);
  974:         if (exists($userenv{'course_init_display'})) {
  975:             $current = $userenv{'course_init_display'};
  976:         }
  977:         unless ($current) {
  978:             $current = 'whatsnew';
  979:         }
  980:     }
  981:     return ($control,$current);
  982: }
  983: 
  984: sub display_launcher {
  985:     my ($r,$action,$refpage,$checkallowed,$show,$headings,$res_title,
  986:         $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered,
  987:         $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs,
  988:         $interval,$countunread,$expired,$expirecount,$activated,$activecount,
  989:         $crstype,$itemserror,$loggedin,$logincount,$sessions,$sessioncount,
  990:         $classlist) = @_;
  991: 
  992:     if ($$checkallowed{$action}) {
  993:         &start_box($r,$show,$headings,$action,$refpage);
  994:         if ($$show{$action}) {
  995:             if ($action eq 'handgrading') {    # UNGRADED ITEMS
  996:                 &display_handgrade($r,$tograde,$ungraded,$itemserror);
  997:             } elsif ($action eq 'haserrors') { # BOMBS
  998:                 &display_haserrors($r,$bombs,$bombed,$res_title,$itemserror);
  999:             } elsif ($action eq 'versionchanges') { # VERSION CHANGES
 1000:                 &display_versionchanges($r,$changed,$res_title,$interval->{'versions'},$itemserror);
 1001:             } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
 1002:                 &display_abovethreshold($r,$refpage,$warnings,$triggered,
 1003: 					$res_title,$itemserror,$checkallowed);
 1004:             } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
 1005:                 &display_coursediscussion($r,$newdiscussions,$unread,
 1006:                                 $countunread,$res_title,$itemserror);
 1007:             } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES
 1008:                 &display_coursenormalmail($r,$msgcount,$newmsgs);
 1009:             } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
 1010:                 &display_coursecritmail($r,$critmsgcount,$critmsgs);
 1011:             } elsif ($action eq 'newroles') { # ACTIVATED ROLES
 1012:                 &display_rolechanges($r,$activecount,$activated,$interval->{'newroles'},
 1013:                                      $crstype,$classlist);
 1014:             } elsif ($action eq 'oldroles') { # EXPIRED ROLES
 1015:                 &display_rolechanges($r,$expirecount,$expired,$interval->{'oldroles'},
 1016:                                      $crstype,$classlist);
 1017:             } elsif ($action eq 'crslogin') { #LAST LOGIN
 1018:                 &display_activity($r,'logins',$logincount,$loggedin,$interval->{'crslogin'},
 1019:                                    $crstype,$classlist);
 1020:             } elsif ($action eq 'sessions') { #ACTIVE SESSIONS
 1021:                 &display_activity($r,'sessions',$sessioncount,$sessions,$interval->{'sessions'},
 1022:                                   $crstype,$classlist);
 1023:             }
 1024:         }
 1025:         &end_box($r);
 1026:     }
 1027:     return;
 1028: }
 1029: 
 1030: sub getitems {
 1031:     my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions,
 1032:         $tograde,$bombs,$warnings,$threshold,$cdom,$crs,$res_title,$show,
 1033:         $starttime,$countunread,$checkallowed) = @_;
 1034:     my $navmap = Apache::lonnavmaps::navmap->new();
 1035:     if (!defined($navmap)) {
 1036:         my $itemserror = '<span class="LC_warning">'.&mt('An error occurred retrieving information about the course.').'<br />'.&mt('It is recommended that you [_1]re-select the course[_2].','<a href="/adm/roles">','</a>').'</span>';
 1037:         return $itemserror;
 1038:     }
 1039:     # force retrieve Resource to seed the part id cache we'll need it later
 1040:     my @allres=$navmap->retrieveResources(undef,
 1041:                      sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
 1042:     my %resourcetracker;
 1043:     my $discussiontime;
 1044: 
 1045: # Resource version changes
 1046:     if ($$show{'versionchanges'}) {
 1047:         &checkversions($cdom,$crs,$navmap,$changed,$starttime);
 1048:     }
 1049: 
 1050:     if ($$show{'abovethreshold'}) {
 1051:         %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',
 1052:                                                                    $cdom,$crs);
 1053:     }
 1054: 
 1055:     foreach my $resource (@allres) {
 1056:         my $result = '';
 1057:         my $applies = 0;
 1058:         my $symb = $resource->symb();
 1059:         %{$$bombed{$symb}} = ();
 1060:         %{$$ungraded{$symb}} = ();
 1061:         %{$$triggered{$symb}} = ();
 1062:         $$triggered{$symb}{numparts} = 0;
 1063:         if ($resource->encrypted()) {
 1064:             $$triggered{$symb}{'enclink'} = $resource->link();
 1065:             $$triggered{$symb}{'encsymb'} = $resource->shown_symb();
 1066:         }
 1067:         my $title = $resource->compTitle();
 1068:         $$res_title{$symb} = $title;
 1069:         my $ressymb = $resource->wrap_symb();
 1070: 
 1071: # Check if there are unread discussion postings
 1072:         if ($$show{'coursediscussion'}) {
 1073:             &check_discussions($resource,$symb,$ressymb,$title,
 1074: 			       $newdiscussions,$unread,$countunread);
 1075:         }
 1076: 
 1077: # Check for ungraded problems
 1078:         if ($resource->is_problem()) {
 1079:             if ($$show{'handgrading'}) {
 1080:                 &check_handgraded($resource,$symb,$title,$cdom,$crs,$ungraded,
 1081:                                                                      $tograde);
 1082:             }
 1083:         }
 1084: 
 1085: # Check for bombs
 1086:         if ($$show{'haserrors'}) {
 1087:             &check_bombed($resource,$symb,$title,$bombs,$bombed);
 1088:         }
 1089: 
 1090: # Maxtries and degree of difficulty for problem parts, unless handgradeable
 1091:         if ($$show{'abovethreshold'}) {  
 1092:             &check_thresholds($resource,$symb,\%resourcetracker,
 1093: 			      $triggered,$threshold,$warnings,
 1094:                               $checkallowed);
 1095:         }
 1096:     }
 1097:     return; 
 1098: }
 1099: 
 1100: sub check_discussions {
 1101:     my ($resource,$symb,$ressymb,$title,$newdiscussions,$unread,
 1102: 	$countunread) = @_;
 1103: 
 1104:     if (!$resource->hasDiscussion()) { return; }
 1105: 
 1106:     %{$$unread{$ressymb}} = ();
 1107:     $$unread{$ressymb}{'title'} = $title;
 1108:     $$unread{$ressymb}{'symb'} = $symb;
 1109:     if ($resource->encrypted()) {
 1110:         $$unread{$ressymb}{'enclink'} = $resource->link();
 1111:         $$unread{$ressymb}{'encsymb'} = $resource->shown_symb();
 1112:     }
 1113:     push(@{$newdiscussions}, $ressymb);
 1114:     
 1115:     $$unread{$ressymb}{'lastpost'} = $resource->last_post_time();
 1116:     
 1117:     if ($countunread eq 'on') {
 1118: 	$$unread{$ressymb}{'unreadcount'} = 
 1119:                             $resource->discussion_info('unread');
 1120:     }
 1121: }
 1122: 
 1123: sub check_handgraded {
 1124:     my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_;
 1125:     if ($resource->is_problem()) {
 1126:         my ($handgradeable,$is_task);
 1127:         my $partlist=$resource->parts();
 1128:         if ($resource->is_task()) {
 1129:             $is_task = 1;
 1130:             foreach my $part (@$partlist) {
 1131:                 if ($resource->handgrade($part) eq 'yes') {
 1132:                     $handgradeable=1;
 1133:                     last;
 1134:                 }
 1135:             }
 1136:         } else {
 1137:             foreach my $part (@$partlist) {
 1138:                 my @types = $resource->responseType($part);
 1139:                 if (grep(/^essay$/,@types)) {
 1140:                     $handgradeable=1;
 1141:                     last;
 1142:                 } elsif (grep(/^custom$/,@types)) {
 1143:                     if ($resource->handgrade($part) eq 'yes') {
 1144:                         $handgradeable=1;
 1145:                         last;
 1146:                     }
 1147:                 }
 1148:             }
 1149:         }
 1150:         if ($handgradeable) {
 1151:             my @ungraded = &Apache::bridgetask::get_queue_symb_status(
 1152:                                              'gradingqueue',$symb,$cdom,$cnum);
 1153:             if (@ungraded > 0) {
 1154:                 $$ungraded{$symb}{count} = scalar(@ungraded);
 1155:                 $$ungraded{$symb}{title} = $title;
 1156:                 $$ungraded{$symb}{is_task} = $is_task;
 1157:                 if ($resource->encrypted()) {
 1158:                     $$ungraded{$symb}{'enclink'} = $resource->link();
 1159:                     $$ungraded{$symb}{'encsymb'} = $resource->shown_symb();
 1160:                 }
 1161:                 push(@{$tograde},$symb);
 1162:             }
 1163:         }
 1164:     }
 1165: }
 1166: 
 1167: sub check_bombed {
 1168:     my ($resource,$symb,$title,$bombs,$bombed) = @_;
 1169:     if ($resource->getErrors()) {
 1170:         my $errors = $resource->getErrors();
 1171:         $errors =~ s/^,//;
 1172:         my @bombs = split(/,/, $errors);
 1173:         my $errorcount = scalar(@bombs);
 1174:         my $errorlink = '<a href="/adm/email?display='.
 1175:                         &escape($bombs[0]).'">'.
 1176:                         $title.'</a>';
 1177:         $$bombed{$symb}{errorcount} = $errorcount;
 1178:         $$bombed{$symb}{errorlink} = $errorlink;
 1179:         push(@{$bombs}, $symb);
 1180:     }
 1181: }
 1182: 
 1183: sub check_thresholds {
 1184:     my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings,
 1185:         $checkallowed) = @_;
 1186: # Compile maxtries and degree of difficulty for problem parts, unless handgradeable
 1187:     my @parts = @{$resource->parts()};
 1188:     my %stats;
 1189:     my %lastreset = ();
 1190:     my $warning = 0;
 1191:     foreach my $part (@parts) {
 1192:         if ($resource->handgrade($part) eq 'yes') {
 1193:             next;
 1194:         }
 1195:         if ($resource->is_anonsurvey($part)) {
 1196:             next;
 1197:         }
 1198:         if ($resource->is_survey($part)) {
 1199:             next;
 1200:         }
 1201:         %{$stats{$part}} = ();
 1202:         my ($attempts,$users,$corrects,$degdiff,$av_attempts);
 1203:         if (exists($$resourcetracker{$symb."\0".$part."\0attempts"})) {
 1204:             $attempts = $$resourcetracker{$symb."\0".$part."\0attempts"};
 1205:         }
 1206:         if (exists($$resourcetracker{$symb."\0".$part."\0users"})) {
 1207:             $users = $$resourcetracker{$symb."\0".$part."\0users"};
 1208:         }
 1209:         if (exists($$resourcetracker{$symb."\0".$part."\0correct"})) {
 1210:             $corrects = $$resourcetracker{$symb."\0".$part."\0correct"};
 1211:         }
 1212:         if ($attempts > 0) {
 1213:             $degdiff =  1 - ($corrects/$attempts);
 1214:             $degdiff = sprintf("%.2f",$degdiff);
 1215:         }
 1216:         if ($users > 0) {
 1217:             $av_attempts = $attempts/$users;
 1218:             $av_attempts = sprintf("%.2f",$av_attempts);
 1219:         }
 1220:         &Apache::lonnet::statslog($symb,$part,$users,$av_attempts,$degdiff);
 1221:         if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
 1222:             $stats{$part}{degdiff} = $degdiff;
 1223:             $stats{$part}{attempts} = $av_attempts;
 1224:             $stats{$part}{users} = $users;
 1225:             $lastreset{$part} = $$resourcetracker{$symb."\0".$part."\0resettime"};
 1226:             if ($lastreset{$part}) {
 1227:                 $lastreset{$part} = &Apache::lonnavmaps::timeToHumanString($lastreset{$part});
 1228:             }
 1229:             $warning = 1;
 1230:         }
 1231:     }
 1232:     if ($warning) {
 1233:         $$triggered{$symb}{title} = $resource->title;
 1234:         my $partcount = 0;
 1235:         @{$$triggered{$symb}{text}} = ();
 1236:         foreach my $part (@parts) {
 1237:             if (exists($stats{$part}{users})) {
 1238:                 my $resetname = 'reset_'.&escape($symb."\0".$part);
 1239:                 my $resettitle = 'title_'.&escape($symb."\0".$part);
 1240:                 if (@parts > 1) {
 1241:                     $$triggered{$symb}{text}[$partcount] = '
 1242:                      <td>'.&mt('part - ').$part.'</td>';
 1243:                 } else {
 1244:                     $$triggered{$symb}{text}[$partcount] = '
 1245:                      <td>'.&mt('single part').'</td>';
 1246:                 }
 1247:                 $$triggered{$symb}{text}[$partcount] .= '
 1248:                      <td>'.$stats{$part}{users}.'</td>
 1249:                      <td>'.$stats{$part}{attempts}.'</td>
 1250:                      <td>'.$stats{$part}{degdiff}.'</td>
 1251:                      <td>'.$lastreset{$part}.'</td>';
 1252:                 if ($checkallowed->{'resetcounters'}) {
 1253:                     $$triggered{$symb}{text}[$partcount] .=
 1254:                         '<td><input type="checkbox" name="'.$resetname.'" />'.
 1255:                         '<input type="hidden" name="'.$resettitle.'" value="'.&escape($$triggered{$symb}{title}).'" /></td>';
 1256:                 }
 1257:                 $partcount ++;
 1258:             }
 1259:             $$triggered{$symb}{numparts} = $partcount;
 1260:         }
 1261:         push(@{$warnings},$symb);
 1262:     }
 1263: }
 1264: 
 1265: 
 1266: sub get_curr_thresholds {
 1267:     my ($threshold,$uname,$udom,$cid,$cdom,$crs) = @_;
 1268:     # set default values
 1269:     %$threshold = (av_attempts => 2,
 1270:                   degdiff => 0.5,
 1271:                   numstudents => 2
 1272:                   );
 1273:     my %thresholdsettings = &Apache::lonnet::dump('nohist_whatsnew',$udom,
 1274:                                                      $uname,$cid.':threshold');
 1275:     my $thresholdcount = 0;
 1276:     my ($tmp) = %thresholdsettings;
 1277:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1278:         foreach my $item (keys(%{$threshold})) { 
 1279:             if (exists($thresholdsettings{$cid.':threshold_'.$item})) {
 1280:                 $$threshold{$item} = 
 1281:                              $thresholdsettings{$cid.':threshold_'.$item};
 1282:                 $thresholdcount ++;
 1283:             }
 1284:         }
 1285:     }
 1286:     if ($thresholdcount == 3) {
 1287:         return;
 1288:     }
 1289:     my %coursesettings = &Apache::lonnet::dump('environment',
 1290:                                               $cdom,$crs,'internal.threshold');
 1291:     my ($temp) = %coursesettings;
 1292:     unless ($temp =~ /^(con_lost|error|no_such_host)/i) {  
 1293:         foreach my $item (keys(%{$threshold})) {
 1294:             unless (exists($thresholdsettings{$cid.':threshold_'.$item})) {
 1295:                 if (exists($coursesettings{'internal.threshold_'.$item})) {
 1296:                     $$threshold{$item} = 
 1297:                              $coursesettings{'internal.threshold_'.$item};
 1298:                 }
 1299:             }
 1300:         }
 1301:     }
 1302:     return;
 1303: }
 1304: 
 1305: sub get_current {
 1306:     my ($uname,$udom,$cid,$caller) = @_;
 1307:     my $currvalue;
 1308:     my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid.
 1309:                                                                 ':'.$caller);
 1310:     my ($tmp) = %settings;
 1311:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1312:         $currvalue = $settings{$cid.':'.$caller};
 1313:     }
 1314:     return $currvalue;
 1315: }
 1316: 
 1317: sub process_reset {
 1318:     my ($dom,$crs,$checkallowed) = @_;
 1319:     if (!$checkallowed->{'resetcounters'}) {
 1320:         return '<b>'.&mt('You do not have the required privileges to reset counters').
 1321:                '</b><br />';
 1322:     }
 1323:     my $result = '<b>'.&mt('Counters reset for following problems (and parts):').
 1324:                            '</b><br />';
 1325:     my @agg_types = ('attempts','users','correct');
 1326:     my %agg_titles = &Apache::lonlocal::texthash (
 1327:                      attempts => 'Number of submissions',
 1328:                      users => 'Students with submissions',
 1329:                      correct => 'Number of correct submissions',
 1330:                      );
 1331:     my @resets = ();
 1332:     my %titles = ();
 1333:     foreach my $key (keys(%env)) {
 1334:         next if ($key !~ /^form\.reset_(.+)$/);
 1335:         my $title = &unescape($env{'form.title_'.$1});
 1336:         my $reset_item = &unescape($1);
 1337:         my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
 1338:         my %aggregates = ();
 1339:         my ($symb,$part) = split(/\0/,$reset_item);
 1340:         foreach my $type (@agg_types) {
 1341:             $aggregates{$reset_item."\0".$type} = 0;
 1342:         }  
 1343: 	$aggregates{$reset_item."\0".'resettime'} = time;
 1344:         my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
 1345:                           $dom,$crs);
 1346:         if ($putresult eq 'ok') {
 1347:             $result .= $title.' -part '.$part.': ';
 1348:             my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
 1349:             foreach my $type (@agg_types) {
 1350:                 $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
 1351:             }
 1352:             $result =~ s/; $//;
 1353:             $result .= '<br />';
 1354:         } else {
 1355:             $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
 1356:         }
 1357:     }
 1358:     return $result;
 1359: }
 1360: 
 1361: sub process_update {
 1362:     my ($uname,$udom,$threshold_titles) = @_;
 1363:     my $setoutput = '<b>'.&mt('Changes to threshold(s) for problem tracking:').'</b><br/><br />';
 1364:     foreach my $key (keys(%env)) {
 1365:         my $name;
 1366:         if ($key =~/^form\.(.+)\_setparmval$/) {
 1367:             $name  = $1;
 1368:         } else {
 1369:             next;
 1370:         }
 1371:         my $value = $env{'form.'.$name.'_value'};
 1372:         if ($name && defined($value) && ($value ne '')) {
 1373:             my $put_result = &Apache::lonnet::put('nohist_whatsnew',
 1374:                                                   {$name=>$value},$udom,$uname);
 1375:            
 1376:             my ($shortname) = ($name =~ /^\Q$env{'request.course.id'}\E:threshold_(.+)$/);
 1377:             if ($put_result eq 'ok') {
 1378:                 $setoutput.= &Apache::lonhtmlcommon::confirm_success(&mt('Set threshold for [_1] to [_2]',
 1379: 				'<b>'.$$threshold_titles{$shortname}.'</b>',
 1380: 				'<b>'.$value.'</b>').'<br />');
 1381: 	    } else {
 1382:                 $setoutput.= &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
 1383: 				'<b>'.$name.'</b>','<b>'.$value.'</b>',
 1384: 				'<tt>'.$put_result.'</tt>').'<br />',1);
 1385:             }
 1386:         }
 1387:     }
 1388:     return &Apache::loncommon::confirmwrapper($setoutput);
 1389: }
 1390: 
 1391: sub getnormalmail {
 1392:     my ($newmsgs) = @_;
 1393: # Check for unread messages in user's INBOX (which were sent in context of current course).
 1394:     my $msgcount = 0;
 1395:     my @messages = &Apache::lonnet::getkeys('nohist_email');
 1396:     return $msgcount if (!@messages);
 1397:     my %emailstatus = &Apache::lonnet::dump('email_status');
 1398:     foreach my $msgid (sort(@messages)) {
 1399:         if ((!$emailstatus{$msgid}) || ($emailstatus{$msgid} eq 'new')) {
 1400:             my $skipstatus;
 1401:             if ($emailstatus{$msgid} eq 'new') {
 1402:                 $skipstatus = 1;
 1403:             }
 1404:             my $esc_msgid = &escape($msgid);
 1405:             my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 1406:                 &Apache::lonmsg::unpackmsgid($esc_msgid,undef,$skipstatus,undef,
 1407:                                              $env{'request.course.id'});
 1408:             if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
 1409:                 if (defined($sendtime) && $sendtime!~/error/) {
 1410:                     if (($emailstatus{$msgid} eq 'new') || ($status eq 'new')) {
 1411:                         $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
 1412: 		        $msgcount ++;
 1413:                         if ($shortsubj eq '') {
 1414:                             $shortsubj = &mt('No subject');
 1415:                         }
 1416:                         push(@{$newmsgs}, {
 1417:                             msgid    => $esc_msgid,
 1418:                             sendtime => $sendtime,
 1419:                             shortsub => $shortsubj,
 1420:                             from     => $fromname,
 1421:                             fromdom  => $fromdom
 1422:                             });
 1423:                     }
 1424:                 }
 1425:             }
 1426:         }
 1427:     }
 1428:     return $msgcount;
 1429: }
 1430: 
 1431: sub getcritmail {
 1432:     my ($critmsgs) = @_; 
 1433: # Check for critical messages which were sent in context of current course.
 1434:     my %what=&Apache::lonnet::dump('critical');
 1435:     my $result = '';
 1436:     my $critmsgcount = 0;
 1437:     foreach my $msgid (sort(keys(%what))) {
 1438:         my $esc_msgid = &escape($msgid);
 1439:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 1440:             &Apache::lonmsg::unpackmsgid($esc_msgid,undef,1,undef,
 1441:                                          $env{'request.course.id'});
 1442:         if (($fromcid) && ($fromcid eq  $env{'request.course.id'})) {
 1443:             if (defined($sendtime) && $sendtime!~/error/) {
 1444:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
 1445:                 $critmsgcount ++;
 1446:                 if ($shortsubj eq '') {
 1447:                     $shortsubj = &mt('No subject');
 1448:                 }
 1449:                 push(@{$critmsgs}, {
 1450:                         msgid    => $esc_msgid,
 1451:                         sendtime => $sendtime,
 1452:                         shortsub => $shortsubj,
 1453:                         from     => $fromname,
 1454:                         fromdom  => $fromdom
 1455:                         });
 1456:             }
 1457:         }
 1458:     }
 1459:     return $critmsgcount;
 1460: }
 1461: 
 1462: sub getexpired {
 1463:     my ($rolechgs,$rolechgtime,$status,$classlist) = @_;
 1464:     my $expirecount = &getrolechanges($rolechgs,$rolechgtime,$status,$classlist);
 1465:     return $expirecount;
 1466: }
 1467: 
 1468: sub getactivated {
 1469:     my ($rolechgs,$rolechgtime,$status,$classlist) = @_;
 1470:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1471:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1472:     my $now = time();
 1473:     my $context = 'course';
 1474:     my ($permission,$allowed) =
 1475:         &Apache::lonuserutils::get_permission($context);
 1476:     my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
 1477:     my %changes=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
 1478:     my (%stucounted,%advcounted);
 1479:     my $activatedcount = 0;
 1480:     if (keys(%changes) > 0) {
 1481:         foreach my $chg (keys(%changes)) {
 1482:             if (ref($changes{$chg}) eq 'HASH') {
 1483:                 next if ($changes{$chg}{'delflag'});
 1484:                 if ($rolechgtime > 0) {
 1485:                     next if ($changes{$chg}{'exe_time'} < $rolechgtime);
 1486:                 }
 1487:                 if ($changes{$chg}{'exe_time'}) {
 1488:                     my $timestamp = $changes{$chg}{'exe_time'};
 1489:                     if (ref($changes{$chg}{'logentry'}) eq 'HASH') {
 1490:                         my $end = $changes{$chg}{'logentry'}{'end'};
 1491:                         next if ($end && $end <= $now);
 1492:                         my $start = $changes{$chg}{'logentry'}{'start'};
 1493:                         next if ($start >= $timestamp);
 1494:                         my $section = $changes{$chg}{'logentry'}{'section'};
 1495:                         if (($viewablesec ne '') && ($section ne '')) {
 1496:                             next if ($viewablesec ne $section);
 1497:                         }
 1498:                         my $role = $changes{$chg}{'logentry'}{'role'};
 1499:                         my $uname = $changes{$chg}{'uname'};
 1500:                         my $udom = $changes{$chg}{'udom'};
 1501:                         if ($role eq 'st') {
 1502:                             $stucounted{$uname.':'.$udom.':'.$section} = $start.':'.$end;
 1503:                         } else {
 1504:                             $advcounted{$uname.':'.$udom.':'.$role.':'.$section} = $start.':'.$end;
 1505:                         }
 1506:                         my %chginfo = (
 1507:                                        'section' => $section,
 1508:                                        'uname'   => $uname,
 1509:                                        'udom'    => $udom,
 1510:                                        'role'    => $role,
 1511:                                        'status'  => $status,
 1512:                         );
 1513:                         $activatedcount ++;
 1514:                         push (@{$rolechgs->{$timestamp}},\%chginfo);
 1515:                     }
 1516:                 }
 1517:             }
 1518:         }
 1519:     }
 1520:     $activatedcount += &getrolechanges($rolechgs,$rolechgtime,$status,$classlist,\%stucounted,
 1521:                                        \%advcounted);
 1522:     return $activatedcount;
 1523: }
 1524: 
 1525: sub getrolechanges {
 1526:     my ($rolechgs,$rolechgtime,$status,$classlist,$stucountref,$advcountref) = @_;
 1527:     my (%stucounted,%advcounted);
 1528:     if (ref($stucountref) eq 'HASH') {
 1529:         %stucounted = %{$stucountref};
 1530:     }
 1531:     if (ref($advcountref) eq 'HASH') {
 1532:         %advcounted = %{$advcountref};
 1533:     }
 1534:     my $withsec = 1;
 1535:     my $hidepriv = 1;
 1536:     my $context = 'course';
 1537:     my @statuses = ($status);
 1538:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1539:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1540:     my $now = time();
 1541:     my ($permission,$allowed) =
 1542:         &Apache::lonuserutils::get_permission($context);
 1543:     my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
 1544:     my $secidx = &Apache::loncoursedata::CL_SECTION();
 1545:     my $startidx = &Apache::loncoursedata::CL_START();
 1546:     my $endidx = &Apache::loncoursedata::CL_END();
 1547:     my $rolechgcount = 0;
 1548:     if (ref($classlist) eq 'HASH') {
 1549:         foreach my $key (keys(%{$classlist})) {
 1550:             my ($userstatus,$eventtime);   
 1551:             my $student = $classlist->{$key};
 1552:             if (ref($student) eq 'ARRAY') {
 1553:                 my $start = $student->[$startidx];
 1554:                 my $end = $student->[$endidx];
 1555:                 my $sec = $student->[$secidx]; 
 1556:                 my ($stuname,$studom) = split(/:/,$key);
 1557:                 if ($status eq 'active') {
 1558:                     if (exists($stucounted{$key.':'.$sec})) {
 1559:                         next;
 1560:                     }
 1561:                 }
 1562:                 if (($end == 0) || ($end > $start)) {
 1563:                     if ($start <= $now) {
 1564:                         if ($end && $end < $now) {
 1565:                             if ($rolechgtime > 0) {
 1566:                                 if ($end > $rolechgtime) {
 1567:                                     $userstatus = 'previous';
 1568:                                 }
 1569:                             } else {
 1570:                                 $userstatus = 'previous';
 1571:                             }
 1572:                         } else {
 1573:                             if ($rolechgtime > 0) {
 1574:                                 if ($start >= $rolechgtime) {
 1575:                                     $userstatus = 'active';
 1576:                                 }
 1577:                             } else {
 1578:                                 $userstatus = 'active';
 1579:                             }
 1580:                         }
 1581:                     }
 1582:                 }
 1583:                 next if ($userstatus ne $status);
 1584:                 if ($status eq 'active') {
 1585:                     $eventtime = $start;
 1586:                 } else {
 1587:                     $eventtime = $end;
 1588:                 }
 1589:                 if (($viewablesec ne '') && ($sec ne '')) {
 1590:                     next if ($viewablesec ne $sec);
 1591:                 }
 1592:                 my %chginfo = (
 1593:                                 'section' => $sec,
 1594:                                 'uname'   => $stuname,
 1595:                                 'udom'    => $studom,
 1596:                                 'role'    => 'st', 
 1597:                                 'status'  => $userstatus,
 1598:                               );
 1599:                 $rolechgcount ++;
 1600:                 push(@{$rolechgs->{$eventtime}},\%chginfo);
 1601:             }
 1602:         }
 1603:     }
 1604:     my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
 1605:                               \@statuses,undef,undef,$withsec,$hidepriv);
 1606:     foreach my $item (keys(%advrolehash)) {
 1607:         my ($userstatus,$eventtime);
 1608:         my ($uname,$udom,$role,$section) = split(/:/,$item,-1);
 1609:         my ($start,$end) = split(/:/,$advrolehash{$item});
 1610:         if ($start eq '-1' && $end eq '-1') {
 1611:             next;
 1612:         } else {
 1613:             if ($status eq 'active') {
 1614:                 if (exists($advcounted{$item})) {
 1615:                     next;
 1616:                 }
 1617:             }
 1618:             if (($end == 0) || ($end > $start)) {
 1619:                 if ($start <= $now) {
 1620:                     if ($end && $end < $now) {
 1621:                         if ($rolechgtime > 0) {
 1622:                             if ($end > $rolechgtime) {
 1623:                                 $userstatus = 'previous';
 1624:                             }
 1625:                         } else {
 1626:                             $userstatus = 'previous';
 1627:                         }
 1628:                     } else {
 1629:                         if ($rolechgtime > 0) {
 1630:                             if ($start >= $rolechgtime) {
 1631:                                 $userstatus = 'active';
 1632:                             }
 1633:                         } else {
 1634:                             $userstatus = 'active';
 1635:                         }
 1636:                     }
 1637:                 }
 1638:             }
 1639:             next if ($userstatus ne $status);
 1640:             if ($status eq 'active') {
 1641:                 $eventtime = $start;
 1642:             } else {
 1643:                 $eventtime = $end;
 1644:             }
 1645:         }
 1646:         if (($viewablesec ne '') && ($section ne '')) {
 1647:             next if ($viewablesec ne $section);
 1648:         }
 1649:         my %chginfo = ( 
 1650:                         'section' => $section,
 1651:                         'uname'   => $uname,
 1652:                         'udom'    => $udom,
 1653:                         'role'    => $role,
 1654:                         'status'  => $userstatus,    
 1655:                       );
 1656:         $rolechgcount ++; 
 1657:         push (@{$rolechgs->{$eventtime}},\%chginfo); 
 1658:     }
 1659:     return $rolechgcount;
 1660: }
 1661: 
 1662: sub getloggedin {
 1663:     my ($cdom,$crs,$lastlogins,$starttime) = @_;
 1664:     my $context = 'course';
 1665:     my ($permission,$allowed) =
 1666:         &Apache::lonuserutils::get_permission($context);
 1667:     my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
 1668:     my %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$crs);
 1669:     my $logincount = 0;
 1670:     my ($tmp) = keys(%crslogins);
 1671:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1672:         if (keys(%crslogins) > 0) {
 1673:             foreach my $key (keys(%crslogins)) {
 1674:                 my ($uname,$udom,$section,$role) = split(/:/,$key);
 1675:                 my $eventtime = $crslogins{$key};
 1676:                 if ($eventtime > $starttime) {
 1677:                     if (($viewablesec ne '') && ($section ne '')) {
 1678:                         next if ($viewablesec ne $section);
 1679:                     }
 1680:                     my %chginfo = (
 1681:                                    'section' => $section,
 1682:                                    'uname'   => $uname,
 1683:                                    'udom'    => $udom,
 1684:                                    'role'    => $role,
 1685:                     );
 1686:                     $logincount ++;
 1687:                     push (@{$lastlogins->{$eventtime}},\%chginfo);
 1688:                 }
 1689:             }
 1690:         }
 1691:     }
 1692:     return $logincount;
 1693: }
 1694: 
 1695: sub getsessions {
 1696:     my ($cdom,$cnum,$sessions,$lastactive,$classlist) = @_;
 1697:     my $context = 'course';
 1698:     my ($permission,$allowed) =
 1699:         &Apache::lonuserutils::get_permission($context);
 1700:     my %crs_sessions = &Apache::lonnet::get_course_sessions($cnum,$cdom,$lastactive);
 1701:     my $sessioncount = 0;
 1702:     if (keys(%crs_sessions) > 0) {
 1703:         if (ref($classlist) eq 'HASH') {
 1704:             my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
 1705:             my $secidx = &Apache::loncoursedata::CL_SECTION();
 1706:             my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'_'.$cnum,1);
 1707:             my %personnel;
 1708:             foreach my $role (sort(keys(%coursepersonnel))) {
 1709:                 my ($rolecode,$section);
 1710:                 if ($role =~ /:/) {
 1711:                     ($rolecode,$section) = split(/:/,$role);
 1712:                 } else {
 1713:                     $rolecode = $role;
 1714:                 }
 1715:                 if ($viewablesec ne '') {
 1716:                     next if ($viewablesec ne $section);
 1717:                 }
 1718:                 foreach my $user (split(/\,/,$coursepersonnel{$role})) {
 1719:                     push(@{$personnel{$user}{$rolecode}},$section);
 1720:                 }
 1721:             }
 1722:             foreach my $key (keys(%crs_sessions)) {
 1723:                 if (exists($classlist->{$key})) {
 1724:                     my $student = $classlist->{$key};
 1725:                     my $section = $student->[$secidx];
 1726:                     my $lastaccess = $crs_sessions{$key};
 1727:                     if ($viewablesec ne '') {
 1728:                         next if ($viewablesec ne $section);
 1729:                     }
 1730:                     my ($stuname,$studom) = split(/:/,$key);
 1731:                     my %info = (
 1732:                                  'section' => $section,
 1733:                                  'role'    => 'st',
 1734:                                  'uname'   => $stuname,
 1735:                                  'udom'    => $studom,
 1736:                     );
 1737:                     $sessioncount ++;
 1738:                     push(@{$sessions->{$lastaccess}},\%info);
 1739:                 } elsif (exists($personnel{$key})) {
 1740:                     my $lastaccess = $crs_sessions{$key};
 1741:                     my ($uname,$udom) = split(/:/,$key);
 1742:                     if (ref($personnel{$key}) eq 'HASH') {
 1743:                         my ($showrole,$showsec);
 1744:                         foreach my $possrole ('cc','co','in','ta','ep','ad','st') {
 1745:                             if (exists($personnel{$key}{$possrole})) {
 1746:                                 $showrole = $possrole;
 1747:                                 $showsec = join(', ',@{$personnel{$key}{$possrole}});
 1748:                                 last;
 1749:                             }
 1750:                         }
 1751:                         my %info = (
 1752:                                      'section' => $showsec,
 1753:                                      'role'    => $showrole,
 1754:                                      'uname'   => $uname,
 1755:                                      'udom'    => $udom,
 1756:                         );
 1757:                         $sessioncount ++;
 1758:                         push(@{$sessions->{$lastaccess}},\%info);
 1759:                     }
 1760:                 }
 1761:             }
 1762:         }
 1763:     }
 1764:     return $sessioncount;
 1765: }
 1766: 
 1767: sub checkversions {
 1768:     my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
 1769:     my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
 1770:     my ($tmp) = keys(%changes);
 1771:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1772:         if (keys(%changes) > 0) {
 1773:             foreach my $key (sort(keys(%changes))) {
 1774:                 if ($changes{$key} > $starttime) {
 1775:                     my $version;
 1776:                     my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
 1777:                     my $currentversion=&Apache::lonnet::getversion($key);
 1778:                     my $revdate = 
 1779:                           &Apache::lonnet::metadata($root.'.'.$extension,
 1780:                                                      'lastrevisiondate');
 1781:                     $revdate =  &Apache::lonlocal::locallocaltime($revdate);
 1782:                     my $linkurl=&Apache::lonnet::clutter($key);
 1783:                     my $usedversion=$navmap->usedVersion($linkurl);
 1784:                     my @resources = $navmap->getResourceByUrl($linkurl,1);
 1785:                     if (($usedversion) && ($usedversion ne 'mostrecent')) {
 1786:                         $version = $usedversion;     
 1787:                     } else {
 1788:                         $version = $currentversion;
 1789:                     }
 1790:                     foreach my $res (@resources) {
 1791:                          if (ref($res) eq 'Apache::lonnavmaps::resource') { 
 1792:                             my $symb = $res->symb();
 1793:                             %{$$changed{$symb}} = (
 1794:                                                 current => $currentversion,
 1795:                                                 version => $version,
 1796:                                                 revdate => $revdate,
 1797:                             );
 1798:                         }
 1799:                     }
 1800:                 }
 1801:             }
 1802:         }
 1803:     }
 1804:     return;
 1805: }
 1806: 
 1807: sub display_handgrade {
 1808:     my ($r,$tograde,$ungraded,$itemserror) = @_;
 1809:     my %lt = &Apache::lonlocal::texthash(
 1810:                         'prna' => 'Problem Name',
 1811:                         'nmun' => 'Number ungraded',
 1812:                         'nopr' => 'No problems require handgrading',
 1813:     );
 1814:     if (@{$tograde} > 0) {
 1815:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1816:                   $lt{'prna'}.'</td><td class="LC_right_item">'.
 1817:                   $lt{'nmun'}.'</td></tr>');
 1818:         my $rowNum = 0;
 1819:         foreach my $res (@{$tograde}) {
 1820:             $rowNum ++;
 1821:             my $css_class = $rowNum%2?' class="LC_odd_row"':'';
 1822:             my $linkurl;
 1823:             if ($$ungraded{$res}{'is_task'}) {
 1824:                 my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
 1825:                 $linkurl=&Apache::lonnet::clutter($url);
 1826:                 $linkurl .= '?symb='.&escape($res);
 1827:                 if ($$ungraded{$res}{'enclink'}) {
 1828:                     $linkurl =
 1829:                         $$ungraded{$res}{'enclink'}.'?symb='.$$ungraded{$res}{'encsymb'};
 1830:                 }
 1831:             } else {
 1832:                 $linkurl='/adm/grades';
 1833:                 if ($$ungraded{$res}{'enclink'}) {
 1834:                     $linkurl.='?symb='.$$ungraded{$res}{'encsymb'};
 1835:                 } else {
 1836:                     $linkurl.='?symb='.&escape($res);
 1837:                 }
 1838:                 $linkurl.='&amp;command=ungraded';
 1839:             }
 1840:             $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.$$ungraded{$res}{title}.'</a></td><td class="LC_right_item">'.$$ungraded{$res}{count}.'</td></tr>');
 1841:         }
 1842:     } elsif ($itemserror) {
 1843:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1844:     } else {
 1845:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
 1846:     }
 1847: }
 1848: 
 1849: sub display_haserrors {
 1850:     my ($r,$bombs,$bombed,$res_title,$itemserror) = @_;
 1851:     my $bombnum = 0;
 1852:     my %lt = &Apache::lonlocal::texthash(
 1853:                                    reso => 'Resource',
 1854:                                    nmer => 'Number of errors',
 1855:                                    noer => 'No problems with errors',
 1856:     );
 1857:     if (@{$bombs} > 0) {
 1858:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1859:                   $lt{'reso'}.'</td><td class="LC_right_item">'.
 1860:                   $lt{'nmer'}.'</td></tr>');
 1861:         @{$bombs} = sort { &cmp_title($a,$b,$res_title) } @{$bombs};
 1862:         foreach my $bomb (@{$bombs}) {
 1863:             $bombnum ++;
 1864:             my $css_class = $bombnum%2?' class="LC_odd_row"':'';
 1865:             $r->print('<tr'.$css_class.'><td>'.$$bombed{$bomb}{errorlink}.
 1866:                       '</td><td class="LC_right_item">'.
 1867:                       $$bombed{$bomb}{errorcount}.'</td></tr>');
 1868:         }
 1869:     } elsif ($itemserror) {
 1870:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1871:     } else {
 1872:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'noer'}.'</td></tr>');
 1873:     }
 1874:     return;
 1875: }
 1876: 
 1877: sub display_abovethreshold {
 1878:     my ($r,$refpage,$warnings,$triggered,$res_title,$itemserror,$checkallowed) = @_;
 1879:     my %lt = &Apache::lonlocal::texthash(
 1880:                  reso => 'Resource',
 1881:                  part => 'Part',
 1882:                  nust => 'Num. students',
 1883:                  avat => 'Av. Attempts',
 1884:                  dedi => 'Deg. Diff',
 1885:                  lare => 'Last Reset',
 1886:                  reco => 'Reset Count?',
 1887:                  rese => 'Reset counters to 0',
 1888:                  nopr => 'No problems satisfy threshold criteria',
 1889:     );
 1890:     if (@{$warnings} > 0) {
 1891:         @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
 1892:         $r->print('<tr class="LC_info_row">'.
 1893: 		  '<td class="LC_left_item">'.$lt{'reso'}.
 1894:                   '<input type="hidden" name="command" value="" /></td>'.
 1895: 		  '<td>'.$lt{'part'}.'</td><td>'.$lt{'nust'}.'</td>'.
 1896: 		  '<td>'.$lt{'avat'}.'</td><td>'.$lt{'dedi'}.'</td>'.
 1897: 		  '<td>'.$lt{'lare'}.'</td>');
 1898:         if ($checkallowed->{'resetcounters'}) {
 1899:             $r->print('<td  class="LC_right_item">'.$lt{'reco'}.'</td>');
 1900:         }
 1901:         $r->print('</tr>');
 1902: 	my $row;
 1903:         foreach my $res (@{$warnings}) {
 1904: 	    $row++;
 1905:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
 1906:             my $linkurl=&Apache::lonnet::clutter($url);
 1907:             my $rowspan;
 1908:             if ($$triggered{$res}{numparts} > 1) {
 1909:                 $rowspan = 'rowspan="'.$$triggered{$res}{numparts}.'"';
 1910:             }
 1911:             $linkurl .= '?symb='.&escape($res);
 1912:             if ($$triggered{$res}{'enclink'}) {
 1913:                 $linkurl = 
 1914:                   $$triggered{$res}{'enclink'}.'?symb='.$$triggered{$res}{'encsymb'};
 1915:             }
 1916:             my $css_class = $row%2?' class="LC_odd_row"':'';
 1917:             $r->print('<tr'.$css_class.'>'.
 1918: 		      '<td class="LC_first_item" '.$rowspan.'><a href="'.$linkurl.'">'.
 1919: 		      $$triggered{$res}{title}.'</a></td>');
 1920:                       if (ref($$triggered{$res}{text}) eq 'ARRAY') {
 1921: 		          $r->print($$triggered{$res}{text}[0]);
 1922:                       }
 1923:                       $r->print('</tr>');
 1924:             if (ref($$triggered{$res}{text}) eq 'ARRAY') {
 1925:                 if (@{$$triggered{$res}{text}} > 1) {
 1926:                     for (my $i=1; $i<@{$$triggered{$res}{text}}; $i++) {
 1927:                         $r->print('<tr '.$css_class.'>'.
 1928:                                   $$triggered{$res}{text}[$i].'</tr>');
 1929:                     }
 1930:                 }
 1931:             }
 1932:         }
 1933:         if ($checkallowed->{'resetcounters'}) {
 1934:             $r->print('<tr class="LC_info_row"><td colspan="7" class="LC_right_item"><br /><input type="button" name="counters" value="'.$lt{'rese'}.'" onclick="javascript:thresholdreset();" /></td></tr>');
 1935:         }
 1936:     } elsif ($itemserror) {
 1937:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1938:     } else {
 1939:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
 1940:     }
 1941: }
 1942: 
 1943: sub display_versionchanges {
 1944:     my ($r,$changed,$res_title,$interval,$itemserror) = @_;
 1945:     my %lt = &Apache::lonlocal::texthash(
 1946:         'reso' => 'Resource',
 1947:         'revd' => 'Last revised',
 1948:         'newv' => 'New version',
 1949:         'veru' => 'Version used',
 1950:     );
 1951:     if (keys(%{$changed}) > 0) {
 1952:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1953:                   $lt{'reso'}.'</td><td>'.$lt{'revd'}.'</td><td>'.
 1954:                   $lt{'newv'}.'</td><td class="LC_right_item">'.
 1955:                   $lt{'veru'}.'</td></tr>');
 1956:         my @changes = sort { &cmp_title($a,$b,$res_title) } keys(%{$changed});
 1957:         my $changenum = 0;
 1958:         foreach my $item (@changes) {
 1959:             $changenum ++;
 1960:             my $css_class = $changenum%2?' class="LC_odd_row"':'';
 1961:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($item);
 1962:             my $linkurl=&Apache::lonnet::clutter($url);
 1963:             $linkurl .= '?symb='.&escape($item);
 1964: 
 1965:             $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.
 1966:                       $$res_title{$item}.'</a></td><td>'.
 1967:                       $$changed{$item}{'revdate'}.'</td><td>'.
 1968:                       $$changed{$item}{'current'}.'</td><td>'.
 1969:                       $$changed{$item}{'version'}.'</td></tr>');
 1970:         }
 1971:     } elsif ($itemserror) {
 1972:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1973:     } else {
 1974:         $r->print('<tr class="LC_empty_row"><td>'
 1975:                  .&mt('No '.$interval).'</td></tr>');
 1976:     }
 1977:     return;
 1978: }
 1979: 
 1980: sub display_rolechanges {
 1981:     my ($r,$chgcount,$changed,$interval,$crstype,$classlist) = @_;
 1982:     my $now = time();
 1983:     my %lt = &Apache::lonlocal::texthash(
 1984:         'user'  => 'User',
 1985:         'tich'  => 'Time of change',
 1986:         'role'  => 'Role',
 1987:         'sec'   => 'Section',
 1988:         'status'  => 'Status',
 1989:     );
 1990:     if ($chgcount) {
 1991:         $r->print('<tr class="LC_info_row">'.
 1992:                   '<td class="LC_left_item">'.$lt{'tich'}.'</td>'.
 1993:                   '<td class="LC_left_item">'.$lt{'user'}.'</td>'.
 1994:                   '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
 1995:                   '<td class="LC_left_item">'.$lt{'sec'}.'</td>'.
 1996:                   '<td class="LC_left_item">'.$lt{'status'}.'</td></tr>');
 1997:         if (ref($changed) eq 'HASH') {
 1998:             my @changes = sort { $b <=> $a } (keys(%{$changed}));
 1999:             my $changenum = 0;
 2000:             my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
 2001:             foreach my $item (@changes) {
 2002:                 if (ref($changed->{$item}) eq 'ARRAY') {
 2003:                     foreach my $chg (@{$changed->{$item}}) {
 2004:                         if (ref($chg) eq 'HASH') {
 2005:                             my $section;
 2006:                             my $role = 
 2007:                                 &Apache::lonnet::plaintext($chg->{'role'},$crstype);
 2008:                             my $status = &mt($chg->{'status'});
 2009:                             if ($chg->{'section'} eq '') {
 2010:                                 $section = &mt('none');
 2011:                             } else {
 2012:                                 $section = $chg->{'section'};
 2013:                             }
 2014:                             my $uname = $chg->{'uname'};
 2015:                             my $udom = $chg->{'udom'};
 2016:                             $changenum ++;
 2017:                             my $css_class = $changenum%2?' class="LC_odd_row"':'';
 2018:                             my $fullname;
 2019:                             if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
 2020:                                 $fullname = $classlist->{$uname.':'.$udom}->[$fullnameidx];
 2021:                             } else {
 2022:                                 $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
 2023:                             }
 2024:                             my $link = 
 2025:                                 &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
 2026:                             $r->print('<tr'.$css_class.'>'.
 2027:                                       '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
 2028:                                       '<td>'.$link.'</td>'.
 2029:                                       '<td>'.$role.'</td>'.
 2030:                                       '<td>'.$section.'</td>'.
 2031:                                       '<td>'.$status.'</td></tr>');
 2032:                         }
 2033:                     }
 2034:                 }
 2035:             }
 2036:         }
 2037:     } else {
 2038:         $r->print('<tr class="LC_empty_row"><td>'
 2039:                  .&mt('There are no '.$interval).'</td></tr>');
 2040:     }
 2041:     return;
 2042: }
 2043: 
 2044: sub display_activity {
 2045:     my ($r,$context,$count,$details,$interval,$crstype,$classlist) = @_;
 2046:     return unless (ref($classlist) eq 'HASH');
 2047:     my %lt = &Apache::lonlocal::texthash(
 2048:         'user'   => 'User',
 2049:         'role'   => 'Role',
 2050:         'sec'    => 'Section',
 2051:         'number' => 'Total number of logins',
 2052:     );
 2053:     my $prefix = 'login';
 2054:     if ($context eq 'sessions') {
 2055:         $lt{'number'} = &mt('Total number of active user sessions');
 2056:         $lt{'active'} = &mt('Last active');
 2057:         $prefix = 'session';
 2058:     }
 2059:     if ($count) {
 2060: 
 2061:         my $hdr = '<tr class="LC_info_row" style="display:none" id="'.$prefix.'titledet">'.
 2062:                   '<td class="LC_left_item">'.$lt{'user'}.'</td>'.
 2063:                   '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
 2064:                   '<td class="LC_left_item">'.$lt{'sec'}.'</td>';
 2065:         if ($context eq 'sessions') {
 2066:             $hdr .= '<td class="LC_left_item">'.$lt{'active'}.'</td>';
 2067:         }
 2068:         $hdr .= '</tr>'."\n".
 2069:                 '<tr class="LC_info_row" id="'.$prefix.'titlesum">'.
 2070:                 '<td class="LC_left_item">'.$lt{'number'}.'</td>'.
 2071:                 '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
 2072:                 '<td class="LC_left_item">'.$lt{'sec'};
 2073:         my (%bylastname,%counts);
 2074:         if (ref($details) eq 'HASH') {
 2075:             my @items = sort { $b <=> $a } (keys(%{$details}));
 2076:             my $num = 0;
 2077:             my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
 2078:             foreach my $item (@items) {
 2079:                 if (ref($details->{$item}) eq 'ARRAY') {
 2080:                     foreach my $user (@{$details->{$item}}) {
 2081:                         if (ref($user) eq 'HASH') {
 2082:                             my $section;
 2083:                             my $role =
 2084:                                 &Apache::lonnet::plaintext($user->{'role'},$crstype);
 2085:                             if ($user->{'section'} eq '') {
 2086:                                 $section = &mt('none');
 2087:                             } else {
 2088:                                 $section = $user->{'section'};
 2089:                             }
 2090:                             $counts{$user->{'role'}}{$section} ++;
 2091:                             my $uname = $user->{'uname'};
 2092:                             my $udom = $user->{'udom'};
 2093:                             my $fullname;
 2094:                             if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
 2095:                                 $fullname = $classlist->{$uname.':'.$udom}->[$fullnameidx];
 2096:                             } else {
 2097:                                 $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
 2098:                             }
 2099:                             my $link =
 2100:                                 &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
 2101:                             my $entry = '<td>'.$link.'</td>'.
 2102:                                         '<td>'.$role.'</td>'.
 2103:                                         '<td>'.$section.'</td>';
 2104:                             if ($context eq 'sessions') {
 2105:                                 $entry .= '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>';
 2106:                             }
 2107:                             push(@{$bylastname{$fullname}},$entry);
 2108:                         }
 2109:                     }
 2110:                 }
 2111:             }
 2112:             my $table;
 2113:             foreach my $person (sort(keys(%bylastname))) {
 2114:                 if (ref($bylastname{$person}) eq 'ARRAY') {
 2115:                     foreach my $item (@{$bylastname{$person}}) {
 2116:                         $num ++;
 2117:                         my $css_class = $num%2?' class="LC_odd_row"':'';
 2118:                         $table .= '<tr'.$css_class.' style="display:none;"  id="'.$prefix.'det_'.$num.'">'.$item.'</tr>';
 2119:                     }
 2120:                 }
 2121:             }
 2122:             my $numrow = 0;
 2123:             foreach my $role (sort(keys(%counts))) {
 2124:                 my $showrole = &Apache::lonnet::plaintext($role,$crstype);
 2125:                 if (ref($counts{$role}) eq 'HASH') {
 2126:                     foreach my $sec (sort { $b <=> $a } (keys(%{$counts{$role}}))) {
 2127:                         $numrow ++;
 2128:                         my $css_class = $numrow%2?' class="LC_odd_row"':'';
 2129:                         $table .= '<tr '.$css_class.' id="'.$prefix.'sum_'.$numrow.'">'.
 2130:                                   '<td>'.$counts{$role}{$sec}.'</td>'.
 2131:                                   '<td>'.$showrole.'</td>'.
 2132:                                   '<td>'.$sec.'</td></tr>';
 2133:                    }
 2134:                 }
 2135:             }
 2136:             $r->print($hdr.'<input type="hidden" name="'.$prefix.'count" value="'.$num.
 2137:                       '" /><input type="hidden" name="'.$prefix.'row" value="'.$numrow.
 2138:                       '" /></td></tr>'.$table);
 2139:         }
 2140:     } else {
 2141:         $r->print('<tr class="LC_empty_row"><td>'.
 2142:                   &mt('There are no '.$interval).
 2143:                   '<input type="hidden" name="'.$prefix.'count" value="'.$count.
 2144:                   '." /></td></tr>');
 2145:     }
 2146:     return;
 2147: }
 2148: 
 2149: sub display_coursediscussion {
 2150:     my ($r,$newdiscussions,$unread,$countunread,$res_title,$itemserror) = @_;
 2151:     my $lctype = lc(&Apache::loncommon::course_type());
 2152:     my %lt = &Apache::lonlocal::texthash(
 2153:                 'loca' => 'Location',
 2154:                 'type' => 'Type',
 2155:                 'numn' => 'Number of new posts',
 2156:                 'noun' => 'No unread posts in '.$lctype.' discussions',
 2157:                 'tmlp' => 'Time of last post', 
 2158:     );
 2159:     if (@{$newdiscussions} > 0) {
 2160:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 2161:                   $lt{'loca'}.'</td><td>'.
 2162:                   $lt{'type'}.'</td>');
 2163:         if ($countunread eq 'on') {
 2164:             $r->print('<td>'.$lt{'tmlp'}.'</td>'.
 2165:                       '<td class="LC_right_item">'.$lt{'numn'}.'</td>');
 2166:         } else {
 2167:             $r->print('<td class="LC_right_item">'.$lt{'tmlp'}.'</td>');
 2168:         }
 2169:         $r->print("</tr>\n");
 2170:         @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) }
 2171:                                                             @{$newdiscussions};
 2172:         my $rowNum = 0;
 2173:         foreach my $ressymb (@{$newdiscussions}) {
 2174:             $rowNum ++;
 2175:             my $forum_title = $$unread{$ressymb}{'title'};
 2176:             my $type = 'Resource';
 2177:             my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
 2178:             my $disclink = $feedurl.'?symb='. &escape($$unread{$ressymb}{symb});
 2179:             if ($feedurl =~ /bulletinboard/) {
 2180:                 $type = 'Discussion Board';
 2181:             }
 2182:             if ($$unread{$ressymb}{'enclink'}) {
 2183:                 $disclink = $$unread{$ressymb}{'enclink'}.'?symb='.$$unread{$ressymb}{'encsymb'};
 2184:             }
 2185:             my $css_class = $rowNum%2?' class="LC_odd_row"':'';
 2186:             my $lastpost = &Apache::lonnavmaps::timeToHumanString(
 2187:                                                $$unread{$ressymb}{'lastpost'});
 2188:             $r->print('<tr'.$css_class.'><td><a href="'.$disclink.'">'.$forum_title.'</a>&nbsp;</td><td>'.&mt($type).'&nbsp;</td>');
 2189:             if ($countunread eq 'on') {
 2190:                 my $unreadnum = $$unread{$ressymb}{'unreadcount'};
 2191:                 $r->print('<td>'.$lastpost.'</td><td class="LC_right_item">'.
 2192:                           $unreadnum.'&nbsp;</td>');
 2193:             } else {
 2194:                 $r->print('<td class="LC_right_item">'.$lastpost.'</td>');
 2195:             }
 2196:             $r->print("</tr>\n");
 2197:         }
 2198:     } elsif ($itemserror) {
 2199:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 2200:     } else {
 2201:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'noun'}.'</td></tr>');
 2202:     }
 2203: }
 2204: 
 2205: sub display_coursenormalmail {
 2206:     my ($r,$msgcount,$newmsgs) = @_;
 2207:     my $lctype = lc(&Apache::loncommon::course_type());
 2208:     if ($msgcount > 0) {
 2209:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 2210:                   &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
 2211:                   &mt('Sender').'</td><td class="LC_right_item">'.
 2212:                   &mt('Date/Time').'</td></tr>');
 2213:         my $mailcount = 0;
 2214:         foreach my $msg (@{$newmsgs}) {
 2215:             $mailcount ++;
 2216:             my $css_class = $mailcount%2?' class="LC_odd_row"':'';
 2217:             $r->print('<tr'.$css_class.'><td>'.$mailcount
 2218:                       .'.&nbsp;</td><td><a href="/adm/email?display='
 2219:                       .$msg->{'msgid'}.'">'
 2220:                       .$msg->{'shortsub'}.'</a>&nbsp;&nbsp;</td><td>&nbsp;'
 2221:                       .$msg->{'from'}.':'.$msg->{'fromdom'}.'&nbsp;</td><td>'
 2222:                       .$msg->{'sendtime'}.'</td></tr>');
 2223:         }
 2224:     } else {
 2225:         $r->print('<tr class="LC_empty_row"><td>'.
 2226:                   &mt('No new '.$lctype.' messages').'</td></tr>');
 2227:     }
 2228: }
 2229: 
 2230: sub display_coursecritmail {
 2231:     my ($r,$critmsgcount,$critmsgs) = @_;
 2232:     my $lctype = lc(&Apache::loncommon::course_type());
 2233:     if ($critmsgcount > 0) {
 2234:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 2235:                   &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
 2236:                   &mt('Sender').'</td><td class="LC_right_item">'.
 2237:                   &mt('Date/Time').'</td></tr>');
 2238:         my $mailcount = 0;
 2239:         foreach my $msg (@{$critmsgs}) {
 2240:             $mailcount ++;
 2241:             my $css_class = $mailcount%2?' class="LC_odd_row"':'';
 2242:             $r->print('<tr'.$css_class.'><td>'.$mailcount.
 2243:                       '. &nbsp;</td><td><a href="/adm/email?folder=critical">'.
 2244:                       $msg->{'shortsub'}.'</a>&nbsp; &nbsp;</td><td>&nbsp;'.
 2245:                       $msg->{'from'}.':'.$msg->{'fromdom'}.'&nbsp;</td><td>'.
 2246:                       $msg->{'sendtime'}.'</td></tr>');
 2247:         }
 2248:     } else {
 2249:         $r->print('<tr class="LC_empty_row"><td>'.
 2250:                   &mt('No unread critical messages in '.$lctype).
 2251:                   '</td></tr>');
 2252:     }
 2253: }
 2254: 
 2255: sub cmp_title {
 2256:     my ($a,$b,$res_title) = @_;
 2257:     my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
 2258:     $atitle=~s/^\s*//;
 2259:     $btitle=~s/^\s*//;
 2260:     return $atitle cmp $btitle;
 2261: }
 2262: 
 2263: sub get_display_settings {
 2264:     my ($uname,$udom,$cid) = @_;
 2265:     my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid); 
 2266:     my ($tmp) = keys(%settings);
 2267:     if ($tmp=~ /^(con_lost|error|no_such_host)/i) {
 2268:         %settings = ();
 2269:         unless ($tmp =~ /^error: 2 /) {
 2270: 	    my $lctype = lc(&Apache::loncommon::course_type());
 2271:             &Apache::lonnet::logthis('Error retrieving whatsnew settings: '.
 2272:             $tmp.' for '.$uname.':'.$udom.' for '.$lctype.': '.$cid);
 2273:         }
 2274:     }
 2275:     return %settings;
 2276: }
 2277: 
 2278: sub store_display_settings {
 2279:     my ($uname,$udom,$cid,$checkallowed) = @_;
 2280:     my %whatsnew_settings;
 2281:     my $result;
 2282:     foreach my $key (keys(%{$checkallowed})) {
 2283: 	if ($key =~ /_section$/) { next; }
 2284:         if (exists($env{'form.display_'.$key})) {
 2285:             unless ($env{'form.display_'.$key} eq '') {
 2286:                 $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key};
 2287:             }
 2288:         }
 2289:     }
 2290:     if (keys(%whatsnew_settings)) {
 2291:         $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings,
 2292:                                                                  $udom,$uname);
 2293:     } else {
 2294:         $result = 'ok';
 2295:     }
 2296:     return $result;
 2297: }
 2298: 
 2299: sub store_interval_setting {
 2300:     my ($uname,$udom,$cid,$interval_titles) = @_;
 2301:     my %interval_settings = ();
 2302:     my $result;
 2303:     my $context = $env{'form.intervaltype'};
 2304:     if ($env{'form.interval'} ne '') {
 2305:         if ($context eq 'oldroles') {
 2306:             $interval_settings{$cid.':oldroleinterval'} = $env{'form.interval'};
 2307:         } elsif ($context eq 'newroles') {
 2308:             $interval_settings{$cid.':newroleinterval'} = $env{'form.interval'};
 2309:         } elsif ($context eq 'crslogin') {
 2310:             $interval_settings{$cid.':crslogininterval'} = $env{'form.interval'};
 2311:         } elsif ($context eq 'sessions') {
 2312:             $interval_settings{$cid.':sessionactivity'} = $env{'form.interval'};
 2313:         } else {
 2314:             $interval_settings{$cid.':interval'} = $env{'form.interval'};
 2315:         }
 2316:         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 2317:                                              \%interval_settings,$udom,$uname);
 2318:         if ($outcome eq 'ok') {
 2319:             if (ref($interval_titles->{$context}) eq 'HASH') {
 2320:                 $result = &Apache::lonhtmlcommon::confirm_success(&mt('New filter setting: [_1].','<b>'. 
 2321:                               $interval_titles->{$context}->{$env{'form.interval'}}.'</b>').'<br />');
 2322:             }
 2323:         } else {
 2324: 	    my $lctype = lc(&Apache::loncommon::course_type());
 2325:             &Apache::lonnet::logthis('Error saving whatsnew '.$context.' interval setting'.
 2326:                 ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
 2327:             $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set interval to [_1] due to [_2].',
 2328:                          '<b>'.$interval_titles->{$context}->{$env{'form.interval'}}.'</b>',
 2329:                          '<tt>'.$outcome.'</tt>'),1);
 2330:         }
 2331:     }
 2332:     return &Apache::loncommon::confirmwrapper($result);
 2333: }
 2334: 
 2335: sub store_discussion_setting {
 2336:     my ($uname,$udom,$cid) = @_;
 2337:     my %discussion_settings;
 2338:     my $result;
 2339:     if (defined($env{'form.countunread'})) {
 2340:         $discussion_settings{$cid.':countunread'} = $env{'form.countunread'};
 2341:         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 2342:                                              \%discussion_settings,$udom,$uname);
 2343:         if ($outcome eq 'ok') {
 2344:             $result = &Apache::lonhtmlcommon::confirm_success(&mt('Count unread posts in discussions display set to [_1]',
 2345:                   '<b>'.&mt($env{'form.countunread'}).'</b>').'<br />');
 2346:                                                                                   
 2347:         } else {
 2348: 	    my $lctype = lc(&Apache::loncommon::course_type());
 2349:             &Apache::lonnet::logthis('Error saving whatsnew countunread setting'.
 2350:                 ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
 2351:             $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set "number unread posts display" to [_1]'.
 2352:                           ' due to [_2].',
 2353:                          '<b>'.&mt($env{'form.countunread'}).'</b>',
 2354:                          '<tt>'.$outcome.'</tt>'),1);
 2355:         }
 2356:     }
 2357:     return &Apache::loncommon::confirmwrapper($result);
 2358: }
 2359: 
 2360: sub store_courseinit_setting {
 2361:     my ($uname,$udom,$cid,$initpage) = @_;
 2362:     my %courseinit_settings;
 2363:     my $page_control;
 2364:     my $result;
 2365:     if (defined($env{'form.courseinit_control'})) {
 2366:         if ($env{'form.courseinit_control'} eq 'userpref') {
 2367:             $courseinit_settings{$cid.':courseinit'} = '';
 2368:             $page_control = 'global preferences';
 2369:         } else {
 2370:             if (defined($env{'form.courseinit_page'})) {
 2371:                 $courseinit_settings{$cid.':courseinit'} = 
 2372:                                                   $env{'form.courseinit_page'};
 2373:                 $page_control = 'course specific setting';
 2374:             }
 2375:         }
 2376:         if ($page_control) {
 2377: 	    my $lctype = lc(&Apache::loncommon::course_type());
 2378:             my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 2379:                                            \%courseinit_settings,$udom,$uname);
 2380:             if ($outcome eq 'ok') {
 2381:                 if ($page_control eq 'global preferences') {
 2382:                     $result = &Apache::lonhtmlcommon::confirm_success(&mt("Page displayed after role selection in $lctype now set by [_1]user's global preferences[_2].",'<b>','</b>'));
 2383:                 } else {
 2384:                     $result = &Apache::lonhtmlcommon::confirm_success(&mt('Page displayed after role selection in this '.$lctype.' set to [_1].'
 2385:                                  ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>'));
 2386:                 }
 2387:             } else {
 2388:                 &Apache::lonnet::logthis('Error saving whatsnew courseinit '.
 2389:                                          'setting: '.$outcome.' for '.$uname.
 2390:                                          ':'.$udom.' in '.$lctype.' '.$cid);
 2391:                 if ($page_control eq 'global preferences') {
 2392:                     $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set control of page display to [_1]'.
 2393:                           ' due to [_2].',
 2394:                          '<b>'.$page_control.'</b>',
 2395:                          '<tt>'.$outcome.'</tt>'),1);
 2396:                 } else {
 2397:                     $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set page display, after role selection, for this '.$lctype.' to [_1] due to [_2].'
 2398:                                  ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>'
 2399:                                  ,'<tt>'.$outcome.'</tt>'),1);
 2400:                 }
 2401:             }
 2402:         }
 2403:     }
 2404:     return &Apache::loncommon::confirmwrapper($result);
 2405: }
 2406: 
 2407: sub start_box {
 2408:     my ($r,$show,$heading,$caller,$refpage) = @_;
 2409:     my %lt = &Apache::lonlocal::texthash( 
 2410:                        chth => 'Change thresholds?',
 2411:                        chin => 'Change interval?',
 2412:                        chop => 'Change options?',
 2413:     );
 2414:     my $showhide;
 2415:     if ($$show{$caller}) {
 2416:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 2417:                                'display_'.$caller.",'hide'".');">'.
 2418:                                &mt('Hide').'</a></b>';
 2419:    
 2420:     } else {
 2421:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 2422:                                'display_'.$caller.",'show'".');">'.
 2423:                                &mt('Show').'</a></b>';
 2424:     }
 2425:     
 2426:     $r->print('
 2427:          <table class="LC_nested_outer">
 2428:           <tr>
 2429:            <th class="LC_left_item">'.$$heading{$caller}.'</th>
 2430:            <th class="LC_right_item">'.$showhide.'</th>
 2431:           </tr>');
 2432:      if (($caller eq 'abovethreshold') && ($$show{$caller})) {
 2433:          if ($$show{$caller}) {
 2434:              $r->print('
 2435:               <tr>
 2436:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgthreshold&amp;refpage='.$refpage.'">'.$lt{'chth'}.'</a></td>
 2437:               </tr>');
 2438:          }
 2439:      } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
 2440:          if ($$show{$caller}) {
 2441:              $r->print('
 2442:               <tr>
 2443:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chginterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2444:               </tr>');
 2445:          }
 2446:      } elsif ($caller eq 'coursediscussion') {
 2447:          if ($$show{$caller}) {
 2448:              $r->print('
 2449:               <tr>
 2450:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&amp;refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
 2451:               </tr>');
 2452:          }
 2453:      } elsif (($caller eq 'newroles') && ($$show{$caller})) {
 2454:          if ($$show{$caller}) {
 2455:              $r->print('
 2456:               <tr>
 2457:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgnewroleinterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2458:               </tr>');
 2459:          }
 2460:      } elsif (($caller eq 'oldroles') && ($$show{$caller})) {
 2461:          if ($$show{$caller}) {
 2462:              $r->print('
 2463:               <tr>
 2464:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2465:               </tr>');
 2466:          }
 2467:     } elsif (($caller eq 'crslogin') && ($$show{$caller})) {
 2468:         if ($$show{$caller}) {
 2469:             $r->print('
 2470:               <tr>
 2471:                 <td class="LC_subheader" align="left"><span class="LC_nobreak"><label><input type="radio" name="logindetails" value="0" checked="checked" onclick="javascript:toggledetails('."'login'".');" />&nbsp;'.&mt('Summary').'</label><label><input type="radio" name="logindetails" value="1" onclick="javascript:toggledetails('."'login'".');" />&nbsp;'.&mt('Details').'</label></span></td><td class="LC_subheader"><a href="/adm/whatsnew?command=chgcrslogininterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2472:               </tr>');
 2473:         }
 2474:     } elsif (($caller eq 'sessions') && ($$show{$caller})) {
 2475:         if ($$show{$caller}) {
 2476:             $r->print('
 2477:               <tr>
 2478:                 <td class="LC_subheader" align="left"><span class="LC_nobreak"><label><input type="radio" name="sessiondetails" value="0" checked="checked" onclick="javascript:toggledetails('."'session'".');" />&nbsp;'.&mt('Summary').'</label><label><input type="radio" name="sessiondetails" value="1" onclick="javascript:toggledetails('."'session'".');" />&nbsp;'.&mt('Details').'</label></span></td><td class="LC_subheader"><a href="/adm/whatsnew?command=chgsessionlimit&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2479:               </tr>');
 2480:         }
 2481:     }
 2482:     $r->print('
 2483:               <tr>
 2484:                <td colspan="2">
 2485:                 <table class="LC_nested">
 2486: ');
 2487:     return;
 2488: }
 2489: 
 2490: sub end_box {
 2491:     my ($r) = shift;
 2492:     $r->print('
 2493:    </table>
 2494:   </td>
 2495:  </tr>
 2496: </table><br />');
 2497:     return;
 2498: }
 2499: 
 2500: 1;

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