File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.24: download - view: text, annotated - select for diffs
Thu Jul 14 21:30:25 2005 UTC (18 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- make lonwhats new faster (BUG#4240)

    1: #
    2: # $Id: lonwhatsnew.pm,v 1.24 2005/07/14 21:30:25 albertel Exp $
    3: #
    4: # Copyright Michigan State University Board of Trustees
    5: #
    6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    7: #
    8: # LON-CAPA is free software; you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation; either version 2 of the License, or
   11: # (at your option) any later version.
   12: #
   13: # LON-CAPA is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16: # GNU General Public License for more details.
   17: #
   18: # You should have received a copy of the GNU General Public License
   19: # along with LON-CAPA; if not, write to the Free Software
   20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21: #
   22: # /home/httpd/html/adm/gpl.txt
   23: #
   24: # http://www.lon-capa.org/
   25: #
   26: 
   27: 
   28: package Apache::lonwhatsnew;
   29: 
   30: use strict;
   31: use lib qw(/home/httpd/lib/perl);
   32: use Apache::lonnet;
   33: use Apache::loncommon();
   34: use Apache::lonhtmlcommon();
   35: use Apache::lonlocal;
   36: use Apache::loncoursedata();
   37: use Apache::lonnavmaps();
   38: use Apache::lonuserstate;
   39: use Apache::Constants qw(:common :http);
   40: use Time::Local;
   41: use GDBM_File;
   42: 
   43: #----------------------------
   44: # handler
   45: #
   46: #----------------------------
   47: 
   48: sub handler {
   49:     my $r = shift;
   50:     if ($r->header_only) {
   51:         &Apache::loncommon::content_type($r,'text/html');
   52:         $r->send_http_header;
   53:         return OK;
   54:     }
   55:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['command']);
   56: 
   57:     my $command;
   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: 
  212:     &get_curr_thresholds(\%threshold,$cdom,$crs);
  213:     &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,%res_title);
  214:     my ($msgcount,$critmsgcount) = &getmail(\@newmsgs,\@critmsgs);
  215: 
  216:     $r->print('<br /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
  217: 
  218: ## UNGRADED ITEMS ##
  219:     $r->print(<<END);
  220:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  221:             <tr><td>
  222:              <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  223:               <tr>
  224:                <td bgcolor="$tabbg"><b>Problems requiring handgrading</b></td></tr>
  225:                   <tr>
  226:                    <td bgcolor="#ffffff">
  227:                      <table cellpadding="2" cellspacing="0" border="0" width="100%">
  228: END
  229: 
  230:     if (@tograde > 0) {
  231:         $r->print('<tr bgcolor="#cccccc"><td><b><small>Problem Name</small></b></td><td align="right"><b><small>Number ungraded</small></b></td></tr>');
  232:         my $rowNum = 0;
  233:         foreach my $res (@tograde) {
  234:             if ($rowNum %2 == 1) {
  235:                 $rowColor = $rowColor1;
  236:             } else {
  237:                 $rowColor = $rowColor2;
  238:             }
  239:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
  240:             my $linkurl=&Apache::lonnet::clutter($url);
  241:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
  242: 
  243:             $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>');
  244:             $rowNum ++;
  245:         }
  246:     } else {
  247:         $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>');
  248:     }
  249:     $r->print('</table></td></tr></table></td></tr></table><br />');
  250: 
  251: ## BOMBS ##
  252:      $r->print(<<"END");
  253:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  254:             <tr>
  255:              <td>
  256:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  257:                <tr>
  258:                 <td bgcolor="$tabbg"><b>Problems with errors</b></td>
  259:                </tr>
  260:                 <tr>
  261:                 <td bgcolor="#ffffff">
  262:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  263: END
  264:      my $bombnum = 0;
  265:      if (@bombs > 0) {
  266:         $r->print('<tr bgcolor="#cccccc"><td><b><small>Resource</small></b></td><td align="right"><b><small>Number of errors</small></b></td></tr>');
  267:         @bombs = sort { &cmp_title($a,$b,\%res_title) } @bombs;
  268:         foreach my $bomb (@bombs) {
  269:             if ($bombnum %2 == 1) {
  270: 		$rowColor = $rowColor1;
  271:             } else {
  272:                 $rowColor = $rowColor2;
  273:             }
  274:             $r->print('<tr bgcolor="'.$rowColor.'"><td><small>'.$bombed{$bomb}{errorlink}.'</small></td><td align="right"><small>'.$bombed{$bomb}{errorcount}.'</small></td></tr>');
  275:             $bombnum ++;
  276:         }
  277:     } else {
  278:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>No problems with errors</small></i></b></center><br /></td></tr>');
  279:     }
  280:     $r->print('</table></td></tr></table></td></tr></table><br />');
  281: 
  282: # DEGDIFF AND AV. TRIES TRIGGERS
  283:     $r->print(<<"END");
  284:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  285:             <tr>
  286:              <td>
  287:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  288:                <tr>
  289:                 <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>
  290:                </tr>
  291:                <tr>
  292:                 <td bgcolor="$tabbg" align="right"><a href="/adm/whatsnew?command=chgthreshold"><b><small>Change thresholds?</small></b></a></td>
  293:                </tr>
  294:                 <tr>
  295:                 <td bgcolor="#ffffff">
  296:                  <table width="100%" cellspacing="2" cellpadding="2" border="0">
  297: END
  298:     my $warningnum = 0;
  299:     if (@warnings > 0) {
  300:         @warnings = sort { &cmp_title($a,$b,\%res_title) } @warnings;
  301:         $r->print('<form name="reset_tracking" method="post">'.
  302:                  '  <input type="hidden" name="action" value="reset" />'."\n");
  303:         $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>');
  304:         foreach my $res (@warnings) {
  305:             if ($warningnum %2 == 1) {
  306:                 $rowColor = $rowColor1;
  307:             } else {
  308:                 $rowColor = $rowColor2;
  309:             }
  310:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
  311:             my $linkurl=&Apache::lonnet::clutter($url);
  312:             my $rowspan;
  313:             if ($triggered{$res}{numparts} > 1) {
  314:                 $rowspan = 'rowspan="'.$triggered{$res}{numparts}.'"';
  315:             }
  316:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
  317:             $r->print('<tr bgcolor="'.$rowColor.'"><td '.$rowspan.'><a href="'.$linkurl.'"><small>'.$triggered{$res}{title}.'</small></a></td>'.$triggered{$res}{text});
  318:             $warningnum ++;
  319:         }
  320:         $r->print('<tr bgcolor="#cccccc"><td colspan="7" align="right"><br /><b><small><input type="submit" name="counters" value="Reset counters to 0" /></form>'); 
  321:     } else {
  322:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>No problems satisfy threshold criteria.</small></i></b></center><br /></td></tr>');
  323:     }
  324:     $r->print('</table></td></tr></table></td></tr></table><br />');
  325: 
  326:     $r->print('</td><td width="5%">&nbsp;</td><td align="left" valign="top" width-"50%">');
  327: 
  328: ## UNREAD COURSE DISCUSSION POSTS ##
  329:     $r->print(<<"END");
  330:               <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  331:                <tr><td>
  332:                 <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  333:                  <tr>
  334:                   <td bgcolor="$tabbg"><b>Unread course discussion posts</b></td>
  335:                  </tr>
  336:                  <tr>
  337:                    <td bgcolor="#ffffff">
  338:                    <table cellpadding="2" cellspacing="0" border="0" width="100%">
  339: END
  340:                                                                                   
  341:     if (@newdiscussions > 0) {
  342:         $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>');
  343:         @newdiscussions = sort { &cmp_title($a,$b,\%res_title) } @newdiscussions;
  344:         my $rowNum = 0;
  345:         foreach my $ressymb (@newdiscussions) {
  346:             my $forum_title = $unread{$ressymb}{'title'};
  347:             my $type = 'Resource';
  348:             my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
  349:             if ($feedurl =~ /bulletinboard/) {
  350:                 $type = 'Bulletin Board';
  351:             }
  352:             my $unreadnum = keys(%{$unread{$ressymb}});
  353:             $unreadnum = $unreadnum - 2;
  354:             if ($unreadnum > 0) {
  355:                 if ($rowNum %2 == 1) {
  356:                     $rowColor = $rowColor1;
  357:                 } else {
  358:                     $rowColor = $rowColor2;
  359:                 }
  360:                 $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>');
  361:                 $rowNum ++;
  362:             }
  363:         }
  364:     } else {
  365:         $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>');
  366:     }
  367:     $r->print('</table></td></tr></table></td></tr></table><br />');
  368: 
  369: ## MESSAGES ##
  370:     $r->print(<<END);
  371:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  372:             <tr>
  373:              <td>
  374:               <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  375:                <tr>
  376:                 <td bgcolor="$tabbg"><b>New course messages</b></td>
  377:                </tr>
  378:                <tr>
  379:                 <td bgcolor="#ffffff">
  380:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  381: END
  382:     if ($msgcount > 0) {
  383:         $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>');
  384:         my $rowNum = 0;
  385:         my $mailcount = 1; 
  386:         foreach my $msg (@newmsgs) {
  387:             if ($rowNum %2 == 1) {
  388:                 $rowColor = $rowColor1;
  389:             } else {
  390:                 $rowColor = $rowColor2;
  391:             }
  392:             $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>');
  393:             $rowNum ++;
  394:             $mailcount ++;
  395:         }
  396:     } else {
  397:         $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>');
  398:     }
  399: 
  400:     $r->print('</table></td></tr></table></td></tr></table><br />');
  401: 
  402:     $r->print(<<END);
  403:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  404:             <tr>
  405:              <td>
  406:               <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  407:                <tr>
  408:                 <td bgcolor="$tabbg"><b>New critical messages in course</b></td>
  409:                </tr>
  410:                <tr>                 <td bgcolor="#ffffff">
  411:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  412: END
  413: 
  414:     if ($critmsgcount > 0) {
  415:         $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>');
  416:         my $rowNum = 0;
  417:         my $mailcount = 1;
  418:         foreach my $msg (@critmsgs) {
  419:             if ($rowNum %2 == 1) {
  420:                 $rowColor = $rowColor1;
  421:             } else {
  422:                 $rowColor = $rowColor2;
  423:             }
  424:             $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>');
  425:             $rowNum ++;
  426:             $mailcount ++;
  427:         }
  428:     } else {
  429:         $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>');
  430:     }
  431:                                                                                
  432:     $r->print('</table></td></tr></table></td></tr></table><br />');
  433: 
  434:     $r->print('
  435:            </table>
  436:           </td>
  437:          </tr>
  438:         </table>');
  439:     $r->print('</td></tr></table>');
  440: }
  441: 
  442: #-------------------------------
  443: # display_config_box
  444: #
  445: # Display the threshold setting screen 
  446: #
  447: #-------------------------------
  448:                                                                                 
  449: sub display_config_box() {
  450:     my ($r,$command,$tabbg,$threshold_titles,$cdom,$crs) = @_;
  451:     my %threshold = ();
  452:     my $rowColor1 = "#ffffff";
  453:     my $rowColor2 = "#eeeeee";
  454:     my $rowColor;
  455: 
  456:     my @thresholditems = ("av_attempts","degdiff","numstudents");
  457:     my %threshold_titles = (
  458:                          av_attempts => 'Average number of attempts',
  459:                          degdiff => 'Degree of difficulty',
  460:                          numstudents => 'Total number of students with submissions',
  461:                          );
  462:     &get_curr_thresholds(\%threshold,$cdom,$crs);
  463: 
  464:     $r->print('<br /><form name="thresholdform" method="post"><table border="0" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">
  465:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  466:             <tr>
  467:              <td>
  468:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">
  469:                 <tr>
  470:                 <td bgcolor="#ffffff">
  471:                  <table cellspacing="0" cellpadding="4" border="0">
  472:      <tr bgcolor="'.$tabbg.'">
  473:       <th>Threshold Name</th>
  474:       <th>Current value</th>
  475:       <th>Change?</th>
  476:      </tr>');
  477:     my $rowNum =0;
  478:     foreach my $type (@thresholditems) {
  479:         my $parameter = 'internal.threshold_'.$type;
  480: # onchange is javascript to automatically check the 'Set' button.
  481:         my $onchange = 'onFocus="javascript:window.document.forms'.
  482:               "['thresholdform'].elements['".$parameter."_setparmval']".
  483:               '.checked=true;"';
  484:         if ($rowNum %2 == 1) {
  485:             $rowColor = $rowColor1;
  486:         } else {
  487:             $rowColor = $rowColor2;
  488:         }
  489:         $r->print('
  490:      <tr bgcolor="'.$rowColor.'">
  491:       <td>'.$threshold_titles{$type}.'</td>
  492:       <td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
  493:                                             $threshold{$type},
  494:                                             10,$onchange).'</td>
  495:       <td>'
  496:            .&Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
  497:       '</td>
  498:      </tr>');
  499:         $rowNum ++;
  500:     }
  501:     $r->print('</table></td></tr></table></td></tr></table>
  502:            <br /><input type="submit" name="threshold" value="Make changes" />
  503:                  <input type="hidden" name="action" value="update" />
  504:                </form>');
  505: }
  506: 
  507: sub getitems {
  508:     my ($unread,$ungraded,$bombed,$triggered,$newdiscussions,$tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs,$res_title) = @_;
  509:     my $navmap = Apache::lonnavmaps::navmap->new();
  510:     my @allres=$navmap->retrieveResources();
  511:     my %discussiontime = &Apache::lonnet::dump('discussiontimes',$cdom,$crs);
  512:     my %lastread = &Apache::lonnet::dump('nohist_'.$env{'request.course.id'}.
  513:                 '_discuss',$env{'user.domain'},$env{'user.name'},'lastread');
  514:     my %lastreadtime = ();
  515:     my @discussions = ();
  516:     my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
  517: 
  518:     my %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',
  519:                $cdom,$crs);
  520:     my $warningnum = 0;
  521:     foreach my $key (keys(%lastread)) {
  522:         my $newkey = $key;
  523:         $newkey =~ s/_lastread$//;
  524:         $lastreadtime{$newkey} = $lastread{$key};
  525:     }
  526:     foreach my $resource (@allres) {
  527:         my $result = '';
  528:         my $applies = 0;
  529:         my $symb = $resource->symb();
  530: #        %{$$bombed{$symb}} = ();
  531:         %{$$ungraded{$symb}} = ();
  532:         %{$$triggered{$symb}} = ();
  533:         $$triggered{$symb}{numparts} = 0;
  534:         my $title = $resource->compTitle();
  535:         $$res_title{$symb} = $title;
  536:         my $ressymb = $resource->wrap_symb();
  537: # Check for unread discussion postings
  538: 	if ($resource->hasDiscussion()) {
  539:             push(@discussions,$ressymb);
  540:             my $prevread = 0;
  541:             my $unreadcount = 0;
  542:             %{$$unread{$ressymb}} = ();
  543:             $$unread{$ressymb}{'title'} = $title;
  544:             $$unread{$ressymb}{'symb'} = $symb;
  545:             if (defined($lastreadtime{$ressymb})) {
  546:                 $prevread = $lastreadtime{$ressymb};
  547:             }
  548:             my %contrib = &Apache::lonnet::restore($ressymb,
  549:                              $env{'request.course.id'},$cdom,$crs);
  550:             if ($contrib{'version'}) {
  551:                 for (my $id=1;$id<=$contrib{'version'};$id++) {
  552:                     unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) {
  553:                         if ($prevread <$contrib{$id.':timestamp'}) {
  554:                             $$unread{$ressymb}{$unreadcount} = $id.': '.$contrib{$id.':subject'};
  555:                             $unreadcount ++;
  556:                         }
  557:                     }
  558:                 }
  559:             }
  560:             if ($unreadcount) { push(@{$newdiscussions}, $ressymb); }
  561: 	}
  562: 
  563: # Check for ungraded problems
  564:         if ($resource->is_problem()) {
  565:             my $ctr = 0;
  566:             my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  567:             my ($partlist,$handgrade,$responseType) = 
  568: 		&Apache::grades::response_type($url,$symb);
  569: 	    my $handgradeable;
  570: 	    foreach my $value (values(%{$handgrade})) {
  571: 		if ($value eq 'yes') { $handgradeable=1; last; }
  572: 	    }
  573: 	    if ($handgradeable) {
  574: 		foreach my $student (keys(%$classlist)) {
  575: 		    my ($uname,$udom) = split(/:/,$student);
  576: 		    my %status=&Apache::grades::student_gradeStatus($url,$symb,$udom,$uname,$partlist);
  577: 		    my $submitted = 0;
  578: 		    my $ungraded = 0;
  579: 		    foreach (keys(%status)) {
  580: 			$submitted = 1 if ($status{$_} ne 'nothing');
  581: 			$ungraded = 1 if ($status{$_} =~ /^ungraded/);
  582: 			my ($foo,$partid,$foo1) = split(/\./,$_);
  583: 			if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
  584: 			    $submitted = 0;
  585: 			}
  586: 		    }
  587: 		    next if (!$submitted || !$ungraded);
  588: 		    $ctr ++;
  589: 		}
  590: 		if ($ctr) {
  591: 		    $$ungraded{$symb}{count} = $ctr;
  592: 		    $$ungraded{$symb}{title} = $title;
  593: 		    push(@{$tograde}, $symb);
  594: 		}
  595: 	    }
  596:         }
  597: 
  598: # Check for bombs
  599:         if ($resource->getErrors()) {
  600:             my $errors = $resource->getErrors();
  601: 	    $errors =~ s/^,//;
  602:             my @bombs = split(/,/, $errors);
  603:             my $errorcount = scalar(@bombs);
  604:             my $errorlink = '<a href="/adm/email?display='.
  605:                             &Apache::lonnet::escape($bombs[0]).'">'.
  606:                             $title.'</a>';
  607:             $$bombed{$symb}{errorcount} = $errorcount;
  608:             $$bombed{$symb}{errorlink} = $errorlink;
  609:             push(@{$bombs}, $symb);
  610:         }
  611: # Compile maxtries and degree of difficulty for problem parts
  612:         my @parts = @{$resource->parts()};
  613:         my %stats;
  614:         my %lastreset = ();
  615:         my $warning = 0;
  616:         my $rowColor;
  617:         foreach my $part (@parts) {
  618:             %{$stats{$part}} = ();
  619:             my ($attempts,$users,$corrects,$degdiff,$av_attempts);
  620:             if (exists($resourcetracker{$symb."\0".$part."\0attempts"})) {
  621:                 $attempts = $resourcetracker{$symb."\0".$part."\0attempts"};
  622:             }
  623:             if (exists($resourcetracker{$symb."\0".$part."\0users"})) {
  624:                 $users = $resourcetracker{$symb."\0".$part."\0users"};
  625:             }
  626:             if (exists($resourcetracker{$symb."\0".$part."\0correct"})) {
  627:                 $corrects = $resourcetracker{$symb."\0".$part."\0correct"};
  628:             }
  629:             if ($attempts > 0) {
  630:                 $degdiff =  1 - ($corrects/$attempts);
  631:                 $degdiff = sprintf("%.2f",$degdiff);
  632:             }
  633:             if ($users > 0) {
  634:                 $av_attempts = $attempts/$users;
  635:                 $av_attempts = sprintf("%.2f",$av_attempts);
  636:             }
  637:             if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
  638:                 $stats{$part}{degdiff} = $degdiff;
  639:                 $stats{$part}{attempts} = $av_attempts;
  640:                 $stats{$part}{users} = $users;
  641: 		$lastreset{$part} = $resourcetracker{$symb."\0".$part."\0resettime"};
  642:                 $warning = 1;
  643:             }
  644:         }
  645:         if ($warning) {
  646:             if ($warningnum %2 == 1) {
  647:                 $rowColor = $rowColor1;
  648:             } else {
  649:                 $rowColor = $rowColor2;
  650:             }
  651:             $$triggered{$symb}{title} = $resource->title;
  652:             foreach my $part (@parts) {
  653:                 if (exists($stats{$part}{users})) {
  654:                     my $resetname = 'reset_'.&Apache::lonnet::escape($symb."\0".$part);
  655:                     my $resettitle = 'title_'.&Apache::lonnet::escape($symb."\0".$part);
  656:                     if ($$triggered{$symb}{numparts}) {
  657:                         $$triggered{$symb}{text} .= '<tr bgcolor="'.$rowColor.'">'."\n";
  658:                     }
  659:                     if (@parts > 1) {
  660:                         $$triggered{$symb}{text} .= '
  661:                          <td align="right"><small>part - '.$part.'<small></td>';
  662:                     } else {
  663:                         $$triggered{$symb}{text} .= '
  664:                          <td align="right"><small>single part</small></td>';
  665:                     }
  666:                     $$triggered{$symb}{text} .= '
  667:                          <td align="right"><small>'.$stats{$part}{users}.'</small></td>
  668:                          <td align="right"><small>'.$stats{$part}{attempts}.'</small></td>
  669:                          <td align="right"><small>'.$stats{$part}{degdiff}.'</small></td>
  670:                          <td align="right"><small>'.$lastreset{$part}.'</small></td>
  671:                          <td align="right"><small><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&Apache::lonnet::escape($$triggered{$symb}{title}).'" /></td> 
  672:                         </tr>';
  673:                     $$triggered{$symb}{numparts} ++;
  674:                 }
  675:             }
  676:             push(@{$warnings},$symb);
  677:             $warningnum ++;
  678:         }
  679:     }
  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 %aggregates = ();
  714:         my ($symb,$part) = split(/\0/,$reset_item);
  715:         foreach my $type (@agg_types) {
  716:             $aggregates{$reset_item."\0".$type} = 0;
  717:         }  
  718: 	$aggregates{$reset_item."\0".'resettime'} = time;
  719:         my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
  720:                           $dom,$crs);
  721:         if ($putresult eq 'ok') {
  722:             $result .= $title.' -part '.$part.': ';
  723:             my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
  724:             foreach my $type (@agg_types) {
  725:                 $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
  726:             }
  727:             $result =~ s/; $//;
  728:             $result .= '<br />';
  729:         } else {
  730:             $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
  731:         }
  732:     }
  733:     return $result;
  734: }
  735: 
  736: sub process_update {
  737:     my ($dom,$crs,$threshold_titles) = @_;
  738:     my $setoutput = '<b>Changes to threshold(s) for problem tracking:</b><br />';
  739:     foreach (keys %env) {
  740:         next if ($_!~/^form\.(.+)\_setparmval$/);
  741:         my $name  = $1;
  742:         my $value = $env{'form.'.$name.'_value'};
  743:         if ($name && defined($value)) {
  744:             my $put_result = &Apache::lonnet::put('environment',
  745:                                                   {$name=>$value},$dom,$crs);
  746:            
  747:             my ($shortname) = ($name =~ /^internal\.threshold_(.+)$/); 
  748:             if ($put_result eq 'ok') {
  749:                 $setoutput.=&mt('Set threshold for [_1] to [_2]',
  750: 				'<b>'.$$threshold_titles{$shortname}.'</b>',
  751: 				'<b>'.$value.'</b>').'<br />';
  752: 	    } else {
  753:                 $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
  754: 				'<b>'.$name.'</b>','<b>'.$value.'</b>',
  755: 				'<tt>'.$put_result.'</tt>').'<br />';
  756:             }
  757:         }
  758:     }
  759:     return $setoutput;
  760: }
  761: 
  762: sub getmail {
  763:     my ($newmsgs,$critmsgs) = @_;
  764: # Check for unread mail in course
  765:     my $msgcount = 0;
  766: 
  767:     my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
  768:     foreach my $message (@messages) {
  769: 	my $msgid=&Apache::lonnet::escape($message);
  770:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
  771:             &Apache::lonmsg::unpackmsgid($msgid);
  772:         if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
  773:             if (defined($sendtime) && $sendtime!~/error/) {
  774:                 my $numsendtime = $sendtime;
  775:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
  776:                 if ($status eq 'new') {
  777:                     $msgcount ++;
  778:                     if ($shortsubj eq '') {
  779:                         $shortsubj = &mt('No subject');
  780:                     }
  781:                     $shortsubj = &Apache::lonnet::unescape($shortsubj);
  782:                     push(@{$newmsgs}, {
  783:                         msgid    => $msgid,
  784:                         sendtime => $sendtime,
  785:                         shortsub => $shortsubj,
  786:                         from     => $fromname,
  787:                         fromdom  => $fromdom
  788:                         });
  789:                 }
  790:             }
  791:         }
  792:     }
  793: 
  794: # Check for critical messages in course
  795:     my %what=&Apache::lonnet::dump('critical');
  796:     my $result = '';
  797:     my $critmsgcount = 0;
  798:     foreach my $msgid (sort(keys(%what))) {
  799:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
  800:             &Apache::lonmsg::unpackmsgid($msgid);
  801:         if (($fromcid) && ($fromcid eq  $env{'request.course.id'})) {
  802:             if (defined($sendtime) && $sendtime!~/error/) {
  803:                 my $numsendtime = $sendtime;
  804:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
  805:                 $critmsgcount ++;
  806:                 if ($shortsubj eq '') {
  807:                     $shortsubj = &mt('No subject');
  808:                 }
  809:                 $shortsubj = &Apache::lonnet::unescape($shortsubj);
  810:                 push(@{$critmsgs}, {
  811:                         msgid    => $msgid,
  812:                         sendtime => $sendtime,
  813:                         shortsub => $shortsubj,
  814:                         from     => $fromname,
  815:                         fromdom  => $fromdom
  816:                         });
  817:             }
  818:         }
  819:     }
  820:     return ($msgcount,$critmsgcount);
  821: }
  822: 
  823: sub cmp_title {
  824:     my ($a,$b,$res_title) = @_;
  825:     my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
  826:     $atitle=~s/^\s*//;
  827:     $btitle=~s/^\s*//;
  828:     return $atitle cmp $btitle;
  829: }
  830: 
  831: 1;

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