--- loncom/interface/lonexttool.pm 2016/01/26 14:30:25 1.3
+++ loncom/interface/lonexttool.pm 2017/11/30 01:52:14 1.5
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Launch External Tool Provider (LTI)
#
-# $Id: lonexttool.pm,v 1.3 2016/01/26 14:30:25 raeburn Exp $
+# $Id: lonexttool.pm,v 1.5 2017/11/30 01:52:14 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -102,15 +102,22 @@ sub handler {
width => $toolsettings{'width'},
height => $toolsettings{'height'},
};
+ $toolhash{'crslabel'} = $toolsettings{'crslabel'};
+ $toolhash{'crstitle'} = $toolsettings{'crstitle'};
+ $toolhash{'crsappend'} = $toolsettings{'crsappend'};
$is_tool = 1;
if ($target eq 'tex') {
$r->print(&mt('External Tool'));
} else {
my $submittext = &mt('Launch [_1]',$toolhash{'title'});
if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') && ($toolhash{'url'} ne '')) {
- my %lti = <i_params($r,$submittext,\%toolhash);
- $r->print(&launch_html($toolhash{'url'},$toolhash{'key'},
- $toolhash{'secret'},$submittext,\%lti));
+ my %lti = <i_params($r,$cnum,$cdom,$submittext,\%toolhash);
+ my $url = $toolhash{'url'};
+ if ($toolhash{'crsappend'} ne '') {
+ $url .= $toolhash{'crsappend'};
+ }
+ $r->print(&launch_html($url,$toolhash{'key'},$toolhash{'secret'},
+ $submittext,\%lti));
} else {
$r->print('
'.&mt('External Tool Unavailable').'
');
}
@@ -129,9 +136,9 @@ sub handler {
}
sub lti_params {
- my ($r,$submittext,$toolsref) = @_;
+ my ($r,$cnum,$cdom,$submittext,$toolsref) = @_;
my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,
- %fields,%rolesmap,%display,%custom,@userlangs);
+ $crslabel,$crstitle,%fields,%rolesmap,%display,%custom,@userlangs);
if (ref($toolsref) eq 'HASH') {
$version = $toolsref->{'version'};
$toolname = $toolsref->{'title'};
@@ -150,6 +157,8 @@ sub lti_params {
if (ref($toolsref->{'custom'}) eq 'HASH') {
%custom = %{$toolsref->{'custom'}};
}
+ $crslabel = $toolsref->{'crslabel'};
+ $crstitle = $toolsref->{'crstitle'};
}
if ($version eq '') {
$version = 'LTI-1p0';
@@ -160,6 +169,12 @@ sub lti_params {
if ($msgtype eq '') {
$msgtype = 'basic-lti-launch-request';
}
+ if ($crslabel eq '') {
+ $crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
+ }
+ if ($crstitle eq '') {
+ $crstitle = $env{'course.'.$env{'request.course.id'}.'.description'},;
+ }
my $lonhost = $r->dir_config('lonHostID');
my $loncaparev = $r->dir_config('lonVersion');
my $uname = $env{'user.name'};
@@ -202,21 +217,28 @@ sub lti_params {
}
}
}
+ my $domdesc = &Apache::lonnet::domain($cdom);
+ my $primary_id = &Apache::lonnet::domain($cdom,'primary');
+ my $int_dom = &Apache::lonnet::internet_dom($primary_id);
+ my $portal_url = &Apache::lonnet::course_portal_url($cnum,$cdom);
+
my %ltiparams = (
lti_version => $version,
lti_message_type => $msgtype,
resource_link_title => $title,
resource_link_id => $digest_symb,
tool_consumer_instance_guid => $lonhost,
+ tool_consumer_instance_description => $domdesc,
tool_consumer_info_product_family_code => 'loncapa',
+ tool_consumer_instance_name => $int_dom,
+ tool_consumer_instance_url => $portal_url,
tool_consumer_info_version => $loncaparev,
user_id => $digest_user,
- lis_person_sourcedid => $uname.':'.$udom,
roles => $ltirole,
context_id => $env{'request.course.id'},
context_type => $context_type,
- context_label => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
- context_title => $env{'course.'.$env{'request.course.id'}.'.description'},
+ context_label => $crslabel,
+ context_title => $crstitle,
launch_presentation_locale => $locale,
);
my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
@@ -228,14 +250,14 @@ sub lti_params {
}
if ($passback) {
if ($ltirole eq 'Learner') {
- $ltiparams{'lis_outcome_service_url'} = $crsprotocol.'//'.$crshostname.'/adm/ltipassback';
+ $ltiparams{'lis_outcome_service_url'} = $crsprotocol.'//'.$crshostname.'/adm/service/passback';
$ltiparams{'ext_ims_lis_basic_outcome_url'} = $ltiparams{'lis_outcome_service_url'};
$ltiparams{'lis_result_sourcedid'} = ''; #FIXME
}
}
if ($roster) {
if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
- $ltiparams{'ext_ims_lis_memberships_url'} = $crsprotocol.'//'.$crshostname.'/adm/ltiroster';
+ $ltiparams{'ext_ims_lis_memberships_url'} = $crsprotocol.'//'.$crshostname.'/adm/service/roster';
$ltiparams{'ext_ims_lis_memberships_id'} = ''; #FIXME
}
}
@@ -269,9 +291,19 @@ sub lti_params {
}
$ltiparams{'lis_person_contact_email_primary'} = $contact_email;
}
+ if ($fields{'user'}) {
+ $ltiparams{'lis_person_sourcedid'} = $uname.':'.$udom;
+ }
if (keys(%custom)) {
foreach my $key (keys(%custom)) {
- $ltiparams{'custom_'.$key} = $custom{$key};
+ my $value = $custom{$key};
+ $value =~ s/^\s+|\s+\$//g;
+ if ($value =~ /^\QLONCAPA::env{\E([^\}]+)\}$/) {
+ if (exists($env{$1})) {
+ $value = $env{$1};
+ }
+ }
+ $ltiparams{'custom_'.$key} = $value;
}
}
foreach my $key (keys(%ltiparams)) {
@@ -284,12 +316,13 @@ sub lti_params {
sub launch_html {
my ($url,$key,$secret,$submittext,$paramsref) = @_;
my $hashref = &sign_params($url,$key,$secret,$paramsref);
+ my $action = &HTML::Entities::encode($url,'<>&"');
my $form = <<"END";
-