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

1.1       bowersj2    1: # The LearningOnline Network with CAPA
                      2: # Quick Student Grades Display
                      3: #
1.49.6.9! raeburn     4: # $Id: lonquickgrades.pm,v 1.49.6.8 2021/12/14 02:44:05 raeburn Exp $
1.1       bowersj2    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: 
                     29: package Apache::lonquickgrades;
                     30: 
                     31: use strict;
1.49.6.1  raeburn    32: use Apache::Constants qw(:common :http REDIRECT);
1.5       bowersj2   33: use POSIX;
1.25      www        34: use Apache::loncommon;
                     35: use Apache::lonlocal;
1.36      albertel   36: use Apache::lonnet;
1.38      bowersj2   37: use Apache::grades;
1.49.6.3  raeburn    38: use Apache::lonuserstate;
1.1       bowersj2   39: 
                     40: sub handler {
                     41:     my $r = shift;
1.5       bowersj2   42:     return real_handler($r);
                     43: }
                     44: 
                     45: sub real_handler {
                     46:     my $r = shift;
1.1       bowersj2   47: 
                     48:     &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
                     49: 
                     50:     # Handle header-only request
1.40      albertel   51:     if ($env{'browser.mathml'}) {
                     52: 	&Apache::loncommon::content_type($r,'text/xml');
                     53:     } else {
                     54: 	&Apache::loncommon::content_type($r,'text/html');
                     55:     }
1.1       bowersj2   56:     if ($r->header_only) {
1.40      albertel   57: 	$r->send_http_header;
1.1       bowersj2   58:         return OK;
                     59:     }
                     60: 
1.49.6.6  raeburn    61:     my $cangrade=&Apache::lonnet::allowed('mgr');
1.49.6.4  raeburn    62:     my $showPoints =
                     63:         $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard';
                     64: 
                     65:     my $reinitresult;
                     66: 
1.49.6.8  raeburn    67:     if ($env{'request.course.id'}) {
                     68:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     69:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                     70:         my $clientip = &Apache::lonnet::get_requestor_ip($r);
                     71:         my ($blocked,$blocktext) =
                     72:             &Apache::loncommon::blocking_status('grades',$clientip,$cnum,$cdom);
                     73:         if ($blocked) {
                     74:             my $checkrole = "cm./$cdom/$cnum";
                     75:             if ($env{'request.course.sec'} ne '') {
                     76:                 $checkrole .= "/$env{'request.course.sec'}";
                     77:             }
                     78:             unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
                     79:                     ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
                     80:                 &grades_blocked($r,$blocktext,$showPoints);
                     81:                 return OK;
                     82:             }
                     83:         }
                     84:     }
                     85: 
