File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.42: download - view: text, annotated - select for diffs
Thu Dec 22 03:39:39 2005 UTC (18 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Add whn privilege to make what's new available to cc, in, ta and custom role. Display NEW button for users with this privilege in a course.
CeS: ----------------------------------------------------------------------

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

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