Diff for /loncom/interface/lonparmset.pm between versions 1.375 and 1.376

version 1.375, 2007/08/07 23:56:34 version 1.376, 2007/08/20 22:31:59
Line 67  use Apache::longroup; Line 67  use Apache::longroup;
 use Apache::lonrss;  use Apache::lonrss;
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
   
 # --- Caches local to lonparmset  
   
 my $parmhashid;  
 my %parmhash;  
 my $symbsid;  
 my %symbs;  
 my $rulesid;  
 my %rules;  
   
 # --- end local caches  
   
 ##################################################  ##################################################
 ##################################################  ##################################################
Line 119  sub parmval { Line 109  sub parmval {
   
 sub parmval_by_symb {  sub parmval_by_symb {
     my ($what,$symb,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;      my ($what,$symb,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
 # load caches  
     &cacheparmhash();  
   
     my $useropt;      my $useropt;
     if ($uname ne '' && $udom ne '') {      if ($uname ne '' && $udom ne '') {
Line 167  sub parmval_by_symb { Line 155  sub parmval_by_symb {
   
 # ------------------------------------------------------ third, check map parms  # ------------------------------------------------------ third, check map parms
   
     my $thisparm=$parmhash{$symbparm};      my $thisparm=&parmhash($symbparm);
     if (defined($thisparm)) { $outpar[11]=$thisparm; $result=11; }      if (defined($thisparm)) { $outpar[11]=$thisparm; $result=11; }
   
     if (defined($$courseopt{$courselevelr})) {      if (defined($$courseopt{$courselevelr})) {
Line 228  sub parmval_by_symb { Line 216  sub parmval_by_symb {
     return ($result,@outpar);      return ($result,@outpar);
 }  }
   
 sub resetparmhash {  
     $parmhashid='';  
 }  
   
 sub cacheparmhash {  
     if ($parmhashid eq  $env{'request.course.fn'}) { return; }  
     my %parmhashfile;  
     if (tie(%parmhashfile,'GDBM_File',  
       $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {  
  %parmhash=%parmhashfile;  
  untie %parmhashfile;  
  $parmhashid=$env{'request.course.fn'};  
     }  
 }  
   
 sub resetsymbcache {  # --- Caches local to lonparmset
     $symbsid='';  
       
   sub reset_caches {
       &resetparmhash();
       &resetsymbcache();
       &resetrulescache();
 }  }
   
 sub symbcache {  {
     my $id=shift;      my $parmhashid;
     if ($symbsid ne $env{'request.course.id'}) {      my %parmhash;
  %symbs=();      sub resetparmhash {
    undef($parmhashid);
    undef(%parmhash);
     }      }
     unless ($symbs{$id}) {      
  my $navmap = Apache::lonnavmaps::navmap->new();      sub cacheparmhash {
  if ($id=~/\./) {   if ($parmhashid eq  $env{'request.course.fn'}) { return; }
     my $resource=$navmap->getById($id);   my %parmhashfile;
     $symbs{$id}=$resource->symb();   if (tie(%parmhashfile,'GDBM_File',
  } else {   $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
     my $resource=$navmap->getByMapPc($id);      %parmhash=%parmhashfile;
     $symbs{$id}=&Apache::lonnet::declutter($resource->src());      untie(%parmhashfile);
       $parmhashid=$env{'request.course.fn'};
  }   }
  $symbsid=$env{'request.course.id'};  
     }      }
     return $symbs{$id};   
 }      sub parmhash {
    my ($id) = @_;
 sub resetrulescache {   &cacheparmhash();
     $rulesid='';   return $parmhash{$id};
 }      }
    }
   
   {   
       my $symbsid;
       my %symbs;
       sub resetsymbcache {
    undef($symbsid);
    undef(%symbs);
       }
       
       sub symbcache {
    my $id=shift;
    if ($symbsid ne $env{'request.course.id'}) {
       undef(%symbs);
    }
    if (!$symbs{$id}) {
       my $navmap = Apache::lonnavmaps::navmap->new();
       if ($id=~/\./) {
    my $resource=$navmap->getById($id);
    $symbs{$id}=$resource->symb();
       } else {
    my $resource=$navmap->getByMapPc($id);
    $symbs{$id}=&Apache::lonnet::declutter($resource->src());
       }
       $symbsid=$env{'request.course.id'};
    }
    return $symbs{$id};
       }
    }
   
 sub rulescache {  {   
     my $id=shift;      my $rulesid;
     if ($rulesid ne $env{'request.course.id'}      my %rules;
  && !defined($rules{$id})) {      sub resetrulescache {
  my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};   undef($rulesid);
  my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};   undef(%rules);
  %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);      }
  $rulesid=$env{'request.course.id'};      
       sub rulescache {
    my $id=shift;
    if ($rulesid ne $env{'request.course.id'}
       && !defined($rules{$id})) {
       my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
       my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
       %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
       $rulesid=$env{'request.course.id'};
    }
    return $rules{$id};
     }      }
     return $rules{$id};  
 }  }
   
 sub preset_defaults {  sub preset_defaults {
Line 345  sub storeparm { Line 365  sub storeparm {
 # - new type  # - new type
 # - username  # - username
 # - userdomain  # - userdomain
   
 my %recstack;  my %recstack;
 sub storeparm_by_symb {  sub storeparm_by_symb {
     my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag,$cgroup)=@_;      my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag,$cgroup)=@_;
Line 2990  sub parse_key { Line 3009  sub parse_key {
  $data{'realm_type'} = 'folder';   $data{'realm_type'} = 'folder';
  $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});   $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
  ($data{'realm_exists'}) = &Apache::lonnet::is_on_map($data{'realm'});   ($data{'realm_exists'}) = &Apache::lonnet::is_on_map($data{'realm'});
  &Apache::lonnet::logthis($1." siad ". $data{'realm_exists'} );  
     } elsif ($middle) {      } elsif ($middle) {
  $data{'realm'} = $middle;   $data{'realm'} = $middle;
  $data{'realm_type'} = 'symb';   $data{'realm_type'} = 'symb';
Line 3953  sub check_for_course_info { Line 3971  sub check_for_course_info {
 Main handler.  Calls &assessparms and &crsenv subroutines.  Main handler.  Calls &assessparms and &crsenv subroutines.
   
 =cut  =cut
   
 ##################################################  ##################################################
 ##################################################  ##################################################
 #    use Data::Dumper;  
   
   
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
   
       &reset_caches();
   
     if ($r->header_only) {      if ($r->header_only) {
  &Apache::loncommon::content_type($r,'text/html');   &Apache::loncommon::content_type($r,'text/html');
  $r->send_http_header;   $r->send_http_header;
Line 3995  sub handler { Line 4014  sub handler {
         $r->send_http_header;          $r->send_http_header;
   
   
         # id numbers can change on re-ordering of folders  
   
         &resetsymbcache();  
   
         #          #
         # Main switch on form.action and form.state, as appropriate          # Main switch on form.action and form.state, as appropriate
         #          #
Line 4067  sub handler { Line 4082  sub handler {
  }   }
  return HTTP_NOT_ACCEPTABLE;   return HTTP_NOT_ACCEPTABLE;
     }      }
       &reset_caches();
   
     return OK;      return OK;
 }  }
   

Removed from v.1.375  
changed lines
  Added in v.1.376


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