File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.123: download - view: text, annotated - select for diffs
Fri May 19 18:23:19 2017 UTC (7 years ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Missing word.

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

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