Diff for /rat/lonuserstate.pm between versions 1.56 and 1.62

version 1.56, 2003/03/17 18:07:09 version 1.62, 2003/10/22 16:52:14
Line 68  my $errtext; # variable with all errors Line 68  my $errtext; # variable with all errors
 my $retfurl; # variable with the very first URL in the course  my $retfurl; # variable with the very first URL in the course
 my %randompick; # randomly picked resources  my %randompick; # randomly picked resources
 my %randompickseed; # optional seed for randomly picking resources  my %randompickseed; # optional seed for randomly picking resources
 my %actualversion; # version of resource as loaded now  
 my %setversion; # forced version of resource  # ----------------------------------- Remove version from URL and store in hash
 my %lastversion; # version when CC came in last  
 my $versionmode; # how versioning is handled in this course  sub versiontrack {
       my $uri=shift;
       if ($uri=~/\.(\d+)\.\w+$/) {
    my $version=$1;
    $uri=~s/\.\d+\.(\w+)$/\.$1/;
           unless ($hash{'version_'.$uri}) {
       $hash{'version_'.$uri}=$version;
    }
       }
       return $uri;
   }
   
   # -------------------------------------------------------------- Put in version
   
   sub putinversion {
       my $uri=shift;
       if ($hash{'version_'.$uri}) {
    my $version=$hash{'version_'.$uri};
    if ($version eq 'current') { return $uri; }
    $uri=~s/\.(\w+)$/\.$version\.$1/;
       }
       return $uri;
   }
   
   # ----------------------------------------- Processing versions file for course
   
   sub processversionfile {
       my %cenv=shift;
       my %versions=&Apache::lonnet::dump('resourceversions',
          $cenv{'domain'},
          $cenv{'num'});
       foreach (keys %versions) {
    if ($_=~/^error\:/) { return; }
    $hash{'version_'.$_}=$versions{$_};
       }
   }
   
 # --------------------------------------------------------- Loads map from disk  # --------------------------------------------------------- Loads map from disk
   
Line 85  sub loadmap { Line 120  sub loadmap {
     $hash{'map_id_'.$lpc}=$uri;      $hash{'map_id_'.$lpc}=$uri;
   
 # Determine and check filename  # Determine and check filename
     my $fn=&Apache::lonnet::filelocation('',$uri);      my $fn=&Apache::lonnet::filelocation('',&putinversion($uri));
   
     my $ispage=($fn=~/\.page$/);      my $ispage=($fn=~/\.page$/);
   
Line 97  sub loadmap { Line 132  sub loadmap {
   
     my $instr=&Apache::lonnet::getfile($fn);      my $instr=&Apache::lonnet::getfile($fn);
   
     unless ($instr == -1) {      unless ($instr eq -1) {
   
 # Successfully got file, parse it  # Successfully got file, parse it
   
Line 119  sub loadmap { Line 154  sub loadmap {
   
                     $hash{'kind_'.$rid}='res';                      $hash{'kind_'.$rid}='res';
                     $hash{'title_'.$rid}=$token->[2]->{'title'};                      $hash{'title_'.$rid}=$token->[2]->{'title'};
                     my $turi=$token->[2]->{'src'};                      my $turi=&versiontrack($token->[2]->{'src'});
                     $Apache::lonnet::titlecache{                      if ($token->[2]->{'version'}) {
      &Apache::lonnet::symbclean(   unless ($hash{'version_'.$turi}) {
                       &Apache::lonnet::declutter($uri).'___'.      $hash{'version_'.$turi}=$1;
                       $token->[2]->{'id'}.'___'.   }
       &Apache::lonnet::declutter($turi))}=      }
                           $token->[2]->{'title'};      &Apache::lonnet::do_cache(\%Apache::lonnet::titlecache,
          &Apache::lonnet::symbclean(
                           &Apache::lonnet::declutter($uri).'___'.
                           $token->[2]->{'id'}.'___'.
           &Apache::lonnet::declutter($turi)),
         $token->[2]->{'title'});
                     unless ($ispage) {                      unless ($ispage) {
                         $turi=~/\.(\w+)$/;                          $turi=~/\.(\w+)$/;
                         my $embstyle=&Apache::loncommon::fileembstyle($1);                          my $embstyle=&Apache::loncommon::fileembstyle($1);
Line 443  sub pickrandom { Line 483  sub pickrandom {
  my (undef,$id)=split(/\./,$rid);   my (undef,$id)=split(/\./,$rid);
         if ($randompickseed{$rid}) { $id=$randompickseed{$rid}; }          if ($randompickseed{$rid}) { $id=$randompickseed{$rid}; }
  my $rndseed=&Apache::lonnet::rndseed($id); # use id instead of symb   my $rndseed=&Apache::lonnet::rndseed($id); # use id instead of symb
  &Math::Random::random_set_seed_from_phrase($rndseed);   &Apache::lonnet::setup_random_from_rndseed($rndseed);
  my @whichids=&Math::Random::random_permuted_index($#currentrids+1);   my @whichids=&Math::Random::random_permuted_index($#currentrids+1);
         for (my $i=1;$i<=$rndpick;$i++) { $currentrids[$whichids[$i]]=''; }          for (my $i=1;$i<=$rndpick;$i++) { $currentrids[$whichids[$i]]=''; }
  #&Apache::lonnet::logthis("$id,$rndseed,".join(':',@whichids));   #&Apache::lonnet::logthis("$id,$rndseed,".join(':',@whichids));
Line 493  sub readmap { Line 533  sub readmap {
     %parmhash=();      %parmhash=();
     $errtext='';      $errtext='';
     $pc=0;      $pc=0;
       &processversionfile(%cenv);
     my $furi=&Apache::lonnet::clutter($uri);      my $furi=&Apache::lonnet::clutter($uri);
     $hash{'src_0.0'}=$furi;      $hash{'src_0.0'}=&versiontrack($furi);
     $hash{'title_0.0'}=&Apache::lonnet::metadata($uri,'title');      $hash{'title_0.0'}=&Apache::lonnet::metadata($uri,'title');
     $hash{'ids_'.$furi}='0.0';      $hash{'ids_'.$furi}='0.0';
     $hash{'is_map_0.0'}=1;      $hash{'is_map_0.0'}=1;
Line 504  sub readmap { Line 545  sub readmap {
         &accinit($uri,$short,$fn);          &accinit($uri,$short,$fn);
         &pickrandom();          &pickrandom();
     }      }
 # ------------------------------------------------------------ Version tracking  # ------------------------------------------------------- Put versions into src
 #    if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {      foreach (keys %hash) {
 # &Apache::lonnet::logthis('Will be version tracking');   if ($_=~/^src\_/) {
 #    }      $hash{$_}=&putinversion($hash{$_});
    }
       }
     unless ((untie(%hash)) && (untie(%parmhash))) {      unless ((untie(%hash)) && (untie(%parmhash))) {
       &Apache::lonnet::logthis("<font color=blue>WARNING: ".        &Apache::lonnet::logthis("<font color=blue>WARNING: ".
                        "Could not untie coursemap $fn for $uri.</font>");                          "Could not untie coursemap $fn for $uri.</font>"); 

Removed from v.1.56  
changed lines
  Added in v.1.62


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