File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.31: download - view: text, annotated - select for diffs
Wed Sep 21 18:20:22 2005 UTC (18 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_0_X, version_2_0_2, HEAD
Do not include handgradeable parts in threshold-based problem display.

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

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