--- loncom/interface/lonparmset.pm 2000/11/27 12:14:32 1.13 +++ loncom/interface/lonparmset.pm 2001/09/01 14:13:47 1.34 @@ -9,7 +9,10 @@ # # 10/11,10/12,10/16 Gerd Kortemeyer) # -# 11/20,11/21,11/22,11/23,11/24,11/25,11/27 Gerd Kortemeyer +# 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28, +# 12/08,12/12, +# 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 Gerd Kortemeyer package Apache::lonparmset; @@ -17,7 +20,6 @@ use strict; use Apache::lonnet; use Apache::Constants qw(:common :http REDIRECT); use GDBM_File; -use Apache::lonmeta; my %courseopt; @@ -31,6 +33,11 @@ my @ids; my %symbp; my %mapp; my %typep; +my %keyp; +my %defp; + +my %allkeys; +my %allmaps; my $uname; my $udom; @@ -53,13 +60,13 @@ sub parmval { my $seclevel= $ENV{'request.course.id'}.'.['. - $ENV{'request.course.sec'}.'].'.$what; + $csec.'].'.$what; my $seclevelr= $ENV{'request.course.id'}.'.['. - $ENV{'request.course.sec'}.'].'.$symbparm; + $csec.'].'.$symbparm; my $seclevelm= $ENV{'request.course.id'}.'.['. - $ENV{'request.course.sec'}.'].'.$mapparm; + $csec.'].'.$mapparm; my $courselevel= $ENV{'request.course.id'}.'.'.$what; @@ -121,16 +128,6 @@ sub parmval { return $result; } -# ---------------------------------------------------------------- Sort routine - -sub bycat { - if ($fcat eq '') { - $a<=>$b; - } else { - &parmval('0.'.$fcat,$a)<=>&parmval('0.'.$fcat,$b); - } -} - # ------------------------------------------------------------ Output for value sub valout { @@ -143,26 +140,23 @@ sub valout { sub plink { my ($type,$dis,$value,$marker,$return,$call)=@_; - return ''. - &valout($value,$type).''; + &valout($value,$type).''; } -# ================================================================ Main Handler +sub assessparms { -sub handler { - my $r=shift; - - if ($r->header_only) { - $r->content_type('text/html'); - $r->send_http_header; - return OK; - } - -# ----------------------------------------------------- Needs to be in a course - - if (($ENV{'request.course.fn'}) && - (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) { + my $r=shift; # -------------------------------------------------------- Variable declaration %courseopt=(); @@ -177,6 +171,25 @@ sub handler { $csec=$ENV{'form.csec'}; $udom=$ENV{'form.udom'}; + unless ($udom) { $udom=$r->dir_config('lonDefDomain'); } + + my $pscat=$ENV{'form.pscat'}; + my $pschp=$ENV{'form.pschp'}; + my $pssymb=''; + +# ----------------------------------------------- Was this started from grades? + + if (($ENV{'form.command'} eq 'set') && ($ENV{'form.url'}) + && (!$ENV{'form.dis'})) { + my $url=$ENV{'form.url'}; + $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--; + $pssymb=&Apache::lonnet::symbread($url); + $pscat='all'; + $pschp=''; + } else { + $ENV{'form.url'}=''; + } + my $id=$ENV{'form.id'}; if (($id) && ($udom)) { $uname=(&Apache::lonnet::idget($udom,$id))[1]; @@ -184,7 +197,7 @@ sub handler { $id=''; } else { $message= - "

Unknown ID '$id' at domain '$udom'

"; + "Unknown ID '$id' at domain '$udom'"; } } else { $uname=$ENV{'form.uname'}; @@ -196,14 +209,14 @@ sub handler { if ($uhome eq 'no_host') { $message= - "

Unknown user '$uname' at domain '$udom'

"; + "Unknown user '$uname' at domain '$udom'"; $uname=''; } else { $csec=&Apache::lonnet::usection( $udom,$uname,$ENV{'request.course.id'}); if ($csec eq '-1') { - $message="

