File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.105.2.3: download - view: text, annotated - select for diffs
Thu Oct 4 06:07:11 2012 UTC (11 years, 7 months ago) by raeburn
Branches: version_2_11_X
- For 2.11.
  - Backport 1.107.

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

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