File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.68: download - view: text, annotated - select for diffs
Tue Feb 27 22:16:02 2007 UTC (17 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- More comprehensive CSS use in "What's New" display.
- Move row color definitions from lonwhatsnew.pm to loncommon::standard_css().
- Add some style definitions to loncommon::standard_css() for nested tables (as used in "What's New" display.
- Rename LC_whatsnew styles as LC_nested_outer and LC_nested, as use on other pages besides "What's New" is anticipated.

    1: #
    2: # $Id: lonwhatsnew.pm,v 1.68 2007/02/27 22:16:02 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::Constants qw(:common :http);
   40: use Time::Local;
   41: use GDBM_File;
   42: use lib '/home/httpd/lib/perl/';
   43: use LONCAPA;
   44: 
   45: #----------------------------
   46: # handler
   47: #
   48: #----------------------------
   49: 
   50: sub handler {
   51:     my $r = shift;
   52:     if ($r->header_only) {
   53:         &Apache::loncommon::content_type($r,'text/html');
   54:         $r->send_http_header;
   55:         return OK;
   56:     }
   57:     &Apache::loncommon::get_unprocessed_cgi(
   58:                                    $ENV{'QUERY_STRING'},['command','refpage']);
   59: 
   60:     my $command = $env{'form.command'};
   61:     my $refpage = $env{'form.refpage'};
   62: 
   63:     my %checkallowed = ( coursenormalmail => 1,
   64: 			 coursecritmail => 1, );
   65:     foreach my $perm_check (['whn','whatsnew',1],
   66: 			    ['pch','coursediscussion',1],
   67: 			    ['mgr','handgrading',1],
   68: 			    ['vgr','abovethreshold',1],
   69: 			    ['opa','haserrors',1],
   70: 			    ['mdc','versionchanges',0],
   71: 			    ) {
   72: 	my ($perm,$key,$check_section) = @{ $perm_check };
   73: 	my $scope = $env{'request.course.id'};
   74: 	if (!($checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope))) {
   75: 	    $scope .= '/'.$env{'request.course.sec'};
   76: 	    if ( $check_section ) {
   77: 		$checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope);
   78: 	    }
   79: 	    if ($checkallowed{$key}) {
   80: 		$checkallowed{$key.'_section'} = $env{'request.course.sec'};
   81: 	    }
   82: 	}
   83:     }
   84: 
   85:     if ( ! $env{'request.course.fn'} || ! $checkallowed{'whatsnew'}) {
   86:         # Not in a course, or no whn priv in course
   87:         $env{'user.error.msg'}="/adm/whatsnew::whn:0:0:Cannot display what's new page";
   88:         return HTTP_NOT_ACCEPTABLE;
   89:     }
   90: 
   91:     &Apache::loncommon::content_type($r,'text/html');
   92:     $r->send_http_header;
   93: 
   94:     $r->print(&display_header($command,\%checkallowed));
   95: 
   96:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   97:     &Apache::lonhtmlcommon::add_breadcrumb
   98:             ({href=>'/adm/whatsnew',
   99:               text=>"Display Action Items"});
  100:     if (($command eq 'chgthreshold') && $checkallowed{'abovethreshold'}) {
  101:         &Apache::lonhtmlcommon::add_breadcrumb
  102:             ({href=>'/adm/whatsnew?command=chgthreshold&refpage='.$refpage,
  103:               text=>"Change thresholds"});
  104:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  105:             ("What's New?",#'Course_Action_Items_Thresholds'
  106: 	     ));
  107:     } elsif (($command eq 'chginterval') && $checkallowed{'versionchanges'} ) {
  108:         &Apache::lonhtmlcommon::add_breadcrumb
  109:             ({href=>'/adm/whatsnew?command=chginterval&refpage='.$refpage,
  110:               text=>"Change interval"});
  111:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  112:             ("What's New?",#'Course_Action_Items_Intervals'
  113: 	     ));
  114:     } elsif (($command eq 'chgdisc') && $checkallowed{'coursediscussion'}) {
  115:         &Apache::lonhtmlcommon::add_breadcrumb
  116:             ({href=>'/adm/whatsnew?command=chgdisc&refpage='.$refpage,
  117:               text=>"Change discussion display"});
  118:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  119:             ("What's New?",#'Course_Action_Items_Intervals'
  120: 	     ));
  121:     } elsif ($command eq 'courseinit') {
  122:         &Apache::lonhtmlcommon::add_breadcrumb
  123:             ({href=>'/adm/whatsnew?command=courseinit&refpage='.$refpage,
  124:               text=>"Course initialization preference"});
  125:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  126:             ("What's New?",#'Course_Action_Items_Initialization'
  127: 	     ));
  128:     } else {
  129:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  130:             ("What's New?",#'Course_Action_Items_Display'
  131: 	     ));
  132:     }
  133:     &display_main_box($r,$command,$refpage,\%checkallowed);
  134:     return OK;
  135: }
  136: 
  137: #------------------------------
  138: # display_main_box
  139: #
  140: # Display all the elements within the main box
  141: #------------------------------
  142:                                                                                 
  143: sub display_main_box {
  144:     my ($r,$command,$refpage,$checkallowed) = @_;
  145:     my $domain=&Apache::loncommon::determinedomain();
  146:     my $function = &Apache::loncommon::get_users_function();
  147:     my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
  148:     my $lctype = lc(&Apache::loncommon::course_type());
  149:     $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
  150: 
  151:     my %threshold_titles = &Apache::lonlocal::texthash (
  152:                          av_attempts => 'Average number of attempts',
  153:                          degdiff => 'Degree of difficulty',
  154:                          numstudents => 'Total number of students with submissions',
  155:     );
  156: 
  157:     my %interval_titles = &Apache::lonlocal::texthash (
  158:                             -1 => "since start of $lctype",
  159:                        2592000 => 'since last month',
  160:                         604800 => 'since last week',
  161:                          86400 => 'since yesterday',
  162:     );
  163: 
  164:     my %initpage = &Apache::lonlocal::texthash (
  165:                      firstres => "first resource in the $lctype",
  166:                      whatsnew => "what's new? page",
  167:                      userpref => 'your general user preferences',
  168:                      coursespecific => "specific setting for this $lctype",
  169:                    );
  170:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  171:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
  172: 
  173:     if (($command eq 'chgthreshold') 
  174: 	&& $checkallowed->{'abovethreshold'}) {
  175:         &display_threshold_config($r,$refpage,$tabbg,\%threshold_titles,
  176:                                                                    $cdom,$crs);
  177:     } elsif (($command eq 'chginterval') 
  178: 	     && $checkallowed->{'versionchanges'}) {
  179:         &display_interval_config($r,$refpage,\%interval_titles);
  180:     } elsif (($command eq 'chgdisc') 
  181: 	     && $checkallowed->{'coursediscussion'}) {
  182:         &display_discussion_config($r,$refpage);
  183:     } elsif ($command eq 'courseinit') {
  184:         &courseinit_config($r,$refpage,\%initpage);
  185:     } else {
  186:         &display_actions_box($r,$tabbg,$command,$refpage,\%threshold_titles,
  187:                         \%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
  188:     }
  189:     my $end_page = &Apache::loncommon::end_page();
  190:     $r->print(<<END_OF_BLOCK);
  191:   </td>
  192:  </tr>
  193: </table><br />
  194: $end_page
  195: END_OF_BLOCK
  196: }
  197: 
  198: #-------------------------------
  199: # display_header
  200: #
  201: # Display the header information and set
  202: # up the HTML
  203: #-------------------------------
  204: 
  205: sub display_header {
  206:     my ($command,$checkallowed) = @_;
  207:     
  208:     my $scripttag;
  209:     unless ($command eq 'chgthreshold' || $command eq 'chginterval') {
  210:        $scripttag = <<"END";
  211: <script type="text/javascript">
  212: function change_display(caller,change) {
  213:     caller.value = change;
  214:     document.visible.submit(); 
  215: }
  216: 
  217: function changeAll(change) {
  218: END
  219:         foreach my $item (keys(%{$checkallowed})) {
  220: 	    if ($item =~ /_section$/) { next; }
  221:             if ($$checkallowed{$item}) {
  222:                 $scripttag.='document.visible.display_'.$item.'.value=change'.
  223:                             "\n";
  224:             }
  225:         }
  226:         $scripttag.='document.visible.submit();
  227: }
  228: </script>
  229: ';
  230:     }
  231:     my $course_type=&Apache::loncommon::course_type();
  232:     return &Apache::loncommon::start_page($course_type.' Action Items',
  233: 					  $scripttag);
  234: }
  235: 
  236: #-------------------------------
  237: # display_actions_box
  238: #
  239: # Display the action items
  240: #
  241: #-------------------------------
  242:                                                                                 
  243: sub display_actions_box {
  244:     my ($r,$tabbg,$command,$refpage,$threshold_titles,$interval_titles,
  245:                                       $initpage,$cdom,$crs,$checkallowed) = @_;
  246:     my $udom = $env{'user.domain'};
  247:     my $uname = $env{'user.name'};
  248:     my $cid = $env{'request.course.id'};
  249:     my $crstype = &Apache::loncommon::course_type();
  250:     my $lctype = lc($crstype);
  251:     my %stulabel = (
  252:                     'Course' => 'students',
  253:                     'Group' => 'members',
  254:                    );
  255:     my %lt = &Apache::lonlocal::texthash(
  256:                  'yacc' => 'You are accessing an invalid course',
  257:                  'gtfr' => 'Go to first resource',
  258:                  'hial' => 'Hide all',
  259:                  'shal' => 'Show all',
  260:     );
  261: 
  262:     my %unread = ();
  263:     my %ungraded = ();
  264:     my %bombed = ();
  265:     my %triggered = ();
  266:     my %changed = ();
  267:     my @newmsgs = ();
  268:     my @critmsgs = ();
  269:     my @newdiscussions = ();
  270:     my @tograde = ();
  271:     my @bombs = ();
  272:     my @warnings = ();
  273:     my $msgcount = 0;
  274:     my $critmsgcount = 0;
  275: 
  276:     my %res_title = ();
  277:     my %show = ();
  278:     my $needitems = 0;
  279:     my $boxcount = 0;
  280: 
  281:     my $result;
  282:     if ($command eq 'newcourseinit') {
  283:         $result = &store_courseinit_setting($uname,$udom,$cid,$initpage);
  284:     }
  285: 
  286:     my %threshold = ();
  287:     my %pagedesc = &Apache::lonlocal::texthash (
  288:                      firstres => 'First resource',
  289:                      whatsnew => "What's New? page",
  290:                      userpref => 'user preference',
  291:                      coursespecific => $lctype.' only',
  292:                      default => 'default',
  293:                    );
  294: 
  295:     my ($initcontrol,$initdisp) = &curr_courseinit();
  296:     my $currinit = $pagedesc{$initdisp}.' ('.$pagedesc{$initcontrol}.')';
  297: 
  298:     unless ($cid) {
  299:         $r->print('<br /><b><center>'.$lt{'yacc'}.'</center></b><br /><br />');
  300:         return;
  301:     }
  302: 
  303:     if ($refpage eq 'start') {
  304:         if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
  305:             &GDBM_READER(),0640)) {
  306:             my $furl=$bighash{'first_url'};
  307:             untie(%bighash);
  308:             $r->print('<font size="+1"><a href="'.$furl.'">'.$lt{'gtfr'}.
  309:                   '</a></font><br />');
  310:         }
  311:     }
  312:     $r->print(&mt('Page set to be displayed after you have selected a role in this '.$lctype).
  313:               '. <nobr>'.&mt('Currently: <i>[_1]</i>',$currinit).'.&nbsp;&nbsp;'.
  314:               &mt('<b>Change</b> for just <a href="/adm/whatsnew?command=courseinit&refpage=[_1]">this '.$lctype.'</a>',$refpage).' '.
  315:               &mt('or for all <a href="/adm/preferences?action=changecourseinit&refpage=[_1]">your courses</a>',$refpage).'</nobr><br /><hr />');
  316: 
  317:     if ($command eq 'reset') {
  318:         $result = &process_reset($cdom,$crs);
  319:     } elsif ($command eq 'update') {
  320:         $result = &process_update($uname,$udom,$threshold_titles);
  321:     } elsif ($command eq 'newinterval') {
  322:         $result = &store_interval_setting($uname,$udom,$cid,$interval_titles);
  323:     } elsif ($command eq 'newdiscconf') {
  324:         $result = &store_discussion_setting($uname,$udom,$cid);
  325:     }
  326: 
  327:     my $store_result=&store_display_settings($uname,$udom,$cid,$checkallowed);
  328: 
  329:     unless ($store_result eq 'ok') { 
  330:         &Apache::lonnet::logthis('Error storing whatsnew settings: '.
  331:             $store_result.' for '.'user '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
  332:         $result .= &mt('Unable to store visibility settings due to [_1]',
  333:                        $store_result); 
  334:     }
  335: 
  336:     if ($result) {
  337:         $r->print($result.'<hr width="100%" />');
  338:     }
  339:     $r->rflush();
  340: 
  341: 
  342:     my %display_settings = &get_display_settings($uname,$udom,$cid);
  343:     my $timediff = $display_settings{$cid.':interval'};
  344:     unless (defined($timediff)) { $timediff = 604800; } 
  345:     my $now = time;
  346:     my $interval = $$interval_titles{$timediff};
  347:     if ($timediff == -1) {
  348:         $timediff = time;
  349:     } 
  350:     my $starttime = $now - $timediff;
  351:     my $countunread = $display_settings{$cid.':countunread'};
  352:     unless (defined($countunread)) {
  353:         $countunread = 'on';
  354:     }
  355: 
  356:     my %headings = &Apache::lonlocal::texthash(
  357:                 coursediscussion =>  'Unread '.$lctype.' discussion posts',
  358:                 handgrading =>  'Problems requiring handgrading',
  359:                 haserrors => 'Problems with errors',
  360:                 versionchanges => 'Resources in '.$lctype.' with version changes '.$interval,
  361:                 coursenormalmail => 'New '.$lctype.' messages',
  362:                 coursecritmail => 'New critical messages in '.$lctype,
  363:     );
  364: 
  365:     if ($$checkallowed{'abovethreshold'}) {
  366:         &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
  367:     }
  368: 
  369:     $headings{'abovethreshold'} = 
  370: 	&mt('Problems with av. attempts &ge; [_1] or deg. difficulty &ge; [_2] <br /> and total number of '.$stulabel{$crstype}.' with submissions &ge; [_3]',
  371: 	    $threshold{'av_attempts'},$threshold{'degdiff'},
  372: 	    $threshold{'numstudents'});
  373: 
  374:     my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail');
  375: 
  376:     foreach my $key (keys(%{$checkallowed})) {
  377: 	if ($key =~ /_section$/) { next; }
  378:         $show{$key} = 0;
  379:         if ($$checkallowed{$key}) {
  380:             unless ($display_settings{$cid.':'.$key} eq 'hide') {
  381:                 $show{$key} = 1;
  382:             }
  383:         }
  384:     }
  385: 
  386:     foreach my $item (@actionorder) {
  387:         unless ($item eq 'coursenormalmail' || $item eq 'coursecritmail') {
  388:             if ($show{$item}) {
  389:                 $needitems = 1;
  390:                 last;
  391:             }
  392:         }
  393:     }
  394: 
  395:     if ($needitems) {
  396:         &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread);
  397:     }
  398:     if ($show{'coursenormalmail'}) {
  399:         $msgcount = &getnormalmail(\@newmsgs);
  400:     }
  401:     if ($show{'coursecritmail'}) {
  402:         $critmsgcount = &getcritmail(\@critmsgs);
  403:     }
  404: 
  405:     $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
  406:      &nbsp;&nbsp;<a href="javascript:changeAll('show');">$lt{'shal'}</a>
  407:      <form method="post" name="visible" action="/adm/whatsnew">\n|);
  408:     foreach my $item (keys(%{$checkallowed})) {
  409: 	if ($item =~ /_section$/) { next; }
  410:         if ($$checkallowed{$item}) {
  411:             $r->print('<input type="hidden" name="display_'.$item.'" />'."\n");
  412:         }
  413:     }
  414: 
  415:     $r->print('<input type="hidden" name="refpage" value="'.$refpage.'"></form><br /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
  416: 
  417:     my $displayed = 0;
  418:     my $totalboxes = 0;
  419:     foreach my $key (keys(%{$checkallowed})) {
  420: 	if ($key =~ /_section$/) { next; }
  421: 	if ($key eq 'whatsnew' ) { next; } # whatsnew check creates no box
  422:         if ($$checkallowed{$key}) {
  423:             $totalboxes ++;
  424:         }
  425:     }
  426:     my $halfway = int($totalboxes/2) + $totalboxes%2;
  427:     foreach my $actionitem (@actionorder) {
  428:         if ($$checkallowed{$actionitem}) {
  429:             if ($displayed == $halfway) {
  430:                 $r->print('</td><td width="6%">&nbsp;</td><td align="left" valign="top" width="47%">');
  431:             }
  432:             &display_launcher($r,$actionitem,$refpage,$checkallowed,$tabbg,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,$interval,$countunread);
  433:             $displayed ++; 
  434:         }
  435:     }
  436:     $r->print('
  437:            </table>
  438:           </td>
  439:          </tr>
  440:         </table>
  441:       </td>
  442:     </tr>
  443:    </table>');
  444: }
  445: 
  446: #-------------------------------
  447: # display_threshold_config
  448: #
  449: # Display the threshold setting screen 
  450: #
  451: #-------------------------------
  452:                                                                                 
  453: sub display_threshold_config {
  454:     my ($r,$refpage,$tabbg,$threshold_titles,$cdom,$crs) = @_;
  455:     my $uname = $env{'user.name'};
  456:     my $udom = $env{'user.dom'};
  457:     my $cid = $env{'request.course.id'};
  458:     my %threshold = ();
  459:     my $rowColor1 = "#ffffff";
  460:     my $rowColor2 = "#eeeeee";
  461:     my $rowColor;
  462: 
  463:     my @thresholditems = ("av_attempts","degdiff","numstudents");
  464:     my %threshold_titles = &Apache::lonlocal::texthash(
  465:                          av_attempts => 'Average number of attempts',
  466:                          degdiff => 'Degree of difficulty',
  467:                          numstudents => 'Total number of students with submissions',
  468:                          );
  469:     &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
  470: 
  471:     $r->print('<br /><form name="thresholdform" method="post" action="/adm/whatsnew">'.
  472:               &Apache::loncommon::start_data_table().
  473:               &Apache::loncommon::start_data_table_header_row().
  474:              '<th>Threshold Name</th>'."\n".
  475:              '<th>Current value</th>'."\n".
  476:              '<th>Change?</th>'."\n".
  477:               &Apache::loncommon::end_data_table_header_row());
  478:     foreach my $type (@thresholditems) {
  479:         my $parameter = $env{'request.course.id'}.':threshold_'.$type;
  480: # onchange is javascript to automatically check the 'Set' button.
  481:         my $onchange = 'onFocus="javascript:window.document.forms'.
  482:               "['thresholdform'].elements['".$parameter."_setparmval']".
  483:               '.checked=true;"';
  484:         $r->print(&Apache::loncommon::start_data_table_row()."\n".
  485:                  '<td>'.$threshold_titles{$type}.'</td>'."\n".
  486:                  '<td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
  487:                                             $threshold{$type},
  488:                                             10,$onchange).'</td>'."\n".
  489:                  '<td>'.
  490:                  &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
  491:                  '</td>'."\n".
  492:                  &Apache::loncommon::end_data_table_row());
  493:     }
  494:     $r->print(&Apache::loncommon::end_data_table()."\n".
  495:           '<br /><input type="submit" name="threshold" value="Make changes" />
  496:                  <input type="hidden" name="command" value="update" />
  497:                  <input type="hidden" name="refpage" value="'.$refpage.'" />
  498:                </form>');
  499: }
  500: 
  501: #-------------------------------
  502: # display_interval_config
  503: #
  504: # Display the interval setting screen
  505: #
  506: #-------------------------------
  507:                                                                                    
  508: sub display_interval_config {
  509:     my ($r,$refpage,$interval_titles) = @_;
  510:     my $lctype = lc(&Apache::loncommon::course_type());
  511:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  512:                                 $env{'request.course.id'},'interval');
  513:     $r->print('<br />'.&mt('Choose the time window to use for display of version changes for resources in the '.$lctype.'.'));
  514:     unless ($current eq '') {
  515:         $r->print(' '.&mt('Current value is [_1]','<b>'.
  516:                   $$interval_titles{$current}.'</b>.'));
  517:     }
  518:     $r->print('<br /><br />
  519: <form method="post" name="intervalswitch" action="/adm/whatsnew">
  520: <input type="hidden" name="command" value="newinterval" />
  521: <input type="hidden" name="refpage" value="'.$refpage.'" />
  522: <select name="interval">
  523: ');
  524:     foreach my $key (reverse sort ({$a cmp $b} (keys(%{$interval_titles})))) {
  525:         $r->print('<option value="'.$key.'">Version changes '.$$interval_titles{$key}.
  526:                   '</option>'."\n");
  527:     }
  528:     $r->print('</select>&nbsp;&nbsp;
  529:                <input type="submit" name="display" value="'.
  530:                &mt('Change interval').'" /></form>');
  531:     return;
  532: }
  533: 
  534: #----------------------------------------------
  535: # display_discussion_config
  536: #
  537: # Display the discussion display setting screen
  538: #
  539: #----------------------------------------------
  540:                                                                                   
  541: sub display_discussion_config {
  542:     my ($r,$refpage) = @_;
  543:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  544:                                 $env{'request.course.id'},'countunread');
  545:     if ($current eq '') {
  546:         $current = 'on';
  547:     }
  548:     my %opposite = ( 
  549:                       'on' => 'off',
  550:                       'off' => 'on',
  551:                     );
  552:     $r->print('<script type="text/javascript">
  553: function toggle_countunread(choice) {
  554:     if (choice == "unchanged") {
  555:         document.discussionswitch.command.value = "";
  556:     }
  557:     document.discussionswitch.submit();
  558: }
  559: </script>');
  560:     $r->print('<br />'.&mt('Choose whether or not to display a count of the number of new posts for each resource or bulletin board which has unread posts.').'<br />'.&mt('This can increase the time taken to gather data for the [_1] page by a few seconds.',"<i>What's New?</i>").'&nbsp;&nbsp;'.&mt('Currently set to [_1].','<b>'.$current.'</b>'));
  561:     $r->print('<br /><br />
  562: <form method="post" name="discussionswitch" action="/adm/whatsnew">
  563: <input type="hidden" name="command" value="newdiscconf" />
  564: <input type="hidden" name="refpage" value="'.$refpage.'" />
  565: <input type="hidden" name="countunread" value="'.$opposite{$current}.'" />
  566: ');
  567:     $r->print('<br/>
  568:                <input type="button" name="display" value="'.
  569:                &mt('Change to [_1]',$opposite{$current}).'" 
  570:                onclick="javascript:toggle_countunread('."'change'".')" />
  571:                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;
  572:                <input type="button" name="nochange" value="'.
  573:                &mt("No change").'" 
  574:                onclick="javascript:toggle_countunread('."'unchanged'".')" />
  575:                </form>');
  576:     return;
  577: }
  578: 
  579: #---------------------------------------------------
  580: # courseinit_config
  581: #
  582: # Set page displayed when course loads after 
  583: # selecting a role in the course from the roles page. 
  584: #
  585: #---------------------------------------------------
  586: 
  587: sub courseinit_config {
  588:     my ($r,$refpage,$initpage) = @_;
  589:     my ($control,$current) = &curr_courseinit();
  590:     my @chgstate = ('userpref','coursespecific');
  591:     my @chgentry = ('firstres','whatsnew');
  592:     my $lctype = lc(&Apache::loncommon::course_type());
  593:     my %lt = &Apache::lonlocal::texthash(
  594:                              'chwp' => "Choose which page will be displayed when you enter this $lctype after selecting a role.",
  595:                              'cuva' => 'Current value is determined by',
  596:                              'anis' => 'and is set to display',
  597:                              'padc' => 'Page display controlled by',
  598:                              'chce' => 'Choose '.$lctype.' entry',
  599:                              'moce' => 'Modify '.$lctype.' entry',
  600:     );
  601:     $r->print(<<"END"); 
  602: <br />$lt{'chwp'}
  603: <br />$lt{'cuva'}: <b>
  604: $$initpage{$control}</b> $lt{'anis'} <b>
  605: $$initpage{$current}</b>.<br /><br />
  606: <form method="post" name="courseinitswitch" action="/adm/whatsnew">
  607: <input type="hidden" name="command" value="newcourseinit" />
  608: <input type="hidden" name="refpage" value="$refpage" />
  609: $lt{'padc'}:&nbsp;&nbsp;
  610: END
  611:     foreach my $choice (@chgstate) {
  612:         my $chkstring;
  613:         if ($choice eq $control) {
  614:             $chkstring = ' checked="checked" ';
  615:         }  
  616:         $r->print('<nobr><label><input type="radio" name="courseinit_control" value="'.
  617:                    $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
  618:                    '&nbsp;&nbsp;</label></nobr>');
  619:     }
  620:     $r->print('<br /><br />'.&mt('If').' '.$$initpage{'coursespecific'}.
  621:               ' - <br />'.$lt{'chce'}.": \n");
  622:     foreach my $choice (@chgentry) {
  623:         my $chkstring;
  624:         if (($choice eq $current) && ($control eq 'coursespecific')) {
  625:             $chkstring = ' checked="checked" ';
  626:         }
  627:         $r->print('<nobr><label><input type="radio" name="courseinit_page" value="'.
  628:                   $choice.'"'.$chkstring.'/>'.$$initpage{$choice}.
  629:                   '&nbsp;&nbsp;</label></nobr>');
  630:     }
  631:     $r->print('<br /><br /><input type="submit" name="display" value="'.
  632:                $lt{'moce'}.'" /></form>');
  633:     return;
  634: }
  635: 
  636: sub curr_courseinit {
  637:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  638:                                 $env{'request.course.id'},'courseinit');
  639:     my $control;
  640:     if ($current) {
  641:         $control = 'coursespecific';
  642:     } else {
  643:         $control = 'userpref';
  644:         my %userenv = &Apache::lonnet::get('environment',
  645:                                                       ['course_init_display']);
  646:         if (exists($userenv{'course_init_display'})) {
  647:             $current = $userenv{'course_init_display'};
  648:         }
  649:         unless ($current) {
  650:             $current = 'whatsnew';
  651:         }
  652:     }
  653:     return ($control,$current);
  654: }
  655: 
  656: sub display_launcher {
  657:     my ($r,$action,$refpage,$checkallowed,$tabbg,$show,$headings,$res_title,
  658:         $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered,
  659:         $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs,
  660:         $interval,$countunread) = @_;
  661: 
  662:     if ($$checkallowed{$action}) {
  663:         &start_box($r,$tabbg,$show,$headings,$action,$refpage,$action);
  664:         if ($$show{$action}) {
  665:             if ($action eq 'handgrading') {    # UNGRADED ITEMS
  666:                 &display_handgrade($r,$tograde,$ungraded);
  667:             } elsif ($action eq 'haserrors') { # BOMBS
  668:                 &display_haserrors($r,$bombs,$bombed,$res_title);
  669:             } elsif ($action eq 'versionchanges') { # VERSION CHANGES
  670:                 &display_versionchanges($r,$changed,$res_title,$interval);
  671:             } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
  672:                 &display_abovethreshold($r,$refpage,$warnings,$triggered,
  673: 					$res_title);
  674:             } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
  675:                 &display_coursediscussion($r,$newdiscussions,$unread,
  676:                                 $countunread,$res_title);
  677:             } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES
  678:                 &display_coursenormalmail($r,$msgcount,$newmsgs);
  679:             } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
  680:                 &display_coursecritmail($r,$critmsgcount,$critmsgs);
  681:             }
  682:         }
  683:         &end_box($r);
  684:     }
  685:     return;
  686: }
  687: 
  688: sub getitems {
  689:     my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions,
  690:         $tograde,$bombs,$warnings,$threshold,$cdom,$crs,$res_title,$show,
  691:         $starttime,$countunread) = @_;
  692:     my $navmap = Apache::lonnavmaps::navmap->new();
  693:     # force retrieve Resource to seed the part id cache we'll need it later
  694:     my @allres=$navmap->retrieveResources(undef,
  695:                      sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
  696:     my %resourcetracker;
  697:     my $discussiontime;
  698: 
  699: # Resource version changes
  700:     if ($$show{'versionchanges'}) {
  701:         &checkversions($cdom,$crs,$navmap,$changed,$starttime);
  702:     }
  703: 
  704:     if ($$show{'abovethreshold'}) {
  705:         %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',
  706:                                                                    $cdom,$crs);
  707:     }
  708: 
  709:     foreach my $resource (@allres) {
  710:         my $result = '';
  711:         my $applies = 0;
  712:         my $symb = $resource->symb();
  713:         %{$$bombed{$symb}} = ();
  714:         %{$$ungraded{$symb}} = ();
  715:         %{$$triggered{$symb}} = ();
  716:         $$triggered{$symb}{numparts} = 0;
  717:         if ($resource->encrypted()) {
  718:             $$triggered{$symb}{'enclink'} = $resource->link();
  719:             $$triggered{$symb}{'encsymb'} = $resource->shown_symb();
  720:         }
  721:         my $title = $resource->compTitle();
  722:         $$res_title{$symb} = $title;
  723:         my $ressymb = $resource->wrap_symb();
  724: 
  725: # Check if there are unread discussion postings
  726:         if ($$show{'coursediscussion'}) {
  727:             &check_discussions($resource,$symb,$ressymb,$title,
  728: 			       $newdiscussions,$unread,$countunread);
  729:         }
  730: 
  731: # Check for ungraded problems
  732:         if ($resource->is_problem()) {
  733:             if ($$show{'handgrading'}) {
  734:                 &check_handgraded($resource,$symb,$title,$cdom,$crs,$ungraded,
  735:                                                                      $tograde);
  736:             }
  737:         }
  738: 
  739: # Check for bombs
  740:         if ($$show{'haserrors'}) {
  741:             &check_bombed($resource,$symb,$title,$bombs,$bombed);
  742:         }
  743: 
  744: # Maxtries and degree of difficulty for problem parts, unless handgradeable
  745:         if ($$show{'abovethreshold'}) {  
  746:             &check_thresholds($resource,$symb,\%resourcetracker,
  747: 			      $triggered,$threshold,$warnings);
  748:         }
  749: 
  750:     }
  751: }
  752: 
  753: sub check_discussions {
  754:     my ($resource,$symb,$ressymb,$title,$newdiscussions,$unread,
  755: 	$countunread) = @_;
  756: 
  757:     if (!$resource->hasDiscussion()) { return; }
  758: 
  759:     %{$$unread{$ressymb}} = ();
  760:     $$unread{$ressymb}{'title'} = $title;
  761:     $$unread{$ressymb}{'symb'} = $symb;
  762:     if ($resource->encrypted()) {
  763:         $$unread{$ressymb}{'enclink'} = $resource->link();
  764:         $$unread{$ressymb}{'encsymb'} = $resource->shown_symb();
  765:     }
  766:     push(@{$newdiscussions}, $ressymb);
  767:     
  768:     $$unread{$ressymb}{'lastpost'} = $resource->last_post_time();
  769:     
  770:     if ($countunread eq 'on') {
  771: 	$$unread{$ressymb}{'unreadcount'} = 
  772:                             $resource->discussion_info('unread');
  773:     }
  774: }
  775: 
  776: sub check_handgraded {
  777:     my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_;
  778:     if ($resource->is_problem()) {
  779:         my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  780:         my $partlist=$resource->parts();
  781:         my $handgradeable;
  782:         foreach my $part (@$partlist) {
  783:             if ($resource->handgrade($part) eq 'yes') {
  784:                 $handgradeable=1; last;
  785:             }
  786:         }
  787:         if ($handgradeable) {
  788:             my @ungraded = &Apache::bridgetask::get_queue_symb_status(
  789:                                              'gradingqueue',$symb,$cdom,$cnum);
  790:             if (@ungraded > 0) {
  791:                 $$ungraded{$symb}{count} = scalar(@ungraded);
  792:                 $$ungraded{$symb}{title} = $title;
  793:                 if ($resource->encrypted()) {
  794:                     $$ungraded{$symb}{'enclink'} = $resource->link();
  795:                     $$ungraded{$symb}{'encsymb'} = $resource->shown_symb();
  796:                 }
  797:                 push(@{$tograde},$symb);
  798:             }
  799:         }
  800:     }
  801: }
  802: 
  803: sub check_bombed {
  804:     my ($resource,$symb,$title,$bombs,$bombed) = @_;
  805:     if ($resource->getErrors()) {
  806:         my $errors = $resource->getErrors();
  807:         $errors =~ s/^,//;
  808:         my @bombs = split(/,/, $errors);
  809:         my $errorcount = scalar(@bombs);
  810:         my $errorlink = '<a href="/adm/email?display='.
  811:                         &escape($bombs[0]).'">'.
  812:                         $title.'</a>';
  813:         $$bombed{$symb}{errorcount} = $errorcount;
  814:         $$bombed{$symb}{errorlink} = $errorlink;
  815:         push(@{$bombs}, $symb);
  816:     }
  817: }
  818: 
  819: sub check_thresholds {
  820:     my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings) = @_;
  821: # Compile maxtries and degree of difficulty for problem parts, unless handgradeable
  822:     my @parts = @{$resource->parts()};
  823:     my %stats;
  824:     my %lastreset = ();
  825:     my $warning = 0;
  826:     foreach my $part (@parts) {
  827:         if ($resource->handgrade($part) eq 'yes') {
  828:             next;
  829:         }
  830:         if ($resource->is_survey($part)) {
  831:             next;
  832:         }
  833:         %{$stats{$part}} = ();
  834:         my ($attempts,$users,$corrects,$degdiff,$av_attempts);
  835:         if (exists($$resourcetracker{$symb."\0".$part."\0attempts"})) {
  836:             $attempts = $$resourcetracker{$symb."\0".$part."\0attempts"};
  837:         }
  838:         if (exists($$resourcetracker{$symb."\0".$part."\0users"})) {
  839:             $users = $$resourcetracker{$symb."\0".$part."\0users"};
  840:         }
  841:         if (exists($$resourcetracker{$symb."\0".$part."\0correct"})) {
  842:             $corrects = $$resourcetracker{$symb."\0".$part."\0correct"};
  843:         }
  844:         if ($attempts > 0) {
  845:             $degdiff =  1 - ($corrects/$attempts);
  846:             $degdiff = sprintf("%.2f",$degdiff);
  847:         }
  848:         if ($users > 0) {
  849:             $av_attempts = $attempts/$users;
  850:             $av_attempts = sprintf("%.2f",$av_attempts);
  851:         }
  852:         if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
  853:             $stats{$part}{degdiff} = $degdiff;
  854:             $stats{$part}{attempts} = $av_attempts;
  855:             $stats{$part}{users} = $users;
  856:             $lastreset{$part} = $$resourcetracker{$symb."\0".$part."\0resettime"};
  857:             if ($lastreset{$part}) {
  858:                 $lastreset{$part} = &Apache::lonnavmaps::timeToHumanString($lastreset{$part});
  859:             }
  860:             $warning = 1;
  861:         }
  862:     }
  863:     if ($warning) {
  864:         $$triggered{$symb}{title} = $resource->title;
  865:         my $partcount = 0;
  866:         @{$$triggered{$symb}{text}} = ();
  867:         foreach my $part (@parts) {
  868:             if (exists($stats{$part}{users})) {
  869:                 my $resetname = 'reset_'.&escape($symb."\0".$part);
  870:                 my $resettitle = 'title_'.&escape($symb."\0".$part);
  871:                 if (@parts > 1) {
  872:                     $$triggered{$symb}{text}[$partcount] = '
  873:                      <td>part - '.$part.'</td>';
  874:                 } else {
  875:                     $$triggered{$symb}{text}[$partcount] = '
  876:                      <td>single part</td>';
  877:                 }
  878:                 $$triggered{$symb}{text}[$partcount] .= '
  879:                      <td>'.$stats{$part}{users}.'</td>
  880:                      <td>'.$stats{$part}{attempts}.'</td>
  881:                      <td>'.$stats{$part}{degdiff}.'</td>
  882:                      <td>'.$lastreset{$part}.'</td>
  883:                      <td><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&escape($$triggered{$symb}{title}).'" /></td>';
  884:                 $partcount ++;
  885:             }
  886:             $$triggered{$symb}{numparts} = $partcount;
  887:         }
  888:         push(@{$warnings},$symb);
  889:     }
  890: }
  891: 
  892: 
  893: sub get_curr_thresholds {
  894:     my ($threshold,$uname,$udom,$cid,$cdom,$crs) = @_;
  895:     # set default values
  896:     %$threshold = (av_attempts => 2,
  897:                   degdiff => 0.5,
  898:                   numstudents => 2
  899:                   );
  900:     my %thresholdsettings = &Apache::lonnet::dump('nohist_whatsnew',$udom,
  901:                                                      $uname,$cid.':threshold');
  902:     my $thresholdcount = 0;
  903:     my ($tmp) = %thresholdsettings;
  904:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
  905:         foreach my $item (keys %{$threshold}) { 
  906:             if (exists($thresholdsettings{$cid.':threshold_'.$item})) {
  907:                 $$threshold{$item} = 
  908:                              $thresholdsettings{$cid.':threshold_'.$item};
  909:                 $thresholdcount ++;
  910:             }
  911:         }
  912:     }
  913:     if ($thresholdcount == 3) {
  914:         return;
  915:     }
  916:     my %coursesettings = &Apache::lonnet::dump('environment',
  917:                                               $cdom,$crs,'internal.threshold');
  918:     my ($temp) = %coursesettings;
  919:     unless ($temp =~ /^(con_lost|error|no_such_host)/i) {  
  920:         foreach my $item (keys %{$threshold}) {
  921:             unless (exists($thresholdsettings{$cid.':threshold_'.$item})) {
  922:                 if (exists($coursesettings{'internal.threshold_'.$item})) {
  923:                     $$threshold{$item} = 
  924:                              $coursesettings{'internal.threshold_'.$item};
  925:                 }
  926:             }
  927:         }
  928:     }
  929:     return;
  930: }
  931: 
  932: sub get_current {
  933:     my ($uname,$udom,$cid,$caller) = @_;
  934:     my $currvalue;
  935:     my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid.
  936:                                                                 ':'.$caller);
  937:     my ($tmp) = %settings;
  938:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
  939:         $currvalue = $settings{$cid.':'.$caller};
  940:     }
  941:     return $currvalue;
  942: }
  943: 
  944: sub process_reset {
  945:     my ($dom,$crs) = @_;
  946:     my $result = '<b>'.&mt('Counters reset for following problems (and parts):').
  947:                            '</b><br />';
  948:     my @agg_types = ('attempts','users','correct');
  949:     my %agg_titles = &Apache::lonlocal::texthash (
  950:                      attempts => 'Number of submissions',
  951:                      users => 'Students with submissions',
  952:                      correct => 'Number of correct submissions',
  953:                      );
  954:     my @resets = ();
  955:     my %titles = ();
  956:     foreach my $key (keys(%env)) {
  957:         next if ($key !~ /^form\.reset_(.+)$/);
  958:         my $title = &unescape($env{'form.title_'.$1});
  959:         my $reset_item = &unescape($1);
  960:         my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
  961:         my %aggregates = ();
  962:         my ($symb,$part) = split(/\0/,$reset_item);
  963:         foreach my $type (@agg_types) {
  964:             $aggregates{$reset_item."\0".$type} = 0;
  965:         }  
  966: 	$aggregates{$reset_item."\0".'resettime'} = time;
  967:         my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
  968:                           $dom,$crs);
  969:         if ($putresult eq 'ok') {
  970:             $result .= $title.' -part '.$part.': ';
  971:             my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
  972:             foreach my $type (@agg_types) {
  973:                 $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
  974:             }
  975:             $result =~ s/; $//;
  976:             $result .= '<br />';
  977:         } else {
  978:             $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
  979:         }
  980:     }
  981:     return $result;
  982: }
  983: 
  984: sub process_update {
  985:     my ($uname,$udom,$threshold_titles) = @_;
  986:     my $setoutput = '<b>Changes to threshold(s) for problem tracking:</b><br />';
  987:     foreach (keys %env) {
  988:         next if ($_!~/^form\.(.+)\_setparmval$/);
  989:         my $name  = $1;
  990:         my $value = $env{'form.'.$name.'_value'};
  991:         if ($name && defined($value) && ($value ne '')) {
  992:             my $put_result = &Apache::lonnet::put('nohist_whatsnew',
  993:                                                   {$name=>$value},$udom,$uname);
  994:            
  995:             my ($shortname) = ($name =~ /^\Q$env{'request.course.id'}\E:threshold_(.+)$/);
  996:             if ($put_result eq 'ok') {
  997:                 $setoutput.=&mt('Set threshold for [_1] to [_2]',
  998: 				'<b>'.$$threshold_titles{$shortname}.'</b>',
  999: 				'<b>'.$value.'</b>').'<br />';
 1000: 	    } else {
 1001:                 $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
 1002: 				'<b>'.$name.'</b>','<b>'.$value.'</b>',
 1003: 				'<tt>'.$put_result.'</tt>').'<br />';
 1004:             }
 1005:         }
 1006:     }
 1007:     return $setoutput;
 1008: }
 1009: 
 1010: sub getnormalmail {
 1011:     my ($newmsgs) = @_;
 1012: # Check for unread mail in course
 1013:     my $msgcount = 0;
 1014: 
 1015:     my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
 1016:     foreach my $message (@messages) {
 1017: 	my $msgid=&escape($message);
 1018:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 1019:             &Apache::lonmsg::unpackmsgid($msgid);
 1020:         if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
 1021:             if (defined($sendtime) && $sendtime!~/error/) {
 1022:                 my $numsendtime = $sendtime;
 1023:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
 1024:                 if ($status eq 'new') {
 1025:                     $msgcount ++;
 1026:                     if ($shortsubj eq '') {
 1027:                         $shortsubj = &mt('No subject');
 1028:                     }
 1029:                     push(@{$newmsgs}, {
 1030:                         msgid    => $msgid,
 1031:                         sendtime => $sendtime,
 1032:                         shortsub => $shortsubj,
 1033:                         from     => $fromname,
 1034:                         fromdom  => $fromdom
 1035:                         });
 1036:                 }
 1037:             }
 1038:         }
 1039:     }
 1040:     return $msgcount;
 1041: }
 1042: 
 1043: sub getcritmail {
 1044:     my ($critmsgs) = @_; 
 1045: # Check for critical messages in course
 1046:     my %what=&Apache::lonnet::dump('critical');
 1047:     my $result = '';
 1048:     my $critmsgcount = 0;
 1049:     foreach my $msgid (sort(keys(%what))) {
 1050:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 1051:             &Apache::lonmsg::unpackmsgid($msgid);
 1052:         if (($fromcid) && ($fromcid eq  $env{'request.course.id'})) {
 1053:             if (defined($sendtime) && $sendtime!~/error/) {
 1054:                 my $numsendtime = $sendtime;
 1055:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
 1056:                 $critmsgcount ++;
 1057:                 if ($shortsubj eq '') {
 1058:                     $shortsubj = &mt('No subject');
 1059:                 }
 1060:                 push(@{$critmsgs}, {
 1061:                         msgid    => $msgid,
 1062:                         sendtime => $sendtime,
 1063:                         shortsub => $shortsubj,
 1064:                         from     => $fromname,
 1065:                         fromdom  => $fromdom
 1066:                         });
 1067:             }
 1068:         }
 1069:     }
 1070:     return $critmsgcount;
 1071: }
 1072: 
 1073: 
 1074: sub checkversions {
 1075:     my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
 1076:     my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
 1077:     my ($tmp) = keys(%changes);
 1078:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1079:         if (keys(%changes) > 0) {
 1080:             foreach my $key (sort(keys(%changes))) {
 1081:                 if ($changes{$key} > $starttime) {
 1082:                     my $version;
 1083:                     my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
 1084:                     my $currentversion=&Apache::lonnet::getversion($key);
 1085:                     my $revdate = 
 1086:                           &Apache::lonnet::metadata($root.'.'.$extension,
 1087:                                                      'lastrevisiondate');
 1088:                     $revdate =  &Apache::lonlocal::locallocaltime($revdate);
 1089:                     my $linkurl=&Apache::lonnet::clutter($key);
 1090:                     my $usedversion=$navmap->usedVersion('version_'.$linkurl);
 1091:                     my @resources = $navmap->getResourceByUrl($linkurl,1);
 1092:                     if (($usedversion) && ($usedversion ne 'mostrecent')) {
 1093:                         $version = $usedversion;     
 1094:                     } else {
 1095:                         $version = $currentversion;
 1096:                     }
 1097:                     foreach my $res (@resources) {
 1098:                          if (ref($res) eq 'Apache::lonnavmaps::resource') { 
 1099:                             my $symb = $res->symb();
 1100:                             %{$$changed{$symb}} = (
 1101:                                                 current => $currentversion,
 1102:                                                 version => $version,
 1103:                                                 revdate => $revdate,
 1104:                             );
 1105:                         }
 1106:                     }
 1107:                 }
 1108:             }
 1109:         }
 1110:     }
 1111:     return;
 1112: }
 1113: 
 1114: sub display_handgrade {
 1115:     my ($r,$tograde,$ungraded) = @_;
 1116:     my %lt = &Apache::lonlocal::texthash(
 1117:                         'prna' => 'Problem Name',
 1118:                         'nmun' => 'Number ungraded',
 1119:                         'nopr' => 'No problems require handgrading',
 1120:     );
 1121:     if (@{$tograde} > 0) {
 1122:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1123:                   $lt{'prna'}.'</td><td class="LC_right_item">'.
 1124:                   $lt{'nmun'}.'</td></tr>');
 1125:         my $rowNum = 0;
 1126:         foreach my $res (@{$tograde}) {
 1127:             $rowNum ++;
 1128:             my $css_class = $rowNum%2?' class="LC_odd_row"':'';
 1129:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
 1130:             my $linkurl=&Apache::lonnet::clutter($url);
 1131:             $linkurl .= '?symb='.&escape($res);
 1132:             if ($$ungraded{$res}{'enclink'}) {
 1133:                 $linkurl = 
 1134:                     $$ungraded{$res}{'enclink'}.'?symb='.$$ungraded{$res}{'encsymb'};
 1135:             } 
 1136:             $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.$$ungraded{$res}{title}.'</a></td><td class="LC_right_item">'.$$ungraded{$res}{count}.'</td></tr>');
 1137:         }
 1138:     } else {
 1139:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
 1140:     }
 1141: }
 1142: 
 1143: sub display_haserrors {
 1144:     my ($r,$bombs,$bombed,$res_title) = @_;
 1145:     my $bombnum = 0;
 1146:     my %lt = &Apache::lonlocal::texthash(
 1147:                                    reso => 'Resource',
 1148:                                    nmer => 'Number of errors',
 1149:                                    noer => 'No problems with errors',
 1150:     );
 1151:     if (@{$bombs} > 0) {
 1152:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1153:                   $lt{'reso'}.'</td><td class="LC_right_item">'.
 1154:                   $lt{'nmer'}.'</td></tr>');
 1155:         @{$bombs} = sort { &cmp_title($a,$b,$res_title) } @{$bombs};
 1156:         foreach my $bomb (@{$bombs}) {
 1157:             $bombnum ++;
 1158:             my $css_class = $bombnum%2?' class="LC_odd_row"':'';
 1159:             $r->print('<tr'.$css_class.'><td>'.$$bombed{$bomb}{errorlink}.
 1160:                       '</td><td class="LC_right_item">'.
 1161:                       $$bombed{$bomb}{errorcount}.'</td></tr>');
 1162:         }
 1163:     } else {
 1164:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'noer'}.'</td></tr>');
 1165:     }
 1166:     return;
 1167: }
 1168: 
 1169: sub display_abovethreshold {
 1170:     my ($r,$refpage,$warnings,$triggered,$res_title) = @_;
 1171:     my %lt = &Apache::lonlocal::texthash(
 1172:                  reso => 'Resource',
 1173:                  part => 'Part',
 1174:                  nust => 'Num. students',
 1175:                  avat => 'Av. Attempts',
 1176:                  dedi => 'Deg. Diff',
 1177:                  lare => 'Last Reset',
 1178:                  reco => 'Reset Count?',
 1179:                  rese => 'Reset counters to 0',
 1180:                  nopr => 'No problems satisfy threshold criteria',
 1181:     );
 1182:     if (@{$warnings} > 0) {
 1183:         @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
 1184:         $r->print('<form name="reset_tracking" method="post" action="/adm/whatsnew">'.
 1185:                 ' <input type="hidden" name="command" value="reset" />'."\n".
 1186:                 ' <input type="hidden" name="refpage" value="'.$refpage.'" />'.
 1187:                 "\n");
 1188:         $r->print('<tr class="LC_info_row">'.
 1189: 		  '<td class="LC_left_item">'.$lt{'reso'}.'</td>'.
 1190: 		  '<td>'.$lt{'part'}.'</td><td>'.$lt{'nust'}.'</td>'.
 1191: 		  '<td>'.$lt{'avat'}.'</td><td>'.$lt{'dedi'}.'</td>'.
 1192: 		  '<td>'.$lt{'lare'}.'</td><td  class="LC_right_item">'.
 1193:                   $lt{'reco'}.'</td></tr>');
 1194: 	my $row;
 1195:         foreach my $res (@{$warnings}) {
 1196: 	    $row++;
 1197:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
 1198:             my $linkurl=&Apache::lonnet::clutter($url);
 1199:             my $rowspan;
 1200:             if ($$triggered{$res}{numparts} > 1) {
 1201:                 $rowspan = 'rowspan="'.$$triggered{$res}{numparts}.'"';
 1202:             }
 1203:             $linkurl .= '?symb='.&escape($res);
 1204:             if ($$triggered{$res}{'enclink'}) {
 1205:                 $linkurl = 
 1206:                   $$triggered{$res}{'enclink'}.'?symb='.$$triggered{$res}{'encsymb'};
 1207:             }
 1208:             my $css_class = $row%2?' class="LC_odd_row"':'';
 1209:             $r->print('<tr'.$css_class.'>'.
 1210: 		      '<td class="LC_first_item" '.$rowspan.'><a href="'.$linkurl.'">'.
 1211: 		      $$triggered{$res}{title}.'</a></td>');
 1212:                       if (ref($$triggered{$res}{text}) eq 'ARRAY') {
 1213: 		          $r->print($$triggered{$res}{text}[0]);
 1214:                       }
 1215:                       $r->print('</tr>');
 1216:             if (ref($$triggered{$res}{text}) eq 'ARRAY') {
 1217:                 if (@{$$triggered{$res}{text}} > 1) {
 1218:                     for (my $i=1; $i<@{$$triggered{$res}{text}}; $i++) {
 1219:                         $r->print('<tr class="'.$css_class.'">'.
 1220:                                   $$triggered{$res}{text}[$i].'</tr>');
 1221:                     }
 1222:                 }
 1223:             }
 1224:         }
 1225:         $r->print('<tr class="LC_info_row"><td colspan="7" class="LC_right_item"><br /><input type="submit" name="counters" value="'.$lt{'rese'}.'" /></td></tr></form>');
 1226:     } else {
 1227:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'nopr'}.'</td></tr>');
 1228:     }
 1229: }
 1230: 
 1231: sub display_versionchanges {
 1232:     my ($r,$changed,$res_title,$interval) = @_;
 1233:     my %lt = &Apache::lonlocal::texthash(
 1234:         'reso' => 'Resource',
 1235:         'revd' => 'Last revised',
 1236:         'newv' => 'New version',
 1237:         'veru' => 'Version used',
 1238:         'noup' => 'No updated versions', 
 1239:     );
 1240:     if (keys(%{$changed}) > 0) {
 1241:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1242:                   $lt{'reso'}.'</td><td>'.$lt{'revd'}.'</td><td>'.
 1243:                   $lt{'newv'}.'</td><td class="LC_right_item">'.
 1244:                   $lt{'veru'}.'</td></tr>');
 1245:         my @changes = sort { &cmp_title($a,$b,$res_title) } keys(%{$changed});
 1246:         my $changenum = 0;
 1247:         foreach my $item (@changes) {
 1248:             $changenum ++;
 1249:             my $css_class = $changenum%2?' class="LC_odd_row"':'';
 1250:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($item);
 1251:             my $linkurl=&Apache::lonnet::clutter($url);
 1252:             $linkurl .= '?symb='.&escape($item);
 1253: 
 1254:             $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.
 1255:                       $$res_title{$item}.'</a></td><td>'.
 1256:                       $$changed{$item}{'revdate'}.'</td><td>'.
 1257:                       $$changed{$item}{'current'}.'</td><td>'.
 1258:                       $$changed{$item}{'version'}.'</td></tr>');
 1259:         }
 1260:     } else {
 1261:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'noup'}.
 1262:                   ' '.$interval.'</td></tr>');
 1263:     }
 1264:     return;
 1265: }
 1266:  
 1267: sub display_coursediscussion {
 1268:     my ($r,$newdiscussions,$unread,$countunread,$res_title) = @_;
 1269:     my $lctype = lc(&Apache::loncommon::course_type());
 1270:     my %lt = &Apache::lonlocal::texthash(
 1271:                 'loca' => 'Location',
 1272:                 'type' => 'Type',
 1273:                 'numn' => 'Number of new posts',
 1274:                 'noun' => 'No unread posts in '.$lctype.' discussions',
 1275:                 'tmlp' => 'Time of last post', 
 1276:     );
 1277:     if (@{$newdiscussions} > 0) {
 1278:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1279:                   $lt{'loca'}.'</td><td>'.
 1280:                   $lt{'type'}.'</td>');
 1281:         if ($countunread eq 'on') {
 1282:             $r->print('<td>'.$lt{'tmlp'}.'</td>'.
 1283:                       '<td class="LC_right_item">'.$lt{'numn'}.'</td>');
 1284:         } else {
 1285:             $r->print('<td class="LC_right_item">'.$lt{'tmlp'}.'</td>');
 1286:         }
 1287:         $r->print("</tr>\n");
 1288:         @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) }
 1289:                                                             @{$newdiscussions};
 1290:         my $rowNum = 0;
 1291:         foreach my $ressymb (@{$newdiscussions}) {
 1292:             $rowNum ++;
 1293:             my $forum_title = $$unread{$ressymb}{'title'};
 1294:             my $type = 'Resource';
 1295:             my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
 1296:             my $disclink = $feedurl.'?symb='.$$unread{$ressymb}{symb};
 1297:             if ($feedurl =~ /bulletinboard/) {
 1298:                 $type = 'Bulletin Board';
 1299:             }
 1300:             if ($$unread{$ressymb}{'enclink'}) {
 1301:                 $disclink = $$unread{$ressymb}{'enclink'}.'?symb='.$$unread{$ressymb}{'encsymb'};
 1302:             }
 1303:             my $css_class = $rowNum%2?' class="LC_odd_row"':'';
 1304:             my $lastpost = &Apache::lonnavmaps::timeToHumanString(
 1305:                                                $$unread{$ressymb}{'lastpost'});
 1306:             $r->print('<tr'.$css_class.'><td><a href="'.$disclink.'">'.$forum_title.'</a>&nbsp;</td><td>'.$type.'&nbsp;</td>');
 1307:             if ($countunread eq 'on') {
 1308:                 my $unreadnum = $$unread{$ressymb}{'unreadcount'};
 1309:                 $r->print('<td>'.$lastpost.'</td><td class="LC_right_item">'.
 1310:                           $unreadnum.'&nbsp;</td>');
 1311:             } else {
 1312:                 $r->print('<td class="LC_right_item">'.$lastpost.'</td>');
 1313:             }
 1314:             $r->print("</tr>\n");
 1315:         }
 1316:     } else {
 1317:         $r->print('<tr class="LC_empty_row"><td>'.$lt{'noun'}.'</td></tr>');
 1318:     }
 1319: }
 1320: 
 1321: sub display_coursenormalmail {
 1322:     my ($r,$msgcount,$newmsgs) = @_;
 1323:     my $lctype = lc(&Apache::loncommon::course_type());
 1324:     if ($msgcount > 0) {
 1325:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1326:                   &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
 1327:                   &mt('Sender').'</td><td class="LC_right_item">'.
 1328:                   &mt('Date/Time').'</td></tr>');
 1329:         my $mailcount = 0;
 1330:         foreach my $msg (@{$newmsgs}) {
 1331:             $mailcount ++;
 1332:             my $css_class = $mailcount%2?' class="LC_odd_row"':'';
 1333:             $r->print('<tr'.$css_class.'><td>'.$mailcount.
 1334:                       '. &nbsp;</td><td><a href="/adm/communicate">'.
 1335:                       $msg->{'shortsub'}.'</a>&nbsp; &nbsp;</td><td>&nbsp;'.
 1336:                       $msg->{'from'}.'@'.$msg->{'fromdom'}.'&nbsp;</td><td>'.
 1337:                       $msg->{'sendtime'}.'</td></tr>');
 1338:         }
 1339:     } else {
 1340:         $r->print('<tr class="LC_empty_row"><td>'.
 1341:                   &mt('No new '.$lctype.' messages').'</td></tr>');
 1342:     }
 1343: }
 1344: 
 1345: sub display_coursecritmail {
 1346:     my ($r,$critmsgcount,$critmsgs) = @_;
 1347:     my $lctype = lc(&Apache::loncommon::course_type());
 1348:     if ($critmsgcount > 0) {
 1349:         $r->print('<tr class="LC_info_row"><td class="LC_left_item">'.
 1350:                   &mt('Number').'</td><td>'.&mt('Subject').'</td><td>'.
 1351:                   &mt('Sender').'</td><td class="LC_right_item">'.
 1352:                   &mt('Date/Time').'</td></tr>');
 1353:         my $mailcount = 0;
 1354:         foreach my $msg (@{$critmsgs}) {
 1355:             $mailcount ++;
 1356:             my $css_class = $mailcount%2?' class="LC_odd_row"':'';
 1357:             $r->print('<tr'.$css_class.'><td>'.$mailcount.
 1358:                       '. &nbsp;</td><td><a href="/adm/email?folder=critical">'.
 1359:                       $msg->{'shortsub'}.'</a>&nbsp; &nbsp;</td><td>&nbsp;'.
 1360:                       $msg->{'from'}.'@'.$msg->{'fromdom'}.'&nbsp;</td><td>'.
 1361:                       $msg->{'sendtime'}.'</td></tr>');
 1362:         }
 1363:     } else {
 1364:         $r->print('<tr class="LC_empty_row"><td>'.
 1365:                   &mt('No unread critical messages in '.$lctype).
 1366:                   '</td></tr>');
 1367:     }
 1368: }
 1369: 
 1370: sub cmp_title {
 1371:     my ($a,$b,$res_title) = @_;
 1372:     my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
 1373:     $atitle=~s/^\s*//;
 1374:     $btitle=~s/^\s*//;
 1375:     return $atitle cmp $btitle;
 1376: }
 1377: 
 1378: sub get_display_settings {
 1379:     my ($uname,$udom,$cid) = @_;
 1380:     my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid); 
 1381:     my ($tmp) = keys(%settings);
 1382:     if ($tmp=~ /^(con_lost|error|no_such_host)/i) {
 1383:         %settings = ();
 1384:         unless ($tmp =~ /^error: 2 /) {
 1385: 	    my $lctype = lc(&Apache::loncommon::course_type());
 1386:             &Apache::lonnet::logthis('Error retrieving whatsnew settings: '.
 1387:             $tmp.' for '.$uname.':'.$udom.' for '.$lctype.': '.$cid);
 1388:         }
 1389:     }
 1390:     return %settings;
 1391: }
 1392: 
 1393: sub store_display_settings {
 1394:     my ($uname,$udom,$cid,$checkallowed) = @_;
 1395:     my %whatsnew_settings;
 1396:     my $result;
 1397:     foreach my $key (keys(%{$checkallowed})) {
 1398: 	if ($key =~ /_section$/) { next; }
 1399:         if (exists($env{'form.display_'.$key})) {
 1400:             unless ($env{'form.display_'.$key} eq '') {
 1401:                 $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key};
 1402:             }
 1403:         }
 1404:     }
 1405:     if (keys(%whatsnew_settings)) {
 1406:         $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings,
 1407:                                                                  $udom,$uname);
 1408:     } else {
 1409:         $result = 'ok';
 1410:     }
 1411:     return $result;
 1412: }
 1413: 
 1414: sub store_interval_setting {
 1415:     my ($uname,$udom,$cid,$interval_titles) = @_;
 1416:     my %interval_settings = ();
 1417:     my $result;
 1418:     if (defined($env{'form.interval'})) {
 1419:         $interval_settings{$cid.':interval'} = $env{'form.interval'};
 1420:         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 1421:                                              \%interval_settings,$udom,$uname);
 1422:         if ($outcome eq 'ok') {
 1423:             $result = &mt('Interval set to version changes [_1]',
 1424:                   '<b>'.$$interval_titles{$env{'form.interval'}}.'</b><br />');
 1425: 
 1426:         } else {
 1427: 	    my $lctype = lc(&Apache::loncommon::course_type());
 1428:             &Apache::lonnet::logthis('Error storing whatsnew interval setting'.
 1429:                 ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
 1430:             $result = &mt('Unable to set interval to [_1] due to [_2].',
 1431:                          '<b>'.$$interval_titles{$env{'form.interval'}}.'</b>',
 1432:                          '<tt>'.$outcome.'</tt>.<br />');
 1433:         }
 1434:     }
 1435:     return $result;
 1436: }
 1437: 
 1438: sub store_discussion_setting {
 1439:     my ($uname,$udom,$cid) = @_;
 1440:     my %discussion_settings;
 1441:     my $result;
 1442:     if (defined($env{'form.countunread'})) {
 1443:         $discussion_settings{$cid.':countunread'} = $env{'form.countunread'};
 1444:         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 1445:                                              \%discussion_settings,$udom,$uname);
 1446:         if ($outcome eq 'ok') {
 1447:             $result = &mt('Count unread posts in discussions display set to [_1]',
 1448:                   '<b>'.$env{'form.countunread'}.'</b><br />');
 1449:                                                                                   
 1450:         } else {
 1451: 	    my $lctype = lc(&Apache::loncommon::course_type());
 1452:             &Apache::lonnet::logthis('Error storing whatsnew countunread setting'.
 1453:                 ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
 1454:             $result = &mt('Unable to set "number unread posts display" to [_1]'.
 1455:                           ' due to [_2].',
 1456:                          '<b>'.$env{'form.countunread'}.'</b>',
 1457:                          '<tt>'.$outcome.'</tt>.<br />');
 1458:         }
 1459:     }
 1460:     return $result;
 1461: }
 1462: 
 1463: sub store_courseinit_setting {
 1464:     my ($uname,$udom,$cid,$initpage) = @_;
 1465:     my %courseinit_settings;
 1466:     my $page_control;
 1467:     my $result;
 1468:     if (defined($env{'form.courseinit_control'})) {
 1469:         if ($env{'form.courseinit_control'} eq 'userpref') {
 1470:             $courseinit_settings{$cid.':courseinit'} = '';
 1471:             $page_control = 'global preferences';
 1472:         } else {
 1473:             if (defined($env{'form.courseinit_page'})) {
 1474:                 $courseinit_settings{$cid.':courseinit'} = 
 1475:                                                   $env{'form.courseinit_page'};
 1476:                 $page_control = 'course specific setting';
 1477:             }
 1478:         }
 1479:         if ($page_control) {
 1480: 	    my $lctype = lc(&Apache::loncommon::course_type());
 1481:             my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 1482:                                            \%courseinit_settings,$udom,$uname);
 1483:             if ($outcome eq 'ok') {
 1484:                 if ($page_control eq 'global preferences') {
 1485:                     $result = &mt("Page displayed after role selection in $lctype now set by <b>user's global preferences</b>.");
 1486:                 } else {
 1487:                     $result = &mt('Page displayed after role selection in this '.$lctype.' set to <b>[_2]</b>',$lctype,$$initpage{$env{'form.courseinit_page'}});
 1488:                 }
 1489:             } else {
 1490:                 &Apache::lonnet::logthis('Error storing whatsnew courseinit '.
 1491:                                          'setting: '.$outcome.' for '.$uname.
 1492:                                          ':'.$udom.' in '.$lctype.' '.$cid);
 1493:                 if ($page_control eq 'global preferences') {
 1494:                     $result = &mt('Unable to set control of page display to [_1]'.
 1495:                           ' due to [_2].',
 1496:                          '<b>'.$page_control.'</b>',
 1497:                          '<tt>'.$outcome.'</tt>.<br />');
 1498:                 } else {
 1499:                     $result = &mt('Unable to set page display, after role selection, for this '.$lctype.' to <b>[_2]</b> due to <tt>[_3]</tt>.<br />',
 1500:                          $$initpage{$env{'form.courseinit_page'}},$outcome);
 1501:                 }
 1502:             }
 1503:         }
 1504:     }
 1505:     return $result;
 1506: }
 1507: 
 1508: sub start_box {
 1509:     my ($r,$tabbg,$show,$heading,$caller,$refpage) = @_;
 1510:     my %lt = &Apache::lonlocal::texthash( 
 1511:                        chth => 'Change thresholds?',
 1512:                        chin => 'Change interval?',
 1513:                        chop => 'Change options?',
 1514:     );
 1515:     my $showhide;
 1516:     if ($$show{$caller}) {
 1517:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 1518:                                'display_'.$caller.",'hide'".');">Hide</a></b>';
 1519:    
 1520:     } else {
 1521:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 1522:                                'display_'.$caller.",'show'".');">Show</a></b>';
 1523:     }
 1524:     
 1525:     $r->print('
 1526:          <table class="LC_nested_outer">
 1527:           <tr>
 1528:            <th>'.$$heading{$caller}.'</th>
 1529:            <th class="LC_right_item">'.$showhide.'</th>
 1530:           </tr>');
 1531:      if (($caller eq 'abovethreshold') && ($$show{$caller})) {
 1532:          if ($$show{$caller}) {
 1533:              $r->print('
 1534:               <tr>
 1535:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgthreshold&refpage='.$refpage.'">'.$lt{'chth'}.'</a></td>
 1536:               </tr>');
 1537:          }
 1538:      } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
 1539:          if ($$show{$caller}) {
 1540:              $r->print('
 1541:               <tr>
 1542:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chginterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
 1543:               </tr>');
 1544:          }
 1545:      } elsif ($caller eq 'coursediscussion') {
 1546:          if ($$show{$caller}) {
 1547:              $r->print('
 1548:               <tr>
 1549:                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
 1550:               </tr>');
 1551:          }
 1552:      }
 1553:     $r->print('
 1554:               <tr>
 1555:                <td colspan="2">
 1556:                 <table class="LC_nested">
 1557: ');
 1558:     return;
 1559: }
 1560: 
 1561: sub end_box {
 1562:     my ($r) = shift;
 1563:     $r->print('
 1564:    </table>
 1565:   </td>
 1566:  </tr>
 1567: </table><br />');
 1568:     return;
 1569: }
 1570: 
 1571: 1;

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