". - "User '$uname' at domain '$udom' not in this course

"; + $message="". + "User '$uname' at domain '$udom' not in this course"; $uname=''; $csec=$ENV{'form.csec'}; } else { @@ -228,6 +241,138 @@ sub handler { (tie(%parmhash,'GDBM_File', $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640))) { +# --------------------------------------------------------- Get all assessments + undef %allkeys; + undef %allmaps; + undef %defp; + map { + if ($_=~/^src\_(\d+)\.(\d+)$/) { + my $mapid=$1; + my $resid=$2; + my $id=$mapid.'.'.$resid; + my $srcf=$bighash{$_}; + if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) { + $ids[$#ids+1]=$id; + $typep{$id}=$1; + $keyp{$id}=''; + map { + if ($_=~/^parameter\_(.*)/) { + my $key=$_; + my $allkey=$1; + $allkey=~s/\_/\./; + my $display= + &Apache::lonnet::metadata($srcf,$key.'.display'); + unless ($display) { + $display= + &Apache::lonnet::metadata($srcf,$key.'.name'); + } + $allkeys{$allkey}=$display; + if ($allkey eq $fcat) { + $defp{$id}= + &Apache::lonnet::metadata($srcf,$key); + } + if ($keyp{$id}) { + $keyp{$id}.=','.$key; + } else { + $keyp{$id}=$key; + } + } + } split(/\,/, + &Apache::lonnet::metadata($srcf,'keys')); + $mapp{$id}= + &Apache::lonnet::declutter($bighash{'map_id_'.$mapid}); + $allmaps{$mapid}=$mapp{$id}; + $symbp{$id}=$mapp{$id}. + '___'.$resid.'___'. + &Apache::lonnet::declutter($srcf); + } + } + } keys %bighash; +# ---------------------------------------------------------- Anything to store? + if ($ENV{'form.pres_marker'}) { + my ($sresid,$spnam,$snum)=split(/\&/,$ENV{'form.pres_marker'}); + $spnam=~s/\_([^\_]+)$/\.$1/; +# ---------------------------------------------------------- Construct prefixes + + my $symbparm=$symbp{$sresid}.'.'.$spnam; + my $mapparm=$mapp{$sresid}.'___(all).'.$spnam; + + 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'}); + + my $reply=''; + if ($snum>3) { +# ---------------------------------------------------------------- Store Course +# +# Expire sheets + &Apache::lonnet::expirespread('','','studentcalc'); + if (($snum==7) || ($snum==4)) { + &Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid}); + } elsif (($snum==8) || ($snum==5)) { + &Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid}); + } else { + &Apache::lonnet::expirespread('','','assesscalc'); + } + +# Store parameter + $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 +# +# Expire sheets + &Apache::lonnet::expirespread($uname,$udom,'studentcalc'); + if ($snum==1) { + &Apache::lonnet::expirespread + ($uname,$udom,'assesscalc',$symbp{$sresid}); + } elsif ($snum==2) { + &Apache::lonnet::expirespread + ($uname,$udom,'assesscalc',$mapp{$sresid}); + } else { + &Apache::lonnet::expirespread($uname,$udom,'assesscalc'); + } + +# Store parameter + $reply= + &Apache::lonnet::critical('put:'.$udom.':'.$uname.':resourcedata:'. + $storecontent,$uhome); + } + + if ($reply=~/^error\:(.*)/) { + $message.="Write Error: $1"; + } +# ---------------------------------------------------------------- Done storing + } # -------------------------------------------------------------- Get coursedata my $reply=&Apache::lonnet::reply('dump:'. $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'. @@ -236,7 +381,8 @@ sub handler { if ($reply!~/^error\:/) { map { my ($name,$value)=split(/\=/,$_); - $courseopt{unescape($name)}=unescape($value); + $courseopt{&Apache::lonnet::unescape($name)}= + &Apache::lonnet::unescape($value); } split(/\&/,$reply); } # --------------------------------------------------- Get userdata (if present) @@ -246,40 +392,30 @@ sub handler { if ($reply!~/^error\:/) { map { my ($name,$value)=split(/\=/,$_); - $useropt{unescape($name)}=unescape($value); + $useropt{&Apache::lonnet::unescape($name)}= + &Apache::lonnet::unescape($value); } split(/\&/,$reply); } } -# --------------------------------------------------------- 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'}) { - $message.="

