--- loncom/interface/lonparmset.pm 2002/08/29 03:57:45 1.61.2.1
+++ loncom/interface/lonparmset.pm 2008/10/23 14:26:17 1.413
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.61.2.1 2002/08/29 03:57:45 albertel Exp $
+# $Id: lonparmset.pm,v 1.413 2008/10/23 14:26:17 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -56,28 +56,18 @@ package Apache::lonparmset;
use strict;
use Apache::lonnet;
use Apache::Constants qw(:common :http REDIRECT);
+use Apache::lonhtmlcommon();
use Apache::loncommon;
use GDBM_File;
use Apache::lonhomework;
use Apache::lonxml;
+use Apache::lonlocal;
+use Apache::lonnavmaps;
+use Apache::longroup;
+use Apache::lonrss;
+use LONCAPA qw(:DEFAULT :match);
-my %courseopt;
-my %useropt;
-my %parmhash;
-
-my @ids;
-my %symbp;
-my %mapp;
-my %typep;
-my %keyp;
-
-my $uname;
-my $udom;
-my $uhome;
-my $csec;
-my $coursename;
-
##################################################
##################################################
@@ -87,95 +77,465 @@ my $coursename;
Figure out a cascading parameter.
-Inputs: $what $id $def
-
-Returns: I am not entirely sure.
+Inputs: $what - a parameter spec (incluse part info and name I.E. 0.weight)
+ $id - a bighash Id number
+ $def - the resource's default value 'stupid emacs
+
+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
+12- resource default
+11- map default
+10- resource level in course
+9 - General for section
+8 - Map or Folder level for section
+7 - resource level in section
+6 - General for group
+5 - Map or Folder level for group
+4 - resource level in group
+3 - General for specific student
+2 - Map or Folder level for specific student
+1 - resource level for specific student
=cut
##################################################
-##################################################
sub parmval {
- my ($what,$id,$def)=@_;
+ 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,$courseopt)=@_;
+
+ 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=$symbp{$id}.'.'.$what;
- my $mapparm=$mapp{$id}.'___(all).'.$what;
-
- my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$what;
- my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
- my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
+ my $symbparm=$symb.'.'.$what;
+ my $mapparm=$map.'___(all).'.$what;
- my $courselevel=$ENV{'request.course.id'}.'.'.$what;
- my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
- my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
+ my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$what;
+ my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
+ my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
-# -------------------------------------------------------- first, check default
+ my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
+ my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
+ my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
- if ($def) { $outpar[11]=$def; $result=11; }
+ my $courselevel=$env{'request.course.id'}.'.'.$what;
+ my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
+ my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
-# ----------------------------------------------------- second, check map parms
- my $thisparm=$parmhash{$symbparm};
- if ($thisparm) { $outpar[10]=$thisparm; $result=10; }
+# --------------------------------------------------------- first, check course
-# --------------------------------------------------------- third, check course
-
- if ($courseopt{$courselevel}) {
- $outpar[9]=$courseopt{$courselevel};
- $result=9;
+ if (defined($$courseopt{$courselevel})) {
+ $outpar[14]=$$courseopt{$courselevel};
+ $result=14;
}
- if ($courseopt{$courselevelm}) {
- $outpar[8]=$courseopt{$courselevelm};
- $result=8;
+ if (defined($$courseopt{$courselevelm})) {
+ $outpar[13]=$$courseopt{$courselevelm};
+ $result=13;
}
- if ($courseopt{$courselevelr}) {
- $outpar[7]=$courseopt{$courselevelr};
- $result=7;
+# ------------------------------------------------------- second, check default
+
+ if (defined($def)) { $outpar[12]=$def; $result=12; }
+
+# ------------------------------------------------------ third, check map parms
+
+ my $thisparm=&parmhash($symbparm);
+ if (defined($thisparm)) { $outpar[11]=$thisparm; $result=11; }
+
+ if (defined($$courseopt{$courselevelr})) {
+ $outpar[10]=$$courseopt{$courselevelr};
+ $result=10;
}
- if ($csec) {
- if ($courseopt{$seclevel}) {
- $outpar[6]=$courseopt{$seclevel};
- $result=6;
+# ------------------------------------------------------ fourth, back to course
+ if ($csec ne '') {
+ if (defined($$courseopt{$seclevel})) {
+ $outpar[9]=$$courseopt{$seclevel};
+ $result=9;
}
- if ($courseopt{$seclevelm}) {
- $outpar[5]=$courseopt{$seclevelm};
- $result=5;
+ if (defined($$courseopt{$seclevelm})) {
+ $outpar[8]=$$courseopt{$seclevelm};
+ $result=8;
}
- if ($courseopt{$seclevelr}) {
- $outpar[4]=$courseopt{$seclevelr};
- $result=4;
+ if (defined($$courseopt{$seclevelr})) {
+ $outpar[7]=$$courseopt{$seclevelr};
+ $result=7;
}
}
+# ------------------------------------------------------ fifth, check course group
+ if ($cgroup ne '') {
+ if (defined($$courseopt{$grplevel})) {
+ $outpar[6]=$$courseopt{$grplevel};
+ $result=6;
+ }
+ if (defined($$courseopt{$grplevelm})) {
+ $outpar[5]=$$courseopt{$grplevelm};
+ $result=5;
+ }
+ if (defined($$courseopt{$grplevelr})) {
+ $outpar[4]=$$courseopt{$grplevelr};
+ $result=4;
+ }
+ }
-# ---------------------------------------------------------- fourth, check user
+# ---------------------------------------------------------- fifth, check user
- if ($uname) {
- if ($useropt{$courselevel}) {
- $outpar[3]=$useropt{$courselevel};
+ if ($uname ne '') {
+ if (defined($$useropt{$courselevel})) {
+ $outpar[3]=$$useropt{$courselevel};
$result=3;
}
- if ($useropt{$courselevelm}) {
- $outpar[2]=$useropt{$courselevelm};
+ if (defined($$useropt{$courselevelm})) {
+ $outpar[2]=$$useropt{$courselevelm};
$result=2;
}
- if ($useropt{$courselevelr}) {
- $outpar[1]=$useropt{$courselevelr};
+ if (defined($$useropt{$courselevelr})) {
+ $outpar[1]=$$useropt{$courselevelr};
$result=1;
}
}
-
return ($result,@outpar);
}
+
+
+# --- Caches local to lonparmset
+
+
+sub reset_caches {
+ &resetparmhash();
+ &resetsymbcache();
+ &resetrulescache();
+}
+
+{
+ my $parmhashid;
+ my %parmhash;
+ sub resetparmhash {
+ undef($parmhashid);
+ undef(%parmhash);
+ }
+
+ 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 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};
+ }
+ }
+
+{
+ my $rulesid;
+ my %rules;
+ sub resetrulescache {
+ undef($rulesid);
+ undef(%rules);
+ }
+
+ 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};
+ }
+}
+
+sub preset_defaults {
+ my $type=shift;
+ if (&rulescache($type.'_action') eq 'default') {
+# yes, there is something
+ return (&rulescache($type.'_hours'),
+ &rulescache($type.'_min'),
+ &rulescache($type.'_sec'),
+ &rulescache($type.'_value'));
+ } else {
+# nothing there or something else
+ return ('','','','','');
+ }
+}
+
+##################################################
+
+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