version 1.9, 2017/12/07 15:36:34
|
version 1.22.2.1, 2021/12/31 15:12:52
|
Line 49 use HTML::Entities;
|
Line 49 use HTML::Entities;
|
use Apache::lonlocal; |
use Apache::lonlocal; |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::loncommon; |
use Apache::loncommon; |
|
use Apache::londatecheck; |
|
use Apache::lonipcheck; |
use LONCAPA::ltiutils; |
use LONCAPA::ltiutils; |
|
|
sub handler { |
sub handler { |
Line 62 sub handler {
|
Line 64 sub handler {
|
# ------------------------------------------------------------ Print the screen |
# ------------------------------------------------------------ Print the screen |
if ($target eq 'tex') { |
if ($target eq 'tex') { |
$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'})); |
$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'})); |
|
} else { |
|
$target = 'web'; |
} |
} |
|
|
# Is this even in a course? |
# Is this even in a course? |
unless ($env{'request.course.id'}) { |
unless ($env{'request.course.id'}) { |
if ($target ne 'tex') { |
if ($target ne 'tex') { |
&Apache::loncommon::simple_error_page($r,'','Not in a course'); |
&Apache::loncommon::simple_error_page($r,'','Not in a course', |
|
{'only_body' => 1}); |
} else { |
} else { |
$r->print('\textbf{Not in a course}\end{document}'); |
$r->print('\textbf{Not in a course}\end{document}'); |
} |
} |
Line 89 sub handler {
|
Line 94 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 $is_tool; |
my ($idx,$is_tool,%toolhash,%toolsettings); |
|
|
if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") { |
if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") { |
my %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); |
%toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); |
if ($toolsettings{'id'}) { |
if ($toolsettings{'id'}) { |
my $idx = $toolsettings{'id'}; |
$idx = $toolsettings{'id'}; |
my %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer'); |
my %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer'); |
if (ref($ltitools{$idx}) eq 'HASH') { |
if (ref($ltitools{$idx}) eq 'HASH') { |
my %toolhash = %{$ltitools{$idx}}; |
%toolhash = %{$ltitools{$idx}}; |
$toolhash{'display'} = { |
$toolhash{'display'} = { |
target => $toolsettings{'target'}, |
target => $toolsettings{'target'}, |
width => $toolsettings{'width'}, |
width => $toolsettings{'width'}, |
height => $toolsettings{'height'}, |
height => $toolsettings{'height'}, |
}; |
}; |
$toolhash{'crslabel'} = $toolsettings{'crslabel'}; |
foreach my $item (qw(crslabel crstitle crsappend)) { |
$toolhash{'crstitle'} = $toolsettings{'crstitle'}; |
$toolhash{$item} = $toolsettings{$item}; |
$toolhash{'crsappend'} = $toolsettings{'crsappend'}; |
|
$is_tool = 1; |
|
my $launchok = 1; |
|
if ($target eq 'tex') { |
|
$r->print(&mt('External Tool')); |
|
} else { |
|
my $now = time; |
|
if ($toolhash{'passback'}) { |
|
if (&LONCAPA::ltiutils::set_service_secret($cdom,$cnum,$marker,'grade',$now, |
|
\%toolsettings,\%toolhash) eq 'ok') { |
|
$toolhash{'gradesecret'} = $toolsettings{'gradesecret'}; |
|
} else { |
|
undef($launchok); |
|
} |
|
} |
|
if ($toolhash{'roster'}) { |
|
if (&LONCAPA::ltiutils::set_service_secret($cdom,$cnum,$marker,'roster',$now, |
|
\%toolsettings,\%toolhash) eq 'ok') { |
|
$toolhash{'rostersecret'} = $toolsettings{'rostersecret'}; |
|
} |
|
} |
|
my $submittext = &mt('Launch [_1]',$toolhash{'title'}); |
|
if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') && |
|
($toolhash{'url'} ne '') && ($launchok)) { |
|
my %lti = <i_params($r,$cnum,$cdom,$idx,$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('<div>'.&mt('External Tool Unavailable').'</div>'); |
|
} |
|
} |
} |
|
$is_tool = 1; |
} |
} |
} |
} |
} |
} |
Line 149 sub handler {
|
Line 121 sub handler {
|
} else { |
} else { |
$r->print('\textbf{'.&mt(Invalid Call).'}\end{document}'); |
$r->print('\textbf{'.&mt(Invalid Call).'}\end{document}'); |
} |
} |
|
return OK; |
|
} |
|
|
|
my ($symb,$status,$open,$close,$msg,$donebuttonresult,$donemsg); |
|
if (($target eq 'tex') || ($toolhash{'gradable'})) { |
|
($symb) = &Apache::lonnet::whichuser(); |
|
} |
|
if ($target eq 'tex') { |
|
my $title = &Apache::lonnet::gettitle($symb); |
|
$r->print(&mt('External Tool: [_1]','\textit{'.$title.'}').'\\\\'); |
|
} |
|
my ($status,$open,$close,$msg)=&Apache::londatecheck::content_date_check(); |
|
if ($status ne 'OPEN') { |
|
if ($target eq 'tex') { |
|
$r->print(&mt('Not open to be viewed').'\end{document}'); |
|
} else { |
|
$r->print($msg); |
|
} |
|
return OK; |
|
} else { |
|
($status,$msg)=&Apache::lonipcheck::ip_access_check(); |
|
if ($status ne 'OPEN') { |
|
if ($target eq 'tex') { |
|
$r->print(&mt('Not open to be viewed').'\end{document}'); |
|
} else { |
|
$r->print($msg); |
|
} |
|
return OK; |
|
} |
|
} |
|
my $launchok = 1; |
|
if ($target eq 'tex') { |
|
$r->print('\end{document}'); |
|
} else { |
|
my $now = time; |
|
my $submittext = &mt('Launch [_1]',$toolhash{'title'}); |
|
if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') && |
|
($toolhash{'url'} ne '') && ($launchok)) { |
|
my %lti = <i_params($r,$cnum,$cdom,$idx,$submittext,\%toolhash); |
|
my $url = $toolhash{'url'}; |
|
if ($toolhash{'crsappend'} ne '') { |
|
$url .= $toolhash{'crsappend'}; |
|
} |
|
$r->print(&launch_html($url,$toolhash{'key'},$toolhash{'secret'}, |
|
$toolhash{'sigmethod'},$submittext,\%lti)); |
|
} else { |
|
$r->print('<div>'.&mt('External Tool Unavailable').'</div>'); |
|
} |
} |
} |
return OK; |
return OK; |
} |
} |
Line 156 sub handler {
|
Line 176 sub handler {
|
sub lti_params { |
sub lti_params { |
my ($r,$cnum,$cdom,$idx,$submittext,$toolsref) = @_; |
my ($r,$cnum,$cdom,$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,%fields,%rolesmap,%display,%custom,@userlangs,$incdom); |
%display,%custom,@userlangs); |
|
if (ref($toolsref) eq 'HASH') { |
if (ref($toolsref) eq 'HASH') { |
$version = $toolsref->{'version'}; |
$version = $toolsref->{'version'}; |
$toolname = $toolsref->{'title'}; |
$toolname = $toolsref->{'title'}; |
$passback = $toolsref->{'passback'}; |
|
$gradesecret = $toolsref->{'gradesecret'}; |
|
$roster = $toolsref->{'roster'}; |
|
$rostersecret = $toolsref->{'rostersecret'}; |
|
$msgtype = $toolsref->{'messagetype'}; |
$msgtype = $toolsref->{'messagetype'}; |
|
$incdom = $toolsref->{'incdom'}; |
if (ref($toolsref->{'fields'}) eq 'HASH') { |
if (ref($toolsref->{'fields'}) eq 'HASH') { |
%fields = %{$toolsref->{'fields'}}; |
%fields = %{$toolsref->{'fields'}}; |
} |
} |
Line 191 sub lti_params {
|
Line 207 sub lti_params {
|
$msgtype = 'basic-lti-launch-request'; |
$msgtype = 'basic-lti-launch-request'; |
} |
} |
if ($crslabel eq '') { |
if ($crslabel eq '') { |
$crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}, |
$crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}; |
} |
} |
if ($crstitle eq '') { |
if ($crstitle eq '') { |
$crstitle = $env{'course.'.$env{'request.course.id'}.'.description'},; |
$crstitle = $env{'course.'.$env{'request.course.id'}.'.description'}; |
} |
} |
my $lonhost = $r->dir_config('lonHostID'); |
my $lonhost = $r->dir_config('lonHostID'); |
my $loncaparev = $r->dir_config('lonVersion'); |
my $loncaparev = $r->dir_config('lonVersion'); |
Line 206 sub lti_params {
|
Line 222 sub lti_params {
|
unless (grep(/^\Q$ltirole\E$/,@possroles)) { |
unless (grep(/^\Q$ltirole\E$/,@possroles)) { |
$ltirole = 'Learner'; |
$ltirole = 'Learner'; |
} |
} |
|
my @possdigest; |
my $digest_user = &Encode::decode_utf8($uname.':'.$udom); |
my $digest_user = &Encode::decode_utf8($uname.':'.$udom); |
$digest_user = &Digest::SHA::sha1_hex($digest_user); |
$digest_user = &Digest::SHA::sha1_hex($digest_user); |
|
push(@possdigest,$digest_user); |
if ($env{'course.'.$env{'request.course.id'}.'.languages'} ne '') { |
if ($env{'course.'.$env{'request.course.id'}.'.languages'} ne '') { |
@userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/, |
@userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/, |
$env{'course.'.$env{'request.course.id'}.'.languages'})); |
$env{'course.'.$env{'request.course.id'}.'.languages'})); |
Line 230 sub lti_params {
|
Line 248 sub lti_params {
|
if ($symb) { |
if ($symb) { |
$digest_symb = &Encode::decode_utf8($symb); |
$digest_symb = &Encode::decode_utf8($symb); |
$digest_symb = &Digest::SHA::sha1_hex($digest_symb); |
$digest_symb = &Digest::SHA::sha1_hex($digest_symb); |
|
push(@possdigest,$digest_symb); |
my $navmap = Apache::lonnavmaps::navmap->new(); |
my $navmap = Apache::lonnavmaps::navmap->new(); |
if (ref($navmap)) { |
if (ref($navmap)) { |
my $res = $navmap->getBySymb($symb); |
my $res = $navmap->getBySymb($symb); |
Line 241 sub lti_params {
|
Line 260 sub lti_params {
|
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'); |
my $int_dom = &Apache::lonnet::internet_dom($primary_id); |
my $int_dom = &Apache::lonnet::internet_dom($primary_id); |
my $portal_url = &Apache::lonnet::course_portal_url($cnum,$cdom); |
my $portal_url = &Apache::lonnet::course_portal_url($cnum,$cdom,$r); |
|
|
my %ltiparams = ( |
my %ltiparams = ( |
lti_version => $version, |
lti_version => $version, |
Line 251 sub lti_params {
|
Line 270 sub lti_params {
|
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', |
tool_consumer_instance_name => $int_dom, |
tool_consumer_instance_name => $int_dom, |
tool_consumer_instance_url => $portal_url, |
tool_consumer_instance_url => $portal_url, |
tool_consumer_info_version => $loncaparev, |
tool_consumer_info_version => $loncaparev, |
user_id => $digest_user, |
user_id => $digest_user, |
Line 269 sub lti_params {
|
Line 288 sub lti_params {
|
unless ($crsprotocol eq 'https') { |
unless ($crsprotocol eq 'https') { |
$crsprotocol = 'http'; |
$crsprotocol = 'http'; |
} |
} |
if (($passback) || ($roster)) { |
|
if ($passback) { |
|
$ltiparams{'lis_outcome_service_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/passback'; |
|
$ltiparams{'ext_ims_lis_basic_outcome_url'} = $ltiparams{'lis_outcome_service_url'}; |
|
if ($gradesecret) { |
|
my $uniqid = $digest_symb.':::'.$digest_user.':::'.$env{'request.course.id'}; |
|
$ltiparams{'lis_result_sourcedid'} = &LONCAPA::ltiutils::get_unique_callback($gradesecret,$uniqid); |
|
} |
|
} |
|
if ($roster) { |
|
if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) { |
|
$ltiparams{'ext_ims_lis_memberships_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/roster'; |
|
if ($rostersecret) { |
|
my $uniqid = $digest_symb.':::'.$env{'request.course.id'}; |
|
$ltiparams{'ext_ims_lis_memberships_id'} = &LONCAPA::ltiutils::get_unique_callback($rostersecret,$uniqid); |
|
} |
|
} |
|
} |
|
my %digesthash; |
|
if ($ltiparams{'lis_result_sourcedid'}) { |
|
$digesthash{$ltiparams{'lis_result_sourcedid'}} = "$idx\0".time; |
|
} |
|
if ($ltiparams{'ext_ims_lis_memberships_id'}) { |
|
$digesthash{$ltiparams{'ext_ims_lis_memberships_id'}} = "$idx\0".time; |
|
} |
|
if (($digest_symb) && ($gradesecret || $rostersecret)) { |
|
$digesthash{$digest_symb} = $symb; |
|
} |
|
if (($passback) && ($gradesecret)) { |
|
$digesthash{$digest_user} = $uname.':'.$udom; |
|
} |
|
if (keys(%digesthash)) { |
|
&Apache::lonnet::put('exttools',\%digesthash,$cdom,$cnum); |
|
} |
|
} |
|
} |
} |
if ($display{'target'}) { |
if ($display{'target'}) { |
$ltiparams{'launch_presentation_document_target'} = $display{'target'}; |
$ltiparams{'launch_presentation_document_target'} = $display{'target'}; |
Line 335 sub lti_params {
|
Line 319 sub lti_params {
|
$ltiparams{'lis_person_contact_email_primary'} = $contact_email; |
$ltiparams{'lis_person_contact_email_primary'} = $contact_email; |
} |
} |
if ($fields{'user'}) { |
if ($fields{'user'}) { |
$ltiparams{'lis_person_sourcedid'} = $uname.':'.$udom; |
if ($incdom) { |
|
$ltiparams{'lis_person_sourcedid'} = $uname.':'.$udom; |
|
} else { |
|
$ltiparams{'lis_person_sourcedid'} = $uname; |
|
} |
} |
} |
if (keys(%custom)) { |
if (keys(%custom)) { |
foreach my $key (keys(%custom)) { |
foreach my $key (keys(%custom)) { |
Line 357 sub lti_params {
|
Line 345 sub lti_params {
|
} |
} |
|
|
sub launch_html { |
sub launch_html { |
my ($url,$key,$secret,$submittext,$paramsref) = @_; |
my ($url,$key,$secret,$sigmethod,$submittext,$paramsref) = @_; |
my $hashref = &LONCAPA::ltiutils::sign_params($url,$key,$secret,$paramsref); |
my $hashref = &LONCAPA::ltiutils::sign_params($url,$key,$secret,$paramsref,$sigmethod); |
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"> |