Diff for /loncom/lonmap.pm between versions 1.8 and 1.15

version 1.8, 2012/12/20 16:10:57 version 1.15, 2014/12/11 01:50:27
Line 157  sub merge_hash { Line 157  sub merge_hash {
  $key .= '.'; # If we are prefixing, prefix then .   $key .= '.'; # If we are prefixing, prefix then .
     }      }
   
     foreach my $childkey (keys (%$child)) {      foreach my $childkey (keys(%$child)) {
  $parent->{$key . $childkey} = $child->{$childkey};   $parent->{$key . $childkey} = $child->{$childkey};
     }      }
 }  }
Line 213  sub get_mapalias_errors { Line 213  sub get_mapalias_errors {
  $count++;   $count++;
      }       }
      my ($mapid) = split(/\./,$id);       my ($mapid) = split(/\./,$id);
      &mt('Resource "[_1]" <br /> in Map "[_2]"',       &mt('Resource [_1][_2]in Map [_3]',
  $hash->{'title_'.$id},   '"'.$hash->{'title_'.$id}.'"',
  $hash->{'title_'.$hash->{'ids_'.$hash->{'map_id_'.$mapid}}});                           '<br />',
    '"'.$hash->{'title_'.$hash->{'ids_'.$hash->{'map_id_'.$mapid}}}.'"');
  } (@{ $mapalias_cache{$mapalias} }));   } (@{ $mapalias_cache{$mapalias} }));
  next if ($count < 2);   next if ($count < 2);
  $error_text .= '<div class="LC_error">'.   $error_text .= '<div class="LC_error">'.
