Diff for /loncom/interface/lonexttool.pm between versions 1.6 and 1.23

version 1.6, 2017/11/30 02:17:50 version 1.23, 2022/03/29 20:12:46
Line 43  package Apache::lonexttool; Line 43  package Apache::lonexttool;
   
 use strict;  use strict;
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
 use Net::OAuth;  
 use Encode;  use Encode;
 use Digest::SHA;  use Digest::SHA;
 use UUID::Tiny ':std';  
 use HTML::Entities;  use HTML::Entities;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon;  use Apache::loncommon;
   use Apache::londatecheck;
   use Apache::lonipcheck;
   use Apache::lonhomework;
   use Apache::structuretags;
   use LONCAPA::ltiutils;
   
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
Line 63  sub handler { Line 66  sub handler {
 # ------------------------------------------------------------ Print the screen  # ------------------------------------------------------------ Print the screen
     if ($target eq 'tex') {      if ($target eq 'tex') {
         $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));          $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
       } else {
           $target = 'web';
     }      }
   
 # Is this even in a course?  # Is this even in a course?
     unless ($env{'request.course.id'}) {      unless ($env{'request.course.id'}) {
         if ($target ne 'tex') {          if ($target ne 'tex') {
             &Apache::loncommon::simple_error_page($r,'','Not in a course');              &Apache::loncommon::simple_error_page($r,'','Not in a course',
                                                     {'only_body' => 1});
         } else {          } else {
             $r->print('\textbf{Not in a course}\end{document}');              $r->print('\textbf{Not in a course}\end{document}');
         }          }
Line 90  sub handler { Line 96  sub handler {
     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};      my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};      my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
     my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};      my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
     my $is_tool;      my ($idx,$is_tool,%toolhash,%toolsettings);
   
     if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") {      if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") {
         my %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);          %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
         if ($toolsettings{'id'}) {          if ($toolsettings{'id'}) {
             my $idx = $toolsettings{'id'};              $idx = $toolsettings{'id'};
             my %ltitools = &Apache::lonnet::get_domain_ltitools($cdom);              my %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
             if (ref($ltitools{$idx}) eq 'HASH') {              if (ref($ltitools{$idx}) eq 'HASH') {
                 my %toolhash = %{$ltitools{$idx}};                   %toolhash = %{$ltitools{$idx}};
                 $toolhash{'display'} = {                  $toolhash{'display'} = {
                                            target => $toolsettings{'target'},                                             target => $toolsettings{'target'},
                                            width  => $toolsettings{'width'},                                             width  => $toolsettings{'width'},
                                            height => $toolsettings{'height'},                                             height => $toolsettings{'height'},
                                        };                                         };
                 $toolhash{'crslabel'} = $toolsettings{'crslabel'};                  foreach my $item (qw(crslabel crstitle crsappend gradable)) {
                 $toolhash{'crstitle'} = $toolsettings{'crstitle'};                      $toolhash{$item} = $toolsettings{$item};
                 $toolhash{'crsappend'} = $toolsettings{'crsappend'};  
                 $is_tool = 1;  
                 my $launchok = 1;  
                 if ($target eq 'tex') {  
                     $r->print(&mt('External Tool'));  
                 } else {  
                     my $now = time;  
                     if ($toolhash{'passback'}) {  
                         unless (&set_callback_secret($cdom,$cnum,$marker,'grade',$now,  
                                                      \%toolsettings,\%toolhash) eq 'ok') {  
                             undef($launchok);  
                         }  
                     }  
                     if ($toolhash{'roster'}) {  
                         &set_callback_secret($cdom,$cnum,$marker,'roster',$now,  
                                              \%toolsettings,\%toolhash);  
                     }  
                     my $submittext = &mt('Launch [_1]',$toolhash{'title'});  
                     if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') &&   
                         ($toolhash{'url'} ne '') && ($launchok)) {  
                         my %lti = &lti_params($r,$cnum,$cdom,$idx,$submittext,\%toolhash);  
                         my $url = $toolhash{'url'};  
                         if ($toolhash{'crsappend'} ne '') {  
                             $url .= $toolhash{'crsappend'};  
                         }  
                         $r->print(&launch_html($url,$toolhash{'key'},$toolhash{'secret'},  
                                                $submittext,\%lti));  
                     } else {  
                         $r->print('<div>'.&mt('External Tool Unavailable').'</div>');  
                     }  
                 }                  }
                   $is_tool = 1;
             }              }
         }          }
     }      }
