Annotation of loncom/interface/lonexttool.pm, revision 1.19
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Launch External Tool Provider (LTI)
3: #
1.19 ! raeburn 4: # $Id: lonexttool.pm,v 1.18 2018/01/31 14:17:44 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.12 raeburn 99: my ($idx,$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.12 raeburn 104: $idx = $toolsettings{'id'};
1.7 raeburn 105: my %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
1.6 raeburn 106: if (ref($ltitools{$idx}) eq 'HASH') {
1.12 raeburn 107: %toolhash = %{$ltitools{$idx}};
1.3 raeburn 108: $toolhash{'display'} = {
109: target => $toolsettings{'target'},
110: width => $toolsettings{'width'},
111: height => $toolsettings{'height'},
112: };
1.19 ! raeburn 113: foreach my $item (qw(crslabel crstitle crsappend gradable)) {
1.16 raeburn 114: $toolhash{$item} = $toolsettings{$item};
115: }
1.3 raeburn 116: $is_tool = 1;
1.1 raeburn 117: }
118: }
1.3 raeburn 119: }
120: unless ($is_tool) {
1.1 raeburn 121: if ($target ne 'tex') {
1.3 raeburn 122: $r->print('<div>'.&mt('Invalid Call').'</div>');
1.1 raeburn 123: } else {
1.3 raeburn 124: $r->print('\textbf{'.&mt(Invalid Call).'}\end{document}');
1.1 raeburn 125: }
1.12 raeburn 126: return OK;
127: }
128:
1.15 raeburn 129: my ($symb,$status,$open,$close,$msg,$donebuttonresult,$donemsg);
130: if (($target eq 'tex') || ($toolhash{'gradable'})) {
131: ($symb) = &Apache::lonnet::whichuser();
132: }
133: if ($target eq 'tex') {
134: my $title = &Apache::lonnet::gettitle($symb);
135: $r->print(&mt('External Tool: [_1]','\textit{'.$title.'}').'\\\\');
136: }
1.12 raeburn 137: if ($toolhash{'gradable'}) {
138: $Apache::lonhomework::browse = &Apache::lonnet::allowed('bre',$r->uri);
139: if ($env{'form.markaccess'}) {
1.13 raeburn 140: my @interval=&Apache::lonnet::EXT('resource.0.interval',$symb);
1.12 raeburn 141: my ($timelimit) = split(/_/,$interval[0]);
142: &Apache::lonnet::set_first_access($interval[1],$timelimit);
1.13 raeburn 143: } elsif ($symb && $env{'form.LC_interval_done'} eq 'true') {
144: # Set the event timer to zero if the "done button" was clicked. The button is
145: # part of the doneButton form created in lonmenu.pm
146: ($donebuttonresult,$donemsg) = &Apache::lonhomework::zero_timer($symb);
147: undef($env{'form.LC_interval_done'});
148: undef($env{'form.LC_interval_done_proctorpass'});
1.12 raeburn 149: }
1.15 raeburn 150: ($status,$msg) = &gradabletool_access_check($target);
1.12 raeburn 151: undef($Apache::lonhomework::browse);
152: if ($status eq 'SHOW_ANSWER') {
1.15 raeburn 153: $r->print(&display_score($target));
154: if ($target eq 'tex') {
155: $r->print('\end{document}');
156: }
1.12 raeburn 157: return OK;
158: } elsif ($status ne 'CAN_ANSWER') {
1.15 raeburn 159: if ($target eq 'tex') {
160: $r->print('\end{document}');
161: } else {
162: $r->print($msg);
163: }
1.12 raeburn 164: return OK;
165: }
166: } else {
167: my ($status,$open,$close,$msg)=&Apache::londatecheck::content_date_check();
168: if ($status ne 'OPEN') {
169: if ($target eq 'tex') {
1.15 raeburn 170: $r->print(&mt('Not open to be viewed').'\end{document}');
1.12 raeburn 171: } else {
172: $r->print($msg);
173: }
174: return OK;
175: } else {
176: ($status,$msg)=&Apache::lonipcheck::ip_access_check();
177: if ($status ne 'OPEN') {
178: if ($target eq 'tex') {
1.15 raeburn 179: $r->print(&mt('Not open to be viewed').'\end{document}');
1.12 raeburn 180: } else {
181: $r->print($msg);
182: }
183: return OK;
184: }
185: }
186: }
187: my $launchok = 1;
188: if ($target eq 'tex') {
1.15 raeburn 189: $r->print('\end{document}');
1.12 raeburn 190: } else {
191: my $now = time;
192: if ($toolhash{'passback'}) {
193: if (&LONCAPA::ltiutils::set_service_secret($cdom,$cnum,$marker,'grade',$now,
194: \%toolsettings,\%toolhash) eq 'ok') {
195: $toolhash{'gradesecret'} = $toolsettings{'gradesecret'};
196: } else {
197: undef($launchok);
198: }
199: }
200: if ($toolhash{'roster'}) {
201: if (&LONCAPA::ltiutils::set_service_secret($cdom,$cnum,$marker,'roster',$now,
202: \%toolsettings,\%toolhash) eq 'ok') {
203: $toolhash{'rostersecret'} = $toolsettings{'rostersecret'};
204: }
205: }
206: my $submittext = &mt('Launch [_1]',$toolhash{'title'});
207: if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') &&
208: ($toolhash{'url'} ne '') && ($launchok)) {
209: my %lti = <i_params($r,$cnum,$cdom,$idx,$submittext,\%toolhash);
210: my $url = $toolhash{'url'};
211: if ($toolhash{'crsappend'} ne '') {
212: $url .= $toolhash{'crsappend'};
213: }
214: $r->print(&launch_html($url,$toolhash{'key'},$toolhash{'secret'},
1.14 raeburn 215: $toolhash{'sigmethod'},$submittext,\%lti));
1.12 raeburn 216: } else {
217: $r->print('<div>'.&mt('External Tool Unavailable').'</div>');
218: }
1.1 raeburn 219: }
220: return OK;
221: }
222:
223: sub lti_params {
1.6 raeburn 224: my ($r,$cnum,$cdom,$idx,$submittext,$toolsref) = @_;
1.1 raeburn 225: my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,
1.6 raeburn 226: $crslabel,$crstitle,$gradesecret,$rostersecret,%fields,%rolesmap,
1.16 raeburn 227: %display,%custom,@userlangs,$incdom);
1.1 raeburn 228: if (ref($toolsref) eq 'HASH') {
229: $version = $toolsref->{'version'};
230: $toolname = $toolsref->{'title'};
231: $passback = $toolsref->{'passback'};
1.6 raeburn 232: $gradesecret = $toolsref->{'gradesecret'};
1.1 raeburn 233: $roster = $toolsref->{'roster'};
1.6 raeburn 234: $rostersecret = $toolsref->{'rostersecret'};
1.1 raeburn 235: $msgtype = $toolsref->{'messagetype'};
1.16 raeburn 236: $incdom = $toolsref->{'incdom'};
1.1 raeburn 237: if (ref($toolsref->{'fields'}) eq 'HASH') {
238: %fields = %{$toolsref->{'fields'}};
239: }
240: if (ref($toolsref->{'roles'}) eq 'HASH') {
241: %rolesmap = %{$toolsref->{'roles'}};
242: }
243: if (ref($toolsref->{'display'}) eq 'HASH') {
244: %display = %{$toolsref->{'display'}};
245: }
246: if (ref($toolsref->{'custom'}) eq 'HASH') {
247: %custom = %{$toolsref->{'custom'}};
248: }
1.4 raeburn 249: $crslabel = $toolsref->{'crslabel'};
250: $crstitle = $toolsref->{'crstitle'};
1.1 raeburn 251: }
252: if ($version eq '') {
253: $version = 'LTI-1p0';
254: }
255: if ($context_type eq '') {
256: $context_type = 'CourseSection';
257: }
258: if ($msgtype eq '') {
259: $msgtype = 'basic-lti-launch-request';
260: }
1.4 raeburn 261: if ($crslabel eq '') {
262: $crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
263: }
264: if ($crstitle eq '') {
265: $crstitle = $env{'course.'.$env{'request.course.id'}.'.description'},;
266: }
1.1 raeburn 267: my $lonhost = $r->dir_config('lonHostID');
268: my $loncaparev = $r->dir_config('lonVersion');
269: my $uname = $env{'user.name'};
270: my $udom = $env{'user.domain'};
271: my @possroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.3 raeburn 272: my ($roleprefix) = ($env{'request.role'} =~ /^(\w+)\./);
273: my $ltirole = $rolesmap{$roleprefix};
1.1 raeburn 274: unless (grep(/^\Q$ltirole\E$/,@possroles)) {
275: $ltirole = 'Learner';
276: }
1.17 raeburn 277: my @possdigest;
1.1 raeburn 278: my $digest_user = &Encode::decode_utf8($uname.':'.$udom);
279: $digest_user = &Digest::SHA::sha1_hex($digest_user);
1.17 raeburn 280: push(@possdigest,$digest_user);
1.1 raeburn 281: if ($env{'course.'.$env{'request.course.id'}.'.languages'} ne '') {
282: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
283: $env{'course.'.$env{'request.course.id'}.'.languages'}));
284: } else {
1.2 raeburn 285: my %langhash = &Apache::loncommon::getlangs($uname,$udom);
1.1 raeburn 286: if ($langhash{'languages'} ne '') {
287: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
288: } else {
289: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
290: if ($domdefs{'lang_def'} ne '') {
291: @userlangs = ($domdefs{'lang_def'});
292: }
293: }
294: }
295: if (scalar(@userlangs) == 1) {
296: $locale = $userlangs[0];
297: }
298: my ($title,$digest_symb);
299: my ($symb) = &Apache::lonnet::whichuser();
300: if ($symb) {
301: $digest_symb = &Encode::decode_utf8($symb);
302: $digest_symb = &Digest::SHA::sha1_hex($digest_symb);
1.17 raeburn 303: push(@possdigest,$digest_symb);
1.1 raeburn 304: my $navmap = Apache::lonnavmaps::navmap->new();
305: if (ref($navmap)) {
306: my $res = $navmap->getBySymb($symb);
307: if (ref($res)) {
308: $title = $res->compTitle();
309: }
310: }
311: }
1.4 raeburn 312: my $domdesc = &Apache::lonnet::domain($cdom);
313: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
314: my $int_dom = &Apache::lonnet::internet_dom($primary_id);
315: my $portal_url = &Apache::lonnet::course_portal_url($cnum,$cdom);
316:
1.1 raeburn 317: my %ltiparams = (
318: lti_version => $version,
319: lti_message_type => $msgtype,
320: resource_link_title => $title,
321: resource_link_id => $digest_symb,
322: tool_consumer_instance_guid => $lonhost,
1.4 raeburn 323: tool_consumer_instance_description => $domdesc,
1.1 raeburn 324: tool_consumer_info_product_family_code => 'loncapa',
1.4 raeburn 325: tool_consumer_instance_name => $int_dom,
326: tool_consumer_instance_url => $portal_url,
1.1 raeburn 327: tool_consumer_info_version => $loncaparev,
328: user_id => $digest_user,
329: roles => $ltirole,
330: context_id => $env{'request.course.id'},
331: context_type => $context_type,
1.4 raeburn 332: context_label => $crslabel,
333: context_title => $crstitle,
1.1 raeburn 334: launch_presentation_locale => $locale,
335: );
1.3 raeburn 336: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
337: my $crshostname = &Apache::lonnet::hostname($crshome);
1.1 raeburn 338: if ($crshostname) {
1.3 raeburn 339: my $crsprotocol = $Apache::lonnet::protocol{$crshome};
1.1 raeburn 340: unless ($crsprotocol eq 'https') {
341: $crsprotocol = 'http';
1.6 raeburn 342: }
343: if (($passback) || ($roster)) {
1.17 raeburn 344: my (%currdigest,%digesthash);
345: if (@possdigest) {
346: %currdigest = &Apache::lonnet::get('exttools',\@possdigest,
347: $cdom,$cnum);
348: }
1.6 raeburn 349: if ($passback) {
1.8 raeburn 350: $ltiparams{'lis_outcome_service_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/passback';
1.1 raeburn 351: $ltiparams{'ext_ims_lis_basic_outcome_url'} = $ltiparams{'lis_outcome_service_url'};
1.6 raeburn 352: if ($gradesecret) {
1.9 raeburn 353: my $uniqid = $digest_symb.':::'.$digest_user.':::'.$env{'request.course.id'};
1.10 raeburn 354: $ltiparams{'lis_result_sourcedid'} = &LONCAPA::ltiutils::get_service_id($gradesecret,$uniqid);
1.6 raeburn 355: }
356: }
357: if ($roster) {
358: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
1.8 raeburn 359: $ltiparams{'ext_ims_lis_memberships_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/roster';
1.6 raeburn 360: if ($rostersecret) {
1.9 raeburn 361: my $uniqid = $digest_symb.':::'.$env{'request.course.id'};
1.10 raeburn 362: $ltiparams{'ext_ims_lis_memberships_id'} = &LONCAPA::ltiutils::get_service_id($rostersecret,$uniqid);
1.6 raeburn 363: }
364: }
365: }
366: if (($digest_symb) && ($gradesecret || $rostersecret)) {
1.17 raeburn 367: unless ((exists($currdigest{$digest_symb})) && ($currdigest{$digest_symb} eq $symb)) {
368: $digesthash{$digest_symb} = $symb;
369: }
1.6 raeburn 370: }
371: if (($passback) && ($gradesecret)) {
1.17 raeburn 372: unless ((exists($currdigest{$digest_user})) && ($currdigest{$digest_user} eq $uname.':'.$udom)) {
373: $digesthash{$digest_user} = $uname.':'.$udom;
374: }
1.6 raeburn 375: }
376: if (keys(%digesthash)) {
377: &Apache::lonnet::put('exttools',\%digesthash,$cdom,$cnum);
1.1 raeburn 378: }
379: }
380: }
381: if ($display{'target'}) {
382: $ltiparams{'launch_presentation_document_target'} = $display{'target'};
383: }
384: if ($display{'width'}) {
385: $ltiparams{'launch_presentation_width'} = $display{'width'};
386: }
387: if ($display{'height'}) {
388: $ltiparams{'launch_presentation_height'} = $display{'height'};
389: }
390: if ($fields{'firstname'}) {
391: $ltiparams{'lis_person_name_given'} = $env{'environment.firstname'};
392: }
393: if ($fields{'lastname'}) {
394: $ltiparams{'lis_person_name_family'} = $env{'environment.lastname'};
395: }
396: if ($fields{'fullname'}) {
397: $ltiparams{'lis_person_name_full'} = &Apache::loncommon::plainname($uname,$udom);
398: }
399: if ($fields{'email'}) {
400: my %emails = &Apache::loncommon::getemails($uname,$udom);
401: my $contact_email;
1.3 raeburn 402: foreach my $type ('permanentemail','critnotification','notification') {
403: if ($emails{$type} =~ /\@/) {
404: $contact_email = $emails{$type};
1.1 raeburn 405: last;
406: }
407: }
1.2 raeburn 408: $ltiparams{'lis_person_contact_email_primary'} = $contact_email;
1.1 raeburn 409: }
1.4 raeburn 410: if ($fields{'user'}) {
1.16 raeburn 411: if ($incdom) {
412: $ltiparams{'lis_person_sourcedid'} = $uname.':'.$udom;
413: } else {
414: $ltiparams{'lis_person_sourcedid'} = $uname;
415: }
1.4 raeburn 416: }
1.1 raeburn 417: if (keys(%custom)) {
418: foreach my $key (keys(%custom)) {
1.5 raeburn 419: my $value = $custom{$key};
420: $value =~ s/^\s+|\s+\$//g;
421: if ($value =~ /^\QLONCAPA::env{\E([^\}]+)\}$/) {
422: if (exists($env{$1})) {
423: $value = $env{$1};
424: }
425: }
426: $ltiparams{'custom_'.$key} = $value;
1.1 raeburn 427: }
428: }
429: foreach my $key (keys(%ltiparams)) {
430: $ltiparams{$key} = &Encode::decode_utf8($ltiparams{$key});
431: }
1.3 raeburn 432: $ltiparams{'basiclti_submit'} = $submittext;
1.1 raeburn 433: return %ltiparams;
434: }
435:
436: sub launch_html {
1.14 raeburn 437: my ($url,$key,$secret,$sigmethod,$submittext,$paramsref) = @_;
438: my $hashref = &LONCAPA::ltiutils::sign_params($url,$key,$secret,$sigmethod,$paramsref);
1.5 raeburn 439: my $action = &HTML::Entities::encode($url,'<>&"');
1.1 raeburn 440: my $form = <<"END";
441: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
442: <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
443: <body>
444: <div id="LCltiLaunch">
1.5 raeburn 445: <form name="LCltiLaunchForm" id="LCltiLaunchFormId" action="$action" method="post" encType="application/x-www-form-urlencoded">
1.1 raeburn 446: END
447: if (ref($hashref) eq 'HASH') {
448: foreach my $item (keys(%{$hashref})) {
1.3 raeburn 449: my $type = 'hidden';
450: if ($item eq 'basiclti_submit') {
451: $type = 'submit';
452: }
453: $form .= '<input type="'.$type.'" name="'.$item.'" value="'.$hashref->{$item}.'" id="id_'.$item.'" />'."\n";
1.1 raeburn 454: }
455: }
456: $form .= "</form></div>\n";
457: $form .= <<"ENDJS";
458: <script type="text/javascript">
459: document.getElementById("LCltiLaunch").style.display = "none";
460: nei = document.createElement('input');
461: nei.setAttribute('type','hidden');
1.3 raeburn 462: nei.setAttribute('name','basiclti_submit');
1.1 raeburn 463: nei.setAttribute('value','$submittext');
1.3 raeburn 464: document.getElementById("LCltiLaunchFormId").appendChild(nei);
1.1 raeburn 465: document.LCltiLaunchForm.submit();
466: </script>
467: ENDJS
468: $form .= "</body></html>\n";
469: return $form;
470: }
471:
1.12 raeburn 472: sub gradabletool_access_check {
1.15 raeburn 473: my ($target) = @_;
1.12 raeburn 474: my ($result,$resource_due);
475: my $status;
476: my ($symb,$courseid,$udom,$uname) = &Apache::lonnet::whichuser();
477: my @targets;
1.15 raeburn 478: if ($target) {
479: @targets = ($target);
480: } elsif (defined($env{'form.submitted'}) && defined($env{'form.validate'})) {
1.12 raeburn 481: @targets = ('grade','web');
482: } else {
483: @targets = ('web');
484: }
485: foreach my $target (@targets) {
1.18 raeburn 486: &Apache::structuretags::initialize_storage($symb);
1.12 raeburn 487: &Apache::lonhomework::set_show_problem_status(&Apache::lonnet::EXT('resource.0.problemstatus'));
488: my ($accessmsg,$slot_name,$slot,$ipused);
489: ($status,$accessmsg,$slot_name,$slot,$ipused) =
490: &Apache::lonhomework::check_slot_access('0','tool',$symb);
491: if (( $status eq 'CLOSED' ) ||
492: ( $status eq 'UNCHECKEDOUT') ||
493: ( $status eq 'NOT_YET_VIEWED') ||
494: ( $status eq 'BANNED') ||
495: ( $status eq 'UNAVAILABLE') ||
496: ( $status eq 'NOT_IN_A_SLOT') ||
497: ( $status eq 'NOTRESERVABLE') ||
498: ( $status eq 'RESERVABLE') ||
499: ( $status eq 'RESERVABLE_LATER') ||
500: ( $status eq 'INVALID_ACCESS') ||
501: ( $status eq 'NEED_DIFFERENT_IP') ||
502: ( $status eq 'WAITING_FOR_GRADE')) {
503: $result = &Apache::structuretags::access_status_msg('tool',$status,$symb,
504: $target,$ipused,$accessmsg);
505: } elsif ($status eq 'NEEDS_CHECKIN') {
506: $result = &Apache::structuretags::checkin_prompt($target,$slot_name,$slot,'tool');
507: } elsif ($target eq 'web') {
508: if ($status eq 'CAN_ANSWER') {
509: $resource_due = &Apache::lonhomework::due_date(0, $env{'request.symb'});
510: if ($slot_name ne '') {
511: $resource_due = &Apache::structuretags::selfcheckin_resource($resource_due,
512: $slot_name,$slot,
513: $env{'request.symb'});
514: }
515: }
516: }
1.18 raeburn 517: if (keys(%Apache::lonhomework::results)) {
518: &Apache::structuretags::finalize_storage();
519: }
1.12 raeburn 520: }
521: return ($status,$result,$resource_due);
522: }
523:
524: sub display_score {
1.15 raeburn 525: my ($target) = @_;
1.12 raeburn 526: my $weight = &Apache::lonnet::EXT('resource.0.weight');
527: if ((!defined($weight)) || ($weight eq '')) { $weight=1; }
528: my $awarded = $Apache::lonhomework::history{'resource.0.awarded'};
529: if (!defined($awarded)) { $awarded=0; }
530: my $display='';
1.15 raeburn 531: if ($target eq 'tex') {
532: $display = '\\\\';
533: }
1.12 raeburn 534: if (!defined($awarded)) {
1.15 raeburn 535: $display .= &mt('[_1] possible points.',$weight);
1.12 raeburn 536: } else {
537: my $points = $awarded*$weight;
538: my $result = sprintf('%.2f',$points);
1.15 raeburn 539: $display .= &mt('You have [_1] out of [quant,_2,possible point]',
1.12 raeburn 540: $result,$weight);
541: }
542: my $comment = $Apache::lonhomework::history{'resource.0.comment'};
543: if (!defined($comment) || $comment!~/\w/) {
544: $comment='';
545: } else {
1.15 raeburn 546: if ($target eq 'tex') {
547: $comment = '\\\\'.$comment;
548: } else {
549: $comment='<br /><table><tr><td bgcolor="#FFFFDD">'.$comment.'</td></tr></table>';
550: }
1.12 raeburn 551: }
552: my $gradeinfo = $Apache::lonhomework::history{'resource.0.gradeinfo'};
553: if (!defined($gradeinfo) || $gradeinfo!~/\w/) {
554: $gradeinfo='';
555: } else {
1.15 raeburn 556: if ($target eq 'tex') {
557: $gradeinfo = '\\\\'.$gradeinfo;
558: } else {
559: $gradeinfo='<br /><table><tr><td bgcolor="#DDDDFF"><font size="+2">'.$gradeinfo.'</font></td></tr></table>';
560: }
1.12 raeburn 561: }
562: return $display.$comment.$gradeinfo;
563: }
564:
1.1 raeburn 565: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>