[LON-CAPA-cvs] cvs: loncom /interface lonparmset.pm
banghart
lon-capa-cvs@mail.lon-capa.org
Fri, 08 Sep 2006 20:49:20 -0000
banghart Fri Sep 8 16:49:20 2006 EDT
Modified files:
/loncom/interface lonparmset.pm
Log:
Instructor side of adding metadata fields sort of, almost works.
(saving work in progress).
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.334 loncom/interface/lonparmset.pm:1.335
--- loncom/interface/lonparmset.pm:1.334 Thu Sep 7 17:57:52 2006
+++ loncom/interface/lonparmset.pm Fri Sep 8 16:49:19 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.334 2006/09/07 21:57:52 banghart Exp $
+# $Id: lonparmset.pm,v 1.335 2006/09/08 20:49:19 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3214,13 +3214,23 @@
my ($r)=@_;
$r->print(&Apache::loncommon::start_page('Add Metadata Field'));
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Add Metadata Field'));
+ my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
if (exists($env{'form.fieldname'})) {
- $r->print('Here is a field');
+ my $meta_field = $env{'form.fieldname'};
+ my $display_field = $env{'form.fieldname'};
+ $meta_field =~ s/\W/_/g;
+ my $put_result = &Apache::lonnet::put('environment',
+ {'metadata.'.$meta_field.'.values'=>"",
+ 'metadata.'.$meta_field.'.added'=>"$display_field",
+ 'metadata.'.$meta_field.'.options'=>""},$dom,$crs);
+ $r->print('Added new Metadata Field '.$env{'form.fieldname'}." with result ".$put_result);
+ } else {
+ $r->print('<form method="post" action="/adm/parmset?action=addmetadata"');
+ $r->print('<input type="text" name="fieldname" /><br />');
+ $r->print('<input type="submit" value="Add Metadata Field" />');
+ $r->print('</form>');
}
- $r->print('<form method="post" action="/adm/parmset?action=addmetadata"');
- $r->print('<input type="text" name="fieldname" /><br />');
- $r->print('<input type="submit" value="Add Metadata Field" />');
- $r->print('</form>');
}
sub setrestrictmeta {
my ($r)=@_;
@@ -3228,7 +3238,6 @@
my $output;
my $item_num;
my $put_result;
- &Apache::lonnet::logthis("restricting metadata");
$r->print(&Apache::loncommon::start_page('Restrict Metadata'));
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Restrict Metadata'));
my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -3263,13 +3272,18 @@
}
&Apache::lonnet::coursedescription($env{'request.course.id'},
{'freshen_cache' => 1});
+ # Get the default metadata fields
my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
+ # Now get possible added metadata fields
+ my $added_metadata_fields = &get_added_meta_fieldnames(\%metadata_fields);
foreach my $field (sort(keys(%metadata_fields))) {
- &Apache::lonnet::logthis ($field);
if ($field ne 'courserestricted') {
$output.= &output_row($r, $field, $metadata_fields{$field});
}
}
+ foreach my $field (sort(keys(%$added_metadata_fields))) {
+ $output.= &output_row($r, $field, $$added_metadata_fields{$field});
+ }
$r->print(<<ENDenv);
<form method="post" action="/adm/parmset?action=setrestrictmeta" name="form">
<p>
@@ -3284,7 +3298,18 @@
return 'ok';
}
##################################################
-
+sub get_added_meta_fieldnames {
+ my %fields;
+ my ($default_fields) = @_;
+ foreach my $key(%env) {
+ if ($key =~ m/\.metadata\.(.+)\.added$/) {
+ my $field_name = $1;
+ my ($display_field_name) = $env{$key};
+ $fields{$field_name} = $display_field_name;
+ }
+ }
+ return \%fields;
+}
sub defaultsetter {
my ($r) = @_;