Storing $ENV{'form.pres.value'} type $ENV{'form.pres_type'} under $ENV{'form.pres_marker'}

"; - } + # ------------------------------------------------------------------- Sort this - @ids=sort bycat @ids; + + @ids=sort { + if ($fcat eq '') { + $a<=>$b; + } else { + 1*$outpar[&parmval($fcat,$a,$defp{$a})]<=> + 1*$outpar[&parmval($fcat,$b,$defp{$b})]; + } + } @ids; + # ------------------------------------------------------------------ Start page $r->content_type('text/html'); $r->send_http_header; $r->print(< -LON-CAPA Assessment Parameters +LON-CAPA Course Parameters -

Set Assessment Parameters

-
+

Set Course Parameters

+

Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}

+

Course Environment

+ +
+
+

Course Assessments

Section/Group: @@ -326,24 +479,55 @@ or ID at Domain - - + ENDHEAD - - $r->print($message.'

Sort list by '); - $r->print(''); + if ($ENV{'form.url'}) { + $r->print(''); + } + map { + $r->print(''); + } ('tolerance','date_default','date_start','date_end','date_interval', + 'int','float','string'); + + $r->print('

'.$message.'

Sort list by'); + $r->print('
Select Enclosing Map
Select Parameter

' + ); + if (($pscat) || ($pschp) || ($pssymb)) { # ----------------------------------------------------------------- Start Table + my $catmarker='parameter_'.$pscat; + $catmarker=~s/\./\_/g; my $coursespan=$csec?8:5; + my $csuname=$ENV{'user.name'}; + my $csudom=$ENV{'user.domain'}; $r->print(< @@ -353,7 +537,9 @@ ENDTABLEHEAD $r->print(""); } $r->print(<Parameter in Effect + + + ENDTABLETWO @@ -372,103 +558,283 @@ ENDTABLEHEADFOUR if ($uname) { $r->print(''); } - $r->print(''); + $r->print(''); + my $defbgone=''; + my $defbgtwo=''; map { + my $rid=$_; + my ($inmapid)=($rid=~/\.(\d+)$/); + if (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid}) || + ($pssymb eq $mapp{$rid}.'___'.$inmapid.'___'. + &Apache::lonnet::declutter($bighash{'src_'.$rid}))) { # ------------------------------------------------------ Entry for one resource + if ($defbgone eq '"E0E099"') { + $defbgone='"E0E0DD"'; + } else { + $defbgone='"E0E099"'; + } + if ($defbgtwo eq '"FFFF99"') { + $defbgtwo='"FFFFDD"'; + } else { + $defbgtwo='"FFFF99"'; + } @outpar=(); - my $rid=$_; my $thistitle=''; - my %name= ('0_deadline' => 'deadline'); - my %part= ('0_deadline' => '0'); - my %display=('0_deadline' => 'Deadline'); - my %type= ('0_deadline' => 'date_end'); - my %default=('0_deadline' => time); - my %metadata=&Apache::lonmeta::unpackagemeta( -&Apache::lonnet::getfile('/home/httpd/html/'.$bighash{'src_'.$rid}.'.meta'),1); + my %name= (); + undef %name; + my %part= (); + my %display=(); + my %type= (); + my %default=(); + my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid}); + map { - if ($_=~/^parameter\_(\d+)\_(\w+)$/) { - my $hashid=$1.'_'.$2; - $part{$hashid}=$1; - $name{$hashid}=$2; - my $tdef; - ($tdef,$display{$hashid})= - split(/\_\_dis\_\_/,$metadata{$_}); - ($type{$hashid},$default{$hashid})=split(/\:/,$tdef); - unless ($display{$hashid}) { - $display{$hashid}=$name{$hashid}; - } - } - if ($_ eq 'title') { - $thistitle=$metadata{$_}; - } - } keys %metadata; + if (($_ eq $catmarker) || ($pscat eq 'all')) { + $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part'); + $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name'); + $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display'); + unless ($display{$_}) { $display{$_}=''; } + $display{$_}.=' ('.$name{$_}.')'; + $default{$_}=&Apache::lonnet::metadata($uri,$_); + $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type'); + $thistitle=&Apache::lonnet::metadata($uri,$_.'.title'); + } + } split(/\,/,$keyp{$rid}); + my $totalparms=scalar keys %name; - $r->print(''); - $r->print(''); - $r->print(''); + $r->print(''); map { - my $result=&parmval($part{$_}.'.'.$name{$_},$rid,$default{$_}); + unless ($firstrow) { + $r->print(''); + } else { + $firstrow=0; + } + $r->print(""); + my $thismarker=$_; + $thismarker=~s/^parameter\_//; + my $mprefix=$rid.'&'.$thismarker.'&'; - $r->print(""); - my $mprefix=$rid.'&'.$_.'&'; - - $r->print(''. + $r->print(''); - $r->print(''. + $r->print(''); - $r->print(''. + $r->print(''); - $r->print(''. + $r->print(''); - $r->print(''. + $r->print(''); if ($csec) { - $r->print(''. + $r->print(''); - $r->print(''. + $r->print(''); - $r->print(''. + $r->print(''); } if ($uname) { - $r->print(''. + $r->print(''); - $r->print(''. + $r->print(''); - $r->print(''. + $r->print(''); } - - $r->print(''); - $r->print("\n"); + $r->print( + ''); + my $sessionval=&Apache::lonnet::EXT('resource.'.$part{$_}. + '.'.$name{$_},$mapp{$rid}.'___'.$inmapid.'___'.$uri); + if (($type{$_}=~/^date/) && ($sessionval)) + { $sessionval=localtime($sessionval); } + $r->print( + ''); + $r->print(""); } sort keys %name; + } # -------------------------------------------------- End entry for one resource + } } @ids; - $r->print('
User $uname at Domain $udom
Parameter in EffectCurrent Session Value
($csuname at $csudom)
Resource Level in Coursegeneralfor Enclosing Mapfor Resource
'. - join(' / ',split(/\//,&Apache::lonnet::declutter($bighash{'src_'.$rid}))). - '

