--- loncom/interface/lonparmset.pm 2000/11/23 20:42:55 1.6 +++ loncom/interface/lonparmset.pm 2002/10/01 06:21:23 1.70 @@ -1,209 +1,286 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# (Handler to resolve ambiguous file locations +# $Id: lonparmset.pm,v 1.70 2002/10/01 06:21:23 albertel 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::loncommon; use GDBM_File; -use Apache::lonmeta; +use Apache::lonhomework; +use Apache::lonxml; my %courseopt; my %useropt; -my %bighash; my %parmhash; my @ids; my %symbp; +my %mapp; my %typep; +my %keyp; my $uname; my $udom; my $uhome; - my $csec; +my $coursename; + +################################################## +################################################## -my $fcat; +=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,$id)=@_; + my ($what,$id,$def)=@_; + my $result=''; + my @outpar=(); # ----------------------------------------------------- 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}; } - } - -# -------------------------------------------------------- second, check course - - if ($courseopt{$reslevel}) { return $courseopt{$reslevel}; } - if ($courseopt{$seclevel}) { return $courseopt{$seclevel}; } - if ($courseopt{$courselevel}) { return $courseopt{$courselevel}; } - -# ------------------------------------------------------ third, check map parms - - my $thisparm=$parmhash{$symbparm}; - if ($thisparm) { return $thisparm; } - -# --------------------------------------------- last, look in resource metadata - - 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; - } - } - return ''; -} -# ---------------------------------------------------------------- Sort routine + my $symbparm=$symbp{$id}.'.'.$what; + my $mapparm=$mapp{$id}.'___(all).'.$what; -sub bycat { - if ($fcat eq '') { - $a<=>$b; - } else { - &parmval('0.'.$fcat,$a)<=>&parmval('0.'.$fcat,$b); + 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; } -} -# -------------------------------------------------------- Produces link anchor + if ($courseopt{$courselevelm}) { + $outpar[8]=$courseopt{$courselevelm}; + $result=8; + } -sub plink { - my ($type,$dis,$value,$marker,$return,$call)=@_; - return ''. - (($type=~/^date/)?localtime($value):$value).''; + 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; + } + } + + return ($result,@outpar); } -# ================================================================ Main Handler +################################################## +################################################## -sub handler { - my $r=shift; +=pod - if ($r->header_only) { - $r->content_type('text/html'); - $r->send_http_header; - return OK; - } +=item valout -# ----------------------------------------------------- Needs to be in a course +Format a value for output. - if (($ENV{'request.course.fn'}) && - (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) { -# -------------------------------------------------------- Variable declaration +Inputs: $value, $type - %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); - } - if ($uhome eq 'no_host') { - $message= - "