Annotation of loncom/interface/lonquickgrades.pm, revision 1.3

1.1       bowersj2    1: # The LearningOnline Network with CAPA
                      2: # Quick Student Grades Display
                      3: #
                      4: # $Id:
                      5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: # Created Nov. 14, 2002 by Jeremy Bowers
                     29: 
                     30: package Apache::lonquickgrades;
                     31: 
                     32: use strict;
                     33: use Apache::Constants qw(:common :http);
                     34: 
                     35: sub handler {
                     36:     my $r = shift;
                     37: 
                     38:     &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
                     39: 
                     40:     # Handle header-only request
                     41:     if ($r->header_only) {
                     42:         if ($ENV{'browser.mathml'}) {
                     43:             $r->content_type('text/xml');
                     44:         } else {
                     45:             $r->content_type('text/html');
                     46:         }
                     47:         $r->send_http_header;
                     48:         return OK;
                     49:     }
                     50: 
                     51:     # Send header, don't cache this page
                     52:     if ($ENV{'browser.mathml'}) {
                     53:         $r->content_type('text/xml');
                     54:     } else {
                     55:         $r->content_type('text/html');
                     56:     }
                     57:     &Apache::loncommon::no_cache($r);
                     58:     $r->send_http_header;
                     59: 
                     60:     # Create the nav map
                     61:     my $navmap = Apache::lonnavmaps::navmap->new(
                     62:                         $ENV{"request.course.fn"}.".db",
1.2       bowersj2   63:                         $ENV{"request.course.fn"}."_parms.db", 1, 0);
1.1       bowersj2   64: 
                     65:     if (!defined($navmap)) {
                     66:         my $requrl = $r->uri;
                     67:         $ENV{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
                     68:         return HTTP_NOT_ACCEPTABLE;
                     69:     }
                     70:  
                     71:     # Header
1.2       bowersj2   72:     $r->print(&Apache::loncommon::bodytag('Quick Score Display','',
1.1       bowersj2   73:                                           ''));
                     74: 
1.2       bowersj2   75:     $navmap->init();
                     76: 
1.1       bowersj2   77:     # End navmap using boilerplate
                     78: 
1.2       bowersj2   79:     # Col labels
                     80:     $r->print(<<TABLETOP);
                     81: <table border="1" cellpadding="3" cellspacing="0">
                     82:   <tr>
                     83:     <td align="center"><b>Problem</b></td>
                     84:     <td align="center"><b>Score</b></td>
                     85:   </tr>
                     86: TABLETOP
                     87: 
1.1       bowersj2   88:     my $iterator = $navmap->getIterator(undef, undef, undef, 1);
                     89:     my $depth = 1;
                     90:     $iterator->next(); # ignore first BEGIN_MAP
                     91:     my $curRes = $iterator->next();
1.2       bowersj2   92:     my $totalAvailable = 0;
                     93:     my $total = 0;
1.1       bowersj2   94:    
                     95:     while ( $depth > 0 ) {
                     96:         if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
                     97:         if ($curRes == $iterator->END_MAP()) { $depth--; }
                     98: 
                     99:         if (ref($curRes) && $curRes->is_problem()) {
                    100:             my $title = $curRes->compTitle();
1.2       bowersj2  101:             $r->print('    <tr>');
                    102:             my $stack = $iterator->getStack();
                    103:             my $src = Apache::lonnavmaps::getLinkForResource($stack);
                    104:             my $srcHasQuestion = $src =~ /\?/;
                    105:             my $link = $src.
                    106:                 ($srcHasQuestion?'&':'?') .
                    107:                 'symb='.&Apache::lonnet::escape($curRes->symb()).
                    108:                 '"';
                    109:             $r->print("<td><a href=\"$link\">$title</td>");
                    110:             
                    111:             my $avail = 0;
                    112:             my $score = 0;
                    113:             my $parts = $curRes->parts();
                    114:             for my $part (@{$parts}) {
                    115:                 my $partAvail = $curRes->weight($part);
                    116:                 my $partScore = $curRes->awarded($part) * $partAvail;
                    117:                 $avail += $partAvail;
                    118:                 $score += $partScore;
                    119:             }
                    120:             
                    121:             $r->print("<td align=\"right\">$score / $avail</td></tr>\n");
                    122:             $totalAvailable += $avail;
                    123:             $total += $score;
1.1       bowersj2  124:         }
                    125: 
                    126:         $curRes = $iterator->next();
                    127:     }
1.2       bowersj2  128: 
                    129:     $r->print("<td colspan=\"2\" align=\"right\">Total Points Scored: <b>$total</b>");
                    130:     $r->print("<br />Total Points Available: <b>$totalAvailable</b>");
                    131:     $r->print("</td></tr></table>\n\n");
1.1       bowersj2  132: 
                    133:     $r->print("</body></html>");
                    134: 
1.3     ! bowersj2  135:     $navmap->untieHashes();
        !           136: 
1.1       bowersj2  137:     return OK;
                    138: }
                    139: 
                    140: 1;

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