File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.47: download - view: text, annotated - select for diffs
Fri Jan 6 23:56:05 2006 UTC (18 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Eliminate radio buttons - less clicking to change display of count of unread.

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

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