File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.56: download - view: text, annotated - select for diffs
Tue May 30 20:16:23 2006 UTC (18 years ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Adding thin veneer to support ANGEL-style groups.  Also modification to row colors for problems with multiple parts above critical values in thresholds display.

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

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