File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.15: download - view: text, annotated - select for diffs
Wed Jun 1 19:24:50 2005 UTC (19 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Pass course domain and course number to subroutines.  Correction to naming of db key for last reset.

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

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