1.49.6.6  raeburn    86:     unless ($cangrade) {
1.49.6.2  raeburn    87:         # Check for critical messages and redirect if present.
                     88:         my ($redirect,$url) = &Apache::loncommon::critical_redirect(300);
                     89:         if ($redirect) {
                     90:             &Apache::loncommon::content_type($r,'text/html');
                     91:             $r->header_out(Location => $url);
                     92:             return REDIRECT;
                     93:         }
                     94: 
                     95:         # Check if course needs to be re-initialized
                     96:         my $loncaparev = $r->dir_config('lonVersion');
1.49.6.4  raeburn    97:         ($reinitresult,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
1.49.6.2  raeburn    98: 
1.49.6.4  raeburn    99:         if ($reinitresult eq 'switch') {
1.49.6.2  raeburn   100:             &Apache::loncommon::content_type($r,'text/html');
                    101:             $r->send_http_header;
                    102:             $r->print(&Apache::loncommon::check_release_result(@reinit));
                    103:             return OK;
1.49.6.4  raeburn   104:         } elsif ($reinitresult eq 'update') {
                    105:             my $cid = $env{'request.course.id'};
                    106:             my $cnum = $env{'course.'.$cid.'.num'};
                    107:             my $cdom = $env{'course.'.$cid.'.domain'};
                    108:             &Apache::loncommon::content_type($r,'text/html');
                    109:             $r->send_http_header;
                    110:             &startpage($r,$showPoints);
                    111:             my $preamble = '<div id="LC_update_'.$cid.'" class="LC_info">'.
                    112:                            '<br />'.
                    113:                            &mt('Your course session is being updated because of recent changes by course personnel.').
1.49.6.7  raeburn   114:                            ' '.&mt('Please be patient').'.<br /></div>'.
1.49.6.4  raeburn   115:                            '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.49.6.5  raeburn   116:             my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
1.49.6.4  raeburn   117:             &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Updating course'));
                    118:             $r->rflush();
1.49.6.2  raeburn   119:             my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
1.49.6.7  raeburn   120:             &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
1.49.6.4  raeburn   121:             &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                    122:             my $closure = <<ENDCLOSE;
                    123: <script type="text/javascript">
                    124: // <![CDATA[
                    125: \$("#LC_update_$cid").hide('slow');
                    126: // ]]>
                    127: </script>
                    128: ENDCLOSE
1.49.6.2  raeburn   129:             if ($ferr) {
1.49.6.4  raeburn   130:                 $r->print($closure.&Apache::loncommon::end_page());
1.49.6.2  raeburn   131:                 my $requrl = $r->uri;
                    132:                 $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                    133:                 $env{'user.reinit'} = 1;
                    134:                 return HTTP_NOT_ACCEPTABLE;
1.49.6.4  raeburn   135:             } else {
                    136:                $r->print($closure);
1.49.6.2  raeburn   137:             }
                    138:         }
                    139:     }
                    140: 
1.49.6.4  raeburn   141:     unless ($reinitresult eq 'update') {
                    142:         # Send header, don't cache this page
                    143:         &Apache::loncommon::no_cache($r);
                    144:         $r->send_http_header;
                    145:         &startpage($r,$showPoints);
                    146:     }
                    147:     $r->rflush();
1.1       bowersj2  148: 
1.49.6.6  raeburn   149:     &startGradeScreen($r);
                    150: 
                    151: #
                    152: # Pick student
                    153: #
                    154:     my $uname;
                    155:     my $udom;
                    156:     my $stdid;
                    157:     if ($cangrade) {
                    158:         if ($env{'form.uname'}) { $uname=$env{'form.uname'}; }
                    159:         if ($env{'form.udom'}) { $udom=$env{'form.udom'}; }
                    160:         if ($env{'form.id'}) { $stdid=$env{'form.id'}; }
                    161:         if (($stdid) && ($udom)) {
                    162:             $uname=(&Apache::lonnet::idget($udom,[$stdid],'ids'))[1];
                    163:         }
                    164:         if (($stdid) && (!$uname)) {
                    165:             $r->print('<p><span class="LC_warning">'.&mt("Unknown Student/Employee ID: [_1]",$stdid).'</span></p>');
                    166:             $stdid='';
                    167:         }
                    168:         if (($uname eq '') && ($udom eq '')) {
                    169:             $uname = $env{'user.name'};
                    170:             $udom = $env{'user.domain'};
                    171:         }
                    172:         $r->print('<form method="post" name="quickform" action="/adm/quickgrades">');
                    173:         my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
                    174:            &Apache::loncommon::selectstudent_link('quickform','uname','udom');
                    175:         $r->print("<p>\n".&Apache::loncommon::studentbrowser_javascript()."\n");
                    176:         $r->print(&mt('For User [_1] or Student/Employee ID [_2] at Domain [_3]'
                    177:                  ,'<input type="text" value="'.$uname.'" size="12" name="uname" />'
                    178:                  ,'<input type="text" value="'.$stdid.'" size="12" name="id" /> '
                    179:                  ,$chooseopt).
                    180:                  '&nbsp;&nbsp;<input type="submit" name="display" value="'.&mt('Display Individual Student').'" /></p>');
                    181:         if (($uname) && ($udom)) {
                    182:             $r->print('<p>'.&mt('Full Name: [_1]',&Apache::loncommon::plainname($uname,$udom)).'</p>');
                    183:         }
                    184:     } else {
                    185:         $r->print('<p class="LC_info">'.&mt('This may take a few moments to display.').'</p>');
                    186:     }
                    187:     $r->rflush();
                    188: 
1.49      www       189:     my $notshowTotals=
                    190:         $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals';
1.17      bowersj2  191: 
1.49.6.6  raeburn   192:     my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,
                    193:         $topLevelRight,$topLevelAttempted) = &getData($showPoints,$uname,$udom);
