--- loncom/interface/lonparmset.pm 2002/08/16 20:47:26 1.61 +++ loncom/interface/lonparmset.pm 2003/06/06 02:24:49 1.98 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.61 2002/08/16 20:47:26 albertel Exp $ +# $Id: lonparmset.pm,v 1.98 2003/06/06 02:24:49 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -56,6 +56,7 @@ 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::lonhomework; @@ -72,6 +73,8 @@ my %mapp; my %typep; my %keyp; +my %maptitles; + my $uname; my $udom; my $uhome; @@ -87,9 +90,23 @@ my $coursename; Figure out a cascading parameter. -Inputs: $what $id $def - -Returns: I am not entirely sure. +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 @@ -123,32 +140,32 @@ sub parmval { # --------------------------------------------------------- third, check course - if ($courseopt{$courselevel}) { + if (defined($courseopt{$courselevel})) { $outpar[9]=$courseopt{$courselevel}; $result=9; } - if ($courseopt{$courselevelm}) { + if (defined($courseopt{$courselevelm})) { $outpar[8]=$courseopt{$courselevelm}; $result=8; } - if ($courseopt{$courselevelr}) { + if (defined($courseopt{$courselevelr})) { $outpar[7]=$courseopt{$courselevelr}; $result=7; } - if ($csec) { - if ($courseopt{$seclevel}) { + if (defined($csec)) { + if (defined($courseopt{$seclevel})) { $outpar[6]=$courseopt{$seclevel}; $result=6; } - if ($courseopt{$seclevelm}) { + if (defined($courseopt{$seclevelm})) { $outpar[5]=$courseopt{$seclevelm}; $result=5; } - if ($courseopt{$seclevelr}) { + if (defined($courseopt{$seclevelr})) { $outpar[4]=$courseopt{$seclevelr}; $result=4; } @@ -156,23 +173,22 @@ sub parmval { # ---------------------------------------------------------- fourth, check user - if ($uname) { - if ($useropt{$courselevel}) { + if (defined($uname)) { + if (defined($useropt{$courselevel})) { $outpar[3]=$useropt{$courselevel}; $result=3; } - if ($useropt{$courselevelm}) { + if (defined($useropt{$courselevelm})) { $outpar[2]=$useropt{$courselevelm}; $result=2; } - if ($useropt{$courselevelr}) { + if (defined($useropt{$courselevelr})) { $outpar[1]=$useropt{$courselevelr}; $result=1; } } - return ($result,@outpar); } @@ -199,9 +215,32 @@ sub valout { my $result = ''; # Values of zero are valid. if (! $value && $value ne '0') { - $result = '  '; + $result = '  '; } else { - if ($type=~/^date/) { + if ($type eq 'date_interval') { + my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value); + $year=$year-70; + $mday--; + if ($year) { + $result.=$year.' yrs '; + } + if ($mon) { + $result.=$mon.' mths '; + } + if ($mday) { + $result.=$mday.' days '; + } + if ($hour) { + $result.=$hour.' hrs '; + } + if ($min) { + $result.=$min.' mins '; + } + if ($sec) { + $result.=$sec.' secs '; + } + $result=~s/\s+$//; + } elsif ($type=~/^date/) { $result = localtime($value); } else { $result = $value; @@ -247,8 +286,13 @@ sub plink { 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()"'); + my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '. + &Apache::loncommon::selectstudent_link('parmform','uname','udom'); + my $selscript=&Apache::loncommon::studentbrowser_javascript(); + my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); $r->print(< @@ -261,15 +305,7 @@ sub startpage { parmwin.close(); } - function pjump(type,dis,value,marker,ret,call) { - document.parmform.pres_marker.value=''; - parmwin=window.open("/adm/rat/parameter.html?type="+escape(type) - +"&value="+escape(value)+"&marker="+escape(marker) - +"&return="+escape(ret) - +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms", - "height=350,width=350,scrollbars=no,menubar=no"); - - } + $pjump_def function psub() { pclose(); @@ -302,10 +338,13 @@ sub startpage { newWin.focus(); } +$selscript - -

Set Course Parameters for Course: -$ENV{'course.'.$ENV{'request.course.id'}.'.description'}

+$bodytag + +Use Assignment Parameter Helper, a +simpler interface to set open, due, or answer open dates for problems or sequences. +

Course Environment

