--- loncom/interface/lonmeta.pm 2005/08/02 17:01:20 1.101
+++ loncom/interface/lonmeta.pm 2005/12/19 16:00:05 1.140
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Metadata display handler
#
-# $Id: lonmeta.pm,v 1.101 2005/08/02 17:01:20 banghart Exp $
+# $Id: lonmeta.pm,v 1.140 2005/12/19 16:00:05 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -243,16 +243,18 @@ sub fieldnames {
'authorspace' => 'Author Space',
'modifyinguser' => 'Last Modifying User',
'subject' => 'Subject',
+ 'standards' => 'Standards',
'keywords' => 'Keyword(s)',
'notes' => 'Notes',
'abstract' => 'Abstract',
'lowestgradelevel' => 'Lowest Grade Level',
- 'highestgradelevel' => 'Highest Grade Level');
+ 'highestgradelevel' => 'Highest Grade Level',
+ 'courserestricted' => 'Course Restricting Metadata');
+
if (! defined($file_type) || $file_type ne 'portfolio') {
%fields =
(%fields,
'domain' => 'Domain',
- 'standards' => 'Standards',
'mime' => 'MIME Type',
'language' => 'Language',
'creationdate' => 'Creation Date',
@@ -282,35 +284,66 @@ sub fieldnames {
'stdno' => 'Total number of students who have worked on this problem',
'difficulty' => 'Degree of difficulty',
'disc' => 'Degree of discrimination',
- 'dependencies' => 'Resources used by this resource',
+ 'dependencies' => 'Resources used by this resource',
);
}
return &Apache::lonlocal::texthash(%fields);
}
-
-sub select_course {
- my ($r)=@_;
- $r->print('
Instructor Selected Meta-Data
');
- $r->print('');
- return 'ok';
+ &Apache::lonnet::logthis('the restricted is'.$Apache::lonpublisher::metadatafields{'courserestricted'});
+ my $meta_not_found = 1;
+ if ($Apache::lonpublisher::metadatafields{'courserestricted'} eq 'none') {
+ $selected = ' SELECTED ';
+ } else {
+ $selected = '';
+ }
+ $output .= '
';
+ return ($output);
}
# Pretty printing of metadata field
@@ -464,10 +497,71 @@ sub relatedfield {
sub prettyinput {
my ($type,$value,$fieldname,$formname,
- $relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
+ $relatedsearchflag,$relatedsep,$relatedvalue,$size,$course_key)=@_;
if (! defined($size)) {
$size = 80;
}
+ my $output;
+ if (defined($course_key)) {
+ my $stu_add;
+ my $only_one;
+ my %meta_options;
+ my @cur_values_inst;
+ my $cur_values_stu;
+ my $values = $env{$course_key.'.metadata.'.$type.'.values'};
+ if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/stuadd/) {
+ $stu_add = 'true';
+ }
+ if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/onlyone/) {
+ $only_one = 'true';
+ }
+ # need to take instructor values out of list where instructor and student
+ # values may be mixed.
+ if ($values) {
+ foreach my $item (split(/,/,$values)) {
+ $item =~ s/^\s+//;
+ $meta_options{$item} = $item;
+ }
+ foreach my $item (split(/,/,$value)) {
+ $item =~ s/^\s+//;
+ if ($meta_options{$item}) {
+ push(@cur_values_inst,$item);
+ } else {
+ $cur_values_stu .= $item.',';
+ }
+ }
+ } else {
+ $cur_values_stu = $value;
+ }
+ if ($type eq 'courserestricted') {
+ return (&select_course());
+ # return ('');
+ }
+ if (($type eq 'keywords') || ($type eq 'subject')
+ || ($type eq 'author')||($type eq 'notes')
+ || ($type eq 'abstract')|| ($type eq 'title')|| ($type eq 'standards')) {
+ if ($values) {
+ if ($only_one) {
+ $output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options));
+ } else {
+ $output .= (&Apache::loncommon::multiple_select_form('new_'.$type,\@cur_values_inst,undef,\%meta_options));
+ }
+ }
+ if ($stu_add) {
+ $output .= ''.
+ &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
+ $relatedvalue);
+ }
+ return ($output);
+ }
+ if (($type eq 'lowestgradelevel') ||
+ ($type eq 'highestgradelevel')) {
+ return &Apache::loncommon::select_level_form($value,$fieldname).
+ &relatedfield(0,$relatedsearchflag,$relatedsep);
+ }
+ return();
+ }
# Language
if ($type eq 'language') {
return &selectbox($fieldname,
@@ -528,6 +622,11 @@ sub prettyinput {
",'rights')\">".&mt('Select').''.
&relatedfield(0,$relatedsearchflag,$relatedsep);
}
+ if ($type eq 'courserestricted') {
+ return (&select_course());
+ #return ('');
+ }
+
# Dates
if (($type eq 'creationdate') ||
($type eq 'lastrevisiondate')) {
@@ -569,11 +668,15 @@ sub handler {
# Looking for all bombs?
&report_bombs($r,$uri);
} elsif ($uri=~/\/portfolio\//) {
+ ($resdomain,$resuser)=
+ (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
$r->print(&Apache::loncommon::bodytag
('Edit Portfolio File Information','','','',$resdomain));
- &present_editable_metadata($r,$uri,'portfolio');
- &select_course($r);
-
+ if ($env{'form.store'}) {
+ &present_editable_metadata($r,$uri,'portfolio');
+ } else {
+ &pre_select_course($r,$uri);
+ }
} elsif ($uri=~/^\/\~/) {
# Construction space
$r->print(&Apache::loncommon::bodytag
@@ -908,6 +1011,8 @@ sub print_dynamic_metadata {
return;
}
+
+
#####################################################
#####################################################
### ###
@@ -923,6 +1028,7 @@ sub present_editable_metadata {
my $fn=&Apache::lonnet::filelocation('',$uri);
$disuri=~s/^\/\~/\/priv\//;
$disuri=~s/\.meta$//;
+ $disuri=~s|^/editupload||;
my $target=$uri;
$target=~s/^\/\~/\/res\/$env{'request.role.domain'}\//;
$target=~s/\.meta$//;
@@ -976,7 +1082,7 @@ ENDDEL
%Apache::lonpublisher::metadatakeys=();
my $result=&Apache::lonnet::getfile($fn);
if ($result == -1){
- $r->print('Creating new '.$fn);
+ $r->print('Creating new '.$disuri);
} else {
&Apache::lonpublisher::metaeval($result);
}
@@ -992,7 +1098,7 @@ ENDEDIT
my @fields;
if ($file_type eq 'portfolio') {
@fields = ('author','title','subject','keywords','abstract','notes','lowestgradelevel',
- 'highestgradelevel');
+ 'highestgradelevel','standards');
} else {
@fields = ('author','title','subject','keywords','abstract','notes',
'copyright','customdistributionfile','language',
@@ -1000,24 +1106,66 @@ ENDEDIT
'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
'obsolete','obsoletereplacement');
}
- foreach (@fields) {
- if (defined($env{'form.new_'.$_})) {
- $Apache::lonpublisher::metadatafields{$_}=
- $env{'form.new_'.$_};
- }
- if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
+ if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
+ (! $env{'form.new_courserestricted'})) {
+ $Apache::lonpublisher::metadatafields{'courserestricted'}=
+ 'none';
+ } elsif ($env{'form.new_courserestricted'}) {
+ $Apache::lonpublisher::metadatafields{'courserestricted'}=
+ $env{'form.new_courserestricted'};
+ }
+ if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
$Apache::lonpublisher::metadatafields{'copyright'}=
- 'default';
+ 'default';
+ }
+ if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
+ $r->print('Using: '.$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.".description"}.
+ " metadata framework
");
+ } else {
+ $r->print("This resource is not associated with a metadata framework
");
+ }
+ foreach my $field_name(@fields) {
+
+ if (defined($env{'form.new_'.$field_name})) {
+ $Apache::lonpublisher::metadatafields{$field_name}=
+ join(',',&Apache::loncommon::get_env_multiple('form.new_'.$field_name));
+ }
+ if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
+ # handle restrictions here
+ if (($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
+ ($field_name eq 'courserestricted')){
+ $output.=(''.$lt{$field_name}.': '.
+ &prettyinput($field_name,
+ $Apache::lonpublisher::metadatafields{$field_name},
+ 'new_'.$field_name,'defaultmeta',
+ undef,undef,undef,undef,
+ $Apache::lonpublisher::metadatafields{'courserestricted'}).'
');
+ }
+ } else {
+
+ $output.=(''.$lt{$field_name}.': '.
+ &prettyinput($field_name,
+ $Apache::lonpublisher::metadatafields{$field_name},
+ 'new_'.$field_name,'defaultmeta').'
');
+
}
- $output.=(''.$lt{$_}.': '.
- &prettyinput($_,
- $Apache::lonpublisher::metadatafields{$_},
- 'new_'.$_,'defaultmeta').'
');
}
- if ($env{'form.store'}) {
+
+ $r->print($output.'
');
+
+ }
+ $r->print('');
+ if ($env{'form.store'}) {
my $mfh;
- my $formname='store';
+ my $formname='store';
my $file_content;
+ foreach my $meta_field (keys %env) {
+ if (&Apache::loncommon::get_env_multiple('form.new_keywords')) {
+ $Apache::lonpublisher::metadatafields{'keywords'} =
+ join (',', &Apache::loncommon::get_env_multiple('form.new_keywords'));
+ }
+ }
foreach (sort keys %Apache::lonpublisher::metadatafields) {
next if ($_ =~ /\./);
my $unikey=$_;
@@ -1029,7 +1177,7 @@ ENDEDIT
$Apache::lonpublisher::metadatakeys{$unikey})
) {
my $value=
- $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
+ $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
$value=~s/\"/\'\'/g;
$file_content.=' '.$_.'="'.$value.'"' ;
# print $mfh ' '.$_.'="'.$value.'"';
@@ -1043,11 +1191,10 @@ ENDEDIT
if ($fn =~ /\/portfolio\//) {
$fn =~ /\/portfolio\/(.*)$/;
my $new_fn = '/'.$1;
- $env{'form.'.$formname}=$file_content;
+ $env{'form.'.$formname}=$file_content."\n";
$env{'form.'.$formname.'.filename'}=$new_fn;
&Apache::lonnet::userfileupload('uploaddoc','',
'portfolio'.$env{'form.currentpath'});
- my $status =&Apache::lonnet::userfileupload($formname,'','portfolio');
if (&Apache::lonnet::userfileupload($formname,'','portfolio') eq 'error: no uploaded file') {
$r->print(''.
&mt('Could not write metadata').', '.
@@ -1070,10 +1217,6 @@ ENDEDIT
}
}
}
- $r->print($output.'
');
- }
- $r->print('');
return;
}