Diff for /loncom/interface/lonparmset.pm between versions 1.195 and 1.200

version 1.195, 2005/05/30 17:58:51 version 1.200, 2005/06/02 16:35:32
Line 62  use GDBM_File; Line 62  use GDBM_File;
 use Apache::lonhomework;  use Apache::lonhomework;
 use Apache::lonxml;  use Apache::lonxml;
 use Apache::lonlocal;  use Apache::lonlocal;
   use Apache::lonnavmaps;
   
 my %courseopt;  # --- Caches local to lonparmset
 my %useropt;  
   my $parmhashid;
 my %parmhash;  my %parmhash;
   
   # --- end local caches
   
   #
   # FIXME: get rid of items below
   #
 my @ids;  my @ids;
 my %symbp;  my %symbp;
 my %mapp;  my %mapp;
 my %typep;  my %typep;
 my %keyp;  my %keyp;
   my %uris;
 my %maptitles;  my %maptitles;
   
 ##################################################  ##################################################
Line 108  Returns:  A list, the first item is the Line 115  Returns:  A list, the first item is the
 ##################################################  ##################################################
 sub parmval {  sub parmval {
     my ($what,$id,$def,$uname,$udom,$csec)=@_;      my ($what,$id,$def,$uname,$udom,$csec)=@_;
   # load caches
   
       &cacheparmhash();
   
       my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
       my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
       my $useropt=&Apache::lonnet::get_userresdata($uname,$udom);
       my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
   
   
     my $result='';      my $result='';
     my @outpar=();      my @outpar=();
 # ----------------------------------------------------- Cascading lookup scheme  # ----------------------------------------------------- Cascading lookup scheme
Line 127  sub parmval { Line 144  sub parmval {
   
 # --------------------------------------------------------- first, check course  # --------------------------------------------------------- first, check course
   
     if (defined($courseopt{$courselevel})) {      if (defined($$courseopt{$courselevel})) {
  $outpar[11]=$courseopt{$courselevel};   $outpar[11]=$$courseopt{$courselevel};
  $result=11;   $result=11;
     }      }
   
     if (defined($courseopt{$courselevelm})) {      if (defined($$courseopt{$courselevelm})) {
  $outpar[10]=$courseopt{$courselevelm};   $outpar[10]=$$courseopt{$courselevelm};
  $result=10;   $result=10;
     }      }
   
Line 146  sub parmval { Line 163  sub parmval {
     my $thisparm=$parmhash{$symbparm};      my $thisparm=$parmhash{$symbparm};
     if (defined($thisparm)) { $outpar[8]=$thisparm; $result=8; }      if (defined($thisparm)) { $outpar[8]=$thisparm; $result=8; }
   
     if (defined($courseopt{$courselevelr})) {      if (defined($$courseopt{$courselevelr})) {
  $outpar[7]=$courseopt{$courselevelr};   $outpar[7]=$$courseopt{$courselevelr};
  $result=7;   $result=7;
     }      }
   
 # ------------------------------------------------------ fourth, back to course  # ------------------------------------------------------ fourth, back to course
     if (defined($csec)) {      if (defined($csec)) {
         if (defined($courseopt{$seclevel})) {          if (defined($$courseopt{$seclevel})) {
     $outpar[6]=$courseopt{$seclevel};      $outpar[6]=$$courseopt{$seclevel};
     $result=6;      $result=6;
  }   }
         if (defined($courseopt{$seclevelm})) {          if (defined($$courseopt{$seclevelm})) {
     $outpar[5]=$courseopt{$seclevelm};      $outpar[5]=$$courseopt{$seclevelm};
     $result=5;      $result=5;
  }   }
   
         if (defined($courseopt{$seclevelr})) {          if (defined($$courseopt{$seclevelr})) {
     $outpar[4]=$courseopt{$seclevelr};      $outpar[4]=$$courseopt
   {$seclevelr};
     $result=4;      $result=4;
  }   }
     }      }
Line 171  sub parmval { Line 189  sub parmval {
 # ---------------------------------------------------------- fifth, check user  # ---------------------------------------------------------- fifth, check user
   
     if (defined($uname)) {      if (defined($uname)) {
  if (defined($useropt{$courselevel})) {   if (defined($$useropt{$courselevel})) {
     $outpar[3]=$useropt{$courselevel};      $outpar[3]=$$useropt{$courselevel};
     $result=3;      $result=3;
  }   }
   
  if (defined($useropt{$courselevelm})) {   if (defined($$useropt{$courselevelm})) {
     $outpar[2]=$useropt{$courselevelm};      $outpar[2]=$$useropt{$courselevelm};
     $result=2;      $result=2;
  }   }
   
  if (defined($useropt{$courselevelr})) {   if (defined($$useropt{$courselevelr})) {
     $outpar[1]=$useropt{$courselevelr};      $outpar[1]=$$useropt{$courselevelr};
     $result=1;      $result=1;
  }   }
     }      }
     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'};
       }
   }
   
 ##################################################  ##################################################
 ##################################################  ##################################################
 #  #
 # Store a parameter  # Store a parameter by ID
 #  #
 # Takes  # Takes
 # - resource id  # - resource id
Line 206  sub parmval { Line 238  sub parmval {
   
 sub storeparm {  sub storeparm {
     my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;      my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
     $spnam=~s/\_([^\_]+)$/\.$1/;      my $navmap = Apache::lonnavmaps::navmap->new();
       if ($sresid=~/\./) {
    my $resource=$navmap->getById($sresid);
    &storeparm_by_symb($resource->symb(),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec);
       } else {
           my $resource=$navmap->getByMapPc($sresid);
    &storeparm_by_symb(&Apache::lonnet::declutter($resource->src()),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec);
       }
   }
   
   #
   # Store a parameter by symb
   #
   # Takes
   # - symb
   # - name of parameter
   # - level
   # - new value
   # - new type
   # - username
   # - userdomain
   
   sub storeparm_by_symb {
   # ---------------------------------------------------------- Get symb, map, etc
       my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
 # ---------------------------------------------------------- Construct prefixes  # ---------------------------------------------------------- Construct prefixes
           $spnam=~s/\_([^\_]+)$/\.$1/;
     my $symbparm=$symbp{$sresid}.'.'.$spnam;      my $map=(&Apache::lonnet::decode_symb($symb))[0];    
     my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;      my $symbparm=$symb.'.'.$spnam;
           my $mapparm=$map.'___(all).'.$spnam;
   
     my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;      my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;
     my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;      my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
     my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;      my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
Line 236  sub storeparm { Line 293  sub storeparm {
     if ($snum>3) {      if ($snum>3) {
 # ---------------------------------------------------------------- Store Course  # ---------------------------------------------------------------- Store Course
 #  #
    my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 # Expire sheets  # Expire sheets
  &Apache::lonnet::expirespread('','','studentcalc');   &Apache::lonnet::expirespread('','','studentcalc');
  if (($snum==7) || ($snum==4)) {   if (($snum==7) || ($snum==4)) {
     &Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid});      &Apache::lonnet::expirespread('','','assesscalc',$symb);
  } elsif (($snum==8) || ($snum==5)) {   } elsif (($snum==8) || ($snum==5)) {
     &Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid});      &Apache::lonnet::expirespread('','','assesscalc',$map);
  } else {   } else {
     &Apache::lonnet::expirespread('','','assesscalc');      &Apache::lonnet::expirespread('','','assesscalc');
  }   }
 # Store parameter  # Store parameter
  if ($delete) {   if ($delete) {
     $reply=&Apache::lonnet::del      $reply=&Apache::lonnet::del
  ('resourcedata',[keys(%storecontent)],   ('resourcedata',[keys(%storecontent)],$cdom,$cnum);
  $env{'course.'.$env{'request.course.id'}.'.domain'},  
  $env{'course.'.$env{'request.course.id'}.'.num'});  
  } else {   } else {
     $reply=&Apache::lonnet::cput      $reply=&Apache::lonnet::cput
  ('resourcedata',\%storecontent,   ('resourcedata',\%storecontent,$cdom,$cnum);
  $env{'course.'.$env{'request.course.id'}.'.domain'},  
  $env{'course.'.$env{'request.course.id'}.'.num'});  
  }   }
    &Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
     } else {      } else {
 # ------------------------------------------------------------------ Store User  # ------------------------------------------------------------------ Store User
 #  #
Line 264  sub storeparm { Line 320  sub storeparm {
  &Apache::lonnet::expirespread($uname,$udom,'studentcalc');   &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
  if ($snum==1) {   if ($snum==1) {
     &Apache::lonnet::expirespread      &Apache::lonnet::expirespread
  ($uname,$udom,'assesscalc',$symbp{$sresid});   ($uname,$udom,'assesscalc',$symb);
  } elsif ($snum==2) {   } elsif ($snum==2) {
     &Apache::lonnet::expirespread      &Apache::lonnet::expirespread
  ($uname,$udom,'assesscalc',$mapp{$sresid});   ($uname,$udom,'assesscalc',$map);
  } else {   } else {
     &Apache::lonnet::expirespread($uname,$udom,'assesscalc');      &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
  }   }
Line 675  Input: See list below: Line 731  Input: See list below:
 =cut  =cut
   
 sub extractResourceInformation {  sub extractResourceInformation {
     my $bighash = shift;  
     my $ids = shift;      my $ids = shift;
     my $typep = shift;      my $typep = shift;
     my $keyp = shift;      my $keyp = shift;
Line 688  sub extractResourceInformation { Line 743  sub extractResourceInformation {
     my $mapp = shift;      my $mapp = shift;
     my $symbp = shift;      my $symbp = shift;
     my $maptitles=shift;      my $maptitles=shift;
       my $uris=shift;
   
   
     foreach (keys %$bighash) {      my $navmap = Apache::lonnavmaps::navmap->new();
  if ($_=~/^src\_(\d+)\.(\d+)$/) {      my @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
     # there are no resources in the 0 level      foreach my $resource (@allres) {
     if ($1 eq '0') { next; }   my $id=$resource->id();
     my $mapid=$1;          my ($mapid,$resid)=split(/\./,$id);
     my $resid=$2;   if ($mapid eq '0') { next; }
     my $id=$mapid.'.'.$resid;   $$ids[$#$ids+1]=$id;
     my $srcf=$$bighash{$_};   my $srcf=$resource->src();
     if (1) {   $srcf=~/\.(\w+)$/;
  $srcf=~/\.(\w+)$/;   $$typep{$id}=$1;
  $$ids[$#$ids+1]=$id;   $$keyp{$id}='';
  $$typep{$id}=$1;          $$uris{$id}=$srcf;
  $$keyp{$id}='';   foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
  foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {      if ($_=~/^parameter\_(.*)/) {
   if ($_=~/^parameter\_(.*)/) {   my $key=$_;
                     my $key=$_;   my $allkey=$1;
                     my $allkey=$1;   $allkey=~s/\_/\./g;
                     $allkey=~s/\_/\./g;   if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 
     if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq       'parm') {
  'parm') {      next; #hide hidden things
  next; #hide hidden things   }
     }   my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
                     my $display= &Apache::lonnet::metadata($srcf,$key.'.display');   my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
                     my $name=&Apache::lonnet::metadata($srcf,$key.'.name');   my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
                     my $part= &Apache::lonnet::metadata($srcf,$key.'.part');   my $parmdis = $display;
                     my $parmdis = $display;   $parmdis =~ s|(\[Part.*)$||g;
                     $parmdis =~ s|(\[Part.*)$||g;   my $partkey = $part;
                     my $partkey = $part;   $partkey =~ tr|_|.|;
                     $partkey =~ tr|_|.|;   $$allparms{$name} = $parmdis;
                     $$allparms{$name} = $parmdis;   $$allparts{$part} = "[Part $part]";
                     $$allparts{$part} = "[Part $part]";   $$allkeys{$allkey}=$display;
                     $$allkeys{$allkey}=$display;   if ($allkey eq $fcat) {
                     if ($allkey eq $fcat) {      $$defp{$id}= &Apache::lonnet::metadata($srcf,$key);
         $$defp{$id}= &Apache::lonnet::metadata($srcf,$key);  
     }  
     if ($$keyp{$id}) {  
         $$keyp{$id}.=','.$key;  
     } else {  
         $$keyp{$id}=$key;  
     }  
   }  
  }   }
  $$mapp{$id}=   if ($$keyp{$id}) {
     &Apache::lonnet::declutter($$bighash{'map_id_'.$mapid});      $$keyp{$id}.=','.$key;
                 $$mapp{$mapid}=$$mapp{$id};  
  $$allmaps{$mapid}=$$mapp{$id};  
  if ($mapid eq '1') {  
     $$maptitles{$mapid}='Main Course Documents';  
  } else {   } else {
     $$maptitles{$mapid}=&Apache::lonnet::gettitle(&Apache::lonnet::clutter($$mapp{$id}));      $$keyp{$id}=$key;
  }   }
  $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};  
  $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);  
                 $$symbp{$mapid}=$$mapp{$id}.'___(all)';  
     }      }
  }   }
    $$mapp{$id}=
       &Apache::lonnet::declutter($resource->enclosing_map_src());
    $$mapp{$mapid}=$$mapp{$id};
    $$allmaps{$mapid}=$$mapp{$id};
    if ($mapid eq '1') {
       $$maptitles{$mapid}='Main Course Documents';
    } else {
       $$maptitles{$mapid}=&Apache::lonnet::gettitle(&Apache::lonnet::clutter($$mapp{$id}));
    }
    $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
    $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
    $$symbp{$mapid}=$$mapp{$id}.'___(all)';
     }      }
 }  }
   
Line 801  sub assessparms { Line 855  sub assessparms {
     my %allparts;      my %allparts;
   
     my %defp;      my %defp;
     %courseopt=();  
     %useropt=();  
     my %bighash=();  
   
     @ids=();      @ids=();
     %symbp=();      %symbp=();
Line 905  sub assessparms { Line 956  sub assessparms {
     my $fcat=$env{'form.fcat'};      my $fcat=$env{'form.fcat'};
     unless ($fcat) { $fcat=''; }      unless ($fcat) { $fcat=''; }
   
 # ------------------------------------------------------------------- Tie hashs  
     if (!(tie(%bighash,'GDBM_File',$env{'request.course.fn'}.'.db',  
       &GDBM_READER(),0640))) {  
  $r->print("Unable to access course data. (File $env{'request.course.fn'}.db not tieable)");  
  return ;  
     }  
     if (!(tie(%parmhash,'GDBM_File',  
       $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640))) {  
  $r->print("Unable to access parameter data. (File $env{'request.course.fn'}_parms.db not tieable)");  
  return ;  
     }  
   
 # --------------------------------------------------------- Get all assessments  # --------------------------------------------------------- Get all assessments
     &extractResourceInformation(\%bighash, \@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allkeys, \%allmaps, $fcat, \%defp, \%mapp, \%symbp,\%maptitles);      &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allkeys, \%allmaps, $fcat, \%defp, \%mapp, \%symbp,\%maptitles,\%uris);
   
     $mapp{'0.0'} = '';      $mapp{'0.0'} = '';
     $symbp{'0.0'} = '';      $symbp{'0.0'} = '';
Line 932  sub assessparms { Line 971  sub assessparms {
 # ---------------------------------------------------------------- Done storing  # ---------------------------------------------------------------- Done storing
  $message.='<h3>'.&mt('Changes can take up to 10 minutes before being active for all students.').&Apache::loncommon::help_open_topic('Caching').'</h3>';   $message.='<h3>'.&mt('Changes can take up to 10 minutes before being active for all students.').&Apache::loncommon::help_open_topic('Caching').'</h3>';
     }      }
 # --------------------------------------------- Devalidate cache for this child  
     &Apache::lonnet::devalidatecourseresdata(  
                  $env{'course.'.$env{'request.course.id'}.'.num'},  
                  $env{'course.'.$env{'request.course.id'}.'.domain'});  
     #&Apache::lonnet::clear_EXT_cache_status();  
 # -------------------------------------------------------------- Get coursedata  
     %courseopt = &Apache::lonnet::dump  
         ('resourcedata',  
          $env{'course.'.$env{'request.course.id'}.'.domain'},  
          $env{'course.'.$env{'request.course.id'}.'.num'});  
 # --------------------------------------------------- Get userdata (if present)  
     if ($uname) {  
         %useropt=&Apache::lonnet::dump('resourcedata',$udom,$uname);  
     }  
   
 # ------------------------------------------------------------------- Sort this  # ------------------------------------------------------------------- Sort this
   
     @ids=sort  {      @ids=sort  {
Line 971  sub assessparms { Line 995  sub assessparms {
     $trimheader = 'yes';      $trimheader = 'yes';
     &startpage($r,$id,$udom,$csec,$uname,$have_assesments,$trimheader);      &startpage($r,$id,$udom,$csec,$uname,$have_assesments,$trimheader);
   
     if (!$have_assesments) {  
  untie(%bighash);  
  untie(%parmhash);  
  return '';  
     }  
 #    if ($env{'form.url'}) {  #    if ($env{'form.url'}) {
 # $r->print('<input type="hidden" value="'.$env{'form.url'}.  # $r->print('<input type="hidden" value="'.$env{'form.url'}.
 #  '" name="url"><input type="hidden" name="command" value="set">');  #  '" name="url"><input type="hidden" name="command" value="set">');
Line 1238  ENDTABLEHEADFOUR Line 1257  ENDTABLEHEADFOUR
                     my %display=();                      my %display=();
                     my %type=   ();                      my %type=   ();
                     my %default=();                      my %default=();
                     my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});                      my $uri=&Apache::lonnet::declutter($uris{$rid});
   
                     foreach (split(/\,/,$keyp{$rid})) {                      foreach (split(/\,/,$keyp{$rid})) {
                         my $tempkeyp = $_;                          my $tempkeyp = $_;
Line 1337  ENDTABLEHEADFOUR Line 1356  ENDTABLEHEADFOUR
 #                  $r->print("$mapid:$map:   $rid <br /> \n");  #                  $r->print("$mapid:$map:   $rid <br /> \n");
   
                   if ($map eq $mapid) {                    if ($map eq $mapid) {
                     my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});                      my $uri=&Apache::lonnet::declutter($uris{$rid});
 #                    $r->print("Keys: $keyp{$rid} <br />\n");  #                    $r->print("Keys: $keyp{$rid} <br />\n");
   
 #--------------------------------------------------------------------  #--------------------------------------------------------------------
Line 1425  ENDMAPONE Line 1444  ENDMAPONE
             foreach (@ids) {              foreach (@ids) {
                 my $rid = $_;                  my $rid = $_;
                   
                 my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});                  my $uri=&Apache::lonnet::declutter($uris{$rid});
   
 #--------------------------------------------------------------------  #--------------------------------------------------------------------
 # @catmarker contains list of all possible parameters including part #s  # @catmarker contains list of all possible parameters including part #s
Line 1485  ENDMAPONE Line 1504  ENDMAPONE
         } # end of $parmlev eq general          } # end of $parmlev eq general
     }      }
     $r->print('</form></body></html>');      $r->print('</form></body></html>');
     untie(%bighash);  
     untie(%parmhash);  
 } # end sub assessparms  } # end sub assessparms
   
   
Line 2169  sub handler { Line 2186  sub handler {
   
 # ----------------------------------------------------------- Clear out garbage  # ----------------------------------------------------------- Clear out garbage
   
     %courseopt=();  
     %useropt=();  
     %parmhash=();  
   
     @ids=();      @ids=();
     %symbp=();      %symbp=();

Removed from v.1.195  
changed lines
  Added in v.1.200


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