'. + if ($totalparms>0) { + my $firstrow=1; + $r->print('

'. + join(' / ',split(/\//,$uri)). + '

'. $bighash{'title_'.$rid}); if ($thistitle) { $r->print(' ('.$thistitle.')'); } $r->print('

'.$typep{$rid}.''. + $r->print(''.$typep{$rid}.''. join(' / ',split(/\//,$mapp{$rid})).'
$part{$_}$display{$_}$part{$_}$display{$_}'. &valout($outpar[11],$type{$_}).''. &valout($outpar[10],$type{$_}).''. &plink($type{$_},$display{$_},$outpar[9],$mprefix.'9', 'parmform.pres','psub').''. &plink($type{$_},$display{$_},$outpar[8],$mprefix.'8', 'parmform.pres','psub').''. &plink($type{$_},$display{$_},$outpar[7],$mprefix.'7', 'parmform.pres','psub').''. &plink($type{$_},$display{$_},$outpar[6],$mprefix.'6', 'parmform.pres','psub').''. &plink($type{$_},$display{$_},$outpar[5],$mprefix.'5', 'parmform.pres','psub').''. &plink($type{$_},$display{$_},$outpar[4],$mprefix.'4', 'parmform.pres','psub').''. &plink($type{$_},$display{$_},$outpar[3],$mprefix.'3', 'parmform.pres','psub').''. &plink($type{$_},$display{$_},$outpar[2],$mprefix.'2', 'parmform.pres','psub').''. &plink($type{$_},$display{$_},$outpar[1],$mprefix.'1', 'parmform.pres','psub').''.&valout($outpar[$result],$type{$_}).'
'.&valout($outpar[$result],$type{$_}).''.$sessionval.' '. + '
'); + $r->print(''); + } + $r->print(''); untie(%bighash); untie(%parmhash); } +} + +sub crsenv { + my $r=shift; + my $setoutput=''; +# -------------------------------------------------- Go through list of changes + map { + if ($_=~/^form\.(.+)\_setparmval$/) { + my $name=$1; + my $value=$ENV{'form.'.$name.'_value'}; + if ($name eq 'newp') { + $name=$ENV{'form.newp_name'}; + } + if ($name eq 'url') { + $value=~s/^\/res\///; + $setoutput.='Backing up previous URL: '. + &Apache::lonnet::reply('put:'. + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}. + ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}. + ':environment:'. + &Apache::lonnet::escape('top level map backup '. + time).'='. + &Apache::lonnet::reply('get:'. + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}. + ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}. + ':environment:url', + $ENV{'course.'.$ENV{'request.course.id'}.'.home'}), + $ENV{'course.'.$ENV{'request.course.id'}.'.home'}). + '
'; + + } + if ($name) { + $setoutput.='Setting '.$name.' to '. + $value.': '. + &Apache::lonnet::reply('put:'. + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}. + ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}. + ':environment:'. + &Apache::lonnet::escape($name).'='. + &Apache::lonnet::escape($value), + $ENV{'course.'.$ENV{'request.course.id'}.'.home'}). + '
'; + } + } + } keys %ENV; +# -------------------------------------------------------- Get parameters again + my $rep=&Apache::lonnet::reply + ('dump:'.$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}. + ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}. + ':environment', + $ENV{'course.'.$ENV{'request.course.id'}.'.home'}); + my $output=''; + if ($rep ne 'con_lost') { + my %values; + my %descriptions= + ('url' => 'Top Level Map
'. + 'Modification may make assessment data inaccessible', + 'description' => 'Course Description', + 'courseid' => 'Course ID or number
(internal, optional)', + 'question.email' => 'Feedback Addresses for Content Questions
'. + '(user:domain,user:domain,...)', + 'comment.email' => 'Feedback Addresses for Comments
'. + '(user:domain,user:domain,...)', + 'policy.email' => 'Feedback Addresses for Course Policy
'. + '(user:domain,user:domain,...)' + ); + + map { + my ($name,$value)=split(/\=/,$_); + $name=&Apache::lonnet::unescape($name); + $values{$name}=&Apache::lonnet::unescape($value); + unless ($descriptions{$name}) { + $descriptions{$name}=$name; + } + } split(/\&/,$rep); + map { + $output.=''.$descriptions{$_}.''; + } keys %descriptions; + $output.='Create New Environment Variable
'. + ''. + ''. + ''; + } + $r->print(< + +LON-CAPA Course Environment + + +

Set Course Parameters

+
+

Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}

+

Course Environment

+$setoutput +

+ + +$output +
ParameterValueSet?
+ +

+ + +ENDENV +} + +# ================================================================ Main Handler + +sub handler { + my $r=shift; + + if ($r->header_only) { + $r->content_type('text/html'); + $r->send_http_header; + return OK; + } + +# ----------------------------------------------------- Needs to be in a course + + if (($ENV{'request.course.id'}) && + (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) { + + unless (($ENV{'form.crsenv'}) || (!$ENV{'request.course.fn'})) { +# --------------------------------------------------------- Bring up assessment + &assessparms($r); +# ---------------------------------------------- This is for course environment + } else { + &crsenv($r); + } } else { # ----------------------------- Not in a course, or not allowed to modify parms $ENV{'user.error.msg'}=