--- loncom/interface/lonparmset.pm 2002/02/12 06:28:23 1.44
+++ loncom/interface/lonparmset.pm 2011/01/15 15:14:47 1.508
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.44 2002/02/12 06:28:23 albertel Exp $
+# $Id: lonparmset.pm,v 1.508 2011/01/15 15:14:47 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,184 +25,834 @@
#
# http://www.lon-capa.org/
#
-# (Handler to resolve ambiguous file locations
-#
-# (TeX Content Handler
-#
-# YEAR=2000
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
-#
-# 10/11,10/12,10/16 Gerd Kortemeyer)
-#
-# 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
-# 12/08,12/12,
-# YEAR=2001
-# 16/01/01,02/08,03/20,03/23,03/24,03/26,05/09,
-# 07/05,07/06,08/08,08/09,09/01,09/21 Gerd Kortemeyer
-# 12/17 Scott Harrison
-# 12/19 Guy Albertelli
-# 12/26,12/27 Gerd Kortemeyer
-#
-###
+###################################################################
+###################################################################
+
+=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
+
+=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
+
+=item parmval_by_symb()
+
+=item reset_caches()
+
+=item cacheparmhash()
+
+=item parmhash()
+
+=item symbcache()
+
+=item preset_defaults()
+
+=item date_sanity_info()
+
+=item storeparm()
+
+Store a parameter by symb
+
+ Takes
+ - symb
+ - name of parameter
+ - level
+ - new value
+ - new type
+ - username
+ - userdomain
+
+=item log_parmset()
+
+=item storeparm_by_symb_inner()
+
+=item valout()
+
+Format a value for output.
+
+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
+
+=item plink()
+
+Produces a link anchor.
+
+Inputs: $type,$dis,$value,$marker,$return,$call
+
+Returns: scalar with html code for a link which will envoke the
+javascript function 'pjump'.
+
+=item page_js()
+
+=item startpage()
+
+=item print_row()
+
+=item print_td()
+
+=item print_usergroups()
+
+=item parm_control_group()
+
+=item extractResourceInformation() :
+
+Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
+
+Input: See list below:
+
+=item * B : An array that will contain all of the ids in the course.
+
+=item * B : hash, id->type, where "type" contains the extension of the file, thus, I.
+
+=item * B : hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
+
+=item * B : hash, name of parameter->display value (what is the display value?)
+
+=item * B : hash, part identification->text representation of part, where the text representation is "[Part $part]"
+
+=item * B : hash, full key to part->display value (what's display value?)
+
+=item * B : hash, ???
+
+=item * B : ???
+
+=item * B : hash, ???
+
+=item * B : ??
+
+=item * B : hash, id->full sym?
+
+
+
+=item isdateparm()
+
+=item parmmenu()
+
+=item partmenu()
+
+=item usermenu()
+
+=item displaymenu()
+
+=item mapmenu()
+
+=item levelmenu()
+
+=item sectionmenu()
+
+=item keysplit()
+
+=item keysinorder()
+
+=item keysinorder_bytype()
+
+=item keysindisplayorder()
+
+=item standardkeyorder()
+
+=item assessparms() :
+
+Show assessment data and parameters. This is a large routine that should
+be simplified and shortened... someday.
+
+Inputs: $r
+
+Returns: nothing
+
+Variables used (guessed by Jeremy):
+
+=item * B: ParameterS CATegories? ends up a list of the types of parameters that exist, e.g., tol, weight, acc, opendate, duedate, answerdate, sig, maxtries, type.
+
+=item * B: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
+
+=item * B<@catmarker> contains list of all possible parameters including part #s
+
+=item * B<$fullkeyp> contains the full part/id # for the extraction of proper parameters
+
+=item * B<$tempkeyp> contains part 0 only (no ids - ie, subparts)
+ When storing information, store as part 0
+ When requesting information, request from full part
+
+=item tablestart()
+
+=item tableend()
+
+=item extractuser()
+
+=item parse_listdata_key()
+
+=item listdata()
+
+=item date_interval_selector()
+
+=item get_date_interval_from_form()
+
+=item default_selector()
+
+=item string_selector()
+
+=item dateshift()
+
+=item newoverview()
+
+=item secgroup_lister()
+
+=item overview()
+
+=item clean_parameters()
+
+=item date_shift_one()
+
+=item date_shift_two()
+
+=item parse_key()
+
+=item header()
+
+Output html header for page
+
+=item print_main_menu()
+
+=item output_row()
+
+Set portfolio metadata
+
+=item order_meta_fields()
+
+=item addmetafield()
+
+=item setrestrictmeta()
+
+=item get_added_meta_fieldnames()
+
+=item get_deleted_meta_fieldnames()
+
+=item defaultsetter()
+
+=item components()
+
+=item load_parameter_names()
+
+=item parm_change_log()
+
+=item handler() :
+
+Main handler. Calls &assessparms subroutine.
+
+
+=back
+
+=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::lonhomework;
+use Apache::lonxml;
+use Apache::lonlocal;
+use Apache::lonnavmaps;
+use Apache::longroup;
+use Apache::lonrss;
+use HTML::Entities;
+use LONCAPA qw(:DEFAULT :match);
+
+
+sub startSettingsScreen {
+ my ($r,$mode)=@_;
+
+ $r->print("\n".'
');
+}
+sub endSettingsScreen {
+ my ($r)=@_;
+ $r->print('
');
+}
-my %courseopt;
-my %useropt;
-my %parmhash;
-
-my @ids;
-my %symbp;
-my %mapp;
-my %typep;
-my %keyp;
-
-my $uname;
-my $udom;
-my $uhome;
-my $csec;
-# -------------------------------------------- Figure out a cascading parameter
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 $symbparm=$symb.'.'.$what;
+ my $mapparm=$map.'___(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 $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$what;
+ my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
+ my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
- my $courselevel=$ENV{'request.course.id'}.'.'.$what;
- my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
- my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
+ my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
+ my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
+ my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
-# -------------------------------------------------------- first, check default
+ my $courselevel=$env{'request.course.id'}.'.'.$what;
+ my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
+ my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
- if ($def) { $outpar[11]=$def; $result=11; }
-# ----------------------------------------------------- second, check map parms
+# --------------------------------------------------------- first, check course
- my $thisparm=$parmhash{$symbparm};
- if ($thisparm) { $outpar[10]=$thisparm; $result=10; }
-
-# --------------------------------------------------------- third, check course
+ if (defined($$courseopt{$courselevel})) {
+ $outpar[14]=$$courseopt{$courselevel};
+ $result=14;
+ }
- if ($courseopt{$courselevel}) {
- $outpar[9]=$courseopt{$courselevel};
- $result=9;
+ if (defined($$courseopt{$courselevelm})) {
+ $outpar[13]=$$courseopt{$courselevelm};
+ $result=13;
}
- if ($courseopt{$courselevelm}) {
- $outpar[8]=$courseopt{$courselevelm};
- $result=8;
+# ------------------------------------------------------- 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 ($courseopt{$courselevelr}) {
- $outpar[7]=$courseopt{$courselevelr};
- $result=7;
+# ------------------------------------------------------ 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 ($csec) {
- if ($courseopt{$seclevel}) {
- $outpar[6]=$courseopt{$seclevel};
- $result=6;
- }
- if ($courseopt{$seclevelm}) {
- $outpar[5]=$courseopt{$seclevelm};
- $result=5;
- }
-
- 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};
- $result=3;
- }
-
- if ($useropt{$courselevelm}) {
- $outpar[2]=$useropt{$courselevelm};
- $result=2;
- }
-
- if ($useropt{$courselevelr}) {
- $outpar[1]=$useropt{$courselevelr};
- $result=1;
- }
+ 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);
}
-# ------------------------------------------------------------ Output for value
+
+
+# --- 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
'
+ .''
+ );
+ } # end of $parmlev eq general
+ }
+ $r->print('');
+ &endSettingsScreen($r);
+ $r->print(&Apache::loncommon::end_page());
+} # end sub assessparms
+
+##################################################
+# Overview mode
+##################################################
+my $tableopen;
+
+sub tablestart {
+ if ($tableopen) {
+ return '';
+ } else {
+ $tableopen=1;
+ return &Apache::loncommon::start_data_table().'