Line 278  sub process_versions { Line 279  sub process_versions {
  $cenv->{'domain'},   $cenv->{'domain'},
  $cenv->{'num'});   $cenv->{'num'});
   
     foreach my $ver (keys (%versions)) {      foreach my $ver (keys(%versions)) {
  if ($ver =~/^error\:/) { # lonc/lond transaction failed.   if ($ver =~/^error\:/) { # lonc/lond transaction failed.
     throw Error::Simple('lonc/lond returned error: ' . $ver);      throw Error::Simple('lonc/lond returned error: ' . $ver);
  }   }
Line 295  sub process_versions { Line 296  sub process_versions {
 #  #
 sub versionerror {  sub versionerror {
     my ($uri, $used, $unused) = @_;      my ($uri, $used, $unused) = @_;
     my ($uri,$usedversion,$unusedversion)=@_;  
     return '<br />'.      return '<br />'.
  &mt('Version discrepancy: resource [_1] included in both version [_2] and version [_3]. Using version [_2].',   &mt('Version discrepancy: resource [_1] included in both version [_2] and version [_3]. Using version [_2].',
     $uri,$used,$unused).'<br />';      $uri,$used,$unused).'<br />';
Line 410  sub hiddenurls { Line 410  sub hiddenurls {
     my $courseid = $hash->{'context.courseid'};      my $courseid = $hash->{'context.courseid'};
   
     my $randomoutentry='';      my $randomoutentry='';
     foreach my $rid (keys %randompick) {      foreach my $rid (keys(%randompick)) {
         my $rndpick=$randompick{$rid};          my $rndpick=$randompick{$rid};
         my $mpc=$hash->{'map_pc_'.$hash->{'src_'.$rid}};          my $mpc=$hash->{'map_pc_'.$hash->{'src_'.$rid}};
 # ------------------------------------------- put existing resources into array  # ------------------------------------------- put existing resources into array
Line 450  sub hiddenurls { Line 450  sub hiddenurls {
         }          }
     }      }
 # ------------------------------ take care of explicitly hidden urls or folders  # ------------------------------ take care of explicitly hidden urls or folders
     foreach my $rid (keys %hiddenurl) {      foreach my $rid (keys(%hiddenurl)) {
  $hash->{'randomout_'.$rid}='1';   $hash->{'randomout_'.$rid}='1';
  my ($mapid,$resid)=split(/\./,$rid);   my ($mapid,$resid)=split(/\./,$rid);
  $randomoutentry.='&'.   $randomoutentry.='&'.
Line 616  sub traceroute { Line 616  sub traceroute {
  my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},$resid,   my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},$resid,
       $hash->{'src_'.$rid});        $hash->{'src_'.$rid});
  my $hidden=&Apache::lonnet::EXT('resource.0.hiddenresource',$symb);   my $hidden=&Apache::lonnet::EXT('resource.0.hiddenresource',$symb);
           my $ignorehidden;
   
  if ($hdnflag || lc($hidden) eq 'yes') {   if ($hdnflag || lc($hidden) eq 'yes') {
     $hiddenurl{$rid}=1;              if (defined($hash->{'is_map_'.$rid})) {
                   if (($hash->{'context.nohideurl'}) && ($hash->{'context.nohideurl'} eq $hash->{'src_'.$rid})) {
                       $ignorehidden = 1; # Hidden parameter explicitly deleted 
                                          # if printing/grading bubblesheet exam
                   }
               }
               unless ($ignorehidden) {
           $hiddenurl{$rid}=1;
               }
  }   }
  if (!$hdnflag && lc($hidden) eq 'no') {   if (!$hdnflag && lc($hidden) eq 'no') {
     delete($hiddenurl{$rid});      delete($hiddenurl{$rid});
Line 648  sub traceroute { Line 657  sub traceroute {
   
  if (defined($hash->{'is_map_'.$rid})) {   if (defined($hash->{'is_map_'.$rid})) {
     if (defined($hash->{'map_start_'.$hash->{'src_'.$rid}})) {      if (defined($hash->{'map_start_'.$hash->{'src_'.$rid}})) {
                   my $maphidden;
                   unless ($ignorehidden) {
                       $maphidden = $hdnflag || $hiddenurl{$rid};
                   }
  $sofar=$newsofar=   $sofar=$newsofar=
     &traceroute($sofar,      &traceroute($sofar,
  $hash->{'map_start_'.$hash->{'src_'.$rid}},   $hash->{'map_start_'.$hash->{'src_'.$rid}},
  $beenhere,   $beenhere,
  $encflag || $encurl{$rid},   $encflag || $encurl{$rid},
  $hdnflag || $hiddenurl{$rid}, $hash);   $maphidden, $hash);
     }      }
  }   }
   
Line 673  sub traceroute { Line 686  sub traceroute {
  $further=simplify('('.'_'.$rid.')&('.   $further=simplify('('.'_'.$rid.')&('.
   $hash->{'condid_'.$hash->{'undercond_'.$id}}.')');    $hash->{'condid_'.$hash->{'undercond_'.$id}}.')');
     } else {      } else {
  my $errtext.=&mt('<br />Undefined condition ID: [_1]',$hash->{'undercond_'.$id});   my $errtext.='<br />'.&mt('Undefined condition ID: [_1]',$hash->{'undercond_'.$id});
  throw Error::Simple($errtext);   throw Error::Simple($errtext);
     }      }
                 }                  }
Line 783  sub parse_param { Line 796  sub parse_param {
     $hiddenurl{$referid}=1;      $hiddenurl{$referid}=1;
  }   }
     }      }
   
 }  }
   
   
Line 971  sub parse_resource { Line 983  sub parse_resource {
     if (($turi=~/\.sequence$/) ||      if (($turi=~/\.sequence$/) ||
  ($turi=~/\.page$/)) {   ($turi=~/\.page$/)) {
  $hash->{'is_map_'.$rid}='1'; # String in lonuserstate.   $hash->{'is_map_'.$rid}='1'; # String in lonuserstate.
           if ($hiddenurl{$rid}) {
               if (($hash->{'context.nohideurl'}) &&
                   ($hash->{'context.nohideurl'} eq $hash->{'src_'.$rid})) {
                   delete($hiddenurl{$rid}); # Hidden parameter explicitly deleted
                                             # if printing/grading bubblesheet exam  
               }
           }
   
  &read_map($turi,$rid,$code,$hash);   &read_map($turi,$rid,$code,$hash);
     }       } 
     return $token->[2]->{'id'};      return $token->[2]->{'id'};
Line 1237  sub read_map { Line 1257  sub read_map {
     my $ispage = ($filename =~/\.page$/);      my $ispage = ($filename =~/\.page$/);
     unless ($ispage || ($filename =~ /\.sequence$/)) {      unless ($ispage || ($filename =~ /\.sequence$/)) {
  &Apache::lonnet::logthis("invalid: $filename : $uri");   &Apache::lonnet::logthis("invalid: $filename : $uri");
  throw Error::Simple(&mt("<br />Invalid map: <tt>[_1]</tt>", $filename));   throw Error::Simple('<br />'.&mt('Invalid map: [_1]','<span class="LC_filename">'.$filename.'</span>'));
     }      }
   
     $filename =~ /\.(\w+)$/;      $filename =~ /\.(\w+)$/;
Line 1248  sub read_map { Line 1268  sub read_map {
         
     my $contents = &Apache::lonnet::getfile($filename);      my $contents = &Apache::lonnet::getfile($filename);
     if($contents eq -1) {      if($contents eq -1) {
         throw Error::Simple(&mt('<br />Map not loaded: The file <tt>[_1]</tt> does not exist.',          throw Error::Simple('<br />'.&mt('Map not loaded: The file [_1] does not exist.',
  $filename));   '<span class="LC_filename">'.$filename.'</span>'));
     }      }
     # Now that we succesfully retrieved the file we can make our parsing passes over it:      # Now that we succesfully retrieved the file we can make our parsing passes over it:
     # parsing is done in passes:      # parsing is done in passes:
Line 1400  sub read_map { Line 1420  sub read_map {
 #    $uname      - Name of the user for whom the course is being read  #    $uname      - Name of the user for whom the course is being read
 #    $udom       - Name of the domain of the user for whom the course is being read.  #    $udom       - Name of the domain of the user for whom the course is being read.
 #    $code       - CODE for which course is being read (CODEd assignments)  #    $code       - CODE for which course is being read (CODEd assignments)
   #    $nohideurl  - URL for an exam folder for which hidden state is to be ignored.
 #    $target_hash- Reference to the target hash into which all of this is read.  #    $target_hash- Reference to the target hash into which all of this is read.
 #                  Note tht some of the hash entries we need to build require knowledge of the  #                  Note tht some of the hash entries we need to build require knowledge of the
 #                  course URI.. these are expected to be filled in by the caller.  #                  course URI.. these are expected to be filled in by the caller.
Line 1408  sub read_map { Line 1429  sub read_map {
 #  #
 #    #  
 sub loadmap {  sub loadmap {
     my ($cnum, $cdom, $uname, $udom, $code, $target_hash) = @_;      my ($cnum, $cdom, $uname, $udom, $code, $nohideurl, $target_hash) = @_;
   
   
   
Line 1426  sub loadmap { Line 1447  sub loadmap {
     $userdomain     = '';      $userdomain     = '';
     %mapalias_cache = ();      %mapalias_cache = ();
     %cenv           = ();      %cenv           = ();
       $map_number     =  0;
           
     #       # 
   
Line 1446  sub loadmap { Line 1467  sub loadmap {
       {'freshen_cache' => 1,        {'freshen_cache' => 1,
        'user'          => $uname});          'user'          => $uname}); 
     
   unless ($cenv{'url'}) {     unless ($cenv{'url'}) {
      &Apache::lonnet::logthis("lonmap::loadmap failed: $cnum/$cdom - did not get url");       &Apache::lonnet::logthis("lonmap::loadmap failed: $cnum/$cdom - did not get url");
      return;        return; 
   }    }
Line 1478  sub loadmap { Line 1499  sub loadmap {
  $target_hash->{'context.username'} = $username;   $target_hash->{'context.username'} = $username;
  $target_hash->{'context.userdom'}  = $userdomain;   $target_hash->{'context.userdom'}  = $userdomain;
  $target_hash->{'context.courseid'} = $course_id;   $target_hash->{'context.courseid'} = $course_id;
    
           # When grading or printing a bubblesheet exam ignore
           # "hidden" parameter set in the map containing the exam folder.
           $target_hash->{'context.nohideurl'} = $nohideurl;
   
         &read_map($course_uri, '0.0', $code, $target_hash);          &read_map($course_uri, '0.0', $code, $target_hash);
   
  #   
   
  if (defined($target_hash->{'map_start_'.$map_uri})) {   if (defined($target_hash->{'map_start_'.$map_uri})) {
   
     &traceroute('0',$target_hash->{'map_start_'.$course_uri},'&', 0, 0, $target_hash);      &traceroute('0',$target_hash->{'map_start_'.$course_uri},'&', 0, 0, $target_hash);
Line 1532  sub loadmap { Line 1554  sub loadmap {
   
   
  &merge_hash($target_hash, 'randompick', \%randompick);   &merge_hash($target_hash, 'randompick', \%randompick);
  &merge_hash($target_hash, 'randompickseed', \%randompick);   &merge_hash($target_hash, 'randompickseed', \%randompickseed);
  &merge_hash($target_hash, 'randomorder', \%randomorder);   &merge_hash($target_hash, 'randomorder', \%randomorder);
  &merge_hash($target_hash, 'encurl', \%encurl);   &merge_hash($target_hash, 'encurl', \%encurl);
  &merge_hash($target_hash, 'hiddenurl', \%hiddenurl);   &merge_hash($target_hash, 'hiddenurl', \%hiddenurl);
Line 1562  Apache::lonmap - Construct a hash that r Line 1584  Apache::lonmap - Construct a hash that r
   
 =head1 SYNOPSIS  =head1 SYNOPSIS
   
 &Apache::lonmap::loadmap($filepath, \%target_hash);  &Apache::lonmap::loadmap($cnum, $cdom, $uname, $udom, $code, $nohideurl, \%target_hash);
   
 =head1 INTRODUCTION  =head1 INTRODUCTION
   
 This module reads a course filename into a hash reference.  It's up to the caller  This module reads a course filename into a hash reference.  It's up to the caller
 to to things like decide the has should be tied to some external file and handle the locking  to do things like decide that the hash should be tied to some external file and handle the
 if this file should be shared amongst several Apache children.  the locking if this file should be shared amongst several Apache children.
   
 =head1 SUBROUTINES  =head1 SUBROUTINES
   
 =over  =over
   
 =item loadmap($filepath, $targethash)  =item loadmap($cnum, $cdom, $uname, $udom, $code, $nohideurl, $targethash)
   
   
 Reads the map file into a target hash.  Reads the top-level map file into a target hash. This is done by first parsing the
   map file into local hashes and then unrolling those hashes into the big hash.
   
 =over  =over
   
 =item $filepath - The path to the map file to read.  =item $cnum - number of course being read.
   
   =item $cdom - domain in which the course is evaluated.
   
   =item $uname - name of the user for whom the course is being read.
   
   =item $udom  - name of the domain of the user for whom the course is being read.
   
   =item $code  - CODE for which course is being read (CODEd assignments).
   
   =item $nohideurl - URL for an exam folder for which hidden state is to be ignored.
   
 =item $targethash - A reference to hash into which the course is read.  =item $targethash - A reference to hash into which the course is read
   
 =back  =back
   

Removed from v.1.8  
changed lines
  Added in v.1.15


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