File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.14: download - view: text, annotated - select for diffs
Tue May 24 15:54:19 2005 UTC (19 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- correcting some invalid html
- making the &mt() easier to translate

    1: #
    2: # $Id: lonwhatsnew.pm,v 1.14 2005/05/24 15:54:19 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::Constants qw(:common :http);
   39: use Time::Local;
   40: 
   41: #----------------------------
   42: # handler
   43: #
   44: #----------------------------
   45: 
   46: sub handler {
   47:     my $r = shift;
   48:     if ($r->header_only) {
   49:         &Apache::loncommon::content_type($r,'text/html');
   50:         $r->send_http_header;
   51:         return OK;
   52:     }
   53:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['command']);
   54: 
   55:     my $command;
   56:     if ($env{'form.action'} eq 'reset') {
   57:         $command = 'reset';
   58:     } elsif ($env{'form.action'} eq 'update') {
   59:         $command = 'update';
   60:     } else {
   61:         $command = $env{'form.command'};
   62:     }
   63: 
   64:     &Apache::loncommon::content_type($r,'text/html');
   65:     $r->send_http_header;
   66:     $r->print(&display_header());
   67:     if (! (($env{'request.course.fn'}) && (&Apache::lonnet::allowed('vsa',$env{'request.course.id'})))) {
   68:         # Not in a course, or not allowed to modify parms
   69:         $env{'user.error.msg'}="/adm/whatsnew:vsa:0:0:Cannot display student activity";
   70:         return HTTP_NOT_ACCEPTABLE;
   71:     }
   72: 
   73:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   74:     if ($command eq 'chgthreshold') {
   75:         &Apache::lonhtmlcommon::add_breadcrumb
   76:             ({href=>'/adm/whatsnew?command=threshold',
   77:               text=>"Change thresholds"});
   78:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
   79:             (undef,'Course Action Items','Course_Action_Items_Thresholds'));
   80:     } else {
   81:         &Apache::lonhtmlcommon::add_breadcrumb
   82:             ({href=>'/adm/whatsnew',
   83:               text=>"Display Action Items"});
   84:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
   85:             (undef,'Course Action Items','Course_Action_Items_Display'));
   86:     }
   87:     &display_main_box($r,$command);
   88:     return OK;
   89: }
   90: 
   91: #------------------------------
   92: # display_main_box
   93: #
   94: # Display all the elements within the main box
   95: #------------------------------
   96:                                                                                 
   97: sub display_main_box {
   98:     my ($r,$command) = @_;
   99:     my $domain=&Apache::loncommon::determinedomain();
  100:     my $tabbg=&Apache::loncommon::designparm('coordinator.tabbg',$domain);
  101:     $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
  102: 
  103:     my %threshold_titles = (
  104:                          av_attempts => 'Average number of attempts',
  105:                          degdiff => 'Degree of difficulty',
  106:                          numstudents => 'Total number of students with submissions',
  107:     );
  108:     if ($command eq 'chgthreshold') {
  109:         &display_config_box($r,$command,$tabbg,\%threshold_titles);
  110:     } else {
  111:         &display_actions_box($r,$command,\%threshold_titles);
  112:     }
  113:     $r->print(<<END_OF_BLOCK);
  114:   </td>
  115:  </tr>
  116: </table><br />
  117: </body>
  118: </html>
  119: END_OF_BLOCK
  120: }
  121: 
  122: #-------------------------------
  123: # display_header
  124: #
  125: # Display the header information and set
  126: # up the HTML
  127: #-------------------------------
  128: 
  129: sub display_header{
  130:     my $html=&Apache::lonxml::xmlbegin();
  131:     my $bodytag=&Apache::loncommon::bodytag('Course Action Items');
  132:     return(<<ENDHEAD);
  133: $html
  134: <head>
  135: <title>Course Action Items</title>
  136: </head>
  137: $bodytag
  138: ENDHEAD
  139: }
  140: 
  141: #-------------------------------
  142: # display_actions_box
  143: #
  144: # Display the action items
  145: #
  146: #-------------------------------
  147:                                                                                 
  148: sub display_actions_box() {
  149:     my ($r,$command,$threshold_titles) = @_;
  150: 
  151:     my $rowColor1 = "#ffffff";
  152:     my $rowColor2 = "#eeeeee";
  153:     my $rowColor;
  154: 
  155:     my %unread = ();
  156:     my %ungraded = ();
  157:     my %bombed = ();
  158:     my %triggered = ();
  159:     my @newmsgs = ();
  160:     my @critmsgs = ();
  161:     my @newdiscussions = ();
  162:     my @tograde = ();
  163:     my @bombs = ();
  164:     my @warnings = ();
  165: 
  166:     my $domain=&Apache::loncommon::determinedomain();
  167:     my $function;
  168:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
  169:         $function='coordinator';
  170:     }
  171:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
  172:         $function='admin';
  173:     }
  174: 
  175:     my %threshold = (
  176:                       av_attempts => 0,
  177:                       degdiff => 0.01,
  178:                       numstudents => 0,
  179:                      );
  180: 
  181:     my $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
  182:     my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
  183: 
  184:     unless ($env{'request.course.id'}) {
  185:         $r->print('<br /><b><center>You are accessing an invalid course</center></b><br /><br />');
  186:         return;
  187:     }
  188: 
  189:     my $result;
  190:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  191:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
  192: 
  193:     if ($command eq 'reset') {
  194:         $result = &process_reset($cdom,$crs);
  195:     } elsif ($command eq 'update') {
  196:         $result = &process_update($cdom,$crs,$threshold_titles);
  197:     }
  198:     if ($result) {
  199:         $r->print($result.'<hr width="100%" />');
  200:     }
  201: 
  202:     &get_curr_thresholds(\%threshold,$cdom,$crs);
  203:     &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs);
  204:     my ($msgcount,$critmsgcount) = &getmail(\@newmsgs,\@critmsgs);
  205: 
  206:     $r->print('<br /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
  207: 
  208: ## UNGRADED ITEMS ##
  209:     $r->print(<<END);
  210:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  211:             <tr><td>
  212:              <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  213:               <tr>
  214:                <td bgcolor="$tabbg"><b>Problems requiring handgrading</b></td></tr>
  215:                   <tr>
  216:                    <td bgcolor="#ffffff">
  217:                      <table cellpadding="2" cellspacing="0" border="0" width="100%">
  218: END
  219: 
  220:     if (@tograde > 0) {
  221:         $r->print('<tr bgcolor="#cccccc"><td><b><small>Problem Name</small></b></td><td align="right"><b><small>Number ungraded</small></b></td></tr>');
  222:         my $rowNum = 0;
  223:         foreach my $res (@tograde) {
  224:             if ($rowNum %2 == 1) {
  225:                 $rowColor = $rowColor1;
  226:             } else {
  227:                 $rowColor = $rowColor2;
  228:             }
  229:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
  230:             my $linkurl=&Apache::lonnet::clutter($url);
  231:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
  232: 
  233:             $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>');
  234:             $rowNum ++;
  235:         }
  236:     } else {
  237:         $r->print('<tr><td bgcolor="#ffffff"><br><center><i><b><small>&nbsp;&nbsp;No problems require handgrading&nbsp;&nbsp;</small><br><br></b></i></td></tr>');
  238:     }
  239:     $r->print('</table></td></tr></table></td></tr></table><br />');
  240: 
  241: ## BOMBS ##
  242:      $r->print(<<"END");
  243:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  244:             <tr>
  245:              <td>
  246:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  247:                <tr>
  248:                 <td bgcolor="$tabbg"><b>Problems with errors</b></td>
  249:                </tr>
  250:                 <tr>
  251:                 <td bgcolor="#ffffff">
  252:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  253: END
  254:      my $bombnum = 0;
  255:      if (@bombs > 0) {
  256:         $r->print('<tr bgcolor="#cccccc"><td><b><small>Resource</small></b></td><td align="right"><b><small>Number of errors</small></b></td></tr>');
  257: #        @bombs = sort { &cmp_title($a,$b) } @bombs;
  258:         foreach my $bomb (@bombs) {
  259:             if ($bombnum %2 == 1) {
  260:                  $rowColor = $rowColor1;
  261:             } else {
  262:                 $rowColor = $rowColor2;
  263:             }
  264:             $r->print('<tr bgcolor="'.$rowColor.'"><td><small>'.$bombed{$bomb}{errorlink}.'</small></td><td align="right"><small>'.$bombed{$bomb}{errorcount}.'</small></td></tr>');
  265:             $bombnum ++;
  266:         }
  267:     } else {
  268:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>No problems with errors</small></i></b></center><br /></td></tr>');
  269:     }
  270:     $r->print('</table></td></tr></table></td></tr></table><br />');
  271: 
  272: # DEGDIFF AND AV. TRIES TRIGGERS
  273:     $r->print(<<"END");
  274:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  275:             <tr>
  276:              <td>
  277:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  278:                <tr>
  279:                 <td bgcolor="$tabbg"><b>Problems with av. attempts &ge; $threshold{'av_attempts'} or deg. difficulty &ge; $threshold{'degdiff'}<br /> and total number of students with submissions &ge; $threshold{'numstudents'}</b></td>
  280:                </tr>
  281:                <tr>
  282:                 <td bgcolor="$tabbg" align="right"><a href="/adm/whatsnew?command=chgthreshold"><b><small>Change thresholds?</small></b></a></td>
  283:                </tr>
  284:                 <tr>
  285:                 <td bgcolor="#ffffff">
  286:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  287: END
  288:     my $warningnum = 0;
  289:     if (@warnings > 0) {
  290: #        @warnings = sort { &cmp_title($a,$b) } @warnings;
  291:         $r->print('<form name="reset_tracking" method="post">'.
  292:                  '  <input type="hidden" name="action" value="reset" />'."\n");
  293:         $r->print('<tr bgcolor="#cccccc"><td><b><small>Resource</small></b></td><td align="right"><b><small>Part</small></b></td><td align="right"><b><small>Num. students</small></b></td><td align="right"><b><small>Av. Attempts</small></b></td><td align="right"><b><small>Deg. Diff</small></b></td><td align="right"><b><small>Last Reset</small></b></td><td align="right"><b><small>Reset Count?</small></b></td></tr>');
  294:         foreach my $res (@warnings) {
  295:             if ($warningnum %2 == 1) {
  296:                 $rowColor = $rowColor1;
  297:             } else {
  298:                 $rowColor = $rowColor2;
  299:             }
  300:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
  301:             my $linkurl=&Apache::lonnet::clutter($url);
  302:             my $rowspan;
  303:             if ($triggered{$res}{numparts} > 1) {
  304:                 $rowspan = 'rowspan="'.$triggered{$res}{numparts}.'"';
  305:             }
  306:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
  307:             $r->print('<tr bgcolor="'.$rowColor.'"><td '.$rowspan.'><a href="'.$linkurl.'"><small>'.$triggered{$res}{title}.'</small></a></td>'.$triggered{$res}{text});
  308:             $warningnum ++;
  309:         }
  310:         $r->print('<tr bgcolor="#cccccc"><td colspan="7" align="right"><br /><b><small><input type="submit" name="counters" value="Reset counters to 0" /></form>'); 
  311:     } else {
  312:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>No problems satisfy threshold criteria.</small></i></b></center><br /></td></tr>');
  313:     }
  314:     $r->print('</table></td></tr></table></td></tr></table><br />');
  315: 
  316:     $r->print('</td><td width="5%">&nbsp;</td><td align="left" valign="top" width-"50%">');
  317: 
  318: ## UNREAD COURSE DISCUSSION POSTS ##
  319:     $r->print(<<"END");
  320:               <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  321:                <tr><td>
  322:                 <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  323:                  <tr>
  324:                   <td bgcolor="$tabbg"><b>Unread course discussion posts</b></td>
  325:                  </tr>
  326:                  <tr>
  327:                    <td bgcolor="#ffffff">
  328:                    <table cellpadding="2" cellspacing="0" border="0" width="100%">
  329: END
  330:                                                                                   
  331:     if (@newdiscussions > 0) {
  332:         $r->print('<tr bgcolor="#cccccc"><td><b><small>Location</small></b></td><td><b><small>Type</small></b><td align="right"><b><small>Number of new posts</small></b></td></tr>');
  333: #        @newdiscussions = sort { &cmp_title($a,$b) } @newdiscussions;
  334:         my $rowNum = 0;
  335:         foreach my $ressymb (@newdiscussions) {
  336:             my $forum_title = $unread{$ressymb}{'title'};
  337:             my $type = 'Resource';
  338:             my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
  339:             if ($feedurl =~ /bulletinboard/) {
  340:                 $type = 'Bulletin Board';
  341:             }
  342:             my $unreadnum = keys(%{$unread{$ressymb}});
  343:             $unreadnum = $unreadnum - 2;
  344:             if ($unreadnum > 0) {
  345:                 if ($rowNum %2 == 1) {
  346:                     $rowColor = $rowColor1;
  347:                 } else {
  348:                     $rowColor = $rowColor2;
  349:                 }
  350:                 $r->print('<tr bgcolor="'.$rowColor.'"><td><small><a href="'.$feedurl.'?symb='.$unread{$ressymb}{symb}.'">'.$forum_title.'</a>&nbsp;</td><td><small>'.$type.'</small></td><td align="right">'.$unreadnum.'&nbsp;</td></tr>');
  351:                 $rowNum ++;
  352:             }
  353:         }
  354:     } else {
  355:         $r->print('<tr><td bgcolor="#ffffff"><br><center>&nbsp;<i><b><small>No unread posts in course discussions</small></b></i><br><br></td></tr>');
  356:     }
  357:     $r->print('</table></td></tr></table></td></tr></table><br />');
  358: 
  359: ## MESSAGES ##
  360:     $r->print(<<END);
  361:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  362:             <tr>
  363:              <td>
  364:               <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  365:                <tr>
  366:                 <td bgcolor="$tabbg"><b>New course messages</b></td>
  367:                </tr>
  368:                <tr>
  369:                 <td bgcolor="#ffffff">
  370:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  371: END
  372:     if ($msgcount > 0) {
  373:         $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>');
  374:         my $rowNum = 0;
  375:         my $mailcount = 1; 
  376:         foreach my $msg (@newmsgs) {
  377:             if ($rowNum %2 == 1) {
  378:                 $rowColor = $rowColor1;
  379:             } else {
  380:                 $rowColor = $rowColor2;
  381:             }
  382:             $r->print('<tr bgcolor="'.$rowColor.'"><td valign="top"><small>'.$mailcount.'. &nbsp;<small></td><td valign="top"><small><a href="/adm/mail?">'.$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>');
  383:             $rowNum ++;
  384:             $mailcount ++;
  385:         }
  386:     } else {
  387:         $r->print('<tr><td bgcolor="#ffffff" width="100%"><center><br /><b><i><small>No new course messages</small></i></b><br /><br /></center></td></tr>');
  388:     }
  389: 
  390:     $r->print('</table></td></tr></table></td></tr></table><br />');
  391: 
  392:     $r->print(<<END);
  393:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  394:             <tr>
  395:              <td>
  396:               <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  397:                <tr>
  398:                 <td bgcolor="$tabbg"><b>New critical messages in course</b></td>
  399:                </tr>
  400:                <tr>                 <td bgcolor="#ffffff">
  401:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  402: END
  403: 
  404:     if ($critmsgcount > 0) {
  405:         $r->print('<tr bgcolor="#cccccc"><td><b><small>Number</small></b></td><td><b><small>Subject</small></b></td><td><b><small>Sender</small></b></td><td><b><small>Date/Time</small></b></td></tr>');
  406:         my $rowNum = 0;
  407:         my $mailcount = 1;
  408:         foreach my $msg (@critmsgs) {
  409:             if ($rowNum %2 == 1) {
  410:                 $rowColor = $rowColor1;
  411:             } else {
  412:                 $rowColor = $rowColor2;
  413:             }
  414:             $r->print('<tr bgcolor="'.$rowColor.'"><td valign="top"><small>'.$mailcount.'. &nbsp;<small></td><td valign="top"><small><a href="/adm/mail?">'.$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>');
  415:             $rowNum ++;
  416:             $mailcount ++;
  417:         }
  418:     } else {
  419:         $r->print('<tr><td bgcolor="#ffffff" width="100%"><center><br /><b><i><small>No unread critical messages in course</small></i></b><br /><br /></center></td></tr>');
  420:     }
  421:                                                                                
  422:     $r->print('</table></td></tr></table></td></tr></table><br />');
  423: 
  424:     $r->print('
  425:            </table>
  426:           </td>
  427:          </tr>
  428:         </table>');
  429:     $r->print('</td></tr></table>');
  430: }
  431: 
  432: #-------------------------------
  433: # display_config_box
  434: #
  435: # Display the threshold setting screen 
  436: #
  437: #-------------------------------
  438:                                                                                 
  439: sub display_config_box() {
  440:     my ($r,$command,$tabbg,$threshold_titles) = @_;
  441:     my %threshold = ();
  442:     my $rowColor1 = "#ffffff";
  443:     my $rowColor2 = "#eeeeee";
  444:     my $rowColor;
  445: 
  446:     my @thresholditems = ("av_attempts","degdiff","numstudents");
  447:     my %threshold_titles = (
  448:                          av_attempts => 'Average number of attempts',
  449:                          degdiff => 'Degree of difficulty',
  450:                          numstudents => 'Total number of students with submissions',
  451:                          );
  452:     &get_curr_thresholds(\%threshold);
  453: 
  454:     $r->print('<br /><form name="thresholdform" method="post"><table border="0" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">
  455:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  456:             <tr>
  457:              <td>
  458:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">
  459:                 <tr>
  460:                 <td bgcolor="#ffffff">
  461:                  <table cellspacing="0" cellpadding="4" border="0">
  462:      <tr bgcolor="'.$tabbg.'">
  463:       <th>Threshold Name</th>
  464:       <th>Current value</th>
  465:       <th>Change?</th>
  466:      </tr>');
  467:     my $rowNum =0;
  468:     foreach my $type (@thresholditems) {
  469:         my $parameter = 'internal.threshold_'.$type;
  470: # onchange is javascript to automatically check the 'Set' button.
  471:         my $onchange = 'onFocus="javascript:window.document.forms'.
  472:               "['thresholdform'].elements['".$parameter."_setparmval']".
  473:               '.checked=true;"';
  474:         if ($rowNum %2 == 1) {
  475:             $rowColor = $rowColor1;
  476:         } else {
  477:             $rowColor = $rowColor2;
  478:         }
  479:         $r->print('
  480:      <tr bgcolor="'.$rowColor.'">
  481:       <td>'.$threshold_titles{$type}.'</td>
  482:       <td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
  483:                                             $threshold{$type},
  484:                                             10,$onchange).'</td>
  485:       <td>'
  486:            .&Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
  487:       '</td>
  488:      </tr>');
  489:         $rowNum ++;
  490:     }
  491:     $r->print('</table></td></tr></table></td></tr></table>
  492:            <br /><input type="submit" name="threshold" value="Make changes" />
  493:                  <input type="hidden" name="action" value="update" />
  494:                </form>');
  495: }
  496: 
  497: sub getitems {
  498:     my ($unread,$ungraded,$bombed,$triggered,$newdiscussions,$tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs) = @_;
  499:     my $navmap = Apache::lonnavmaps::navmap->new();
  500:     my @allres=$navmap->retrieveResources();
  501:     my %discussiontime = &Apache::lonnet::dump('discussiontimes',$cdom,$crs);
  502:     my %lastread = &Apache::lonnet::dump('nohist_'.$env{'request.course.id'}.
  503:                 '_discuss',$env{'user.domain'},$env{'user.name'},'lastread');
  504:     my %lastreadtime = ();
  505:     my @discussions = ();
  506:     my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
  507: 
  508:     my %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',
  509:                $cdom,$crs);
  510:     my %res_title;
  511:     my $warningnum = 0;
  512:     foreach my $key (keys(%lastread)) {
  513:         my $newkey = $key;
  514:         $newkey =~ s/_lastread$//;
  515:         $lastreadtime{$newkey} = $lastread{$key};
  516:     }
  517:     foreach my $resource (@allres) {
  518:         my $result = '';
  519:         my $applies = 0;
  520:         my $symb = $resource->symb();
  521: #        %{$$bombed{$symb}} = ();
  522:         %{$$ungraded{$symb}} = ();
  523:         %{$$triggered{$symb}} = ();
  524:         $$triggered{$symb}{numparts} = 0;
  525:         my $title = $resource->compTitle();
  526:         $res_title{$symb} = $title;
  527:         my $ressymb = $resource->wrap_symb();
  528: # Check for unread discussion postings
  529:         if (defined($discussiontime{$ressymb})) {
  530:             push(@discussions,$ressymb);
  531:             my $prevread = 0;
  532:             my $unreadcount = 0;
  533:             %{$$unread{$ressymb}} = ();
  534:             $$unread{$ressymb}{'title'} = $title;
  535:             $$unread{$ressymb}{'symb'} = $symb;
  536:             if (defined($lastreadtime{$ressymb})) {
  537:                 $prevread = $lastreadtime{$ressymb};
  538:             }
  539:             my %contrib = &Apache::lonnet::restore($ressymb,
  540:                              $env{'request.course.id'},$cdom,$crs);
  541:             if ($contrib{'version'}) {
  542:                 for (my $id=1;$id<=$contrib{'version'};$id++) {
  543:                     unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) {
  544:                         if ($prevread <$contrib{$id.':timestamp'}) {
  545:                             $$unread{$ressymb}{$unreadcount} = $id.': '.$contrib{$id.':subject'};
  546:                             $unreadcount ++;
  547:                         }
  548:                     }
  549:                 }
  550:             }
  551:             if ($unreadcount) { push(@{$newdiscussions}, $ressymb); }
  552: 	}
  553: 
  554: # Check for ungraded problems
  555:         if ($resource->is_problem()) {
  556:             my $ctr = 0;
  557:             my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  558:             my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($url,$symb);
  559:             foreach my $student (keys(%$classlist)) {
  560:                 my ($uname,$udom) = split(/:/,$student);
  561:                 my %status=&Apache::grades::student_gradeStatus($url,$symb,$udom,$uname,$partlist);
  562:                 my $submitted = 0;
  563:                 my $ungraded = 0;
  564:                 foreach (keys(%status)) {
  565:                     $submitted = 1 if ($status{$_} ne 'nothing');
  566:                     $ungraded = 1 if ($status{$_} =~ /^ungraded/);
  567:                     my ($foo,$partid,$foo1) = split(/\./,$_);
  568:                     if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
  569:                         $submitted = 0;
  570:                     }
  571:                 }
  572:                 next if (!$submitted || !$ungraded);
  573:                 $ctr ++;
  574:             }
  575:             if ($ctr) {
  576:                 $$ungraded{$symb}{count} = $ctr;
  577:                 $$ungraded{$symb}{title} = $title;
  578:                 push(@{$tograde}, $symb);
  579:             }
  580:         }
  581: 
  582: # Check for bombs
  583:         if ($resource->getErrors()) {
  584:             my $errors = $resource->getErrors();
  585:             $errors =~ s/^,//;
  586:             my @bombs = split(/,/, $errors);
  587:             my $errorcount = scalar(@bombs);
  588:             my $errorlink = '<a href="/adm/email?display='.
  589:                             &Apache::lonnet::escape($bombs[0]).'">'.
  590:                             $title.'</a>';
  591:             $$bombed{$symb}{errorcount} = $errorcount;
  592:             $$bombed{$symb}{errorlink} = $errorlink;
  593:             push(@{$bombs}, $symb);
  594:         }
  595: # Compile maxtries and degree of difficulty for problem parts
  596:         my @parts = @{$resource->parts()};
  597:         my %stats;
  598:         my %lastreset = ();
  599:         my $warning = 0;
  600:         my $rowColor;
  601:         foreach my $part (@parts) {
  602:             %{$stats{$part}} = ();
  603:             my ($attempts,$users,$corrects,$degdiff,$av_attempts);
  604:             if (exists($resourcetracker{$symb."\0".$part."\0attempts"})) {
  605:                 $attempts = $resourcetracker{$symb."\0".$part."\0attempts"};
  606:             }
  607:             if (exists($resourcetracker{$symb."\0".$part."\0users"})) {
  608:                 $users = $resourcetracker{$symb."\0".$part."\0users"};
  609:             }
  610:             if (exists($resourcetracker{$symb."\0".$part."\0correct"})) {
  611:                 $corrects = $resourcetracker{$symb."\0".$part."\0correct"};
  612:             }
  613:             if ($attempts > 0) {
  614:                 $degdiff =  1 - ($corrects/$attempts);
  615:                 $degdiff = sprintf("%.2f",$degdiff);
  616:             }
  617:             if ($users > 0) {
  618:                 $av_attempts = $attempts/$users;
  619:             }
  620:             if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
  621:                 $stats{$part}{degdiff} = $degdiff;
  622:                 $stats{$part}{attempts} = $av_attempts;
  623:                 $stats{$part}{users} = $users;
  624:                 my %resethash = &Apache::lonnet::restore($symb,'nohist_resourcetracker',$cdom,$crs);
  625:                 $lastreset{$part} = &get_counter_resets(\%resethash,$part);
  626:                 $warning = 1;
  627:             }
  628:         }
  629:         if ($warning) {
  630:             if ($warningnum %2 == 1) {
  631:                 $rowColor = $rowColor1;
  632:             } else {
  633:                 $rowColor = $rowColor2;
  634:             }
  635:             $$triggered{$symb}{title} = $resource->title;
  636:             foreach my $part (@parts) {
  637:                 if (exists($stats{$part}{users})) {
  638:                     my $resetname = 'reset_'.&Apache::lonnet::escape($symb."\0".$part);
  639:                     my $resettitle = 'title_'.&Apache::lonnet::escape($symb."\0".$part);
  640:                     if ($$triggered{$symb}{numparts}) {
  641:                         $$triggered{$symb}{text} .= '<tr bgcolor="'.$rowColor.'">'."\n";
  642:                     }
  643:                     if (@parts > 1) {
  644:                         $$triggered{$symb}{text} .= '
  645:                          <td align="right"><small>part - '.$part.'<small></td>';
  646:                     } else {
  647:                         $$triggered{$symb}{text} .= '
  648:                          <td align="right"><small>single part</small></td>';
  649:                     }
  650:                     $$triggered{$symb}{text} .= '
  651:                          <td align="right"><small>'.$stats{$part}{users}.'</small></td>
  652:                          <td align="right"><small>'.$stats{$part}{attempts}.'</small></td>
  653:                          <td align="right"><small>'.$stats{$part}{degdiff}.'</small></td>
  654:                          <td align="right"><small>'.$lastreset{$part}.'</small></td>
  655:                          <td align="right"><small><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&Apache::lonnet::escape($$triggered{$symb}{title}).'" /></td> 
  656:                         </tr>';
  657:                     $$triggered{$symb}{numparts} ++;
  658:                 }
  659:             }
  660:             push(@{$warnings},$symb);
  661:             $warningnum ++;
  662:         }
  663:     }
  664: }
  665: 
  666: sub get_counter_resets {
  667:     my ($resethash,$part) = @_;
  668:     my $lastreset = 'None';
  669:     if ($$resethash{'version'}) {
  670:         for (my $version=1;$version<=$$resethash{'version'};$version++) {
  671:             if (exists($$resethash{$version.':'.$part.'prev_attempts'})) {
  672:                  $lastreset = $$resethash{$version.':timestamp'};
  673:             }
  674:         }
  675:     }
  676:     unless ($lastreset eq 'None') {
  677:         $lastreset = localtime($lastreset);
  678:     }
  679:     return $lastreset;
  680: }
  681: 
  682: sub get_curr_thresholds {
  683:     my ($threshold,$cdom,$crs) = @_;
  684:     my %coursesettings = &Apache::lonnet::dump('environment',
  685:                                      $cdom,$crs,'internal.threshold');
  686:     if (exists($coursesettings{'internal.threshold_av_attempts'})) {
  687:         $$threshold{'av_attempts'} = $coursesettings{'internal.threshold_av_attempts'};
  688:     }
  689:     if (exists($coursesettings{'internal.threshold_degdiff'})) {
  690:         $$threshold{'degdiff'} = $coursesettings{'internal.threshold_degdiff'};
  691:     }
  692:     if (exists($coursesettings{'internal.threshold_numstudents'})) {
  693:         $$threshold{'numstudents'} = $coursesettings{'internal.threshold_numstudents'};
  694:     }
  695: }
  696: 
  697: sub process_reset {
  698:     my ($dom,$crs) = @_;
  699:     my $result = '<b>Counters reset for following problems (and parts):</b><br />';
  700:     my @agg_types = ('attempts','users','correct');
  701:     my %agg_titles = (
  702:                      attempts => 'Number of submissions',
  703:                      users => 'Students with submissions',
  704:                      correct => 'Number of correct submissions',
  705:                      );
  706:     my @resets = ();
  707:     my %titles = ();
  708:     foreach my $key (keys %env) {
  709:         next if ($key !~ /^form\.reset_(.+)$/);
  710:         my $title = &Apache::lonnet::unescape($env{'form.title_'.$1});
  711:         my $reset_item = &Apache::lonnet::unescape($1);
  712:         my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
  713:         my %resethash = ();
  714:         my %aggregates = ();
  715:         my ($symb,$part) = split/\0/,$reset_item;
  716:         foreach my $type (@agg_types) {
  717:             $aggregates{$reset_item."\0".$type} = 0;
  718:             $resethash{$part."\0".'prev_'.$type} = $curr_aggregates{$reset_item."\0".$type};
  719:         }  
  720:         my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
  721:                           $dom,$crs);
  722:         if ($putresult eq 'ok') {
  723:             my $storeresult = &Apache::lonnet::cstore(\%resethash,$symb,'nohist_resourcetracker',$dom,$crs);
  724:             $result .= $title.' -part '.$part.': ';
  725:             my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
  726:             foreach my $type (@agg_types) {
  727:                 $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
  728:             }
  729:             $result =~ s/; $//;
  730:             $result .= '<br />';
  731:         } else {
  732:             $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
  733:         }
  734:     }
  735:     return $result;
  736: }
  737: 
  738: sub process_update {
  739:     my ($dom,$crs,$threshold_titles) = @_;
  740:     my $setoutput = '<b>Changes to threshold(s):</b><br />';
  741:     foreach (keys %env) {
  742:         next if ($_!~/^form\.(.+)\_setparmval$/);
  743:         my $name  = $1;
  744:         my $value = $env{'form.'.$name.'_value'};
  745:         if ($name && defined($value)) {
  746:             my $put_result = &Apache::lonnet::put('environment',
  747:                                                   {$name=>$value},$dom,$crs);
  748:            
  749:             my ($shortname) = ($name =~ /^internal\.threshold_(.+)$/); 
  750:             if ($put_result eq 'ok') {
  751:                 $setoutput.=&mt('Set threshold for [_1] to [_2]',
  752: 				'<b>'.$$threshold_titles{$shortname}.'</b>',
  753: 				'<b>'.$value.'</b>').'<br />';
  754: 	    } else {
  755:                 $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
  756: 				'<b>'.$name.'</b>','<b>'.$value.'</b>',
  757: 				'<tt>'.$put_result.'</tt>').'<br />';
  758:             }
  759:         }
  760:     }
  761:     return $setoutput;
  762: }
  763: 
  764: sub getmail {
  765:     my ($newmsgs,$critmsgs) = @_;
  766: # Check for unread mail in course
  767:     my $msgcount = 0;
  768: 
  769:     my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
  770:     foreach my $message (@messages) {
  771: 	my $msgid=&Apache::lonnet::escape($message);
  772:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
  773:             &Apache::lonmsg::unpackmsgid($msgid);
  774:         if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
  775:             if (defined($sendtime) && $sendtime!~/error/) {
  776:                 my $numsendtime = $sendtime;
  777:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
  778:                 if ($status eq 'new') {
  779:                     $msgcount ++;
  780:                     if ($shortsubj eq '') {
  781:                         $shortsubj = &mt('No subject');
  782:                     }
  783:                     $shortsubj = &Apache::lonnet::unescape($shortsubj);
  784:                     push(@{$newmsgs}, {
  785:                         msgid    => $msgid,
  786:                         sendtime => $sendtime,
  787:                         shortsub => $shortsubj,
  788:                         from     => $fromname,
  789:                         fromdom  => $fromdom
  790:                         });
  791:                 }
  792:             }
  793:         }
  794:     }
  795: 
  796: # Check for critical messages in course
  797:     my %what=&Apache::lonnet::dump('critical');
  798:     my $result = '';
  799:     my $critmsgcount = 0;
  800:     foreach my $msgid (sort(keys(%what))) {
  801:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
  802:             &Apache::lonmsg::unpackmsgid($msgid);
  803:         if (($fromcid) && ($fromcid eq  $env{'request.course.id'})) {
  804:             if (defined($sendtime) && $sendtime!~/error/) {
  805:                 my $numsendtime = $sendtime;
  806:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
  807:                 $critmsgcount ++;
  808:                 if ($shortsubj eq '') {
  809:                     $shortsubj = &mt('No subject');
  810:                 }
  811:                 $shortsubj = &Apache::lonnet::unescape($shortsubj);
  812:                 push(@{$critmsgs}, {
  813:                         msgid    => $msgid,
  814:                         sendtime => $sendtime,
  815:                         shortsub => $shortsubj,
  816:                         from     => $fromname,
  817:                         fromdom  => $fromdom
  818:                         });
  819:             }
  820:         }
  821:     }
  822:     return ($msgcount,$critmsgcount);
  823: }
  824: 
  825: sub cmp_title {
  826:     my ($atitle,$btitle) = (lc($_[0]->compTitle),lc($_[1]->compTitle));
  827:     $atitle=~s/^\s*//;
  828:     $btitle=~s/^\s*//;
  829:     return $atitle cmp $btitle;
  830: }
  831: 
  832: 1;

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