File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.38: download - view: text, annotated - select for diffs
Thu Dec 15 13:38:58 2005 UTC (18 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Only loop through once.

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

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