version 1.9, 2018/05/15 04:33:17
|
version 1.10, 2018/05/15 04:59:22
|
Line 34 use Digest::SHA;
|
Line 34 use Digest::SHA;
|
use UUID::Tiny ':std'; |
use UUID::Tiny ':std'; |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::loncommon; |
use Apache::loncommon; |
|
use Math::Round(); |
use LONCAPA qw(:DEFAULT :match); |
use LONCAPA qw(:DEFAULT :match); |
|
|
# |
# |
Line 474 sub release_tool_lock {
|
Line 475 sub release_tool_lock {
|
# |
# |
|
|
sub lti_provider_scope { |
sub lti_provider_scope { |
my ($tail,$cdom,$cnum) = @_; |
my ($tail,$cdom,$cnum,$getunenc) = @_; |
my ($scope,$realuri); |
my ($scope,$realuri,$passkey,$unencsymb); |
if ($tail =~ m{^/uploaded/$cdom/$cnum/(?:default|supplemental)(?:|_\d+)\.(?:sequence|page)(|___\d+___.+)$}) { |
if ($tail =~ m{^/?uploaded/$cdom/$cnum/(?:default|supplemental)(?:|_\d+)\.(?:sequence|page)(|___\d+___.+)$}) { |
my $rest = $1; |
my $rest = $1; |
if ($rest eq '') { |
if ($rest eq '') { |
$scope = 'map'; |
$scope = 'map'; |
Line 489 sub lti_provider_scope {
|
Line 490 sub lti_provider_scope {
|
} else { |
} else { |
$scope = 'resource'; |
$scope = 'resource'; |
$realuri .= '?symb='.$tail; |
$realuri .= '?symb='.$tail; |
|
$passkey = $tail; |
|
if ($getunenc) { |
|
$unencsymb = $tail; |
|
} |
} |
} |
} |
} |
} elsif ($tail =~ m{^/res/$match_domain/$match_username/.+\.(?:sequence|page)(|___\d+___.+)$}) { |
} elsif ($tail =~ m{^/?res/$match_domain/$match_username/.+\.(?:sequence|page)(|___\d+___.+)$}) { |
my $rest = $1; |
my $rest = $1; |
if ($rest eq '') { |
if ($rest eq '') { |
$scope = 'map'; |
$scope = 'map'; |
Line 504 sub lti_provider_scope {
|
Line 509 sub lti_provider_scope {
|
} else { |
} else { |
$scope = 'resource'; |
$scope = 'resource'; |
$realuri .= '?symb='.$tail; |
$realuri .= '?symb='.$tail; |
|
$passkey = $tail; |
|
if ($getunenc) { |
|
$unencsymb = $tail; |
|
} |
} |
} |
} |
} |
} elsif ($tail =~ m{^/tiny/$cdom/(\w+)$}) { |
} elsif ($tail =~ m{^/tiny/$cdom/(\w+)$}) { |
Line 528 sub lti_provider_scope {
|
Line 537 sub lti_provider_scope {
|
} else { |
} else { |
$scope = 'resource'; |
$scope = 'resource'; |
} |
} |
|
$passkey = $symb; |
if ((&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) && |
if ((&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) && |
(!$env{'request.role.adv'})) { |
(!$env{'request.role.adv'})) { |
$realuri = &Apache::lonenc::encrypted(&Apache::lonnet::clutter($url)); |
$realuri = &Apache::lonenc::encrypted(&Apache::lonnet::clutter($url)); |
Line 540 sub lti_provider_scope {
|
Line 550 sub lti_provider_scope {
|
$realuri .= '?symb='.$symb; |
$realuri .= '?symb='.$symb; |
} |
} |
} |
} |
|
if ($getunenc) { |
|
$unencsymb = $symb; |
|
} |
} |
} |
} elsif ($tail =~ m{^/$cdom/$cnum$}) { |
} elsif (($tail =~ m{^/$cdom/$cnum$}) || ($tail eq '')) { |
$scope = 'course'; |
$scope = 'course'; |
$realuri = '/adm/navmaps'; |
$realuri = '/adm/navmaps'; |
|
$passkey = $tail; |
|
} |
|
if ($scope eq 'map') { |
|
$passkey = $realuri; |
|
} |
|
if (wantarray) { |
|
return ($scope,$realuri,$unencsymb); |
|
} else { |
|
return $passkey; |
|
} |
|
} |
|
|
|
sub send_grade { |
|
my ($id,$url,$ckey,$secret,$scoretype,$total,$possible) = @_; |
|
my $score; |
|
if ($possible > 0) { |
|
if ($scoretype eq 'ratio') { |
|
$score = Math::Round::round($total).'/'.Math::Round::round($possible); |
|
} elsif ($scoretype eq 'percentage') { |
|
$score = (100.0*$total)/$possible; |
|
$score = Math::Round::round($score); |
|
} else { |
|
$score = $total/$possible; |
|
$score = sprintf("%.2f",$score); |
|
} |
|
} |
|
my $date = &Apache::loncommon::utc_string(time); |
|
my %ltiparams = ( |
|
lti_version => 'LTI-1p0', |
|
lti_message_type => 'basic-lis-updateresult', |
|
sourcedid => $id, |
|
result_resultscore_textstring => $score, |
|
result_resultscore_language => 'en-US', |
|
result_resultvaluesourcedid => $scoretype, |
|
result_statusofresult => 'final', |
|
result_date => $date, |
|
); |
|
my $hashref = &sign_params($url,$ckey,$secret,\%ltiparams); |
|
if (ref($hashref) eq 'HASH') { |
|
my $request=new HTTP::Request('POST',$url); |
|
$request->content(join('&',map { |
|
my $name = escape($_); |
|
"$name=" . ( ref($hashref->{$_}) eq 'ARRAY' |
|
? join("&$name=", map {escape($_) } @{$hashref->{$_}}) |
|
: &escape($hashref->{$_}) ); |
|
} keys(%{$hashref}))); |
|
my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10); |
|
my $message=$response->status_line; |
|
#FIXME Handle case where pass back of score to LTI Consumer failed. |
} |
} |
return ($scope,$realuri); |
|
} |
} |
|
|
1; |
1; |