--- loncom/interface/lonparmset.pm 2000/11/27 16:08:55 1.15 +++ loncom/interface/lonparmset.pm 2002/08/17 20:04:18 1.62 @@ -1,343 +1,258 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# (Handler to resolve ambiguous file locations +# $Id: lonparmset.pm,v 1.62 2002/08/17 20:04:18 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,11/22,11/23,11/24,11/25,11/27 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 @outpar; - 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,$def)=@_; my $result=''; - @outpar=(); + my @outpar=(); # ----------------------------------------------------- Cascading lookup scheme - my $symbparm=$symbp{$id}.'.'.$what; - my $mapparm=$mapp{$id}.'___(all).'.$what; + my $symbparm=$symbp{$id}.'.'.$what; + my $mapparm=$mapp{$id}.'___(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 $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; + + 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; } + if ($def) { $outpar[11]=$def; $result=11; } # ----------------------------------------------------- second, check map parms - my $thisparm=$parmhash{$symbparm}; - if ($thisparm) { $outpar[10]=$thisparm; - $result=10; } + 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 ($courseopt{$courselevel}) { + $outpar[9]=$courseopt{$courselevel}; + $result=9; + } - if ($csec) { + if ($courseopt{$courselevelm}) { + $outpar[8]=$courseopt{$courselevelm}; + $result=8; + } - if ($courseopt{$seclevel}) { $outpar[6]=$courseopt{$seclevel}; - $result=6; } + if ($courseopt{$courselevelr}) { + $outpar[7]=$courseopt{$courselevelr}; + $result=7; + } - if ($courseopt{$seclevelm}) { $outpar[5]=$courseopt{$seclevelm}; - $result=5; } - - if ($courseopt{$seclevelr}) { $outpar[4]=$courseopt{$seclevelr}; - $result=4; } - - } + 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; -} - -# ---------------------------------------------------------------- Sort routine - -sub bycat { - if ($fcat eq '') { - $a<=>$b; - } else { - &parmval('0.'.$fcat,$a)<=>&parmval('0.'.$fcat,$b); + 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; + } } -} -# ------------------------------------------------------------ Output for value - -sub valout { - my ($value,$type)=@_; - return - ($value?(($type=~/^date/)?localtime($value):$value):' '); + return ($result,@outpar); } -# -------------------------------------------------------- Produces link anchor +################################################## +################################################## -sub plink { - my ($type,$dis,$value,$marker,$return,$call)=@_; - return ''. - &valout($value,$type).''; -} +=pod -# ================================================================ Main Handler +=item valout -sub handler { - my $r=shift; +Format a value for output. - if ($r->header_only) { - $r->content_type('text/html'); - $r->send_http_header; - return OK; - } +Inputs: $value, $type -# ----------------------------------------------------- Needs to be in a course +Returns: $value, formatted for output. If $type indicates it is a date, +localtime($value) is returned. - if (($ENV{'request.course.fn'}) && - (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) { -# -------------------------------------------------------- Variable declaration +=cut - %courseopt=(); - %useropt=(); - %bighash=(); - - @ids=(); - %symbp=(); - %typep=(); - - my $message=''; - - $csec=$ENV{'form.csec'}; - $udom=$ENV{'form.udom'}; - my $id=$ENV{'form.id'}; - if (($id) && ($udom)) { - $uname=(&Apache::lonnet::idget($udom,$id))[1]; - if ($uname) { - $id=''; - } else { - $message= - "
\nFull Name: ".
- $name{'firstname'}.' '.$name{'middlename'}
- .$name{'lastname'}.' '.$name{'generation'}.
- "
\nID: ".$name{'id'}.'
'; - } + $result = $value; } - } + } + return $result; +} - unless ($csec) { $csec=''; } +################################################## +################################################## - $fcat=$ENV{'form.fcat'}; - unless ($fcat) { $fcat=''; } +=pod -# ------------------------------------------------------------------- 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))) { +=item plink -# --------------------------------------------------------- Get all assessments - map { - if ($_=~/^src\_(\d+)\.(\d+)$/) { - my $mapid=$1; - my $resid=$2; - my $id=$mapid.'.'.$resid; - if ($bighash{$_}=~/\.(problem|exam|quiz|assess|survey|form)$/) { - $ids[$#ids+1]=$id; - $typep{$id}=$1; - $mapp{$id}= - &Apache::lonnet::declutter($bighash{'map_id_'.$mapid}); - $symbp{$id}=$mapp{$id}. - '___'.$resid.'___'. - &Apache::lonnet::declutter($bighash{$_}); - } - } - } keys %bighash; -# ---------------------------------------------------------- Anything to store? - if ($ENV{'form.pres_marker'}) { - my ($sresid,$spnam,$snum)=split(/\&/,$ENV{'form.pres_marker'}); - $spnam=~s/\_/\./; -# ---------------------------------------------------------- Construct prefixes +Produces a link anchor. - my $symbparm=$symbp{$sresid}.'.'.$spnam; - my $mapparm=$mapp{$sresid}.'___(all).'.$spnam; +Inputs: $type,$dis,$value,$marker,$return,$call - my $seclevel= - $ENV{'request.course.id'}.'.['. - $csec.'].'.$spnam; - my $seclevelr= - $ENV{'request.course.id'}.'.['. - $csec.'].'.$symbparm; - my $seclevelm= - $ENV{'request.course.id'}.'.['. - $csec.'].'.$mapparm; - - my $courselevel= - $ENV{'request.course.id'}.'.'.$spnam; - my $courselevelr= - $ENV{'request.course.id'}.'.'.$symbparm; - my $courselevelm= - $ENV{'request.course.id'}.'.'.$mapparm; - - my $storeunder=''; - if (($snum==9) || ($snum==3)) { $storeunder=$courselevel; } - if (($snum==8) || ($snum==2)) { $storeunder=$courselevelm; } - if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; } - if ($snum==6) { $storeunder=$seclevel; } - if ($snum==5) { $storeunder=$seclevelm; } - if ($snum==4) { $storeunder=$seclevelr; } - $storeunder=&Apache::lonnet::escape($storeunder); - - my $storecontent= - $storeunder.'='.&Apache::lonnet::escape($ENV{'form.pres_value'}).'&'. - $storeunder.'.type='.&Apache::lonnet::escape($ENV{'form.pres_type'}); +Returns: scalar with html code for a link which will envoke the +javascript function 'pjump'. - my $reply=''; - if ($snum>3) { -# ---------------------------------------------------------------- Store Course - $reply=&Apache::lonnet::critical('put:'. - $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'. - $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':resourcedata:'. - $storecontent, - $ENV{'course.'.$ENV{'request.course.id'}.'.home'}); - } else { -# ------------------------------------------------------------------ Store User - $reply= - &Apache::lonnet::critical('put:'.$udom.':'.$uname.':resourcedata:'. - $storecontent,$uhome); - } +=cut - if ($reply=~/^error\:(.*)/) { - $message.="