Line 146  sub handler { Line 123  sub handler {
         } else {          } else {
             $r->print('\textbf{'.&mt(Invalid Call).'}\end{document}');              $r->print('\textbf{'.&mt(Invalid Call).'}\end{document}');
         }          }
           return OK;
     }      }
     return OK;  
 }  
   
 sub set_callback_secret {      my ($symb,$status,$open,$close,$msg,$donebuttonresult,$donemsg);
     my ($cdom,$cnum,$marker,$name,$now,$toolsettings,$toolhash) = @_;      if (($target eq 'tex') || ($toolhash{'gradable'})) {
     return unless ((ref($toolsettings) eq 'HASH') && (ref($toolhash) eq 'HASH'));          ($symb) = &Apache::lonnet::whichuser();
     my $warning;      }
     my ($needsnew,$oldsecret,$lifetime);      if ($target eq 'tex') {
     if ($name eq 'grade') {            my $title = &Apache::lonnet::gettitle($symb);
         $lifetime = $toolhash->{'passbackvalid'}          $r->print(&mt('External Tool: [_1]','\textit{'.$title.'}').'\\\\');
     } elsif ($name eq 'roster') {      }
         $lifetime = $toolhash->{'rostervalid'};      if ($toolhash{'gradable'}) {
     }            $Apache::lonhomework::browse = &Apache::lonnet::allowed('bre',$r->uri);
     if ($toolsettings->{$name} eq '') {          if ($env{'form.markaccess'}) {
         $needsnew = 1;              my @interval=&Apache::lonnet::EXT('resource.0.interval',$symb);
     } elsif (($toolsettings->{$name.'date'} + $lifetime) < $now) {              my ($timelimit) = split(/_/,$interval[0]);
         $oldsecret = $toolsettings->{$name.'secret'};              &Apache::lonnet::set_first_access($interval[1],$timelimit);
         $needsnew = 1;          } elsif ($symb && $env{'form.LC_interval_done'} eq 'true') {
     }              # Set the event timer to zero if the "done button" was clicked.  The button is
     if ($needsnew) {              # part of the doneButton form created in lonmenu.pm
         if (&get_tool_lock($cdom,$cnum,$marker,$now) eq 'ok') {              ($donebuttonresult,$donemsg) = &Apache::lonhomework::zero_timer($symb);
             my $secret = UUID::Tiny::create_uuid_as_string(UUID_V4);              undef($env{'form.LC_interval_done'});
             $toolhash->{$name.'secret'} = $secret;              undef($env{'form.LC_interval_done_proctorpass'});
             my %secrethash = (          }
                            $name.'secret' => $secret,          ($status,$msg) = &gradabletool_access_check($target);
                            $name.'secretdate' => $now,          undef($Apache::lonhomework::browse);
                           );          if ($status eq 'SHOW_ANSWER') {
             if ($oldsecret ne '') {              $r->print(&display_score($target));
                 $secrethash{'old'.$name.'secret'} = $oldsecret;              if ($target eq 'tex') {
             }                  $r->print('\end{document}');
             my $putres = &Apache::lonnet::put('exttool_'.$marker,              }
                                               \%secrethash,$cdom,$cnum);              return OK;
             my $delresult = &release_tool_lock($cdom,$cnum,$marker);          } elsif ($status ne 'CAN_ANSWER') {
             if ($delresult ne 'ok') {              if ($target eq 'tex') {
                 $warning = $delresult ;                  $r->print('\end{document}');
               } else {
                   $r->print($msg);
             }              }
             if ($putres eq 'ok') {              return OK;
                 return 'ok';          }
       } else {
           my ($status,$open,$close,$msg)=&Apache::londatecheck::content_date_check();
           if ($status ne 'OPEN') {
               if ($target eq 'tex') {
                   $r->print(&mt('Not open to be viewed').'\end{document}');
               } else {
                   $r->print($msg);
             }              }
               return OK;
         } else {          } else {
             $warning = '<span class="LC_error">'.              ($status,$msg)=&Apache::lonipcheck::ip_access_check();
                        &mt('Could not obtain exclusive lock').              if ($status ne 'OPEN') {
                        '</span>';                  if ($target eq 'tex') {
                       $r->print(&mt('Not open to be viewed').'\end{document}');
                   } else {
                       $r->print($msg);
                   }
                   return OK;
               }
         }          }
       }
       my $launchok = 1;
       if ($target eq 'tex') {
           $r->print('\end{document}');
     } else {      } else {
         $toolhash->{$name.'secret'} = $toolsettings->{$name.'secret'};          my $now = time;
         return 'ok';          if ($toolhash{'passback'}) {
               if (&LONCAPA::ltiutils::set_service_secret($cdom,$cnum,$marker,'grade',$now,
                                                          \%toolsettings,\%toolhash) eq 'ok') {
                   $toolhash{'gradesecret'} = $toolsettings{'gradesecret'};
               } else {
                   undef($launchok);
               }
           }
           if ($toolhash{'roster'}) {
               if (&LONCAPA::ltiutils::set_service_secret($cdom,$cnum,$marker,'roster',$now,
                                                          \%toolsettings,\%toolhash) eq 'ok') {
                   $toolhash{'rostersecret'} = $toolsettings{'rostersecret'};
               }
           }
           my $submittext = &mt('Launch [_1]',$toolhash{'title'});
           if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') && 
               ($toolhash{'url'} ne '') && ($launchok)) {
               my %lti = &lti_params($r,$cnum,$cdom,$idx,$submittext,\%toolhash);
               my $url = $toolhash{'url'};
               if ($toolhash{'crsappend'} ne '') {
                   $url .= $toolhash{'crsappend'};
               }
               $r->print(&launch_html($url,$toolhash{'key'},$toolhash{'secret'},
                                      $toolhash{'sigmethod'},$submittext,\%lti));
           } else {
               $r->print('<div>'.&mt('External Tool Unavailable').'</div>');
           }
     }      }
     return;      return OK;
 }  }
   
 sub lti_params {  sub lti_params {
     my ($r,$cnum,$cdom,$idx,$submittext,$toolsref) = @_;      my ($r,$cnum,$cdom,$idx,$submittext,$toolsref) = @_;
     my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,      my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale,
         $crslabel,$crstitle,$gradesecret,$rostersecret,%fields,%rolesmap,          $crslabel,$crstitle,$gradesecret,$rostersecret,%fields,%rolesmap,
         %display,%custom,@userlangs);          %display,%custom,@userlangs,$incdom);
     if (ref($toolsref) eq 'HASH') {      if (ref($toolsref) eq 'HASH') {
         $version = $toolsref->{'version'};          $version = $toolsref->{'version'};
         $toolname = $toolsref->{'title'};          $toolname = $toolsref->{'title'};
Line 211  sub lti_params { Line 233  sub lti_params {
         $roster = $toolsref->{'roster'};          $roster = $toolsref->{'roster'};
         $rostersecret = $toolsref->{'rostersecret'};          $rostersecret = $toolsref->{'rostersecret'};
         $msgtype = $toolsref->{'messagetype'};          $msgtype = $toolsref->{'messagetype'};
           $incdom = $toolsref->{'incdom'};
         if (ref($toolsref->{'fields'}) eq 'HASH') {          if (ref($toolsref->{'fields'}) eq 'HASH') {
             %fields = %{$toolsref->{'fields'}};              %fields = %{$toolsref->{'fields'}};
         }          }
Line 236  sub lti_params { Line 259  sub lti_params {
         $msgtype = 'basic-lti-launch-request';          $msgtype = 'basic-lti-launch-request';
     }      }
     if ($crslabel eq '') {      if ($crslabel eq '') {
         $crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},          $crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'};
     }      }
     if ($crstitle eq '') {      if ($crstitle eq '') {
         $crstitle = $env{'course.'.$env{'request.course.id'}.'.description'},;          $crstitle = $env{'course.'.$env{'request.course.id'}.'.description'};
     }      }
     my $lonhost = $r->dir_config('lonHostID');      my $lonhost = $r->dir_config('lonHostID');
     my $loncaparev = $r->dir_config('lonVersion');      my $loncaparev = $r->dir_config('lonVersion');
Line 251  sub lti_params { Line 274  sub lti_params {
     unless (grep(/^\Q$ltirole\E$/,@possroles)) {      unless (grep(/^\Q$ltirole\E$/,@possroles)) {
         $ltirole = 'Learner';          $ltirole = 'Learner';
     }      }
     my $digest_user = &Encode::decode_utf8($uname.':'.$udom);      my @possdigest;
       my $digest_user = &Encode::decode('UTF-8',$uname.':'.$udom);
     $digest_user = &Digest::SHA::sha1_hex($digest_user);      $digest_user = &Digest::SHA::sha1_hex($digest_user);
       push(@possdigest,$digest_user);
     if ($env{'course.'.$env{'request.course.id'}.'.languages'} ne '') {      if ($env{'course.'.$env{'request.course.id'}.'.languages'} ne '') {
         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,          @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                     $env{'course.'.$env{'request.course.id'}.'.languages'}));                      $env{'course.'.$env{'request.course.id'}.'.languages'}));
Line 273  sub lti_params { Line 298  sub lti_params {
     my ($title,$digest_symb);      my ($title,$digest_symb);
     my ($symb) = &Apache::lonnet::whichuser();      my ($symb) = &Apache::lonnet::whichuser();
     if ($symb) {      if ($symb) {
         $digest_symb = &Encode::decode_utf8($symb);          $digest_symb = &Encode::decode('UTF-8',$symb);
         $digest_symb = &Digest::SHA::sha1_hex($digest_symb);          $digest_symb = &Digest::SHA::sha1_hex($digest_symb);
           push(@possdigest,$digest_symb);
         my $navmap = Apache::lonnavmaps::navmap->new();          my $navmap = Apache::lonnavmaps::navmap->new();
         if (ref($navmap)) {          if (ref($navmap)) {
             my $res = $navmap->getBySymb($symb);              my $res = $navmap->getBySymb($symb);
Line 286  sub lti_params { Line 312  sub lti_params {
     my $domdesc = &Apache::lonnet::domain($cdom);      my $domdesc = &Apache::lonnet::domain($cdom);
     my $primary_id = &Apache::lonnet::domain($cdom,'primary');      my $primary_id = &Apache::lonnet::domain($cdom,'primary');
     my $int_dom = &Apache::lonnet::internet_dom($primary_id);      my $int_dom = &Apache::lonnet::internet_dom($primary_id);
     my $portal_url = &Apache::lonnet::course_portal_url($cnum,$cdom);      my $portal_url = &Apache::lonnet::course_portal_url($cnum,$cdom,$r);
   
     my %ltiparams = (      my %ltiparams = (
         lti_version                            => $version,          lti_version                            => $version,
Line 296  sub lti_params { Line 322  sub lti_params {
         tool_consumer_instance_guid            => $lonhost,          tool_consumer_instance_guid            => $lonhost,
         tool_consumer_instance_description     => $domdesc,          tool_consumer_instance_description     => $domdesc,
         tool_consumer_info_product_family_code => 'loncapa',          tool_consumer_info_product_family_code => 'loncapa',
         tool_consumer_instance_name            => $int_dom,            tool_consumer_instance_name            => $int_dom,
         tool_consumer_instance_url             => $portal_url,          tool_consumer_instance_url             => $portal_url,
         tool_consumer_info_version             => $loncaparev,          tool_consumer_info_version             => $loncaparev,
         user_id                                => $digest_user,          user_id                                => $digest_user,
Line 315  sub lti_params { Line 341  sub lti_params {
             $crsprotocol = 'http';              $crsprotocol = 'http';
         }          }
         if (($passback) || ($roster)) {          if (($passback) || ($roster)) {
               my (%currdigest,%digesthash);
               if (@possdigest) {
                   %currdigest = &Apache::lonnet::get('exttools',\@possdigest,
                                                      $cdom,$cnum);
               }
             if ($passback) {              if ($passback) {
                 $ltiparams{'lis_outcome_service_url'} = $crsprotocol.'//'.$crshostname.'/adm/service/passback';                  $ltiparams{'lis_outcome_service_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/passback';
                 $ltiparams{'ext_ims_lis_basic_outcome_url'} = $ltiparams{'lis_outcome_service_url'};                  $ltiparams{'ext_ims_lis_basic_outcome_url'} = $ltiparams{'lis_outcome_service_url'};
                 if ($gradesecret) {                  if ($gradesecret) {
                     my $result_sig =                       my $uniqid = $digest_symb.':::'.$digest_user.':::'.$env{'request.course.id'};
                         Digest::SHA::sha1_hex($gradesecret.':::'.$digest_symb.':::'.$digest_user.':::'.$env{'request.course.id'});                      $ltiparams{'lis_result_sourcedid'} = &LONCAPA::ltiutils::get_service_id($gradesecret,$uniqid);
                     $ltiparams{'lis_result_sourcedid'} =  
                         $result_sig.':::'.$digest_symb.':::'.$digest_user.':::'.$env{'request.course.id'};  
                 }                  }
             }              }
             if ($roster) {              if ($roster) {
                 if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {                  if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
                     $ltiparams{'ext_ims_lis_memberships_url'} = $crsprotocol.'//'.$crshostname.'/adm/service/roster';                      $ltiparams{'ext_ims_lis_memberships_url'} = $crsprotocol.'://'.$crshostname.'/adm/service/roster';
                     if ($rostersecret) {                      if ($rostersecret) {
                         my $roster_sig = Digest::SHA::sha1_hex($gradesecret.':::'.$digest_symb.':::'.$env{'request.course.id'});                          my $uniqid = $digest_symb.':::'.$env{'request.course.id'};
                         $ltiparams{'ext_ims_lis_memberships_id'} = $roster_sig.':::'.$digest_symb.':::'.$env{'request.course.id'};                          $ltiparams{'ext_ims_lis_memberships_id'} = &LONCAPA::ltiutils::get_service_id($rostersecret,$uniqid);
                     }                      }
                 }                  }
             }              }
             my %digesthash;  
             if ($ltiparams{'lis_result_sourcedid'}) {  
                 $digesthash{$ltiparams{'lis_result_sourcedid'}} = "$idx\0".time;   
             }  
             if ($ltiparams{'ext_ims_lis_memberships_id'}) {  
                 $digesthash{$ltiparams{'ext_ims_lis_memberships_id'}} = "$idx\0".time;   
             }  
             if (($digest_symb) && ($gradesecret || $rostersecret)) {              if (($digest_symb) && ($gradesecret || $rostersecret)) {
                 $digesthash{$digest_symb} = $symb;                  unless ((exists($currdigest{$digest_symb})) && ($currdigest{$digest_symb} eq $symb)) {
                       $digesthash{$digest_symb} = $symb;
                   }
             }              }
             if (($passback) && ($gradesecret)) {              if (($passback) && ($gradesecret)) {
                 $digesthash{$digest_user} = $uname.':'.$udom;                  unless ((exists($currdigest{$digest_user})) && ($currdigest{$digest_user} eq $uname.':'.$udom)) {
                       $digesthash{$digest_user} = $uname.':'.$udom;
                   }
             }              }
             if (keys(%digesthash)) {              if (keys(%digesthash)) {
                 &Apache::lonnet::put('exttools',\%digesthash,$cdom,$cnum);                  &Apache::lonnet::put('exttools',\%digesthash,$cdom,$cnum);
Line 382  sub lti_params { Line 408  sub lti_params {
         $ltiparams{'lis_person_contact_email_primary'} = $contact_email;          $ltiparams{'lis_person_contact_email_primary'} = $contact_email;
     }      }
     if ($fields{'user'}) {      if ($fields{'user'}) {
         $ltiparams{'lis_person_sourcedid'} = $uname.':'.$udom;          if ($incdom) {
               $ltiparams{'lis_person_sourcedid'} = $uname.':'.$udom;
           } else {
               $ltiparams{'lis_person_sourcedid'} = $uname;
           }
     }      }
     if (keys(%custom)) {      if (keys(%custom)) {
         foreach my $key (keys(%custom)) {          foreach my $key (keys(%custom)) {
Line 397  sub lti_params { Line 427  sub lti_params {
         }          }
     }      }
     foreach my $key (keys(%ltiparams)) {      foreach my $key (keys(%ltiparams)) {
         $ltiparams{$key} = &Encode::decode_utf8($ltiparams{$key});          $ltiparams{$key} = &Encode::decode('UTF-8',$ltiparams{$key});
     }      }
     $ltiparams{'basiclti_submit'} = $submittext;      $ltiparams{'basiclti_submit'} = $submittext;
     return %ltiparams;      return %ltiparams;
 }  }
   
 sub launch_html {  sub launch_html {
     my ($url,$key,$secret,$submittext,$paramsref) = @_;      my ($url,$key,$secret,$sigmethod,$submittext,$paramsref) = @_;
     my $hashref = &sign_params($url,$key,$secret,$paramsref);      my $hashref = &LONCAPA::ltiutils::sign_params($url,$key,$secret,$paramsref,$sigmethod);
     my $action = &HTML::Entities::encode($url,'<>&"');      my $action = &HTML::Entities::encode($url,'<>&"');
     my $form = <<"END";      my $form = <<"END";
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Line 439  ENDJS Line 469  ENDJS
     return $form;      return $form;
 }  }
   
 sub sign_params {  sub gradabletool_access_check {
     my ($url,$key,$secret,$paramsref) = @_;      my ($target) = @_;
     my $nonce = Digest::SHA::sha1_hex(sprintf("%06x%06x",rand(0xfffff0),rand(0xfffff0)));      my ($result,$resource_due);
       my $status;
     my $request = Net::OAuth->request("request token")->new(      my ($symb,$courseid,$udom,$uname) = &Apache::lonnet::whichuser();
             consumer_key => $key,      my @targets;
             consumer_secret => $secret,      if ($target) {
             request_url => $url,          @targets = ($target);
             request_method => 'POST',      } elsif (defined($env{'form.submitted'}) && defined($env{'form.validate'})) {
             signature_method => 'HMAC-SHA1',          @targets = ('grade','web');
             timestamp => time,      } else {
             nonce => $nonce,          @targets = ('web');
             callback => 'about:blank',  
             extra_params => $paramsref,  
             version      => '1.0',  
             );  
     $request->sign;  
     return $request->to_hash();  
 }  
   
 sub get_tool_lock {  
     my ($cdom,$cnum,$marker,$now) = @_;  
     # get lock for tool for which gradesecret is being set  
     my $lockhash = {  
                   $marker."\0".'lock' => $now.':'.$env{'user.name'}.  
                                          ':'.$env{'user.domain'},  
                    };  
     my $tries = 0;  
     my $gotlock = &Apache::lonnet::newput('exttools',$lockhash,$cdom,$cnum);  
   
     while (($gotlock ne 'ok') && $tries <3) {  
         $tries ++;  
         sleep(1);  
         $gotlock = &Apache::lonnet::newput('exttools',$lockhash,$cdom,$cnum);  
     }      }
     return $gotlock;      foreach my $target (@targets) {
           &Apache::structuretags::initialize_storage($symb);
           &Apache::lonhomework::set_show_problem_status(&Apache::lonnet::EXT('resource.0.problemstatus'));
           my ($accessmsg,$slot_name,$slot,$ipused);
           ($status,$accessmsg,$slot_name,$slot,$ipused) =
               &Apache::lonhomework::check_slot_access('0','tool',$symb);
           if (( $status eq 'CLOSED' ) ||
               ( $status eq 'UNCHECKEDOUT') ||
               ( $status eq 'NOT_YET_VIEWED') ||
               ( $status eq 'BANNED') ||
               ( $status eq 'UNAVAILABLE') ||
               ( $status eq 'NOT_IN_A_SLOT') ||
               ( $status eq 'NOTRESERVABLE') ||
               ( $status eq 'RESERVABLE') ||
               ( $status eq 'RESERVABLE_LATER') ||
               ( $status eq 'INVALID_ACCESS') ||
               ( $status eq 'NEED_DIFFERENT_IP') ||
               ( $status eq 'WAITING_FOR_GRADE')) {
               $result = &Apache::structuretags::access_status_msg('tool',$status,$symb,
                                                                   $target,$ipused,$accessmsg);
           } elsif ($status eq 'NEEDS_CHECKIN') {
               $result = &Apache::structuretags::checkin_prompt($target,$slot_name,$slot,'tool');
           } elsif ($target eq 'web') {
               if ($status eq 'CAN_ANSWER') {
                   $resource_due = &Apache::lonhomework::due_date(0, $env{'request.symb'});
                   if ($slot_name ne '') {
                       $resource_due = &Apache::structuretags::selfcheckin_resource($resource_due,
                                                                                    $slot_name,$slot,
                                                                                    $env{'request.symb'});
                   }
               }
           }
           if (keys(%Apache::lonhomework::results)) {
               &Apache::structuretags::finalize_storage();
           }
       }
       return ($status,$result,$resource_due);
 }  }
   
 sub release_tool_lock {  sub display_score {
     my ($cdom,$cnum,$marker) = @_;      my ($target) = @_;
     #  remove lock      my $weight = &Apache::lonnet::EXT('resource.0.weight');
     my @del_lock = ($marker."\0".'lock');      if ((!defined($weight)) || ($weight eq '')) { $weight=1; }
     my $dellockoutcome=&Apache::lonnet::del('exttools',\@del_lock,$cdom,$cnum);      my $awarded = $Apache::lonhomework::history{'resource.0.awarded'};
     if ($dellockoutcome ne 'ok') {      if (!defined($awarded)) { $awarded=0; }
         return ('<div class="LC_error">'      my $display='';
                .&mt('Warning: failed to release lock for exttool: [_1].','<tt>'.$marker.'</tt>')      if ($target eq 'tex') {
                .'</div>'          $display = '\\\\';
                );      }
       if (!defined($awarded)) {
           $display .= &mt('[_1] possible points.',$weight);
       } else {
           my $points = $awarded*$weight;
           my $result = sprintf('%.2f',$points);
           $display .= &mt('You have [_1] out of [quant,_2,possible point]',
                          $result,$weight);
       }
       my $comment = $Apache::lonhomework::history{'resource.0.comment'};
       if (!defined($comment) || $comment!~/\w/) {
           $comment='';
     } else {      } else {
         return 'ok';          if ($target eq 'tex') {
               $comment = '\\\\'.$comment;
           } else {
               $comment='<br /><table><tr><td bgcolor="#FFFFDD">'.$comment.'</td></tr></table>';
           }
       }
       my $gradeinfo = $Apache::lonhomework::history{'resource.0.gradeinfo'};
       if (!defined($gradeinfo) || $gradeinfo!~/\w/) {
           $gradeinfo='';
       } else {
           if ($target eq 'tex') {
               $gradeinfo = '\\\\'.$gradeinfo;
           } else {
               $gradeinfo='<br /><table><tr><td bgcolor="#DDDDFF"><font size="+2">'.$gradeinfo.'</font></td></tr></table>';
           }
     }      }
       return $display.$comment.$gradeinfo;
 }  }
   
 1;  1;

Removed from v.1.6  
changed lines
  Added in v.1.23


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