File:  [LON-CAPA] / loncom / interface / lonexttool.pm
Revision 1.19: download - view: text, annotated - select for diffs
Wed May 23 16:36:14 2018 UTC (6 years ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6754 LON-CAPA as LTI Consumer
  Domain configuration for information sent to Tool Provider on launch
  includes choice of: username, or username:domain in LON-CAPA,
  when "User" is included in the data to be sent (as lis_person_sourcedid).

    1: # The LearningOnline Network with CAPA
    2: # Launch External Tool Provider (LTI)
    3: #
    4: # $Id: lonexttool.pm,v 1.19 2018/05/23 16:36:14 raeburn Exp $
    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;
   52: use Apache::londatecheck;
   53: use Apache::lonipcheck;
   54: use Apache::lonhomework;
   55: use Apache::structuretags;
   56: use LONCAPA::ltiutils;
   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'}));
   69:     } else {
   70:         $target = 'web';
   71:     }
   72: 
   73: # Is this even in a course?
   74:     unless ($env{'request.course.id'}) {
   75:         if ($target ne 'tex') {
   76:             &Apache::loncommon::simple_error_page($r,'','Not in a course',
   77:                                                   {'only_body' => 1});
   78:         } else {
   79:             $r->print('\textbf{Not in a course}\end{document}');
   80:         }
   81:         return OK;
   82:     }
   83: 
   84:     my ($marker,$exttool) = (split(m{/},$r->uri))[4,5];
   85:     $marker=~s/\D//g;
   86: 
   87:     if (!$marker) {
   88:         if ($target ne 'tex') {
   89:             $r->print(&mt('Invalid Call'));
   90:         } else {
   91:             $r->print('\textbf{'&mt('Invalid Call').'}\end{document}');
   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'};
   99:     my ($idx,$is_tool,%toolhash,%toolsettings);
  100: 
  101:     if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") {
  102:         %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
  103:         if ($toolsettings{'id'}) {
  104:             $idx = $toolsettings{'id'};
  105:             my %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
  106:             if (ref($ltitools{$idx}) eq 'HASH') {
  107:                 %toolhash = %{$ltitools{$idx}};
  108:                 $toolhash{'display'} = {
  109:                                            target => $toolsettings{'target'},
  110:                                            width  => $toolsettings{'width'},
  111:                                            height => $toolsettings{'height'},
  112:                                        };
  113:                 foreach my $item (qw(crslabel crstitle crsappend gradable)) {
  114:                     $toolhash{$item} = $toolsettings{$item};
  115:                 }
  116:                 $is_tool = 1;
  117:             }
  118:         }
  119:     }
  120:     unless ($is_tool) {
  121:         if ($target ne 'tex') {
  122:             $r->print('<div>'.&mt('Invalid Call').'</div>');
  123:         } else {
  124:             $r->print('\textbf{'.&mt(Invalid Call).'}\end{document}');
  125:         }
  126:         return OK;
  127:     }
  128: 
  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:     }
  137:     if ($toolhash{'gradable'}) {
  138:         $Apache::lonhomework::browse = &Apache::lonnet::allowed('bre',$r->uri);
  139:         if ($env{'form.markaccess'}) {
  140:             my @interval=&Apache::lonnet::EXT('resource.0.interval',$symb);
  141:             my ($timelimit) = split(/_/,$interval[0]);
  142:             &Apache::lonnet::set_first_access($interval[1],$timelimit);
  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'});
  149:         }
  150:         ($status,$msg) = &gradabletool_access_check($target);
  151:         undef($Apache::lonhomework::browse);
  152:         if ($status eq 'SHOW_ANSWER') {
  153:             $r->print(&display_score($target));
  154:             if ($target eq 'tex') {
  155:                 $r->print('\end{document}');
  156:             }
  157:             return OK;
  158:         } elsif ($status ne 'CAN_ANSWER') {
  159:             if ($target eq 'tex') {
  160:                 $r->print('\end{document}');
  161:             } else {
  162:                 $r->print($msg);
  163:             }
  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') {
  170:                 $r->print(&mt('Not open to be viewed').'\end{document}');
  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') {
  179:                     $r->print(&mt('Not open to be viewed').'\end{document}');
  180:                 } else {
  181:                     $r->print($msg);
  182:                 }
  183:                 return OK;
  184:             }
  185:         }
  186:     }
  187:     my $launchok = 1;
  188:     if ($target eq 'tex') {
  189:         $r->print('\end{document}');
  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 = &lti_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'},
  215:                                    $toolhash{'sigmethod'},$submittext,\%lti));
  216:         } else {
  217:             $r->print('<div>'.&mt('External Tool Unavailable').'</div>');
  218:         }
  219:     }
  220:     return OK;
  221: }
  222: 
  223: sub lti_params {
  224:     my ($r,$cnum,$cdom,$idx,$submittext,$toolsref) = @_;
  225:     my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,
  226:         $crslabel,$crstitle,$gradesecret,$rostersecret,%fields,%rolesmap,
  227:         %display,%custom,@userlangs,$incdom);
  228:     if (ref($toolsref) eq 'HASH') {
  229:         $version = $toolsref->{'version'};
  230:         $toolname = $toolsref->{'title'};
  231:         $passback = $toolsref->{'passback'};
  232:         $gradesecret = $toolsref->{'gradesecret'};
  233:         $roster = $toolsref->{'roster'};
  234:         $rostersecret = $toolsref->{'rostersecret'};
  235:         $msgtype = $toolsref->{'messagetype'};
  236:         $incdom = $toolsref->{'incdom'};
  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:         }
  249:         $crslabel = $toolsref->{'crslabel'};
  250:         $crstitle = $toolsref->{'crstitle'};
  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:     }
  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:     }
  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);
  272:     my ($roleprefix) = ($env{'request.role'} =~ /^(\w+)\./);
  273:     my $ltirole = $rolesmap{$roleprefix};
  274:     unless (grep(/^\Q$ltirole\E$/,@possroles)) {
  275:         $ltirole = 'Learner';
  276:     }
  277:     my @possdigest;
  278:     my $digest_user = &Encode::decode_utf8($uname.':'.$udom);
  279:     $digest_user = &Digest::SHA::sha1_hex($digest_user);
  280:     push(@possdigest,$digest_user);
  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 {
  285:         my %langhash = &Apache::loncommon::getlangs($uname,$udom);
  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);
  303:         push(@possdigest,$digest_symb);
  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:     }
  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: 
  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,
  323:         tool_consumer_instance_description     => $domdesc,
  324:         tool_consumer_info_product_family_code => 'loncapa',
  325:         tool_consumer_instance_name            => $int_dom,  
  326:         tool_consumer_instance_url             => $portal_url,
  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,
  332:         context_label                          => $crslabel,
  333:         context_title                          => $crstitle,
  334:         launch_presentation_locale             => $locale,
  335:     );
  336:     my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
  337:     my $crshostname = &Apache::lonnet::hostname($crshome);
  338:     if ($crshostname) {
  339:         my $crsprotocol = $Apache::lonnet::protocol{$crshome};
  340:         unless ($crsprotocol eq 'https') {
  341:             $crsprotocol = 'http';
  342:         }
  343:         if (($passback) || ($roster)) {
  344:             my (%currdigest,%digesthash);
  345:             if (@possdigest) {
  346:                 %currdigest = &Apache::lonnet::get('exttools',\@possdigest,
  347:                                                    $cdom,$cnum);
  348:             }
  349:             if ($passback) {
  350:                 $ltiparams{'lis_outcome_service_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/passback';
  351:                 $ltiparams{'ext_ims_lis_basic_outcome_url'} = $ltiparams{'lis_outcome_service_url'};
  352:                 if ($gradesecret) {
  353:                     my $uniqid = $digest_symb.':::'.$digest_user.':::'.$env{'request.course.id'};
  354:                     $ltiparams{'lis_result_sourcedid'} = &LONCAPA::ltiutils::get_service_id($gradesecret,$uniqid); 
  355:                 }
  356:             }
  357:             if ($roster) {
  358:                 if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
  359:                     $ltiparams{'ext_ims_lis_memberships_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/roster';
  360:                     if ($rostersecret) {
  361:                         my $uniqid = $digest_symb.':::'.$env{'request.course.id'};
  362:                         $ltiparams{'ext_ims_lis_memberships_id'} = &LONCAPA::ltiutils::get_service_id($rostersecret,$uniqid);
  363:                     }
  364:                 }
  365:             }
  366:             if (($digest_symb) && ($gradesecret || $rostersecret)) {
  367:                 unless ((exists($currdigest{$digest_symb})) && ($currdigest{$digest_symb} eq $symb)) {
  368:                     $digesthash{$digest_symb} = $symb;
  369:                 }
  370:             }
  371:             if (($passback) && ($gradesecret)) {
  372:                 unless ((exists($currdigest{$digest_user})) && ($currdigest{$digest_user} eq $uname.':'.$udom)) {
  373:                     $digesthash{$digest_user} = $uname.':'.$udom;
  374:                 }
  375:             }
  376:             if (keys(%digesthash)) {
  377:                 &Apache::lonnet::put('exttools',\%digesthash,$cdom,$cnum);
  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;
  402:         foreach my $type ('permanentemail','critnotification','notification') {
  403:             if ($emails{$type} =~ /\@/) {
  404:                 $contact_email = $emails{$type};
  405:                 last;
  406:             }
  407:         }
  408:         $ltiparams{'lis_person_contact_email_primary'} = $contact_email;
  409:     }
  410:     if ($fields{'user'}) {
  411:         if ($incdom) {
  412:             $ltiparams{'lis_person_sourcedid'} = $uname.':'.$udom;
  413:         } else {
  414:             $ltiparams{'lis_person_sourcedid'} = $uname;
  415:         }
  416:     }
  417:     if (keys(%custom)) {
  418:         foreach my $key (keys(%custom)) {
  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;
  427:         }
  428:     }
  429:     foreach my $key (keys(%ltiparams)) {
  430:         $ltiparams{$key} = &Encode::decode_utf8($ltiparams{$key});
  431:     }
  432:     $ltiparams{'basiclti_submit'} = $submittext;
  433:     return %ltiparams;
  434: }
  435: 
  436: sub launch_html {
  437:     my ($url,$key,$secret,$sigmethod,$submittext,$paramsref) = @_;
  438:     my $hashref = &LONCAPA::ltiutils::sign_params($url,$key,$secret,$sigmethod,$paramsref);
  439:     my $action = &HTML::Entities::encode($url,'<>&"');
  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">
  445: <form name="LCltiLaunchForm" id="LCltiLaunchFormId" action="$action" method="post" encType="application/x-www-form-urlencoded">
  446: END
  447:     if (ref($hashref) eq 'HASH') {
  448:         foreach my $item (keys(%{$hashref})) {
  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";
  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');
  462:     nei.setAttribute('name','basiclti_submit');
  463:     nei.setAttribute('value','$submittext');
  464:     document.getElementById("LCltiLaunchFormId").appendChild(nei);
  465:     document.LCltiLaunchForm.submit();
  466:  </script>
  467: ENDJS
  468:     $form .= "</body></html>\n";
  469:     return $form;
  470: }
  471: 
  472: sub gradabletool_access_check {
  473:     my ($target) = @_;
  474:     my ($result,$resource_due);
  475:     my $status;
  476:     my ($symb,$courseid,$udom,$uname) = &Apache::lonnet::whichuser();
  477:     my @targets;
  478:     if ($target) {
  479:         @targets = ($target);
  480:     } elsif (defined($env{'form.submitted'}) && defined($env{'form.validate'})) {
  481:         @targets = ('grade','web');
  482:     } else {
  483:         @targets = ('web');
  484:     }
  485:     foreach my $target (@targets) {
  486:         &Apache::structuretags::initialize_storage($symb);
  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:         }
  517:         if (keys(%Apache::lonhomework::results)) {
  518:             &Apache::structuretags::finalize_storage();
  519:         }
  520:     }
  521:     return ($status,$result,$resource_due);
  522: }
  523: 
  524: sub display_score {
  525:     my ($target) = @_;
  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='';
  531:     if ($target eq 'tex') {
  532:         $display = '\\\\';
  533:     }
  534:     if (!defined($awarded)) {
  535:         $display .= &mt('[_1] possible points.',$weight);
  536:     } else {
  537:         my $points = $awarded*$weight;
  538:         my $result = sprintf('%.2f',$points);
  539:         $display .= &mt('You have [_1] out of [quant,_2,possible point]',
  540:                        $result,$weight);
  541:     }
  542:     my $comment = $Apache::lonhomework::history{'resource.0.comment'};
  543:     if (!defined($comment) || $comment!~/\w/) {
  544:         $comment='';
  545:     } else {
  546:         if ($target eq 'tex') {
  547:             $comment = '\\\\'.$comment;
  548:         } else {
  549:             $comment='<br /><table><tr><td bgcolor="#FFFFDD">'.$comment.'</td></tr></table>';
  550:         }
  551:     }
  552:     my $gradeinfo = $Apache::lonhomework::history{'resource.0.gradeinfo'};
  553:     if (!defined($gradeinfo) || $gradeinfo!~/\w/) {
  554:         $gradeinfo='';
  555:     } else {
  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:         }
  561:     }
  562:     return $display.$comment.$gradeinfo;
  563: }
  564: 
  565: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>