File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.44: download - view: text, annotated - select for diffs
Fri Jan 6 21:52:19 2006 UTC (18 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- checkallowed now also checks for section based priv
    - set <boxname>_section to section if priv is section scoped
- need to return HTTP_NOT_AUTHORIZED before sending the http headers

    1: #
    2: # $Id: lonwhatsnew.pm,v 1.44 2006/01/06 21:52:19 albertel Exp $
    3: #
    4: # Copyright Michigan State University Board of Trustees
    5: #
    6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    7: #
    8: # LON-CAPA is free software; you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation; either version 2 of the License, or
   11: # (at your option) any later version.
   12: #
   13: # LON-CAPA is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16: # GNU General Public License for more details.
   17: #
   18: # You should have received a copy of the GNU General Public License
   19: # along with LON-CAPA; if not, write to the Free Software
   20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21: #
   22: # /home/httpd/html/adm/gpl.txt
   23: #
   24: # http://www.lon-capa.org/
   25: #
   26: 
   27: 
   28: package Apache::lonwhatsnew;
   29: 
   30: use strict;
   31: use lib qw(/home/httpd/lib/perl);
   32: use Apache::lonnet;
   33: use Apache::loncommon();
   34: use Apache::lonhtmlcommon();
   35: use Apache::lonlocal;
   36: use Apache::loncoursedata();
   37: use Apache::lonnavmaps();
   38: use Apache::lonuserstate;
   39: use Apache::Constants qw(:common :http);
   40: use Time::Local;
   41: use GDBM_File;
   42: 
   43: #----------------------------
   44: # handler
   45: #
   46: #----------------------------
   47: 
   48: sub handler {
   49:     my $r = shift;
   50:     if ($r->header_only) {
   51:         &Apache::loncommon::content_type($r,'text/html');
   52:         $r->send_http_header;
   53:         return OK;
   54:     }
   55:     &Apache::loncommon::get_unprocessed_cgi(
   56:                                    $ENV{'QUERY_STRING'},['command','refpage']);
   57: 
   58:     my $command = $env{'form.command'};
   59:     my $refpage = $env{'form.refpage'};
   60: 
   61:     my %checkallowed = ( coursenormalmail => 1,
   62: 			 coursecritmail => 1, );
   63:     foreach my $perm_check (['whn','whatsnew',1],
   64: 			    ['pch','coursediscussion',1],
   65: 			    ['mgr','handgrading',1],
   66: 			    ['vgr','abovethreshold',1],
   67: 			    ['opa','haserrors',1],
   68: 			    ['mdc','versionchanges',0],
   69: 			    ) {
   70: 	my ($perm,$key,$check_section) = @{ $perm_check };
   71: 	my $scope = $env{'request.course.id'};
   72: 	if (!($checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope))) {
   73: 	    $scope .= '/'.$env{'request.course.sec'};
   74: 	    if ( $check_section ) {
   75: 		$checkallowed{$key} = &Apache::lonnet::allowed($perm,$scope);
   76: 	    }
   77: 	    if ($checkallowed{$key}) {
   78: 		$checkallowed{$key.'_section'} = $env{'request.course.sec'};
   79: 	    }
   80: 	}
   81:     }
   82: 
   83:     if ( ! $env{'request.course.fn'} || ! $checkallowed{'whatsnew'}) {
   84:         # Not in a course, or no whn priv in course
   85:         $env{'user.error.msg'}="/adm/whatsnew::whn:0:0:Cannot display what's new page";
   86:         return HTTP_NOT_ACCEPTABLE;
   87:     }
   88: 
   89:     &Apache::loncommon::content_type($r,'text/html');
   90:     $r->send_http_header;
   91: 
   92:     $r->print(&display_header($command,\%checkallowed));
   93: 
   94:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   95:     &Apache::lonhtmlcommon::add_breadcrumb
   96:             ({href=>'/adm/whatsnew',
   97:               text=>"Display Action Items"});
   98:     if (($command eq 'chgthreshold') && $checkallowed{'abovethreshold'}) {
   99:         &Apache::lonhtmlcommon::add_breadcrumb
  100:             ({href=>'/adm/whatsnew?command=chgthreshold&refpage='.$refpage,
  101:               text=>"Change thresholds"});
  102:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
  103:             (undef,"What's New?",'Course_Action_Items_Thresholds'));
  104:     } 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 %status = (
  568:                     on => 'checked="checked"',
  569:                     off => 'checked="checked"',
  570:                  );
  571:     $status{$current} = '';
  572:     $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>.");
  573:     $r->print('<br /><br />
  574: <form method="post" name="discussionswitch" action="/adm/whatsnew">'.
  575: &mt('Display of unread post counts?').'&nbsp;
  576: <input type="hidden" name="command" value="newdiscconf" />
  577: <input type="hidden" name="refpage" value="'.$refpage.'" />
  578: <input type ="radio" '.$status{'on'}.' name="countunread" value="on">on
  579: &nbsp;&nbsp;&nbsp;
  580: <input type ="radio" '.$status{'off'}.' name="countunread" value="off">off
  581: ');
  582:     $r->print('<br/><br />
  583:                <input type="submit" name="display" value="'.
  584:                &mt('Make changes').'" /></form>');
  585:     return;
  586: }
  587: 
  588: #---------------------------------------------------
  589: # courseinit_config
  590: #
  591: # Set page displayed when course loads after 
  592: # selecting a role in the course from the roles page. 
  593: #
  594: #---------------------------------------------------
  595: 
  596: sub courseinit_config {
  597:     my ($r,$refpage,$initpage) = @_;
  598:     my ($control,$current) = &curr_courseinit();
  599:     my @chgstate = ('userpref','coursespecific');
  600:     my @chgentry = ('firstres','whatsnew');
  601:     my %lt = &Apache::lonlocal::texthash(
  602:                              'chwp' => 'Choose which page will be displayed when you enter this course after selecting a role.',
  603:                              'cuva' => 'Current value is determined by',
  604:                              'anis' => 'and is set to display',
  605:                              'padc' => 'Page display controlled by',
  606:                              'chce' => 'Choose course entry',
  607:                              'moce' => 'Modify course entry',
  608:     );
  609:     $r->print(<<"END"); 
  610: <br />$lt{'chwp'}
  611: <br />$lt{'cuva'}: <b>
  612: $$initpage{$control}</b> $lt{'anis'} <b>
  613: $$initpage{$current}</b>.<br /><br />
  614: <form method="post" name="courseinitswitch" action="/adm/whatsnew">
  615: <input type="hidden" name="command" value="newcourseinit" />
  616: <input type="hidden" name="refpage" value="$refpage" />
  617: $lt{'padc'}&nbsp;&nbsp;
  618: END
  619:     foreach my $choice (@chgstate) {
  620:         $r->print('<nobr><input type="radio" name="courseinit_control" value="'.
  621:                    $choice.'"/>'.$$initpage{$choice}.'&nbsp;&nbsp;</nobr>');
  622:     }
  623:     $r->print('<br /><br />'.&mt('If').' '.$$initpage{'coursespecific'}.
  624:               '<br />'.$lt{'chce'}." \n");
  625:     foreach my $choice (@chgentry) {
  626:         $r->print('<nobr><input type="radio" name="courseinit_page" value="'.
  627:                   $choice.'"/>'.$$initpage{$choice}.'&nbsp;&nbsp;</nobr>');
  628:     }
  629:     $r->print('<br /><br /><input type="submit" name="display" value="'.
  630:                $lt{'moce'}.'" /></form>');
  631:     return;
  632: }
  633: 
  634: sub curr_courseinit {
  635:     my $current = &get_current($env{'user.name'},$env{'user.domain'},
  636:                                 $env{'request.course.id'},'courseinit');
  637:     my $control;
  638:     if ($current) {
  639:         $control = 'coursespecific';
  640:     } else {
  641:         $control = 'userpref';
  642:         my %userenv = &Apache::lonnet::get('environment',
  643:                                                       ['course_init_display']);
  644:         if (exists($userenv{'course_init_display'})) {
  645:             $current = $userenv{'course_init_display'};
  646:         }
  647:         unless ($current) {
  648:             $current = 'whatsnew';
  649:         }
  650:     }
  651:     return ($control,$current);
  652: }
  653: 
  654: sub display_launcher {
  655:     my ($r,$action,$refpage,$checkallowed,$tabbg,$rowColor1,$rowColor2,$show,
  656:         $headings,$res_title,$tograde,$ungraded,$bombs,$bombed,$changed,
  657:         $warnings,$triggered,$newdiscussions,$unread,$msgcount,$newmsgs,
  658:                           $critmsgcount,$critmsgs,$interval,$countunread) = @_;
  659: 
  660:     if ($$checkallowed{$action}) {
  661:         &start_box($r,$tabbg,$show,$headings,$action,$refpage);
  662:         if ($$show{$action}) {
  663:             if ($action eq 'handgrading') {    # UNGRADED ITEMS
  664:                 &display_handgrade($r,$tograde,$rowColor1,$rowColor2,
  665:                                                                     $ungraded);
  666:             } elsif ($action eq 'haserrors') { # BOMBS
  667:                 &display_haserrors($r,$bombs,$rowColor1,$rowColor2,$bombed,
  668:                                                                    $res_title);
  669:             } elsif ($action eq 'versionchanges') { # VERSION CHANGES
  670:                 &display_versionchanges($r,$changed,$res_title,$rowColor1,
  671:                                                          $rowColor2,$interval);
  672: 
  673:             } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
  674:                 &display_abovethreshold($r,$refpage,$warnings,$triggered,
  675:                                              $res_title,$rowColor1,$rowColor2);
  676:             } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
  677:                 &display_coursediscussion($r,$newdiscussions,$unread,
  678:                                 $countunread,$res_title,$rowColor1,$rowColor2);
  679:             } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES
  680:                 &display_coursenormalmail($r,$msgcount,$newmsgs,$rowColor1,
  681:                                                                    $rowColor2);
  682:             } elsif ($action eq 'coursecritmail') { # CRITICAL MESSAGES
  683:                 &display_coursecritmail($r,$critmsgcount,$critmsgs,$rowColor1,
  684:                                                                    $rowColor2);
  685:             }
  686:         }
  687:         &end_box($r);
  688:     }
  689:     return;
  690: }
  691: 
  692: sub getitems {
  693:     my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions,
  694:         $tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs,
  695:                                  $res_title,$show,$starttime,$countunread) = @_;
  696:     my $navmap = Apache::lonnavmaps::navmap->new();
  697:     # force retrieve Resource to seed the part id cache we'll need it later
  698:     my @allres=$navmap->retrieveResources(undef,
  699:                      sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
  700:     my %lastreadtime;
  701:     my %resourcetracker;
  702:     my $discussiontime;
  703: 
  704: # Resource version changes
  705:     if ($$show{'versionchanges'}) {
  706:         &checkversions($cdom,$crs,$navmap,$changed,$starttime);
  707:     }
  708: 
  709:     if ($$show{'coursediscussion'}) {   
  710:         my %lastread = &Apache::lonnet::dump('nohist_'.
  711:                         $env{'request.course.id'}.'_discuss',
  712:                         $env{'user.domain'},$env{'user.name'},'lastread');
  713:         foreach my $key (keys(%lastread)) {
  714:             my $newkey = $key;
  715:             $newkey =~ s/_lastread$//;
  716:             $lastreadtime{$newkey} = $lastread{$key};
  717:         }
  718:     }
  719:  
  720:     if ($$show{'abovethreshold'}) {
  721:         %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',
  722:                                                                    $cdom,$crs);
  723:     }
  724: 
  725:     my $warningnum = 0;
  726:     foreach my $resource (@allres) {
  727:         my $result = '';
  728:         my $applies = 0;
  729:         my $symb = $resource->symb();
  730:         %{$$bombed{$symb}} = ();
  731:         %{$$ungraded{$symb}} = ();
  732:         %{$$triggered{$symb}} = ();
  733:         $$triggered{$symb}{numparts} = 0;
  734:         my $title = $resource->compTitle();
  735:         $$res_title{$symb} = $title;
  736:         my $ressymb = $resource->wrap_symb();
  737: 
  738: # Check if there are unread discussion postings
  739:         if ($$show{'coursediscussion'}) {
  740:             &check_discussions($cdom,$crs,$resource,$symb,$ressymb,$title,
  741:                                                       $newdiscussions,$unread);
  742:         }
  743: 
  744: # Check for ungraded problems
  745:         if ($resource->is_problem()) {
  746:             if ($$show{'handgrading'}) {
  747:                 &check_handgraded($resource,$symb,$title,$cdom,$crs,$ungraded,
  748:                                                                      $tograde);
  749:             }
  750:         }
  751: 
  752: # Check for bombs
  753:         if ($$show{'haserrors'}) {
  754:             &check_bombed($resource,$symb,$title,$bombs,$bombed);
  755:         }
  756: 
  757: # Maxtries and degree of difficulty for problem parts, unless handgradeable
  758:         if ($$show{'abovethreshold'}) {  
  759:             &check_thresholds($resource,$symb,\%resourcetracker,$triggered,
  760:                        $threshold,$warnings,$warningnum,$rowColor1,$rowColor2);
  761:         }
  762: 
  763:     }
  764:     my $hasdiscussion = @{$newdiscussions};
  765:     if ($$show{'coursediscussion'} && $hasdiscussion) { # Get time of last post; 
  766:         $discussiontime = $navmap->{DISCUSSION_TIME};
  767:         foreach my $ressymb (@{$newdiscussions}) {
  768:             $$unread{$ressymb}{'lastpost'} = $$discussiontime{$ressymb};
  769:         }
  770:         if ($countunread eq 'on') { #Get count of unread postings for each resource 
  771:             my $discussiondata = $navmap->get_discussion_data();
  772:             foreach my $ressymb (@{$newdiscussions}) {
  773:                 &get_discussions($cdom,$crs,$discussiondata,$ressymb,
  774:                                                        $unread,\%lastreadtime);
  775:             }
  776:         }
  777:     }
  778: }
  779: 
  780: sub check_discussions {
  781:     my ($cdom,$crs,$resource,$symb,$ressymb,$title,$newdiscussions,
  782:                                                                  $unread) = @_;
  783:     if ($resource->hasDiscussion()) {
  784:         %{$$unread{$ressymb}} = ();
  785:         $$unread{$ressymb}{'title'} = $title;
  786:         $$unread{$ressymb}{'symb'} = $symb;
  787:         push(@{$newdiscussions}, $ressymb);
  788:     }
  789: }
  790: 
  791: sub get_discussions {
  792:     my ($cdom,$crs,$discussiondata,$ressymb,$unread,$lastreadtime) = @_;
  793:     my $prevread = 0;
  794:     my $unreadcount = 0;
  795:     if (defined($$lastreadtime{$ressymb})) {
  796:         $prevread = $$lastreadtime{$ressymb};
  797:     }
  798:     my $version = $$discussiondata{'version:'.$ressymb};
  799:     if ($version) {
  800:         my $hiddenflag = 0;
  801:         my $deletedflag = 0;
  802:         my ($hidden,$deleted);
  803:         for (my $id=$version; $id>0; $id--) {
  804:             my $vkeys=$$discussiondata{$id.':keys:'.$ressymb};
  805:             my @keys=split(/:/,$vkeys);
  806:             if (grep/^hidden$/,@keys) {
  807:                 unless ($hiddenflag) {
  808:                     $hidden = $$discussiondata{$id.':'.$ressymb.':hidden'};
  809:                     $hiddenflag = 1;
  810:                 }
  811:             } elsif (grep/^deleted$/,@keys) {
  812:                 unless ($deletedflag) {
  813:                     $deleted = $$discussiondata{$id.':'.$ressymb.':deleted'};
  814:                     $deletedflag = 1;
  815:                 }
  816:             } else {
  817:                 unless (($hidden =~/\.$id\./) || ($deleted =~/\.$id\./)) {
  818:                     if ($prevread <$$discussiondata{$id.':'.$ressymb.':timestamp'}) {
  819:                         $unreadcount ++;
  820:                         $$unread{$ressymb}{$unreadcount} = $id.': '.
  821:                                  $$discussiondata{$id.':'.$ressymb.':subject'};
  822:                     }
  823:                 }
  824:             }
  825:         }
  826:         $$unread{$ressymb}{'unreadcount'} = $unreadcount;
  827:     }
  828: }
  829: 
  830: 
  831: sub check_handgraded {
  832:     my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_;
  833:     if ($resource->is_problem()) {
  834:         my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  835:         my $partlist=$resource->parts();
  836:         my $handgradeable;
  837:         foreach my $part (@$partlist) {
  838:             if ($resource->handgrade($part) eq 'yes') {
  839:                 $handgradeable=1; last;
  840:             }
  841:         }
  842:         if ($handgradeable) {
  843:             my @ungraded = &Apache::bridgetask::get_queue_symb_status(
  844:                                              'gradingqueue',$symb,$cdom,$cnum);
  845:             if (@ungraded > 0) {
  846:                 $$ungraded{$symb}{count} = scalar(@ungraded);
  847:                 $$ungraded{$symb}{title} = $title;
  848:                 push(@{$tograde}, $symb);
  849:             }
  850:         }
  851:     }
  852: }
  853: 
  854: sub check_bombed {
  855:     my ($resource,$symb,$title,$bombs,$bombed) = @_;
  856:     if ($resource->getErrors()) {
  857:         my $errors = $resource->getErrors();
  858:         $errors =~ s/^,//;
  859:         my @bombs = split(/,/, $errors);
  860:         my $errorcount = scalar(@bombs);
  861:         my $errorlink = '<a href="/adm/email?display='.
  862:                         &Apache::lonnet::escape($bombs[0]).'">'.
  863:                         $title.'</a>';
  864:         $$bombed{$symb}{errorcount} = $errorcount;
  865:         $$bombed{$symb}{errorlink} = $errorlink;
  866:         push(@{$bombs}, $symb);
  867:     }
  868: }
  869: 
  870: sub check_thresholds {
  871:     my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings,
  872:                                        $warningnum,$rowColor1,$rowColor2) = @_;
  873: # Compile maxtries and degree of difficulty for problem parts, unless handgradeable
  874:     my @parts = @{$resource->parts()};
  875:     my %stats;
  876:     my %lastreset = ();
  877:     my $warning = 0;
  878:     my $rowColor;
  879:     foreach my $part (@parts) {
  880:         if ($resource->handgrade($part) eq 'yes') {
  881:             next;
  882:         }
  883:         %{$stats{$part}} = ();
  884:         my ($attempts,$users,$corrects,$degdiff,$av_attempts);
  885:         if (exists($$resourcetracker{$symb."\0".$part."\0attempts"})) {
  886:             $attempts = $$resourcetracker{$symb."\0".$part."\0attempts"};
  887:         }
  888:         if (exists($$resourcetracker{$symb."\0".$part."\0users"})) {
  889:             $users = $$resourcetracker{$symb."\0".$part."\0users"};
  890:         }
  891:         if (exists($$resourcetracker{$symb."\0".$part."\0correct"})) {
  892:             $corrects = $$resourcetracker{$symb."\0".$part."\0correct"};
  893:         }
  894:         if ($attempts > 0) {
  895:             $degdiff =  1 - ($corrects/$attempts);
  896:             $degdiff = sprintf("%.2f",$degdiff);
  897:         }
  898:         if ($users > 0) {
  899:             $av_attempts = $attempts/$users;
  900:             $av_attempts = sprintf("%.2f",$av_attempts);
  901:         }
  902:         if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
  903:             $stats{$part}{degdiff} = $degdiff;
  904:             $stats{$part}{attempts} = $av_attempts;
  905:             $stats{$part}{users} = $users;
  906:             $lastreset{$part} = $$resourcetracker{$symb."\0".$part."\0resettime"};
  907:             if ($lastreset{$part}) {
  908:                 $lastreset{$part} = &Apache::lonnavmaps::timeToHumanString($lastreset{$part});
  909:             }
  910:             $warning = 1;
  911:         }
  912:     }
  913:     if ($warning) {
  914:         if ($warningnum %2 == 1) {
  915:             $rowColor = $rowColor1;
  916:         } else {
  917:             $rowColor = $rowColor2;
  918:         }
  919:         $$triggered{$symb}{title} = $resource->title;
  920:         foreach my $part (@parts) {
  921:             if (exists($stats{$part}{users})) {
  922:                 my $resetname = 'reset_'.&Apache::lonnet::escape($symb."\0".$part);
  923:                 my $resettitle = 'title_'.&Apache::lonnet::escape($symb."\0".$part);
  924:                 if ($$triggered{$symb}{numparts}) {
  925:                     $$triggered{$symb}{text} .= '<tr bgcolor="'.$rowColor.'">'."\n";
  926:                 }
  927:                 if (@parts > 1) {
  928:                     $$triggered{$symb}{text} .= '
  929:                      <td align="right"><small>part - '.$part.'<small></td>';
  930:                 } else {
  931:                     $$triggered{$symb}{text} .= '
  932:                      <td align="right"><small>single part</small></td>';
  933:                 }
  934:                 $$triggered{$symb}{text} .= '
  935:                      <td align="right"><small>'.$stats{$part}{users}.'</small></td>
  936:                      <td align="right"><small>'.$stats{$part}{attempts}.'</small></td>
  937:                      <td align="right"><small>'.$stats{$part}{degdiff}.'</small></td>
  938:                      <td align="right"><small>'.$lastreset{$part}.'</small></td>
  939:                      <td align="right"><small><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&Apache::lonnet::escape($$triggered{$symb}{title}).'" /></td>
  940:                     </tr>';
  941:                 $$triggered{$symb}{numparts} ++;
  942:             }
  943:         }
  944:         push(@{$warnings},$symb);
  945:         $warningnum ++;
  946:     }
  947: }
  948: 
  949: 
  950: sub get_curr_thresholds {
  951:     my ($threshold,$uname,$udom,$cid,$cdom,$crs) = @_;
  952:     my %thresholdsettings = &Apache::lonnet::dump('nohist_whatsnew',$udom,
  953:                                                      $uname,$cid.':threshold');
  954:     my $thresholdcount = 0;
  955:     my ($tmp) = %thresholdsettings;
  956:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
  957:         foreach my $item (keys %{$threshold}) { 
  958:             if (exists($thresholdsettings{$cid.':threshold_'.$item})) {
  959:                 $$threshold{$item} = 
  960:                              $thresholdsettings{$cid.':threshold_'.$item};
  961:                 $thresholdcount ++;
  962:             }
  963:         }
  964:     }
  965:     if ($thresholdcount == 3) {
  966:         return;
  967:     }
  968:     my %coursesettings = &Apache::lonnet::dump('environment',
  969:                                               $cdom,$crs,'internal.threshold');
  970:     my ($temp) = %coursesettings;
  971:     unless ($temp =~ /^(con_lost|error|no_such_host)/i) {  
  972:         foreach my $item (keys %{$threshold}) {
  973:             unless (exists($thresholdsettings{$cid.':threshold_'.$item})) {
  974:                 if (exists($coursesettings{'internal.threshold_'.$item})) {
  975:                     $$threshold{$item} = 
  976:                              $coursesettings{'internal.threshold_'.$item};
  977:                 }
  978:             }
  979:         }
  980:     }
  981:     return;
  982: }
  983: 
  984: sub get_current {
  985:     my ($uname,$udom,$cid,$caller) = @_;
  986:     my $currvalue;
  987:     my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid.
  988:                                                                 ':'.$caller);
  989:     my ($tmp) = %settings;
  990:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
  991:         $currvalue = $settings{$cid.':'.$caller};
  992:     }
  993:     return $currvalue;
  994: }
  995: 
  996: sub process_reset {
  997:     my ($dom,$crs) = @_;
  998:     my $result = '<b>'.&mt('Counters reset for following problems (and parts):').
  999:                            '</b><br />';
 1000:     my @agg_types = ('attempts','users','correct');
 1001:     my %agg_titles = &Apache::lonlocal::texthash (
 1002:                      attempts => 'Number of submissions',
 1003:                      users => 'Students with submissions',
 1004:                      correct => 'Number of correct submissions',
 1005:                      );
 1006:     my @resets = ();
 1007:     my %titles = ();
 1008:     foreach my $key (keys(%env)) {
 1009:         next if ($key !~ /^form\.reset_(.+)$/);
 1010:         my $title = &Apache::lonnet::unescape($env{'form.title_'.$1});
 1011:         my $reset_item = &Apache::lonnet::unescape($1);
 1012:         my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
 1013:         my %aggregates = ();
 1014:         my ($symb,$part) = split(/\0/,$reset_item);
 1015:         foreach my $type (@agg_types) {
 1016:             $aggregates{$reset_item."\0".$type} = 0;
 1017:         }  
 1018: 	$aggregates{$reset_item."\0".'resettime'} = time;
 1019:         my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
 1020:                           $dom,$crs);
 1021:         if ($putresult eq 'ok') {
 1022:             $result .= $title.' -part '.$part.': ';
 1023:             my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
 1024:             foreach my $type (@agg_types) {
 1025:                 $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
 1026:             }
 1027:             $result =~ s/; $//;
 1028:             $result .= '<br />';
 1029:         } else {
 1030:             $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
 1031:         }
 1032:     }
 1033:     return $result;
 1034: }
 1035: 
 1036: sub process_update {
 1037:     my ($uname,$udom,$threshold_titles) = @_;
 1038:     my $setoutput = '<b>Changes to threshold(s) for problem tracking:</b><br />';
 1039:     foreach (keys %env) {
 1040:         next if ($_!~/^form\.(.+)\_setparmval$/);
 1041:         my $name  = $1;
 1042:         my $value = $env{'form.'.$name.'_value'};
 1043:         if ($name && defined($value)) {
 1044:             my $put_result = &Apache::lonnet::put('nohist_whatsnew',
 1045:                                                   {$name=>$value},$udom,$uname);
 1046:            
 1047:             my ($shortname) = ($name =~ /^\Q$env{'request.course.id'}\E:threshold_(.+)$/);
 1048:             if ($put_result eq 'ok') {
 1049:                 $setoutput.=&mt('Set threshold for [_1] to [_2]',
 1050: 				'<b>'.$$threshold_titles{$shortname}.'</b>',
 1051: 				'<b>'.$value.'</b>').'<br />';
 1052: 	    } else {
 1053:                 $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
 1054: 				'<b>'.$name.'</b>','<b>'.$value.'</b>',
 1055: 				'<tt>'.$put_result.'</tt>').'<br />';
 1056:             }
 1057:         }
 1058:     }
 1059:     return $setoutput;
 1060: }
 1061: 
 1062: sub getnormalmail {
 1063:     my ($newmsgs) = @_;
 1064: # Check for unread mail in course
 1065:     my $msgcount = 0;
 1066: 
 1067:     my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
 1068:     foreach my $message (@messages) {
 1069: 	my $msgid=&Apache::lonnet::escape($message);
 1070:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 1071:             &Apache::lonmsg::unpackmsgid($msgid);
 1072:         if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
 1073:             if (defined($sendtime) && $sendtime!~/error/) {
 1074:                 my $numsendtime = $sendtime;
 1075:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
 1076:                 if ($status eq 'new') {
 1077:                     $msgcount ++;
 1078:                     if ($shortsubj eq '') {
 1079:                         $shortsubj = &mt('No subject');
 1080:                     }
 1081:                     $shortsubj = &Apache::lonnet::unescape($shortsubj);
 1082:                     push(@{$newmsgs}, {
 1083:                         msgid    => $msgid,
 1084:                         sendtime => $sendtime,
 1085:                         shortsub => $shortsubj,
 1086:                         from     => $fromname,
 1087:                         fromdom  => $fromdom
 1088:                         });
 1089:                 }
 1090:             }
 1091:         }
 1092:     }
 1093:     return $msgcount;
 1094: }
 1095: 
 1096: sub getcritmail {
 1097:     my ($critmsgs) = @_; 
 1098: # Check for critical messages in course
 1099:     my %what=&Apache::lonnet::dump('critical');
 1100:     my $result = '';
 1101:     my $critmsgcount = 0;
 1102:     foreach my $msgid (sort(keys(%what))) {
 1103:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 1104:             &Apache::lonmsg::unpackmsgid($msgid);
 1105:         if (($fromcid) && ($fromcid eq  $env{'request.course.id'})) {
 1106:             if (defined($sendtime) && $sendtime!~/error/) {
 1107:                 my $numsendtime = $sendtime;
 1108:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
 1109:                 $critmsgcount ++;
 1110:                 if ($shortsubj eq '') {
 1111:                     $shortsubj = &mt('No subject');
 1112:                 }
 1113:                 $shortsubj = &Apache::lonnet::unescape($shortsubj);
 1114:                 push(@{$critmsgs}, {
 1115:                         msgid    => $msgid,
 1116:                         sendtime => $sendtime,
 1117:                         shortsub => $shortsubj,
 1118:                         from     => $fromname,
 1119:                         fromdom  => $fromdom
 1120:                         });
 1121:             }
 1122:         }
 1123:     }
 1124:     return $critmsgcount;
 1125: }
 1126: 
 1127: 
 1128: sub checkversions {
 1129:     my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
 1130:     my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
 1131:     my ($tmp) = keys(%changes);
 1132:     unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
 1133:         if (keys(%changes) > 0) {
 1134:             foreach my $key (sort(keys(%changes))) {
 1135:                 if ($changes{$key} > $starttime) {
 1136:                     my $version;
 1137:                     my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
 1138:                     my $currentversion=&Apache::lonnet::getversion($key);
 1139:                     my $revdate = 
 1140:                           &Apache::lonnet::metadata($root.'.'.$extension,
 1141:                                                      'lastrevisiondate');
 1142:                     $revdate =  &Apache::lonlocal::locallocaltime($revdate);
 1143:                     my $linkurl=&Apache::lonnet::clutter($key);
 1144:                     my $usedversion=$navmap->usedVersion('version_'.$linkurl);
 1145:                     my @resources = $navmap->getResourceByUrl($linkurl,1);
 1146:                     if (($usedversion) && ($usedversion ne 'mostrecent')) {
 1147:                         $version = $usedversion;     
 1148:                     } else {
 1149:                         $version = $currentversion;
 1150:                     }
 1151:                     foreach my $res (@resources) {
 1152:                          if (ref($res) eq 'Apache::lonnavmaps::resource') { 
 1153:                             my $symb = $res->symb();
 1154:                             %{$$changed{$symb}} = (
 1155:                                                 current => $currentversion,
 1156:                                                 version => $version,
 1157:                                                 revdate => $revdate,
 1158:                             );
 1159:                         }
 1160:                     }
 1161:                 }
 1162:             }
 1163:         }
 1164:     }
 1165:     return;
 1166: }
 1167: 
 1168: sub display_handgrade {
 1169:     my ($r,$tograde,$rowColor1,$rowColor2,$ungraded) = @_;
 1170:     my $rowColor;
 1171:     my %lt = &Apache::lonlocal::texthash(
 1172:                         'prna' => 'Problem Name',
 1173:                         'nmun' => 'Number ungraded',
 1174:                         'nopr' => 'No problems require handgrading',
 1175:     );
 1176:     if (@{$tograde} > 0) {
 1177:         $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'prna'}.'</small></b></td><td align="right"><b><small>'.$lt{'nmun'}.'</small></b></td></tr>');
 1178:         my $rowNum = 0;
 1179:         foreach my $res (@{$tograde}) {
 1180:             if ($rowNum %2 == 1) {
 1181:                 $rowColor = $rowColor1;
 1182:             } else {
 1183:                 $rowColor = $rowColor2;
 1184:             }
 1185:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
 1186:             my $linkurl=&Apache::lonnet::clutter($url);
 1187:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
 1188:                                                                                
 1189:             $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>');
 1190:             $rowNum ++;
 1191:         }
 1192:     } else {
 1193:         $r->print('<tr><td bgcolor="#ffffff"><br><center><i><b><small>&nbsp;&nbsp;'.$lt{'nopr'}.'&nbsp;&nbsp;</small><br><br></b></i></td></tr>');
 1194:     }
 1195: }
 1196: 
 1197: sub display_haserrors {
 1198:     my ($r,$bombs,$rowColor1,$rowColor2,$bombed,$res_title) = @_;
 1199:     my $bombnum = 0;
 1200:     my $rowColor;
 1201:     my %lt = &Apache::lonlocal::texthash(
 1202:                                    reso => 'Resource',
 1203:                                    nmer => 'Number of errors',
 1204:                                    noer => 'No problems with errors',
 1205:     );
 1206:     if (@{$bombs} > 0) {
 1207:         $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'reso'}.'</small></b></td><td align="right"><b><small>'.$lt{'nmer'}.'</small></b></td></tr>');
 1208:         @{$bombs} = sort { &cmp_title($a,$b,$res_title) } @{$bombs};
 1209:         foreach my $bomb (@{$bombs}) {
 1210:             if ($bombnum %2 == 1) {
 1211:                 $rowColor = $rowColor1;
 1212:             } else {
 1213:                 $rowColor = $rowColor2;
 1214:             }
 1215:             $r->print('<tr bgcolor="'.$rowColor.'"><td><small>'.$$bombed{$bomb}{errorlink}.'</small></td><td align="right"><small>'.$$bombed{$bomb}{errorcount}.'</small></td></tr>');
 1216:             $bombnum ++;
 1217:         }
 1218:     } else {
 1219:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'noer'}.'</small></i></b></center><br /></td></tr>');
 1220:     }
 1221:     return;
 1222: }
 1223: 
 1224: sub display_abovethreshold {
 1225:     my ($r,$refpage,$warnings,$triggered,$res_title,$rowColor1,$rowColor2) = @_;
 1226:     my %lt = &Apache::lonlocal::texthash(
 1227:                  reso => 'Resource',
 1228:                  part => 'Part',
 1229:                  nust => 'Num. students',
 1230:                  avat => 'Av. Attempts',
 1231:                  dedi => 'Deg. Diff',
 1232:                  lare => 'Last Reset',
 1233:                  reco => 'Reset Count?',
 1234:                  rese => 'Reset counters to 0',
 1235:                  nopr => 'No problems satisfy threshold criteria',
 1236:     );
 1237:     my $rowColor; 
 1238:     my $warningnum = 0;
 1239:     if (@{$warnings} > 0) {
 1240:         @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
 1241:         $r->print('<form name="reset_tracking" method="post" action="/adm/whatsnew">'.
 1242:                 ' <input type="hidden" name="command" value="reset" />'."\n".
 1243:                 ' <input type="hidden" name="refpage" value="'.$refpage.'" />'.
 1244:                 "\n");
 1245:         $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>');
 1246:         foreach my $res (@{$warnings}) {
 1247:             if ($warningnum %2 == 1) {
 1248:                 $rowColor = $rowColor1;
 1249:             } else {
 1250:                 $rowColor = $rowColor2;
 1251:             }
 1252:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
 1253:             my $linkurl=&Apache::lonnet::clutter($url);
 1254:             my $rowspan;
 1255:             if ($$triggered{$res}{numparts} > 1) {
 1256:                 $rowspan = 'rowspan="'.$$triggered{$res}{numparts}.'"';
 1257:             }
 1258:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
 1259:             $r->print('<tr bgcolor="'.$rowColor.'"><td '.$rowspan.'><a href="'.$linkurl.'"><small>'.$$triggered{$res}{title}.'</small></a></td>'.$$triggered{$res}{text});
 1260:             $warningnum ++;
 1261:         }
 1262:         $r->print('<tr bgcolor="#cccccc"><td colspan="7" align="right"><br /><b><small><input type="submit" name="counters" value="'.$lt{'rese'}.'" /></form>');
 1263:     } else {
 1264:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'nopr'}.'</small></i></b></center><br /></td></tr>');
 1265:     }
 1266: }
 1267: 
 1268: sub display_versionchanges {
 1269:     my ($r,$changed,$res_title,$rowColor1,$rowColor2,$interval) = @_;
 1270:     my %lt = &Apache::lonlocal::texthash(
 1271:         'reso' => 'Resource',
 1272:         'revd' => 'Last revised',
 1273:         'newv' => 'New version',
 1274:         'veru' => 'Version used',
 1275:         'noup' => 'No updated versions', 
 1276:     );
 1277:     my $rowColor;
 1278:     if (keys(%{$changed}) > 0) {
 1279:         $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>');
 1280:         
 1281:         
 1282:         my @changes = sort { &cmp_title($a,$b,$res_title) } keys(%{$changed});
 1283:         my $changenum = 0;
 1284:         foreach my $item (@changes) {
 1285:             if ($changenum %2 == 1) {
 1286:                 $rowColor = $rowColor1;
 1287:             } else {
 1288:                 $rowColor = $rowColor2;
 1289:             }
 1290:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($item);
 1291:             my $linkurl=&Apache::lonnet::clutter($url);
 1292:             $linkurl .= '?symb='.&Apache::lonnet::escape($item);
 1293: 
 1294:             $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>');
 1295:             $changenum ++;
 1296:         }
 1297:     } else {
 1298:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>'.$lt{'noup'}.' '.$interval.'</small></i></b></center><br /></td></tr>');
 1299:     }
 1300:     return;
 1301: }
 1302:  
 1303: sub display_coursediscussion {
 1304:     my ($r,$newdiscussions,$unread,$countunread,$res_title,$rowColor1,
 1305:                                                               $rowColor2) = @_;
 1306:     my %lt = &Apache::lonlocal::texthash(
 1307:                 'loca' => 'Location',
 1308:                 'type' => 'Type',
 1309:                 'numn' => 'Number of new posts',
 1310:                 'noun' => 'No unread posts in course discussions',
 1311:                 'tmlp' => 'Time of last post', 
 1312:     );
 1313:     my $rowColor;
 1314:     if (@{$newdiscussions} > 0) {
 1315:         $r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'loca'}.
 1316:                   '</small></b></td><td><b><small>'.$lt{'type'}.
 1317:                   '</small></b>');
 1318:         if ($countunread eq 'on') {
 1319:             $r->print('<td><b><small>'.$lt{'tmlp'}.'</small></b></td>'.
 1320:                       '<td align="right"><b><small>'.$lt{'numn'}.
 1321:                       '</small></b></td>');
 1322:         } else {
 1323:             $r->print('<td align="right"><b><small>'.$lt{'tmlp'}.
 1324:                          '</small></b></td>');
 1325:         }
 1326:         $r->print("</tr>\n");
 1327:         @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) }
 1328:                                                             @{$newdiscussions};
 1329:         my $rowNum = 0;
 1330:         foreach my $ressymb (@{$newdiscussions}) {
 1331:             my $forum_title = $$unread{$ressymb}{'title'};
 1332:             my $type = 'Resource';
 1333:             my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
 1334:             if ($feedurl =~ /bulletinboard/) {
 1335:                 $type = 'Bulletin Board';
 1336:             }
 1337:             if ($rowNum %2 == 1) {
 1338:                 $rowColor = $rowColor1;
 1339:             } else {
 1340:                 $rowColor = $rowColor2;
 1341:             }
 1342:             my $lastpost = &Apache::lonnavmaps::timeToHumanString(
 1343:                                                $$unread{$ressymb}{'lastpost'});
 1344:             $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>');
 1345:             if ($countunread eq 'on') {
 1346:                 my $unreadnum = $$unread{$ressymb}{'unreadcount'};
 1347:                 $r->print('<td><small>'.$lastpost.'<small></td><td align="right">'.
 1348:                           '<small>',$unreadnum.'&nbsp;</small></td>');
 1349:             } else {
 1350:                 $r->print('<td align="right"><small>'.$lastpost.'</small></td>');
 1351:             }
 1352:             $r->print("</tr>\n");
 1353:             $rowNum ++;
 1354:         }
 1355:     } else {
 1356:         $r->print('<tr><td bgcolor="#ffffff"><br><center>&nbsp;<i><b><small>'.
 1357:                   $lt{'noun'}.'</small></b></i><br><br></td></tr>');
 1358:     }
 1359: }
 1360: 
 1361: sub display_coursenormalmail {
 1362:     my ($r,$msgcount,$newmsgs,$rowColor1,$rowColor2) = @_;
 1363:     my $rowColor;
 1364:     if ($msgcount > 0) {
 1365:         $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>');
 1366:         my $rowNum = 0;
 1367:         my $mailcount = 1;
 1368:         foreach my $msg (@{$newmsgs}) {
 1369:             if ($rowNum %2 == 1) {
 1370:                 $rowColor = $rowColor1;
 1371:             } else {
 1372:                 $rowColor = $rowColor2;
 1373:             }
 1374:             $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>');
 1375:             $rowNum ++;
 1376:             $mailcount ++;
 1377:         }
 1378:     } else {
 1379:         $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>');
 1380:     }
 1381: }
 1382: 
 1383: sub display_coursecritmail {
 1384:     my ($r,$critmsgcount,$critmsgs,$rowColor1,$rowColor2) = @_;
 1385:     my $rowColor;
 1386:     if ($critmsgcount > 0) {
 1387:         $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>');
 1388:         my $rowNum = 0;
 1389:         my $mailcount = 1;
 1390:         foreach my $msg (@{$critmsgs}) {
 1391:             if ($rowNum %2 == 1) {
 1392:                 $rowColor = $rowColor1;
 1393:             } else {
 1394:                 $rowColor = $rowColor2;
 1395:             }
 1396:             $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>');
 1397:             $rowNum ++;
 1398:             $mailcount ++;
 1399:         }
 1400:     } else {
 1401:         $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>');
 1402:     }
 1403: }
 1404: 
 1405: sub cmp_title {
 1406:     my ($a,$b,$res_title) = @_;
 1407:     my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
 1408:     $atitle=~s/^\s*//;
 1409:     $btitle=~s/^\s*//;
 1410:     return $atitle cmp $btitle;
 1411: }
 1412: 
 1413: sub get_display_settings {
 1414:     my ($uname,$udom,$cid) = @_;
 1415:     my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid); 
 1416:     my ($tmp) = keys(%settings);
 1417:     if ($tmp=~ /^(con_lost|error|no_such_host)/i) {
 1418:         %settings = ();
 1419:         unless ($tmp =~ /^error: 2 /) {
 1420:             &Apache::lonnet::logthis('Error retrieving whatsnew settings: '.
 1421:             $tmp.' for '.$uname.':'.$udom.' for course: '.$cid);
 1422:         }
 1423:     }
 1424:     return %settings;
 1425: }
 1426: 
 1427: sub store_display_settings {
 1428:     my ($uname,$udom,$cid,$checkallowed) = @_;
 1429:     my %whatsnew_settings;
 1430:     my $result;
 1431:     foreach my $key (keys(%{$checkallowed})) {
 1432: 	if ($key =~ /_section$/) { next; }
 1433:         if (exists($env{'form.display_'.$key})) {
 1434:             unless ($env{'form.display_'.$key} eq '') {
 1435:                 $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key};
 1436:             }
 1437:         }
 1438:     }
 1439:     if (keys(%whatsnew_settings)) {
 1440:         $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings,
 1441:                                                                  $udom,$uname);
 1442:     } else {
 1443:         $result = 'ok';
 1444:     }
 1445:     return $result;
 1446: }
 1447: 
 1448: sub store_interval_setting {
 1449:     my ($uname,$udom,$cid,$interval_titles) = @_;
 1450:     my %interval_settings = ();
 1451:     my $result;
 1452:     if (defined($env{'form.interval'})) {
 1453:         $interval_settings{$cid.':interval'} = $env{'form.interval'};
 1454:         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 1455:                                              \%interval_settings,$udom,$uname);
 1456:         if ($outcome eq 'ok') {
 1457:             $result = &mt('Interval set to version changes [_1]',
 1458:                   '<b>'.$$interval_titles{$env{'form.interval'}}.'</b><br />');
 1459: 
 1460:         } else {
 1461:             &Apache::lonnet::logthis('Error storing whatsnew interval setting'.
 1462:                      ' '.$outcome.' for '.$uname.':'.$udom.' in course '.$cid);
 1463:             $result = &mt('Unable to set interval to [_1] due to [_2].',
 1464:                          '<b>'.$$interval_titles{$env{'form.interval'}}.'</b>',
 1465:                          '<tt>'.$outcome.'</tt>.<br />');
 1466:         }
 1467:     }
 1468:     return $result;
 1469: }
 1470: 
 1471: sub store_discussion_setting {
 1472:     my ($uname,$udom,$cid) = @_;
 1473:     my %discussion_settings;
 1474:     my $result;
 1475:     if (defined($env{'form.countunread'})) {
 1476:         $discussion_settings{$cid.':countunread'} = $env{'form.countunread'};
 1477:         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 1478:                                              \%discussion_settings,$udom,$uname);
 1479:         if ($outcome eq 'ok') {
 1480:             $result = &mt('Count unread posts in discussions display set to [_1]',
 1481:                   '<b>'.$env{'form.countunread'}.'</b><br />');
 1482:                                                                                   
 1483:         } else {
 1484:             &Apache::lonnet::logthis('Error storing whatsnew countunread setting'.
 1485:                      ' '.$outcome.' for '.$uname.':'.$udom.' in course '.$cid);
 1486:             $result = &mt('Unable to set "number unread posts display" to [_1]'.
 1487:                           ' due to [_2].',
 1488:                          '<b>'.$env{'form.countunread'}.'</b>',
 1489:                          '<tt>'.$outcome.'</tt>.<br />');
 1490:         }
 1491:     }
 1492:     return $result;
 1493: }
 1494: 
 1495: sub store_courseinit_setting {
 1496:     my ($uname,$udom,$cid,$initpage) = @_;
 1497:     my %courseinit_settings;
 1498:     my $page_control;
 1499:     my $result;
 1500:     if (defined($env{'form.courseinit_control'})) {
 1501:         if ($env{'form.courseinit_control'} eq 'userpref') {
 1502:             $courseinit_settings{$cid.':courseinit'} = '';
 1503:             $page_control = 'global preferences';
 1504:         } else {
 1505:             if (defined($env{'form.courseinit_page'})) {
 1506:                 $courseinit_settings{$cid.':courseinit'} = 
 1507:                                                   $env{'form.courseinit_page'};
 1508:                 $page_control = 'course specific setting';
 1509:             }
 1510:         }
 1511:         if ($page_control) {
 1512:             my $outcome = &Apache::lonnet::put('nohist_whatsnew',
 1513:                                            \%courseinit_settings,$udom,$uname);
 1514:             if ($outcome eq 'ok') {
 1515:                 if ($page_control eq 'global preferences') {
 1516:                     $result = &mt('Page displayed after role selection in course now set by [_1]',"<b>user's global preferences</b>.");
 1517:                 } else {
 1518:                     $result = &mt('Page displayed after role selection in this course set to [_1]','<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>.');
 1519:                 }
 1520:             } else {
 1521:                 &Apache::lonnet::logthis('Error storing whatsnew courseinit '.
 1522:                                          'setting: '.$outcome.' for '.$uname.
 1523:                                                  ':'.$udom.' in course '.$cid);
 1524:                 if ($page_control eq 'global preferences') {
 1525:                     $result = &mt('Unable to set control of page display to [_1]'.
 1526:                           ' due to [_2].',
 1527:                          '<b>'.$page_control.'</b>',
 1528:                          '<tt>'.$outcome.'</tt>.<br />');
 1529:                 } else {
 1530:                     $result = &mt('Unable to set page display, after role selection, for this course to [_1] due to [_2].',
 1531:                          '<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>',
 1532:                          '<tt>'.$outcome.'</tt>.<br />');
 1533:                 }
 1534:             }
 1535:         }
 1536:     }
 1537:     return $result;
 1538: }
 1539: 
 1540: sub start_box {
 1541:     my ($r,$tabbg,$show,$heading,$caller,$refpage) = @_;
 1542:     my %lt = &Apache::lonlocal::texthash( 
 1543:                        chth => 'Change thresholds?',
 1544:                        chin => 'Change interval?',
 1545:                        chop => 'Change options?',
 1546:     );
 1547:     my $showhide;
 1548:     if ($$show{$caller}) {
 1549:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 1550:                                'display_'.$caller.",'hide'".');">Hide</a></b>';
 1551:    
 1552:     } else {
 1553:         $showhide = '<b><a href="javascript:change_display(document.visible.'.
 1554:                                'display_'.$caller.",'show'".');">Show</a></b>';
 1555:     }
 1556:     
 1557:     $r->print('
 1558:          <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
 1559:           <tr>
 1560:            <td>
 1561:             <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
 1562:               <tr>
 1563:                <td bgcolor="'.$tabbg.'">
 1564:                 <table width="100%" border="0" cellspacing="0" cellpadding="0">
 1565:                  <tr>
 1566:                   <td><b>'.$$heading{$caller}.'</b></td>
 1567:                   <td valign="top" align="right">'.$showhide.'</td>
 1568:                  </tr>
 1569:                 </table>
 1570:                </td>
 1571:               </tr>');
 1572:      if (($caller eq 'abovethreshold') && ($$show{$caller})) {
 1573:          if ($$show{$caller}) {
 1574:              $r->print('
 1575:               <tr>
 1576:                 <td bgcolor="'.$tabbg.'" align="right"><a href="/adm/whatsnew?command=chgthreshold&refpage='.$refpage.'"><b><small>'.$lt{'chth'}.'</small></b></a></td>
 1577:               </tr>');
 1578:          }
 1579:      } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
 1580:          if ($$show{$caller}) {
 1581:              $r->print('
 1582:               <tr>
 1583:                 <td bgcolor="'.$tabbg.'" align="right"><a href="/adm/whatsnew?command=chginterval&refpage='.$refpage.'"><b><small>'.$lt{'chin'}.'</small></b></a></td>
 1584:               </tr>');
 1585:          }
 1586:      } elsif ($caller eq 'coursediscussion') {
 1587:          if ($$show{$caller}) {
 1588:              $r->print('
 1589:               <tr>
 1590:                 <td bgcolor="'.$tabbg.'" align="right"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'"><b><small>'.$lt{'chop'}.'</small></b></a></td>
 1591:               </tr>');
 1592:          }
 1593:      }
 1594:      $r->print('
 1595:               <tr>
 1596:                <td bgcolor="#ffffff">
 1597:                 <table cellpadding="2" cellspacing="0" border="0" width="100%">
 1598: ');
 1599:     return;
 1600: }
 1601: 
 1602: sub end_box {
 1603:     my ($r) = shift;
 1604:     $r->print('
 1605:       </table>
 1606:      </td>
 1607:     </tr>
 1608:    </table>
 1609:   </td>
 1610:  </tr>
 1611: </table><br />');
 1612:     return;
 1613: }
 1614: 
 1615: 1;

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