--- loncom/interface/lonexttool.pm 2016/01/11 16:42:37 1.1
+++ loncom/interface/lonexttool.pm 2016/01/26 14:30:25 1.3
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Launch External Tool Provider (LTI)
#
-# $Id: lonexttool.pm,v 1.1 2016/01/11 16:42:37 raeburn Exp $
+# $Id: lonexttool.pm,v 1.3 2016/01/26 14:30:25 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -74,15 +74,14 @@ sub handler {
return OK;
}
- my $marker = (split(m{/},$r->uri))[4];
+ my ($marker,$exttool) = (split(m{/},$r->uri))[4,5];
$marker=~s/\D//g;
if (!$marker) {
if ($target ne 'tex') {
- &Apache::loncommon::simple_error_page($r,'Invalid Call',
- 'Invalid Call');
+ $r->print(&mt('Invalid Call'));
} else {
- $r->print('\textbf{Invalid call}\end{document}');
+ $r->print('\textbf{'&mt('Invalid Call').'}\end{document}');
}
return OK;
}
@@ -90,46 +89,47 @@ sub handler {
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
+ my $is_tool;
- if ($r->uri eq "/adm/$cdom/$cnum/$marker/exttool") {
- my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
- if ($target eq 'tex') {
- $r->print(&mt('External Tool'));
- } else {
- if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') && ($toolhash{'url'} ne '')) {
- my %lti = <i_params($r,\%toolhash);
- $r->print(&launch_html($toolhash{'url'},$toolhash{'key'},
- $toolhash{'secret'},$toolhash{'title'},\%lti));
- } else {
- &Apache::loncommon::simple_error_page($r,'External Tool Unavailable',
- 'External Tool Unavailable');
+ if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") {
+ my %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
+ if ($toolsettings{'id'}) {
+ my %ltitools = &Apache::lonnet::get_domain_ltitools($cdom);
+ if (ref($ltitools{$toolsettings{'id'}}) eq 'HASH') {
+ my %toolhash = %{$ltitools{$toolsettings{'id'}}};
+ $toolhash{'display'} = {
+ target => $toolsettings{'target'},
+ width => $toolsettings{'width'},
+ height => $toolsettings{'height'},
+ };
+ $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));
+ } else {
+ $r->print('
'.&mt('External Tool Unavailable').'
');
+ }
+ }
}
}
- } else {
+ }
+ unless ($is_tool) {
if ($target ne 'tex') {
- &Apache::loncommon::simple_error_page($r,'Invalid Call',
- 'Invalid Call');
+ $r->print(''.&mt('Invalid Call').'
');
} else {
- $r->print('\textbf{Invalid call}\end{document}');
+ $r->print('\textbf{'.&mt(Invalid Call).'}\end{document}');
}
- return OK;
}
-
- &print_end_page($r,$target);
return OK;
}
-sub print_end_page {
- my ($r,$target) = @_;
- if ($target ne 'tex') {
- $r->print(&Apache::loncommon::end_page());
- } else {
- $r->print('\end{document}');
- }
-}
-
sub lti_params {
- my ($r,$toolsref) = @_;
+ my ($r,$submittext,$toolsref) = @_;
my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,
%fields,%rolesmap,%display,%custom,@userlangs);
if (ref($toolsref) eq 'HASH') {
@@ -165,7 +165,8 @@ sub lti_params {
my $uname = $env{'user.name'};
my $udom = $env{'user.domain'};
my @possroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
- my $ltirole = $rolesmap{$env{'request.role'}};
+ my ($roleprefix) = ($env{'request.role'} =~ /^(\w+)\./);
+ my $ltirole = $rolesmap{$roleprefix};
unless (grep(/^\Q$ltirole\E$/,@possroles)) {
$ltirole = 'Learner';
}
@@ -175,7 +176,7 @@ sub lti_params {
@userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
$env{'course.'.$env{'request.course.id'}.'.languages'}));
} else {
- my %langhash = &getlangs($uname,$udom);
+ my %langhash = &Apache::loncommon::getlangs($uname,$udom);
if ($langhash{'languages'} ne '') {
@userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
} else {
@@ -218,10 +219,10 @@ sub lti_params {
context_title => $env{'course.'.$env{'request.course.id'}.'.description'},
launch_presentation_locale => $locale,
);
- my $crshostname = $env{'course.'.$env{'request.course.id'}.'.home'};
- my $crsprotocol = $Apache::lonnet::protocol{$crshostname};
+ my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
+ my $crshostname = &Apache::lonnet::hostname($crshome);
if ($crshostname) {
- my $crsprotocol = $Apache::lonnet::protocol{$crshostname};
+ my $crsprotocol = $Apache::lonnet::protocol{$crshome};
unless ($crsprotocol eq 'https') {
$crsprotocol = 'http';
}
@@ -260,13 +261,13 @@ sub lti_params {
if ($fields{'email'}) {
my %emails = &Apache::loncommon::getemails($uname,$udom);
my $contact_email;
- foreach my $email ('permanentemail','critnotification','notification') {
- if ($email =~ /\@/) {
- $contact_email = $email;
+ foreach my $type ('permanentemail','critnotification','notification') {
+ if ($emails{$type} =~ /\@/) {
+ $contact_email = $emails{$type};
last;
}
}
- $ltiparams{'lis_person_contact_email_primary'} = &contact_email;
+ $ltiparams{'lis_person_contact_email_primary'} = $contact_email;
}
if (keys(%custom)) {
foreach my $key (keys(%custom)) {
@@ -276,24 +277,27 @@ sub lti_params {
foreach my $key (keys(%ltiparams)) {
$ltiparams{$key} = &Encode::decode_utf8($ltiparams{$key});
}
+ $ltiparams{'basiclti_submit'} = $submittext;
return %ltiparams;
}
sub launch_html {
- my ($url,$key,$secret,$toolname,$paramsref) = @_;
+ my ($url,$key,$secret,$submittext,$paramsref) = @_;
my $hashref = &sign_params($url,$key,$secret,$paramsref);
- my $submittext = &mt('Launch [_1]',$toolname);
my $form = <<"END";
-
\n";
@@ -302,9 +306,9 @@ END
document.getElementById("LCltiLaunch").style.display = "none";
nei = document.createElement('input');
nei.setAttribute('type','hidden');
- nei.setAttribute('name','LCbasicltiSubmit');
+ nei.setAttribute('name','basiclti_submit');
nei.setAttribute('value','$submittext');
- document.getElementById("LCltiLaunchForm").appendChild(nei);
+ document.getElementById("LCltiLaunchFormId").appendChild(nei);
document.LCltiLaunchForm.submit();
ENDJS