--- loncom/interface/lonparmset.pm 2005/06/28 15:26:06 1.234
+++ loncom/interface/lonparmset.pm 2005/11/11 20:37:47 1.264
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.234 2005/06/28 15:26:06 albertel Exp $
+# $Id: lonparmset.pm,v 1.264 2005/11/11 20:37:47 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -904,12 +904,12 @@ ENDSCRIPT
$r->print("\n
");
my $cnt=0;
foreach $tempkey (&keysindisplayorder($allparms,$keyorder)) {
- $r->print("\nprint("\n | | ');
+ $r->print('>'.$$allparms{$tempkey}.'');
$cnt++;
if ($cnt==3) {
$r->print("
\n");
@@ -1067,6 +1067,18 @@ sub keysinorder {
} (keys %{$name});
}
+sub keysinorder_bytype {
+ my ($name,$keyorder)=@_;
+ return sort {
+ my $ta=(split('_',$a))[-1];
+ my $tb=(split('_',$b))[-1];
+ if ($$keyorder{'parameter_0_'.$ta} == $$keyorder{'parameter_0_'.$tb}) {
+ return ($a cmp $b);
+ }
+ $$keyorder{'parameter_0_'.$ta} <=> $$keyorder{'parameter_0_'.$tb};
+ } (keys %{$name});
+}
+
sub keysindisplayorder {
my ($name,$keyorder)=@_;
return sort {
@@ -1076,16 +1088,17 @@ sub keysindisplayorder {
sub sortmenu {
my ($r,$sortorder)=@_;
- $r->print('
print('
');
}
sub standardkeyorder {
@@ -1317,7 +1330,9 @@ sub assessparms {
} else {
my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb);
$r->print(&mt('Specific Resource').": ".$resource.
- '
');
+ ''.
+ '
');
}
&usermenu($r,$uname,$id,$udom,$csec);
@@ -1462,14 +1477,9 @@ ENDTABLEHEADFOUR
$r->print('');
-
- $r->print(' / res / ');
- $r->print(join(' / ', split(/\//,$mapp{$rid})));
-
- $r->print(' | ');
+ '>'.$maptitles{$mapp{$rid}}.'');
- foreach (&keysinorder(\%name,\%keyorder)) {
+ foreach (&keysinorder_bytype(\%name,\%keyorder)) {
unless ($firstrow) {
$r->print('
');
} else {
@@ -1759,9 +1769,13 @@ sub crsenv {
#
# Let the user know we made the changes
if ($name && defined($value)) {
+ my $failed_cloners;
if ($name eq 'cloners') {
+ $value =~ s/\s//g;
$value =~ s/^,//;
$value =~ s/,$//;
+ # check requested clones are valid users.
+ $failed_cloners = &check_cloners(\$value,\@oldcloner);
}
my $put_result = &Apache::lonnet::put('environment',
{$name=>$value},$dom,$crs);
@@ -1778,6 +1792,18 @@ sub crsenv {
$setoutput.=&mt('Unable to set').' '.$name.' '.&mt('to').
' '.$value.' '.&mt('due to').' '.$put_result.'.
';
}
+ if (($name eq 'cloners') && ($failed_cloners)) {
+ $setoutput.= &mt('Unable to include').' - '.$failed_cloners.', '.
+ &mt('reason').' - '.&mt('LON-CAPA user(s) do(es) not exist').
+ '.
'.&mt('Please ').
+ ' '.
+ &mt('add the user(s)').', '.
+ &mt('and then return to the ').
+ ''.
+ &mt('Course Parameters page').' '.
+ &mt('to add the new user(s) to the list of possible cloners').
+ '.
';
+ }
}
}
# ------------------------- Re-init course environment entries for this session
@@ -1895,6 +1921,9 @@ sub crsenv {
'disablesigfigs'
=> ''.&mt('Disable checking of Significant Figures').'
'.
' ('.&mt('"[_1]" to disable, anything else if not','yes').')',
+ 'disableexampointprint'
+ => ''.&mt('Disable automatically printing point values onto exams.').'
'.
+ ' ('.&mt('"[_1]" to disable, anything else if not','yes').')',
'tthoptions'
=> ''.&mt('Default set of options to pass to tth/m when converting tex').''
);
@@ -1921,10 +1950,11 @@ sub crsenv {
'default_enrollment_start_date',
'default_enrollment_end_date',
'tthoptions',
- 'disablesigfigs'
+ 'disablesigfigs',
+ 'disableexampointprint'
);
foreach my $parameter (sort(keys(%values))) {
- unless ($parameter =~ m/^internal\./) {
+ unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./)) {
if (! $descriptions{$parameter}) {
$descriptions{$parameter}=$parameter;
push(@Display_Order,$parameter);
@@ -2163,15 +2193,41 @@ sub listdata {
my $pointer=0;
$tableopen=0;
my $foundkeys=0;
+ my %keyorder=&standardkeyorder();
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);
+ my ($astudent,$arealm)=($a=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)\.[^\.]+$/);
+ my ($bstudent,$brealm)=($b=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)\.[^\.]+$/);
+ if (!defined($astudent)) {
+ ($arealm)=($a=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
+ }
+ if (!defined($bstudent)) {
+ ($brealm)=($b=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
+ }
+ $arealm=~s/\.type//;
+ my ($ares, $aparm) = ($arealm=~/^(.*)\.(.*)$/);
+ $aparm=$keyorder{'parameter_0_'.$aparm};
+ $brealm=~s/\.type//;
+ my ($bres, $bparm) = ($brealm=~/^(.*)\.(.*)$/);
+ $bparm=$keyorder{'parameter_0_'.$bparm};
+ if ($ares eq $bres) {
+ if (defined($aparm) && defined($bparm)) {
+ ($aparm <=> $bparm);
+ } elsif (defined($aparm)) {
+ -1;
+ } elsif (defined($bparm)) {
+ 1;
+ } else {
+ ($arealm cmp $brealm) || ($astudent cmp $bstudent);
+ }
+ } else {
+ ($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'}) {
@@ -2475,25 +2531,76 @@ ENDOVER
##################################################
=pod
-
-=item change clone
-
+
+=item check_cloners
+
+Checks if new users included in list of allowed cloners
+are valid users. Replaces supplied list with
+cleaned list containing only users with valid usernames
+and domains.
+
+Inputs: $clonelist, $oldcloner
+where $clonelist is ref to array of requested cloners,
+and $oldcloner is ref to array of currently allowed
+cloners.
+
+Returns: string - comma separated list of requested
+cloners (username:domain) who do not exist in system.
+
+=item change_clone
+
Modifies the list of courses a user can clone (stored
-in the user's environemnt.db file), called when a
+in the user's environment.db file), called when a
change is made to the list of users allowed to clone
a course.
-
+
Inputs: $action,$cloner
where $action is add or drop, and $cloner is identity of
user for whom cloning ability is to be changed in course.
-
-Returns:
=cut
##################################################
##################################################
+sub extract_cloners {
+ my ($clonelist,$allowclone) = @_;
+ if ($clonelist =~ /,/) {
+ @{$allowclone} = split/,/,$clonelist;
+ } else {
+ $$allowclone[0] = $clonelist;
+ }
+}
+
+
+sub check_cloners {
+ my ($clonelist,$oldcloner) = @_;
+ my ($clean_clonelist,$disallowed);
+ my @allowclone = ();
+ &extract_cloners($$clonelist,\@allowclone);
+ foreach my $currclone (@allowclone) {
+ if (!grep/^$currclone$/,@$oldcloner) {
+ my ($uname,$udom) = split/:/,$currclone;
+ if ($uname && $udom) {
+ if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
+ $disallowed .= $currclone.',';
+ } else {
+ $clean_clonelist .= $currclone.',';
+ }
+ }
+ } else {
+ $clean_clonelist .= $currclone.',';
+ }
+ }
+ if ($disallowed) {
+ $disallowed =~ s/,$//;
+ }
+ if ($clean_clonelist) {
+ $clean_clonelist =~ s/,$//;
+ }
+ $$clonelist = $clean_clonelist;
+ return $disallowed;
+}
sub change_clone {
my ($clonelist,$oldcloner) = @_;
@@ -2503,12 +2610,8 @@ sub change_clone {
my $clone_crs = $cnum.':'.$cdom;
if ($cnum && $cdom) {
- my @allowclone = ();
- if ($clonelist =~ /,/) {
- @allowclone = split/,/,$clonelist;
- } else {
- $allowclone[0] = $clonelist;
- }
+ my @allowclone;
+ &extract_cloners($clonelist,\@allowclone);
foreach my $currclone (@allowclone) {
if (!grep/^$currclone$/,@$oldcloner) {
($uname,$udom) = split/:/,$currclone;
@@ -2599,6 +2702,10 @@ ENDMAINFORMHEAD
action => 'crsenv',
permission => $parm_permission,
},
+ { text => 'Set Portfolio Metadata',
+ action => 'setrestrictmeta',
+ permission => $parm_permission,
+ },
{ text => 'Set/Modify Resource Parameters - Helper Mode',
url => '/adm/helper/parameter.helper',
permission => $parm_permission,
@@ -2642,8 +2749,90 @@ ENDMAINFORMHEAD
$r->print($menu_html);
return;
}
-
-
+### Set portfolio metadata
+sub output_row {
+ my ($r, $field_name, $field_text) = @_;
+ my $output;
+ my $options=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'};
+ my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.values'};
+ unless (defined($options)) {
+ $options = 'active,stuadd';
+ $values = '';
+ }
+ $output.=''.$field_text.':';
+ $output.='
';
+
+ my @options= ( ['active', 'Show to student'],
+ ['onlyone','Student may select only one choice'],
+ ['stuadd', 'Student may type choices']);
+ foreach my $opt (@options) {
+ my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ;
+ $output.=(' 'x5).'
';
+ }
+ return ($output);
+}
+
+sub setrestrictmeta {
+ my ($r)=@_;
+ my $next_meta;
+ my $output;
+ my $item_num;
+ my $put_result;
+ $r->print(&Apache::lonxml::xmlbegin());
+ $r->print('
+ LON-CAPA Restrict Metadata
+ ');
+ $r->print(&Apache::loncommon::bodytag('Restrict Metadata'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs(undef,
+ 'Restrict Metadata'));
+ my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $key_base = $env{'course.'.$env{'request.course.id'}.'.'};
+ my $save_field = '';
+ if ($env{'form.restrictmeta'}) {
+ foreach my $field (sort(keys(%env))) {
+ if ($field=~m/^form.(.+)_(.+)$/) {
+ my $options;
+ my $meta_field = $1;
+ my $meta_key = $2;
+ if ($save_field ne $meta_field) {
+ $save_field = $meta_field;
+ if ($env{'form.'.$meta_field.'_stuadd'}) {
+ $options.='stuadd,';
+ }
+ if ($env{'form.'.$meta_field.'_onlyone'}) {
+ $options.='onlyone,';
+ }
+ if ($env{'form.'.$meta_field.'_active'}) {
+ $options.='active,';
+ }
+ my $name = $save_field;
+ $put_result = &Apache::lonnet::put('environment',
+ {'metadata.'.$meta_field.'.options'=>$options,
+ 'metadata.'.$meta_field.'.values'=>$env{'form.'.$meta_field.'_values'},
+ },$dom,$crs);
+ }
+ }
+ }
+ }
+ &Apache::lonnet::coursedescription($env{'request.course.id'});
+ my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
+ foreach my $field (sort(keys(%metadata_fields))) {
+ $output.= &output_row($r, $field, $metadata_fields{$field});
+ }
+ $r->print(<
+
+ $output
+
+
+ENDenv
+ $r->print('