--- loncom/interface/lonparmset.pm 2005/06/03 21:19:04 1.206 +++ loncom/interface/lonparmset.pm 2005/06/07 15:21:03 1.217 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.206 2005/06/03 21:19:04 www Exp $ +# $Id: lonparmset.pm,v 1.217 2005/06/07 15:21:03 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -403,7 +403,7 @@ sub valout { $result.=$sec.' secs '; } $result=~s/\s+$//; - } elsif ($type=~/^date/) { + } elsif (&isdateparm($type)) { $result = localtime($value); } else { $result = $value; @@ -434,12 +434,14 @@ sub plink { my ($type,$dis,$value,$marker,$return,$call)=@_; my $winvalue=$value; unless ($winvalue) { - if ($type=~/^date/) { + if (&isdateparm($type)) { $winvalue=$env{'form.recent_'.$type}; } else { $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]}; } } + + return ''. @@ -447,22 +449,13 @@ sub plink { } sub startpage { - my ($r,$id,$udom,$csec,$uname,$have_assessments)=@_; + my $r=shift; my $bodytag=&Apache::loncommon::bodytag('Set/Modify Course Parameters','', 'onUnload="pclose()"'); my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Table Mode Parameter Setting'); - 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(); - my %lt=&Apache::lonlocal::texthash( - 'captm' => "Course Assessments Parameters - Table Mode", - 'sg' => "Section/Group", - 'fu' => "For User", - 'oi' => "or ID", - 'ad' => "at Domain" - ); my $html=&Apache::lonxml::xmlbegin(); $r->print(< $bodytag $breadcrumbs -ENDHEAD - my %sectionhash=(); - my $sections=''; - if (&Apache::loncommon::get_sections( - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}, - \%sectionhash)) { - $sections=$lt{'sg'}.': '; - } - $r->print(< -

$lt{'captm'}