1.1       bowersj2  194: 
1.49.6.6  raeburn   195:     if (ref($navmap)) {
1.49.6.9! raeburn   196:         my $nostdtotals;
        !           197:         if ($showPoints) {
        !           198:             if ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard') {
        !           199:                 my $hidetotals = $env{'course.'.$env{'request.course.id'}.'.hidetotals'};
        !           200:                 if ($hidetotals eq 'all') {
        !           201:                     $nostdtotals = 1;
        !           202:                 } elsif ($hidetotals ne '') {
        !           203:                     my $usec;
        !           204:                     if ($cangrade) {
        !           205:                         if (($uname eq $env{'user.name'}) && ($udom eq $env{'user.domain'})) {
        !           206:                             $usec = $env{'request.course.sec'};
        !           207:                         } else {
        !           208:                             $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
        !           209:                         }
        !           210:                     } else {
        !           211:                         $usec = $env{'request.course.sec'};
        !           212:                     }
        !           213:                     if ($usec ne '') {
        !           214:                         my %secnototals;
        !           215:                         map { $secnototals{$_} = 1; } split(/,/,$hidetotals);
        !           216:                         if ($secnototals{$usec}) {
        !           217:                             $nostdtotals = 1;
        !           218:                         }
        !           219:                     }
        !           220:                 }
        !           221:             }
        !           222:         }
        !           223:         &outputTable($r,$showPoints,$notshowTotals,$nostdtotals,$navmap,
        !           224:                      $totalParts,$totalPossible,$totalRight,$totalAttempted,
        !           225:                      $topLevelParts,$topLevelRight,$topLevelAttempted);
1.49.6.6  raeburn   226:     } else {
                    227:         if ($cangrade) { $r->print("\n</form>\n"); }
1.7       bowersj2  228:         my $requrl = $r->uri;
1.49.6.6  raeburn   229:         $env{'user.error.msg'} = "$requrl:bre:0:0:Navmap initialization failed.";
1.7       bowersj2  230:         return HTTP_NOT_ACCEPTABLE;
                    231:     }
1.49.6.6  raeburn   232:     if ($cangrade) { $r->print("\n</form>\n"); }
                    233:     &endGradeScreen($r);
                    234:     return OK;
                    235: }
1.7       bowersj2  236: 
1.49.6.8  raeburn   237: sub grades_blocked {
                    238:     my ($r,$blocktext,$caller) = @_;
                    239:     my $title = 'Points Display';
                    240:     if ($caller eq 'spreadsheet') {
                    241:         $title = 'Spreadsheet';
                    242:     } elsif ($env{'course.'.$env{'request.course.id'}.'.grading'} ne 'standard') {
                    243:         $title = 'Completed Problems Display';
                    244:     }
                    245:     my $brcrum = [{href=>"/adm/quickgrades",text => $title}];
                    246:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    247:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/quickgrades',
                    248:                                             text=> $title});
                    249:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs($title);
                    250:     &Apache::loncommon::content_type($r,'text/html');
                    251:     &Apache::loncommon::no_cache($r);
                    252:     $r->send_http_header;
                    253:     $r->print(&Apache::loncommon::start_page($title).
                    254:               $breadcrumbs.
                    255:               $blocktext.
                    256:               &Apache::loncommon::end_page());
                    257:     return;
                    258: }
                    259: 
1.49.6.6  raeburn   260: #
                    261: # Go through the complete course and collect data
                    262: #
1.17      bowersj2  263: 
1.49.6.6  raeburn   264: sub getData {
1.17      bowersj2  265: 
1.49.6.6  raeburn   266:     my ($showPoints,$uname,$udom)=@_;
1.2       bowersj2  267: 
1.49.6.6  raeburn   268:     # Create the nav map
                    269:     my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom);
                    270: 
                    271:     if (!defined($navmap)) {
                    272:         return ();
                    273:     }
                    274: 
                    275:     my $res = $navmap->firstResource(); # temp resource to access constants
1.1       bowersj2  276: 
                    277:     my $iterator = $navmap->getIterator(undef, undef, undef, 1);
                    278:     my $depth = 1;
                    279:     $iterator->next(); # ignore first BEGIN_MAP
                    280:     my $curRes = $iterator->next();
1.49.6.6  raeburn   281: 
1.5       bowersj2  282:     # General overview of the following: Walk along the course resources.
                    283:     # For every problem in the resource, tell its parent maps how many
                    284:     # parts and how many parts correct it has. After that, each map will
                    285:     # have a count of the total parts underneath it, correct and otherwise.
                    286:     # After that, we will walk through the course again and read off
                    287:     # maps in order, with their data. 
                    288:     # (If in the future people decide not to be cumulative, only add
                    289:     #  the counts to the parent map.)
