version 1.370, 2018/01/31 15:28:28
|
version 1.374, 2018/09/20 14:16:51
|
Line 53 use Apache::loncapamath();
|
Line 53 use Apache::loncapamath();
|
use Apache::Constants qw(:common); |
use Apache::Constants qw(:common); |
use Apache::loncommon(); |
use Apache::loncommon(); |
use Apache::lonparmset(); |
use Apache::lonparmset(); |
|
use Apache::lonnavmaps(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
|
use LONCAPA qw(:DEFAULT :match); |
|
use LONCAPA::ltiutils(); |
use Time::HiRes qw( gettimeofday tv_interval ); |
use Time::HiRes qw( gettimeofday tv_interval ); |
use HTML::Entities(); |
use HTML::Entities(); |
use File::Copy(); |
use File::Copy(); |
|
|
# FIXME - improve commenting |
# FIXME - improve commenting |
|
|
|
my $registered_cleanup; |
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register_insert(); |
&Apache::lonxml::register_insert(); |
Line 238 sub check_slot_access {
|
Line 242 sub check_slot_access {
|
$consumed_uniq = $slot{'uniqueperiod'}; |
$consumed_uniq = $slot{'uniqueperiod'}; |
if ($slot{'iptied'}) { |
if ($slot{'iptied'}) { |
$ipused = $Apache::lonhomework::history{"$checkin.ip"}; |
$ipused = $Apache::lonhomework::history{"$checkin.ip"}; |
unless (($ip ne '') && ($ipused eq $ip)) { |
unless (($ip ne '') && |
|
(($ipused eq $ip) || ($ENV{'REMOTE_ADDR'} eq '127.0.0.1'))) { |
$blockip = $slot{'iptied'}; |
$blockip = $slot{'iptied'}; |
$slot_name = $checkinslot; |
$slot_name = $checkinslot; |
$returned_slot = \%slot; |
$returned_slot = \%slot; |
Line 252 sub check_slot_access {
|
Line 257 sub check_slot_access {
|
} else { |
} else { |
return ($status,$datemsg); |
return ($status,$datemsg); |
} |
} |
} |
} |
|
|
if ($status eq 'CLOSED' || |
if ($status eq 'CLOSED' || |
$status eq 'INVALID_ACCESS' || |
$status eq 'INVALID_ACCESS' || |
Line 262 sub check_slot_access {
|
Line 267 sub check_slot_access {
|
if ($env{'request.state'} eq "construct") { |
if ($env{'request.state'} eq "construct") { |
return ($status,$datemsg); |
return ($status,$datemsg); |
} |
} |
|
|
if ($type eq 'Task') { |
if ($type eq 'Task') { |
if ($checkedin && |
if ($checkedin && |
$Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass') { |
$Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass') { |
Line 272 sub check_slot_access {
|
Line 277 sub check_slot_access {
|
return ('SHOW_ANSWER'); |
return ('SHOW_ANSWER'); |
} |
} |
} |
} |
|
} elsif (($type eq 'problem') && |
|
($Apache::lonhomework::browse eq 'F') && |
|
($ENV{'REMOTE_ADDR'} eq '127.0.0.1') && |
|
($env{'form.grade_courseid'} eq $env{'request.course.id'}) && |
|
(&Apache::lonnet::allowed('mgr',$env{'request.course.id'}))) { |
|
return ($status,$datemsg); |
} |
} |
|
|
my $availablestudent = &Apache::lonnet::EXT("resource.0.availablestudent",$symb); |
my $availablestudent = &Apache::lonnet::EXT("resource.0.availablestudent",$symb); |
Line 365 sub check_slot_access {
|
Line 376 sub check_slot_access {
|
$earlyout = 1; |
$earlyout = 1; |
} |
} |
} |
} |
if (($currtries == $maxtries) || ($is_correct)) { |
if ($currtries == $maxtries) { |
$earlyout = 1; |
$earlyout = 1; |
} else { |
} else { |
$numgraded ++; |
$numgraded ++; |
Line 1671 sub handler {
|
Line 1682 sub handler {
|
} |
} |
# just render the page normally outside of construction space |
# just render the page normally outside of construction space |
&Apache::lonxml::debug("not construct"); |
&Apache::lonxml::debug("not construct"); |
|
undef(@Apache::lonhomework::ltipassback); |
&renderpage($request,$file,undef,undef,$donemsg); |
&renderpage($request,$file,undef,undef,$donemsg); |
|
if (@Apache::lonhomework::ltipassback) { |
|
unless ($registered_cleanup) { |
|
my $handlers = $request->get_handlers('PerlCleanupHandler'); |
|
$request->set_handlers('PerlCleanupHandler' => |
|
[\&do_ltipassback,@{$handlers}]); |
|
} |
|
} |
} |
} |
#my $td=&tv_interval($t0); |
#my $td=&tv_interval($t0); |
#&Apache::lonxml::debug("Spent $td seconds processing"); |
#&Apache::lonxml::debug("Spent $td seconds processing"); |
Line 1859 sub convert_for_js {
|
Line 1878 sub convert_for_js {
|
return $return; |
return $return; |
} |
} |
|
|
|
sub do_ltipassback { |
|
if (@Apache::lonhomework::ltipassback) { |
|
foreach my $item (@Apache::lonhomework::ltipassback) { |
|
if (ref($item) eq 'HASH') { |
|
if ((ref($item->{'lti'}) eq 'HASH') && ($item->{'cid'} =~ /^($match_domain)_($match_courseid)$/)) { |
|
my ($cdom,$cnum) = ($1,$2); |
|
my $ckey = $item->{'lti'}->{'key'}; |
|
my $secret = $item->{'lti'}->{'secret'}; |
|
my $msgformat = $item->{'lti'}->{'passbackformat'}; |
|
my $sigmethod = 'HMAC-SHA1'; |
|
my $id = $item->{'pbid'}; |
|
my $url = $item->{'pburl'}; |
|
my $scope = $item->{'scope'}; |
|
my $map = $item->{'ltimap'}; |
|
my $symb = $item->{'ltisymb'}; |
|
my $uname = $item->{'uname'}; |
|
my $udom = $item->{'udom'}; |
|
my $scoretype = $item->{'format'}; |
|
my ($total,$possible); |
|
if ($scope eq 'resource') { |
|
$total = $item->{'total'}; |
|
$possible = $item->{'possible'}; |
|
} elsif ($scope eq 'map') { |
|
($total,$possible) = &get_lti_score($uname,$udom,$map); |
|
} elsif ($scope eq 'course') { |
|
($total,$possible) = &get_lti_score($uname,$udom); |
|
} |
|
if (($ckey ne '') && ($secret ne '') && ($id ne '') && ($url ne '') && ($possible)) { |
|
&LONCAPA::ltiutils::send_grade($id,$url,$ckey,$secret,$scoretype,$sigmethod, |
|
$msgformat,$total,$possible); |
|
} |
|
} |
|
} |
|
} |
|
undef(@Apache::lonhomework::ltipassback); |
|
} |
|
} |
|
|
|
sub get_lti_score { |
|
my ($uname,$udom,$mapurl) = @_; |
|
my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom); |
|
if (ref($navmap)) { |
|
my $iterator; |
|
if ($mapurl ne '') { |
|
my $map = $navmap->getResourceByUrl($mapurl); |
|
my $firstres = $map->map_start(); |
|
my $finishres = $map->map_finish(); |
|
$iterator = $navmap->getIterator($firstres,$finishres,undef,1); |
|
} else { |
|
$iterator = $navmap->getIterator(undef,undef,undef,1); |
|
} |
|
if (ref($iterator)) { |
|
my $depth = 1; |
|
my $total = 0; |
|
my $possible = 0; |
|
$iterator->next(); # ignore first BEGIN_MAP |
|
my $curRes = $iterator->next(); |
|
while ( $depth > 0 ) { |
|
if ($curRes == $iterator->BEGIN_MAP()) {$depth++;} |
|
if ($curRes == $iterator->END_MAP()) { $depth--; } |
|
if (ref($curRes) && $curRes->is_gradable() && !$curRes->randomout) { |
|
my $parts = $curRes->parts(); |
|
foreach my $part (@{$parts}) { |
|
next if ($curRes->solved($part) eq 'excused'); |
|
$total += $curRes->weight($part) * $curRes->awarded($part); |
|
$possible += $curRes->weight($part); |
|
} |
|
} |
|
$curRes = $iterator->next(); |
|
} |
|
if ($total > $possible) { |
|
$total = $possible; |
|
} |
|
return ($total,$possible); |
|
} |
|
} |
|
return; |
|
} |
|
|
1; |
1; |
__END__ |
__END__ |