--- loncom/interface/lonparmset.pm 2000/11/23 20:20:39 1.5 +++ loncom/interface/lonparmset.pm 2003/06/23 21:42:07 1.109 @@ -1,298 +1,1689 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# (Handler to resolve ambiguous file locations +# $Id: lonparmset.pm,v 1.109 2003/06/23 21:42:07 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::lonhtmlcommon(); +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 %maptitles; 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 - 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 11 possible levels + +11- resource default +10- map default +9 - General Course +8 - Map or Folder level in course +7 - resource level in course +6 - General for section +5 - Map or Folder level for section +4 - resource level in section +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)=@_; + 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 (defined($courseopt{$courselevel})) { + $outpar[9]=$courseopt{$courselevel}; + $result=9; } -} -# -------------------------------------------------------- Produces link anchor + if (defined($courseopt{$courselevelm})) { + $outpar[8]=$courseopt{$courselevelm}; + $result=8; + } -sub plink { - my ($type,$dis,$value,$marker,$return,$call)=@_; - return ''. - (($type=~/^date/)?localtime($value):$value).''; + if (defined($courseopt{$courselevelr})) { + $outpar[7]=$courseopt{$courselevelr}; + $result=7; + } + + if (defined($csec)) { + if (defined($courseopt{$seclevel})) { + $outpar[6]=$courseopt{$seclevel}; + $result=6; + } + if (defined($courseopt{$seclevelm})) { + $outpar[5]=$courseopt{$seclevelm}; + $result=5; + } + + if (defined($courseopt{$seclevelr})) { + $outpar[4]=$courseopt{$seclevelr}; + $result=4; + } + } + +# ---------------------------------------------------------- fourth, check user + + if (defined($uname)) { + 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); } -# ================================================================ 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= - "