File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.105.2.4: download - view: text, annotated - select for diffs
Thu Dec 13 22:09:33 2012 UTC (11 years, 5 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.108, 1.109, 1.110 (part).

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

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