--- loncom/interface/lonparmset.pm 2006/11/15 22:33:13 1.346
+++ loncom/interface/lonparmset.pm 2009/09/15 02:21:20 1.413.6.1
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.346 2006/11/15 22:33:13 banghart Exp $
+# $Id: lonparmset.pm,v 1.413.6.1 2009/09/15 02:21:20 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -65,18 +65,8 @@ use Apache::lonlocal;
use Apache::lonnavmaps;
use Apache::longroup;
use Apache::lonrss;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
-# --- Caches local to lonparmset
-
-my $parmhashid;
-my %parmhash;
-my $symbsid;
-my %symbs;
-my $rulesid;
-my %rules;
-
-# --- end local caches
##################################################
##################################################
@@ -119,10 +109,11 @@ 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=();
@@ -164,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})) {
@@ -173,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;
@@ -189,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;
@@ -206,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;
@@ -225,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 {
@@ -304,14 +325,31 @@ sub date_sanity_info {
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!');
+ $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!');
+ $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;
}
##################################################
@@ -344,7 +382,6 @@ sub storeparm {
# - new type
# - username
# - userdomain
-
my %recstack;
sub storeparm_by_symb {
my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag,$cgroup)=@_;
@@ -531,31 +568,44 @@ sub valout {
} 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).&date_sanity_info($value);
+ $result = &Apache::lonlocal::locallocaltime($value).
+ &date_sanity_info($value);
} else {
$result = $value;
+ $result = &HTML::Entities::encode($result,'"<>&');
}
}
return $result;
@@ -592,10 +642,17 @@ sub plink {
my ($parmname)=((split(/\&/,$marker))[1]=~/\_([^\_]+)$/);
my ($hour,$min,$sec,$val)=&preset_defaults($parmname);
unless (defined($winvalue)) { $winvalue=$val; }
- return ''.
+ my $valout = &valout($value,$type,1);
+ my $unencmarker = $marker;
+ 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 {
@@ -933,57 +990,72 @@ 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 $parmdis = $display;
- $parmdis =~ s/\[Part.*$//g;
- $$allparms{$name}=$parmdis;
- $$defkeytype{$name}=&Apache::lonnet::metadata($srcf,$key.'.type');
+ my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
+ if (!exists($$allparms{$name}) || $$allparms{$name} =~ m/^\s*$/ ) {
+ my ($display,$parmdis);
+ $display = &standard_parameter_names($name);
+ if ($display eq '') {
+ $display= &Apache::lonnet::metadata($srcf,$key.'.display');
+ $parmdis = $display;
+ $parmdis =~ s/\s*\[Part.*$//g;
+ } else {
+ $parmdis = &mt($display);
+ }
+ $$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)';
}
}
@@ -1062,43 +1134,70 @@ sub parmmenu {
ENDSCRIPT
$r->print();
- $r->print("\n'
+ );
}
sub partmenu {
my ($r,$allparts,$psprt)=@_;
- $r->print('');
+ $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; }
@@ -1108,7 +1207,7 @@ sub partmenu {
unless ($tempkey =~ /\./) {
$r->print('print(' selected');
+ $r->print(' selected="selected"');
}
$r->print('>'.$$allparts{$tempkey}.' ');
}
@@ -1121,21 +1220,18 @@ sub usermenu {
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 $sections='';
my %sectionhash = &Apache::loncommon::get_sections();
my $groups;
my %grouphash = &Apache::longroup::coursegroups();
+ my $g_s_header='';
+ my $g_s_footer='';
+
if (%sectionhash) {
- $sections=$lt{'se'}.': ';
}
+
if (%sectionhash && %grouphash && $parmlev ne 'full') {
- $sections .= ' or ';
+ $sections .= ' '.&mt('or').' ';
$sections .= qq|
';
-
+ my ($jscript,$categorize_js);
+ my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
+ if ($can_categorize) {
+ $categorize_js = <'."\n".
+ $browse_js."\n".$categorize_js."\n".'';
my $start_page =
&Apache::loncommon::start_page('Set Course Environment',
- $browse_js);
+ $jscript);
my $end_page =
&Apache::loncommon::end_page();
my $end_table=&Apache::loncommon::end_data_table();
@@ -2320,17 +2615,110 @@ $start_page
$breadcrumbs
$end_page
ENDENV
}
+
+sub can_modify_catsettings {
+ my ($dom) = @_;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
+ my ($can_toggle_cat,$can_categorize);
+ if (ref($domconf{'coursecategories'}) eq 'HASH') {
+ if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
+ $can_toggle_cat = 1;
+ }
+ if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
+ $can_categorize = 1;
+ }
+ }
+ return ($can_toggle_cat,$can_categorize);
+}
+
+sub assign_course_categories {
+ my ($r) = @_;
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $hascats = 0;
+ my $cathash;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
+ if (ref($domconf{'coursecategories'}) eq 'HASH') {
+ $cathash = $domconf{'coursecategories'}{'cats'};
+ if (ref($cathash) eq 'HASH') {
+ $hascats = 1;
+ }
+ }
+ my $catwin_js;
+ if ($hascats) {
+ my $alert = &mt('Use \"Save\" in the main window to save course categories');
+ $catwin_js = <
+
+function updateCategories() {
+ var newcategories = '';
+ var unescapedcats = '';
+ if (document.chgcats.usecategory.length) {
+ for (var i=0; i 0) {
+ newcategories = newcategories.slice(0,-1);
+ }
+ if (unescapedcats.length > 0) {
+ unescapedcats = unescapedcats.slice(0,-3);
+ }
+ } else {
+ if (document.chgcats.usecategory.checked == true) {
+ newcategories = document.chgcats.usecategory.value;
+ unescapedcats = document.chgcats.catname.value;
+ }
+ }
+ opener.document.envform.categories_value.value = newcategories;
+ opener.document.envform.categories_display.value = unescapedcats;
+ opener.document.envform.categories_setparmval.checked = true;
+ alert("$alert");
+ self.close();
+ return;
+}
+
+
+ENDSCRIPT
+ } else {
+ my $onload;
+ }
+ my $start_page =
+ &Apache::loncommon::start_page('Course Categories',$catwin_js,
+ {'only_body' => 1,});
+ my $end_page = &Apache::loncommon::end_page();
+ my $categoriesform = ''.&mt('Categorize Course').' ';
+ if ($hascats) {
+ my %currsettings =
+ &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
+ $categoriesform .= &mt('Assign one or more categories to this course.').' '.
+ ' ';
+ } else {
+ $categoriesform .= &mt('No categories defined for this domain');
+ }
+ $r->print($start_page.$categoriesform.$end_page);
+ return;
+}
+
##################################################
# Overview mode
##################################################
@@ -2363,8 +2751,7 @@ sub readdata {
my $classlist=&Apache::loncoursedata::get_classlist();
foreach (keys %$classlist) {
- # the following undefs are for 'domain', and 'username' respectively.
- if ($_=~/^(\w+)\:(\w+)$/) {
+ if ($_=~/^($match_username)\:($match_domain)$/) {
my ($tuname,$tudom)=($1,$2);
my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
foreach my $userkey (keys %{$useropt}) {
@@ -2400,20 +2787,32 @@ sub storedata {
if ($tuname) {
$tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
}
- if ($cmd eq 'set') {
- my $data=$env{$_};
- my $typeof=$env{'form.typeof_'.$thiskey};
- if ($$olddata{$thiskey} ne $data) {
+ if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') {
+ my ($data, $typeof, $text);
+ if ($cmd eq 'set') {
+ $data=$env{$_};
+ $typeof=$env{'form.typeof_'.$thiskey};
+ $text = &mt('Saved modified parameter for');
+ } elsif ($cmd eq 'datepointer') {
+ $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
+ $typeof=$env{'form.typeof_'.$thiskey};
+ $text = &mt('Saved modified date for');
+ } elsif ($cmd eq 'dateinterval') {
+ $data=&get_date_interval_from_form($thiskey);
+ $typeof=$env{'form.typeof_'.$thiskey};
+ $text = &mt('Saved modified date for');
+ }
+ if (defined($data) and $$olddata{$thiskey} ne $data) {
if ($tuname) {
if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
$tkey.'.type' => $typeof},
$tudom,$tuname) eq 'ok') {
&log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
- $r->print(' '.&mt('Stored modified parameter for').' '.
+ $r->print(' '.$text.' '.
&Apache::loncommon::plainname($tuname,$tudom));
} else {
$r->print(''.
- &mt('Error storing parameters').'
');
+ &mt('Error saving parameters').'');
}
&Apache::lonnet::devalidateuserresdata($tuname,$tudom);
} else {
@@ -2434,26 +2833,6 @@ sub storedata {
} else {
push (@deldata,$thiskey,$thiskey.'.type');
}
- } elsif ($cmd eq 'datepointer') {
- my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
- my $typeof=$env{'form.typeof_'.$thiskey};
- if (defined($data) and $$olddata{$thiskey} ne $data) {
- if ($tuname) {
- if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
- $tkey.'.type' => $typeof},
- $tudom,$tuname) eq 'ok') {
- &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
- $r->print(' '.&mt('Stored modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom));
- } else {
- $r->print(''.
- &mt('Error storing parameters').'
');
- }
- &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
- } else {
- $newdata{$thiskey}=$data;
- $newdata{$thiskey.'.type'}=$typeof;
- }
- }
}
}
}
@@ -2475,10 +2854,10 @@ sub storedata {
if ($putentries) {
if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
&log_parmset(\%newdata,0);
- $r->print(''.&mt('Stored [_1] parameter(s)',$putentries/2).' ');
+ $r->print(''.&mt('Saved [_1] parameter(s)',$putentries/2).' ');
} else {
$r->print(''.
- &mt('Error storing parameters').'
');
+ &mt('Error saving parameters').'');
}
&Apache::lonnet::devalidatecourseresdata($crs,$dom);
}
@@ -2486,7 +2865,27 @@ sub storedata {
sub extractuser {
my $key=shift;
- return ($key=~/^$env{'request.course.id'}.\[useropt\:(\w+)\:(\w+)\]\./);
+ return ($key=~/^$env{'request.course.id'}.\[useropt\:($match_username)\:($match_domain)\]\./);
+}
+
+sub parse_listdata_key {
+ my ($key,$listdata) = @_;
+ # split into student/section affected, and
+ # the realm (folder/resource part and parameter
+ my ($student,$realm) =
+ ($key=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)$/);
+ # if course wide student would be undefined
+ if (!defined($student)) {
+ ($realm)=($key=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
+ }
+ # strip off the .type if it's not the Question type parameter
+ if ($realm=~/\.type$/ && !exists($listdata->{$key.'.type'})) {
+ $realm=~s/\.type//;
+ }
+ # split into resource+part and parameter name
+ my ($res, $parm) = ($realm=~/^(.*)\.(.*)$/);
+ ($res, my $part) = ($res =~/^(.*)\.(.*)$/);
+ return ($student,$res,$part,$parm);
}
sub listdata {
@@ -2500,40 +2899,48 @@ sub listdata {
$tableopen=0;
my $foundkeys=0;
my %keyorder=&standardkeyorder();
+
foreach my $thiskey (sort {
+ my ($astudent,$ares,$apart,$aparm) = &parse_listdata_key($a,$listdata);
+ my ($bstudent,$bres,$bpart,$bparm) = &parse_listdata_key($b,$listdata);
+
+ # get the numerical order for the param
+ $aparm=$keyorder{'parameter_0_'.$aparm};
+ $bparm=$keyorder{'parameter_0_'.$bparm};
+
+ my $result=0;
+
if ($sortorder eq 'realmstudent') {
- my ($astudent,$arealm)=($a=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)\.[^\.]+$/);
- my ($bstudent,$brealm)=($b=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)\.[^\.]+$/);
- if (!defined($astudent)) {
- ($arealm)=($a=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
- }
- if (!defined($bstudent)) {
- ($brealm)=($b=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
- }
- $arealm=~s/\.type//;
- my ($ares, $aparm) = ($arealm=~/^(.*)\.(.*)$/);
- $aparm=$keyorder{'parameter_0_'.$aparm};
- $brealm=~s/\.type//;
- my ($bres, $bparm) = ($brealm=~/^(.*)\.(.*)$/);
- $bparm=$keyorder{'parameter_0_'.$bparm};
- if ($ares eq $bres) {
- if (defined($aparm) && defined($bparm)) {
- ($aparm <=> $bparm);
- } elsif (defined($aparm)) {
- -1;
- } elsif (defined($bparm)) {
- 1;
- } else {
- ($arealm cmp $brealm) || ($astudent cmp $bstudent);
- }
- } else {
- ($arealm cmp $brealm) || ($astudent cmp $bstudent);
+ if ($ares ne $bres ) {
+ $result = ($ares cmp $bres);
+ } elsif ($astudent ne $bstudent) {
+ $result = ($astudent cmp $bstudent);
+ } elsif ($apart ne $bpart ) {
+ $result = ($apart cmp $bpart);
}
} else {
- $a cmp $b;
+ if ($astudent ne $bstudent) {
+ $result = ($astudent cmp $bstudent);
+ } elsif ($ares ne $bres ) {
+ $result = ($ares cmp $bres);
+ } elsif ($apart ne $bpart ) {
+ $result = ($apart cmp $bpart);
+ }
}
+
+ if (!$result) {
+ if (defined($aparm) && defined($bparm)) {
+ $result = ($aparm <=> $bparm);
+ } elsif (defined($aparm)) {
+ $result = -1;
+ } elsif (defined($bparm)) {
+ $result = 1;
+ }
+ }
+
+ $result;
} keys %{$listdata}) {
-
+
if ($$listdata{$thiskey.'.type'}) {
my $thistype=$$listdata{$thiskey.'.type'};
if ($$resourcedata{$thiskey.'.type'}) {
@@ -2544,7 +2951,7 @@ sub listdata {
my $section=&mt('All Students');
if ($middle=~/^\[(.*)\]/) {
my $issection=$1;
- if ($issection=~/^useropt\:(\w+)\:(\w+)/) {
+ if ($issection=~/^useropt\:($match_username)\:($match_domain)/) {
$section=&mt('User').": ".&Apache::loncommon::plainname($1,$2);
} else {
$section=&mt('Group/Section').': '.$issection;
@@ -2585,15 +2992,16 @@ sub listdata {
}
if ($part ne $oldpart) {
$r->print(&tableend().
- "\n".&mt('Part').": $part ");
+ "\n".''.&mt('Part').": $part ");
$oldpart=$part;
}
#
# Ready to print
#
+ my $parmitem = &standard_parameter_names($name);
$r->print(&tablestart().
&Apache::loncommon::start_data_table_row().
- ''.&standard_parameter_names($name).
+ ' '.&mt($parmitem).
' ');
$foundkeys++;
@@ -2606,41 +3014,138 @@ sub listdata {
$$resourcedata{$thiskey},
'',1,'','').
' '.
+(($$resourcedata{$thiskey}!=0)?''.
+&mt('Shift all dates based on this date').' ':'').
&date_sanity_info($$resourcedata{$thiskey})
);
- } elsif ($thistype eq 'string_yesno') {
- my $showval;
- if (defined($$resourcedata{$thiskey})) {
- $showval=$$resourcedata{$thiskey};
- }
- $r->print(' print(' checked="checked"');
- }
- $r->print(' />'.&mt('Yes').' ');
- $r->print(' print(' checked="checked"');
- }
- $r->print(' />'.&mt('No').' ');
+ } elsif ($thistype eq 'date_interval') {
+ $r->print(&date_interval_selector($thiskey,
+ $$resourcedata{$thiskey}));
+ } elsif ($thistype =~ m/^string/) {
+ $r->print(&string_selector($thistype,$thiskey,
+ $$resourcedata{$thiskey}));
} else {
- my $showval;
- if (defined($$resourcedata{$thiskey})) {
- $showval=$$resourcedata{$thiskey};
- }
- $r->print(' ');
+ $r->print(&default_selector($thiskey,$$resourcedata{$thiskey}));
}
$r->print(' ');
+ $thistype.'" />');
$r->print(' '.&Apache::loncommon::end_data_table_row());
}
}
return $foundkeys;
}
+
+sub date_interval_selector {
+ my ($thiskey, $showval) = @_;
+ my $result;
+ foreach my $which (['days', 86400, 31],
+ ['hours', 3600, 23],
+ ['minutes', 60, 59],
+ ['seconds', 1, 59]) {
+ my ($name, $factor, $max) = @{ $which };
+ my $amount = int($showval/$factor);
+ $showval %= $factor;
+ my %select = ((map {$_ => $_} (0..$max)),
+ 'select_form_order' => [0..$max]);
+ $result .= &Apache::loncommon::select_form($amount,$name.'_'.$thiskey,
+ %select);
+ $result .= ' '.&mt($name);
+ }
+ $result .= ' ';
+ return $result;
+
+}
+
+sub get_date_interval_from_form {
+ my ($key) = @_;
+ my $seconds = 0;
+ foreach my $which (['days', 86400],
+ ['hours', 3600],
+ ['minutes', 60],
+ ['seconds', 1]) {
+ my ($name, $factor) = @{ $which };
+ if (defined($env{'form.'.$name.'_'.$key})) {
+ $seconds += $env{'form.'.$name.'_'.$key} * $factor;
+ }
+ }
+ return $seconds;
+}
+
+
+sub default_selector {
+ my ($thiskey, $showval) = @_;
+ return ' ';
+}
+
+my %strings =
+ (
+ 'string_yesno'
+ => [[ 'yes', 'Yes' ],
+ [ 'no', 'No' ]],
+ 'string_problemstatus'
+ => [[ 'yes', 'Yes' ],
+ [ 'answer', 'Yes, and show correct answer if they exceed the maximum number of tries.' ],
+ [ 'no', 'No, don\'t show correct/incorrect feedback.' ],
+ [ 'no_feedback_ever', 'No, show no feedback at all.' ]],
+ );
+
+
+sub string_selector {
+ my ($thistype, $thiskey, $showval) = @_;
+
+ if (!exists($strings{$thistype})) {
+ return &default_selector($thiskey,$showval);
+ }
+
+ my $result;
+ foreach my $possibilities (@{ $strings{$thistype} }) {
+ my ($name, $description) = @{ $possibilities };
+ $result .= ' ';
+ }
+ return $result;
+}
+
+#
+# Shift all start and end dates by $shift
+#
+
+sub dateshift {
+ my ($shift)=@_;
+ my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my %data=&Apache::lonnet::dump('resourcedata',$dom,$crs);
+# ugly retro fix for broken version of types
+ foreach my $key (keys %data) {
+ if ($key=~/\wtype$/) {
+ my $newkey=$key;
+ $newkey=~s/type$/\.type/;
+ $data{$newkey}=$data{$key};
+ delete $data{$key};
+ }
+ }
+ my %storecontent=();
+# go through all parameters and look for dates
+ foreach my $key (keys %data) {
+ if ($data{$key.'.type'}=~/^date_(start|end)$/) {
+ my $newdate=$data{$key}+$shift;
+ $storecontent{$key}=$newdate;
+ }
+ }
+ my $reply=&Apache::lonnet::cput
+ ('resourcedata',\%storecontent,$dom,$crs);
+ if ($reply eq 'ok') {
+ &log_parmset(\%storecontent);
+ }
+ &Apache::lonnet::devalidatecourseresdata($crs,$dom);
+ return $reply;
+}
+
sub newoverview {
my ($r) = @_;
@@ -2682,8 +3187,8 @@ ENDOVER
my @selected_sections =
&Apache::loncommon::get_env_multiple('form.Section');
@selected_sections = ('all') if (! @selected_sections);
- foreach (@selected_sections) {
- if ($_ eq 'all') {
+ foreach my $sec (@selected_sections) {
+ if ($sec eq 'all') {
@selected_sections = ('all');
}
}
@@ -2703,6 +3208,9 @@ ENDOVER
\%mapp, \%symbp,\%maptitles,\%uris,
\%keyorder,\%defkeytype);
+ if (grep {$_ eq 'all'} (@psprt)) {
+ @psprt = keys(%allparts);
+ }
# Menu to select levels, etc
$r->print('
@@ -2759,7 +3267,7 @@ ENDOVER
&listdata($r,$resourcedata,$listdata,$sortorder);
}
$r->print(&tableend().
- ((($env{'form.store'}) || ($env{'form.dis'}))?'
':'').
+ ((($env{'form.store'}) || ($env{'form.dis'}))?'
':'').
''.&Apache::loncommon::end_page());
}
@@ -2857,7 +3365,7 @@ ENDOVER
$r->print(''.
&mt('These parameters refer to resources that do not exist.').
' '.
- ' '.' '.
+ ' '.' '.
' ');
$r->print(&Apache::loncommon::start_data_table().
''.
@@ -2868,16 +3376,22 @@ ENDOVER
next if (!exists($resourcedata->{$thiskey.'.type'})
&& $thiskey=~/\.type$/);
my %data = &parse_key($thiskey);
- if (exists($data{'realm_exists'})
- && !$data{'realm_exists'}) {
+ if (1) { #exists($data{'realm_exists'})
+ #&& !$data{'realm_exists'}) {
$r->print(&Apache::loncommon::start_data_table_row().
' '.
' ' );
$r->print('');
+ my $display_value = $resourcedata->{$thiskey};
+ if (&isdateparm($resourcedata->{$thiskey.'.type'})) {
+ $display_value =
+ &Apache::lonlocal::locallocaltime($display_value);
+ }
+ my $parmitem = &standard_parameter_names($data{'parameter_name'});
+ $parmitem = &mt($parmitem);
$r->print(&mt('Parameter: "[_1]" with value: "[_2]"',
- &standard_parameter_names($data{'parameter_name'}),
- $resourcedata->{$thiskey}));
+ $parmitem,$resourcedata->{$thiskey}));
$r->print(' ');
if ($data{'scope_type'} eq 'all') {
$r->print(&mt('All users'));
@@ -2899,17 +3413,62 @@ ENDOVER
$r->print(&mt('Resource: [_1] with ID: [_2] in folder [_3]',
$url,$resid,$map));
}
- $r->print(&mt('Part: [_1]',$data{'parameter_part'}));
+ $r->print(' '.&mt('Part: [_1]',$data{'parameter_part'}));
$r->print(' ');
}
}
$r->print(&Apache::loncommon::end_data_table().''.
- ' '.
+ ' '.
'
'.
&Apache::loncommon::end_page());
}
+sub date_shift_one {
+ my ($r) = @_;
+ my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+
+ my $start_page=&Apache::loncommon::start_page('Shift Dates');
+ my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
+ $r->print(<print('');
+ $r->print(&Apache::loncommon::end_page());
+}
+
+sub date_shift_two {
+ my ($r) = @_;
+ my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $start_page=&Apache::loncommon::start_page('Shift Dates');
+ my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
+ $r->print(<print(&mt('Shifting all dates such that [_1] becomes [_2]',
+ &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
+ &Apache::lonlocal::locallocaltime($timeshifted)));
+ my $delta=$timeshifted-$env{'form.timebase'};
+ &dateshift($delta);
+ $r->print(&Apache::loncommon::end_page());
+}
+
sub parse_key {
my ($key) = @_;
my %data;
@@ -2918,7 +3477,7 @@ sub parse_key {
$data{'scope_type'} = 'all';
if ($middle=~/^\[(.*)\]/) {
$data{'scope'} = $1;
- if ($data{'scope'}=~/^useropt\:(\w+)\:(\w+)/) {
+ if ($data{'scope'}=~/^useropt\:($match_username)\:($match_domain)/) {
$data{'scope_type'} = 'user';
$data{'scope'} = [$1,$2];
} else {
@@ -2935,7 +3494,6 @@ sub parse_key {
$data{'realm_type'} = 'folder';
$data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
($data{'realm_exists'}) = &Apache::lonnet::is_on_map($data{'realm'});
- &Apache::lonnet::logthis($1." siad ". $data{'realm_exists'} );
} elsif ($middle) {
$data{'realm'} = $middle;
$data{'realm_type'} = 'symb';
@@ -2982,48 +3540,63 @@ where $action is add or drop, and $clone
user for whom cloning ability is to be changed in course.
=cut
-
+
##################################################
##################################################
sub extract_cloners {
my ($clonelist,$allowclone) = @_;
if ($clonelist =~ /,/) {
- @{$allowclone} = split/,/,$clonelist;
+ @{$allowclone} = split(/,/,$clonelist);
} else {
$$allowclone[0] = $clonelist;
}
}
-
sub check_cloners {
my ($clonelist,$oldcloner) = @_;
- my ($clean_clonelist,$disallowed);
+ my ($clean_clonelist,%disallowed);
my @allowclone = ();
&extract_cloners($$clonelist,\@allowclone);
foreach my $currclone (@allowclone) {
- if (!grep/^$currclone$/,@$oldcloner) {
- my ($uname,$udom) = split/:/,$currclone;
- if ($uname && $udom) {
- if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
- $disallowed .= $currclone.',';
+ if (!grep(/^\Q$currclone\E$/,@$oldcloner)) {
+ if ($currclone eq '*') {
+ $clean_clonelist .= $currclone.',';
+ } else {
+ my ($uname,$udom) = split(/:/,$currclone);
+ if ($uname eq '*') {
+ if ($udom =~ /^$match_domain$/) {
+ if (!&Apache::lonnet::domain($udom)) {
+ $disallowed{'domain'} .= $currclone.',';
+ } else {
+ $clean_clonelist .= $currclone.',';
+ }
+ } else {
+ $disallowed{'format'} .= $currclone.',';
+ }
+ } elsif ($currclone !~/^($match_username)\:($match_domain)$/) {
+ $disallowed{'format'} .= $currclone.',';
} else {
- $clean_clonelist .= $currclone.',';
+ if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
+ $disallowed{'newuser'} .= $currclone.',';
+ } else {
+ $clean_clonelist .= $currclone.',';
+ }
}
}
} else {
$clean_clonelist .= $currclone.',';
}
}
- if ($disallowed) {
- $disallowed =~ s/,$//;
+ foreach my $key (keys(%disallowed)) {
+ $disallowed{$key} =~ s/,$//;
}
if ($clean_clonelist) {
$clean_clonelist =~ s/,$//;
}
$$clonelist = $clean_clonelist;
- return $disallowed;
-}
+ return %disallowed;
+}
sub change_clone {
my ($clonelist,$oldcloner) = @_;
@@ -3036,43 +3609,47 @@ sub change_clone {
my @allowclone;
&extract_cloners($clonelist,\@allowclone);
foreach my $currclone (@allowclone) {
- if (!grep/^$currclone$/,@$oldcloner) {
- ($uname,$udom) = split/:/,$currclone;
- if ($uname && $udom) {
- unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
- my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
- if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
- if ($currclonecrs{'cloneable'} eq '') {
- $currclonecrs{'cloneable'} = $clone_crs;
- } else {
- $currclonecrs{'cloneable'} .= ','.$clone_crs;
+ if (!grep(/^$currclone$/,@$oldcloner)) {
+ if ($currclone ne '*') {
+ ($uname,$udom) = split(/:/,$currclone);
+ if ($uname && $udom && $uname ne '*') {
+ if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
+ my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
+ if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
+ if ($currclonecrs{'cloneable'} eq '') {
+ $currclonecrs{'cloneable'} = $clone_crs;
+ } else {
+ $currclonecrs{'cloneable'} .= ','.$clone_crs;
+ }
+ &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
}
- &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
}
}
}
}
}
foreach my $oldclone (@$oldcloner) {
- if (!grep/^$oldclone$/,@allowclone) {
- ($uname,$udom) = split/:/,$oldclone;
- if ($uname && $udom) {
- unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
- my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
- my %newclonecrs = ();
- if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
- if ($currclonecrs{'cloneable'} =~ /,/) {
- my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
- foreach (@currclonecrs) {
- unless ($_ eq $clone_crs) {
- $newclonecrs{'cloneable'} .= $_.',';
+ if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
+ if ($oldclone ne '*') {
+ ($uname,$udom) = split(/:/,$oldclone);
+ if ($uname && $udom && $uname ne '*' ) {
+ if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
+ my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
+ my %newclonecrs = ();
+ if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
+ if ($currclonecrs{'cloneable'} =~ /,/) {
+ my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
+ foreach my $crs (@currclonecrs) {
+ if ($crs ne $clone_crs) {
+ $newclonecrs{'cloneable'} .= $crs.',';
+ }
}
+ $newclonecrs{'cloneable'} =~ s/,$//;
+ } else {
+ $newclonecrs{'cloneable'} = '';
}
- $newclonecrs{'cloneable'} =~ s/,$//;
- } else {
- $newclonecrs{'cloneable'} = '';
+ &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
}
- &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
}
}
}
@@ -3111,6 +3688,7 @@ ENDMAINFORMHEAD
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $vgr = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
+ my $mgr = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
my @menu =
( { divider=>'Settings for Your Course',
@@ -3128,6 +3706,11 @@ ENDMAINFORMHEAD
url => '/adm/slotrequest?command=showslots',
permission => $vgr,
},
+ { text => 'Reset Student Access Times',
+ url => '/adm/helper/resettimes.helper',
+ permission => $mgr,
+ },
+
{ text => 'Set Parameter Setting Default Actions',
action => 'setdefaults',
permission => $parm_permission,
@@ -3188,15 +3771,8 @@ ENDMAINFORMHEAD
}
### Set portfolio metadata
sub output_row {
- my ($r, $field_name, $field_text, $added_flag, $alt_row) = @_;
- my $row_class;
- if ($alt_row) {
- $row_class = ' class="LC_metadata_light" ';
- } else {
- $row_class = ' class="LC_metadata_dark" ';
- }
+ my ($r, $field_name, $field_text, $added_flag) = @_;
my $output;
- $output = "";
my $options=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'};
my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.values'};
if (!defined($options)) {
@@ -3204,23 +3780,47 @@ sub output_row {
$values = '';
}
if (!($options =~ /deleted/)) {
- $output = " ";
- $output .= ''.$field_text.': ';
- $output .= ' ';
- $output .= " \n";
my @options= ( ['active', 'Show to student'],
- ['onlyone','Student may select only one choice'],
- ['stuadd', 'Student may type choices']);
+ ['stuadd', 'Provide text area for students to type catalog information'],
+ ['choices','Provide choices for students to select from']);
+# ['onlyone','Student may select only one choice']);
if ($added_flag) {
push @options,['deleted', 'Delete Metadata Field'];
}
+ $output = &Apache::loncommon::start_data_table_row();
+ $output .= ''.$field_text.': ';
+ $output .= &Apache::loncommon::end_data_table_row();
foreach my $opt (@options) {
my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ;
- $output .= ''.(' ' x 5).' '.
- &mt($opt->[1]).' '."\n";
- }
-
+ $output .= &Apache::loncommon::continue_data_table_row();
+ $output .= ''.(' ' x 5).'
+ '.
+ &mt($opt->[1]).' ';
+ $output .= &Apache::loncommon::end_data_table_row();
+ }
+ $output .= &Apache::loncommon::continue_data_table_row();
+ $output .= ''.(' ' x 10).' ';
+ $output .= &Apache::loncommon::end_data_table_row();
+ my $multiple_checked;
+ my $single_checked;
+ if ($options =~ m/onlyone/) {
+ $multiple_checked = '';
+ $single_checked = ' checked="checked"';
+ } else {
+ $multiple_checked = ' checked="checked"';
+ $single_checked = '';
+ }
+ $output .= &Apache::loncommon::continue_data_table_row();
+ $output .= ''.(' ' x 10).'
+
+ '.&mt('Student may select multiple choices from list').' ';
+ $output .= &Apache::loncommon::end_data_table_row();
+ $output .= &Apache::loncommon::continue_data_table_row();
+ $output .= ''.(' ' x 10).'
+
+ '.&mt('Student may select only one choice from list').' ';
+ $output .= &Apache::loncommon::end_data_table_row();
}
return ($output);
}
@@ -3269,9 +3869,9 @@ sub order_meta_fields {
my $ordered_fields = join ",", @neworder;
my $put_result = &Apache::lonnet::put('environment',
{'metadata.addedorder'=>$ordered_fields},$dom,$crs);
- &Apache::lonnet::appenv('course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields);
+ &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields});
}
- my $fields = &get_added_meta_fieldnames();
+ my $fields = &get_added_meta_fieldnames($env{'request.course.id'});
my $ordered_fields;
my @fields_in_order = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};
if (!@fields_in_order) {
@@ -3306,6 +3906,13 @@ sub order_meta_fields {
$r->print('
');
return 'ok';
}
+sub continue {
+ my $output;
+ $output .= '');
@@ -3350,8 +3956,8 @@ sub addmetafield {
$r->print('Or you may enter a new metadata field name.');
}
+ $r->print('');
}
sub setrestrictmeta {
my ($r)=@_;
@@ -3376,7 +3982,10 @@ sub setrestrictmeta {
if ($env{'form.'.$meta_field.'_stuadd'}) {
$options.='stuadd,';
}
- if ($env{'form.'.$meta_field.'_onlyone'}) {
+ if ($env{'form.'.$meta_field.'_choices'}) {
+ $options.='choices,';
+ }
+ if ($env{'form.'.$meta_field.'_onlyone'} eq 'single') {
$options.='onlyone,';
}
if ($env{'form.'.$meta_field.'_active'}) {
@@ -3385,7 +3994,6 @@ sub setrestrictmeta {
if ($env{'form.'.$meta_field.'_deleted'}) {
$options.='deleted,';
}
-
my $name = $save_field;
$put_result = &Apache::lonnet::put('environment',
{'metadata.'.$meta_field.'.options'=>$options,
@@ -3400,32 +4008,35 @@ sub setrestrictmeta {
# Get the default metadata fields
my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
# Now get possible added metadata fields
- my $added_metadata_fields = &get_added_meta_fieldnames(\%metadata_fields);
+ my $added_metadata_fields = &get_added_meta_fieldnames($env{'request.course.id'});
my $row_alt = 1;
- $output .= '";
+ $output .= &Apache::loncommon::end_data_table();
$r->print(<
$output
-
-
-
-
-
ENDenv
$r->print(&Apache::loncommon::end_page());
@@ -3433,9 +4044,10 @@ ENDenv
}
##################################################
sub get_added_meta_fieldnames {
+ my ($cid) = @_;
my %fields;
foreach my $key(%env) {
- if ($key =~ m/\.metadata\.(.+)\.added$/) {
+ if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
my $field_name = $1;
my ($display_field_name) = $env{$key};
$fields{$field_name} = $display_field_name;
@@ -3444,10 +4056,10 @@ sub get_added_meta_fieldnames {
return \%fields;
}
sub get_deleted_meta_fieldnames {
+ my ($cid) = @_;
my %fields;
- my ($default_fields) = @_;
foreach my $key(%env) {
- if ($key =~ m/\.metadata\.(.+)\.added$/) {
+ if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
my $field_name = $1;
if ($env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/) {
my ($display_field_name) = $env{$key};
@@ -3612,7 +4224,7 @@ ENDYESNO
}
$r->print(&Apache::loncommon::end_data_table().
"\n \n".
+ &mt('Save Rules')."' />\n".
&Apache::loncommon::end_page());
return;
}
@@ -3670,7 +4282,6 @@ sub load_parameter_names {
close($config);
$standard_parms{'int_pos'} = 'Positive Integer';
$standard_parms{'int_zero_pos'} = 'Positive Integer or Zero';
- %standard_parms=&Apache::lonlocal::texthash(%standard_parms);
}
sub standard_parameter_names {
@@ -3709,13 +4320,7 @@ sub parm_change_log {
\%saveable_parameters);
&Apache::loncommon::restore_course_settings('parameter_log',
\%saveable_parameters);
- if (!$env{'form.show'}) { $env{'form.show'}=10; }
-
- my $countselect =
- &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
- (&mt('all'),10,20,50,100,1000,10000));
-
- $r->print(''.&mt('[_1] Records',$countselect).' '.
+ $r->print(&Apache::loncommon::display_filter().
''.&Apache::lonhtmlcommon::checkbox('includetypes',$env{'form.includetypes'},'1').
' '.&mt('Include parameter types').' '.
' ');
@@ -3727,7 +4332,25 @@ sub parm_change_log {
&mt('Parameter').''.&mt('Part').' '.&mt('New Value').' '.&mt('Announce').' '.
&Apache::loncommon::end_data_table_header_row());
my $shown=0;
- foreach my $id (sort { $parmlog{$b}{'exe_time'}<=>$parmlog{$a}{'exe_time'} } (keys(%parmlog))) {
+ my $folder='';
+ if ($env{'form.displayfilter'} eq 'currentfolder') {
+ my $last='';
+ if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
+ &GDBM_READER(),0640)) {
+ $last=$hash{'last_known'};
+ untie(%hash);
+ }
+ if ($last) { ($folder) = &Apache::lonnet::decode_symb($last); }
+ }
+ foreach my $id (sort
+ {
+ if ($parmlog{$b}{'exe_time'} ne $parmlog{$a}{'exe_time'}) {
+ return $parmlog{$b}{'exe_time'} <=>$parmlog{$a}{'exe_time'}
+ }
+ my $aid = (split('00000',$a))[-1];
+ my $bid = (split('00000',$b))[-1];
+ return $bid<=>$aid;
+ } (keys(%parmlog))) {
my @changes=keys(%{$parmlog{$id}{'logentry'}});
my $count = 0;
my $time =
@@ -3748,7 +4371,6 @@ sub parm_change_log {
$parmlog{$id}{'exe_udom'});
}
my $row_start=&Apache::loncommon::start_data_table_row();
- $r->print($row_start);
my $makenewrow=0;
my %istype=();
my $output;
@@ -3758,6 +4380,11 @@ sub parm_change_log {
!exists($parmlog{$id}{'logentry'}{$changed.'.type'}));
my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)=
&components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},undef,undef,$typeflag);
+ if ($env{'form.displayfilter'} eq 'currentfolder') {
+ if ($folder) {
+ if ($middle!~/^\Q$folder\E/) { next; }
+ }
+ }
if ($typeflag) {
$istype{$parmname}=$value;
if (!$env{'form.includetypes'}) { next; }
@@ -3768,15 +4395,18 @@ sub parm_change_log {
} else {
$makenewrow=1;
}
+ my $parmitem = &standard_parameter_names($parmname);
$output .=''.$realm.' '.$section.' '.
- &standard_parameter_names($parmname).' '.
+ &mt($parmitem).' '.
($part?&mt('Part: [_1]',$part):&mt('All Parts')).' ';
my $stillactive=0;
if ($parmlog{$id}{'delflag'}) {
$output .= &mt('Deleted');
} else {
if ($typeflag) {
- $output .= &mt('Type: [_1]',&standard_parameter_names($value));
+ my $parmitem = &standard_parameter_names($value);
+ $parmitem = &mt($parmitem);
+ $output .= &mt('Type: [_1]',$parmitem);
} else {
my ($level,@all)=&parmval_by_symb($what,$middle,&Apache::lonnet::metadata($middle,$what),
$uname,$udom,$issection,$issection,$courseopt);
@@ -3794,8 +4424,11 @@ sub parm_change_log {
}
$output .= ' ';
if ($stillactive) {
- my $title=&mt('Changed [_1]',&standard_parameter_names($parmname));
- my $description=&mt('Changed [_1] for [_2] to [_3]',&standard_parameter_names($parmname),$realmdescription,
+ my $parmitem = &standard_parameter_names($parmname);
+ $parmitem = &mt($parmitem);
+ my $title=&mt('Changed [_1]',$parmitem);
+ my $description=&mt('Changed [_1] for [_2] to [_3]',
+ $parmitem,$realmdescription,
(&isdateparm($istype{$parmname})?&Apache::lonlocal::locallocaltime($value):$value));
if (($uname) && ($udom)) {
$output .=
@@ -3810,13 +4443,20 @@ sub parm_change_log {
}
$output .= ' '.&Apache::loncommon::end_data_table_row();
}
- $r->print(''.$time.'
+ if ($env{'form.displayfilter'} eq 'containing') {
+ my $wholeentry=$about_me_link.':'.
+ $parmlog{$id}{'exe_uname'}.':'.$parmlog{$id}{'exe_udom'}.':'.
+ $output;
+ if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
+ }
+ if ($count) {
+ $r->print($row_start.''.$time.'
'.$about_me_link.
''.$parmlog{$id}{'exe_uname'}.
':'.$parmlog{$id}{'exe_udom'}.' '.
$send_msg_link.' '.$output);
-
- $shown++;
+ $shown++;
+ }
if (!($env{'form.show'} eq &mt('all')
|| $shown<=$env{'form.show'})) { last; }
}
@@ -3824,6 +4464,12 @@ sub parm_change_log {
$r->print(&Apache::loncommon::end_page());
}
+sub check_for_course_info {
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ return 1 if ($navmap);
+ return 0;
+}
+
##################################################
##################################################
@@ -3834,14 +4480,15 @@ sub parm_change_log {
Main handler. Calls &assessparms and &crsenv subroutines.
=cut
+
##################################################
##################################################
-# use Data::Dumper;
-
sub handler {
my $r=shift;
+ &reset_caches();
+
if ($r->header_only) {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
@@ -3852,7 +4499,7 @@ sub handler {
'pres_marker',
'pres_value',
'pres_type',
- 'udom','uname','symb','serial']);
+ 'udom','uname','symb','serial','timebase']);
&Apache::lonhtmlcommon::clear_breadcrumbs();
@@ -3867,17 +4514,15 @@ sub handler {
(&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
&Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
$env{'request.course.sec'}));
- if ($env{'request.course.id'} && $parm_permission) {
+ my $exists = &check_for_course_info();
+
+ if ($env{'request.course.id'} && $parm_permission && $exists) {
# Start Page
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
- # id numbers can change on re-ordering of folders
-
- &resetsymbcache();
-
#
# Main switch on form.action and form.state, as appropriate
#
@@ -3934,13 +4579,30 @@ sub handler {
&Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=cleanparameters',
text=>"Clean Parameters"});
&clean_parameters($r);
- }
+ } elsif ($env{'form.action'} eq 'dateshift1' && $parm_permission) {
+ &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
+ text=>"Shifting Dates"});
+ &date_shift_one($r);
+ } elsif ($env{'form.action'} eq 'dateshift2' && $parm_permission) {
+ &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
+ text=>"Shifting Dates"});
+ &date_shift_two($r);
+ } elsif ($env{'form.action'} eq 'categorizecourse' && $parm_permission) {
+ &assign_course_categories($r);
+ }
} else {
# ----------------------------- Not in a course, or not allowed to modify parms
- $env{'user.error.msg'}=
- "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
+ if ($exists) {
+ $env{'user.error.msg'}=
+ "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
+ } else {
+ $env{'user.error.msg'}=
+ "/adm/parmset::0:1:Course environment gone, reinitialize the course";
+ }
return HTTP_NOT_ACCEPTABLE;
}
+ &reset_caches();
+
return OK;
}