File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.132: download - view: text, annotated - select for diffs
Sat Mar 22 21:18:30 2025 UTC (3 months, 1 week ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- WCAG 2 compliance.

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

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