File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.49: download - view: text, annotated - select for diffs
Thu Jan 12 09:32:26 2006 UTC (18 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_1, HEAD
- commenting out non existant help links BUG#4566

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

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