Annotation of loncom/interface/lonwhatsnew.pm, revision 1.13

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

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