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

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: 
1.4     ! bowersj2   65:     # Keep this hash in sync with %statusIconMap in lonnavmaps; they
        !            66:     # should match color/icon
        !            67:     my $res = $navmap->firstResource(); # temp resource to access constants
        !            68: 
        !            69:     my $green = "#AAFFAA";
        !            70:     my $red = "#FFAAAA";
        !            71:     my $yellow = "#FFFFAA";
        !            72:     my $orange = "#FFBB88";
        !            73:     my $neutral = "";
        !            74:     my %statusColorMap = 
        !            75:         ( $res->NETWORK_FAILURE    => $neutral,
        !            76:           $res->NOTHING_SET        => $neutral,
        !            77:           $res->CORRECT            => $green,
        !            78:           $res->EXCUSED            => $green,
        !            79:           $res->PAST_DUE_NO_ANSWER => $orange,
        !            80:           $res->PAST_DUE_ANSWER_LATER => $orange,
        !            81:           $res->ANSWER_OPEN        => $orange,
        !            82:           $res->OPEN_LATER         => $neutral,
        !            83:           $res->TRIES_LEFT         => $neutral,
        !            84:           $res->INCORRECT          => $orange,
        !            85:           $res->OPEN               => $yellow,
        !            86:           $res->ATTEMPTED          => $yellow );
        !            87:     
1.1       bowersj2   88:     if (!defined($navmap)) {
                     89:         my $requrl = $r->uri;
                     90:         $ENV{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
                     91:         return HTTP_NOT_ACCEPTABLE;
                     92:     }
                     93:  
                     94:     # Header
1.2       bowersj2   95:     $r->print(&Apache::loncommon::bodytag('Quick Score Display','',
1.1       bowersj2   96:                                           ''));
                     97: 
1.2       bowersj2   98:     $navmap->init();
                     99: 
1.1       bowersj2  100:     # End navmap using boilerplate
                    101: 
                    102:     my $iterator = $navmap->getIterator(undef, undef, undef, 1);
                    103:     my $depth = 1;
                    104:     $iterator->next(); # ignore first BEGIN_MAP
                    105:     my $curRes = $iterator->next();
1.4     ! bowersj2  106:     my $totalParts = 0;
        !           107:     my $totalRight = 0;
        !           108:     my $totalCurrentlyPossible = 0;
        !           109:     
        !           110:     $r->print("<div width=\"50%\">\n"); # use this to format the col
1.1       bowersj2  111:    
                    112:     while ( $depth > 0 ) {
                    113:         if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
                    114:         if ($curRes == $iterator->END_MAP()) { $depth--; }
                    115: 
                    116:         if (ref($curRes) && $curRes->is_problem()) {
                    117:             my $title = $curRes->compTitle();
1.2       bowersj2  118:             my $stack = $iterator->getStack();
                    119:             my $src = Apache::lonnavmaps::getLinkForResource($stack);
                    120:             my $srcHasQuestion = $src =~ /\?/;
                    121:             my $link = $src.
                    122:                 ($srcHasQuestion?'&':'?') .
                    123:                 'symb='.&Apache::lonnet::escape($curRes->symb()).
                    124:                 '"';
                    125:             my $parts = $curRes->parts();
1.4     ! bowersj2  126:             my $multipart = scalar(@{$parts}) > 1;
        !           127: 
1.2       bowersj2  128:             for my $part (@{$parts}) {
1.4     ! bowersj2  129:                 if ($multipart && $part eq '0') { next; }
        !           130:                 $totalParts++;
        !           131: 
        !           132:                 my $status = $curRes->status($part);
        !           133:                 my $color = $statusColorMap{$status};
        !           134:                 if ($color eq $green) { # I'm being bad here... ;-)
        !           135:                     $totalRight++; $totalCurrentlyPossible++;
        !           136:                 }
        !           137:                 if ($color eq $yellow || $color eq $orange) {
        !           138:                     $totalCurrentlyPossible++;
        !           139:                 }
        !           140: 
        !           141:                 $r->print("<div style=\"background-color: $color\" width=\"100%\">" .
        !           142:                           "<nobr><a href=\"$link\">$title" . 
        !           143:                           ($multipart ? ', ' . $part : '') . '</a></nobr></div>'
        !           144:                           ."\n");
        !           145: 
        !           146:                 if (!($totalParts % 20)) { $r->rflush(); }
1.2       bowersj2  147:             }
1.1       bowersj2  148:         }
                    149: 
                    150:         $curRes = $iterator->next();
                    151:     }
1.2       bowersj2  152: 
1.4     ! bowersj2  153:     $r->print("<br><hr>\n");
        !           154:     $r->print("<div width=\"100%\" align=\"right\">");
        !           155:     $r->print("Total Parts Correct: <b>$totalRight</b><br>");
        !           156:     $r->print("Number Of Parts Possibly Correct: <b>$totalCurrentlyPossible</b><br>");
        !           157:     $r->print("Total Parts In Course: <b>$totalParts</b></div></div>\n\n");
1.1       bowersj2  158: 
                    159:     $r->print("</body></html>");
                    160: 
1.3       bowersj2  161:     $navmap->untieHashes();
                    162: 
1.1       bowersj2  163:     return OK;
                    164: }
                    165: 
                    166: 1;

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