File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.59: download - view: text, annotated - select for diffs
Sat Jun 3 21:28:07 2006 UTC (18 years ago) by albertel
Branches: MAIN
CVS tags: version_2_1_99_0, HEAD
- switching to type accessor
- modified the use of mt args for course type

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

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