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