File:  [LON-CAPA] / loncom / interface / lonwhatsnew.pm
Revision 1.11: download - view: text, annotated - select for diffs
Mon Apr 18 20:35:07 2005 UTC (19 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Unread course discussion posts moved to top of column 2.  Display of problems with anomalous average number of attempts and/or degree of difficulty added.  Data extracted from resourcetracker.db for course. Work in progress.

    1: #
    2: # $Id: lonwhatsnew.pm,v 1.11 2005/04/18 20:35:07 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 = $env{'form.command'};
   56: 
   57:     if ($command eq '') {
   58:         $command = "info";
   59:     }
   60: 
   61:     &Apache::loncommon::content_type($r,'text/html');
   62:     $r->send_http_header;
   63:     $r->print(&display_header());
   64:     if (! (($env{'request.course.fn'}) && (&Apache::lonnet::allowed('vsa',$env{'request.course.id'})))) {
   65:         # Not in a course, or not allowed to modify parms
   66:         $env{'user.error.msg'}="/adm/whatsnew:vsa:0:0:Cannot display student activity";
   67:         return HTTP_NOT_ACCEPTABLE;
   68:     }
   69: 
   70:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   71:     if ($command eq 'config') {
   72:         &Apache::lonhtmlcommon::add_breadcrumb
   73:             ({href=>'/adm/whatsnew?command=config',
   74:               text=>"Configure display"});
   75:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
   76:             (undef,'Course Action Items','Course_Action_Items_Config'));
   77:     } else {
   78:         &Apache::lonhtmlcommon::add_breadcrumb
   79:             ({href=>'/adm/whatsnew?command=info',
   80:               text=>"Display Action Items"});
   81:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
   82:             (undef,'Course Action Items','Course_Action_Items_Display'));
   83:     }
   84:     &display_main_box($r,$command);
   85: }
   86: 
   87: #------------------------------
   88: # display_main_box
   89: #
   90: # Display all the elements within the main box
   91: #------------------------------
   92:                                                                                 
   93: sub display_main_box {
   94:     my ($r,$command) = @_;
   95:     my $domain=&Apache::loncommon::determinedomain();
   96:     my $tabbg=&Apache::loncommon::designparm('coordinator.tabbg',$domain);
   97:     my $selconfig;
   98:     my $selinfo;
   99:     if ($command eq 'config') {
  100:         $selinfo = 'selected="selected"';
  101:     } else {
  102:         $selconfig = 'selected="selected"';
  103:     }
  104:     my $picker = ('
  105: <form>
  106:  <nobr>
  107:   <input type="submit" value="'.&mt('Change page to:').'" />
  108:    <select name="command">
  109:     <option value="info" '.$selinfo.'">'.&mt('Display Action Items').'</option>
  110:     <option value="config" '.$selconfig.'">'.&mt('Configure Settings').'</option>
  111:    </select>
  112:  </nobr>
  113: </form>');
  114:                                                                                
  115:     $r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
  116:                                                                                
  117:     if ($command eq 'config') {
  118:         &display_config_box($r,$picker);
  119:     } else {
  120:         &display_actions_box($r,$picker);
  121:     }
  122:     $r->print(<<END_OF_BLOCK);
  123:   </td>
  124:  </tr>
  125: </table><br />
  126: </body>
  127: </html>
  128: END_OF_BLOCK
  129: }
  130: 
  131: #-------------------------------
  132: # display_header
  133: #
  134: # Display the header information and set
  135: # up the HTML
  136: #-------------------------------
  137: 
  138: sub display_header{
  139:     my $html=&Apache::lonxml::xmlbegin();
  140:     my $bodytag=&Apache::loncommon::bodytag('Course Action Items');
  141:     return(<<ENDHEAD);
  142: $html
  143: <head>
  144: <title>Course Action Items</title>
  145: </head>
  146: $bodytag
  147: ENDHEAD
  148: }
  149: 
  150: #-------------------------------
  151: # display_actions_box
  152: #
  153: # Display the action items
  154: #
  155: #-------------------------------
  156:                                                                                 
  157: sub display_actions_box() {
  158:     my ($r,$picker) = @_;
  159: 
  160:     my $rowColor1 = "#ffffff";
  161:     my $rowColor2 = "#eeeeee";
  162:     my $rowColor;
  163: 
  164:     my %unread = ();
  165:     my %ungraded = ();
  166:     my %bombed = ();
  167:     my %triggered = ();
  168:     my @newmsgs = ();
  169:     my @critmsgs = ();
  170:     my @newdiscussions = ();
  171:     my @tograde = ();
  172:     my @bombs = ();
  173:     my @warnings = ();
  174: 
  175:     my $domain=&Apache::loncommon::determinedomain();
  176:     my $function;
  177:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
  178:         $function='coordinator';
  179:     }
  180:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
  181:         $function='admin';
  182:     }
  183: 
  184:     my $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
  185:     my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
  186: 
  187:     &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2);
  188:     my ($msgcount,$critmsgcount) = &getmail(\@newmsgs,\@critmsgs);
  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: 
  195:     $r->print('<b>'.$picker.'</b><br /><hr width="100%" /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
  196: 
  197: ## UNGRADED ITEMS ##
  198:     $r->print(<<END);
  199:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  200:             <tr><td>
  201:              <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  202:               <tr>
  203:                <td bgcolor="$tabbg"><b>Problems requiring handgrading</b></td></tr>
  204:                   <tr>
  205:                    <td bgcolor="#ffffff">
  206:                      <table cellpadding="2" cellspacing="0" border="0" width="100%">
  207: END
  208: 
  209:     if (@tograde > 0) {
  210:         $r->print('<tr bgcolor="#cccccc"><td><b><small>Problem Name</small></b></td><td align="right"><b><small>Number ungraded</small></b></td></tr>');
  211:         my $rowNum = 0;
  212:         foreach my $res (@tograde) {
  213:             if ($rowNum %2 == 1) {
  214:                 $rowColor = $rowColor1;
  215:             } else {
  216:                 $rowColor = $rowColor2;
  217:             }
  218:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
  219:             my $linkurl=&Apache::lonnet::clutter($url);
  220:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
  221: 
  222:             $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>');
  223:             $rowNum ++;
  224:         }
  225:     } else {
  226:         $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>');
  227:     }
  228:     $r->print('</table></td></tr></table></td></tr></table><br />');
  229: 
  230: ## BOMBS ##
  231:      $r->print(<<"END");
  232:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  233:             <tr>
  234:              <td>
  235:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  236:                <tr>
  237:                 <td bgcolor="$tabbg"><b>Problems with errors</b></td>
  238:                </tr>
  239:                 <tr>
  240:                 <td bgcolor="#ffffff">
  241:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  242: END
  243:      my $bombnum = 0;
  244:      if (@bombs > 0) {
  245: #        @bombs = sort { &cmp_title($a,$b) } @bombs;
  246:         foreach my $bomb (@bombs) {
  247:             if ($bombnum %2 == 1) {
  248:                  $rowColor = $rowColor1;
  249:             } else {
  250:                 $rowColor = $rowColor2;
  251:             }
  252:             $r->print('<tr bgcolor="'.$rowColor.'"><td>'.$bombed{$bomb}{errorlink}.'</td></tr>');
  253:             $bombnum ++;
  254:         }
  255:     } else {
  256:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>No problems with errors</small></i></b></center><br /></td></tr>');
  257:     }
  258:     $r->print('</table></td></tr></table></td></tr></table><br />');
  259: 
  260: # DEGDIFF AND AV. TRIES TRIGGERS
  261:      $r->print(<<"END");
  262:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  263:             <tr>
  264:              <td>
  265:                <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  266:                <tr>
  267:                 <td bgcolor="$tabbg"><b>Problems with average attempts > 0 or degree of difficulty > 0</b></td>
  268:                </tr>
  269:                 <tr>
  270:                 <td bgcolor="#ffffff">
  271:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  272: END
  273:      my $warningnum = 0;
  274:      if (@warnings > 0) {
  275: #        @warnings = sort { &cmp_title($a,$b) } @warnings;
  276:         $r->print('<tr bgcolor="#cccccc"><td><b><small>Resource</small></b></td><td align="right"><b><small>Part</small></b><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></tr>');
  277:         foreach my $res (@warnings) {
  278:             if ($warningnum %2 == 1) {
  279:                  $rowColor = $rowColor1;
  280:             } else {
  281:                 $rowColor = $rowColor2;
  282:             }
  283:             my ($map,$id,$url)=&Apache::lonnet::decode_symb($res);
  284:             my $linkurl=&Apache::lonnet::clutter($url);
  285:             my $rowspan;
  286:             if ($triggered{$res}{numparts} > 1) {
  287:                 $rowspan = 'rowspan="'.$triggered{$res}{numparts}.'"';
  288:             }
  289:             $linkurl .= '?symb='.&Apache::lonnet::escape($res);
  290:             $r->print('<tr bgcolor="'.$rowColor.'"><td '.$rowspan.'><a href="'.$linkurl.'"><small>'.$triggered{$res}{title}.'</small></a></td>'.$triggered{$res}{text});
  291:             $warningnum ++;
  292:         }
  293:     } else {
  294:         $r->print('<tr><td bgcolor="#ffffff"><br /><center><b><i><small>No problems with av. attempts or degree of difficulty above thresholds</small></i></b></center><br /></td></tr>');
  295:     }
  296:     $r->print('</table></td></tr></table></td></tr></table><br />');
  297: 
  298:     $r->print('</td><td width="5%">&nbsp;</td><td align="left" valign="top" width-"50%">');
  299: 
  300: ## UNREAD COURSE DISCUSSION POSTS ##
  301:     $r->print(<<"END");
  302:               <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  303:                <tr><td>
  304:                 <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  305:                  <tr>
  306:                   <td bgcolor="$tabbg"><b>Unread course discussion posts</b></td>
  307:                  </tr>
  308:                  <tr>
  309:                    <td bgcolor="#ffffff">
  310:                    <table cellpadding="2" cellspacing="0" border="0" width="100%">
  311: END
  312:                                                                                   
  313:     if (@newdiscussions > 0) {
  314:         $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>');
  315: #        @newdiscussions = sort { &cmp_title($a,$b) } @newdiscussions;
  316:         my $rowNum = 0;
  317:         foreach my $ressymb (@newdiscussions) {
  318:             my $forum_title = $unread{$ressymb}{'title'};
  319:             my $type = 'Resource';
  320:             my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
  321:             if ($feedurl =~ /bulletinboard/) {
  322:                 $type = 'Bulletin Board';
  323:             }
  324:             my $unreadnum = keys(%{$unread{$ressymb}});
  325:             $unreadnum = $unreadnum - 2;
  326:             if ($unreadnum > 0) {
  327:                 if ($rowNum %2 == 1) {
  328:                     $rowColor = $rowColor1;
  329:                 } else {
  330:                     $rowColor = $rowColor2;
  331:                 }
  332:                 $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>');
  333:                 $rowNum ++;
  334:             }
  335:         }
  336:     } else {
  337:         $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>');
  338:     }
  339:     $r->print('</table></td></tr></table></td></tr></table><br />');
  340: 
  341: ## MESSAGES ##
  342:     $r->print(<<END);
  343:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  344:             <tr>
  345:              <td>
  346:               <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  347:                <tr>
  348:                 <td bgcolor="$tabbg"><b>New course messages</b></td>
  349:                </tr>
  350:                <tr>
  351:                 <td bgcolor="#ffffff">
  352:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  353: END
  354:     if ($msgcount > 0) {
  355:         $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>');
  356:         my $rowNum = 0;
  357:         my $mailcount = 1; 
  358:         foreach my $msg (@newmsgs) {
  359:             if ($rowNum %2 == 1) {
  360:                 $rowColor = $rowColor1;
  361:             } else {
  362:                 $rowColor = $rowColor2;
  363:             }
  364:             $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>');
  365:             $rowNum ++;
  366:             $mailcount ++;
  367:         }
  368:     } else {
  369:         $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>');
  370:     }
  371: 
  372:     $r->print('</table></td></tr></table></td></tr></table><br />');
  373: 
  374:     $r->print(<<END);
  375:            <table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
  376:             <tr>
  377:              <td>
  378:               <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
  379:                <tr>
  380:                 <td bgcolor="$tabbg"><b>New critical messages in course</b></td>
  381:                </tr>
  382:                <tr>                 <td bgcolor="#ffffff">
  383:                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
  384: END
  385: 
  386:     if ($critmsgcount > 0) {
  387:         $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>');
  388:         my $rowNum = 0;
  389:         my $mailcount = 1;
  390:         foreach my $msg (@critmsgs) {
  391:             if ($rowNum %2 == 1) {
  392:                 $rowColor = $rowColor1;
  393:             } else {
  394:                 $rowColor = $rowColor2;
  395:             }
  396:             $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>');
  397:             $rowNum ++;
  398:             $mailcount ++;
  399:         }
  400:     } else {
  401:         $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>');
  402:     }
  403:                                                                                
  404:     $r->print('</table></td></tr></table></td></tr></table><br />');
  405: 
  406:     $r->print('
  407:            </table>
  408:           </td>
  409:          </tr>
  410:         </table>');
  411:     $r->print('</td></tr></table>');
  412: }
  413: 
  414: #-------------------------------
  415: # display_config_box
  416: #
  417: # Display the action items
  418: #
  419: #-------------------------------
  420:                                                                                 
  421: sub display_config_box() {
  422:     my ($r,$picker) = @_;
  423:     $r->print('<b>'.$picker.'</b><br /><hr width="100%" /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
  424: }
  425: 
  426: sub getitems {
  427:     my ($unread,$ungraded,$bombed,$triggered,$newdiscussions,$tograde,$bombs,$warnings,$rowColor1,$rowColor2) = @_;
  428:     my $navmap = Apache::lonnavmaps::navmap->new();
  429:     my @allres=$navmap->retrieveResources();
  430:     my %discussiontime = &Apache::lonnet::dump('discussiontimes',
  431:                $env{'course.'.$env{'request.course.id'}.'.domain'},
  432:                $env{'course.'.$env{'request.course.id'}.'.num'});
  433:     my %lastread = &Apache::lonnet::dump('nohist_'.$env{'request.course.id'}.'_discuss',$env{'user.domain'},$env{'user.name'},'lastread');
  434:     my %lastreadtime = ();
  435:     my @discussions = ();
  436:     my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
  437: 
  438:     my %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',
  439:                $env{'course.'.$env{'request.course.id'}.'.domain'},
  440:                $env{'course.'.$env{'request.course.id'}.'.num'});
  441: 
  442:     my $diffcheck = 0;
  443:     my $triescheck = 0;
  444:     my $warningnum = 0;
  445:     foreach my $key (keys(%lastread)) {
  446:         my $newkey = $key;
  447:         $newkey =~ s/_lastread$//;
  448:         $lastreadtime{$newkey} = $lastread{$key};
  449:     }
  450:     foreach my $resource (@allres) {
  451:         my $result = '';
  452:         my $applies = 0;
  453:         my $symb = $resource->symb();
  454:         %{$$bombed{$symb}} = ();
  455:         %{$$ungraded{$symb}} = ();
  456:         %{$$triggered{$symb}} = ();
  457:         $$triggered{$symb}{numparts} = 0;
  458:         my $title = $resource->compTitle();
  459:         my $ressymb = $resource->wrap_symb();
  460: # Check for unread discussion postings
  461:         if (defined($discussiontime{$ressymb})) {
  462:             push(@discussions,$ressymb);
  463:             my $prevread = 0;
  464:             my $unreadcount = 0;
  465:             %{$$unread{$ressymb}} = ();
  466:             $$unread{$ressymb}{'title'} = $title;
  467:             $$unread{$ressymb}{'symb'} = $symb;
  468:             if (defined($lastreadtime{$ressymb})) {
  469:                 $prevread = $lastreadtime{$ressymb};
  470:             }
  471:             my %contrib = &Apache::lonnet::restore($ressymb,$env{'request.course.id'},
  472:             $env{'course.'.$env{'request.course.id'}.'.domain'},
  473:             $env{'course.'.$env{'request.course.id'}.'.num'});
  474:             if ($contrib{'version'}) {
  475:                 for (my $id=1;$id<=$contrib{'version'};$id++) {
  476:                     unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) {
  477:                         if ($prevread <$contrib{$id.':timestamp'}) {
  478:                             $$unread{$ressymb}{$unreadcount} = $id.': '.$contrib{$id.':subject'};
  479:                             $unreadcount ++;
  480:                         }
  481:                     }
  482:                 }
  483:             }
  484:             if ($unreadcount) { push(@{$newdiscussions}, $ressymb); }
  485: 	}
  486: 
  487: # Check for ungraded problems
  488:         if ($resource->is_problem()) {
  489:             my $ctr = 0;
  490:             my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  491:             my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($url,$symb);
  492:             foreach my $student (keys(%$classlist)) {
  493:                 my ($uname,$udom) = split(/:/,$student);
  494:                 my %status=&Apache::grades::student_gradeStatus($url,$symb,$udom,$uname,$partlist);
  495:                 my $submitted = 0;
  496:                 my $ungraded = 0;
  497:                 foreach (keys(%status)) {
  498:                     $submitted = 1 if ($status{$_} ne 'nothing');
  499:                     $ungraded = 1 if ($status{$_} =~ /^ungraded/);
  500:                     my ($foo,$partid,$foo1) = split(/\./,$_);
  501:                     if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
  502:                         $submitted = 0;
  503:                     }
  504:                 }
  505:                 next if (!$submitted || !$ungraded);
  506:                 $ctr ++;
  507:             }
  508:             if ($ctr) {
  509:                 $$ungraded{$symb}{count} = $ctr;
  510:                 $$ungraded{$symb}{title} = $title;
  511:                 push(@{$tograde}, $symb);
  512:             }
  513:         }
  514: 
  515: # Check for bombs
  516:         if ($resource->getErrors()) {
  517:             my $errors = $resource->getErrors();
  518:             my @bombs = split(/,/, $errors);
  519:             my $errorcount = scalar(@bombs);
  520:             my $errorlink = '<a href="/adm/email?display='.
  521:                             &Apache::lonnet::escape($$bombs[0]).'">';
  522:             $$bombed{$symb}{errorcount} = $errorcount;
  523:             $$bombed{$symb}{errorlink} = $errorlink;
  524:             push(@{$bombs}, $symb);
  525:         }
  526: # Compile maxtries and degree of difficulty for problem parts
  527:         my @parts = @{$resource->parts()};
  528:         my %stats = ();
  529:         my $warning = 0;
  530:         my $rowColor;
  531:         foreach (@parts) {
  532:             %{$stats{$_}} = ();
  533:             my ($attempts,$users,$corrects,$degdiff,$av_attempts);
  534:             if (exists($resourcetracker{$symb.'_'.$_.'_attempts'})) {
  535:                 $attempts = $resourcetracker{$symb.'_'.$_.'_attempts'};
  536:             }
  537:             if (exists($resourcetracker{$symb.'_'.$_.'_users'})) {
  538:                 $users = $resourcetracker{$symb.'_'.$_.'_users'};
  539:             }
  540:             if (exists($resourcetracker{$symb.'_'.$_.'_correct'})) {
  541:                 $corrects = $resourcetracker{$symb.'_'.$_.'_correct'};
  542:             }
  543:             if ($attempts > 0) {
  544:                 $degdiff =  1 - ($corrects/$attempts);
  545:                 $degdiff = sprintf("%.2f",$degdiff);
  546:             }
  547:             if ($users > 0) {
  548:                 $av_attempts = $attempts/$users;
  549:             }
  550:             if (($degdiff ne '' && $degdiff >= $diffcheck) || ($av_attempts ne '' && $av_attempts >= $triescheck)) {
  551:                 $stats{$_}{degdiff} = $degdiff;
  552:                 $stats{$_}{attempts} = $av_attempts;
  553:                 $stats{$_}{users} = $users;
  554:                 $warning = 1;
  555:             }
  556:         }
  557:         if ($warning) {
  558:             if ($warningnum %2 == 1) {
  559:                 $rowColor = $rowColor1;
  560:             } else {
  561:                 $rowColor = $rowColor2;
  562:             }
  563:             $$triggered{$symb}{title} = $resource->title;
  564:             foreach (@parts) {
  565:                 if (exists($stats{$_}{users})) {
  566:                     if ($$triggered{$symb}{numparts}) {
  567:                         $$triggered{$symb}{text} .= '<tr bgcolor="'.$rowColor.'">'."\n";
  568:                     }
  569:                     if (@parts > 1) {
  570:                         $$triggered{$symb}{text} .= '
  571:                          <td align="right"><small>part - '.$_.'<small></td>';
  572:                     } else {
  573:                         $$triggered{$symb}{text} .= '
  574:                          <td align="right"><small>single part</small></td>';
  575:                     }
  576:                     $$triggered{$symb}{text} .= '
  577:                          <td align="right"><small>'.$stats{$_}{users}.'</small></td>
  578:                          <td align="right"><small>'.$stats{$_}{attempts}.'</small></td>
  579:                          <td align="right"><small>'.$stats{$_}{degdiff}.'</small></td>
  580:                         </tr>';
  581:                     $$triggered{$symb}{numparts} ++;
  582:                 }
  583:             }
  584:             push(@{$warnings},$symb);
  585:             $warningnum ++;
  586:         }
  587:     }
  588: }
  589: 
  590: sub getmail {
  591:     my ($newmsgs,$critmsgs) = @_;
  592: # Check for unread mail in course
  593:     my $msgcount = 0;
  594: 
  595:     my @messages = sort(&Apache::lonnet::getkeys('nohist_email'));
  596:     foreach my $message (@messages) {
  597: 	my $msgid=&Apache::lonnet::escape($message);
  598:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
  599:             &Apache::lonmsg::unpackmsgid($msgid);
  600:         if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
  601:             if (defined($sendtime) && $sendtime!~/error/) {
  602:                 my $numsendtime = $sendtime;
  603:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
  604:                 if ($status eq 'new') {
  605:                     $msgcount ++;
  606:                     if ($shortsubj eq '') {
  607:                         $shortsubj = &mt('No subject');
  608:                     }
  609:                     $shortsubj = &Apache::lonnet::unescape($shortsubj);
  610:                     push(@{$newmsgs}, {
  611:                         msgid    => $msgid,
  612:                         sendtime => $sendtime,
  613:                         shortsub => $shortsubj,
  614:                         from     => $fromname,
  615:                         fromdom  => $fromdom
  616:                         });
  617:                 }
  618:             }
  619:         }
  620:     }
  621: 
  622: # Check for critical messages in course
  623:     my %what=&Apache::lonnet::dump('critical');
  624:     my $result = '';
  625:     my $critmsgcount = 0;
  626:     foreach my $msgid (sort(keys(%what))) {
  627:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
  628:             &Apache::lonmsg::unpackmsgid($msgid);
  629:         if (($fromcid) && ($fromcid eq  $env{'request.course.id'})) {
  630:             if (defined($sendtime) && $sendtime!~/error/) {
  631:                 my $numsendtime = $sendtime;
  632:                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
  633:                 $critmsgcount ++;
  634:                 if ($shortsubj eq '') {
  635:                     $shortsubj = &mt('No subject');
  636:                 }
  637:                 $shortsubj = &Apache::lonnet::unescape($shortsubj);
  638:                 push(@{$critmsgs}, {
  639:                         msgid    => $msgid,
  640:                         sendtime => $sendtime,
  641:                         shortsub => $shortsubj,
  642:                         from     => $fromname,
  643:                         fromdom  => $fromdom
  644:                         });
  645:             }
  646:         }
  647:     }
  648:     return ($msgcount,$critmsgcount);
  649: }
  650: 
  651: sub cmp_title {
  652:     my ($atitle,$btitle) = (lc($_[0]->compTitle),lc($_[1]->compTitle));
  653:     $atitle=~s/^\s*//;
  654:     $btitle=~s/^\s*//;
  655:     return $atitle cmp $btitle;
  656: }
  657: 
  658: 1;

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