1.17      bowersj2  290:     # For convenience, "totalParts" is also "totalPoints" when we're looking
                    291:     #  at points; I can't come up with a variable name that makes sense
                    292:     #  equally for both cases.
1.5       bowersj2  293: 
                    294:     my $totalParts = 0; my $totalPossible = 0; my $totalRight = 0;
1.28      bowersj2  295:     my $totalAttempted = 0;
1.14      bowersj2  296:     my $now = time();
1.28      bowersj2  297:     my $topLevelParts = 0; my $topLevelRight = 0; my $topLevelAttempted = 0;
1.5       bowersj2  298: 
                    299:     # Pre-run: Count parts correct
1.1       bowersj2  300:     while ( $depth > 0 ) {
                    301:         if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
                    302:         if ($curRes == $iterator->END_MAP()) { $depth--; }
                    303: 
1.7       bowersj2  304:         if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout)
1.5       bowersj2  305:         {
                    306:             # Get number of correct, incorrect parts
                    307:             my $parts = $curRes->parts();
                    308:             my $partsRight = 0;
1.17      bowersj2  309: 	    my $partsCount = 0;
1.28      bowersj2  310: 	    my $partsAttempted = 0;
1.5       bowersj2  311:             my $stack = $iterator->getStack();
                    312:             
                    313:             for my $part (@{$parts}) {
1.28      bowersj2  314: 		my $dateStatus = $curRes->getDateStatus($part);
1.49.6.6  raeburn   315:                 my $weight = $curRes->weight($part);
                    316:                 my $problemstatus = $curRes->problemstatus($part);
                    317: 
                    318:                 if ($curRes->solved($part) eq 'excused') {
1.21      matthew   319:                     next;
                    320:                 }
1.17      bowersj2  321: 		if ($showPoints) {
1.28      bowersj2  322: 		    my $score = 0;
                    323: 		    # If we're not telling status and the answer date isn't passed yet, 
                    324: 		    # it's an "attempted" point
1.49.6.6  raeburn   325: 		    if ((($problemstatus eq 'no') ||
                    326:                          ($problemstatus eq 'no_feedback_ever')) &&
1.28      bowersj2  327: 			($dateStatus != $curRes->ANSWER_OPEN)) {
1.31      albertel  328: 			my $status = $curRes->simpleStatus($part);
                    329: 			if ($status == $curRes->ATTEMPTED) {
1.49.6.6  raeburn   330: 			    $partsAttempted += $weight;
1.31      albertel  331: 			    $totalAttempted += $partsAttempted;
                    332: 			}
1.28      bowersj2  333: 		    } else {
1.49.6.6  raeburn   334: 			$score = &Apache::grades::compute_points($weight, $curRes->awarded($part));
1.28      bowersj2  335: 		    }
1.17      bowersj2  336: 		    $partsRight += $score;
                    337: 		    $totalRight += $score;
1.49.6.6  raeburn   338: 		    $partsCount += $weight;
1.18      bowersj2  339: 
1.17      bowersj2  340: 		    if ($curRes->opendate($part) < $now) {
1.49.6.6  raeburn   341: 			$totalPossible += $weight;
1.17      bowersj2  342: 		    }
1.49.6.6  raeburn   343: 		    $totalParts += $weight;
1.17      bowersj2  344: 		} else {
1.27      bowersj2  345: 		    my $status = $curRes->simpleStatus($part);
1.17      bowersj2  346: 		    my $thisright = 0;
                    347: 		    $partsCount++;
1.37      albertel  348: 		    if ($status == $curRes->CORRECT ||
                    349: 			$status == $curRes->PARTIALLY_CORRECT ) {
1.17      bowersj2  350: 			$partsRight++;
                    351: 			$totalRight++;
                    352: 			$thisright = 1;
                    353: 		    }
1.28      bowersj2  354: 
                    355: 		    if ($status == $curRes->ATTEMPTED) {
                    356: 			$partsAttempted++;
                    357: 			$totalAttempted++;
                    358: 		    }
1.17      bowersj2  359: 		    
1.19      bowersj2  360: 		    $totalParts++;
1.17      bowersj2  361: 		    if ($curRes->opendate($part) < $now) {
                    362: 			$totalPossible++;
                    363: 		    }
                    364: 		}
1.5       bowersj2  365:             }
1.15      bowersj2  366: 
                    367:             if ($depth == 1) { # in top-level only
1.19      bowersj2  368: 		$topLevelParts += $partsCount;
1.15      bowersj2  369: 		$topLevelRight += $partsRight;
1.28      bowersj2  370: 		$topLevelAttempted += $partsAttempted;
1.15      bowersj2  371: 	    }
                    372: 
1.5       bowersj2  373:             # Crawl down stack and record parts correct and total
                    374:             for my $res (@{$stack}) {
                    375:                 if (ref($res) && $res->is_map()) {
                    376:                     if (!defined($res->{DATA}->{CHILD_PARTS})) {
                    377:                         $res->{DATA}->{CHILD_PARTS} = 0;
                    378:                         $res->{DATA}->{CHILD_CORRECT} = 0;
1.28      bowersj2  379: 			$res->{DATA}->{CHILD_ATTEMPTED} = 0;
1.5       bowersj2  380:                     }
                    381:                     
1.17      bowersj2  382:                     $res->{DATA}->{CHILD_PARTS} += $partsCount;
1.5       bowersj2  383:                     $res->{DATA}->{CHILD_CORRECT} += $partsRight;
1.28      bowersj2  384: 		    $res->{DATA}->{CHILD_ATTEMPTED} += $partsAttempted;
1.5       bowersj2  385:                 }
                    386:             }
                    387:         }
                    388:         $curRes = $iterator->next();
                    389:     }
