--- loncom/interface/lonparmset.pm 2006/05/11 17:38:44 1.303
+++ loncom/interface/lonparmset.pm 2008/05/28 23:53:35 1.396
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.303 2006/05/11 17:38:44 www Exp $
+# $Id: lonparmset.pm,v 1.396 2008/05/28 23:53:35 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -63,18 +63,10 @@ use Apache::lonhomework;
use Apache::lonxml;
use Apache::lonlocal;
use Apache::lonnavmaps;
+use Apache::longroup;
use Apache::lonrss;
+use LONCAPA qw(:DEFAULT :match);
-# --- Caches local to lonparmset
-
-my $parmhashid;
-my %parmhash;
-my $symbsid;
-my %symbs;
-my $rulesid;
-my %rules;
-
-# --- end local caches
##################################################
##################################################
@@ -91,11 +83,11 @@ Inputs: $what - a parameter spec (inclu
Returns: A list, the first item is the index into the remaining list of items of parm valuse that is the active one, the list consists of parm values at the 14 possible levels
-14 - General Course
-13 - Map or Folder level in course
+14- General Course
+13- Map or Folder level in course
12- resource default
11- map default
-10 - resource level in course
+10- resource level in course
9 - General for section
8 - Map or Folder level for section
7 - resource level in section
@@ -117,15 +109,17 @@ sub parmval {
sub parmval_by_symb {
my ($what,$symb,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
-# load caches
- &cacheparmhash();
- my $useropt=&Apache::lonnet::get_userresdata($uname,$udom);
+ my $useropt;
+ if ($uname ne '' && $udom ne '') {
+ $useropt = &Apache::lonnet::get_userresdata($uname,$udom);
+ }
my $result='';
my @outpar=();
# ----------------------------------------------------- Cascading lookup scheme
my $map=(&Apache::lonnet::decode_symb($symb))[0];
+ $map = &Apache::lonnet::deversion($map);
my $symbparm=$symb.'.'.$what;
my $mapparm=$map.'___(all).'.$what;
@@ -161,7 +155,7 @@ sub parmval_by_symb {
# ------------------------------------------------------ third, check map parms
- my $thisparm=$parmhash{$symbparm};
+ my $thisparm=&parmhash($symbparm);
if (defined($thisparm)) { $outpar[11]=$thisparm; $result=11; }
if (defined($$courseopt{$courselevelr})) {
@@ -170,7 +164,7 @@ sub parmval_by_symb {
}
# ------------------------------------------------------ fourth, back to course
- if (defined($csec)) {
+ if ($csec ne '') {
if (defined($$courseopt{$seclevel})) {
$outpar[9]=$$courseopt{$seclevel};
$result=9;
@@ -186,7 +180,7 @@ sub parmval_by_symb {
}
}
# ------------------------------------------------------ fifth, check course group
- if (defined($cgroup)) {
+ if ($cgroup ne '') {
if (defined($$courseopt{$grplevel})) {
$outpar[6]=$$courseopt{$grplevel};
$result=6;
@@ -203,7 +197,7 @@ sub parmval_by_symb {
# ---------------------------------------------------------- fifth, check user
- if (defined($uname)) {
+ if ($uname ne '') {
if (defined($$useropt{$courselevel})) {
$outpar[3]=$$useropt{$courselevel};
$result=3;
@@ -222,60 +216,90 @@ sub parmval_by_symb {
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 {
- $symbsid='';
+# --- Caches local to lonparmset
+
+
+sub reset_caches {
+ &resetparmhash();
+ &resetsymbcache();
+ &resetrulescache();
}
-sub symbcache {
- my $id=shift;
- if ($symbsid ne $env{'request.course.id'}) {
- %symbs=();
+{
+ my $parmhashid;
+ my %parmhash;
+ sub resetparmhash {
+ undef($parmhashid);
+ undef(%parmhash);
}
- unless ($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());
+
+ 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'};
}
- $symbsid=$env{'request.course.id'};
}
- return $symbs{$id};
-}
-
-sub resetrulescache {
- $rulesid='';
-}
+
+ sub parmhash {
+ my ($id) = @_;
+ &cacheparmhash();
+ 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;
- if ($rulesid ne $env{'request.course.id'}) {
- %rules=();
+{
+ my $rulesid;
+ my %rules;
+ sub resetrulescache {
+ undef($rulesid);
+ undef(%rules);
}
- unless (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'};
+
+ 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 {
@@ -341,7 +365,6 @@ sub storeparm {
# - new type
# - username
# - userdomain
-
my %recstack;
sub storeparm_by_symb {
my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag,$cgroup)=@_;
@@ -404,6 +427,8 @@ sub storeparm_by_symb_inner {
# ---------------------------------------------------------- Construct prefixes
$spnam=~s/\_([^\_]+)$/\.$1/;
my $map=(&Apache::lonnet::decode_symb($symb))[0];
+ $map = &Apache::lonnet::deversion($map);
+
my $symbparm=$symb.'.'.$spnam;
my $mapparm=$map.'___(all).'.$spnam;
@@ -489,7 +514,7 @@ sub storeparm_by_symb_inner {
}
if ($reply=~/^error\:(.*)/) {
- return "Write Error: $1";
+ return "Write Error: $1";
}
return '';
}
@@ -503,21 +528,26 @@ sub storeparm_by_symb_inner {
Format a value for output.
-Inputs: $value, $type
+Inputs: $value, $type, $editable
Returns: $value, formatted for output. If $type indicates it is a date,
localtime($value) is returned.
+$editable will return an icon to click on
=cut
##################################################
##################################################
sub valout {
- my ($value,$type)=@_;
+ my ($value,$type,$editable)=@_;
my $result = '';
# Values of zero are valid.
if (! $value && $value ne '0') {
- $result = ' ';
+ if ($editable) {
+ $result = '*';
+ } else {
+ $result=' ';
+ }
} else {
if ($type eq 'date_interval') {
my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);
@@ -543,9 +573,11 @@ sub valout {
}
$result=~s/\s+$//;
} elsif (&isdateparm($type)) {
- $result = localtime($value).&date_sanity_info($value);
+ $result = &Apache::lonlocal::locallocaltime($value).
+ &date_sanity_info($value);
} else {
$result = $value;
+ $result = &HTML::Entities::encode($result,'"<>&');
}
}
return $result;
@@ -582,10 +614,16 @@ sub plink {
my ($parmname)=((split(/\&/,$marker))[1]=~/\_([^\_]+)$/);
my ($hour,$min,$sec,$val)=&preset_defaults($parmname);
unless (defined($winvalue)) { $winvalue=$val; }
+ my $valout = &valout($value,$type,1);
+ foreach my $item (\$type, \$dis, \$winvalue, \$marker, \$return, \$call,
+ \$hour, \$min, \$sec) {
+ $$item = &HTML::Entities::encode($$item,'"<>&');
+ $$item =~ s/\'/\\\'/g;
+ }
return '
';
+ $valout.'';
}
sub page_js {
@@ -650,7 +688,7 @@ sub startpage {
&page_js(),
{'add_entries' => \%loaditems,});
my $breadcrumbs =
- &Apache::lonhtmlcommon::breadcrumbs('Table Mode Parameter Setting');
+ &Apache::lonhtmlcommon::breadcrumbs('Table Mode Parameter Setting','Table_Mode');
$r->print(<
'.&mt('Automatically sets').' '.join(', ',split(/\:/,$automatic)).'';
+ $parm.='
'.&mt('Automatically sets').' '.join(', ',split(/\:/,$automatic)).'';
}
$r->print(''.$parm.' | ');
@@ -923,57 +961,66 @@ sub extractResourceInformation {
$$typep{$id}=$1;
$$keyp{$id}='';
$$uris{$id}=$srcf;
- foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
- if ($_=~/^parameter\_(.*)/) {
- my $key=$_;
+ foreach my $key (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
+ next if ($key!~/^parameter_/);
+
# Hidden parameters
- if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm') {
- next;
- }
- my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
- my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
- my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
+ next if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm');
#
# allparms is a hash of parameter names
#
+ my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
+ if (!exists($$allparms{$name}) || $$allparms{$name} =~ m/^\s*$/ ) {
+ my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
my $parmdis = $display;
$parmdis =~ s/\[Part.*$//g;
- $$allparms{$name}=$parmdis;
- $$defkeytype{$name}=&Apache::lonnet::metadata($srcf,$key.'.type');
+ $$allparms{$name}=$parmdis;
+ if (ref($defkeytype)) {
+ $$defkeytype{$name}=
+ &Apache::lonnet::metadata($srcf,$key.'.type');
+ }
+ }
+
#
# allparts is a hash of all parts
#
- $$allparts{$part} = "Part: $part";
+ my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
+ $$allparts{$part} = "Part: $part";
#
# Remember all keys going with this resource
#
- if ($$keyp{$id}) {
- $$keyp{$id}.=','.$key;
- } else {
- $$keyp{$id}=$key;
- }
+ if ($$keyp{$id}) {
+ $$keyp{$id}.=','.$key;
+ } else {
+ $$keyp{$id}=$key;
+ }
#
# Put in order
#
- unless ($$keyorder{$key}) {
- $$keyorder{$key}=$keyordercnt;
- $keyordercnt++;
- }
-
+ unless ($$keyorder{$key}) {
+ $$keyorder{$key}=$keyordercnt;
+ $keyordercnt++;
}
}
- $$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';
+
+
+ if (!exists($$mapp{$mapid})) {
+ $$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($$mapp{$id});
+ }
+ $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
+ $$symbp{$mapid}=$$mapp{$id}.'___(all)';
} else {
- $$maptitles{$mapid}=&Apache::lonnet::gettitle(&Apache::lonnet::clutter($$mapp{$id}));
+ $$mapp{$id} = $$mapp{$mapid};
}
- $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
$$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
- $$symbp{$mapid}=$$mapp{$id}.'___(all)';
}
}
@@ -1052,15 +1099,17 @@ sub parmmenu {
ENDSCRIPT
$r->print();
- $r->print("\n