Diff for /loncom/homework/lonhomework.pm between versions 1.344.2.10.4.1 and 1.344.2.10.4.2

version 1.344.2.10.4.1, 2023/07/05 16:51:49 version 1.344.2.10.4.2, 2023/07/05 16:58:52
Line 51  use Apache::functionplotresponse(); Line 51  use Apache::functionplotresponse();
 use Apache::drawimage();  use Apache::drawimage();
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::loncommon();  use Apache::loncommon();
   use Apache::lonparmset();
   use Apache::lonnavmaps();
 use Apache::lonlocal;  use Apache::lonlocal;
   use LONCAPA qw(:DEFAULT :match);
   use LONCAPA::ltiutils();
 use Time::HiRes qw( gettimeofday tv_interval );  use Time::HiRes qw( gettimeofday tv_interval );
 use HTML::Entities();  use HTML::Entities();
 use File::Copy();  use File::Copy();
   
 # FIXME - improve commenting  # FIXME - improve commenting
   
   my $registered_cleanup;
   
 BEGIN {  BEGIN {
     &Apache::lonxml::register_insert();      &Apache::lonxml::register_insert();
Line 188  sub proctor_checked_in { Line 193  sub proctor_checked_in {
     if ($type eq 'Task') {      if ($type eq 'Task') {
  my $version=$Apache::lonhomework::history{'resource.0.version'};   my $version=$Apache::lonhomework::history{'resource.0.version'};
  $key ="resource.$version.0.checkedin";   $key ="resource.$version.0.checkedin";
     } elsif ($type eq 'problem') {      } elsif (($type eq 'problem') || ($type eq 'tool')) {
  $key ='resource.0.checkedin';   $key ='resource.0.checkedin';
     }      }
     # backward compatability, used to be username@domain,       # backward compatability, used to be username@domain, 
Line 203  sub proctor_checked_in { Line 208  sub proctor_checked_in {
     return 1;      return 1;
  }   }
     }      }
       
     return 0;      return 0;
 }  }
   
