File:  [LON-CAPA] / loncom / interface / lonexttool.pm
Revision 1.25: download - view: text, annotated - select for diffs
Fri Jun 2 01:20:26 2023 UTC (11 months, 2 weeks ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- Bugs 6754 and 6907
  - Return of grades to launcher CMS supported for resources or folders
    accessed via LTI-mediated deep link.
  - Support option: "Encrypt stored consumer secrets defined in domain"
  - Signing of LTI payloads for roster retrieval, passback of grades,
    and callback to logput launcher CMS session all now occur on
    primary library server for course's domain.

    1: # The LearningOnline Network with CAPA
    2: # Launch External Tool Provider (LTI)
    3: #
    4: # $Id: lonexttool.pm,v 1.25 2023/06/02 01:20:26 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,$crstool,$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:             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:             }
  113:             if (ref($ltitools{$idx}) eq 'HASH') {
  114:                 %toolhash = %{$ltitools{$idx}};
  115:                 $toolhash{'display'} = {
  116:                                            target => $toolsettings{'target'},
  117:                                            width  => $toolsettings{'width'},
  118:                                            height => $toolsettings{'height'},
  119:                                        };
  120:                 foreach my $item (qw(crslabel crstitle crsappend gradable)) {
  121:                     $toolhash{$item} = $toolsettings{$item};
  122:                 }
  123:                 $is_tool = 1;
  124:             }
  125:         }
  126:     }
  127:     unless ($is_tool) {
  128:         if ($target ne 'tex') {
  129:             $r->print('<div>'.&mt('Invalid Call').'</div>');
  130:         } else {
  131:             $r->print('\textbf{'.&mt(Invalid Call).'}\end{document}');
  132:         }
  133:         return OK;
  134:     }
  135: 
  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:     }
  144:     if ($toolhash{'gradable'}) {
  145:         $Apache::lonhomework::browse = &Apache::lonnet::allowed('bre',$r->uri);
  146:         if ($env{'form.markaccess'}) {
  147:             my @interval=&Apache::lonnet::EXT('resource.0.interval',$symb);
  148:             my ($timelimit) = split(/_/,$interval[0]);
  149:             &Apache::lonnet::set_first_access($interval[1],$timelimit);
  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'});
  156:         }
  157:         ($status,$msg) = &gradabletool_access_check($target);
  158:         undef($Apache::lonhomework::browse);
  159:         if ($status eq 'SHOW_ANSWER') {
  160:             $r->print(&display_score($target));
  161:             if ($target eq 'tex') {
  162:                 $r->print('\end{document}');
  163:             }
  164:             return OK;
  165:         } elsif ($status ne 'CAN_ANSWER') {
  166:             if ($target eq 'tex') {
  167:                 $r->print('\end{document}');
  168:             } else {
  169:                 $r->print($msg);
  170:             }
  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') {
  177:                 $r->print(&mt('Not open to be viewed').'\end{document}');
  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') {
  186:                     $r->print(&mt('Not open to be viewed').'\end{document}');
  187:                 } else {
  188:                     $r->print($msg);
  189:                 }
  190:                 return OK;
  191:             }
  192:         }
  193:     }
  194:     my $launchok = 1;
  195:     if ($target eq 'tex') {
  196:         $r->print('\end{document}');
  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'});
  214:         if (($toolhash{'url'} ne '') && ($launchok)) {
  215:             my %lti = &lti_params($r,$cnum,$cdom,$idx,$submittext,\%toolhash);
  216:             my $url = $toolhash{'url'};
  217:             if ($toolhash{'crsappend'} ne '') {
  218:                 $url .= $toolhash{'crsappend'};
  219:             }
  220:             my %info = (
  221:                          method => $toolhash{'sigmethod'},
  222:                        );
  223:             $r->print(&launch_html($cdom,$cnum,$crstool,$url,$idx,
  224:                                    $toolhash{'cipher'},$submittext,\%lti,\%info));
  225:         } else {
  226:             $r->print('<div class="LC_warning">'.&mt('External Tool Unavailable').'</div>');
  227:         }
  228:     }
  229:     return OK;
  230: }
  231: 
  232: sub lti_params {
  233:     my ($r,$cnum,$cdom,$idx,$submittext,$toolsref) = @_;
  234:     my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,
  235:         $crslabel,$crstitle,$gradesecret,$rostersecret,%fields,%rolesmap,
  236:         %display,%custom,@userlangs,$incdom);
  237:     if (ref($toolsref) eq 'HASH') {
  238:         $version = $toolsref->{'version'};
  239:         $toolname = $toolsref->{'title'};
  240:         $passback = $toolsref->{'passback'};
  241:         $gradesecret = $toolsref->{'gradesecret'};
  242:         $roster = $toolsref->{'roster'};
  243:         $rostersecret = $toolsref->{'rostersecret'};
  244:         $msgtype = $toolsref->{'messagetype'};
  245:         $incdom = $toolsref->{'incdom'};
  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:         }
  258:         $crslabel = $toolsref->{'crslabel'};
  259:         $crstitle = $toolsref->{'crstitle'};
  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:     }
  270:     if ($crslabel eq '') {
  271:         $crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'};
  272:     }
  273:     if ($crstitle eq '') {
  274:         $crstitle = $env{'course.'.$env{'request.course.id'}.'.description'};
  275:     }
  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);
  281:     my ($roleprefix) = ($env{'request.role'} =~ /^(\w+)\./);
  282:     my $ltirole = $rolesmap{$roleprefix};
  283:     unless (grep(/^\Q$ltirole\E$/,@possroles)) {
  284:         $ltirole = 'Learner';
  285:     }
  286:     my @possdigest;
  287:     my $digest_user = &Encode::decode('UTF-8',$uname.':'.$udom);
  288:     $digest_user = &Digest::SHA::sha1_hex($digest_user);
  289:     push(@possdigest,$digest_user);
  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 {
  294:         my %langhash = &Apache::loncommon::getlangs($uname,$udom);
  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) {
  310:         $digest_symb = &Encode::decode('UTF-8',$symb);
  311:         $digest_symb = &Digest::SHA::sha1_hex($digest_symb);
  312:         push(@possdigest,$digest_symb);
  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:     }
  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);
  324:     my $portal_url = &Apache::lonnet::course_portal_url($cnum,$cdom,$r);
  325: 
  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,
  332:         tool_consumer_instance_description     => $domdesc,
  333:         tool_consumer_info_product_family_code => 'loncapa',
  334:         tool_consumer_instance_name            => $int_dom,
  335:         tool_consumer_instance_url             => $portal_url,
  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,
  341:         context_label                          => $crslabel,
  342:         context_title                          => $crstitle,
  343:         launch_presentation_locale             => $locale,
  344:     );
  345:     my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
  346:     my $crshostname = &Apache::lonnet::hostname($crshome);
  347:     if ($crshostname) {
  348:         my $crsprotocol = $Apache::lonnet::protocol{$crshome};
  349:         unless ($crsprotocol eq 'https') {
  350:             $crsprotocol = 'http';
  351:         }
  352:         if (($passback) || ($roster)) {
  353:             my (%currdigest,%digesthash);
  354:             if (@possdigest) {
  355:                 %currdigest = &Apache::lonnet::get('exttools',\@possdigest,
  356:                                                    $cdom,$cnum);
  357:             }
  358:             if ($passback) {
  359:                 $ltiparams{'lis_outcome_service_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/passback';
  360:                 $ltiparams{'ext_ims_lis_basic_outcome_url'} = $ltiparams{'lis_outcome_service_url'};
  361:                 if ($gradesecret) {
  362:                     my $uniqid = $digest_symb.':::'.$digest_user.':::'.$env{'request.course.id'};
  363:                     $ltiparams{'lis_result_sourcedid'} = &LONCAPA::ltiutils::get_service_id($gradesecret,$uniqid);
  364:                 }
  365:             }
  366:             if ($roster) {
  367:                 if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
  368:                     $ltiparams{'ext_ims_lis_memberships_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/roster';
  369:                     if ($rostersecret) {
  370:                         my $uniqid = $digest_symb.':::'.$env{'request.course.id'};
  371:                         $ltiparams{'ext_ims_lis_memberships_id'} = &LONCAPA::ltiutils::get_service_id($rostersecret,$uniqid);
  372:                     }
  373:                 }
  374:             }
  375:             if (($digest_symb) && ($gradesecret || $rostersecret)) {
  376:                 unless ((exists($currdigest{$digest_symb})) && ($currdigest{$digest_symb} eq $symb)) {
  377:                     $digesthash{$digest_symb} = $symb;
  378:                 }
  379:             }
  380:             if (($passback) && ($gradesecret)) {
  381:                 unless ((exists($currdigest{$digest_user})) && ($currdigest{$digest_user} eq $uname.':'.$udom)) {
  382:                     $digesthash{$digest_user} = $uname.':'.$udom;
  383:                 }
  384:             }
  385:             if (keys(%digesthash)) {
  386:                 &Apache::lonnet::put('exttools',\%digesthash,$cdom,$cnum);
  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;
  411:         foreach my $type ('permanentemail','critnotification','notification') {
  412:             if ($emails{$type} =~ /\@/) {
  413:                 $contact_email = $emails{$type};
  414:                 last;
  415:             }
  416:         }
  417:         $ltiparams{'lis_person_contact_email_primary'} = $contact_email;
  418:     }
  419:     if ($fields{'user'}) {
  420:         if ($incdom) {
  421:             $ltiparams{'lis_person_sourcedid'} = $uname.':'.$udom;
  422:         } else {
  423:             $ltiparams{'lis_person_sourcedid'} = $uname;
  424:         }
  425:     }
  426:     if (keys(%custom)) {
  427:         foreach my $key (keys(%custom)) {
  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;
  436:         }
  437:     }
  438:     foreach my $key (keys(%ltiparams)) {
  439:         $ltiparams{$key} = &Encode::decode('UTF-8',$ltiparams{$key});
  440:     }
  441:     $ltiparams{'basiclti_submit'} = $submittext;
  442:     return %ltiparams;
  443: }
  444: 
  445: sub launch_html {
  446:     my ($cdom,$cnum,$crstool,$url,$idx,$keynum,$submittext,$paramsref,$inforef) = @_;
  447:     my ($status,$hashref) =
  448:         &Apache::lonnet::sign_lti($cdom,$cnum,$crstool,'tools','launch',$url,$idx,$keynum,
  449:                                   $paramsref,$inforef);
  450:     unless ($status eq 'ok') {
  451:         return '<div class="LC_warning">'.&mt('External Tool Unavailable').'</div>';
  452:     }
  453:     my $action = &HTML::Entities::encode($url,'<>&"');
  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">
  459: <form name="LCltiLaunchForm" id="LCltiLaunchFormId" action="$action" method="post" encType="application/x-www-form-urlencoded">
  460: END
  461:     if (ref($hashref) eq 'HASH') {
  462:         foreach my $item (keys(%{$hashref})) {
  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";
  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');
  476:     nei.setAttribute('name','basiclti_submit');
  477:     nei.setAttribute('value','$submittext');
  478:     document.getElementById("LCltiLaunchFormId").appendChild(nei);
  479:     document.LCltiLaunchForm.submit();
  480:  </script>
  481: ENDJS
  482:     $form .= "</body></html>\n";
  483:     return $form;
  484: }
  485: 
  486: sub gradabletool_access_check {
  487:     my ($target) = @_;
  488:     my ($result,$resource_due);
  489:     my $status;
  490:     my ($symb,$courseid,$udom,$uname) = &Apache::lonnet::whichuser();
  491:     my @targets;
  492:     if ($target) {
  493:         @targets = ($target);
  494:     } elsif (defined($env{'form.submitted'}) && defined($env{'form.validate'})) {
  495:         @targets = ('grade','web');
  496:     } else {
  497:         @targets = ('web');
  498:     }
  499:     foreach my $target (@targets) {
  500:         &Apache::structuretags::initialize_storage($symb);
  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:         }
  531:         if (keys(%Apache::lonhomework::results)) {
  532:             &Apache::structuretags::finalize_storage();
  533:         }
  534:     }
  535:     return ($status,$result,$resource_due);
  536: }
  537: 
  538: sub display_score {
  539:     my ($target) = @_;
  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='';
  545:     if ($target eq 'tex') {
  546:         $display = '\\\\';
  547:     }
  548:     if (!defined($awarded)) {
  549:         $display .= &mt('[_1] possible points.',$weight);
  550:     } else {
  551:         my $points = $awarded*$weight;
  552:         my $result = sprintf('%.2f',$points);
  553:         $display .= &mt('You have [_1] out of [quant,_2,possible point]',
  554:                        $result,$weight);
  555:     }
  556:     my $comment = $Apache::lonhomework::history{'resource.0.comment'};
  557:     if (!defined($comment) || $comment!~/\w/) {
  558:         $comment='';
  559:     } else {
  560:         if ($target eq 'tex') {
  561:             $comment = '\\\\'.$comment;
  562:         } else {
  563:             $comment='<br /><table><tr><td bgcolor="#FFFFDD">'.$comment.'</td></tr></table>';
  564:         }
  565:     }
  566:     my $gradeinfo = $Apache::lonhomework::history{'resource.0.gradeinfo'};
  567:     if (!defined($gradeinfo) || $gradeinfo!~/\w/) {
  568:         $gradeinfo='';
  569:     } else {
  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:         }
  575:     }
  576:     return $display.$comment.$gradeinfo;
  577: }
  578: 
  579: 1;

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