--- loncom/interface/lonexttool.pm 2016/01/25 20:13:02 1.2
+++ loncom/interface/lonexttool.pm 2025/03/15 17:28:14 1.27
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Launch External Tool Provider (LTI)
#
-# $Id: lonexttool.pm,v 1.2 2016/01/25 20:13:02 raeburn Exp $
+# $Id: lonexttool.pm,v 1.27 2025/03/15 17:28:14 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -43,13 +43,17 @@ package Apache::lonexttool;
use strict;
use Apache::Constants qw(:common :http);
-use Net::OAuth;
use Encode;
use Digest::SHA;
use HTML::Entities;
use Apache::lonlocal;
use Apache::lonnet;
use Apache::loncommon;
+use Apache::londatecheck;
+use Apache::lonipcheck;
+use Apache::lonhomework;
+use Apache::structuretags;
+use LONCAPA::ltiutils;
sub handler {
my $r=shift;
@@ -62,27 +66,29 @@ sub handler {
# ------------------------------------------------------------ Print the screen
if ($target eq 'tex') {
$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
+ } else {
+ $target = 'web';
}
# Is this even in a course?
unless ($env{'request.course.id'}) {
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 {
$r->print('\textbf{Not in a course}\end{document}');
}
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,54 +96,169 @@ 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 ($idx,$crstool,$is_tool,%toolhash,%toolsettings);
- 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));
+ if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") {
+ %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
+ if ($toolsettings{'id'}) {
+ my %ltitools;
+ if ($toolsettings{'id'} =~ /^c(\d+)$/) {
+ $idx = $1;
+ $crstool = 1;
+ %ltitools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
} else {
- &Apache::loncommon::simple_error_page($r,'External Tool Unavailable',
- 'External Tool Unavailable');
+ $idx = $toolsettings{'id'};
+ %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
+ }
+ if (ref($ltitools{$idx}) eq 'HASH') {
+ %toolhash = %{$ltitools{$idx}};
+ $toolhash{'display'} = {
+ target => $toolsettings{'target'},
+ width => $toolsettings{'width'},
+ height => $toolsettings{'height'},
+ };
+ foreach my $item (qw(crslabel crstitle crsappend gradable)) {
+ $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;
}
}
- } 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());
+ 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.'}').'\\\\');
+ }
+ if ($toolhash{'gradable'}) {
+ $Apache::lonhomework::browse = &Apache::lonnet::allowed('bre',$r->uri);
+ if ($env{'form.markaccess'}) {
+ my @interval=&Apache::lonnet::EXT('resource.0.interval',$symb);
+ my ($timelimit) = split(/_/,$interval[0]);
+ &Apache::lonnet::set_first_access($interval[1],$timelimit);
+ } elsif ($symb && $env{'form.LC_interval_done'} eq 'true') {
+ # Set the event timer to zero if the "done button" was clicked. The button is
+ # part of the doneButton form created in lonmenu.pm
+ ($donebuttonresult,$donemsg) = &Apache::lonhomework::zero_timer($symb);
+ undef($env{'form.LC_interval_done'});
+ undef($env{'form.LC_interval_done_proctorpass'});
+ }
+ ($status,$msg) = &gradabletool_access_check($target);
+ undef($Apache::lonhomework::browse);
+ if ($status eq 'SHOW_ANSWER') {
+ $r->print(&display_score($target));
+ if ($target eq 'tex') {
+ $r->print('\end{document}');
+ }
+ return OK;
+ } elsif ($status ne 'CAN_ANSWER') {
+ if ($target eq 'tex') {
+ $r->print('\end{document}');
+ } else {
+ $r->print($msg);
+ }
+ return OK;
+ }
} else {
+ 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;
+ 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{'url'} ne '') && ($launchok)) {
+ my %lti = <i_params($r,$cnum,$cdom,$marker,$exttool,$idx,$submittext,\%toolhash);
+ my $url = $toolhash{'url'};
+ if ($toolhash{'crsappend'} ne '') {
+ $url .= $toolhash{'crsappend'};
+ }
+ my %info = (
+ method => $toolhash{'sigmethod'},
+ );
+ $r->print(&launch_html($cdom,$cnum,$crstool,$url,$idx,
+ $toolhash{'cipher'},$submittext,\%lti,\%info));
+ } else {
+ $r->print(''.&mt('External Tool Unavailable').'
');
+ }
}
+ return OK;
}
sub lti_params {
- my ($r,$toolsref) = @_;
+ my ($r,$cnum,$cdom,$marker,$exttool,$idx,$submittext,$toolsref) = @_;
my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,
- %fields,%rolesmap,%display,%custom,@userlangs);
+ $crslabel,$crstitle,$gradesecret,$rostersecret,%fields,%rolesmap,
+ %display,%custom,@userlangs,$incdom,$returnurl,$backtourl);
if (ref($toolsref) eq 'HASH') {
$version = $toolsref->{'version'};
$toolname = $toolsref->{'title'};
$passback = $toolsref->{'passback'};
+ $gradesecret = $toolsref->{'gradesecret'};
$roster = $toolsref->{'roster'};
+ $rostersecret = $toolsref->{'rostersecret'};
$msgtype = $toolsref->{'messagetype'};
+ $incdom = $toolsref->{'incdom'};
if (ref($toolsref->{'fields'}) eq 'HASH') {
%fields = %{$toolsref->{'fields'}};
}
@@ -150,6 +271,10 @@ sub lti_params {
if (ref($toolsref->{'custom'}) eq 'HASH') {
%custom = %{$toolsref->{'custom'}};
}
+ $crslabel = $toolsref->{'crslabel'};
+ $crstitle = $toolsref->{'crstitle'};
+ $returnurl = $toolsref->{'returnurl'};
+ $backtourl = $toolsref->{'backtourl'};
}
if ($version eq '') {
$version = 'LTI-1p0';
@@ -160,17 +285,26 @@ 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'};
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';
}
- my $digest_user = &Encode::decode_utf8($uname.':'.$udom);
+ my @possdigest;
+ my $digest_user = &Encode::decode('UTF-8',$uname.':'.$udom);
$digest_user = &Digest::SHA::sha1_hex($digest_user);
+ push(@possdigest,$digest_user);
if ($env{'course.'.$env{'request.course.id'}.'.languages'} ne '') {
@userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
$env{'course.'.$env{'request.course.id'}.'.languages'}));
@@ -188,11 +322,14 @@ sub lti_params {
if (scalar(@userlangs) == 1) {
$locale = $userlangs[0];
}
- my ($title,$digest_symb);
+ my ($title,$digest_symb,$digest_suppurl,$resource_link_id);
my ($symb) = &Apache::lonnet::whichuser();
+ my $uri = "/adm/$cdom/$cnum/$marker/$exttool";
if ($symb) {
- $digest_symb = &Encode::decode_utf8($symb);
+ $digest_symb = &Encode::decode('UTF-8',$symb);
$digest_symb = &Digest::SHA::sha1_hex($digest_symb);
+ $resource_link_id = $digest_symb;
+ push(@possdigest,$digest_symb);
my $navmap = Apache::lonnavmaps::navmap->new();
if (ref($navmap)) {
my $res = $navmap->getBySymb($symb);
@@ -200,42 +337,77 @@ sub lti_params {
$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 $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,$r);
+
my %ltiparams = (
lti_version => $version,
lti_message_type => $msgtype,
resource_link_title => $title,
- resource_link_id => $digest_symb,
+ resource_link_id => $resource_link_id,
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 $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';
- }
- if ($passback) {
- if ($ltirole eq 'Learner') {
- $ltiparams{'lis_outcome_service_url'} = $crsprotocol.'//'.$crshostname.'/adm/ltipassback';
+ }
+ if (($passback) || ($roster)) {
+ my (%currdigest,%digesthash);
+ if (@possdigest) {
+ %currdigest = &Apache::lonnet::get('exttools',\@possdigest,
+ $cdom,$cnum);
+ }
+ if ($passback) {
+ $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 ($gradesecret) {
+ my $uniqid = $digest_symb.':::'.$digest_user.':::'.$env{'request.course.id'};
+ $ltiparams{'lis_result_sourcedid'} = &LONCAPA::ltiutils::get_service_id($gradesecret,$uniqid);
+ }
}
- }
- 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_id'} = ''; #FIXME
+ 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_service_id($rostersecret,$uniqid);
+ }
+ }
+ }
+ if (($digest_symb) && ($gradesecret || $rostersecret)) {
+ unless ((exists($currdigest{$digest_symb})) && ($currdigest{$digest_symb} eq $symb)) {
+ $digesthash{$digest_symb} = $symb;
+ }
+ }
+ if (($passback) && ($gradesecret)) {
+ unless ((exists($currdigest{$digest_user})) && ($currdigest{$digest_user} eq $uname.':'.$udom)) {
+ $digesthash{$digest_user} = $uname.':'.$udom;
+ }
+ }
+ if (keys(%digesthash)) {
+ &Apache::lonnet::put('exttools',\%digesthash,$cdom,$cnum);
}
}
}
@@ -260,40 +432,108 @@ 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;
}
+ if ($fields{'user'}) {
+ if ($incdom) {
+ $ltiparams{'lis_person_sourcedid'} = $uname.':'.$udom;
+ } else {
+ $ltiparams{'lis_person_sourcedid'} = $uname;
+ }
+ }
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)) {
- $ltiparams{$key} = &Encode::decode_utf8($ltiparams{$key});
+ $ltiparams{$key} = &Encode::decode('UTF-8',$ltiparams{$key});
+ }
+ $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;
}
sub launch_html {
- my ($url,$key,$secret,$toolname,$paramsref) = @_;
- my $hashref = &sign_params($url,$key,$secret,$paramsref);
- my $submittext = &mt('Launch [_1]',$toolname);
+ my ($cdom,$cnum,$crstool,$url,$idx,$keynum,$submittext,$paramsref,$inforef) = @_;
+ my ($status,$hashref) =
+ &Apache::lonnet::sign_lti($cdom,$cnum,$crstool,'tools','launch',$url,$idx,$keynum,
+ $paramsref,$inforef);
+ unless ($status eq 'ok') {
+ return ''.&mt('External Tool Unavailable').'
';
+ }
+ my $action = &HTML::Entities::encode($url,'<>&"');
my $form = <<"END";
-
\n";
@@ -302,9 +542,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
@@ -312,23 +552,97 @@ ENDJS
return $form;
}
-sub sign_params {
- my ($url,$key,$secret,$paramsref) = @_;
- my $nonce = Digest::SHA::sha1_hex(sprintf("%06x%06x",rand(0xfffff0),rand(0xfffff0)));
- my $request = Net::OAuth->request("request token")->new(
- consumer_key => $key,
- consumer_secret => $secret,
- request_url => $url,
- request_method => 'POST',
- signature_method => 'HMAC-SHA1',
- timestamp => time,
- nonce => $nonce,
- callback => 'about:blank',
- extra_params => $paramsref,
- version => '1.0',
- );
- $request->sign;
- return $request->to_hash();
+sub gradabletool_access_check {
+ my ($target) = @_;
+ my ($result,$resource_due);
+ my $status;
+ my ($symb,$courseid,$udom,$uname) = &Apache::lonnet::whichuser();
+ my @targets;
+ if ($target) {
+ @targets = ($target);
+ } elsif (defined($env{'form.submitted'}) && defined($env{'form.validate'})) {
+ @targets = ('grade','web');
+ } else {
+ @targets = ('web');
+ }
+ foreach my $target (@targets) {
+ &Apache::structuretags::initialize_storage($symb);
+ &Apache::lonhomework::set_show_problem_status(&Apache::lonnet::EXT('resource.0.problemstatus'));
+ my ($accessmsg,$slot_name,$slot,$ipused);
+ ($status,$accessmsg,$slot_name,$slot,$ipused) =
+ &Apache::lonhomework::check_slot_access('0','tool',$symb);
+ if (( $status eq 'CLOSED' ) ||
+ ( $status eq 'UNCHECKEDOUT') ||
+ ( $status eq 'NOT_YET_VIEWED') ||
+ ( $status eq 'BANNED') ||
+ ( $status eq 'UNAVAILABLE') ||
+ ( $status eq 'NOT_IN_A_SLOT') ||
+ ( $status eq 'NOTRESERVABLE') ||
+ ( $status eq 'RESERVABLE') ||
+ ( $status eq 'RESERVABLE_LATER') ||
+ ( $status eq 'INVALID_ACCESS') ||
+ ( $status eq 'NEED_DIFFERENT_IP') ||
+ ( $status eq 'WAITING_FOR_GRADE')) {
+ $result = &Apache::structuretags::access_status_msg('tool',$status,$symb,
+ $target,$ipused,$accessmsg);
+ } elsif ($status eq 'NEEDS_CHECKIN') {
+ $result = &Apache::structuretags::checkin_prompt($target,$slot_name,$slot,'tool');
+ } elsif ($target eq 'web') {
+ if ($status eq 'CAN_ANSWER') {
+ $resource_due = &Apache::lonhomework::due_date(0, $env{'request.symb'});
+ if ($slot_name ne '') {
+ $resource_due = &Apache::structuretags::selfcheckin_resource($resource_due,
+ $slot_name,$slot,
+ $env{'request.symb'});
+ }
+ }
+ }
+ if (keys(%Apache::lonhomework::results)) {
+ &Apache::structuretags::finalize_storage();
+ }
+ }
+ return ($status,$result,$resource_due);
+}
+
+sub display_score {
+ my ($target) = @_;
+ my $weight = &Apache::lonnet::EXT('resource.0.weight');
+ if ((!defined($weight)) || ($weight eq '')) { $weight=1; }
+ my $awarded = $Apache::lonhomework::history{'resource.0.awarded'};
+ if (!defined($awarded)) { $awarded=0; }
+ my $display='';
+ if ($target eq 'tex') {
+ $display = '\\\\';
+ }
+ if (!defined($awarded)) {
+ $display .= &mt('[_1] possible points.',$weight);
+ } else {
+ my $points = $awarded*$weight;
+ my $result = sprintf('%.2f',$points);
+ $display .= &mt('You have [_1] out of [quant,_2,possible point]',
+ $result,$weight);
+ }
+ my $comment = $Apache::lonhomework::history{'resource.0.comment'};
+ if (!defined($comment) || $comment!~/\w/) {
+ $comment='';
+ } else {
+ if ($target eq 'tex') {
+ $comment = '\\\\'.$comment;
+ } else {
+ $comment='
';
+ }
+ }
+ my $gradeinfo = $Apache::lonhomework::history{'resource.0.gradeinfo'};
+ if (!defined($gradeinfo) || $gradeinfo!~/\w/) {
+ $gradeinfo='';
+ } else {
+ if ($target eq 'tex') {
+ $gradeinfo = '\\\\'.$gradeinfo;
+ } else {
+ $gradeinfo='
';
+ }
+ }
+ return $display.$comment.$gradeinfo;
}
1;