--- loncom/interface/lonquickgrades.pm 2025/01/16 21:11:56 1.49.6.8.2.6 +++ loncom/interface/lonquickgrades.pm 2011/05/24 18:06:10 1.90 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Quick Student Grades Display # -# $Id: lonquickgrades.pm,v 1.49.6.8.2.6 2025/01/16 21:11:56 raeburn Exp $ +# $Id: lonquickgrades.pm,v 1.90 2011/05/24 18:06:10 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -29,13 +29,12 @@ package Apache::lonquickgrades; use strict; -use Apache::Constants qw(:common :http REDIRECT); +use Apache::Constants qw(:common :http); use POSIX; use Apache::loncommon; use Apache::lonlocal; use Apache::lonnet; use Apache::grades; -use Apache::lonuserstate; sub handler { my $r = shift; @@ -58,110 +57,31 @@ sub real_handler { return OK; } - my $cangrade=&Apache::lonnet::allowed('mgr'); - my $showPoints = - $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard'; - - my $reinitresult; + # Send header, don't cache this page + &Apache::loncommon::no_cache($r); + $r->send_http_header; - if ($env{'request.course.id'}) { - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - my $clientip = &Apache::lonnet::get_requestor_ip($r); - my ($blocked,$blocktext) = - &Apache::loncommon::blocking_status('grades',$clientip,$cnum,$cdom); - if ($blocked) { - my $checkrole = "cm./$cdom/$cnum"; - if ($env{'request.course.sec'} ne '') { - $checkrole .= "/$env{'request.course.sec'}"; - } - unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) && - ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) { - &grades_blocked($r,$blocktext,$showPoints); - return OK; - } - } - } + my $showPoints = + (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard') + || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories')); + my $notshowSPRSlink = + (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external') + || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals')); + my $notshowTotals= + $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals'; + my $showCategories= + $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories'; - unless ($cangrade) { - # Check for critical messages and redirect if present. - my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'grades'); - if ($redirect) { - &Apache::loncommon::content_type($r,'text/html'); - $r->header_out(Location => $url); - return REDIRECT; - } - - # Check if course needs to be re-initialized - my $loncaparev = $r->dir_config('lonVersion'); - ($reinitresult,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev); - - if ($reinitresult eq 'switch') { - &Apache::loncommon::content_type($r,'text/html'); - $r->send_http_header; - $r->print(&Apache::loncommon::check_release_result(@reinit)); - return OK; - } - my ($cid,$cnum,$cdom); - if ($reinitresult) { - $cid = $env{'request.course.id'}; - $cnum = $env{'course.'.$cid.'.num'}; - $cdom = $env{'course.'.$cid.'.domain'}; - } - if (($reinitresult eq 'main') || ($reinitresult eq 'both')) { - &Apache::loncommon::content_type($r,'text/html'); - $r->send_http_header; - &startpage($r,$showPoints); - my $preamble = '
'.&mt("Unknown Student/Employee ID: [_1]",$stdid).'
'); $stdid=''; } - if (($uname eq '') && ($udom eq '')) { - $uname = $env{'user.name'}; - $udom = $env{'user.domain'}; - } $r->print('\n"); } + &endGradeScreen($r); + return OK; + +} + +sub startGradeScreen { + my ($r,$mode)=@_; + + my $showPoints = + $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard'; + my $notshowSPRSlink = + (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external') + || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals') + || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories')); my $notshowTotals= $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals'; + my $showCategories= + $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories'; - my $usec; - if ($cangrade) { - if (($uname eq $env{'user.name'}) && ($udom eq $env{'user.domain'})) { - $usec = $env{'request.course.sec'}; - } else { - $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'}); - } - } else { - $usec = $env{'request.course.sec'}; + my $allowed_to_view = &Apache::lonnet::allowed('vgr',$env{'request.course.id'}); + my $allowed_to_edit = &Apache::lonnet::allowed('mgr',$env{'request.course.id'}); + + if ($allowed_to_view) { + my @notes; + push(@notes,&mt('Students do not see total points.')) if ($notshowTotals); + push(@notes,&mt('Students do not see link to spreadsheet.')) if ($notshowSPRSlink); + push(@notes,&mt('Students will see points based on problem weights.')) if ($showPoints); + push(@notes,&mt('Students will see points based on categories.')) if ($showCategories); + push(@notes, &Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading')); + $r->print(&Apache::loncommon::head_subbox(join(' ',@notes))); } - my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts, - $topLevelRight,$topLevelAttempted) = &getData($showPoints,$uname,$udom,$usec); - if (ref($navmap)) { - my $nostdtotals; - if ($showPoints) { - if ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard') { - my $hidetotals = $env{'course.'.$env{'request.course.id'}.'.hidetotals'}; - if ($hidetotals eq 'all') { - $nostdtotals = 1; - } elsif ($hidetotals ne '') { - if ($usec ne '') { - my %secnototals; - map { $secnototals{$_} = 1; } split(/,/,$hidetotals); - if ($secnototals{$usec}) { - $nostdtotals = 1; - } - } - } - } - } - &outputTable($r,$showPoints,$notshowTotals,$nostdtotals,$navmap, - $totalParts,$totalPossible,$totalRight,$totalAttempted, - $topLevelParts,$topLevelRight,$topLevelAttempted); - } else { - if ($cangrade) { $r->print("\n\n"); } - my $requrl = $r->uri; - $env{'user.error.msg'} = "$requrl:bre:0:0:Navmap initialization failed."; - return HTTP_NOT_ACCEPTABLE; + $r->print("\n".''.&mt('Total raw points: [_1]/[_2]',$totalcorrect,$totalpossible).'
'); + if ($cangrade) { + $r->print(''.&mt('Adjusted raw points: [_1]/[_2]',$totalcorrect,$totalpossible).'
'); + } + - my $allowed_to_edit = &Apache::lonnet::allowed('mgr',$env{'request.course.id'}); - if ((!$allowed_to_edit) && ($env{'request.course.sec'} ne '')) { - $allowed_to_edit = &Apache::lonnet::allowed('mgr', - "$env{'request.course.id'}/$env{'request.course.sec'}"); +# Calculation + if ($output) { $r->print('