--- loncom/interface/lonparmset.pm 2000/11/21 12:22:29 1.2
+++ loncom/interface/lonparmset.pm 2002/08/21 17:18:08 1.64
@@ -1,196 +1,1504 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# (Handler to resolve ambiguous file locations
+# $Id: lonparmset.pm,v 1.64 2002/08/21 17:18:08 www 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 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::loncommon;
use GDBM_File;
+use Apache::lonhomework;
+use Apache::lonxml;
+
my %courseopt;
my %useropt;
-my %bighash;
my %parmhash;
-my @srcp;
-my @typep;
-my @resp;
-my @mapp;
-my @symbp;
+my @ids;
+my %symbp;
+my %mapp;
+my %typep;
+my %keyp;
my $uname;
my $udom;
my $uhome;
-
my $csec;
+my $coursename;
+
+##################################################
+##################################################
+
+=pod
-# -------------------------------------------- Figure out a cascading parameter
+=item parmval
+Figure out a cascading parameter.
+
+Inputs: $what $id $def
+
+Returns: I am not entirely sure.
+
+=cut
+
+##################################################
+##################################################
sub parmval {
- my ($what,$idx)=@_;
+ my ($what,$id,$def)=@_;
+ my $result='';
+ my @outpar=();
# ----------------------------------------------------- Cascading lookup scheme
- my $symbparm=$symbp[$idx].'.'.$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
+ my $symbparm=$symbp{$id}.'.'.$what;
+ my $mapparm=$mapp{$id}.'___(all).'.$what;
- 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;
+
+ my $courselevel=$ENV{'request.course.id'}.'.'.$what;
+ my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
+ my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
+
+# -------------------------------------------------------- first, check default
+
+ if ($def) { $outpar[11]=$def; $result=11; }
+
+# ----------------------------------------------------- second, check map parms
+
+ my $thisparm=$parmhash{$symbparm};
+ if ($thisparm) { $outpar[10]=$thisparm; $result=10; }
+
+# --------------------------------------------------------- third, check course
+
+ if ($courseopt{$courselevel}) {
+ $outpar[9]=$courseopt{$courselevel};
+ $result=9;
+ }
+
+ if ($courseopt{$courselevelm}) {
+ $outpar[8]=$courseopt{$courselevelm};
+ $result=8;
+ }
+
+ if ($courseopt{$courselevelr}) {
+ $outpar[7]=$courseopt{$courselevelr};
+ $result=7;
+ }
+
+ 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;
+ }
+ }
+
+# ---------------------------------------------------------- fourth, 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;
+ }
+ }
-# -------------------------------------------------------- second, check course
+ return ($result,@outpar);
+}
- if ($courseopt{$reslevel}) { return $courseopt{$reslevel}; }
- if ($courseopt{$seclevel}) { return $courseopt{$seclevel}; }
- if ($courseopt{$courselevel}) { return $courseopt{$courselevel}; }
+##################################################
+##################################################
-# ------------------------------------------------------ third, check map parms
+=pod
- my $thisparm=$parmhash{$symbparm};
- if ($thisparm) { return $thisparm; }
+=item valout
-
-# --------------------------------------------- last, look in resource metadata
+Format a value for output.
- my $filename='/home/httpd/res/'.$srcp[$idx].'.meta';
- if (-e $filename) {
- my @content;
- {
- my $fh=Apache::File->new($filename);
- @content=<$fh>;
- }
- if (join('',@content)=~
- /\<$what[^\>]*\>([^\<]*)\<\/$what\>/) {
- return $1;
- }
+Inputs: $value, $type
+
+Returns: $value, formatted for output. If $type indicates it is a date,
+localtime($value) is returned.
+
+=cut
+
+##################################################
+##################################################
+sub valout {
+ my ($value,$type)=@_;
+ my $result = '';
+ # Values of zero are valid.
+ if (! $value && $value ne '0') {
+ $result = ' ';
+ } else {
+ if ($type=~/^date/) {
+ $result = localtime($value);
+ } else {
+ $result = $value;
}
- return '';
+ }
+ return $result;
}
-# ================================================================ Main Handler
+##################################################
+##################################################
-sub handler {
- my $r=shift;
+=pod
- if ($r->header_only) {
- $r->content_type('text/html');
- $r->send_http_header;
- return OK;
- }
+=item plink
-# ----------------------------------------------------- Needs to be in a course
+Produces a link anchor.
- if (($ENV{'request.course.fn'}) &&
- (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
-# -------------------------------------------------------- Variable declaration
+Inputs: $type,$dis,$value,$marker,$return,$call
- %courseopt=();
- %useropt=();
- %bighash=();
-
- @srcp=();
- @typep=();
- @resp=();
- @mapp=();
- @symbp=();
-
- $uname=$ENV{'form.uname'};
- $udom=$ENV{'form.udom'};
- unless ($udom) { $uname=''; }
- $uhome='';
- if ($uname) {
- $uhome=&Apache::lonnet::homeserver($uname,$udom);
- }
+Returns: scalar with html code for a link which will envoke the
+javascript function 'pjump'.
- $csec=$ENV{'form.csec'};
+=cut
-# ------------------------------------------------------------------- Tie hashs
- if ((tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
- &GDBM_READER,0640)) &&
- (tie(%parmhash,'GDBM_File',
- $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640))) {
+##################################################
+##################################################
+sub plink {
+ my ($type,$dis,$value,$marker,$return,$call)=@_;
+ my $winvalue=$value;
+ unless ($winvalue) {
+ if ($type=~/^date/) {
+ $winvalue=$ENV{'form.recent_'.$type};
+ } else {
+ $winvalue=$ENV{'form.recent_'.(split(/\_/,$type))[0]};
+ }
+ }
+ return
+ ''.
+ &valout($value,$type).'';
+}
-# -------------------------------------------------------------- Get coursedata
- my $reply=&Apache::lonnet::reply('dump:'.
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':resourcedata',
- $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
- if ($reply!~/^error\:/) {
- map {
- my ($name,$value)=split(/\=/,$_);
- $courseopt{unescape($name)}=unescape($value);
- } split(/\&/,$reply);
+
+sub startpage {
+ my ($r,$id,$udom,$csec,$uname)=@_;
+ $r->content_type('text/html');
+ $r->send_http_header;
+
+ my $bodytag=&Apache::loncommon::bodytag('Set Course Parameters','',
+ 'onUnload="pclose()"');
+ $r->print(<
+
+LON-CAPA Course Parameters
+
+
+$bodytag
+
+