File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.17: download - view: text, annotated - select for diffs
Sat Jun 4 03:36:36 2005 UTC (18 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- chanign it so that no longer storing and restoring to a putted DB

    1: #
    2: # $Id: lonwhatsnew.pm,v 1.17 2005/06/04 03:36:36 albertel Exp $
    3: #
    4: # Copyright Michigan State University Board of Trustees
    5: #
    6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    7: #
    8: # LON-CAPA is free software; you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation; either version 2 of the License, or
   11: # (at your option) any later version.
   12: #
   13: # LON-CAPA is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16: # GNU General Public License for more details.
   17: #
   18: # You should have received a copy of the GNU General Public License
   19: # along with LON-CAPA; if not, write to the Free Software
   20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21: #
   22: # /home/httpd/html/adm/gpl.txt
   23: #
   24: # http://www.lon-capa.org/
   25: #
   26: 
   27: 
   28: package Apache::lonwhatsnew;
   29: 
   30: use strict;
   31: use lib qw(/home/httpd/lib/perl);
   32: use Apache::lonnet;
   33: use Apache::loncommon();
   34: use Apache::lonhtmlcommon();
   35: use Apache::lonlocal;
   36: use Apache::loncoursedata();
   37: use Apache::lonnavmaps();
   38: use Apache::Constants qw(:common :http);
   39: use Time::Local;
   40: 
   41: #----------------------------
   42: # handler
   43: #
   44: #----------------------------
   45: 
   46: sub handler {
   47:     my $r = shift;
   48:     if ($r->header_only) {
   49:         &Apache::loncommon::content_type($r,'text/html');
   50:         $r->send_http_header;
   51:         return OK;
   52:     }
   53:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['command']);
   54: 
   55:     my $command;
   56:     if ($env{'form.action'} eq 'reset') {
   57:         $command = 'reset';
   58:     } elsif ($env{'form.action'} eq 'update') {
   59:         $command = 'update';
   60:     } else {
   61:         $command = $env{'form.command'};
   62:     }
   63: 
   64:     &Apache::loncommon::content_type($r,'text/html');
   65:     $r->send_http_header;
   66:     $r->print(&display_header());
   67:     if (! (($env{'request.course.fn'}) && (&Apache::lonnet::allowed('vsa',$env{'request.course.id'})))) {
   68:         # Not in a course, or not allowed to modify parms
   69:         $env{'user.error.msg'}="/adm/whatsnew:vsa:0:0:Cannot display student activity";
   70:         return HTTP_NOT_ACCEPTABLE;
   71:     }
   72: 
   73:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   74:     if ($command eq 'chgthreshold') {
   75:         &Apache::lonhtmlcommon::add_breadcrumb
   76:             ({href=>'/adm/whatsnew?command=threshold',
   77:               text=>"Change thresholds"});
   78:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
   79:             (undef,'Course Action Items','Course_Action_Items_Thresholds'));
   80:     } else {
   81:         &Apache::lonhtmlcommon::add_breadcrumb
   82:             ({href=>'/adm/whatsnew',
   83:               text=>"Display Action Items"});
   84:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
   85:             (undef,'Course Action Items','Course_Action_Items_Display'));
   86:     }
   87:     &display_main_box($r,$command);
   88:     return OK;
   89: }
   90: 
   91: #------------------------------
   92: # display_main_box
   93: #
   94: # Display all the elements within the main box
   95: #------------------------------
   96:                                                                                 
   97: sub display_main_box {
   98:     my ($r,$command) = @_;
   99:     my $domain=&Apache::loncommon::determinedomain();
  100:     my $tabbg=&Apache::loncommon::designparm('coordinator.tabbg',$domain);
  101:     $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
  102: 
  103:     my %threshold_titles = (
  104:                          av_attempts => 'Average number of attempts',
  105:                          degdiff => 'Degree of difficulty',
  106:                          numstudents => 'Total number of students with submissions',
  107:     );
  108:     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:     my %res_title = ();
  169: 
  170:     my $domain=&Apache::loncommon::determinedomain();
  171:     my $function;
  172:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
  173:         $function='coordinator';
  174:     }
  175:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
  176:         $function='admin';
  177:     }
  178: 
  179:     my %threshold = (
  180:                       av_attempts => 0,
  181:                       degdiff => 0.01,
  182:                       numstudents => 0,
  183:                      );
  184: 
  185:     my $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
  186:     my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
  187: 
  188:     unless ($env{'request.course.id'}) {
  189:         $r->print('<br /><b><center>You are accessing an invalid course</center></b><br /><br />');
  190:         return;
  191:     }
  192: 
  193:     my $result;
  194: 
  195:     if ($command eq 'reset') {
  196:         $result = &process_reset($cdom,$crs);
  197:     } elsif ($command eq 'update') {
  198:         $result = &process_update($cdom,$crs,$threshold_titles);
  199:     }
  200:     if ($result) {
  201:         $r->print($result.'<hr width="100%" />');
  202:     }
  203: 
  204:     &get_curr_thresholds(\%threshold,$cdom,$crs);
  205:     &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,%res_title);
  206:     my ($msgcount,$critmsgcount) = &getmail(\@newmsgs,\@critmsgs);
  207: 
  208:     $r->print('<br /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
  209: 
  210: ## UNGRADED ITEMS ##
  211:     $r->print(<<END);
  212:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  213:             <tr><td>
  214:              <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  215:               <tr>
  216:                <td bgcolor="$tabbg"><b>Problems requiring handgrading</b></td></tr>
  217:                   <tr>
  218:                    <td bgcolor="#ffffff">
  219:                      <table cellpadding="2" cellspacing="0" border="0" width="100%">
  220: END
  221: 
  222:     if (@tograde > 0) {
  223:         $r->print('<tr bgcolor="#cccccc"><td><b><small>Problem Name</small></b></td><td align="right"><b><small>Number ungraded</small></b></td></tr>');
  224:         my $rowNum = 0;
  225:         foreach my $res (@tograde) {
  226:             if ($rowNum %2 == 1) {
  227:                 $rowColor = $rowColor1;
  228:             } else {
  229:                 $rowColor = $rowColor2;
  230:             }
  231:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
  232:             my $linkurl=&Apache::lonnet::clutter($url);
  233:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
  234: 
  235:             $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>');
  236:             $rowNum ++;
  237:         }
  238:     } else {
  239:         $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>');
  240:     }
  241:     $r->print('</table></td></tr></table></td></tr></table><br />');
  242: 
  243: ## BOMBS ##
  244:      $r->print(<<"END");
  245:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  246:             <tr>
  247:              <td>
  248:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  249:                <tr>
  250:                 <td bgcolor="$tabbg"><b>Problems with errors</b></td>
  251:                </tr>
  252:                 <tr>
  253:                 <td bgcolor="#ffffff">
  254:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  255: END
  256:      my $bombnum = 0;
  257:      if (@bombs > 0) {
  258:         $r->print('<tr bgcolor="#cccccc"><td><b><small>Resource</small></b></td><td align="right"><b><small>Number of errors</small></b></td></tr>');
  259:         @bombs = sort { &cmp_title($a,$b,\%res_title) } @bombs;
  260:         foreach my $bomb (@bombs) {
  261:             if ($bombnum %2 == 1) {
  262:                  $rowColor = $rowColor1;
  263:             } else {
  264:                 $rowColor = $rowColor2;
  265:             }
  266:             $r->print('<tr bgcolor="'.$rowColor.'"><td><small>'.$bombed{$bomb}{errorlink}.'</small></td><td align="right"><small>'.$bombed{$bomb}{errorcount}.'</small></td></tr>');
  267:             $bombnum ++;
  268:         }
  269:     } else {
  270:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>No problems with errors</small></i></b></center><br /></td></tr>');
  271:     }
  272:     $r->print('</table></td></tr></table></td></tr></table><br />');
  273: 
  274: # DEGDIFF AND AV. TRIES TRIGGERS
  275:     $r->print(<<"END");
  276:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  277:             <tr>
  278:              <td>
  279:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  280:                <tr>
  281:                 <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>
  282:                </tr>
  283:                <tr>
  284:                 <td bgcolor="$tabbg" align="right"><a href="/adm/whatsnew?command=chgthreshold"><b><small>Change thresholds?</small></b></a></td>
  285:                </tr>
  286:                 <tr>
  287:                 <td bgcolor="#ffffff">
  288:                  <table width="100%" cellspacing="2" cellpadding="2" border="0">
  289: END
  290:     my $warningnum = 0;
  291:     if (@warnings > 0) {
  292:         @warnings = sort { &cmp_title($a,$b,\%res_title) } @warnings;
  293:         $r->print('<form name="reset_tracking" method="post">'.
  294:                  '  <input type="hidden" name="action" value="reset" />'."\n");
  295:         $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>');
  296:         foreach my $res (@warnings) {
  297:             if ($warningnum %2 == 1) {
  298:                 $rowColor = $rowColor1;
  299:             } else {
  300:                 $rowColor = $rowColor2;
  301:             }
  302:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
  303:             my $linkurl=&Apache::lonnet::clutter($url);
  304:             my $rowspan;
  305:             if ($triggered{$res}{numparts} > 1) {
  306:                 $rowspan = 'rowspan="'.$triggered{$res}{numparts}.'"';
  307:             }
  308:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
  309:             $r->print('<tr bgcolor="'.$rowColor.'"><td '.$rowspan.'><a href="'.$linkurl.'"><small>'.$triggered{$res}{title}.'</small></a></td>'.$triggered{$res}{text});
  310:             $warningnum ++;
  311:         }
  312:         $r->print('<tr bgcolor="#cccccc"><td colspan="7" align="right"><br /><b><small><input type="submit" name="counters" value="Reset counters to 0" /></form>'); 
  313:     } else {
  314:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>No problems satisfy threshold criteria.</small></i></b></center><br /></td></tr>');
  315:     }
  316:     $r->print('</table></td></tr></table></td></tr></table><br />');
  317: 
  318:     $r->print('</td><td width="5%">&nbsp;</td><td align="left" valign="top" width-"50%">');
  319: 
  320: ## UNREAD COURSE DISCUSSION POSTS ##
  321:     $r->print(<<"END");
  322:               <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  323:                <tr><td>
  324:                 <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  325:                  <tr>
  326:                   <td bgcolor="$tabbg"><b>Unread course discussion posts</b></td>
  327:                  </tr>
  328:                  <tr>
  329:                    <td bgcolor="#ffffff">
  330:                    <table cellpadding="2" cellspacing="0" border="0" width="100%">
  331: END
  332:                                                                                   
  333:     if (@newdiscussions > 0) {
  334:         $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>');
  335:         @newdiscussions = sort { &cmp_title($a,$b,\%res_title) } @newdiscussions;
  336:         my $rowNum = 0;
  337:         foreach my $ressymb (@newdiscussions) {
  338:             my $forum_title = $unread{$ressymb}{'title'};
  339:             my $type = 'Resource';
  340:             my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
  341:             if ($feedurl =~ /bulletinboard/) {
  342:                 $type = 'Bulletin Board';
  343:             }
  344:             my $unreadnum = keys(%{$unread{$ressymb}});
  345:             $unreadnum = $unreadnum - 2;
  346:             if ($unreadnum > 0) {
  347:                 if ($rowNum %2 == 1) {
  348:                     $rowColor = $rowColor1;
  349:                 } else {
  350:                     $rowColor = $rowColor2;
  351:                 }
  352:                 $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>');
  353:                 $rowNum ++;
  354:             }
  355:         }
  356:     } else {
  357:         $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>');
  358:     }
  359:     $r->print('</table></td></tr></table></td></tr></table><br />');
  360: 
  361: ## MESSAGES ##
  362:     $r->print(<<END);
  363:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  364:             <tr>
  365:              <td>
  366:               <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  367:                <tr>
  368:                 <td bgcolor="$tabbg"><b>New course messages</b></td>
  369:                </tr>
  370:                <tr>
  371:                 <td bgcolor="#ffffff">
  372:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  373: END
  374:     if ($msgcount > 0) {
  375:         $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>');
  376:         my $rowNum = 0;
  377:         my $mailcount = 1; 
  378:         foreach my $msg (@newmsgs) {
  379:             if ($rowNum %2 == 1) {
  380:                 $rowColor = $rowColor1;
  381:             } else {
  382:                 $rowColor = $rowColor2;
  383:             }
  384:             $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>');
  385:             $rowNum ++;
  386:             $mailcount ++;
  387:         }
  388:     } else {
  389:         $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>');
  390:     }
  391: 
  392:     $r->print('</table></td></tr></table></td></tr></table><br />');
  393: 
  394:     $r->print(<<END);
  395:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  396:             <tr>
  397:              <td>
  398:               <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  399:                <tr>
  400:                 <td bgcolor="$tabbg"><b>New critical messages in course</b></td>
  401:                </tr>
  402:                <tr>                 <td bgcolor="#ffffff">
  403:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  404: END
  405: 
  406:     if ($critmsgcount > 0) {
  407:         $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>');
  408:         my $rowNum = 0;
  409:         my $mailcount = 1;
  410:         foreach my $msg (@critmsgs) {
  411:             if ($rowNum %2 == 1) {
  412:                 $rowColor = $rowColor1;
  413:             } else {
  414:                 $rowColor = $rowColor2;
  415:             }
  416:             $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>');
  417:             $rowNum ++;
  418:             $mailcount ++;
  419:         }
  420:     } else {
  421:         $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>');
  422:     }
  423:                                                                                
  424:     $r->print('</table></td></tr></table></td></tr></table><br />');
  425: 
  426:     $r->print('
  427:            </table>
  428:           </td>
  429:          </tr>
  430:         </table>');
  431:     $r->print('</td></tr></table>');
  432: }
  433: 
  434: #-------------------------------
  435: # display_config_box
  436: #
  437: # Display the threshold setting screen 
  438: #
  439: #-------------------------------
  440:                                                                                 
  441: sub display_config_box() {
  442:     my ($r,$command,$tabbg,$threshold_titles,$cdom,$crs) = @_;
  443:     my %threshold = ();
  444:     my $rowColor1 = "#ffffff";
  445:     my $rowColor2 = "#eeeeee";
  446:     my $rowColor;
  447: 
  448:     my @thresholditems = ("av_attempts","degdiff","numstudents");
  449:     my %threshold_titles = (
  450:                          av_attempts => 'Average number of attempts',
  451:                          degdiff => 'Degree of difficulty',
  452:                          numstudents => 'Total number of students with submissions',
  453:                          );
  454:     &get_curr_thresholds(\%threshold,$cdom,$crs);
  455: 
  456:     $r->print('<br /><form name="thresholdform" method="post"><table border="0" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">
  457:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  458:             <tr>
  459:              <td>
  460:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">
  461:                 <tr>
  462:                 <td bgcolor="#ffffff">
  463:                  <table cellspacing="0" cellpadding="4" border="0">
  464:      <tr bgcolor="'.$tabbg.'">
  465:       <th>Threshold Name</th>
  466:       <th>Current value</th>
  467:       <th>Change?</th>
  468:      </tr>');
  469:     my $rowNum =0;
  470:     foreach my $type (@thresholditems) {
  471:         my $parameter = 'internal.threshold_'.$type;
  472: # onchange is javascript to automatically check the 'Set' button.
  473:         my $onchange = 'onFocus="javascript:window.document.forms'.
  474:               "['thresholdform'].elements['".$parameter."_setparmval']".
  475:               '.checked=true;"';
  476:         if ($rowNum %2 == 1) {
  477:             $rowColor = $rowColor1;
  478:         } else {
  479:             $rowColor = $rowColor2;
  480:         }
  481:         $r->print('
  482:      <tr bgcolor="'.$rowColor.'">
  483:       <td>'.$threshold_titles{$type}.'</td>
  484:       <td>'.&Apache::lonhtmlcommon::textbox($parameter.'_value',
  485:                                             $threshold{$type},
  486:                                             10,$onchange).'</td>
  487:       <td>'
  488:            .&Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
  489:       '</td>
  490:      </tr>');
  491:         $rowNum ++;
  492:     }
  493:     $r->print('</table></td></tr></table></td></tr></table>
  494:            <br /><input type="submit" name="threshold" value="Make changes" />
  495:                  <input type="hidden" name="action" value="update" />
  496:                </form>');
  497: }
  498: 
  499: sub getitems {
  500:     my ($unread,$ungraded,$bombed,$triggered,$newdiscussions,$tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs,$res_title) = @_;
  501:     my $navmap = Apache::lonnavmaps::navmap->new();
  502:     my @allres=$navmap->retrieveResources();
  503:     my %discussiontime = &Apache::lonnet::dump('discussiontimes',$cdom,$crs);
  504:     my %lastread = &Apache::lonnet::dump('nohist_'.$env{'request.course.id'}.
  505:                 '_discuss',$env{'user.domain'},$env{'user.name'},'lastread');
  506:     my %lastreadtime = ();
  507:     my @discussions = ();
  508:     my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
  509: 
  510:     my %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',
  511:                $cdom,$crs);
  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:                 $av_attempts = sprintf("%.2f",$av_attempts);
  621:             }
  622:             if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
  623:                 $stats{$part}{degdiff} = $degdiff;
  624:                 $stats{$part}{attempts} = $av_attempts;
  625:                 $stats{$part}{users} = $users;
  626: 		$lastreset{$part} = $resourcetracker{$symb."\0".$part."\0resettime"};
  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_curr_thresholds {
  668:     my ($threshold,$cdom,$crs) = @_;
  669:     my %coursesettings = &Apache::lonnet::dump('environment',
  670:                                      $cdom,$crs,'internal.threshold');
  671:     if (exists($coursesettings{'internal.threshold_av_attempts'})) {
  672:         $$threshold{'av_attempts'} = $coursesettings{'internal.threshold_av_attempts'};
  673:     }
  674:     if (exists($coursesettings{'internal.threshold_degdiff'})) {
  675:         $$threshold{'degdiff'} = $coursesettings{'internal.threshold_degdiff'};
  676:     }
  677:     if (exists($coursesettings{'internal.threshold_numstudents'})) {
  678:         $$threshold{'numstudents'} = $coursesettings{'internal.threshold_numstudents'};
  679:     }
  680: }
  681: 
  682: sub process_reset {
  683:     my ($dom,$crs) = @_;
  684:     my $result = '<b>Counters reset for following problems (and parts):</b><br />';
  685:     my @agg_types = ('attempts','users','correct');
  686:     my %agg_titles = (
  687:                      attempts => 'Number of submissions',
  688:                      users => 'Students with submissions',
  689:                      correct => 'Number of correct submissions',
  690:                      );
  691:     my @resets = ();
  692:     my %titles = ();
  693:     foreach my $key (keys(%env)) {
  694:         next if ($key !~ /^form\.reset_(.+)$/);
  695:         my $title = &Apache::lonnet::unescape($env{'form.title_'.$1});
  696:         my $reset_item = &Apache::lonnet::unescape($1);
  697:         my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
  698:         my %aggregates = ();
  699:         my ($symb,$part) = split(/\0/,$reset_item);
  700:         foreach my $type (@agg_types) {
  701:             $aggregates{$reset_item."\0".$type} = 0;
  702:         }  
  703: 	$aggregates{$reset_item."\0".'resettime'} = time;
  704:         my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates,
  705:                           $dom,$crs);
  706:         if ($putresult eq 'ok') {
  707:             $result .= $title.' -part '.$part.': ';
  708:             my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item);
  709:             foreach my $type (@agg_types) {
  710:                 $result .= $agg_titles{$type}.' = '.$new_aggregates{$reset_item."\0".$type}.'; ';
  711:             }
  712:             $result =~ s/; $//;
  713:             $result .= '<br />';
  714:         } else {
  715:             $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.<br />'."\n";
  716:         }
  717:     }
  718:     return $result;
  719: }
  720: 
  721: sub process_update {
  722:     my ($dom,$crs,$threshold_titles) = @_;
  723:     my $setoutput = '<b>Changes to threshold(s) for problem tracking:</b><br />';
  724:     foreach (keys %env) {
  725:         next if ($_!~/^form\.(.+)\_setparmval$/);
  726:         my $name  = $1;
  727:         my $value = $env{'form.'.$name.'_value'};
  728:         if ($name && defined($value)) {
  729:             my $put_result = &Apache::lonnet::put('environment',
  730:                                                   {$name=>$value},$dom,$crs);
  731:            
  732:             my ($shortname) = ($name =~ /^internal\.threshold_(.+)$/); 
  733:             if ($put_result eq 'ok') {
  734:                 $setoutput.=&mt('Set threshold for [_1] to [_2]',
  735: 				'<b>'.$$threshold_titles{$shortname}.'</b>',
  736: 				'<b>'.$value.'</b>').'<br />';
  737: 	    } else {
  738:                 $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
  739: 				'<b>'.$name.'</b>','<b>'.$value.'</b>',
  740: 				'<tt>'.$put_result.'</tt>').'<br />';
  741:             }
  742:         }
  743:     }
  744:     return $setoutput;
  745: }
  746: 
  747: sub getmail {
  748:     my ($newmsgs,$critmsgs) = @_;
  749: # Check for unread mail in course
  750:     my $msgcount = 0;
  751: 
  752:     my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
  753:     foreach my $message (@messages) {
  754: 	my $msgid=&Apache::lonnet::escape($message);
  755:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
  756:             &Apache::lonmsg::unpackmsgid($msgid);
  757:         if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
  758:             if (defined($sendtime) && $sendtime!~/error/) {
  759:                 my $numsendtime = $sendtime;
  760:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
  761:                 if ($status eq 'new') {
  762:                     $msgcount ++;
  763:                     if ($shortsubj eq '') {
  764:                         $shortsubj = &mt('No subject');
  765:                     }
  766:                     $shortsubj = &Apache::lonnet::unescape($shortsubj);
  767:                     push(@{$newmsgs}, {
  768:                         msgid    => $msgid,
  769:                         sendtime => $sendtime,
  770:                         shortsub => $shortsubj,
  771:                         from     => $fromname,
  772:                         fromdom  => $fromdom
  773:                         });
  774:                 }
  775:             }
  776:         }
  777:     }
  778: 
  779: # Check for critical messages in course
  780:     my %what=&Apache::lonnet::dump('critical');
  781:     my $result = '';
  782:     my $critmsgcount = 0;
  783:     foreach my $msgid (sort(keys(%what))) {
  784:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
  785:             &Apache::lonmsg::unpackmsgid($msgid);
  786:         if (($fromcid) && ($fromcid eq  $env{'request.course.id'})) {
  787:             if (defined($sendtime) && $sendtime!~/error/) {
  788:                 my $numsendtime = $sendtime;
  789:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
  790:                 $critmsgcount ++;
  791:                 if ($shortsubj eq '') {
  792:                     $shortsubj = &mt('No subject');
  793:                 }
  794:                 $shortsubj = &Apache::lonnet::unescape($shortsubj);
  795:                 push(@{$critmsgs}, {
  796:                         msgid    => $msgid,
  797:                         sendtime => $sendtime,
  798:                         shortsub => $shortsubj,
  799:                         from     => $fromname,
  800:                         fromdom  => $fromdom
  801:                         });
  802:             }
  803:         }
  804:     }
  805:     return ($msgcount,$critmsgcount);
  806: }
  807: 
  808: sub cmp_title {
  809:     my ($a,$b,$res_title) = @_;
  810:     my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b}));
  811:     $atitle=~s/^\s*//;
  812:     $btitle=~s/^\s*//;
  813:     return $atitle cmp $btitle;
  814: }
  815: 
  816: 1;

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