File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.53: download - view: text, annotated - select for diffs
Sun Apr 23 04:04:38 2006 UTC (18 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- more properly hadle the bmsgiid subject (it is normally enocded then escaped, take care of undoing tat in the unpackmsgid now)

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

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