Line 212  sub check_slot_access { Line 216  sub check_slot_access {
   
     # does it pass normal muster      # does it pass normal muster
     my ($status,$datemsg)=&check_access($id,$symb);      my ($status,$datemsg)=&check_access($id,$symb);
       
     my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);      my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
     if ($useslots ne 'resource' && $useslots ne 'map'       if ($useslots ne 'resource' && $useslots ne 'map' 
  && $useslots ne 'map_map') {   && $useslots ne 'map_map') {
Line 292  sub check_slot_access { Line 296  sub check_slot_access {
      || $Apache::lonhomework::history{"resource.0.solved"} =~ /^correct_/ );       || $Apache::lonhomework::history{"resource.0.solved"} =~ /^correct_/ );
  $checkedin =   $checkedin =
     $Apache::lonhomework::history{"resource.$version.0.checkedin"};      $Apache::lonhomework::history{"resource.$version.0.checkedin"};
     } elsif ($type eq 'problem') {      } elsif (($type eq 'problem') || ($type eq 'tool')) {
         $checkin = 'resource.0.checkedin';          $checkin = 'resource.0.checkedin';
  $checkedin  = $Apache::lonhomework::history{$checkin};   $checkedin  = $Apache::lonhomework::history{$checkin};
     }      }
Line 301  sub check_slot_access { Line 305  sub check_slot_access {
         my %slot=&Apache::lonnet::get_slot($checkinslot);          my %slot=&Apache::lonnet::get_slot($checkinslot);
         $consumed_uniq = $slot{'uniqueperiod'};          $consumed_uniq = $slot{'uniqueperiod'};
     }      }
     if ($type eq 'problem') {      if (($type eq 'problem') || ($type eq 'tool')) {
         if ((ref($partlist) eq 'ARRAY') && (@{$partlist} > 0)) {          if ((ref($partlist) eq 'ARRAY') && (@{$partlist} > 0)) {
             my ($numcorrect,$numgraded) = (0,0);              my ($numcorrect,$numgraded) = (0,0);
             foreach my $part (@{$partlist}) {              foreach my $part (@{$partlist}) {
Line 360  sub check_slot_access { Line 364  sub check_slot_access {
     # However, the problem is not closed, and potentially, another slot might be      # However, the problem is not closed, and potentially, another slot might be
     # used to gain access to it to work on it, until the due date is reached, and the      # used to gain access to it to work on it, until the due date is reached, and the
     # problem then becomes CLOSED.  Therefore return the slotstatus -       # problem then becomes CLOSED.  Therefore return the slotstatus - 
     # (which will be one of: NOT_IN_A_SLOT, RESERVABLE, RESERVABLE_LATER, or NOTRESERVABLE.      # (which will be one of: NOT_IN_A_SLOT, RESERVABLE, RESERVABLE_LATER, or NOTRESERVABLE).
     if (!defined($slot_name) && $type eq 'problem') {  
       if (!defined($slot_name) && (($type eq 'problem') || ($type eq 'tool'))) {
         if ($slotstatus eq 'NOT_IN_A_SLOT') {          if ($slotstatus eq 'NOT_IN_A_SLOT') {
             if (!$num_usable_slots) {              if (!$num_usable_slots) {
                 if ($env{'request.course.id'}) {                  if ($env{'request.course.id'}) {
Line 445  sub check_slot_access { Line 450  sub check_slot_access {
     }      }
   
     if ( $is_correct) {      if ( $is_correct) {
  if ($type eq 'problem') {   if (($type eq 'problem') || ($type eq 'tool')) {
     return ($status);      return ($status);
  }   }
  return ('SHOW_ANSWER');   return ('SHOW_ANSWER');
Line 1062  sub editxmlmode { Line 1067  sub editxmlmode {
   
  $problem='';   $problem='';
     }      }
   
     if (($env{'form.problemmode'} eq 'saveeditxml') ||      if (($env{'form.problemmode'} eq 'saveeditxml') ||
         ($env{'form.problemmode'} eq 'saveviewxml') ||           ($env{'form.problemmode'} eq 'saveviewxml') ||
         ($env{'form.problemmode'} eq 'undoxml')) {          ($env{'form.problemmode'} eq 'undoxml')) {
  my $error=&handle_save_or_undo($request,\$problem,   my $error=&handle_save_or_undo($request,\$problem,
        \$env{'form.editxmltext'});         \$env{'form.editxmltext'});
Line 1283  sub finished_parsing { Line 1287  sub finished_parsing {
     undef($Apache::lonhomework::parsing_a_task);      undef($Apache::lonhomework::parsing_a_task);
 }  }
   
   
 # function extracted from get_template_html  # function extracted from get_template_html
 # returns "key" -> list  # returns "key" -> list
 # key: path of template  # key: path of template
Line 1547  sub handler { Line 1550  sub handler {
     my $file=&Apache::lonnet::filelocation("",$request->uri);      my $file=&Apache::lonnet::filelocation("",$request->uri);
   
     #check if we know where we are      #check if we know where we are
     if ($env{'request.course.fn'} && !&Apache::lonnet::symbread('','',1,1)) {       if ($env{'request.course.fn'} && !&Apache::lonnet::symbread('','',1,1)) {
  # if we are browsing we might not be able to know where we are   # if we are browsing we might not be able to know where we are
  if ($Apache::lonhomework::browse ne 'F' &&    if ($Apache::lonhomework::browse ne 'F' &&
     $env{'request.state'} ne "construct") {      $env{'request.state'} ne "construct") {
     #should know where we are, so ask      #should know where we are, so ask
     &unset_permissions();      &unset_permissions();
Line 1561  sub handler { Line 1564  sub handler {
  &unset_permissions();   &unset_permissions();
  return OK;   return OK;
     }      }
   
     &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:$Apache::lonhomework::modifygrades:$Apache::lonhomework::queuegrade");      &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:$Apache::lonhomework::modifygrades:$Apache::lonhomework::queuegrade");
     &Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'});      &Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'});
     my ($symb) = &Apache::lonnet::whichuser();      my ($symb) = &Apache::lonnet::whichuser();
Line 1601  sub handler { Line 1605  sub handler {
         }          }
  # just render the page normally outside of construction space   # just render the page normally outside of construction space
  &Apache::lonxml::debug("not construct");   &Apache::lonxml::debug("not construct");
           undef(@Apache::lonhomework::ltipassback);
  &renderpage($request,$file,undef,undef,$donemsg);   &renderpage($request,$file,undef,undef,$donemsg);
           if (@Apache::lonhomework::ltipassback) {
               unless ($registered_cleanup) {
                   my $handlers = $request->get_handlers('PerlCleanupHandler');
                   $request->set_handlers('PerlCleanupHandler' =>
                                          [\&do_ltipassback,@{$handlers}]);
               }
           }
     }      }
     #my $td=&tv_interval($t0);      #my $td=&tv_interval($t0);
     #&Apache::lonxml::debug("Spent $td seconds processing");      #&Apache::lonxml::debug("Spent $td seconds processing");
Line 1786  sub convert_for_js { Line 1798  sub convert_for_js {
     return $return;      return $return;
 }  }
   
   sub do_ltipassback {
       if (@Apache::lonhomework::ltipassback) {
           foreach my $item (@Apache::lonhomework::ltipassback) {
               if (ref($item) eq 'HASH') {
                   if ((ref($item->{'lti'}) eq 'HASH') && ($item->{'cid'} =~ /^($match_domain)_($match_courseid)$/)) {
                       my ($cdom,$cnum) = ($1,$2);
                       my $msgformat = $item->{'lti'}->{'passbackformat'};
                       my $sigmethod = 'HMAC-SHA1';
                       my $ltinum = $item->{'ltinum'};
                       my $id = $item->{'pbid'};
                       my $url = $item->{'pburl'};
                       my $type = $item->{'pbtype'};
                       my $scope = $item->{'scope'};
                       my $map = $item->{'ltimap'};
                       my $symb = $item->{'ltisymb'};
                       my $uname = $item->{'uname'};
                       my $udom = $item->{'udom'};
                       my $keynum = $item->{'lti'}->{'cipher'};
                       my $crsdef = $item->{'crsdef'};
                       my $scoretype = $item->{'format'};
                       my ($total,$possible);
                       if ($scope eq 'resource') {
                           $total = $item->{'total'};
                           $possible = $item->{'possible'};
                       } elsif ($scope eq 'map') {
                           ($total,$possible) = &get_lti_score($uname,$udom,$map);
                       } elsif ($scope eq 'course') {
                           ($total,$possible) = &get_lti_score($uname,$udom);
                       }
                       if (($id ne '') && ($url ne '') && ($possible)) {
                           &LONCAPA::ltiutils::send_grade($cdom,$cnum,$crsdef,$type,$ltinum,$keynum,$id,$url,$scoretype,$sigmethod,$msgformat,$total,$possible);
                       }
                   }
               }
           }
           undef(@Apache::lonhomework::ltipassback);
       }
   }
   
   sub get_lti_score {
       my ($uname,$udom,$mapurl) = @_;
       my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom);
       if (ref($navmap)) {
           my $iterator;
           if ($mapurl ne '') {
               my $map = $navmap->getResourceByUrl($mapurl);
               my $firstres = $map->map_start();
               my $finishres = $map->map_finish();
               $iterator = $navmap->getIterator($firstres,$finishres,undef,1);
           } else {
               $iterator = $navmap->getIterator(undef,undef,undef,1);
           }
           if (ref($iterator)) {
               my $depth = 1;
               my $total = 0;
               my $possible = 0;
               $iterator->next(); # ignore first BEGIN_MAP
               my $curRes = $iterator->next();
               while ( $depth > 0 ) {
                   if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
                   if ($curRes == $iterator->END_MAP()) { $depth--; }
                   if (ref($curRes) && $curRes->is_gradable() && !$curRes->randomout) {
                       my $parts = $curRes->parts();
                       foreach my $part (@{$parts}) {
                           next if ($curRes->solved($part) eq 'excused');
                           $total += $curRes->weight($part) * $curRes->awarded($part);
                           $possible += $curRes->weight($part);
                       }
                   }
                   $curRes = $iterator->next();
               }
               if ($total > $possible) {
                   $total = $possible;
               }
               return ($total,$possible);
           }
       }
       return;
   }
   
 1;  1;
 __END__  __END__

Removed from v.1.344.2.10.4.1  
changed lines
  Added in v.1.344.2.10.4.2


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