--- loncom/interface/lonparmset.pm 2000/11/23 20:50:41 1.7
+++ loncom/interface/lonparmset.pm 2008/11/17 16:57:06 1.415
@@ -1,299 +1,4577 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# (Handler to resolve ambiguous file locations
+# $Id: lonparmset.pm,v 1.415 2008/11/17 16:57:06 schafran Exp $
#
-# (TeX Content Handler
+# Copyright Michigan State University Board of Trustees
#
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
-# 10/11,10/12,10/16 Gerd Kortemeyer)
+# LON-CAPA is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
#
-# 11/20,11/21,11/22,11/23 Gerd Kortemeyer
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# /home/httpd/html/adm/gpl.txt
+#
+# http://www.lon-capa.org/
+#
+###################################################################
+###################################################################
+
+=pod
+
+=head1 NAME
+
+lonparmset - Handler to set parameters for assessments and course
+
+=head1 SYNOPSIS
+
+lonparmset provides an interface to setting course parameters.
+
+=head1 DESCRIPTION
+
+This module sets coursewide and assessment parameters.
+
+=head1 INTERNAL SUBROUTINES
+
+=over 4
+
+=cut
+
+###################################################################
+###################################################################
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::lonmeta;
+use Apache::lonhomework;
+use Apache::lonxml;
+use Apache::lonlocal;
+use Apache::lonnavmaps;
+use Apache::longroup;
+use Apache::lonrss;
+use LONCAPA qw(:DEFAULT :match);
+
+
+##################################################
+##################################################
+
+=pod
+
+=item parmval
+
+Figure out a cascading parameter.
+
+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
-my %courseopt;
-my %useropt;
-my %bighash;
-my %parmhash;
+##################################################
+sub parmval {
+ my ($what,$id,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
+ return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec,
+ $cgroup,$courseopt);
+}
-my @ids;
-my %symbp;
-my %typep;
+sub parmval_by_symb {
+ my ($what,$symb,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
-my $uname;
-my $udom;
-my $uhome;
+ my $useropt;
+ if ($uname ne '' && $udom ne '') {
+ $useropt = &Apache::lonnet::get_userresdata($uname,$udom);
+ }
-my $csec;
+ my $result='';
+ my @outpar=();
+# ----------------------------------------------------- Cascading lookup scheme
+ my $map=(&Apache::lonnet::decode_symb($symb))[0];
+ $map = &Apache::lonnet::deversion($map);
-my $fcat;
+ my $symbparm=$symb.'.'.$what;
+ my $mapparm=$map.'___(all).'.$what;
-# -------------------------------------------- Figure out a cascading parameter
+ my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$what;
+ my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
+ my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
-sub parmval {
- my ($what,$id)=@_;
-# ----------------------------------------------------- Cascading lookup scheme
- my $symbparm=$symbp{$id}.'.'.$what;
- my $reslevel=
- $ENV{'request.course.id'}.'.'.$symbparm;
- my $seclevel=
- $ENV{'request.course.id'}.'.'.
- $ENV{'request.course.sec'}.'.'.$what;
- my $courselevel=
- $ENV{'request.course.id'}.'.'.$what;
-
-# ----------------------------------------------------------- first, check user
-
- if ($uname) {
- if ($useropt{$reslevel}) { return $useropt{$reslevel}; }
- if ($useropt{$seclevel}) { return $useropt{$seclevel}; }
- if ($useropt{$courselevel}) { return $useropt{$courselevel}; }
- }
+ my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
+ my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
+ my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
-# -------------------------------------------------------- second, check course
+ my $courselevel=$env{'request.course.id'}.'.'.$what;
+ my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
+ my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
- if ($courseopt{$reslevel}) { return $courseopt{$reslevel}; }
- if ($courseopt{$seclevel}) { return $courseopt{$seclevel}; }
- if ($courseopt{$courselevel}) { return $courseopt{$courselevel}; }
+
+# --------------------------------------------------------- first, check course
+
+ if (defined($$courseopt{$courselevel})) {
+ $outpar[14]=$$courseopt{$courselevel};
+ $result=14;
+ }
+
+ if (defined($$courseopt{$courselevelm})) {
+ $outpar[13]=$$courseopt{$courselevelm};
+ $result=13;
+ }
+
+# ------------------------------------------------------- second, check default
+
+ if (defined($def)) { $outpar[12]=$def; $result=12; }
# ------------------------------------------------------ third, check map parms
- my $thisparm=$parmhash{$symbparm};
- if ($thisparm) { return $thisparm; }
-
-# --------------------------------------------- last, look in resource metadata
+ my $thisparm=&parmhash($symbparm);
+ if (defined($thisparm)) { $outpar[11]=$thisparm; $result=11; }
- my $filename='/home/httpd/res/'.$bighash{'src_'.$id}.'.meta';
- if (-e $filename) {
- my @content;
- {
- my $fh=Apache::File->new($filename);
- @content=<$fh>;
- }
- if (join('',@content)=~
- /\<$what[^\>]*\>([^\<]*)\<\/$what\>/) {
- return $1;
- }
+ if (defined($$courseopt{$courselevelr})) {
+ $outpar[10]=$$courseopt{$courselevelr};
+ $result=10;
+ }
+
+# ------------------------------------------------------ fourth, back to course
+ if ($csec ne '') {
+ if (defined($$courseopt{$seclevel})) {
+ $outpar[9]=$$courseopt{$seclevel};
+ $result=9;
+ }
+ if (defined($$courseopt{$seclevelm})) {
+ $outpar[8]=$$courseopt{$seclevelm};
+ $result=8;
+ }
+
+ 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;
}
- return '';
-}
+ if (defined($$courseopt{$grplevelm})) {
+ $outpar[5]=$$courseopt{$grplevelm};
+ $result=5;
+ }
+ if (defined($$courseopt{$grplevelr})) {
+ $outpar[4]=$$courseopt{$grplevelr};
+ $result=4;
+ }
+ }
-# ---------------------------------------------------------------- Sort routine
+# ---------------------------------------------------------- fifth, check user
-sub bycat {
- if ($fcat eq '') {
- $a<=>$b;
- } else {
- &parmval('0.'.$fcat,$a)<=>&parmval('0.'.$fcat,$b);
+ if ($uname ne '') {
+ if (defined($$useropt{$courselevel})) {
+ $outpar[3]=$$useropt{$courselevel};
+ $result=3;
+ }
+
+ if (defined($$useropt{$courselevelm})) {
+ $outpar[2]=$$useropt{$courselevelm};
+ $result=2;
+ }
+
+ if (defined($$useropt{$courselevelr})) {
+ $outpar[1]=$$useropt{$courselevelr};
+ $result=1;
+ }
}
+ return ($result,@outpar);
}
-# -------------------------------------------------------- Produces link anchor
-sub plink {
- my ($type,$dis,$value,$marker,$return,$call)=@_;
- return ''.
- (($type=~/^date/)?localtime($value):$value).'';
+
+# --- Caches local to lonparmset
+
+
+sub reset_caches {
+ &resetparmhash();
+ &resetsymbcache();
+ &resetrulescache();
}
-# ================================================================ Main Handler
+{
+ 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};
+ }
+ }
-sub handler {
- my $r=shift;
+{
+ 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};
+ }
+ }
- if ($r->header_only) {
- $r->content_type('text/html');
- $r->send_http_header;
- return OK;
- }
+{
+ 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};
+ }
+}
-# ----------------------------------------------------- Needs to be in a course
+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 ('','','','','');
+ }
+}
- if (($ENV{'request.course.fn'}) &&
- (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
-# -------------------------------------------------------- Variable declaration
+##################################################
- %courseopt=();
- %useropt=();
- %bighash=();
-
- @ids=();
- %symbp=();
- %typep=();
-
- $uname=$ENV{'form.uname'};
- $udom=$ENV{'form.udom'};
- unless ($udom) { $uname=''; }
- $uhome='';
- my $message='';
- if ($uname) {
- $uhome=&Apache::lonnet::homeserver($uname,$udom);
+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 ($uhome eq 'no_host') {
- $message=
- "
Unknown User $uname at Domain $udom
";
- $uname='';
+ }
+ 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