File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.111: download - view: text, annotated - select for diffs
Tue Mar 5 22:51:48 2013 UTC (11 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6638.
  - As nohist_rolelog.db keys include timestamp and process number, numerical
    sort should not be used (process number is variable number of digits).

    1: #
    2: # $Id: lonwhatsnew.pm,v 1.111 2013/03/05 22:51:48 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,$starttime,$activatedstart,$expiredstart,$crsloginstart);
  536:     $now = time;
  537: 
  538:     if ($timediff{'versions'} == -1) {
  539:         $starttime = 0;
  540:     } else {
  541:         $starttime = $now - $timediff{'versions'};
  542:     }
  543: 
  544:     if ($timediff{'newroles'} == -1) {
  545:         $activatedstart = 0;
  546:     } else {
  547:         $activatedstart = $now - $timediff{'newroles'};
  548:     }
  549: 
  550:     if ($timediff{'oldroles'} == -1) {
  551:         $expiredstart = 0;
  552:     } else {
  553:         $expiredstart = $now - $timediff{'oldroles'};
  554:     }
  555: 
  556:     if ($timediff{'crslogin'} == -1) {
  557:         $crsloginstart = 0;
  558:     } else {
  559:         $crsloginstart = $now - $timediff{'crslogin'};
  560:     }
  561: 
  562:     my $countunread = $display_settings{$cid.':countunread'};
  563:     unless (defined($countunread)) {
  564:         $countunread = 'on';
  565:     }
  566:     if ($$checkallowed{'abovethreshold'}) {
  567:         &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
  568:     }
  569: 
  570:     $headings{'abovethreshold'} = 
  571: 	&mt('(Problems with av. attempts &ge; [_1] or deg. difficulty &ge; [_2]) [_3] and total number of '.$stulabel{$crstype}.' with submissions &ge; [_4]',
  572: 	    $threshold{'av_attempts'},$threshold{'degdiff'},
  573: 	    '<br />',$threshold{'numstudents'});
  574: 
  575:     my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles','crslogin');
  576: 
  577:     foreach my $key (keys(%{$checkallowed})) {
  578: 	if ($key =~ /_section$/) { next; }
  579:         $show{$key} = 0;
  580:         if ($$checkallowed{$key}) {
  581:             unless ($display_settings{$cid.':'.$key} eq 'hide') {
  582:                 $show{$key} = 1;
  583:             }
  584:         }
  585:     }
  586: 
  587:     foreach my $item (@actionorder) {
  588:         unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail' ||
  589:                 $item eq 'newroles' || $item eq 'oldroles') {
  590:             if ($show{$item}) {
  591:                 $needitems = 1;
  592:                 last;
  593:             }
  594:         }
  595:     }
  596: 
  597:     my $itemserror;
  598:     if ($needitems) {
  599:         $itemserror = &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread);
  600:     }
  601:     if ($show{'coursenormalmail'}) {
  602:         $msgcount = &getnormalmail(\@newmsgs);
  603:     }
  604:     if ($show{'coursecritmail'}) {
  605:         $critmsgcount = &getcritmail(\@critmsgs);
  606:     }
  607:     if ($show{'oldroles'}) {
  608:         $expirecount = &getexpired(\%expired,$expiredstart,'previous');
  609:     }
  610:     if ($show{'newroles'}) {
  611:         $activecount = &getactivated(\%activated,$activatedstart,'active');
  612:     }
  613:     if ($show{'crslogin'}) {
  614:         $logincount = &getloggedin($cdom,$crs,\%loggedin,$crsloginstart);
  615:     }
  616:     $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
  617:      &nbsp;&nbsp;<a href="javascript:changeAll('show');">$lt{'shal'}</a>
  618:      <form method="post" name="visible" action="/adm/whatsnew">\n|);
  619:     foreach my $item (keys(%{$checkallowed})) {
  620: 	if ($item =~ /_section$/) { next; }
  621:         if ($$checkallowed{$item}) {
  622:             $r->print('<input type="hidden" name="display_'.$item.'" />'."\n");
  623:         }
  624:     }
  625: 
  626:     $r->print('<input type="hidden" name="refpage" value="'.$refpage.'" /><table class="LC_double_column"><tr><td class="LC_left_col">');
  627: 
  628:     my $displayed = 0;
  629:     my $totalboxes = 0;
  630:     foreach my $key (keys(%{$checkallowed})) {
  631: 	if ($key =~ /_section$/) { next; }
  632: 	if ($key eq 'whatsnew' ) { next; } # whatsnew check creates no box
  633:         if ($$checkallowed{$key}) {
  634:             $totalboxes ++;
  635:         }
  636:     }
  637:     my $halfway = 4;
  638: #    my $halfway = int($totalboxes/2) + $totalboxes%2;
  639:     foreach my $actionitem (@actionorder) {
  640:         if ($$checkallowed{$actionitem}) {
  641:             if ($displayed == $halfway) {
  642:                 $r->print('</td><td>&nbsp;</td><td class="LC_right_col" >');
  643:             }
  644:             &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);
  645:             $displayed ++; 
  646:         }
  647:     }
  648:     $r->print('
  649:       </td>
  650:     </tr>
  651:    </table>
  652:    </form>
  653: ');
  654: }
  655: 
  656: #-------------------------------
  657: # display_threshold_config
  658: #
  659: # Display the threshold setting screen 
  660: #
  661: #-------------------------------
  662:                                                                                 
  663: sub display_threshold_config {
  664:     my ($r,$refpage,$threshold_titles,$cdom,$crs) = @_;
  665:     my $uname = $env{'user.name'};
  666:     my $udom = $env{'user.dom'};
  667:     my $cid = $env{'request.course.id'};
  668:     my %threshold = ();
  669:     my $rowColor1 = "#ffffff";
  670:     my $rowColor2 = "#eeeeee";
  671:     my $rowColor;
  672: 
  673:     my @thresholditems = ("av_attempts","degdiff","numstudents");
  674:     my %threshold_titles = &Apache::lonlocal::texthash(
  675:                          av_attempts => 'Average number of attempts',
  676:                          degdiff => 'Degree of difficulty',
  677:                          numstudents => 'Total number of students with submissions',
  678:                          );
  679:     &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
  680: 
  681:     $r->print('<br /><form name="thresholdform" method="post" action="/adm/whatsnew">'.
  682:               &Apache::loncommon::start_data_table().
  683:               &Apache::loncommon::start_data_table_header_row().
  684:              '<th>'.&mt('Threshold Name').'</th>'."\n".
  685:              '<th>'.&mt('Current value').'</th>'."\n".
  686:              '<th>'.&mt('Change?').'</th>'."\n".
  687:               &Apache::loncommon::end_data_table_header_row());
  688:     foreach my $type (@thresholditems) {
  689:         my $parameter = $env{'request.course.id'}.':threshold_'.$type;
  690: # onchange is javascript to automatically check the 'Set' button.
  691:         my $onchange = 'onFocus="javascript:window.document.forms'.
  692:               "['thresholdform'].elements['".$parameter."_setparmval']".
  693:               '.checked=true;"';
  694:         $r->print(&Apache::loncommon::start_data_table_row()."\n".
  695:                  '<td>'.$threshold_titles{$type}.'</td>'."\n".
  696:                  '<td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
  697:                                             $threshold{$type},
  698:                                             10,$onchange).'</td>'."\n".
  699:                  '<td>'.
  700:                  &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
  701:                  '</td>'."\n".
  702:                  &Apache::loncommon::end_data_table_row());
  703:     }
  704:     $r->print(&Apache::loncommon::end_data_table()."\n".
  705:           '<br /><input type="submit" name="threshold" value="'.&mt('Save').'" />
  706:                  <input type="hidden" name="command" value="update" />
  707:                  <input type="hidden" name="refpage" value="'.$refpage.'" />
  708:                </form>');
  709: }
  710: 
  711: #-------------------------------
  712: # display_interval_config
  713: #
  714: # Display the interval setting screen
  715: #
  716: #-------------------------------
  717:                                                                                    
  718: sub display_interval_config {
  719:     my ($r,$refpage,$interval_titles,$context) = @_;
  720:     my $setting = 'interval';
  721:     if ($context eq 'oldroles') {
  722:         $setting = 'oldroleinterval';
  723:     } elsif ($context eq 'newroles') {
  724:         $setting = 'newroleinterval'; 
  725:     }
  726:     my $lctype = lc(&Apache::loncommon::course_type());
  727:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  728:                                 $env{'request.course.id'},$setting);
  729:     if ($context eq 'oldroles') {
  730:         $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' expired.').'<br />');
  731:     } elsif ($context eq 'newroles') {
  732:         $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' became available.').'<br />');
  733:     } elsif ($context eq 'crslogin') {
  734:         $r->print('<br />'.&mt('Choose the time window to use to display the last login by a user in the '.$lctype).'<br />');
  735:     } else {
  736:         $r->print('<br />'.&mt('Choose the time window to use to display resources in the '.$lctype.' with version changes.').'<br />');
  737:     }
  738:     unless ($current eq '') {
  739:         if (ref($interval_titles->{$context}) eq 'HASH') {
  740:             $r->print(' '.&mt('Current value is "[_1]".','<b>'.
  741:                       $interval_titles->{$context}->{$current}.'</b>').'<br />');
  742:         }
  743:     }
  744:     $r->print('<br />
  745: <form method="post" name="intervalswitch" action="/adm/whatsnew">
  746: <input type="hidden" name="command" value="newinterval" />
  747: <input type="hidden" name="intervaltype" value="'.$context.'" />
  748: <input type="hidden" name="refpage" value="'.$refpage.'" />'.
  749: &mt('Display:').' 
  750: <select name="interval">
  751: <option value="" selected="selected">'.&mt('Select').'</option>
  752: ');
  753:     if (ref($interval_titles) eq 'HASH') {
  754:         if (ref($interval_titles->{$context}) eq 'HASH') {
  755:             foreach my $key (reverse sort ({$a cmp $b} (keys(%{$interval_titles->{$context}})))) {
  756:                 $r->print('<option value="'.$key.'">'.&mt($interval_titles->{$context}->{$key}).
  757:                           '</option>'."\n");
  758:             }
  759:         }
  760:     }
  761:     $r->print('</select>&nbsp;&nbsp;
  762:                <input type="submit" name="display" value="'.
  763:                &mt('Save').'" /></form>');
  764:     return;
  765: }
  766: 
  767: #----------------------------------------------
  768: # display_discussion_config
  769: #
  770: # Display the discussion display setting screen
  771: #
  772: #----------------------------------------------
  773:                                                                                   
  774: sub display_discussion_config {
  775:     my ($r,$refpage) = @_;
  776:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  777:                                 $env{'request.course.id'},'countunread');
  778:     if ($current eq '') {
  779:         $current = 'on';
  780:     }
  781:     my %opposite = ( 
  782:                       'on' => 'off',
  783:                       'off' => 'on',
  784:                     );
  785:     $r->print('<script type="text/javascript">
  786: function toggle_countunread(choice) {
  787:     if (choice == "unchanged") {
  788:         document.discussionswitch.command.value = "";
  789:     }
  790:     document.discussionswitch.submit();
  791: }
  792: </script>');
  793:     $r->print('<br />'
  794:              .&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.')
  795:              .'<br />'
  796:              .&mt("This can increase the time taken to gather data for the [_1]What's New Page[_2] by a few seconds.",'<i>','</i>')
  797:              .'&nbsp;&nbsp;'
  798:              .&mt('Currently set to [_1].','<b>'.$current.'</b>.')
  799:     );
  800:     $r->print('<br /><br />
  801: <form method="post" name="discussionswitch" action="/adm/whatsnew">
  802: <input type="hidden" name="command" value="newdiscconf" />
  803: <input type="hidden" name="refpage" value="'.$refpage.'" />
  804: <input type="hidden" name="countunread" value="'.$opposite{$current}.'" />
  805: ');
  806:     $r->print('<br/>
  807:                <input type="button" name="display" value="'.
  808:                &mt('Change to [_1]',&mt($opposite{$current})).'" 
  809:                onclick="javascript:toggle_countunread('."'change'".')" />'.
  810:                ('&nbsp;' x7).
  811:                '<input type="button" name="nochange" value="'.
  812:                &mt("No change").'" 
  813:                onclick="javascript:toggle_countunread('."'unchanged'".')" />
  814:                </form>');
  815:     return;
  816: }
  817: 
  818: #---------------------------------------------------
  819: # courseinit_config
  820: #
  821: # Set page displayed when course loads after 
  822: # selecting a role in the course from the roles page. 
  823: #
  824: #---------------------------------------------------
  825: 
  826: sub courseinit_config {
  827:     my ($r,$refpage,$initpage) = @_;
  828:     my ($control,$current) = &curr_courseinit();
  829:     my @chgstate = ('userpref','coursespecific');
  830:     my @chgentry = ('firstres','whatsnew');
  831:     my $lctype = lc(&Apache::loncommon::course_type());
  832:     my %lt = &Apache::lonlocal::texthash(
  833:                              'chwp' => "Choose which page will be displayed when you enter this $lctype after selecting a role.",
  834:                              'cuva' => 'Current value is determined by',
  835:                              'anis' => 'and is set to display',
  836:                              'padc' => 'Page display controlled by',
  837:                              'chce' => 'Choose '.$lctype.' entry',
  838:                              'moce' => 'Save',
  839:     );
  840:     $r->print(<<"END"); 
  841: <br />$lt{'chwp'}
  842: <br />$lt{'cuva'}: <b>
  843: $$initpage{$control}</b> $lt{'anis'} <b>
  844: $$initpage{$current}</b>.<br /><br />
  845: <form method="post" name="courseinitswitch" action="/adm/whatsnew">
  846: <input type="hidden" name="command" value="newcourseinit" />
  847: <input type="hidden" name="refpage" value="$refpage" />
  848: $lt{'padc'}:&nbsp;&nbsp;
  849: END
  850:     foreach my $choice (@chgstate) {
  851:         my $chkstring;
  852:         if ($choice eq $control) {
  853:             $chkstring = ' checked="checked" ';
  854:         }  
  855:         $r->print('<span class="LC_nobreak"><label><input type="radio" name="courseinit_control" value="'.
  856:                    $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
  857:                    '&nbsp;&nbsp;</label></span>');
  858:     }
  859:     $r->print('<br /><br />'.&mt('If').' '.$$initpage{'coursespecific'}.
  860:               ' - <br />'.$lt{'chce'}.": \n");
  861:     foreach my $choice (@chgentry) {
  862:         my $chkstring;
  863:         if (($choice eq $current) && ($control eq 'coursespecific')) {
  864:             $chkstring = ' checked="checked" ';
  865:         }
  866:         $r->print('<span class="LC_nobreak"><label><input type="radio" name="courseinit_page" value="'.
  867:                   $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
  868:                   '&nbsp;&nbsp;</label></span>');
  869:     }
  870:     $r->print('<br /><br /><input type="submit" name="display" value="'.
  871:                $lt{'moce'}.'" /></form>');
  872:     return;
  873: }
  874: 
  875: sub curr_courseinit {
  876:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  877:                                 $env{'request.course.id'},'courseinit');
  878:     my $control;
  879:     if ($current) {
  880:         $control = 'coursespecific';
  881:     } else {
  882:         $control = 'userpref';
  883:         my %userenv = &Apache::lonnet::get('environment',
  884:                                                       ['course_init_display']);
  885:         if (exists($userenv{'course_init_display'})) {
  886:             $current = $userenv{'course_init_display'};
  887:         }
  888:         unless ($current) {
  889:             $current = 'whatsnew';
  890:         }
  891:     }
  892:     return ($control,$current);
  893: }
  894: 
  895: sub display_launcher {
  896:     my ($r,$action,$refpage,$checkallowed,$show,$headings,$res_title,
  897:         $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered,
  898:         $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs,
  899:         $interval,$countunread,$expired,$expirecount,$activated,$activecount,
  900:         $crstype,$itemserror,$loggedin,$logincount) = @_;
  901: 
  902:     if ($$checkallowed{$action}) {
  903:         &start_box($r,$show,$headings,$action,$refpage);
  904:         if ($$show{$action}) {
  905:             if ($action eq 'handgrading') {    # UNGRADED ITEMS
  906:                 &display_handgrade($r,$tograde,$ungraded,$itemserror);
  907:             } elsif ($action eq 'haserrors') { # BOMBS
  908:                 &display_haserrors($r,$bombs,$bombed,$res_title,$itemserror);
  909:             } elsif ($action eq 'versionchanges') { # VERSION CHANGES
  910:                 &display_versionchanges($r,$changed,$res_title,$interval->{'versions'},$itemserror);
  911:             } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
  912:                 &display_abovethreshold($r,$refpage,$warnings,$triggered,
  913: 					$res_title,$itemserror);
  914:             } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
  915:                 &display_coursediscussion($r,$newdiscussions,$unread,
  916:                                 $countunread,$res_title,$itemserror);
  917:             } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES
  918:                 &display_coursenormalmail($r,$msgcount,$newmsgs);
  919:             } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
  920:                 &display_coursecritmail($r,$critmsgcount,$critmsgs);
  921:             } elsif ($action eq 'newroles') { # ACTIVATED ROLES
  922:                 &display_rolechanges($r,$activecount,$activated,$interval->{'newroles'},
  923:                                      $crstype);
  924:             } elsif ($action eq 'oldroles') { # EXPIRED ROLES
  925:                 &display_rolechanges($r,$expirecount,$expired,$interval->{'oldroles'},
  926:                                      $crstype);
  927:             } elsif ($action eq 'crslogin') { #LAST LOGIN
  928:                 &display_crslogins($r,$logincount,$loggedin,$interval->{'crslogin'},
  929:                                    $crstype);
  930:             }
  931:         }
  932:         &end_box($r);
  933:     }
  934:     return;
  935: }
  936: 
  937: sub getitems {
  938:     my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions,
  939:         $tograde,$bombs,$warnings,$threshold,$cdom,$crs,$res_title,$show,
  940:         $starttime,$countunread) = @_;
  941:     my $navmap = Apache::lonnavmaps::navmap->new();
  942:     if (!defined($navmap)) {
  943:         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>';
  944:         return $itemserror;
  945:     }
  946:     # force retrieve Resource to seed the part id cache we'll need it later
  947:     my @allres=$navmap->retrieveResources(undef,
  948:                      sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
  949:     my %resourcetracker;
  950:     my $discussiontime;
  951: 
  952: # Resource version changes
  953:     if ($$show{'versionchanges'}) {
  954:         &checkversions($cdom,$crs,$navmap,$changed,$starttime);
  955:     }
  956: 
  957:     if ($$show{'abovethreshold'}) {
  958:         %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',
  959:                                                                    $cdom,$crs);
  960:     }
  961: 
  962:     foreach my $resource (@allres) {
  963:         my $result = '';
  964:         my $applies = 0;
  965:         my $symb = $resource->symb();
  966:         %{$$bombed{$symb}} = ();
  967:         %{$$ungraded{$symb}} = ();
  968:         %{$$triggered{$symb}} = ();
  969:         $$triggered{$symb}{numparts} = 0;
  970:         if ($resource->encrypted()) {
  971:             $$triggered{$symb}{'enclink'} = $resource->link();
  972:             $$triggered{$symb}{'encsymb'} = $resource->shown_symb();
  973:         }
  974:         my $title = $resource->compTitle();
  975:         $$res_title{$symb} = $title;
  976:         my $ressymb = $resource->wrap_symb();
  977: 
  978: # Check if there are unread discussion postings
  979:         if ($$show{'coursediscussion'}) {
  980:             &check_discussions($resource,$symb,$ressymb,$title,
  981: 			       $newdiscussions,$unread,$countunread);
  982:         }
  983: 
  984: # Check for ungraded problems
  985:         if ($resource->is_problem()) {
  986:             if ($$show{'handgrading'}) {
  987:                 &check_handgraded($resource,$symb,$title,$cdom,$crs,$ungraded,
  988:                                                                      $tograde);
  989:             }
  990:         }
  991: 
  992: # Check for bombs
  993:         if ($$show{'haserrors'}) {
  994:             &check_bombed($resource,$symb,$title,$bombs,$bombed);
  995:         }
  996: 
  997: # Maxtries and degree of difficulty for problem parts, unless handgradeable
  998:         if ($$show{'abovethreshold'}) {  
  999:             &check_thresholds($resource,$symb,\%resourcetracker,
 1000: 			      $triggered,$threshold,$warnings);
 1001:         }
 1002: 
 1003:     }
 1004:     return; 
 1005: }
 1006: 
 1007: sub check_discussions {
 1008:     my ($resource,$symb,$ressymb,$title,$newdiscussions,$unread,
 1009: 	$countunread) = @_;
 1010: 
 1011:     if (!$resource->hasDiscussion()) { return; }
 1012: 
 1013:     %{$$unread{$ressymb}} = ();
 1014:     $$unread{$ressymb}{'title'} = $title;
 1015:     $$unread{$ressymb}{'symb'} = $symb;
 1016:     if ($resource->encrypted()) {
 1017:         $$unread{$ressymb}{'enclink'} = $resource->link();
 1018:         $$unread{$ressymb}{'encsymb'} = $resource->shown_symb();
 1019:     }
 1020:     push(@{$newdiscussions}, $ressymb);
 1021:     
 1022:     $$unread{$ressymb}{'lastpost'} = $resource->last_post_time();
 1023:     
 1024:     if ($countunread eq 'on') {
 1025: 	$$unread{$ressymb}{'unreadcount'} = 
 1026:                             $resource->discussion_info('unread');
 1027:     }
 1028: }
 1029: 
 1030: sub check_handgraded {
 1031:     my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_;
 1032:     if ($resource->is_problem()) {
 1033:         my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 1034:         my $partlist=$resource->parts();
 1035:         my $handgradeable;
 1036:         foreach my $part (@$partlist) {
 1037:             if ($resource->handgrade($part) eq 'yes') {
 1038:                 $handgradeable=1; last;
 1039:             }
 1040:         }
 1041:         if ($handgradeable) {
 1042:             my @ungraded = &Apache::bridgetask::get_queue_symb_status(
 1043:                                              'gradingqueue',$symb,$cdom,$cnum);
 1044:             if (@ungraded > 0) {
 1045:                 $$ungraded{$symb}{count} = scalar(@ungraded);
 1046:                 $$ungraded{$symb}{title} = $title;
 1047:                 if ($resource->encrypted()) {
 1048:                     $$ungraded{$symb}{'enclink'} = $resource->link();
 1049:                     $$ungraded{$symb}{'encsymb'} = $resource->shown_symb();
 1050:                 }
 1051:                 push(@{$tograde},$symb);
 1052:             }
 1053:         }
 1054:     }
 1055: }
 1056: 
 1057: sub check_bombed {
 1058:     my ($resource,$symb,$title,$bombs,$bombed) = @_;
 1059:     if ($resource->getErrors()) {
 1060:         my $errors = $resource->getErrors();
 1061:         $errors =~ s/^,//;
 1062:         my @bombs = split(/,/, $errors);
 1063:         my $errorcount = scalar(@bombs);
 1064:         my $errorlink = '<a href="/adm/email?display='.
 1065:                         &escape($bombs[0]).'">'.
 1066:                         $title.'</a>';
 1067:         $$bombed{$symb}{errorcount} = $errorcount;
 1068:         $$bombed{$symb}{errorlink} = $errorlink;
 1069:         push(@{$bombs}, $symb);
 1070:     }
 1071: }
 1072: 
 1073: sub check_thresholds {
 1074:     my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings) = @_;
 1075: # Compile maxtries and degree of difficulty for problem parts, unless handgradeable
 1076:     my @parts = @{$resource->parts()};
 1077:     my %stats;
 1078:     my %lastreset = ();
 1079:     my $warning = 0;
 1080:     foreach my $part (@parts) {
 1081:         if ($resource->handgrade($part) eq 'yes') {
 1082:             next;
 1083:         }
 1084:         if ($resource->is_anonsurvey($part)) {
 1085:             next;
 1086:         }
 1087:         if ($resource->is_survey($part)) {
 1088:             next;
 1089:         }
 1090:         %{$stats{$part}} = ();
 1091:         my ($attempts,$users,$corrects,$degdiff,$av_attempts);
 1092:         if (exists($$resourcetracker{$symb."\0".$part."\0attempts"})) {
 1093:             $attempts = $$resourcetracker{$symb."\0".$part."\0attempts"};
 1094:         }
 1095:         if (exists($$resourcetracker{$symb."\0".$part."\0users"})) {
 1096:             $users = $$resourcetracker{$symb."\0".$part."\0users"};
 1097:         }
 1098:         if (exists($$resourcetracker{$symb."\0".$part."\0correct"})) {
 1099:             $corrects = $$resourcetracker{$symb."\0".$part."\0correct"};
 1100:         }
 1101:         if ($attempts > 0) {
 1102:             $degdiff =  1 - ($corrects/$attempts);
 1103:             $degdiff = sprintf("%.2f",$degdiff);
 1104:         }
 1105:         if ($users > 0) {
 1106:             $av_attempts = $attempts/$users;
 1107:             $av_attempts = sprintf("%.2f",$av_attempts);
 1108:         }
 1109:         &Apache::lonnet::statslog($symb,$part,$users,$av_attempts,$degdiff);
 1110:         if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
 1111:             $stats{$part}{degdiff} = $degdiff;
 1112:             $stats{$part}{attempts} = $av_attempts;
 1113:             $stats{$part}{users} = $users;
 1114:             $lastreset{$part} = $$resourcetracker{$symb."\0".$part."\0resettime"};
 1115:             if ($lastreset{$part}) {
 1116:                 $lastreset{$part} = &Apache::lonnavmaps::timeToHumanString($lastreset{$part});
 1117:             }
 1118:             $warning = 1;
 1119:         }
 1120:     }
 1121:     if ($warning) {
 1122:         $$triggered{$symb}{title} = $resource->title;
 1123:         my $partcount = 0;
 1124:         @{$$triggered{$symb}{text}} = ();
 1125:         foreach my $part (@parts) {
 1126:             if (exists($stats{$part}{users})) {
 1127:                 my $resetname = 'reset_'.&escape($symb."\0".$part);
 1128:                 my $resettitle = 'title_'.&escape($symb."\0".$part);
 1129:                 if (@parts > 1) {
 1130:                     $$triggered{$symb}{text}[$partcount] = '
 1131:                      <td>'.&mt('part - ').$part.'</td>';
 1132:                 } else {
 1133:                     $$triggered{$symb}{text}[$partcount] = '
 1134:                      <td>'.&mt('single part').'</td>';
 1135:                 }
 1136:                 $$triggered{$symb}{text}[$partcount] .= '
 1137:                      <td>'.$stats{$part}{users}.'</td>
 1138:                      <td>'.$stats{$part}{attempts}.'</td>
 1139:                      <td>'.$stats{$part}{degdiff}.'</td>
 1140:                      <td>'.$lastreset{$part}.'</td>
 1141:                      <td><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&escape($$triggered{$symb}{title}).'" /></td>';
 1142:                 $partcount ++;
 1143:             }
 1144:             $$triggered{$symb}{numparts} = $partcount;
 1145:         }
 1146:         push(@{$warnings},$symb);
 1147:     }
 1148: }
 1149: 
 1150: 
 1151: sub get_curr_thresholds {
 1152:     my ($threshold,$uname,$udom,$cid,$cdom,$crs) = @_;
 1153:     # set default values
 1154:     %$threshold = (av_attempts => 2,
 1155:                   degdiff => 0.5,
 1156:                   numstudents => 2
 1157:                   );
 1158:     my %thresholdsettings = &Apache::lonnet::dump('nohist_whatsnew',$udom,
 1159:                                                      $uname,$cid.':threshold');
 1160:     my $thresholdcount = 0;
 1161:     my ($tmp) = %thresholdsettings;
 1162:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1163:         foreach my $item (keys %{$threshold}) { 
 1164:             if (exists($thresholdsettings{$cid.':threshold_'.$item})) {
 1165:                 $$threshold{$item} = 
 1166:                              $thresholdsettings{$cid.':threshold_'.$item};
 1167:                 $thresholdcount ++;
 1168:             }
 1169:         }
 1170:     }
 1171:     if ($thresholdcount == 3) {
 1172:         return;
 1173:     }
 1174:     my %coursesettings = &Apache::lonnet::dump('environment',
 1175:                                               $cdom,$crs,'internal.threshold');
 1176:     my ($temp) = %coursesettings;
 1177:     unless ($temp =~ /^(con_lost|error|no_such_host)/i) {  
 1178:         foreach my $item (keys %{$threshold}) {
 1179:             unless (exists($thresholdsettings{$cid.':threshold_'.$item})) {
 1180:                 if (exists($coursesettings{'internal.threshold_'.$item})) {
 1181:                     $$threshold{$item} = 
 1182:                              $coursesettings{'internal.threshold_'.$item};
 1183:                 }
 1184:             }
 1185:         }
 1186:     }
 1187:     return;
 1188: }
 1189: 
 1190: sub get_current {
 1191:     my ($uname,$udom,$cid,$caller) = @_;
 1192:     my $currvalue;
 1193:     my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid.
 1194:                                                                 ':'.$caller);
 1195:     my ($tmp) = %settings;
 1196:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1197:         $currvalue = $settings{$cid.':'.$caller};
 1198:     }
 1199:     return $currvalue;
 1200: }
 1201: 
 1202: sub process_reset {
 1203:     my ($dom,$crs) = @_;
 1204:     my $result = '<b>'.&mt('Counters reset for following problems (and parts):').
 1205:                            '</b><br />';
 1206:     my @agg_types = ('attempts','users','correct');
 1207:     my %agg_titles = &Apache::lonlocal::texthash (
 1208:                      attempts => 'Number of submissions',
 1209:                      users => 'Students with submissions',
 1210:                      correct => 'Number of correct submissions',
 1211:                      );
 1212:     my @resets = ();
 1213:     my %titles = ();
 1214:     foreach my $key (keys(%env)) {
 1215:         next if ($key !~ /^form\.reset_(.+)$/);
 1216:         my $title = &unescape($env{'form.title_'.$1});
 1217:         my $reset_item = &unescape($1);
 1218:         my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
 1219:         my %aggregates = ();
 1220:         my ($symb,$part) = split(/\0/,$reset_item);
 1221:         foreach my $type (@agg_types) {
 1222:             $aggregates{$reset_item."\0".$type} = 0;
 1223:         }  
 1224: 	$aggregates{$reset_item."\0".'resettime'} = time;
 1225:         my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
 1226:                           $dom,$crs);
 1227:         if ($putresult eq 'ok') {
 1228:             $result .= $title.' -part '.$part.': ';
 1229:             my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
 1230:             foreach my $type (@agg_types) {
 1231:                 $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
 1232:             }
 1233:             $result =~ s/; $//;
 1234:             $result .= '<br />';
 1235:         } else {
 1236:             $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
 1237:         }
 1238:     }
 1239:     return $result;
 1240: }
 1241: 
 1242: sub process_update {
 1243:     my ($uname,$udom,$threshold_titles) = @_;
 1244:     my $setoutput = '<b>'.&mt('Changes to threshold(s) for problem tracking:').'</b><br/><br />';
 1245:     foreach (keys %env) {
 1246:         next if ($_!~/^form\.(.+)\_setparmval$/);
 1247:         my $name  = $1;
 1248:         my $value = $env{'form.'.$name.'_value'};
 1249:         if ($name && defined($value) && ($value ne '')) {
 1250:             my $put_result = &Apache::lonnet::put('nohist_whatsnew',
 1251:                                                   {$name=>$value},$udom,$uname);
 1252:            
 1253:             my ($shortname) = ($name =~ /^\Q$env{'request.course.id'}\E:threshold_(.+)$/);
 1254:             if ($put_result eq 'ok') {
 1255:                 $setoutput.= &Apache::lonhtmlcommon::confirm_success(&mt('Set threshold for [_1] to [_2]',
 1256: 				'<b>'.$$threshold_titles{$shortname}.'</b>',
 1257: 				'<b>'.$value.'</b>').'<br />');
 1258: 	    } else {
 1259:                 $setoutput.= &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
 1260: 				'<b>'.$name.'</b>','<b>'.$value.'</b>',
 1261: 				'<tt>'.$put_result.'</tt>').'<br />',1);
 1262:             }
 1263:         }
 1264:     }
 1265:     return &Apache::loncommon::confirmwrapper($setoutput);
 1266: }
 1267: 
 1268: sub getnormalmail {
 1269:     my ($newmsgs) = @_;
 1270: # Check for unread mail in course
 1271:     my $msgcount = 0;
 1272: 
 1273:     my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
 1274:     foreach my $message (@messages) {
 1275: 	my $msgid=&escape($message);
 1276:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 1277:             &Apache::lonmsg::unpackmsgid($msgid);
 1278:         if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
 1279:             if (defined($sendtime) && $sendtime!~/error/) {
 1280:                 if ($status eq 'new') {
 1281:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
 1282: 		    $msgcount ++;
 1283:                     if ($shortsubj eq '') {
 1284:                         $shortsubj = &mt('No subject');
 1285:                     }
 1286:                     push(@{$newmsgs}, {
 1287:                         msgid    => $msgid,
 1288:                         sendtime => $sendtime,
 1289:                         shortsub => $shortsubj,
 1290:                         from     => $fromname,
 1291:                         fromdom  => $fromdom
 1292:                         });
 1293:                 }
 1294:             }
 1295:         }
 1296:     }
 1297:     return $msgcount;
 1298: }
 1299: 
 1300: sub getcritmail {
 1301:     my ($critmsgs) = @_; 
 1302: # Check for critical messages in course
 1303:     my %what=&Apache::lonnet::dump('critical');
 1304:     my $result = '';
 1305:     my $critmsgcount = 0;
 1306:     foreach my $msgid (sort(keys(%what))) {
 1307:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 1308:             &Apache::lonmsg::unpackmsgid($msgid);
 1309:         if (($fromcid) && ($fromcid eq  $env{'request.course.id'})) {
 1310:             if (defined($sendtime) && $sendtime!~/error/) {
 1311:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
 1312:                 $critmsgcount ++;
 1313:                 if ($shortsubj eq '') {
 1314:                     $shortsubj = &mt('No subject');
 1315:                 }
 1316:                 push(@{$critmsgs}, {
 1317:                         msgid    => $msgid,
 1318:                         sendtime => $sendtime,
 1319:                         shortsub => $shortsubj,
 1320:                         from     => $fromname,
 1321:                         fromdom  => $fromdom
 1322:                         });
 1323:             }
 1324:         }
 1325:     }
 1326:     return $critmsgcount;
 1327: }
 1328: 
 1329: sub getexpired {
 1330:     my ($rolechgs,$rolechgtime,$status) = @_;
 1331:     my $expirecount = &getrolechanges($rolechgs,$rolechgtime,$status);
 1332:     return $expirecount;
 1333: }
 1334: 
 1335: sub getactivated {
 1336:     my ($rolechgs,$rolechgtime,$status) = @_;
 1337:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1338:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1339:     my $now = time();
 1340:     my $context = 'course';
 1341:     my ($permission,$allowed) =
 1342:         &Apache::lonuserutils::get_permission($context);
 1343:     my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
 1344:     my %changes=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
 1345:     my (%stucounted,%advcounted);
 1346:     my $activatedcount = 0;
 1347:     if (keys(%changes) > 0) {
 1348:         foreach my $chg (keys(%changes)) {
 1349:             if (ref($changes{$chg}) eq 'HASH') {
 1350:                 if ($rolechgtime > 0) {
 1351:                     next if ($changes{$chg}{'exe_time'} < $rolechgtime);    
 1352:                 }
 1353:                 if ($changes{$chg}{'exe_time'}) {
 1354:                     my $timestamp = $changes{$chg}{'exe_time'};
 1355:                     if (ref($changes{$chg}{'logentry'}) eq 'HASH') {
 1356:                         next if ($changes{$chg}{'delflag'});
 1357:                         my $start = $changes{$chg}{'logentry'}{'start'};
 1358:                         my $end = $changes{$chg}{'logentry'}{'end'};
 1359:                         my $section = $changes{$chg}{'logentry'}{'section'};
 1360:                         my $role = $changes{$chg}{'logentry'}{'role'};
 1361:                         my $uname = $changes{$chg}{'uname'};
 1362:                         my $udom = $changes{$chg}{'udom'};
 1363:                         next if ($end && $end <= $now);
 1364:                         if (($viewablesec ne '') && ($section ne '')) {
 1365:                             next if ($viewablesec ne $section);
 1366:                         }
 1367:                         next if ($start >= $timestamp);
 1368:                         if ($role eq 'st') {
 1369:                             $stucounted{$uname.':'.$udom.':'.$section} = $start.':'.$end;
 1370:                         } else {
 1371:                             $advcounted{$uname.':'.$udom.':'.$role.':'.$section} = $start.':'.$end;
 1372:                         }
 1373:                         my %chginfo = (
 1374:                                        'section' => $section,
 1375:                                        'uname'   => $uname,
 1376:                                        'udom'    => $udom,
 1377:                                        'role'    => $role,
 1378:                                        'status'  => $status,
 1379:                         );
 1380:                         $activatedcount ++;
 1381:                         push (@{$rolechgs->{$timestamp}},\%chginfo);
 1382:                     }
 1383:                 }
 1384:             }
 1385:         }
 1386:     }
 1387:     $activatedcount += &getrolechanges($rolechgs,$rolechgtime,$status,\%stucounted,\%advcounted);
 1388:     return $activatedcount;
 1389: }
 1390: 
 1391: sub getrolechanges {
 1392:     my ($rolechgs,$rolechgtime,$status,$stucountref,$advcountref) = @_;
 1393:     my (%stucounted,%advcounted);
 1394:     if (ref($stucountref) eq 'HASH') {
 1395:         %stucounted = %{$stucountref};
 1396:     }
 1397:     if (ref($advcountref) eq 'HASH') {
 1398:         %advcounted = %{$advcountref};
 1399:     }
 1400:     my $withsec = 1;
 1401:     my $hidepriv = 1;
 1402:     my $context = 'course';
 1403:     my @statuses = ($status);
 1404:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1405:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1406:     my $now = time();
 1407:     my ($permission,$allowed) =
 1408:         &Apache::lonuserutils::get_permission($context);
 1409:     my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
 1410:     my $classlist = &Apache::loncoursedata::get_classlist();
 1411:     my $secidx = &Apache::loncoursedata::CL_SECTION();
 1412:     my $startidx = &Apache::loncoursedata::CL_START();
 1413:     my $endidx = &Apache::loncoursedata::CL_END();
 1414:     my $rolechgcount = 0;
 1415:     foreach my $key (keys(%{$classlist})) {
 1416:         my ($userstatus,$eventtime);   
 1417:         my $student = $classlist->{$key};
 1418:         if (ref($student) eq 'ARRAY') {
 1419:             my $start = $student->[$startidx];
 1420:             my $end = $student->[$endidx];
 1421:             my $sec = $student->[$secidx]; 
 1422:             my ($stuname,$studom) = split(/:/,$key);
 1423:             if ($status eq 'active') {
 1424:                 if (exists($stucounted{$key.':'.$sec})) {
 1425:                     next;
 1426:                 }
 1427:             }
 1428:             if (($end == 0) || ($end > $start)) {
 1429:                 if ($start <= $now) {
 1430:                     if ($end && $end < $now) {
 1431:                         if ($rolechgtime > 0) {
 1432:                             if ($end > $rolechgtime) {
 1433:                                 $userstatus = 'previous';
 1434:                             }
 1435:                         } else {
 1436:                             $userstatus = 'previous';
 1437:                         }
 1438:                     } else {
 1439:                         if ($rolechgtime > 0) {
 1440:                             if ($start >= $rolechgtime) {
 1441:                                 $userstatus = 'active';
 1442:                             }
 1443:                         } else {
 1444:                             $userstatus = 'active';
 1445:                         }
 1446:                     }
 1447:                 }
 1448:             }
 1449:             next if ($userstatus ne $status);
 1450:             if ($status eq 'active') {
 1451:                 $eventtime = $start;
 1452:             } else {
 1453:                 $eventtime = $end;
 1454:             }
 1455:             if (($viewablesec ne '') && ($sec ne '')) {
 1456:                 next if ($viewablesec ne $sec);
 1457:             }
 1458:             my %chginfo = (
 1459:                             'section' => $sec,
 1460:                             'uname'   => $stuname,
 1461:                             'udom'    => $studom,
 1462:                             'role'    => 'st', 
 1463:                             'status'  => $userstatus,
 1464:                           );
 1465:             $rolechgcount ++;
 1466:             push (@{$rolechgs->{$eventtime}},\%chginfo);
 1467:         }
 1468:     }
 1469:     my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
 1470:                               \@statuses,undef,undef,$withsec,$hidepriv);
 1471:     foreach my $item (keys(%advrolehash)) {
 1472:         my ($userstatus,$eventtime);
 1473:         my ($uname,$udom,$role,$section) = split(/:/,$item,-1);
 1474:         my ($start,$end) = split(/:/,$advrolehash{$item});
 1475:         if ($start eq '-1' && $end eq '-1') {
 1476:             next;
 1477:         } else {
 1478:             if ($status eq 'active') {
 1479:                 if (exists($advcounted{$item})) {
 1480:                     next;
 1481:                 }
 1482:             }
 1483:             if (($end == 0) || ($end > $start)) {
 1484:                 if ($start <= $now) {
 1485:                     if ($end && $end < $now) {
 1486:                         if ($rolechgtime > 0) {
 1487:                             if ($end > $rolechgtime) {
 1488:                                 $userstatus = 'previous';
 1489:                             }
 1490:                         } else {
 1491:                             $userstatus = 'previous';
 1492:                         }
 1493:                     } else {
 1494:                         if ($rolechgtime > 0) {
 1495:                             if ($start >= $rolechgtime) {
 1496:                                 $userstatus = 'active';
 1497:                             }
 1498:                         } else {
 1499:                             $userstatus = 'active';
 1500:                         }
 1501:                     }
 1502:                 }
 1503:             }
 1504:             next if ($userstatus ne $status);
 1505:             if ($status eq 'active') {
 1506:                 $eventtime = $start;
 1507:             } else {
 1508:                 $eventtime = $end;
 1509:             }
 1510:         }
 1511:         if (($viewablesec ne '') && ($section ne '')) {
 1512:             next if ($viewablesec ne $section);
 1513:         }
 1514:         my %chginfo = ( 
 1515:                         'section' => $section,
 1516:                         'uname'   => $uname,
 1517:                         'udom'    => $udom,
 1518:                         'role'    => $role,
 1519:                         'status'  => $userstatus,    
 1520:                       );
 1521:         $rolechgcount ++; 
 1522:         push (@{$rolechgs->{$eventtime}},\%chginfo); 
 1523:     }
 1524:     return $rolechgcount;
 1525: }
 1526: 
 1527: sub getloggedin {
 1528:     my ($cdom,$crs,$lastlogins,$starttime) = @_;
 1529:     my $context = 'course';
 1530:     my ($permission,$allowed) =
 1531:         &Apache::lonuserutils::get_permission($context);
 1532:     my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
 1533:     my %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$crs);
 1534:     my $logincount = 0;
 1535:     my ($tmp) = keys(%crslogins);
 1536:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1537:         if (keys(%crslogins) > 0) {
 1538:             foreach my $key (keys(%crslogins)) {
 1539:                 my ($uname,$udom,$section,$role) = split(/:/,$key);
 1540:                 my $eventtime = $crslogins{$key};
 1541:                 if ($eventtime > $starttime) {
 1542:                     if (($viewablesec ne '') && ($section ne '')) {
 1543:                         next if ($viewablesec ne $section);
 1544:                     }
 1545:                     my %chginfo = (
 1546:                                    'section' => $section,
 1547:                                    'uname'   => $uname,
 1548:                                    'udom'    => $udom,
 1549:                                    'role'    => $role,
 1550:                     );
 1551:                     $logincount ++;
 1552:                     push (@{$lastlogins->{$eventtime}},\%chginfo);
 1553:                 }
 1554:             }
 1555:         }
 1556:     }
 1557:     return $logincount;
 1558: }
 1559: 
 1560: sub checkversions {
 1561:     my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
 1562:     my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
 1563:     my ($tmp) = keys(%changes);
 1564:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1565:         if (keys(%changes) > 0) {
 1566:             foreach my $key (sort(keys(%changes))) {
 1567:                 if ($changes{$key} > $starttime) {
 1568:                     my $version;
 1569:                     my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
 1570:                     my $currentversion=&Apache::lonnet::getversion($key);
 1571:                     my $revdate = 
 1572:                           &Apache::lonnet::metadata($root.'.'.$extension,
 1573:                                                      'lastrevisiondate');
 1574:                     $revdate =  &Apache::lonlocal::locallocaltime($revdate);
 1575:                     my $linkurl=&Apache::lonnet::clutter($key);
 1576:                     my $usedversion=$navmap->usedVersion($linkurl);
 1577:                     my @resources = $navmap->getResourceByUrl($linkurl,1);
 1578:                     if (($usedversion) && ($usedversion ne 'mostrecent')) {
 1579:                         $version = $usedversion;     
 1580:                     } else {
 1581:                         $version = $currentversion;
 1582:                     }
 1583:                     foreach my $res (@resources) {
 1584:                          if (ref($res) eq 'Apache::lonnavmaps::resource') { 
 1585:                             my $symb = $res->symb();
 1586:                             %{$$changed{$symb}} = (
 1587:                                                 current => $currentversion,
 1588:                                                 version => $version,
 1589:                                                 revdate => $revdate,
 1590:                             );
 1591:                         }
 1592:                     }
 1593:                 }
 1594:             }
 1595:         }
 1596:     }
 1597:     return;
 1598: }
 1599: 
 1600: sub display_handgrade {
 1601:     my ($r,$tograde,$ungraded,$itemserror) = @_;
 1602:     my %lt = &Apache::lonlocal::texthash(
 1603:                         'prna' => 'Problem Name',
 1604:                         'nmun' => 'Number ungraded',
 1605:                         'nopr' => 'No problems require handgrading',
 1606:     );
 1607:     if (@{$tograde} > 0) {
 1608:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1609:                   $lt{'prna'}.'</td><td class="LC_right_item">'.
 1610:                   $lt{'nmun'}.'</td></tr>');
 1611:         my $rowNum = 0;
 1612:         foreach my $res (@{$tograde}) {
 1613:             $rowNum ++;
 1614:             my $css_class = $rowNum%2?' class="LC_odd_row"':'';
 1615:             my $linkurl='/adm/grades';
 1616:             if ($$ungraded{$res}{'enclink'}) {
 1617:                 $linkurl.='?symb='.$$ungraded{$res}{'encsymb'};
 1618:             } else {
 1619:                 $linkurl.='?symb='.&escape($res);
 1620:             }
 1621:             $linkurl.='&amp;command=ungraded';
 1622:             $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.$$ungraded{$res}{title}.'</a></td><td class="LC_right_item">'.$$ungraded{$res}{count}.'</td></tr>');
 1623:         }
 1624:     } elsif ($itemserror) {
 1625:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1626:     } else {
 1627:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
 1628:     }
 1629: }
 1630: 
 1631: sub display_haserrors {
 1632:     my ($r,$bombs,$bombed,$res_title,$itemserror) = @_;
 1633:     my $bombnum = 0;
 1634:     my %lt = &Apache::lonlocal::texthash(
 1635:                                    reso => 'Resource',
 1636:                                    nmer => 'Number of errors',
 1637:                                    noer => 'No problems with errors',
 1638:     );
 1639:     if (@{$bombs} > 0) {
 1640:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1641:                   $lt{'reso'}.'</td><td class="LC_right_item">'.
 1642:                   $lt{'nmer'}.'</td></tr>');
 1643:         @{$bombs} = sort { &cmp_title($a,$b,$res_title) } @{$bombs};
 1644:         foreach my $bomb (@{$bombs}) {
 1645:             $bombnum ++;
 1646:             my $css_class = $bombnum%2?' class="LC_odd_row"':'';
 1647:             $r->print('<tr'.$css_class.'><td>'.$$bombed{$bomb}{errorlink}.
 1648:                       '</td><td class="LC_right_item">'.
 1649:                       $$bombed{$bomb}{errorcount}.'</td></tr>');
 1650:         }
 1651:     } elsif ($itemserror) {
 1652:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1653:     } else {
 1654:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'noer'}.'</td></tr>');
 1655:     }
 1656:     return;
 1657: }
 1658: 
 1659: sub display_abovethreshold {
 1660:     my ($r,$refpage,$warnings,$triggered,$res_title,$itemserror) = @_;
 1661:     my %lt = &Apache::lonlocal::texthash(
 1662:                  reso => 'Resource',
 1663:                  part => 'Part',
 1664:                  nust => 'Num. students',
 1665:                  avat => 'Av. Attempts',
 1666:                  dedi => 'Deg. Diff',
 1667:                  lare => 'Last Reset',
 1668:                  reco => 'Reset Count?',
 1669:                  rese => 'Reset counters to 0',
 1670:                  nopr => 'No problems satisfy threshold criteria',
 1671:     );
 1672:     if (@{$warnings} > 0) {
 1673:         @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
 1674:         $r->print('<tr class="LC_info_row">'.
 1675: 		  '<td class="LC_left_item">'.$lt{'reso'}.
 1676:                   '<input type="hidden" name="command" value="" /></td>'.
 1677: 		  '<td>'.$lt{'part'}.'</td><td>'.$lt{'nust'}.'</td>'.
 1678: 		  '<td>'.$lt{'avat'}.'</td><td>'.$lt{'dedi'}.'</td>'.
 1679: 		  '<td>'.$lt{'lare'}.'</td><td  class="LC_right_item">'.
 1680:                   $lt{'reco'}.'</td></tr>');
 1681: 	my $row;
 1682:         foreach my $res (@{$warnings}) {
 1683: 	    $row++;
 1684:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
 1685:             my $linkurl=&Apache::lonnet::clutter($url);
 1686:             my $rowspan;
 1687:             if ($$triggered{$res}{numparts} > 1) {
 1688:                 $rowspan = 'rowspan="'.$$triggered{$res}{numparts}.'"';
 1689:             }
 1690:             $linkurl .= '?symb='.&escape($res);
 1691:             if ($$triggered{$res}{'enclink'}) {
 1692:                 $linkurl = 
 1693:                   $$triggered{$res}{'enclink'}.'?symb='.$$triggered{$res}{'encsymb'};
 1694:             }
 1695:             my $css_class = $row%2?' class="LC_odd_row"':'';
 1696:             $r->print('<tr'.$css_class.'>'.
 1697: 		      '<td class="LC_first_item" '.$rowspan.'><a href="'.$linkurl.'">'.
 1698: 		      $$triggered{$res}{title}.'</a></td>');
 1699:                       if (ref($$triggered{$res}{text}) eq 'ARRAY') {
 1700: 		          $r->print($$triggered{$res}{text}[0]);
 1701:                       }
 1702:                       $r->print('</tr>');
 1703:             if (ref($$triggered{$res}{text}) eq 'ARRAY') {
 1704:                 if (@{$$triggered{$res}{text}} > 1) {
 1705:                     for (my $i=1; $i<@{$$triggered{$res}{text}}; $i++) {
 1706:                         $r->print('<tr '.$css_class.'>'.
 1707:                                   $$triggered{$res}{text}[$i].'</tr>');
 1708:                     }
 1709:                 }
 1710:             }
 1711:         }
 1712:         $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>');
 1713:     } elsif ($itemserror) {
 1714:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1715:     } else {
 1716:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
 1717:     }
 1718: }
 1719: 
 1720: sub display_versionchanges {
 1721:     my ($r,$changed,$res_title,$interval,$itemserror) = @_;
 1722:     my %lt = &Apache::lonlocal::texthash(
 1723:         'reso' => 'Resource',
 1724:         'revd' => 'Last revised',
 1725:         'newv' => 'New version',
 1726:         'veru' => 'Version used',
 1727:     );
 1728:     if (keys(%{$changed}) > 0) {
 1729:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1730:                   $lt{'reso'}.'</td><td>'.$lt{'revd'}.'</td><td>'.
 1731:                   $lt{'newv'}.'</td><td class="LC_right_item">'.
 1732:                   $lt{'veru'}.'</td></tr>');
 1733:         my @changes = sort { &cmp_title($a,$b,$res_title) } keys(%{$changed});
 1734:         my $changenum = 0;
 1735:         foreach my $item (@changes) {
 1736:             $changenum ++;
 1737:             my $css_class = $changenum%2?' class="LC_odd_row"':'';
 1738:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($item);
 1739:             my $linkurl=&Apache::lonnet::clutter($url);
 1740:             $linkurl .= '?symb='.&escape($item);
 1741: 
 1742:             $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.
 1743:                       $$res_title{$item}.'</a></td><td>'.
 1744:                       $$changed{$item}{'revdate'}.'</td><td>'.
 1745:                       $$changed{$item}{'current'}.'</td><td>'.
 1746:                       $$changed{$item}{'version'}.'</td></tr>');
 1747:         }
 1748:     } elsif ($itemserror) {
 1749:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1750:     } else {
 1751:         $r->print('<tr class="LC_empty_row"><td>'
 1752:                  .&mt('No '.$interval).'</td></tr>');
 1753:     }
 1754:     return;
 1755: }
 1756: 
 1757: sub display_rolechanges {
 1758:     my ($r,$chgcount,$changed,$interval,$crstype) = @_;
 1759:     my $now = time();
 1760:     my %lt = &Apache::lonlocal::texthash(
 1761:         'user'  => 'User',
 1762:         'tich'  => 'Time of change',
 1763:         'role'  => 'Role',
 1764:         'sec'   => 'Section',
 1765:         'status'  => 'Status',
 1766:     );
 1767:     if ($chgcount) {
 1768:         $r->print('<tr class="LC_info_row">'.
 1769:                   '<td class="LC_left_item">'.$lt{'tich'}.'</td>'.
 1770:                   '<td class="LC_left_item">'.$lt{'user'}.'</td>'.
 1771:                   '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
 1772:                   '<td class="LC_left_item">'.$lt{'sec'}.'</td>'.
 1773:                   '<td class="LC_left_item">'.$lt{'status'}.'</td></tr>');
 1774:         if (ref($changed) eq 'HASH') {
 1775:             my @changes = sort { $b <=> $a } (keys(%{$changed}));
 1776:             my $changenum = 0;
 1777:             foreach my $item (@changes) {
 1778:                 if (ref($changed->{$item}) eq 'ARRAY') {
 1779:                     foreach my $chg (@{$changed->{$item}}) {
 1780:                         if (ref($chg) eq 'HASH') {
 1781:                             my $section;
 1782:                             my $role = 
 1783:                                 &Apache::lonnet::plaintext($chg->{'role'},$crstype);
 1784:                             my $status = &mt($chg->{'status'});
 1785:                             if ($chg->{'section'} eq '') {
 1786:                                 $section = &mt('none');
 1787:                             } else {
 1788:                                 $section = $chg->{'section'};
 1789:                             }
 1790:                             my $uname = $chg->{'uname'};
 1791:                             my $udom = $chg->{'udom'};
 1792:                             $changenum ++;
 1793:                             my $css_class = $changenum%2?' class="LC_odd_row"':'';
 1794:                             my $link = 
 1795:                                 &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
 1796:                             $r->print('<tr'.$css_class.'>'.
 1797:                                       '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
 1798:                                       '<td>'.$link.'</td>'.
 1799:                                       '<td>'.$role.'</td>'.
 1800:                                       '<td>'.$section.'</td>'.
 1801:                                       '<td>'.$status.'</td></tr>');
 1802:                         }
 1803:                     }
 1804:                 }
 1805:             }
 1806:         }
 1807:     } else {
 1808:         $r->print('<tr class="LC_empty_row"><td>'
 1809:                  .&mt('There are no '.$interval).'</td></tr>');
 1810:     }
 1811:     return;
 1812: }
 1813: 
 1814: sub display_crslogins {
 1815:     my ($r,$logincount,$loggedin,$interval,$crstype) = @_;
 1816:     my %lt = &Apache::lonlocal::texthash(
 1817:         'user'   => 'User',
 1818:         'role'   => 'Role',
 1819:         'sec'    => 'Section',
 1820:         'number' => 'Total number of logins',
 1821:     );
 1822:     if ($logincount) {
 1823: 
 1824:         my $hdr = '<tr class="LC_info_row" style="display:none" id="logintitledet">'.
 1825:                   '<td class="LC_left_item">'.$lt{'user'}.'</td>'.
 1826:                   '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
 1827:                   '<td class="LC_left_item">'.$lt{'sec'}.'</td></tr>'.
 1828:                   '<tr class="LC_info_row" id="logintitlesum">'.
 1829:                   '<td class="LC_left_item">'.$lt{'number'}.'</td>'.
 1830:                   '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
 1831:                   '<td class="LC_left_item">'.$lt{'sec'};
 1832:         my (%bylastname,%counts);
 1833:         if (ref($loggedin) eq 'HASH') {
 1834:             my @logins = sort { $b <=> $a } (keys(%{$loggedin}));
 1835:             my $numlogin = 0;
 1836:             foreach my $item (@logins) {
 1837:                 if (ref($loggedin->{$item}) eq 'ARRAY') {
 1838:                     foreach my $user (@{$loggedin->{$item}}) {
 1839:                         if (ref($user) eq 'HASH') {
 1840:                             my $section;
 1841:                             my $role =
 1842:                                 &Apache::lonnet::plaintext($user->{'role'},$crstype);
 1843:                             my $status = &mt($user->{'status'});
 1844:                             if ($user->{'section'} eq '') {
 1845:                                 $section = &mt('none');
 1846:                             } else {
 1847:                                 $section = $user->{'section'};
 1848:                             }
 1849:                             $counts{$user->{'role'}}{$section} ++;
 1850:                             my $uname = $user->{'uname'};
 1851:                             my $udom = $user->{'udom'};
 1852:                             my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
 1853:                             my $link =
 1854:                                 &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
 1855:                             push(@{$bylastname{$fullname}},
 1856:                                                           '<td>'.$link.'</td>'.
 1857:                                                           '<td>'.$role.'</td>'.
 1858:                                                           '<td>'.$section.'</td>');
 1859:                         }
 1860:                     }
 1861:                 }
 1862:             }
 1863:             my $table;
 1864:             foreach my $person (sort(keys(%bylastname))) {
 1865:                 if (ref($bylastname{$person}) eq 'ARRAY') {
 1866:                     foreach my $item (@{$bylastname{$person}}) {
 1867:                         $numlogin ++;
 1868:                         my $css_class = $numlogin%2?' class="LC_odd_row"':'';
 1869:                         $table .= '<tr'.$css_class.' style="display:none;"  id="logindet_'.$numlogin.'">'.$item.'</tr>';
 1870:                     }
 1871:                 }
 1872:             }
 1873:             my $numrow = 0;
 1874:             foreach my $role (sort(keys(%counts))) {
 1875:                 my $showrole = &Apache::lonnet::plaintext($role,$crstype);
 1876:                 if (ref($counts{$role}) eq 'HASH') {
 1877:                     foreach my $sec (sort { $b <=> $a } (keys(%{$counts{$role}}))) {
 1878:                         $numrow ++;
 1879:                         my $css_class = $numrow%2?' class="LC_odd_row"':'';
 1880:                         $table .= '<tr '.$css_class.' id="loginsum_'.$numrow.'">'.
 1881:                                   '<td>'.$counts{$role}{$sec}.'</td>'.
 1882:                                   '<td>'.$showrole.'</td>'.
 1883:                                   '<td>'.$sec.'</td></tr>';
 1884:                    }
 1885:                 }
 1886:             }
 1887:             $r->print($hdr.'<input type="hidden" name="logincount" value="'.$numlogin.
 1888:                       '" /><input type="hidden" name="loginrow" value="'.$numrow.
 1889:                       '" /></td></tr>'.$table);
 1890:         }
 1891:     } else {
 1892:         $r->print('<tr class="LC_empty_row"><td>'.
 1893:                   &mt('There are no '.$interval).
 1894:                   '<input type="hidden" name="logincount" value="'.$logincount.
 1895:                   '." /></td></tr>');
 1896:     }
 1897:     return;
 1898: }
 1899:  
 1900: sub display_coursediscussion {
 1901:     my ($r,$newdiscussions,$unread,$countunread,$res_title,$itemserror) = @_;
 1902:     my $lctype = lc(&Apache::loncommon::course_type());
 1903:     my %lt = &Apache::lonlocal::texthash(
 1904:                 'loca' => 'Location',
 1905:                 'type' => 'Type',
 1906:                 'numn' => 'Number of new posts',
 1907:                 'noun' => 'No unread posts in '.$lctype.' discussions',
 1908:                 'tmlp' => 'Time of last post', 
 1909:     );
 1910:     if (@{$newdiscussions} > 0) {
 1911:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1912:                   $lt{'loca'}.'</td><td>'.
 1913:                   $lt{'type'}.'</td>');
 1914:         if ($countunread eq 'on') {
 1915:             $r->print('<td>'.$lt{'tmlp'}.'</td>'.
 1916:                       '<td class="LC_right_item">'.$lt{'numn'}.'</td>');
 1917:         } else {
 1918:             $r->print('<td class="LC_right_item">'.$lt{'tmlp'}.'</td>');
 1919:         }
 1920:         $r->print("</tr>\n");
 1921:         @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) }
 1922:                                                             @{$newdiscussions};
 1923:         my $rowNum = 0;
 1924:         foreach my $ressymb (@{$newdiscussions}) {
 1925:             $rowNum ++;
 1926:             my $forum_title = $$unread{$ressymb}{'title'};
 1927:             my $type = 'Resource';
 1928:             my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
 1929:             my $disclink = $feedurl.'?symb='. &escape($$unread{$ressymb}{symb});
 1930:             if ($feedurl =~ /bulletinboard/) {
 1931:                 $type = 'Discussion Board';
 1932:             }
 1933:             if ($$unread{$ressymb}{'enclink'}) {
 1934:                 $disclink = $$unread{$ressymb}{'enclink'}.'?symb='.$$unread{$ressymb}{'encsymb'};
 1935:             }
 1936:             my $css_class = $rowNum%2?' class="LC_odd_row"':'';
 1937:             my $lastpost = &Apache::lonnavmaps::timeToHumanString(
 1938:                                                $$unread{$ressymb}{'lastpost'});
 1939:             $r->print('<tr'.$css_class.'><td><a href="'.$disclink.'">'.$forum_title.'</a>&nbsp;</td><td>'.&mt($type).'&nbsp;</td>');
 1940:             if ($countunread eq 'on') {
 1941:                 my $unreadnum = $$unread{$ressymb}{'unreadcount'};
 1942:                 $r->print('<td>'.$lastpost.'</td><td class="LC_right_item">'.
 1943:                           $unreadnum.'&nbsp;</td>');
 1944:             } else {
 1945:                 $r->print('<td class="LC_right_item">'.$lastpost.'</td>');
 1946:             }
 1947:             $r->print("</tr>\n");
 1948:         }
 1949:     } elsif ($itemserror) {
 1950:         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
 1951:     } else {
 1952:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'noun'}.'</td></tr>');
 1953:     }
 1954: }
 1955: 
 1956: sub display_coursenormalmail {
 1957:     my ($r,$msgcount,$newmsgs) = @_;
 1958:     my $lctype = lc(&Apache::loncommon::course_type());
 1959:     if ($msgcount > 0) {
 1960:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1961:                   &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
 1962:                   &mt('Sender').'</td><td class="LC_right_item">'.
 1963:                   &mt('Date/Time').'</td></tr>');
 1964:         my $mailcount = 0;
 1965:         foreach my $msg (@{$newmsgs}) {
 1966:             $mailcount ++;
 1967:             my $css_class = $mailcount%2?' class="LC_odd_row"':'';
 1968:             $r->print('<tr'.$css_class.'><td>'.$mailcount
 1969:                       .'.&nbsp;</td><td><a href="/adm/email?display='
 1970:                       .$msg->{'msgid'}.'">'
 1971:                       .$msg->{'shortsub'}.'</a>&nbsp;&nbsp;</td><td>&nbsp;'
 1972:                       .$msg->{'from'}.':'.$msg->{'fromdom'}.'&nbsp;</td><td>'
 1973:                       .$msg->{'sendtime'}.'</td></tr>');
 1974:         }
 1975:     } else {
 1976:         $r->print('<tr class="LC_empty_row"><td>'.
 1977:                   &mt('No new '.$lctype.' messages').'</td></tr>');
 1978:     }
 1979: }
 1980: 
 1981: sub display_coursecritmail {
 1982:     my ($r,$critmsgcount,$critmsgs) = @_;
 1983:     my $lctype = lc(&Apache::loncommon::course_type());
 1984:     if ($critmsgcount > 0) {
 1985:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1986:                   &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
 1987:                   &mt('Sender').'</td><td class="LC_right_item">'.
 1988:                   &mt('Date/Time').'</td></tr>');
 1989:         my $mailcount = 0;
 1990:         foreach my $msg (@{$critmsgs}) {
 1991:             $mailcount ++;
 1992:             my $css_class = $mailcount%2?' class="LC_odd_row"':'';
 1993:             $r->print('<tr'.$css_class.'><td>'.$mailcount.
 1994:                       '. &nbsp;</td><td><a href="/adm/email?folder=critical">'.
 1995:                       $msg->{'shortsub'}.'</a>&nbsp; &nbsp;</td><td>&nbsp;'.
 1996:                       $msg->{'from'}.':'.$msg->{'fromdom'}.'&nbsp;</td><td>'.
 1997:                       $msg->{'sendtime'}.'</td></tr>');
 1998:         }
 1999:     } else {
 2000:         $r->print('<tr class="LC_empty_row"><td>'.
 2001:                   &mt('No unread critical messages in '.$lctype).
 2002:                   '</td></tr>');
 2003:     }
 2004: }
 2005: 
 2006: sub cmp_title {
 2007:     my ($a,$b,$res_title) = @_;
 2008:     my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
 2009:     $atitle=~s/^\s*//;
 2010:     $btitle=~s/^\s*//;
 2011:     return $atitle cmp $btitle;
 2012: }
 2013: 
 2014: sub get_display_settings {
 2015:     my ($uname,$udom,$cid) = @_;
 2016:     my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid); 
 2017:     my ($tmp) = keys(%settings);
 2018:     if ($tmp=~ /^(con_lost|error|no_such_host)/i) {
 2019:         %settings = ();
 2020:         unless ($tmp =~ /^error: 2 /) {
 2021: 	    my $lctype = lc(&Apache::loncommon::course_type());
 2022:             &Apache::lonnet::logthis('Error retrieving whatsnew settings: '.
 2023:             $tmp.' for '.$uname.':'.$udom.' for '.$lctype.': '.$cid);
 2024:         }
 2025:     }
 2026:     return %settings;
 2027: }
 2028: 
 2029: sub store_display_settings {
 2030:     my ($uname,$udom,$cid,$checkallowed) = @_;
 2031:     my %whatsnew_settings;
 2032:     my $result;
 2033:     foreach my $key (keys(%{$checkallowed})) {
 2034: 	if ($key =~ /_section$/) { next; }
 2035:         if (exists($env{'form.display_'.$key})) {
 2036:             unless ($env{'form.display_'.$key} eq '') {
 2037:                 $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key};
 2038:             }
 2039:         }
 2040:     }
 2041:     if (keys(%whatsnew_settings)) {
 2042:         $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings,
 2043:                                                                  $udom,$uname);
 2044:     } else {
 2045:         $result = 'ok';
 2046:     }
 2047:     return $result;
 2048: }
 2049: 
 2050: sub store_interval_setting {
 2051:     my ($uname,$udom,$cid,$interval_titles) = @_;
 2052:     my %interval_settings = ();
 2053:     my $result;
 2054:     my $context = $env{'form.intervaltype'};
 2055:     if ($env{'form.interval'} ne '') {
 2056:         if ($context eq 'oldroles') {
 2057:             $interval_settings{$cid.':oldroleinterval'} = $env{'form.interval'};
 2058:         } elsif ($context eq 'newroles') {
 2059:             $interval_settings{$cid.':newroleinterval'} = $env{'form.interval'};
 2060:         } elsif ($context eq 'crslogin') {
 2061:             $interval_settings{$cid.':crslogininterval'} = $env{'form.interval'};
 2062:         } else {
 2063:             $interval_settings{$cid.':interval'} = $env{'form.interval'};
 2064:         }
 2065:         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 2066:                                              \%interval_settings,$udom,$uname);
 2067:         if ($outcome eq 'ok') {
 2068:             if (ref($interval_titles->{$context}) eq 'HASH') {
 2069:                 $result = &Apache::lonhtmlcommon::confirm_success(&mt('New filter setting: [_1].','<b>'. 
 2070:                               $interval_titles->{$context}->{$env{'form.interval'}}.'</b>').'<br />');
 2071:             }
 2072:         } else {
 2073: 	    my $lctype = lc(&Apache::loncommon::course_type());
 2074:             &Apache::lonnet::logthis('Error saving whatsnew '.$context.' interval setting'.
 2075:                 ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
 2076:             $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set interval to [_1] due to [_2].',
 2077:                          '<b>'.$interval_titles->{$context}->{$env{'form.interval'}}.'</b>',
 2078:                          '<tt>'.$outcome.'</tt>'),1);
 2079:         }
 2080:     }
 2081:     return &Apache::loncommon::confirmwrapper($result);
 2082: }
 2083: 
 2084: sub store_discussion_setting {
 2085:     my ($uname,$udom,$cid) = @_;
 2086:     my %discussion_settings;
 2087:     my $result;
 2088:     if (defined($env{'form.countunread'})) {
 2089:         $discussion_settings{$cid.':countunread'} = $env{'form.countunread'};
 2090:         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 2091:                                              \%discussion_settings,$udom,$uname);
 2092:         if ($outcome eq 'ok') {
 2093:             $result = &Apache::lonhtmlcommon::confirm_success(&mt('Count unread posts in discussions display set to [_1]',
 2094:                   '<b>'.&mt($env{'form.countunread'}).'</b>').'<br />');
 2095:                                                                                   
 2096:         } else {
 2097: 	    my $lctype = lc(&Apache::loncommon::course_type());
 2098:             &Apache::lonnet::logthis('Error saving whatsnew countunread setting'.
 2099:                 ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
 2100:             $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set "number unread posts display" to [_1]'.
 2101:                           ' due to [_2].',
 2102:                          '<b>'.&mt($env{'form.countunread'}).'</b>',
 2103:                          '<tt>'.$outcome.'</tt>'),1);
 2104:         }
 2105:     }
 2106:     return &Apache::loncommon::confirmwrapper($result);
 2107: }
 2108: 
 2109: sub store_courseinit_setting {
 2110:     my ($uname,$udom,$cid,$initpage) = @_;
 2111:     my %courseinit_settings;
 2112:     my $page_control;
 2113:     my $result;
 2114:     if (defined($env{'form.courseinit_control'})) {
 2115:         if ($env{'form.courseinit_control'} eq 'userpref') {
 2116:             $courseinit_settings{$cid.':courseinit'} = '';
 2117:             $page_control = 'global preferences';
 2118:         } else {
 2119:             if (defined($env{'form.courseinit_page'})) {
 2120:                 $courseinit_settings{$cid.':courseinit'} = 
 2121:                                                   $env{'form.courseinit_page'};
 2122:                 $page_control = 'course specific setting';
 2123:             }
 2124:         }
 2125:         if ($page_control) {
 2126: 	    my $lctype = lc(&Apache::loncommon::course_type());
 2127:             my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 2128:                                            \%courseinit_settings,$udom,$uname);
 2129:             if ($outcome eq 'ok') {
 2130:                 if ($page_control eq 'global preferences') {
 2131:                     $result = &Apache::lonhtmlcommon::confirm_success(&mt("Page displayed after role selection in $lctype now set by [_1]user's global preferences[_2].",'<b>','</b>'));
 2132:                 } else {
 2133:                     $result = &Apache::lonhtmlcommon::confirm_success(&mt('Page displayed after role selection in this '.$lctype.' set to [_1].'
 2134:                                  ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>'));
 2135:                 }
 2136:             } else {
 2137:                 &Apache::lonnet::logthis('Error saving whatsnew courseinit '.
 2138:                                          'setting: '.$outcome.' for '.$uname.
 2139:                                          ':'.$udom.' in '.$lctype.' '.$cid);
 2140:                 if ($page_control eq 'global preferences') {
 2141:                     $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set control of page display to [_1]'.
 2142:                           ' due to [_2].',
 2143:                          '<b>'.$page_control.'</b>',
 2144:                          '<tt>'.$outcome.'</tt>'),1);
 2145:                 } else {
 2146:                     $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set page display, after role selection, for this '.$lctype.' to [_1] due to [_2].'
 2147:                                  ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>'
 2148:                                  ,'<tt>'.$outcome.'</tt>'),1);
 2149:                 }
 2150:             }
 2151:         }
 2152:     }
 2153:     return &Apache::loncommon::confirmwrapper($result);
 2154: }
 2155: 
 2156: sub start_box {
 2157:     my ($r,$show,$heading,$caller,$refpage) = @_;
 2158:     my %lt = &Apache::lonlocal::texthash( 
 2159:                        chth => 'Change thresholds?',
 2160:                        chin => 'Change interval?',
 2161:                        chop => 'Change options?',
 2162:     );
 2163:     my $showhide;
 2164:     if ($$show{$caller}) {
 2165:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 2166:                                'display_'.$caller.",'hide'".');">'.
 2167:                                &mt('Hide').'</a></b>';
 2168:    
 2169:     } else {
 2170:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 2171:                                'display_'.$caller.",'show'".');">'.
 2172:                                &mt('Show').'</a></b>';
 2173:     }
 2174:     
 2175:     $r->print('
 2176:          <table class="LC_nested_outer">
 2177:           <tr>
 2178:            <th class="LC_left_item">'.$$heading{$caller}.'</th>
 2179:            <th class="LC_right_item">'.$showhide.'</th>
 2180:           </tr>');
 2181:      if (($caller eq 'abovethreshold') && ($$show{$caller})) {
 2182:          if ($$show{$caller}) {
 2183:              $r->print('
 2184:               <tr>
 2185:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgthreshold&amp;refpage='.$refpage.'">'.$lt{'chth'}.'</a></td>
 2186:               </tr>');
 2187:          }
 2188:      } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
 2189:          if ($$show{$caller}) {
 2190:              $r->print('
 2191:               <tr>
 2192:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chginterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2193:               </tr>');
 2194:          }
 2195:      } elsif ($caller eq 'coursediscussion') {
 2196:          if ($$show{$caller}) {
 2197:              $r->print('
 2198:               <tr>
 2199:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&amp;refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
 2200:               </tr>');
 2201:          }
 2202:      } elsif (($caller eq 'newroles') && ($$show{$caller})) {
 2203:          if ($$show{$caller}) {
 2204:              $r->print('
 2205:               <tr>
 2206:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgnewroleinterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2207:               </tr>');
 2208:          }
 2209:      } elsif (($caller eq 'oldroles') && ($$show{$caller})) {
 2210:          if ($$show{$caller}) {
 2211:              $r->print('
 2212:               <tr>
 2213:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 2214:               </tr>');
 2215:          }
 2216:     } elsif (($caller eq 'crslogin') && ($$show{$caller})) {
 2217:         if ($$show{$caller}) {
 2218:             $r->print('
 2219:               <tr>
 2220:                 <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>
 2221:               </tr>');
 2222:         }
 2223:     }
 2224: 
 2225:     $r->print('
 2226:               <tr>
 2227:                <td colspan="2">
 2228:                 <table class="LC_nested">
 2229: ');
 2230:     return;
 2231: }
 2232: 
 2233: sub end_box {
 2234:     my ($r) = shift;
 2235:     $r->print('
 2236:    </table>
 2237:   </td>
 2238:  </tr>
 2239: </table><br />');
 2240:     return;
 2241: }
 2242: 
 2243: 1;

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