--- loncom/interface/lonparmset.pm 2005/12/29 14:59:58 1.273
+++ loncom/interface/lonparmset.pm 2008/12/12 20:22:33 1.413.2.1
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.273 2005/12/29 14:59:58 www Exp $
+# $Id: lonparmset.pm,v 1.413.2.1 2008/12/12 20:22:33 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -63,17 +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
##################################################
##################################################
@@ -90,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
@@ -109,25 +102,24 @@ Returns: A list, the first item is the
##################################################
sub parmval {
- my ($what,$id,$def,$uname,$udom,$csec,$cgroup)=@_;
- return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec,$cgroup);
+ my ($what,$id,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
+ return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec,
+ $cgroup,$courseopt);
}
sub parmval_by_symb {
- my ($what,$symb,$def,$uname,$udom,$csec,$cgroup)=@_;
-# load caches
-
- &cacheparmhash();
+ my ($what,$symb,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
- 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 $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;
@@ -163,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})) {
@@ -172,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;
@@ -187,8 +179,8 @@ sub parmval_by_symb {
$result=7;
}
}
-# ------------------------------------------------------ fifth, check gourse group
- if (defined($cgroup)) {
+# ------------------------------------------------------ fifth, check course group
+ if ($cgroup ne '') {
if (defined($$courseopt{$grplevel})) {
$outpar[6]=$$courseopt{$grplevel};
$result=6;
@@ -205,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;
@@ -224,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 {
@@ -295,6 +317,42 @@ sub preset_defaults {
}
##################################################
+
+sub date_sanity_info {
+ my $checkdate=shift;
+ unless ($checkdate) { return ''; }
+ my $result='';
+ my $crsprefix='course.'.$env{'request.course.id'}.'.';
+ if ($env{$crsprefix.'default_enrollment_end_date'}) {
+ if ($checkdate>$env{$crsprefix.'default_enrollment_end_date'}) {
+ $result.='
'
+ .&mt('After course enrollment end!')
+ .'
';
+ }
+ }
+ if ($env{$crsprefix.'default_enrollment_start_date'}) {
+ if ($checkdate<$env{$crsprefix.'default_enrollment_start_date'}) {
+ $result.=''
+ .&mt('Before course enrollment start!')
+ .'
';
+ }
+ }
+# Preparation for additional warnings about dates in the past/future.
+# An improved, more context sensitive version is recommended,
+# e.g. warn for due and answer dates which are defined before the corresponding open date, etc.
+# if ($checkdate'
+# .'('.&mt('in the past').')'
+# .'';
+# }
+# if ($checkdate>time) {
+# $result.=''
+# .'('.&mt('in the future').')'
+# .'
';
+# }
+ return $result;
+}
+##################################################
##################################################
#
# Store a parameter by ID
@@ -310,7 +368,7 @@ sub preset_defaults {
sub storeparm {
my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
- &storeparm_by_symb(&symbcache($sresid),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup);
+ &storeparm_by_symb(&symbcache($sresid),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,'',$cgroup);
}
#
@@ -324,10 +382,9 @@ sub storeparm {
# - new type
# - username
# - userdomain
-
my %recstack;
sub storeparm_by_symb {
- my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup,$recflag)=@_;
+ my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag,$cgroup)=@_;
unless ($recflag) {
# first time call
%recstack=();
@@ -370,19 +427,25 @@ sub storeparm_by_symb {
}
if ($active) {
&storeparm_by_symb($symb,$newspnam,$snum,$newvalue,&rulescache($triggered.'_type'),
- $uname,$udom,$csec,$cgroup,$recflag);
+ $uname,$udom,$csec,$recflag,$cgroup);
}
}
}
return '';
}
+sub log_parmset {
+ return &Apache::lonnet::instructor_log('parameterlog',@_);
+}
+
sub storeparm_by_symb_inner {
# ---------------------------------------------------------- Get symb, map, etc
my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
# ---------------------------------------------------------- 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;
@@ -433,9 +496,11 @@ sub storeparm_by_symb_inner {
if ($delete) {
$reply=&Apache::lonnet::del
('resourcedata',[keys(%storecontent)],$cdom,$cnum);
+ &log_parmset(\%storecontent,1);
} else {
$reply=&Apache::lonnet::cput
('resourcedata',\%storecontent,$cdom,$cnum);
+ &log_parmset(\%storecontent);
}
&Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
} else {
@@ -456,15 +521,17 @@ sub storeparm_by_symb_inner {
if ($delete) {
$reply=&Apache::lonnet::del
('resourcedata',[keys(%storecontent)],$udom,$uname);
+ &log_parmset(\%storecontent,1,$uname,$udom);
} else {
$reply=&Apache::lonnet::cput
('resourcedata',\%storecontent,$udom,$uname);
+ &log_parmset(\%storecontent,0,$uname,$udom);
}
&Apache::lonnet::devalidateuserresdata($uname,$udom);
}
if ($reply=~/^error\:(.*)/) {
- return "Write Error: $1 ";
+ return "Write Error: $1 ";
}
return '';
}
@@ -478,49 +545,67 @@ 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);
+ my @timer;
$year=$year-70;
$mday--;
if ($year) {
- $result.=$year.' yrs ';
+# $result.=&mt('[quant,_1,yr]',$year).' ';
+ push(@timer,&mt('[quant,_1,yr]',$year));
}
if ($mon) {
- $result.=$mon.' mths ';
+# $result.=&mt('[quant,_1,mth]',$mon).' ';
+ push(@timer,&mt('[quant,_1,mth]',$mon));
}
if ($mday) {
- $result.=$mday.' days ';
+# $result.=&mt('[quant,_1,day]',$mday).' ';
+ push(@timer,&mt('[quant,_1,day]',$mday));
}
if ($hour) {
- $result.=$hour.' hrs ';
+# $result.=&mt('[quant,_1,hr]',$hour).' ';
+ push(@timer,&mt('[quant,_1,hr]',$hour));
}
if ($min) {
- $result.=$min.' mins ';
+# $result.=&mt('[quant,_1,min]',$min).' ';
+ push(@timer,&mt('[quant,_1,min]',$min));
}
if ($sec) {
- $result.=$sec.' secs ';
+# $result.=&mt('[quant,_1,sec]',$sec).' ';
+ push(@timer,&mt('[quant,_1,sec]',$sec));
+ }
+# $result=~s/\s+$//;
+ if (!@timer) { # Special case: all entries 0 -> display "0 secs" intead of empty field to keep this field editable
+ push(@timer,&mt('[quant,_1,sec]',0));
}
- $result=~s/\s+$//;
+ $result.=join(", ",@timer);
} elsif (&isdateparm($type)) {
- $result = localtime($value);
+ $result = &Apache::lonlocal::locallocaltime($value).
+ &date_sanity_info($value);
} else {
$result = $value;
+ $result = &HTML::Entities::encode($result,'"<>&');
}
}
return $result;
@@ -557,26 +642,25 @@ 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 startpage {
- my $r=shift;
- my $loaditems = qq|onUnload="pclose()" onLoad="group_or_section('cgroup')"|;
- my $bodytag=&Apache::loncommon::bodytag('Set/Modify Course Parameters','',
- $loaditems);
- my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Table Mode Parameter Setting');
+sub page_js {
+
my $selscript=&Apache::loncommon::studentbrowser_javascript();
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
- my $html=&Apache::lonxml::xmlbegin();
- $r->print(<
-LON-CAPA Course Parameters
-
$selscript
-
-$bodytag
+ENDJS
+
+}
+sub startpage {
+ my ($r) = @_;
+
+ my %loaditems = ('onunload' => "pclose()",
+ 'onload' => "group_or_section('cgroup')",);
+
+ my $start_page =
+ &Apache::loncommon::start_page('Set/Modify Course Parameters',
+ &page_js(),
+ {'add_entries' => \%loaditems,});
+ my $breadcrumbs =
+ &Apache::lonhtmlcommon::breadcrumbs('Table Mode Parameter Setting','Table_Mode');
+ $r->print(<
-
-
-
-
+
+
+
+
ENDHEAD
}
sub print_row {
my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
- $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup)=@_;
+ $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups)=@_;
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
# get the values for the parameter in cascading order
# empty levels will remain empty
my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
- $rid,$$default{$which},$uname,$udom,$csec,$cgroup);
+ $rid,$$default{$which},$uname,$udom,$csec,$cgroup,$courseopt);
# get the type for the parameters
# problem: these may not be set for all levels
my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
- $$name{$which}.'.type',
- $rid,$$defaulttype{$which},$uname,$udom,$csec,$cgroup);
+ $$name{$which}.'.type',$rid,
+ $$defaulttype{$which},$uname,$udom,$csec,$cgroup,$courseopt);
# cascade down manually
my $cascadetype=$$defaulttype{$which};
for (my $i=14;$i>0;$i--) {
@@ -661,13 +763,15 @@ sub print_row {
}
my $automatic=&rulescache(($which=~/\_([^\_]+)$/)[0].'_triggers');
if ($automatic) {
- $parm.=' '.&mt('Automatically sets').' '.join(', ',split(/\:/,$automatic)).' ';
+ $parm.=' '.&mt('Automatically sets').' '.join(', ',split(/\:/,$automatic)).' ';
}
$r->print(''.$parm.' ');
my $thismarker=$which;
$thismarker=~s/^parameter\_//;
my $mprefix=$rid.'&'.$thismarker.'&';
+ my $effective_parm = &valout($outpar[$result],$typeoutpar[$result]);
+ my ($othergrp,$grp_parm,$controlgrp);
if ($parmlev eq 'general') {
@@ -692,6 +796,22 @@ sub print_row {
&print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
}
} else {
+ if ($uname) {
+ if (@{$usersgroups} > 1) {
+ my ($coursereply,$grp_parm,$controlgrp);
+ ($coursereply,$othergrp,$grp_parm,$controlgrp) =
+ &print_usergroups($r,$$part{$which}.'.'.$$name{$which},
+ $rid,$cgroup,$defbgone,$usersgroups,$result,$courseopt);
+ if ($coursereply && $result > 3) {
+ if (defined($controlgrp)) {
+ if ($cgroup ne $controlgrp) {
+ $effective_parm = $grp_parm;
+ $result = 0;
+ }
+ }
+ }
+ }
+ }
&print_td($r,14,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
@@ -711,24 +831,25 @@ sub print_row {
&print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
&print_td($r,4,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
}
-
+
if ($uname) {
+ if ($othergrp) {
+ $r->print($othergrp);
+ }
&print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
&print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
&print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
}
} # end of $parmlev if/else
-
- $r->print(''.
- &valout($outpar[$result],$typeoutpar[$result]).' ');
+ $r->print(''.$effective_parm.' ');
if ($parmlev eq 'full') {
my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
'.'.$$name{$which},$$symbp{$rid});
my $sessionvaltype=$typeoutpar[$result];
if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; }
- $r->print(''.
+ $r->print(' '.
&valout($sessionval,$sessionvaltype).' '.
' ');
}
@@ -750,6 +871,61 @@ sub print_td {
$r->print(''."\n");
}
+sub print_usergroups {
+ my ($r,$what,$rid,$cgroup,$defbg,$usersgroups,$result,$courseopt) = @_;
+ my $courseid = $env{'request.course.id'};
+ my $output;
+ my $symb = &symbcache($rid);
+ my $symbparm=$symb.'.'.$what;
+ my $map=(&Apache::lonnet::decode_symb($symb))[0];
+ my $mapparm=$map.'___(all).'.$what;
+ my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype) =
+ &parm_control_group($courseid,$usersgroups,$symbparm,$mapparm,$what,
+ $courseopt);
+ my $bgcolor = $defbg;
+ my $grp_parm;
+ if (($coursereply) && ($cgroup ne $resultgroup)) {
+ if ($result > 3) {
+ $bgcolor = '"#AAFFAA"';
+ $grp_parm = &valout($coursereply,$resulttype);
+ }
+ $grp_parm = &valout($coursereply,$resulttype);
+ $output = '';
+ if ($resultgroup && $resultlevel) {
+ $output .= ''.$resultgroup.' ('.$resultlevel.'): '.$grp_parm;
+ } else {
+ $output .= ' ';
+ }
+ $output .= ' ';
+ } else {
+ $output .= ' ';
+ }
+ return ($coursereply,$output,$grp_parm,$resultgroup);
+}
+
+sub parm_control_group {
+ my ($courseid,$usersgroups,$symbparm,$mapparm,$what,$courseopt) = @_;
+ my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
+ my $grpfound = 0;
+ my @levels = ($symbparm,$mapparm,$what);
+ my @levelnames = ('resource','map/folder','general');
+ foreach my $group (@{$usersgroups}) {
+ if ($grpfound) { last; }
+ for (my $i=0; $i<@levels; $i++) {
+ my $item = $courseid.'.['.$group.'].'.$levels[$i];
+ if (defined($$courseopt{$item})) {
+ $coursereply = $$courseopt{$item};
+ $resultitem = $item;
+ $resultgroup = $group;
+ $resultlevel = $levelnames[$i];
+ $resulttype = $$courseopt{$item.'.type'};
+ $grpfound = 1;
+ last;
+ }
+ }
+ }
+ return($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
+}
=pod
@@ -813,57 +989,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');
+ $parmdis =~ s/\s*\[Part.*$//g;
+ $$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} = &mt('Part: [_1]',$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}=&mt('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)';
}
}
@@ -942,43 +1127,70 @@ sub parmmenu {
ENDSCRIPT
$r->print();
- $r->print("\n");
+ $r->print("\n');
+ $r->print(' '
+ .'
'
+ );
}
sub partmenu {
my ($r,$allparts,$psprt)=@_;
$r->print('');
$r->print('print(' selected') unless (@{$psprt});
+ $r->print(' selected="selected"') unless (@{$psprt});
$r->print('>'.&mt('All Parts').' ');
my %temphash=();
foreach (@{$psprt}) { $temphash{$_}=1; }
@@ -988,7 +1200,7 @@ sub partmenu {
unless ($tempkey =~ /\./) {
$r->print('print(' selected');
+ $r->print(' selected="selected"');
}
$r->print('>'.$$allparts{$tempkey}.' ');
}
@@ -997,43 +1209,36 @@ sub partmenu {
}
sub usermenu {
- my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev)=@_;
+ my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,$usersgroups)=@_;
my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
&Apache::loncommon::selectstudent_link('parmform','uname','udom');
my $selscript=&Apache::loncommon::studentbrowser_javascript();
- my %lt=&Apache::lonlocal::texthash(
- 'se' => "Section",
- 'gr' => "Group",
- 'fu' => "For User",
- 'oi' => "or ID",
- 'ad' => "at Domain"
- );
- my %sectionhash=();
+
my $sections='';
- my $numsec = &Apache::loncommon::get_sections(
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'},
- \%sectionhash);
+ my %sectionhash = &Apache::loncommon::get_sections();
+
my $groups;
- my %grouphash;
- my $numgrp = &Apache::loncommon::coursegroups(
- \%grouphash,
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'});
- if ($numsec > 0) {
- $sections=$lt{'se'}.': '.$_.'';
+ foreach my $section ('',sort keys %sectionhash) {
+ $sections.=''.$section.
+ ' ';
}
$sections.=' ';
}
- if ($numsec && $numgrp && $parmlev ne 'full') {
- $sections .= ' or ';
+
+ if (%sectionhash && %grouphash && $parmlev ne 'full') {
+ $sections .= ' '.&mt('or').' ';
$sections .= qq|
|;
}
- if ($numgrp > 0) {
- $groups=$lt{'gr'}.': '.
- $_.'';
+ foreach my $grp ('',sort keys %grouphash) {
+ $groups.='';
}
$groups.=' ';
}
- $r->print(<
-$sections
-$groups
-
-$lt{'fu'}
-
-$lt{'oi'}
-
-$lt{'ad'}
-$chooseopt
-
-ENDMENU
+
+ if (%sectionhash || %grouphash) {
+ $g_s_header=''.&mt('Group/Section').' ';
+ $g_s_footer='
';
+ }
+
+ $r->print(''
+ .$g_s_header
+ .$sections
+ .$groups
+ .$g_s_footer
+ .''.&mt('User').' '
+ .&mt('For User [_1] or Student/Employee ID [_2] at Domain [_3]'
+ ,' '
+ ,' '
+ ,$chooseopt)
+ .'
'
+ .' '
+ );
}
sub displaymenu {
@@ -1091,7 +1313,7 @@ sub displaymenu {
$r->print(''.&mt('Select Parameters to View').' '.
&mt('Select Parts to View').' ');
&parmmenu($r,$allparms,$pscat,$keyorder);
- $r->print(' ');
+ $r->print(' ');
&partmenu($r,$allparts,$psprt);
$r->print('
');
}
@@ -1103,7 +1325,7 @@ sub mapmenu {
$r->print(''.&mt('All Maps or Folders').' ');
foreach (sort {$$allmaps{$a} cmp $$allmaps{$b}} keys %{$allmaps}) {
$r->print('print(' selected'); }
+ if (($pschp eq $_)) { $r->print(' selected="selected"'); }
$r->print('>'.$$maptitles{$_}.($$allmaps{$_}!~/^uploaded/?' ['.$$allmaps{$_}.']':'').' ');
}
$r->print(" ");
@@ -1117,9 +1339,9 @@ sub levelmenu {
foreach (reverse sort keys %{$alllevs}) {
$r->print('print(' selected');
+ $r->print(' selected="selected"');
}
- $r->print('>'.$_.' ');
+ $r->print('>'.&mt($_).'');
}
$r->print("");
}
@@ -1127,49 +1349,40 @@ sub levelmenu {
sub sectionmenu {
my ($r,$selectedsections)=@_;
- my %sectionhash=();
- my $sections='';
- my $numsec = &Apache::loncommon::get_sections(
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'},
- \%sectionhash);
- if ($numsec) {
- $r->print('');
- foreach my $s ('all',sort keys %sectionhash) {
- $r->print(' print(' selected');
- last;
- }
+ my %sectionhash = &Apache::loncommon::get_sections();
+ return if (!%sectionhash);
+
+ $r->print('');
+ foreach my $s ('all',sort keys %sectionhash) {
+ $r->print(' print(' selected="selected"');
+ last;
}
- $r->print('>'.$s." \n");
}
- $r->print(" \n");
- }
+ $r->print('>'.$s." \n");
+ }
+ $r->print(" \n");
}
sub groupmenu {
my ($r,$selectedgroups)=@_;
- my %grouphash;
- my $numgrp = &Apache::loncommon::coursegroups(
- \%grouphash,
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'});
- if ($numgrp) {
- $r->print('');
- foreach my $group (sort(keys(%grouphash))) {
- $r->print(' print(' selected');
- last;
- }
- }
- $r->print('>'.$group." \n");
- }
- $r->print(" \n");
+ my %grouphash = &Apache::longroup::coursegroups();
+ return if (!%grouphash);
+
+ $r->print('');
+ foreach my $group (sort(keys(%grouphash))) {
+ $r->print(' print(' selected="selected"');
+ last;
+ }
+ }
+ $r->print('>'.$group." \n");
}
+ $r->print(" \n");
}
@@ -1294,6 +1507,7 @@ sub assessparms {
my $uhome;
my $csec;
my $cgroup;
+ my @usersgroups = ();
my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
@@ -1364,8 +1578,8 @@ sub assessparms {
$id='';
} else {
$message=
- "".&mt("Unknown ID")." '$id' ".
- &mt('at domain')." '$udom' ";
+ ''.&mt("Unknown ID")." '$id' ".
+ &mt('at domain')." '$udom' ";
}
} else {
$uname=$env{'form.uname'};
@@ -1376,17 +1590,17 @@ sub assessparms {
$uhome=&Apache::lonnet::homeserver($uname,$udom);
if ($uhome eq 'no_host') {
$message=
- "".&mt("Unknown user")." '$uname' ".
- &mt("at domain")." '$udom' ";
+ ''.&mt("Unknown user")." '$uname' ".
+ &mt("at domain")." '$udom' ";
$uname='';
} else {
$csec=&Apache::lonnet::getsection($udom,$uname,
$env{'request.course.id'});
if ($csec eq '-1') {
- $message="".
+ $message=''.
&mt("User")." '$uname' ".&mt("at domain")." '$udom' ".
- &mt("not in this course")." ";
+ &mt("not in this course")."";
$uname='';
$csec=$env{'form.csec'};
$cgroup=$env{'form.cgroup'};
@@ -1396,14 +1610,14 @@ sub assessparms {
$message="\n\n".&mt("Full Name").": ".
$name{'firstname'}.' '.$name{'middlename'}.' '
.$name{'lastname'}.' '.$name{'generation'}.
- " \n".&mt('ID').": ".$name{'id'}.'
';
+ " \n".&mt('ID').": ".$name{'id'}.'
';
}
- my $grouplist = &Apache::lonnet::get_users_groups(
- $udom,$uname,$env{'request.course.id'});
- if ($grouplist) {
- my @groups = split(/:/,$grouplist);
- @groups = sort(@groups);
- $cgroup = $groups[0];
+ @usersgroups = &Apache::lonnet::get_users_groups(
+ $udom,$uname,$env{'request.course.id'});
+ if (@usersgroups > 0) {
+ unless (grep(/^\Q$cgroup\E$/,@usersgroups)) {
+ $cgroup = $usersgroups[0];
+ }
}
}
}
@@ -1444,7 +1658,8 @@ sub assessparms {
foreach ('tolerance','date_default','date_start','date_end',
'date_interval','int','float','string') {
$r->print(' ');
+ &HTML::Entities::encode($env{'form.recent_'.$_},'"&<>').
+ '" name="recent_'.$_.'" />');
}
if (!$pssymb) {
@@ -1459,12 +1674,13 @@ sub assessparms {
&displaymenu($r,\%allparms,\%allparts,\@pscat,\@psprt,\%keyorder);
} else {
my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb);
- $r->print(&mt('Specific Resource').": ".$resource.
- ' '.
+ my $title = &Apache::lonnet::gettitle($pssymb);
+ $r->print(&mt('Specific Resource: [_1] ([_2])',$title,$resource).
+ ' '.
''.&mt('Show all parts').': ');
}
- &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev);
+ &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups);
$r->print('
'.$message.'
');
@@ -1486,6 +1702,7 @@ sub assessparms {
if ($parmlev eq 'full') {
my $coursespan=$csec?8:5;
+ my $userspan=3;
if ($cgroup ne '') {
$coursespan += 3;
}
@@ -1494,7 +1711,10 @@ sub assessparms {
$r->print(' ');
$r->print(''.&mt('Any User').' ');
if ($uname) {
- $r->print("");
+ if (@usersgroups > 1) {
+ $userspan ++;
+ }
+ $r->print(' ');
$r->print(&mt("User")." $uname ".&mt('at Domain')." $udom ");
}
my %lt=&Apache::lonlocal::texthash(
@@ -1516,7 +1736,7 @@ sub assessparms {
);
$r->print(<$lt{'pie'}
-$lt{'csv'} ($csuname $lt{'at'} $csudom)
+$lt{'csv'} ($csuname $lt{'at'} $csudom)
$lt{'ic'} $lt{'rl'}
$lt{'ic'}
@@ -1545,6 +1765,9 @@ ENDTABLEHEADFOUR
}
if ($uname) {
+ if (@usersgroups > 1) {
+ $r->print(''.&mt('Control by other group?').' ');
+ }
$r->print(''.&mt('general').' '.&mt('for Enclosing Map or Folder').' '.&mt('for Resource').' ');
}
@@ -1605,16 +1828,17 @@ ENDTABLEHEADFOUR
my $totalparms=scalar keys %name;
if ($totalparms>0) {
my $firstrow=1;
- my $title=&Apache::lonnet::gettitle($uri);
+ my $title=&Apache::lonnet::gettitle($symbp{$rid});
$r->print(''.
join(' / ',split(/\//,$uri)).
' '.
"$title");
+ &Apache::lonnet::clutter($uri).'?symb='.
+ &escape($symbp{$rid}).
+ "', 'metadatafile', '450', '500', 'no', 'yes');\"".
+ " target=\"_self\">$title");
if ($thistitle) {
$r->print(' ('.$thistitle.')');
@@ -1637,7 +1861,7 @@ ENDTABLEHEADFOUR
&print_row($r,$_,\%part,\%name,\%symbp,$rid,\%default,
\%type,\%display,$defbgone,$defbgtwo,
$defbgthree,$parmlev,$uname,$udom,$csec,
- $cgroup);
+ $cgroup,\@usersgroups);
}
}
}
@@ -1714,29 +1938,30 @@ ENDTABLEHEADFOUR
#---------------------------------------------------- print header information
my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
- $r->print(<
-Set Defaults for All Resources in $foldermap
-$showtitle
-Specifically for
-ENDMAPONE
+ my $tmp="";
if ($uname) {
my $person=&Apache::loncommon::plainname($uname,$udom);
- $r->print(&mt("User")." $uname \($person\) ".
- &mt('in')." \n");
+ $tmp.=&mt("User")." $uname \($person\) ".
+ &mt('in')." \n";
} else {
- $r->print("".&mt('all').' '.&mt('users in')." \n");
+ $tmp.="".&mt('all').' '.&mt('users in')." \n";
}
if ($cgroup) {
- $r->print(&mt("Group")." $cgroup".
- " ".&mt('of')." \n");
+ $tmp.=&mt("Group")." $cgroup".
+ " ".&mt('of')." \n";
$csec = '';
} elsif ($csec) {
- $r->print(&mt("Section")." $csec".
- " ".&mt('of')." \n");
+ $tmp.=&mt("Section")." $csec".
+ " ".&mt('of')." \n";
}
- $r->print("$coursename ");
- $r->print(" \n");
+ $r->print(''
+ .&mt('Set Defaults for All Resources in [_1]Specifically for [_2][_3]'
+ ,$foldermap.''.$showtitle.' '
+ ,$tmp
+ ,''.$coursename.' '
+ )
+ ." \n"
+ );
#---------------------------------------------------------------- print table
$r->print('
');
$r->print(''.&mt('Parameter Name').' ');
@@ -1749,7 +1974,7 @@ ENDMAPONE
\%type,\%display,$defbgone,$defbgtwo,$defbgthree,
$parmlev,$uname,$udom,$csec,$cgroup);
}
- $r->print("
");
+ $r->print("
");
} # end each map
} # end of $parmlev eq map
#--------------------------------- Entry for parm level general (Course level)
@@ -1811,7 +2036,7 @@ ENDMAPONE
}
if ($csec) {$r->print(&mt("Section")." $csec \n")};
- if ($cgroup) {$r->print(&mt("Group")." $csec \n")};
+ if ($cgroup) {$r->print(&mt("Group")." $cgroup \n")};
$r->print("\n");
#---------------------------------------------------------------- print table
$r->print('
');
@@ -1828,7 +2053,7 @@ ENDMAPONE
$r->print("
");
} # end of $parmlev eq general
}
- $r->print('