File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.38.2.1: download - view: text, annotated - select for diffs
Mon Dec 19 23:24:40 2005 UTC (18 years, 6 months ago) by albertel
- backport bugfix from 1.39

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

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