@@ -321,7 +360,7 @@ For User or ID at Domain - +$chooseopt @@ -331,10 +370,27 @@ ENDHEAD } sub print_row { - my ($r,$which,$part,$name,$rid,$default,$type,$display,$defbgone, + my ($r,$which,$part,$name,$rid,$default,$defaulttype,$display,$defbgone, $defbgtwo,$parmlev)=@_; +# get the values for the parameter in cascading order +# empty levels will remain empty my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which}, $rid,$$default{$which}); +# get the type for the parameters +# problem: these may not be set for all levels + my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'. + $$name{$which}.'.type', + $rid,$$defaulttype{$which}); +# cascade down manually + my $cascadetype=$defaulttype; + for (my $i=$#typeoutpar;$i>0;$i--) { + if ($typeoutpar[$i]) { + $cascadetype=$typeoutpar[$i]; + } else { + $typeoutpar[$i]=$cascadetype; + } + } + my $parm=$$display{$which}; if ($parmlev eq 'full' || $parmlev eq 'brief') { @@ -353,73 +409,79 @@ sub print_row { if ($parmlev eq 'general') { if ($uname) { - &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); } elsif ($csec) { - &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); } else { - &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); } } elsif ($parmlev eq 'map') { if ($uname) { - &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); } elsif ($csec) { - &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); } else { - &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); } } else { - &print_td($r,11,'#FFDDDD',$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,11,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); if ($parmlev eq 'brief') { - &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); if ($csec) { - &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); } if ($uname) { - &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); } } else { - &print_td($r,10,'#FFDDDD',$result,\@outpar,$mprefix,$_,$type,$display); - &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); - &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); - &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,10,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); + &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); + &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); + &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); if ($csec) { - &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display); - &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display); - &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); + &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); + &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); } if ($uname) { - &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); - &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); - &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); + &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); + &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); + &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); } } # end of $brief if/else } # end of $parmlev if/else if ($parmlev eq 'full' || $parmlev eq 'brief') { $r->print(''. - &valout($outpar[$result],$$type{$which}).''); + &valout($outpar[$result],$typeoutpar[$result]).''); } my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}. '.'.$$name{$which},$symbp{$rid}); +# this doesn't seem to work, and I don't think is correct +# my $sessionvaltype=&Apache::lonnet::EXT('resource.'.$$part{$which}. +# '.'.$$name{$which}.'.type',$symbp{$rid}); +# this seems to work + my $sessionvaltype=$typeoutpar[$result]; + if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; } $r->print(''. - &valout($sessionval,$$type{$which}).' '. + &valout($sessionval,$sessionvaltype).' '. ''); $r->print(''); $r->print("\n"); } sub print_td { - my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$type,$display)=@_; + my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_; $r->print(''. - &plink($$type{$value},$$display{$value},$$outpar[$which], + &plink($$typeoutpar[$which],$$display{$value},$$outpar[$which], $mprefix."$which",'parmform.pres','psub').''."\n"); } @@ -437,6 +499,106 @@ sub get_env_multiple { return(@values); } +=pod + +=item B: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes. + +Input: See list below: + +=over 4 + +=item B: An array that will contain all of the ids in the course. + +=item B: hash, id->type, where "type" contains the extension of the file, thus, I. + +=item B: hash, id->key list, will contain a comma seperated list of the meta-data keys available for the given id + +=item B: hash, name of parameter->display value (what is the display value?) + +=item B: hash, part identification->text representation of part, where the text representation is "[Part $part]" + +=item B: hash, full key to part->display value (what's display value?) + +=item B: hash, ??? + +=item B: ??? + +=item B: hash, ??? + +=item B: ?? + +=item B: hash, id->full sym? + +=back + +=cut + +sub extractResourceInformation { + my $bighash = shift; + my $ids = shift; + my $typep = shift; + my $keyp = shift; + my $allparms = shift; + my $allparts = shift; + my $allkeys = shift; + my $allmaps = shift; + my $fcat = shift; + my $defp = shift; + my $mapp = shift; + my $symbp = shift; + my $maptitles=shift; + + foreach (keys %$bighash) { + 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}=''; + foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) { + if ($_=~/^parameter\_(.*)/) { + my $key=$_; + my $allkey=$1; + $allkey=~s/\_/\./g; + my $display= &Apache::lonnet::metadata($srcf,$key.'.display'); + my $name=&Apache::lonnet::metadata($srcf,$key.'.name'); + my $part= &Apache::lonnet::metadata($srcf,$key.'.part'); + my $parmdis = $display; + $parmdis =~ s|(\[Part.*$)||g; + my $partkey = $part; + $partkey =~ tr|_|.|; + $$allparms{$name} = $parmdis; + $$allparts{$part} = "[Part $part]"; + $$allkeys{$allkey}=$display; + if ($allkey eq $fcat) { + $$defp{$id}= &Apache::lonnet::metadata($srcf,$key); + } + if ($$keyp{$id}) { + $$keyp{$id}.=','.$key; + } else { + $$keyp{$id}=$key; + } + } + } + $$mapp{$id}= + &Apache::lonnet::declutter($$bighash{'map_id_'.$mapid}); + $$mapp{$mapid}=$$mapp{$id}; + $$allmaps{$mapid}=$$mapp{$id}; + $$maptitles{$mapid}= + $$bighash{'title_'.$$bighash{'ids_'.&Apache::lonnet::clutter($$mapp{$id})}}; + $$maptitles{$$mapp{$id}}=$$maptitles{$mapid}; + $$symbp{$id}=$$mapp{$id}. + '___'.$resid.'___'. + &Apache::lonnet::declutter($srcf); + $$symbp{$mapid}=$$mapp{$id}.'___(all)'; + } + } + } +} + ################################################## ################################################## @@ -451,6 +613,18 @@ Inputs: $r Returns: nothing +Variables used (guessed by Jeremy): + +=over 4 + +=item B: ParameterS CATegories? ends up a list of the types of parameters that exist, e.g., tol, weight, acc, opendate, duedate, answerdate, sig, maxtries, type. + +=item B: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts? + +=item B: + +=back + =cut ################################################## @@ -489,6 +663,7 @@ sub assessparms { my @pscat=&get_env_multiple('form.pscat'); my $pschp=$ENV{'form.pschp'}; my @psprt=&get_env_multiple('form.psprt'); + if (!@psprt) { $psprt[0]='0'; } my $showoptions=$ENV{'form.showoptions'}; my $pssymb=''; @@ -512,12 +687,12 @@ sub assessparms { my $url=$ENV{'form.url'}; $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--; $pssymb=&Apache::lonnet::symbread($url); - @pscat='all'; + if (!@pscat) { @pscat=('all'); } $pschp=''; $parmlev = 'full'; } elsif ($ENV{'form.symb'}) { $pssymb=$ENV{'form.symb'}; - @pscat='all'; + if (!@pscat) { @pscat=('all'); } $pschp=''; $parmlev = 'full'; } else { @@ -580,53 +755,10 @@ sub assessparms { $r->print("Unable to access parameter data. (File $ENV{'request.course.fn'}_parms.db not tieable)"); return ; } + # --------------------------------------------------------- Get all assessments - foreach (keys %bighash) { - 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}=''; - foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'keys'))) { - if ($_=~/^parameter\_(.*)/) { - my $key=$_; - my $allkey=$1; - $allkey=~s/\_/\./g; - my $display= &Apache::lonnet::metadata($srcf,$key.'.display'); - my $name=&Apache::lonnet::metadata($srcf,$key.'.name'); - my $part= &Apache::lonnet::metadata($srcf,$key.'.part'); - my $parmdis = $display; - $parmdis =~ s|(\[Part.*$)||g; - my $partkey = $part; - $partkey =~ tr|_|.|; - $allparms{$name} = $parmdis; - $allparts{$part} = "[Part $part]"; - $allkeys{$allkey}=$display; - if ($allkey eq $fcat) { - $defp{$id}= &Apache::lonnet::metadata($srcf,$key); - } - if ($keyp{$id}) { - $keyp{$id}.=','.$key; - } else { - $keyp{$id}=$key; - } - } - } - $mapp{$id}= - &Apache::lonnet::declutter($bighash{'map_id_'.$mapid}); - $mapp{$mapid}=$mapp{$id}; - $allmaps{$mapid}=$mapp{$id}; - $symbp{$id}=$mapp{$id}. - '___'.$resid.'___'. - &Apache::lonnet::declutter($srcf); - $symbp{$mapid}=$mapp{$id}.'___(all)'; - } - } - } + extractResourceInformation(\%bighash, \@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allkeys, \%allmaps, $fcat, \%defp, \%mapp, \%symbp,\%maptitles); + $mapp{'0.0'} = ''; $symbp{'0.0'} = ''; # ---------------------------------------------------------- Anything to store? @@ -654,8 +786,10 @@ sub assessparms { if ($snum==5) { $storeunder=$seclevelm; } if ($snum==4) { $storeunder=$seclevelr; } - my %storecontent = ($storeunder => $ENV{'form.pres_value'}, - $storeunder.'type' => $ENV{'form.pres_type'}); + my $delete; + if ($ENV{'form.pres_value'} eq '') { $delete=1;} + my %storecontent = ($storeunder => $ENV{'form.pres_value'}, + $storeunder.'.type' => $ENV{'form.pres_type'}); my $reply=''; if ($snum>3) { # ---------------------------------------------------------------- Store Course @@ -670,10 +804,17 @@ sub assessparms { &Apache::lonnet::expirespread('','','assesscalc'); } # Store parameter - $reply=&Apache::lonnet::cput - ('resourcedata',\%storecontent, - $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, - $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + if ($delete) { + $reply=&Apache::lonnet::del + ('resourcedata',[keys(%storecontent)], + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + } else { + $reply=&Apache::lonnet::cput + ('resourcedata',\%storecontent, + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + } } else { # ------------------------------------------------------------------ Store User # @@ -689,15 +830,25 @@ sub assessparms { &Apache::lonnet::expirespread($uname,$udom,'assesscalc'); } # Store parameter - $reply=&Apache::lonnet::cput - ('resourcedata',\%storecontent,$udom,$uname); + if ($delete) { + $reply=&Apache::lonnet::del + ('resourcedata',[keys(%storecontent)],$udom,$uname); + } else { + $reply=&Apache::lonnet::cput + ('resourcedata',\%storecontent,$udom,$uname); + } } if ($reply=~/^error\:(.*)/) { $message.="Write Error: $1"; } # ---------------------------------------------------------------- Done storing + $message.='

Changes can take up to 10 minutes before being active for all students

'; } +# --------------------------------------------- Devalidate cache for this child + &Apache::lonnet::devalidatecourseresdata( + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}); # -------------------------------------------------------------- Get coursedata %courseopt = &Apache::lonnet::dump ('resourcedata', @@ -725,6 +876,7 @@ sub assessparms { if ($pscat[0] eq "all" || !@pscat) {@pscat = (keys %allparms);} if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);} # ------------------------------------------------------------------ Start page + &startpage($r,$id,$udom,$csec,$uname); # if ($ENV{'form.url'}) { # $r->print('\n"); } else { @@ -800,7 +952,6 @@ sub assessparms { $r->print('>All Parameters'); my $cnt=0; - foreach $tempkey (sort { $allparms{$a} cmp $allparms{$b} } keys %allparms ) { ++$cnt; @@ -819,10 +970,12 @@ sub assessparms { $r->print(''); + my %temphash=(); + foreach (@psprt) { $temphash{$_}=1; } foreach $tempkey (sort keys %allparts) { unless ($tempkey =~ /\./) { $r->print(''); @@ -832,7 +985,7 @@ sub assessparms { $r->print('Sort list by'); $r->print(''. ''."\n"; } - my $onchange = 'onchange="javascript:window.document.forms'. + my $onchange = 'onFocus="javascript:window.document.forms'. '[\'envform\'].elements[\'newp_setparmval\']'. '.checked=true;"'; $output.='Create New Environment Variable
'. @@ -1361,11 +1545,8 @@ sub crsenv { LON-CAPA Course Environment - -

Set Course Parameters

+$bodytag -

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

-

Course Environment

$setoutput

@@ -1384,7 +1565,7 @@ ENDENV =pod -=item handler +=item * handler Main handler. Calls &assessparms and &crsenv subroutines. @@ -1392,6 +1573,7 @@ Main handler. Calls &assessparms and &c ################################################## ################################################## + use Data::Dumper; sub handler { my $r=shift; @@ -1401,6 +1583,10 @@ sub handler { return OK; } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); + + $r->content_type('text/html'); + $r->send_http_header; + # ----------------------------------------------------- Needs to be in a course if (($ENV{'request.course.id'}) &&