File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.39: download - view: text, annotated - select for diffs
Mon Dec 19 21:39:37 2005 UTC (18 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Display of whatsnew page on entering a course can be set for specific courses (override user prefs).  Can suppress count of unread posts per resource. Link to first resource at top of page not shown if NEW button used to get to whatsnew. What's new no longer restricted to CC role - accessible to adavnced roles in a course.

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

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