1.49.6.6  raeburn   390:     return ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,
                    391:             $topLevelParts,$topLevelRight,$topLevelAttempted);
                    392: }
1.5       bowersj2  393: 
1.49.6.6  raeburn   394: #
                    395: # Outputting everything.
                    396: #
                    397: 
                    398: sub outputTable {
                    399: 
1.49.6.9! raeburn   400:     my ($r,$showPoints,$notshowTotals,$nostdtotals,$navmap,$totalParts,$totalPossible,
        !           401:         $totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
1.5       bowersj2  402: 
1.7       bowersj2  403:     my @start = (255, 255, 192);
1.5       bowersj2  404:     my @end   = (0, 192, 0);
                    405: 
                    406:     my $indentString = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                    407: 
                    408:     # Second pass: Print the maps.
1.43      bisitz    409:     $r->print(&Apache::loncommon::start_data_table()
                    410:              .&Apache::loncommon::start_data_table_header_row()
                    411:              .'<th>'.&mt('Folder').'</th>');
1.49.6.5  raeburn   412:     my $title = &mt($showPoints ? "Points Scored" : "Done");
1.28      bowersj2  413:     if ($totalAttempted) {
1.49.6.6  raeburn   414:         $title .= " / " . &mt("Attempted");
1.28      bowersj2  415:     }
1.49      www       416:     $r->print("<th>$title".($notshowTotals?'':" / ".&mt('Total')).'</th>'
1.43      bisitz    417:              .&Apache::loncommon::end_data_table_header_row());
1.49.6.6  raeburn   418: #
                    419: # Output of folder scores
                    420: #
                    421: 
                    422:     my $iterator = $navmap->getIterator(undef, undef, undef, 1);
                    423:     my $depth = 1;
                    424:     $iterator->next(); # ignore first BEGIN_MAP
                    425:     my $curRes = $iterator->next();
                    426: 
1.5       bowersj2  427:     while ($depth > 0) {
                    428:         if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
                    429:         if ($curRes == $iterator->END_MAP()) { $depth--; }
                    430: 
                    431:         if (ref($curRes) && $curRes->is_map()) {
                    432:             my $title = $curRes->compTitle();
                    433:             
                    434:             my $correct = $curRes->{DATA}->{CHILD_CORRECT};
                    435:             my $total = $curRes->{DATA}->{CHILD_PARTS};
1.28      bowersj2  436: 	    my $attempted = $curRes->{DATA}->{CHILD_ATTEMPTED};
1.5       bowersj2  437: 
1.6       bowersj2  438:             if ($total > 0) {
                    439:                 my $ratio;
                    440:                 $ratio = $correct / $total;
1.49.6.4  raeburn   441:                 my $color = &mixColors(\@start, \@end, $ratio);
1.43      bisitz    442:                 $r->print(&Apache::loncommon::start_data_table_row()
                    443:                          .'<td style="background-color:'.$color.';">');
1.6       bowersj2  444:                 
1.15      bowersj2  445: 		my $thisIndent = '';
                    446:                 for (my $i = 1; $i < $depth; $i++) { $thisIndent .= $indentString; }
1.6       bowersj2  447:                 
1.15      bowersj2  448:                 $r->print("$thisIndent$title</td>");
1.28      bowersj2  449: 		if ($totalAttempted) {
1.45      bisitz    450: 		    $r->print('<td valign="top">'
                    451:                              .$thisIndent
                    452:                              .'<span class="LC_nobreak">'
1.49      www       453:                              .$correct.' / '.$attempted.($notshowTotals?'':' / '.$total)
1.45      bisitz    454:                              .'</span></td>'
                    455:                              .&Apache::loncommon::end_data_table_row()
                    456:                     );
1.28      bowersj2  457: 		} else {
1.45      bisitz    458: 		    $r->print('<td valign="top">'
                    459:                              .$thisIndent
                    460:                              .'<span class="LC_nobreak">'
1.49      www       461:                              .$correct.($notshowTotals?'':' / '.$total)
1.45      bisitz    462:                              .'</span></td>'
1.43      bisitz    463:                              .&Apache::loncommon::end_data_table_row());
1.28      bowersj2  464: 		}
1.6       bowersj2  465:             }
1.5       bowersj2  466:         }
1.4       bowersj2  467: 
1.5       bowersj2  468:         $curRes = $iterator->next();
                    469:     }
1.4       bowersj2  470: 
1.6       bowersj2  471:     # If there were any problems at the top level, print an extra "catchall"
1.15      bowersj2  472:     if ($topLevelParts > 0) {
                    473:         my $ratio = $topLevelRight / $topLevelParts;
1.49.6.4  raeburn   474:         my $color = &mixColors(\@start, \@end, $ratio);
1.43      bisitz    475:         $r->print(&Apache::loncommon::start_data_table_row()
                    476:                  .'<td style="background-color:'.$color.';">');
1.25      www       477:         $r->print(&mt("Problems Not Contained In A Folder")."</td><td>");
1.43      bisitz    478:         $r->print("$topLevelRight / $topLevelParts</td>"
                    479:                  .&Apache::loncommon::end_data_table_row());
1.6       bowersj2  480:     }
1.4       bowersj2  481: 
1.49.6.6  raeburn   482: #
                    483: # show totals (if applicable), close table
                    484: #
1.35      albertel  485:     if ($showPoints) {
1.49.6.9! raeburn   486:         unless ($nostdtotals) {
        !           487: 	    my $maxHelpLink = &Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct");
1.2       bowersj2  488: 
1.49.6.9! raeburn   489: 	    $title = $showPoints ? "Points" : "Parts Done";
        !           490: 	    my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done");
        !           491: 	    $r->print(&Apache::loncommon::start_data_table_row()
        !           492:                      .'<td colspan="2" align="right">'.$totaltitle.': <b>'.$totalRight.'</b><br />');
        !           493: 	    $r->print(&mt('Max Possible To Date')." $maxHelpLink: <b>$totalPossible</b><br />");
        !           494: 	    $title = $showPoints ? "Points" : "Parts";
        !           495: 	    $r->print(&mt("Total $title In Course").': <b>'.$totalParts.'</b></td>'
        !           496:                      .&Apache::loncommon::end_data_table_row());
        !           497:         }
1.34      www       498:     }
1.1       bowersj2  499: 
1.49.6.6  raeburn   500:     $r->print(&Apache::loncommon::end_data_table());
                    501:     return;
1.5       bowersj2  502: }
                    503: 
1.49.6.4  raeburn   504: sub startpage {
                    505:     my ($r,$showPoints) = @_;
                    506:     my $title = "Grading and Statistics";#$showPoints ? "Points Display" : "Completed Problems Display";
                    507:     my $brcrum = [{href=>"/adm/quickgrades",text => "Points Display"}];
                    508:     $r->print(&Apache::loncommon::start_page($title,undef,
                    509:                                             {'bread_crumbs' => $brcrum})
                    510:              );
                    511: }
                    512: 
1.49.6.6  raeburn   513: sub startGradeScreen {
                    514:     my ($r)=@_;
                    515: 
                    516:     my $showPoints =
                    517:         $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard';
1.49.6.9! raeburn   518:     my $hidetotals =
        !           519:         $env{'course.'.$env{'request.course.id'}.'.hidetotals'};
1.49.6.6  raeburn   520:     my $notshowSPRSlink =
                    521:         (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external')
                    522:       || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals'));
                    523:     my $notshowTotals =
                    524:         $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals';
                    525:     my $showSPRSlink =
                    526:         $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet';
                    527: 
                    528:     my $allowed_to_view = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
                    529:     if ((!$allowed_to_view) && ($env{'request.course.sec'} ne '')) {
                    530:         $allowed_to_view = &Apache::lonnet::allowed('vgr',
                    531:                                "$env{'request.course.id'}/$env{'request.course.sec'}");
                    532:     }
                    533: 
                    534:     my $allowed_to_edit = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
                    535:     if ((!$allowed_to_edit) && ($env{'request.course.sec'} ne '')) {
                    536:         $allowed_to_edit = &Apache::lonnet::allowed('mgr',
                    537:                                "$env{'request.course.id'}/$env{'request.course.sec'}");
                    538:     }
                    539: 
                    540:     if ($allowed_to_view) {
                    541:         my @notes;
                    542:         push(@notes,&mt('Students do not see total points.')) if ($notshowTotals);
                    543:         push(@notes,&mt('Students do not see link to spreadsheet.')) if ($notshowSPRSlink);
                    544:         push(@notes,&mt('Students will see points based on problem weights.')) if ($showPoints);
1.49.6.9! raeburn   545:         if (($showPoints) && ($hidetotals ne '')) {
        !           546:             if ($hidetotals eq 'all') {
        !           547:                 push(@notes,&mt('Students do not see course totals.'));
        !           548:             } else {
        !           549:                 my @secs = split(/,/,$hidetotals);
        !           550:                 if (@secs == 1) {
        !           551:                     push(@notes,&mt('Students in section [_1] do not see course totals.',
        !           552:                                     $hidetotals));
        !           553:                 } elsif (@secs > 1) {
        !           554:                     push(@notes,&mt('Students in sections [_1] do not see course totals.',
        !           555:                                     join(', ',@secs)));
        !           556:                 }
        !           557:             }
        !           558:         }
1.49.6.6  raeburn   559:         push(@notes,&mt('Students will see link to spreadsheet.')) if ($showSPRSlink);
                    560:         push(@notes,&Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading'));
                    561:         $r->print(&Apache::loncommon::head_subbox(join('&nbsp;&nbsp;',@notes)));
                    562:     } elsif (!$allowed_to_edit) {
                    563:         if (!$showPoints && !$notshowSPRSlink ) {
                    564:             $r->print(&Apache::loncommon::head_subbox(
                    565:                       &mt('This screen shows how many problems (or problem parts) you have completed'
                    566:                      .', and how many you have not yet done.'
                    567:                      .' You can also look at [_1]a detailed score sheet[_2].'
                    568:                      ,'<a href="/adm/studentcalc">','</a>')));
                    569:         }
                    570:     }
                    571:     return;
                    572: }
                    573: 
                    574: sub endGradeScreen {
                    575:     my ($r)=@_;
                    576:     $r->print(&Apache::loncommon::end_page());
                    577:     return;
                    578: }
                    579: 
1.5       bowersj2  580: # Pass this two refs to arrays for the start and end color, and a number
                    581: # from 0 to 1 for how much of the latter you want to mix in. It will
                    582: # return a string ready to show ("#FFC309");
                    583: sub mixColors {
                    584:     my $start = shift;
                    585:     my $end = shift;
                    586:     my $ratio = shift;
                    587:     
1.9       matthew   588:     my ($a,$b);
1.5       bowersj2  589:     my $final = "";
1.9       matthew   590:     $a = $start->[0]; $b = $end->[0];
1.5       bowersj2  591:     my $mix1 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
1.9       matthew   592:     $a = $start->[1]; $b = $end->[1];
1.5       bowersj2  593:     my $mix2 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
1.9       matthew   594:     $a = $start->[2]; $b = $end->[2];
1.5       bowersj2  595:     my $mix3 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
                    596: 
1.16      bowersj2  597:     $final = sprintf "%02x%02x%02x", $mix1, $mix2, $mix3;
1.5       bowersj2  598:     return "#" . $final;
1.1       bowersj2  599: }
                    600: 
                    601: 1;

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