-ENDHEAD3 - - if (!$have_assessments) { - $r->print(''.&mt('There are no assessment parameters in this course to set.').'
'); - } else { - $r->print(< -$sections -
-$lt{'fu'} - -$lt{'oi'} - -$lt{'ad'} -$chooseopt - + ENDHEAD - } } + sub print_row { my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone, $defbgtwo,$parmlev,$uname,$udom,$csec)=@_; @@ -700,15 +662,15 @@ sub extractResourceInformation { 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; my $uris=shift; + my $keyorder=shift; + my $defkeytype=shift; + my $keyordercnt=100; my $navmap = Apache::lonnavmaps::navmap->new(); my @allres=$navmap->retrieveResources(undef,undef,1,undef,1); @@ -725,30 +687,40 @@ sub extractResourceInformation { foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) { if ($_=~/^parameter\_(.*)/) { my $key=$_; - my $allkey=$1; - $allkey=~s/\_/\./g; - if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq - 'parm') { - next; #hide hidden things +# Hidden parameters + if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm') { + next; } my $display= &Apache::lonnet::metadata($srcf,$key.'.display'); my $name=&Apache::lonnet::metadata($srcf,$key.'.name'); my $part= &Apache::lonnet::metadata($srcf,$key.'.part'); +# +# allparms is a hash of parameter names +# 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); - } + $parmdis =~ s/\[Part.*$//g; + $$allparms{$name}=$parmdis; + $$defkeytype{$name}=&Apache::lonnet::metadata($srcf,$key.'.type'); +# +# allparts is a hash of all parts +# + $$allparts{$part} = "Part: $part"; +# +# Remember all keys going with this resource +# if ($$keyp{$id}) { $$keyp{$id}.=','.$key; } else { $$keyp{$id}=$key; } +# +# Put in order +# + unless ($$keyorder{$key}) { + $$keyorder{$key}=$keyordercnt; + $keyordercnt++; + } + } } $$mapp{$id}= @@ -766,6 +738,275 @@ sub extractResourceInformation { } } + +################################################## +################################################## + +sub isdateparm { + my $type=shift; + return (($type=~/^date/) && (!($type eq 'date_interval'))); +} + +sub parmmenu { + my ($r,$allparms,$pscat,$keyorder)=@_; + my $tempkey; + $r->print(< + function checkall(value, checkName) { + for (i=0; i +ENDSCRIPT + $r->print(); + $r->print("\n"); + my $cnt=0; + foreach $tempkey (&keysindisplayorder($allparms,$keyorder)) { + $r->print("\n'); + $cnt++; + if ($cnt==3) { + $r->print("\n"); + $cnt=0; + } + } + $r->print(' + +'); + $r->print('
print('value="'.$tempkey.'"'); + if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) { + $r->print(' checked'); + } + $r->print('>'.$$allparms{$tempkey}.'
+Select All +Select Standard + +Select Dates +Select Visibilities +Select Part Parameters + +Unselect All +
'); +} + +sub partmenu { + my ($r,$allparts,$psprt)=@_; + $r->print(''); +} + +sub usermenu { + my ($r,$uname,$id,$udom,$csec)=@_; + my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '. + &Apache::loncommon::selectstudent_link('parmform','uname','udom'); + my $selscript=&Apache::loncommon::studentbrowser_javascript(); + my %lt=&Apache::lonlocal::texthash( + 'sg' => "Section/Group", + 'fu' => "For User", + 'oi' => "or ID", + 'ad' => "at Domain" + ); + my %sectionhash=(); + my $sections=''; + if (&Apache::loncommon::get_sections( + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}, + \%sectionhash)) { + $sections=$lt{'sg'}.': '; + } + $r->print(< +$sections +
+$lt{'fu'} + +$lt{'oi'} + +$lt{'ad'} +$chooseopt + +ENDMENU +} + +sub displaymenu { + my ($r,$allparms,$allparts,$pscat,$psprt,$keyorder)=@_; + $r->print('
'.&mt('Select Parameters to View').''. + &mt('Select Parts to View').'
'); + &parmmenu($r,$allparms,$pscat,$keyorder); + $r->print(''); + &partmenu($r,$allparts,$psprt); + $r->print('
'); +} + +sub mapmenu { + my ($r,$allmaps,$pschp,$maptitles)=@_; + $r->print(&mt('Select Enclosing Map or Folder').' '); + $r->print('"); +} + +sub levelmenu { + my ($r,$alllevs,$parmlev)=@_; + $r->print(&mt('Select Parameter Level'). + &Apache::loncommon::help_open_topic('Course_Parameter_Levels').' '); + $r->print('"); +} + + +sub sectionmenu { + my ($r,$selectedsections)=@_; + my %sectionhash=(); + + if (&Apache::loncommon::get_sections( + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}, + \%sectionhash)) { + $r->print('\n"); + } +} + +sub keysplit { + my $keyp=shift; + return (split(/\,/,$keyp)); +} + +sub keysinorder { + my ($name,$keyorder)=@_; + return sort { + $$keyorder{$a} <=> $$keyorder{$b}; + } (keys %{$name}); +} + +sub keysindisplayorder { + my ($name,$keyorder)=@_; + return sort { + $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b}; + } (keys %{$name}); +} + +sub sortmenu { + my ($r,$sortorder)=@_; + $r->print('
print(' checked="on"'); + } + $r->print(' />'.&mt('Sort by realm first, then student (group/section)')); + $r->print('
print(' checked="on"'); + } + $r->print(' />'.&mt('Sort by student (group/section) first, then realm')); +} + +sub standardkeyorder { + return ('parameter_0_opendate' => 1, + 'parameter_0_duedate' => 2, + 'parameter_0_answerdate' => 3, + 'parameter_0_interval' => 4, + 'parameter_0_weight' => 5, + 'parameter_0_maxtries' => 6, + 'parameter_0_hinttries' => 7, + 'parameter_0_contentopen' => 8, + 'parameter_0_contentclose' => 9, + 'parameter_0_type' => 10, + 'parameter_0_problemstatus' => 11, + 'parameter_0_hiddenresource' => 12, + 'parameter_0_hiddenparts' => 13, + 'parameter_0_display' => 14, + 'parameter_0_ordered' => 15, + 'parameter_0_tol' => 16, + 'parameter_0_sig' => 17, + 'parameter_0_turnoffunit' => 18); +} + ################################################## ################################################## @@ -809,7 +1050,7 @@ sub assessparms { my %maptitles=(); # -------------------------------------------------------- Variable declaration - my %allkeys=(); + my %allmaps=(); my %alllevs=(); @@ -821,13 +1062,15 @@ sub assessparms { my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'}; $alllevs{'Resource Level'}='full'; - $alllevs{'Map Level'}='map'; + $alllevs{'Map/Folder Level'}='map'; $alllevs{'Course Level'}='general'; my %allparms; my %allparts; - - my %defp; +# +# Order in which these parameters will be displayed +# + my %keyorder=&standardkeyorder(); @ids=(); %symbp=(); @@ -848,11 +1091,9 @@ sub assessparms { my $pschp=$env{'form.pschp'}; my @psprt=&Apache::loncommon::get_env_multiple('form.psprt'); if (!@psprt) { $psprt[0]='0'; } - my $showoptions=$env{'form.showoptions'}; my $pssymb=''; my $parmlev=''; - my $prevvisit=$env{'form.prevvisit'}; unless ($env{'form.parmlev'}) { $parmlev = 'map'; @@ -923,11 +1164,10 @@ sub assessparms { unless ($csec) { $csec=''; } - my $fcat=$env{'form.fcat'}; - unless ($fcat) { $fcat=''; } - # --------------------------------------------------------- Get all assessments - &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allkeys, \%allmaps, $fcat, \%defp, \%mapp, \%symbp,\%maptitles,\%uris); + &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps, + \%mapp, \%symbp,\%maptitles,\%uris, + \%keyorder); $mapp{'0.0'} = ''; $symbp{'0.0'} = ''; @@ -946,185 +1186,40 @@ sub assessparms { # ---------------------------------------------------------------- Done storing $message.='

'.&mt('Changes can take up to 10 minutes before being active for all students.').&Apache::loncommon::help_open_topic('Caching').'

'; } -# ------------------------------------------------------------------- Sort this - - @ids=sort { - if ($fcat eq '') { - $a<=>$b; - } else { - my ($result,@outpar)=&parmval($fcat,$a,$defp{$a},$uname,$udom,$csec); - my $aparm=$outpar[$result]; - ($result,@outpar)=&parmval($fcat,$b,$defp{$b},$uname,$udom,$csec); - my $bparm=$outpar[$result]; - 1*$aparm<=>1*$bparm; - } - } @ids; #----------------------------------------------- if all selected, fill in array - if ($pscat[0] eq "all" || !@pscat) {@pscat = (keys %allparms);} + if ($pscat[0] eq "all") {@pscat = (keys %allparms);} + if (!@pscat) { @pscat=('duedate','opendate','answerdate','weight','maxtries') }; if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);} # ------------------------------------------------------------------ Start page - &startpage($r,$id,$udom,$csec,$uname,scalar(keys(%allkeys))); - - $r->print(''); + &startpage($r); foreach ('tolerance','date_default','date_start','date_end', 'date_interval','int','float','string') { $r->print(''); } - - $r->print('

'.$message.'

'); - my $submitmessage = &mt('Update Section or Specific User'); if (!$pssymb) { - $r->print('\n"); - - $r->print(''); + $r->print('
'.&mt('Select Parameter Level'). - &Apache::loncommon::help_open_topic('Course_Parameter_Levels'). - ''); - $r->print('
'); - $r->print('\n"); + $r->print(''); } + $r->print('
'); + &levelmenu($r,\%alllevs,$parmlev); if ($parmlev ne 'general') { - $r->print('
'.&mt('Select Enclosing Map or Folder').'
'); + &mapmenu($r,\%allmaps,$pschp,\%maptitles); + $r->print('
'); + &displaymenu($r,\%allparms,\%allparts,\@pscat,\@psprt,\%keyorder); } else { my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb); - $r->print("".&mt('Specific Resource')."$resource"); - $r->print(''); - $r->print(''); - $r->print(''); - } - - $r->print('

'); -# $r->print("Show: $showoptions"); -# $r->print("pscat: @pscat"); -# $r->print("psprt: @psprt"); -# $r->print("fcat: $fcat"); - - if ($showoptions eq 'show') { - my $tempkey; - - $r->print(''.&mt('Select Parameters to View').''); - - $r->print(''); - my $cnt=0; - foreach $tempkey (sort { $allparms{$a} cmp $allparms{$b} } - keys %allparms ) { - ++$cnt; - $r->print('') if ($cnt%2); - $r->print(''); - } - $r->print(' - -'); - $r->print('
print('value="'.$tempkey.'"'); - if ($pscat[0] eq "all" || grep $_ eq $tempkey, @pscat) { - $r->print(' checked'); - } - $r->print('>'.$allparms{$tempkey}.'
- - - - -
'); + &usermenu($r,$uname,$id,$udom,$csec); -# $r->print('Select Parts'); - $r->print('
'); + $r->print('

'.$message.'

'); - $r->print(''.&mt('Sort list by').''); - $r->print(''); - - $r->print('
'); - - } else { # hide options - include any necessary extras here - - $r->print(''."\n"); - - unless (@pscat) { - foreach (keys %allparms ) { - $r->print(''."\n"); - } - } else { - foreach (@pscat) { - $r->print(''."\n"); - } - } - - unless (@psprt) { - foreach (keys %allparts ) { - $r->print(''."\n"); - } - } else { - foreach (@psprt) { - $r->print(''."\n"); - } - } - - } - $r->print('
'); - if (($prevvisit) || ($pschp) || ($pssymb)) { - $submitmessage = &mt("Update Course Assessment Parameter Display"); - } else { - $submitmessage = &mt("Set/Modify Course Assessment Parameters"); - } - $r->print(''); - -# my @temp_psprt; -# foreach my $t (@psprt) { -# push(@temp_psprt, grep {eval (/^$t\./ || ($_ == $t))} (keys %allparts)); -# } - -# @psprt = @temp_psprt; + $r->print('
'); my @temp_pscat; map { @@ -1134,7 +1229,7 @@ sub assessparms { @pscat = @temp_pscat; - if (($prevvisit) || ($pschp) || ($pssymb)) { + if (($env{'form.prevvisit'}) || ($pschp) || ($pssymb)) { # ----------------------------------------------------------------- Start Table my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat; my $csuname=$env{'user.name'}; @@ -1226,7 +1321,7 @@ ENDTABLEHEADFOUR my %default=(); my $uri=&Apache::lonnet::declutter($uris{$rid}); - foreach (split(/\,/,$keyp{$rid})) { + foreach (&keysplit($keyp{$rid})) { my $tempkeyp = $_; if (grep $_ eq $tempkeyp, @catmarker) { $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part'); @@ -1270,7 +1365,7 @@ ENDTABLEHEADFOUR $r->print(''); - foreach (sort keys %name) { + foreach (&keysinorder(\%name,\%keyorder)) { unless ($firstrow) { $r->print(''); } else { @@ -1333,7 +1428,7 @@ ENDTABLEHEADFOUR # When storing information, store as part 0 # When requesting information, request from full part #------------------------------------------------------------------- - foreach (split(/\,/,$keyp{$rid})) { + foreach (&keysplit($keyp{$rid})) { my $tempkeyp = $_; my $fullkeyp = $tempkeyp; $tempkeyp =~ s/_\w+_/_0_/; @@ -1383,12 +1478,11 @@ ENDMAPONE $r->print(''.&mt('Default Value').''); $r->print(''.&mt('Parameter in Effect').''); - foreach (sort keys %name) { + foreach (&keysinorder(\%name,\%keyorder)) { $r->print(''); &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default, \%type,\%display,$defbgone,$defbgtwo, $parmlev,$uname,$udom,$csec); -# $r->print("resource.$part{$_}.$name{$_},$symbp{$mapid}\n"); } $r->print(""); } # end each map @@ -1420,7 +1514,7 @@ ENDMAPONE # When storing information, store as part 0 # When requesting information, request from full part #------------------------------------------------------------------- - foreach (split(/\,/,$keyp{$rid})) { + foreach (&keysplit($keyp{$rid})) { my $tempkeyp = $_; my $fullkeyp = $tempkeyp; $tempkeyp =~ s/_\w+_/_0_/; @@ -1461,11 +1555,10 @@ ENDMAPONE $r->print(''.&mt('Default Value').''); $r->print(''.&mt('Parameter in Effect').''); - foreach (sort keys %name) { + foreach (&keysinorder(\%name,\%keyorder)) { $r->print(''); &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default, \%type,\%display,$defbgone,$defbgtwo,$parmlev,$uname,$udom,$csec); -# $r->print("resource.$part{$_}.$name{$_},$symbp{$mapid}\n"); } $r->print(""); } # end of $parmlev eq general @@ -1687,8 +1780,8 @@ sub crsenv { 'anonymous_quiz' => ''.&mt('Anonymous quiz/exam').'
'. ' ('.&mt('yes').' '.&mt('to avoid print students names').' )', - 'default_enrollment_start_date' => ''.&mt('Default beginning date when enrolling students').'', - 'default_enrollment_end_date' => ''.&mt('Default ending date when enrolling students').'', + 'default_enrollment_start_date' => ''.&mt('Default beginning date for student access.').'', + 'default_enrollment_end_date' => ''.&mt('Default ending date for student access.').'', 'nothideprivileged' => ''.&mt('Privileged users that should not be hidden on staff listings').''. '
(user:domain,user:domain,...)', 'languages' => ''.&mt('Languages used').'', @@ -1805,7 +1898,8 @@ $output ENDenv } ################################################## - +# Overview mode +################################################## my $tableopen; sub tablestart { @@ -1827,26 +1921,38 @@ sub tableend { } } -sub overview { - my $r=shift; - my $bodytag=&Apache::loncommon::bodytag( - 'Set/Modify Course Assessment Parameters'); - my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; - my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview'); - my $html=&Apache::lonxml::xmlbegin(); - $r->print(< -LON-CAPA Course Environment - -$bodytag -$breadcrumbs -
- -ENDOVER +sub readdata { + my ($crs,$dom)=@_; +# Read coursedata + my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom); +# Read userdata + + my $classlist=&Apache::loncoursedata::get_classlist(); + foreach (keys %$classlist) { + # the following undefs are for 'domain', and 'username' respectively. + if ($_=~/^(\w+)\:(\w+)$/) { + my ($tuname,$tudom)=($1,$2); + my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom); + foreach my $userkey (keys %{$useropt}) { + if ($userkey=~/^$env{'request.course.id'}/) { + my $newkey=$userkey; + $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./; + $$resourcedata{$newkey}=$$useropt{$userkey}; + } + } + } + } + return $resourcedata; +} + + # Setting - my %olddata=&Apache::lonnet::dump('resourcedata',$dom,$crs); + +sub storedata { + my ($r,$crs,$dom)=@_; +# Set userlevel immediately +# Do an intermediate store of course level + my $olddata=&readdata($crs,$dom); my %newdata=(); undef %newdata; my @deldata=(); @@ -1855,18 +1961,66 @@ ENDOVER if ($_=~/^form\.([a-z]+)\_(.+)$/) { my $cmd=$1; my $thiskey=$2; + my ($tuname,$tudom)=&extractuser($thiskey); + my $tkey=$thiskey; + if ($tuname) { + $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./; + } if ($cmd eq 'set') { my $data=$env{$_}; - if ($olddata{$thiskey} ne $data) { $newdata{$thiskey}=$data; } + my $typeof=$env{'form.typeof_'.$thiskey}; + if ($$olddata{$thiskey} ne $data) { + if ($tuname) { + if (&Apache::lonnet::put('resourcedata',{$tkey=>$data, + $tkey.'.type' => $typeof}, + $tudom,$tuname) eq 'ok') { + $r->print('
'.&mt('Stored modified parameter for').' '. + &Apache::loncommon::plainname($tuname,$tudom)); + } else { + $r->print('

'. + &mt('Error storing parameters').'

'); + } + &Apache::lonnet::devalidateuserresdata($tuname,$tudom); + } else { + $newdata{$thiskey}=$data; + $newdata{$thiskey.'.type'}=$typeof; + } + } } elsif ($cmd eq 'del') { - push (@deldata,$thiskey); + if ($tuname) { + if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') { + $r->print('
'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom)); + } else { + $r->print('

'. + &mt('Error deleting parameters').'

'); + } + &Apache::lonnet::devalidateuserresdata($tuname,$tudom); + } else { + push (@deldata,$thiskey); + } } elsif ($cmd eq 'datepointer') { my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_}); - if (defined($data) and $olddata{$thiskey} ne $data) { $newdata{$thiskey}=$data; } + my $typeof=$env{'form.typeof_'.$thiskey}; + if (defined($data) and $$olddata{$thiskey} ne $data) { + if ($tuname) { + if (&Apache::lonnet::put('resourcedata',{$tkey=>$data, + $tkey.'.type' => $typeof}, + $tudom,$tuname) eq 'ok') { + $r->print('
'.&mt('Stored modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom)); + } else { + $r->print('

'. + &mt('Error storing parameters').'

'); + } + &Apache::lonnet::devalidateuserresdata($tuname,$tudom); + } else { + $newdata{$thiskey}=$data; + $newdata{$thiskey.'.type'}=$typeof; + } + } } } } -# Store +# Store all course level my $delentries=$#deldata+1; my @newdatakeys=keys %newdata; my $putentries=$#newdatakeys+1; @@ -1881,32 +2035,23 @@ ENDOVER } if ($putentries) { if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') { - $r->print('

'.&mt('Stored [_1] parameter(s)

',$putentries)); + $r->print('

'.&mt('Stored [_1] parameter(s)',$putentries/2).'

'); } else { $r->print('

'. &mt('Error storing parameters').'

'); } &Apache::lonnet::devalidatecourseresdata($crs,$dom); } -# Read coursedata - my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom); -# Read userdata +} - my $classlist=&Apache::loncoursedata::get_classlist(); - foreach (keys %$classlist) { - # the following undefs are for 'domain', and 'username' respectively. - if ($_=~/^(\w+)\:(\w+)$/) { - my ($tuname,$tudom)=($1,$2); - my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom); - foreach my $userkey (keys %{$useropt}) { - if ($userkey=~/^$env{'request.course.id'}/) { - my $newkey=$userkey; - $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./; - $$resourcedata{$newkey}=$$useropt{$userkey}; - } - } - } - } +sub extractuser { + my $key=shift; + return ($key=~/^$env{'request.course.id'}.\[useropt\:(\w+)\:(\w+)\]\./); +} + +sub listdata { + my ($r,$resourcedata,$listdata,$sortorder)=@_; +# Start list output my $oldsection=''; my $oldrealm=''; @@ -1914,22 +2059,34 @@ ENDOVER my $pointer=0; $tableopen=0; my $foundkeys=0; - foreach my $thiskey (sort keys %{$resourcedata}) { - if ($$resourcedata{$thiskey.'.type'}) { - $r->print($thiskey); - my ($course,$middle,$part,$name)= - ($thiskey=~/^(\w+)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/); + foreach my $thiskey (sort { + if ($sortorder eq 'realmstudent') { + my ($astudent,$arealm)=($a=~/^$env{'request.course.id'}\.([^\.]+)\.(.+)\.[^\.]+$/); + my ($bstudent,$brealm)=($b=~/^$env{'request.course.id'}\.([^\.]+)\.(.+)\.[^\.]+$/); + ($arealm cmp $brealm) || ($astudent cmp $bstudent); + } else { + $a cmp $b; + } + } keys %{$listdata}) { + if ($$listdata{$thiskey.'.type'}) { + my $thistype=$$listdata{$thiskey.'.type'}; + if ($$resourcedata{$thiskey.'.type'}) { + $thistype=$$resourcedata{$thiskey.'.type'}; + } + my ($middle,$part,$name)= + ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/); my $section=&mt('All Students'); - if ($middle=~/^\[(.*)\]\./) { + if ($middle=~/^\[(.*)\]/) { my $issection=$1; if ($issection=~/^useropt\:(\w+)\:(\w+)/) { $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2); } else { $section=&mt('Group/Section').': '.$issection; } - $middle=~s/^\[(.*)\]\.//; + $middle=~s/^\[(.*)\]//; } - $middle=~s/\.$//; + $middle=~s/\.+$//; + $middle=~s/^\.+//; my $realm=''.&mt('All Resources').''; if ($middle=~/^(.+)\_\_\_\(all\)$/) { $realm=''.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).'
('.$1.')
'; @@ -1937,19 +2094,32 @@ ENDOVER my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle); $realm=''.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).'
('.$url.' in '.$map.' id: '.$id.')
'; } - if ($section ne $oldsection) { - $r->print(&tableend()."\n

$section

"); - $oldsection=$section; - $oldrealm=''; - } - if ($realm ne $oldrealm) { - $r->print(&tableend()."\n

$realm

"); - $oldrealm=$realm; - $oldpart=''; + if ($sortorder eq 'realmstudent') { + if ($realm ne $oldrealm) { + $r->print(&tableend()."\n

$realm

"); + $oldrealm=$realm; + $oldsection=''; + } + if ($section ne $oldsection) { + $r->print(&tableend()."\n

$section

"); + $oldsection=$section; + $oldpart=''; + } + } else { + if ($section ne $oldsection) { + $r->print(&tableend()."\n

$section

"); + $oldsection=$section; + $oldrealm=''; + } + if ($realm ne $oldrealm) { + $r->print(&tableend()."\n

$realm

"); + $oldrealm=$realm; + $oldpart=''; + } } if ($part ne $oldpart) { $r->print(&tableend(). - "\n

".&mt('Part').": $part

"); + "\n".&mt('Part').": $part"); $oldpart=$part; } # @@ -1959,7 +2129,7 @@ ENDOVER ':'); $foundkeys++; - if ($$resourcedata{$thiskey.'.type'}=~/^date/) { + if (&isdateparm($thistype)) { my $jskey='key_'.$pointer; $pointer++; $r->print( @@ -1969,16 +2139,197 @@ ENDOVER '' ); } else { - $r->print( - ''); } + $r->print(''); $r->print(''); } } - + return $foundkeys; +} + +sub newoverview { + my $r=shift; + my $bodytag=&Apache::loncommon::bodytag('Set Parameters'); + my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview'); + my $html=&Apache::lonxml::xmlbegin(); + $r->print(< +LON-CAPA Parameters + +$bodytag +$breadcrumbs + +ENDOVER + my @ids=(); + my %typep=(); + my %keyp=(); + my %allparms=(); + my %allparts=(); + my %allmaps=(); + my %mapp=(); + my %symbp=(); + my %maptitles=(); + my %uris=(); + my %keyorder=&standardkeyorder(); + my %defkeytype=(); + + my %alllevs=(); + $alllevs{'Resource Level'}='full'; + $alllevs{'Map/Folder Level'}='map'; + $alllevs{'Course Level'}='general'; + + my $csec=$env{'form.csec'}; + + my @pscat=&Apache::loncommon::get_env_multiple('form.pscat'); + my $pschp=$env{'form.pschp'}; + my @psprt=&Apache::loncommon::get_env_multiple('form.psprt'); + if (!@psprt) { $psprt[0]='0'; } + + my @selected_sections = + &Apache::loncommon::get_env_multiple('form.Section'); + @selected_sections = ('all') if (! @selected_sections); + foreach (@selected_sections) { + if ($_ eq 'all') { + @selected_sections = ('all'); + } + } + + my $pssymb=''; + my $parmlev=''; + + unless ($env{'form.parmlev'}) { + $parmlev = 'map'; + } else { + $parmlev = $env{'form.parmlev'}; + } + + &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps, + \%mapp, \%symbp,\%maptitles,\%uris, + \%keyorder,\%defkeytype); + +# Menu to select levels, etc + + $r->print(''); + } + $r->print('
'); + &levelmenu($r,\%alllevs,$parmlev); + if ($parmlev ne 'general') { + $r->print(''); + &mapmenu($r,\%allmaps,$pschp,\%maptitles); + $r->print('
'); + + $r->print('
'); + &parmmenu($r,\%allparms,\@pscat,\%keyorder); + $r->print(''); + &partmenu($r,\%allparts,\@psprt); + $r->print(''); + §ionmenu($r,\@selected_sections); + + $r->print('
'); + + my $sortorder=$env{'form.sortorder'}; + unless ($sortorder) { $sortorder='realmstudent'; } + &sortmenu($r,$sortorder); + + $r->print('

'); + +# Build the list data hash from the specified parms + + my $listdata; + %{$listdata}=(); + + foreach my $cat (@pscat) { + foreach my $section (@selected_sections) { + foreach my $part (@psprt) { + my $rootparmkey=$env{'request.course.id'}; + if (($section ne 'all') && ($section ne 'none') && ($section)) { + $rootparmkey.='.['.$section.']'; + } + if ($parmlev eq 'general') { +# course-level parameter + my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat; + $$listdata{$newparmkey}=1; + $$listdata{$newparmkey.'.type'}=$defkeytype{$cat}; + } elsif ($parmlev eq 'map') { +# map-level parameter + foreach my $mapid (keys %allmaps) { + if (($pschp ne 'all') && ($pschp ne $mapid)) { next; } + my $newparmkey=$rootparmkey.'.'.$allmaps{$mapid}.'___(all).'.$part.'.'.$cat; + $$listdata{$newparmkey}=1; + $$listdata{$newparmkey.'.type'}=$defkeytype{$cat}; + } + } else { +# resource-level parameter + foreach my $rid (@ids) { + my ($map,$resid,$url)=&Apache::lonnet::decode_symb($symbp{$rid}); + if (($pschp ne 'all') && ($allmaps{$pschp} ne $map)) { next; } + my $newparmkey=$rootparmkey.'.'.$symbp{$rid}.'.'.$part.'.'.$cat; + $$listdata{$newparmkey}=1; + $$listdata{$newparmkey.'.type'}=$defkeytype{$cat}; + } + } + } + } + } + + if (($env{'form.store'}) || ($env{'form.dis'})) { + + if ($env{'form.store'}) { &storedata($r,$crs,$dom); } + +# Read modified data + + my $resourcedata=&readdata($crs,$dom); + +# List data + + &listdata($r,$resourcedata,$listdata,$sortorder); + } + $r->print(&tableend(). + ((($env{'form.store'}) || ($env{'form.dis'}))?'

':''). + ''); +} + +sub overview { + my $r=shift; + my $bodytag=&Apache::loncommon::bodytag('Modify Parameters'); + my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview'); + my $html=&Apache::lonxml::xmlbegin(); + $r->print(< +LON-CAPA Parameters + +$bodytag +$breadcrumbs +
+ENDOVER +# Store modified + + &storedata($r,$crs,$dom); + +# Read modified data + + my $resourcedata=&readdata($crs,$dom); + + + my $sortorder=$env{'form.sortorder'}; + unless ($sortorder) { $sortorder='realmstudent'; } + &sortmenu($r,$sortorder); + +# List data + + my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder); + $r->print(&tableend().'

'. - ($foundkeys?'':&mt('There are no course or section parameters.')).'

'); + ($foundkeys?'':&mt('There are no parameters.')).'

'); } ################################################## @@ -2109,15 +2460,19 @@ ENDMAINFORMHEAD action => 'crsenv', permission => $parm_permission, }, - { text => 'Set/Modify Course Assessment Parameters - Helper Mode', + { text => 'Set/Modify Resource Parameters - Helper Mode', url => '/adm/helper/parameter.helper', permission => $parm_permission, }, - { text => 'Modify Course Assessment Parameters - Overview Mode', + { text => 'Modify Resource Parameters - Overview Mode', action => 'setoverview', permission => $parm_permission, + }, + { text => 'Set Resource Parameters - Overview Mode', + action => 'newoverview', + permission => $parm_permission, }, - { text => 'Set/Modify Course Assessment Parameters - Table Mode', + { text => 'Set/Modify Resource Parameters - Table Mode', action => 'settable', permission => $parm_permission, help => 'Cascading_Parameters', @@ -2179,7 +2534,7 @@ sub handler { 'pres_marker', 'pres_value', 'pres_type', - 'udom','uname']); + 'udom','uname','symb']); &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -2228,6 +2583,10 @@ sub handler { &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview', text=>"Overview Mode"}); &overview($r); + } elsif ($env{'form.action'} eq 'newoverview' && $parm_permission) { + &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview', + text=>"Overview Mode"}); + &newoverview($r); } elsif ($env{'form.action'} eq 'settable' && $parm_permission) { &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable', text=>"Table Mode",