Annotation of loncom/interface/lonexttool.pm, revision 1.24
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Launch External Tool Provider (LTI)
3: #
1.24 ! raeburn 4: # $Id: lonexttool.pm,v 1.23 2022/03/29 20:12:46 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: =pod
30:
31: =head1 NAME
32:
33: Apache::lonexttool - Tool Provider launcher
34:
35: =head1 SYNOPSIS
36:
37:
38: =head1 OVERVIEW
39:
40: =cut
41:
42: package Apache::lonexttool;
43:
44: use strict;
45: use Apache::Constants qw(:common :http);
46: use Encode;
47: use Digest::SHA;
48: use HTML::Entities;
49: use Apache::lonlocal;
50: use Apache::lonnet;
51: use Apache::loncommon;
1.12 raeburn 52: use Apache::londatecheck;
53: use Apache::lonipcheck;
54: use Apache::lonhomework;
55: use Apache::structuretags;
1.9 raeburn 56: use LONCAPA::ltiutils;
1.1 raeburn 57:
58: sub handler {
59: my $r=shift;
60: &Apache::loncommon::content_type($r,'text/html');
61: $r->send_http_header;
62:
63: return OK if $r->header_only;
64:
65: my $target=$env{'form.grade_target'};
66: # ------------------------------------------------------------ Print the screen
67: if ($target eq 'tex') {
68: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.12 raeburn 69: } else {
70: $target = 'web';
1.1 raeburn 71: }
72:
73: # Is this even in a course?
74: unless ($env{'request.course.id'}) {
75: if ($target ne 'tex') {
1.11 raeburn 76: &Apache::loncommon::simple_error_page($r,'','Not in a course',
77: {'only_body' => 1});
1.1 raeburn 78: } else {
79: $r->print('\textbf{Not in a course}\end{document}');
80: }
81: return OK;
82: }
83:
1.3 raeburn 84: my ($marker,$exttool) = (split(m{/},$r->uri))[4,5];
1.1 raeburn 85: $marker=~s/\D//g;
86:
87: if (!$marker) {
88: if ($target ne 'tex') {
1.3 raeburn 89: $r->print(&mt('Invalid Call'));
1.1 raeburn 90: } else {
1.3 raeburn 91: $r->print('\textbf{'&mt('Invalid Call').'}\end{document}');
1.1 raeburn 92: }
93: return OK;
94: }
95:
96: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
97: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
98: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
1.24 ! raeburn 99: my ($idx,$crstool,$is_tool,%toolhash,%toolsettings);
1.1 raeburn 100:
1.3 raeburn 101: if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") {
1.12 raeburn 102: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
1.3 raeburn 103: if ($toolsettings{'id'}) {
1.24 ! raeburn 104: my %ltitools;
! 105: if ($toolsettings{'id'} =~ /^c(\d+)$/) {
! 106: $idx = $1;
! 107: $crstool = 1;
! 108: %ltitools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
! 109: } else {
! 110: $idx = $toolsettings{'id'};
! 111: %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
! 112: }
1.6 raeburn 113: if (ref($ltitools{$idx}) eq 'HASH') {
1.12 raeburn 114: %toolhash = %{$ltitools{$idx}};
1.3 raeburn 115: $toolhash{'display'} = {
116: target => $toolsettings{'target'},
117: width => $toolsettings{'width'},
118: height => $toolsettings{'height'},
119: };
1.19 raeburn 120: foreach my $item (qw(crslabel crstitle crsappend gradable)) {
1.16 raeburn 121: $toolhash{$item} = $toolsettings{$item};
122: }
1.3 raeburn 123: $is_tool = 1;
1.1 raeburn 124: }
125: }
1.3 raeburn 126: }
127: unless ($is_tool) {
1.1 raeburn 128: if ($target ne 'tex') {
1.3 raeburn 129: $r->print('<div>'.&mt('Invalid Call').'</div>');
1.1 raeburn 130: } else {
1.3 raeburn 131: $r->print('\textbf{'.&mt(Invalid Call).'}\end{document}');
1.1 raeburn 132: }
1.12 raeburn 133: return OK;
134: }
135:
1.15 raeburn 136: my ($symb,$status,$open,$close,$msg,$donebuttonresult,$donemsg);
137: if (($target eq 'tex') || ($toolhash{'gradable'})) {
138: ($symb) = &Apache::lonnet::whichuser();
139: }
140: if ($target eq 'tex') {
141: my $title = &Apache::lonnet::gettitle($symb);
142: $r->print(&mt('External Tool: [_1]','\textit{'.$title.'}').'\\\\');
143: }
1.12 raeburn 144: if ($toolhash{'gradable'}) {
145: $Apache::lonhomework::browse = &Apache::lonnet::allowed('bre',$r->uri);
146: if ($env{'form.markaccess'}) {
1.13 raeburn 147: my @interval=&Apache::lonnet::EXT('resource.0.interval',$symb);
1.12 raeburn 148: my ($timelimit) = split(/_/,$interval[0]);
149: &Apache::lonnet::set_first_access($interval[1],$timelimit);
1.13 raeburn 150: } elsif ($symb && $env{'form.LC_interval_done'} eq 'true') {
151: # Set the event timer to zero if the "done button" was clicked. The button is
152: # part of the doneButton form created in lonmenu.pm
153: ($donebuttonresult,$donemsg) = &Apache::lonhomework::zero_timer($symb);
154: undef($env{'form.LC_interval_done'});
155: undef($env{'form.LC_interval_done_proctorpass'});
1.12 raeburn 156: }
1.15 raeburn 157: ($status,$msg) = &gradabletool_access_check($target);
1.12 raeburn 158: undef($Apache::lonhomework::browse);
159: if ($status eq 'SHOW_ANSWER') {
1.15 raeburn 160: $r->print(&display_score($target));
161: if ($target eq 'tex') {
162: $r->print('\end{document}');
163: }
1.12 raeburn 164: return OK;
165: } elsif ($status ne 'CAN_ANSWER') {
1.15 raeburn 166: if ($target eq 'tex') {
167: $r->print('\end{document}');
168: } else {
169: $r->print($msg);
170: }
1.12 raeburn 171: return OK;
172: }
173: } else {
174: my ($status,$open,$close,$msg)=&Apache::londatecheck::content_date_check();
175: if ($status ne 'OPEN') {
176: if ($target eq 'tex') {
1.15 raeburn 177: $r->print(&mt('Not open to be viewed').'\end{document}');
1.12 raeburn 178: } else {
179: $r->print($msg);
180: }
181: return OK;
182: } else {
183: ($status,$msg)=&Apache::lonipcheck::ip_access_check();
184: if ($status ne 'OPEN') {
185: if ($target eq 'tex') {
1.15 raeburn 186: $r->print(&mt('Not open to be viewed').'\end{document}');
1.12 raeburn 187: } else {
188: $r->print($msg);
189: }
190: return OK;
191: }
192: }
193: }
194: my $launchok = 1;
195: if ($target eq 'tex') {
1.15 raeburn 196: $r->print('\end{document}');
1.12 raeburn 197: } else {
198: my $now = time;
199: if ($toolhash{'passback'}) {
200: if (&LONCAPA::ltiutils::set_service_secret($cdom,$cnum,$marker,'grade',$now,
201: \%toolsettings,\%toolhash) eq 'ok') {
202: $toolhash{'gradesecret'} = $toolsettings{'gradesecret'};
203: } else {
204: undef($launchok);
205: }
206: }
207: if ($toolhash{'roster'}) {
208: if (&LONCAPA::ltiutils::set_service_secret($cdom,$cnum,$marker,'roster',$now,
209: \%toolsettings,\%toolhash) eq 'ok') {
210: $toolhash{'rostersecret'} = $toolsettings{'rostersecret'};
211: }
212: }
213: my $submittext = &mt('Launch [_1]',$toolhash{'title'});
1.24 ! raeburn 214: if (($toolhash{'url'} ne '') && ($launchok)) {
1.12 raeburn 215: my %lti = <i_params($r,$cnum,$cdom,$idx,$submittext,\%toolhash);
216: my $url = $toolhash{'url'};
217: if ($toolhash{'crsappend'} ne '') {
218: $url .= $toolhash{'crsappend'};
219: }
1.24 ! raeburn 220: my %info = (
! 221: method => $toolhash{'sigmethod'},
! 222: );
! 223: $r->print(&launch_html($cdom,$cnum,$crstool,$url,$idx,
! 224: $toolhash{'cipher'},$submittext,\%lti,\%info));
1.12 raeburn 225: } else {
1.24 ! raeburn 226: $r->print('<div class="LC_warning">'.&mt('External Tool Unavailable').'</div>');
1.12 raeburn 227: }
1.1 raeburn 228: }
229: return OK;
230: }
231:
232: sub lti_params {
1.6 raeburn 233: my ($r,$cnum,$cdom,$idx,$submittext,$toolsref) = @_;
1.1 raeburn 234: my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,
1.6 raeburn 235: $crslabel,$crstitle,$gradesecret,$rostersecret,%fields,%rolesmap,
1.16 raeburn 236: %display,%custom,@userlangs,$incdom);
1.1 raeburn 237: if (ref($toolsref) eq 'HASH') {
238: $version = $toolsref->{'version'};
239: $toolname = $toolsref->{'title'};
240: $passback = $toolsref->{'passback'};
1.6 raeburn 241: $gradesecret = $toolsref->{'gradesecret'};
1.1 raeburn 242: $roster = $toolsref->{'roster'};
1.6 raeburn 243: $rostersecret = $toolsref->{'rostersecret'};
1.1 raeburn 244: $msgtype = $toolsref->{'messagetype'};
1.16 raeburn 245: $incdom = $toolsref->{'incdom'};
1.1 raeburn 246: if (ref($toolsref->{'fields'}) eq 'HASH') {
247: %fields = %{$toolsref->{'fields'}};
248: }
249: if (ref($toolsref->{'roles'}) eq 'HASH') {
250: %rolesmap = %{$toolsref->{'roles'}};
251: }
252: if (ref($toolsref->{'display'}) eq 'HASH') {
253: %display = %{$toolsref->{'display'}};
254: }
255: if (ref($toolsref->{'custom'}) eq 'HASH') {
256: %custom = %{$toolsref->{'custom'}};
257: }
1.4 raeburn 258: $crslabel = $toolsref->{'crslabel'};
259: $crstitle = $toolsref->{'crstitle'};
1.1 raeburn 260: }
261: if ($version eq '') {
262: $version = 'LTI-1p0';
263: }
264: if ($context_type eq '') {
265: $context_type = 'CourseSection';
266: }
267: if ($msgtype eq '') {
268: $msgtype = 'basic-lti-launch-request';
269: }
1.4 raeburn 270: if ($crslabel eq '') {
1.20 raeburn 271: $crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'};
1.4 raeburn 272: }
273: if ($crstitle eq '') {
1.20 raeburn 274: $crstitle = $env{'course.'.$env{'request.course.id'}.'.description'};
1.4 raeburn 275: }
1.1 raeburn 276: my $lonhost = $r->dir_config('lonHostID');
277: my $loncaparev = $r->dir_config('lonVersion');
278: my $uname = $env{'user.name'};
279: my $udom = $env{'user.domain'};
280: my @possroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.3 raeburn 281: my ($roleprefix) = ($env{'request.role'} =~ /^(\w+)\./);
282: my $ltirole = $rolesmap{$roleprefix};
1.1 raeburn 283: unless (grep(/^\Q$ltirole\E$/,@possroles)) {
284: $ltirole = 'Learner';
285: }
1.17 raeburn 286: my @possdigest;
1.23 raeburn 287: my $digest_user = &Encode::decode('UTF-8',$uname.':'.$udom);
1.1 raeburn 288: $digest_user = &Digest::SHA::sha1_hex($digest_user);
1.17 raeburn 289: push(@possdigest,$digest_user);
1.1 raeburn 290: if ($env{'course.'.$env{'request.course.id'}.'.languages'} ne '') {
291: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
292: $env{'course.'.$env{'request.course.id'}.'.languages'}));
293: } else {
1.2 raeburn 294: my %langhash = &Apache::loncommon::getlangs($uname,$udom);
1.1 raeburn 295: if ($langhash{'languages'} ne '') {
296: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
297: } else {
298: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
299: if ($domdefs{'lang_def'} ne '') {
300: @userlangs = ($domdefs{'lang_def'});
301: }
302: }
303: }
304: if (scalar(@userlangs) == 1) {
305: $locale = $userlangs[0];
306: }
307: my ($title,$digest_symb);
308: my ($symb) = &Apache::lonnet::whichuser();
309: if ($symb) {
1.23 raeburn 310: $digest_symb = &Encode::decode('UTF-8',$symb);
1.1 raeburn 311: $digest_symb = &Digest::SHA::sha1_hex($digest_symb);
1.17 raeburn 312: push(@possdigest,$digest_symb);
1.1 raeburn 313: my $navmap = Apache::lonnavmaps::navmap->new();
314: if (ref($navmap)) {
315: my $res = $navmap->getBySymb($symb);
316: if (ref($res)) {
317: $title = $res->compTitle();
318: }
319: }
320: }
1.4 raeburn 321: my $domdesc = &Apache::lonnet::domain($cdom);
322: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
323: my $int_dom = &Apache::lonnet::internet_dom($primary_id);
1.21 raeburn 324: my $portal_url = &Apache::lonnet::course_portal_url($cnum,$cdom,$r);
1.4 raeburn 325:
1.1 raeburn 326: my %ltiparams = (
327: lti_version => $version,
328: lti_message_type => $msgtype,
329: resource_link_title => $title,
330: resource_link_id => $digest_symb,
331: tool_consumer_instance_guid => $lonhost,
1.4 raeburn 332: tool_consumer_instance_description => $domdesc,
1.1 raeburn 333: tool_consumer_info_product_family_code => 'loncapa',
1.20 raeburn 334: tool_consumer_instance_name => $int_dom,
1.4 raeburn 335: tool_consumer_instance_url => $portal_url,
1.1 raeburn 336: tool_consumer_info_version => $loncaparev,
337: user_id => $digest_user,
338: roles => $ltirole,
339: context_id => $env{'request.course.id'},
340: context_type => $context_type,
1.4 raeburn 341: context_label => $crslabel,
342: context_title => $crstitle,
1.1 raeburn 343: launch_presentation_locale => $locale,
344: );
1.3 raeburn 345: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
346: my $crshostname = &Apache::lonnet::hostname($crshome);
1.1 raeburn 347: if ($crshostname) {
1.3 raeburn 348: my $crsprotocol = $Apache::lonnet::protocol{$crshome};
1.1 raeburn 349: unless ($crsprotocol eq 'https') {
350: $crsprotocol = 'http';
1.6 raeburn 351: }
352: if (($passback) || ($roster)) {
1.17 raeburn 353: my (%currdigest,%digesthash);
354: if (@possdigest) {
355: %currdigest = &Apache::lonnet::get('exttools',\@possdigest,
356: $cdom,$cnum);
357: }
1.6 raeburn 358: if ($passback) {
1.8 raeburn 359: $ltiparams{'lis_outcome_service_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/passback';
1.1 raeburn 360: $ltiparams{'ext_ims_lis_basic_outcome_url'} = $ltiparams{'lis_outcome_service_url'};
1.6 raeburn 361: if ($gradesecret) {
1.9 raeburn 362: my $uniqid = $digest_symb.':::'.$digest_user.':::'.$env{'request.course.id'};
1.20 raeburn 363: $ltiparams{'lis_result_sourcedid'} = &LONCAPA::ltiutils::get_service_id($gradesecret,$uniqid);
1.6 raeburn 364: }
365: }
366: if ($roster) {
367: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
1.8 raeburn 368: $ltiparams{'ext_ims_lis_memberships_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/roster';
1.6 raeburn 369: if ($rostersecret) {
1.9 raeburn 370: my $uniqid = $digest_symb.':::'.$env{'request.course.id'};
1.10 raeburn 371: $ltiparams{'ext_ims_lis_memberships_id'} = &LONCAPA::ltiutils::get_service_id($rostersecret,$uniqid);
1.6 raeburn 372: }
373: }
374: }
375: if (($digest_symb) && ($gradesecret || $rostersecret)) {
1.17 raeburn 376: unless ((exists($currdigest{$digest_symb})) && ($currdigest{$digest_symb} eq $symb)) {
377: $digesthash{$digest_symb} = $symb;
378: }
1.6 raeburn 379: }
380: if (($passback) && ($gradesecret)) {
1.17 raeburn 381: unless ((exists($currdigest{$digest_user})) && ($currdigest{$digest_user} eq $uname.':'.$udom)) {
382: $digesthash{$digest_user} = $uname.':'.$udom;
383: }
1.6 raeburn 384: }
385: if (keys(%digesthash)) {
386: &Apache::lonnet::put('exttools',\%digesthash,$cdom,$cnum);
1.1 raeburn 387: }
388: }
389: }
390: if ($display{'target'}) {
391: $ltiparams{'launch_presentation_document_target'} = $display{'target'};
392: }
393: if ($display{'width'}) {
394: $ltiparams{'launch_presentation_width'} = $display{'width'};
395: }
396: if ($display{'height'}) {
397: $ltiparams{'launch_presentation_height'} = $display{'height'};
398: }
399: if ($fields{'firstname'}) {
400: $ltiparams{'lis_person_name_given'} = $env{'environment.firstname'};
401: }
402: if ($fields{'lastname'}) {
403: $ltiparams{'lis_person_name_family'} = $env{'environment.lastname'};
404: }
405: if ($fields{'fullname'}) {
406: $ltiparams{'lis_person_name_full'} = &Apache::loncommon::plainname($uname,$udom);
407: }
408: if ($fields{'email'}) {
409: my %emails = &Apache::loncommon::getemails($uname,$udom);
410: my $contact_email;
1.3 raeburn 411: foreach my $type ('permanentemail','critnotification','notification') {
412: if ($emails{$type} =~ /\@/) {
413: $contact_email = $emails{$type};
1.1 raeburn 414: last;
415: }
416: }
1.2 raeburn 417: $ltiparams{'lis_person_contact_email_primary'} = $contact_email;
1.1 raeburn 418: }
1.4 raeburn 419: if ($fields{'user'}) {
1.16 raeburn 420: if ($incdom) {
421: $ltiparams{'lis_person_sourcedid'} = $uname.':'.$udom;
422: } else {
423: $ltiparams{'lis_person_sourcedid'} = $uname;
424: }
1.4 raeburn 425: }
1.1 raeburn 426: if (keys(%custom)) {
427: foreach my $key (keys(%custom)) {
1.5 raeburn 428: my $value = $custom{$key};
429: $value =~ s/^\s+|\s+\$//g;
430: if ($value =~ /^\QLONCAPA::env{\E([^\}]+)\}$/) {
431: if (exists($env{$1})) {
432: $value = $env{$1};
433: }
434: }
435: $ltiparams{'custom_'.$key} = $value;
1.1 raeburn 436: }
437: }
438: foreach my $key (keys(%ltiparams)) {
1.23 raeburn 439: $ltiparams{$key} = &Encode::decode('UTF-8',$ltiparams{$key});
1.1 raeburn 440: }
1.3 raeburn 441: $ltiparams{'basiclti_submit'} = $submittext;
1.1 raeburn 442: return %ltiparams;
443: }
444:
445: sub launch_html {
1.24 ! raeburn 446: my ($cdom,$cnum,$crstool,$url,$idx,$keynum,$submittext,$paramsref,$inforef) = @_;
! 447: my ($status,$hashref) =
! 448: &Apache::lonnet::sign_lti($cdom,$cnum,$crstool,$url,$idx,$keynum,
! 449: '',$paramsref,$inforef);
! 450: unless ($status eq 'ok') {
! 451: return '<div class="LC_warning">'.&mt('External Tool Unavailable').'</div>';
! 452: }
1.5 raeburn 453: my $action = &HTML::Entities::encode($url,'<>&"');
1.1 raeburn 454: my $form = <<"END";
455: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
456: <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
457: <body>
458: <div id="LCltiLaunch">
1.5 raeburn 459: <form name="LCltiLaunchForm" id="LCltiLaunchFormId" action="$action" method="post" encType="application/x-www-form-urlencoded">
1.1 raeburn 460: END
461: if (ref($hashref) eq 'HASH') {
462: foreach my $item (keys(%{$hashref})) {
1.3 raeburn 463: my $type = 'hidden';
464: if ($item eq 'basiclti_submit') {
465: $type = 'submit';
466: }
467: $form .= '<input type="'.$type.'" name="'.$item.'" value="'.$hashref->{$item}.'" id="id_'.$item.'" />'."\n";
1.1 raeburn 468: }
469: }
470: $form .= "</form></div>\n";
471: $form .= <<"ENDJS";
472: <script type="text/javascript">
473: document.getElementById("LCltiLaunch").style.display = "none";
474: nei = document.createElement('input');
475: nei.setAttribute('type','hidden');
1.3 raeburn 476: nei.setAttribute('name','basiclti_submit');
1.1 raeburn 477: nei.setAttribute('value','$submittext');
1.3 raeburn 478: document.getElementById("LCltiLaunchFormId").appendChild(nei);
1.1 raeburn 479: document.LCltiLaunchForm.submit();
480: </script>
481: ENDJS
482: $form .= "</body></html>\n";
483: return $form;
484: }
485:
1.12 raeburn 486: sub gradabletool_access_check {
1.15 raeburn 487: my ($target) = @_;
1.12 raeburn 488: my ($result,$resource_due);
489: my $status;
490: my ($symb,$courseid,$udom,$uname) = &Apache::lonnet::whichuser();
491: my @targets;
1.15 raeburn 492: if ($target) {
493: @targets = ($target);
494: } elsif (defined($env{'form.submitted'}) && defined($env{'form.validate'})) {
1.12 raeburn 495: @targets = ('grade','web');
496: } else {
497: @targets = ('web');
498: }
499: foreach my $target (@targets) {
1.18 raeburn 500: &Apache::structuretags::initialize_storage($symb);
1.12 raeburn 501: &Apache::lonhomework::set_show_problem_status(&Apache::lonnet::EXT('resource.0.problemstatus'));
502: my ($accessmsg,$slot_name,$slot,$ipused);
503: ($status,$accessmsg,$slot_name,$slot,$ipused) =
504: &Apache::lonhomework::check_slot_access('0','tool',$symb);
505: if (( $status eq 'CLOSED' ) ||
506: ( $status eq 'UNCHECKEDOUT') ||
507: ( $status eq 'NOT_YET_VIEWED') ||
508: ( $status eq 'BANNED') ||
509: ( $status eq 'UNAVAILABLE') ||
510: ( $status eq 'NOT_IN_A_SLOT') ||
511: ( $status eq 'NOTRESERVABLE') ||
512: ( $status eq 'RESERVABLE') ||
513: ( $status eq 'RESERVABLE_LATER') ||
514: ( $status eq 'INVALID_ACCESS') ||
515: ( $status eq 'NEED_DIFFERENT_IP') ||
516: ( $status eq 'WAITING_FOR_GRADE')) {
517: $result = &Apache::structuretags::access_status_msg('tool',$status,$symb,
518: $target,$ipused,$accessmsg);
519: } elsif ($status eq 'NEEDS_CHECKIN') {
520: $result = &Apache::structuretags::checkin_prompt($target,$slot_name,$slot,'tool');
521: } elsif ($target eq 'web') {
522: if ($status eq 'CAN_ANSWER') {
523: $resource_due = &Apache::lonhomework::due_date(0, $env{'request.symb'});
524: if ($slot_name ne '') {
525: $resource_due = &Apache::structuretags::selfcheckin_resource($resource_due,
526: $slot_name,$slot,
527: $env{'request.symb'});
528: }
529: }
530: }
1.18 raeburn 531: if (keys(%Apache::lonhomework::results)) {
532: &Apache::structuretags::finalize_storage();
533: }
1.12 raeburn 534: }
535: return ($status,$result,$resource_due);
536: }
537:
538: sub display_score {
1.15 raeburn 539: my ($target) = @_;
1.12 raeburn 540: my $weight = &Apache::lonnet::EXT('resource.0.weight');
541: if ((!defined($weight)) || ($weight eq '')) { $weight=1; }
542: my $awarded = $Apache::lonhomework::history{'resource.0.awarded'};
543: if (!defined($awarded)) { $awarded=0; }
544: my $display='';
1.15 raeburn 545: if ($target eq 'tex') {
546: $display = '\\\\';
547: }
1.12 raeburn 548: if (!defined($awarded)) {
1.15 raeburn 549: $display .= &mt('[_1] possible points.',$weight);
1.12 raeburn 550: } else {
551: my $points = $awarded*$weight;
552: my $result = sprintf('%.2f',$points);
1.15 raeburn 553: $display .= &mt('You have [_1] out of [quant,_2,possible point]',
1.12 raeburn 554: $result,$weight);
555: }
556: my $comment = $Apache::lonhomework::history{'resource.0.comment'};
557: if (!defined($comment) || $comment!~/\w/) {
558: $comment='';
559: } else {
1.15 raeburn 560: if ($target eq 'tex') {
561: $comment = '\\\\'.$comment;
562: } else {
563: $comment='<br /><table><tr><td bgcolor="#FFFFDD">'.$comment.'</td></tr></table>';
564: }
1.12 raeburn 565: }
566: my $gradeinfo = $Apache::lonhomework::history{'resource.0.gradeinfo'};
567: if (!defined($gradeinfo) || $gradeinfo!~/\w/) {
568: $gradeinfo='';
569: } else {
1.15 raeburn 570: if ($target eq 'tex') {
571: $gradeinfo = '\\\\'.$gradeinfo;
572: } else {
573: $gradeinfo='<br /><table><tr><td bgcolor="#DDDDFF"><font size="+2">'.$gradeinfo.'</font></td></tr></table>';
574: }
1.12 raeburn 575: }
576: return $display.$comment.$gradeinfo;
577: }
578:
1.1 raeburn 579: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>