version 1.23, 2022/03/29 20:12:46
|
version 1.27, 2025/03/15 17:28:14
|
Line 96 sub handler {
|
Line 96 sub handler {
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
my $chome = $env{'course.'.$env{'request.course.id'}.'.home'}; |
my $chome = $env{'course.'.$env{'request.course.id'}.'.home'}; |
my ($idx,$is_tool,%toolhash,%toolsettings); |
my ($idx,$crstool,$is_tool,%toolhash,%toolsettings); |
|
|
if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") { |
if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") { |
%toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); |
%toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); |
if ($toolsettings{'id'}) { |
if ($toolsettings{'id'}) { |
$idx = $toolsettings{'id'}; |
my %ltitools; |
my %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer'); |
if ($toolsettings{'id'} =~ /^c(\d+)$/) { |
|
$idx = $1; |
|
$crstool = 1; |
|
%ltitools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer'); |
|
} else { |
|
$idx = $toolsettings{'id'}; |
|
%ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer'); |
|
} |
if (ref($ltitools{$idx}) eq 'HASH') { |
if (ref($ltitools{$idx}) eq 'HASH') { |
%toolhash = %{$ltitools{$idx}}; |
%toolhash = %{$ltitools{$idx}}; |
$toolhash{'display'} = { |
$toolhash{'display'} = { |
Line 113 sub handler {
|
Line 120 sub handler {
|
foreach my $item (qw(crslabel crstitle crsappend gradable)) { |
foreach my $item (qw(crslabel crstitle crsappend gradable)) { |
$toolhash{$item} = $toolsettings{$item}; |
$toolhash{$item} = $toolsettings{$item}; |
} |
} |
|
if ($toolhash{'returnurl'}) { |
|
my $gotreturnurl; |
|
if (ref($toolhash{'crsconf'}) eq 'HASH') { |
|
if ($toolhash{'crsconf'}{'returnurl'}) { |
|
foreach my $item (qw(returnurl backtourl)) { |
|
$toolhash{$item} = $toolsettings{$item}; |
|
} |
|
$gotreturnurl = 1; |
|
} |
|
} |
|
unless ($gotreturnurl) { |
|
$toolhash{'returnurl'} = 'default'; |
|
} |
|
} else { |
|
$toolhash{'returnurl'} = 'none'; |
|
} |
$is_tool = 1; |
$is_tool = 1; |
} |
} |
} |
} |
Line 204 sub handler {
|
Line 227 sub handler {
|
} |
} |
} |
} |
my $submittext = &mt('Launch [_1]',$toolhash{'title'}); |
my $submittext = &mt('Launch [_1]',$toolhash{'title'}); |
if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') && |
if (($toolhash{'url'} ne '') && ($launchok)) { |
($toolhash{'url'} ne '') && ($launchok)) { |
my %lti = <i_params($r,$cnum,$cdom,$marker,$exttool,$idx,$submittext,\%toolhash); |
my %lti = <i_params($r,$cnum,$cdom,$idx,$submittext,\%toolhash); |
|
my $url = $toolhash{'url'}; |
my $url = $toolhash{'url'}; |
if ($toolhash{'crsappend'} ne '') { |
if ($toolhash{'crsappend'} ne '') { |
$url .= $toolhash{'crsappend'}; |
$url .= $toolhash{'crsappend'}; |
} |
} |
$r->print(&launch_html($url,$toolhash{'key'},$toolhash{'secret'}, |
my %info = ( |
$toolhash{'sigmethod'},$submittext,\%lti)); |
method => $toolhash{'sigmethod'}, |
|
); |
|
$r->print(&launch_html($cdom,$cnum,$crstool,$url,$idx, |
|
$toolhash{'cipher'},$submittext,\%lti,\%info)); |
} else { |
} else { |
$r->print('<div>'.&mt('External Tool Unavailable').'</div>'); |
$r->print('<div class="LC_warning">'.&mt('External Tool Unavailable').'</div>'); |
} |
} |
} |
} |
return OK; |
return OK; |
} |
} |
|
|
sub lti_params { |
sub lti_params { |
my ($r,$cnum,$cdom,$idx,$submittext,$toolsref) = @_; |
my ($r,$cnum,$cdom,$marker,$exttool,$idx,$submittext,$toolsref) = @_; |
my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale, |
my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale, |
$crslabel,$crstitle,$gradesecret,$rostersecret,%fields,%rolesmap, |
$crslabel,$crstitle,$gradesecret,$rostersecret,%fields,%rolesmap, |
%display,%custom,@userlangs,$incdom); |
%display,%custom,@userlangs,$incdom,$returnurl,$backtourl); |
if (ref($toolsref) eq 'HASH') { |
if (ref($toolsref) eq 'HASH') { |
$version = $toolsref->{'version'}; |
$version = $toolsref->{'version'}; |
$toolname = $toolsref->{'title'}; |
$toolname = $toolsref->{'title'}; |
Line 248 sub lti_params {
|
Line 273 sub lti_params {
|
} |
} |
$crslabel = $toolsref->{'crslabel'}; |
$crslabel = $toolsref->{'crslabel'}; |
$crstitle = $toolsref->{'crstitle'}; |
$crstitle = $toolsref->{'crstitle'}; |
|
$returnurl = $toolsref->{'returnurl'}; |
|
$backtourl = $toolsref->{'backtourl'}; |
} |
} |
if ($version eq '') { |
if ($version eq '') { |
$version = 'LTI-1p0'; |
$version = 'LTI-1p0'; |
Line 295 sub lti_params {
|
Line 322 sub lti_params {
|
if (scalar(@userlangs) == 1) { |
if (scalar(@userlangs) == 1) { |
$locale = $userlangs[0]; |
$locale = $userlangs[0]; |
} |
} |
my ($title,$digest_symb); |
my ($title,$digest_symb,$digest_suppurl,$resource_link_id); |
my ($symb) = &Apache::lonnet::whichuser(); |
my ($symb) = &Apache::lonnet::whichuser(); |
|
my $uri = "/adm/$cdom/$cnum/$marker/$exttool"; |
if ($symb) { |
if ($symb) { |
$digest_symb = &Encode::decode('UTF-8',$symb); |
$digest_symb = &Encode::decode('UTF-8',$symb); |
$digest_symb = &Digest::SHA::sha1_hex($digest_symb); |
$digest_symb = &Digest::SHA::sha1_hex($digest_symb); |
|
$resource_link_id = $digest_symb; |
push(@possdigest,$digest_symb); |
push(@possdigest,$digest_symb); |
my $navmap = Apache::lonnavmaps::navmap->new(); |
my $navmap = Apache::lonnavmaps::navmap->new(); |
if (ref($navmap)) { |
if (ref($navmap)) { |
Line 308 sub lti_params {
|
Line 337 sub lti_params {
|
$title = $res->compTitle(); |
$title = $res->compTitle(); |
} |
} |
} |
} |
|
} elsif ($env{'httpref.'.$uri} eq '/adm/coursedoc') { |
|
$digest_suppurl = &Encode::decode('UTF-8',$uri); |
|
$digest_suppurl = &Digest::SHA::sha1_hex($digest_suppurl); |
|
$resource_link_id = $digest_suppurl; |
} |
} |
my $domdesc = &Apache::lonnet::domain($cdom); |
my $domdesc = &Apache::lonnet::domain($cdom); |
my $primary_id = &Apache::lonnet::domain($cdom,'primary'); |
my $primary_id = &Apache::lonnet::domain($cdom,'primary'); |
Line 318 sub lti_params {
|
Line 351 sub lti_params {
|
lti_version => $version, |
lti_version => $version, |
lti_message_type => $msgtype, |
lti_message_type => $msgtype, |
resource_link_title => $title, |
resource_link_title => $title, |
resource_link_id => $digest_symb, |
resource_link_id => $resource_link_id, |
tool_consumer_instance_guid => $lonhost, |
tool_consumer_instance_guid => $lonhost, |
tool_consumer_instance_description => $domdesc, |
tool_consumer_instance_description => $domdesc, |
tool_consumer_info_product_family_code => 'loncapa', |
tool_consumer_info_product_family_code => 'loncapa', |
Line 430 sub lti_params {
|
Line 463 sub lti_params {
|
$ltiparams{$key} = &Encode::decode('UTF-8',$ltiparams{$key}); |
$ltiparams{$key} = &Encode::decode('UTF-8',$ltiparams{$key}); |
} |
} |
$ltiparams{'basiclti_submit'} = $submittext; |
$ltiparams{'basiclti_submit'} = $submittext; |
|
if ($returnurl eq 'default') { |
|
my $hostname = &Apache::lonnet::hostname($r->dir_config('lonHostID')); |
|
my $protocol = 'http'; |
|
my $port = $r->get_server_port(); |
|
if ($port eq '443') { |
|
$protocol = 'https'; |
|
} |
|
if (&Apache::lonnet::get_proxy_alias()) { |
|
my $hdrhost = $r->headers_in->get('Host'); |
|
if ($hdrhost ne '') { |
|
$hostname = $r->headers_in->get('Host'); |
|
} |
|
} |
|
my $location = $protocol.'://'.$hostname; |
|
if ($display{'target'} eq 'iframe') { |
|
my $return_url; |
|
if ($symb) { |
|
my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb); |
|
my $mapurl = &Apache::lonnet::clutter($map); |
|
my $mapsymb = &Apache::lonnet::symbread($map); |
|
if ((&Apache::lonnet::EXT('resource.0.encrypturl',$mapsymb) =~ /^yes$/i) && |
|
(!$env{'request.role.adv'})) { |
|
$return_url = &Apache::lonenc::encrypted($mapurl); |
|
} else { |
|
$return_url = $mapurl; |
|
} |
|
$return_url .= '?navmap=1'; |
|
} elsif ($env{'httpref.'.$uri} eq '/adm/coursedoc') { |
|
$return_url = '/adm/supplemental'; |
|
} else { |
|
$return_url = '/adm/navmaps'; |
|
} |
|
$ltiparams{'launch_presentation_return_url'} = $location.$return_url; |
|
} else { |
|
$uri = '/adm/wrapper'.$uri; |
|
if ($env{'request.enc'}) { |
|
$uri = &Apache::lonenc::encrypted($uri); |
|
} |
|
$ltiparams{'launch_presentation_return_url'} = $location.$uri; |
|
} |
|
} elsif ($returnurl eq 'custom') { |
|
if ($backtourl ne '') { |
|
$ltiparams{'launch_presentation_return_url'} = $backtourl; |
|
} |
|
} |
return %ltiparams; |
return %ltiparams; |
} |
} |
|
|
sub launch_html { |
sub launch_html { |
my ($url,$key,$secret,$sigmethod,$submittext,$paramsref) = @_; |
my ($cdom,$cnum,$crstool,$url,$idx,$keynum,$submittext,$paramsref,$inforef) = @_; |
my $hashref = &LONCAPA::ltiutils::sign_params($url,$key,$secret,$paramsref,$sigmethod); |
my ($status,$hashref) = |
|
&Apache::lonnet::sign_lti($cdom,$cnum,$crstool,'tools','launch',$url,$idx,$keynum, |
|
$paramsref,$inforef); |
|
unless ($status eq 'ok') { |
|
return '<div class="LC_warning">'.&mt('External Tool Unavailable').'</div>'; |
|
} |
my $action = &HTML::Entities::encode($url,'<>&"'); |
my $action = &HTML::Entities::encode($url,'<>&"'); |
my $form = <<"END"; |
my $form = <<"END"; |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |