File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.105.2.9: download - view: text, annotated - select for diffs
Sat Dec 14 02:08:30 2013 UTC (10 years, 4 months ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0
- For 2.11
  - Backport 1.116

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

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