--- loncom/interface/lonmeta.pm 2005/07/15 12:57:53 1.100
+++ loncom/interface/lonmeta.pm 2005/12/19 21:17:25 1.144
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Metadata display handler
#
-# $Id: lonmeta.pm,v 1.100 2005/07/15 12:57:53 banghart Exp $
+# $Id: lonmeta.pm,v 1.144 2005/12/19 21:17:25 albertel 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,32 +284,81 @@ 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
@@ -461,10 +512,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,
@@ -525,6 +637,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')) {
@@ -566,11 +683,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
@@ -905,6 +1026,8 @@ sub print_dynamic_metadata {
return;
}
+
+
#####################################################
#####################################################
### ###
@@ -920,6 +1043,10 @@ sub present_editable_metadata {
my $fn=&Apache::lonnet::filelocation('',$uri);
$disuri=~s/^\/\~/\/priv\//;
$disuri=~s/\.meta$//;
+ my $meta_uri = $disuri;
+ if ($disuri =~ m|/portfolio/|) {
+ ($disuri, $meta_uri) = &portfolio_display_uri($disuri);
+ }
my $target=$uri;
$target=~s/^\/\~/\/res\/$env{'request.role.domain'}\//;
$target=~s/\.meta$//;
@@ -973,7 +1100,7 @@ ENDDEL
%Apache::lonpublisher::metadatakeys=();
my $result=&Apache::lonnet::getfile($fn);
if ($result == -1){
- $r->print('Creating new '.$fn);
+ $r->print(&mt('Creating new file [_1]'),$meta_uri);
} else {
&Apache::lonpublisher::metaeval($result);
}
@@ -989,7 +1116,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',
@@ -997,80 +1124,118 @@ 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';
- }
- $output.=(''.$lt{$_}.': '.
- &prettyinput($_,
- $Apache::lonpublisher::metadatafields{$_},
- 'new_'.$_,'defaultmeta').'
');
+ 'default';
}
- if ($env{'form.store'}) {
- my $mfh;
- my $formname='store';
- my $file_content;
- foreach (sort keys %Apache::lonpublisher::metadatafields) {
- next if ($_ =~ /\./);
- my $unikey=$_;
- $unikey=~/^([A-Za-z]+)/;
- my $tag=$1;
- $tag=~tr/A-Z/a-z/;
- $file_content.= "\n\<$tag";
- foreach (split(/\,/,
- $Apache::lonpublisher::metadatakeys{$unikey})
- ) {
- my $value=
- $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
- $value=~s/\"/\'\'/g;
- $file_content.=' '.$_.'="'.$value.'"' ;
- # print $mfh ' '.$_.'="'.$value.'"';
- }
- $file_content.= '>'.
- &HTML::Entities::encode
- ($Apache::lonpublisher::metadatafields{$unikey},
- '<>&"').
- ''.$tag.'>';
+ if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
+ $r->print(&mt('Associated with course [_1]',''.$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.".description"}.
+ '').'
');
+ } else {
+ $r->print("This resource is not associated with a course.
");
+ }
+ 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 ($fn =~ /\/portfolio\//) {
- $fn =~ /\/portfolio\/(.*)$/;
- my $new_fn = '/'.$1;
- $env{'form.'.$formname}=$file_content;
- $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').', '.
- &mt('FAIL').'
');
- } else {
- $r->print(''.&mt('Wrote Metadata').
- ' '.&Apache::lonlocal::locallocaltime(time).
- '
');
- }
+ 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.=("\n".''.$lt{$field_name}.': '.
+ &prettyinput($field_name,
+ $Apache::lonpublisher::metadatafields{$field_name},
+ 'new_'.$field_name,'defaultmeta',
+ undef,undef,undef,undef,
+ $Apache::lonpublisher::metadatafields{'courserestricted'}).'
'."\n");
+ }
} else {
- if (! ($mfh=Apache::File->new('>'.$fn))) {
- $r->print(''.
- &mt('Could not write metadata').', '.
- &mt('FAIL').'
');
- } else {
- print $mfh $file_content;
+
+ $output.=(''.$lt{$field_name}.': '.
+ &prettyinput($field_name,
+ $Apache::lonpublisher::metadatafields{$field_name},
+ 'new_'.$field_name,'defaultmeta').'
');
+
+ }
+ }
+ if ($env{'form.store'}) {
+ my $mfh;
+ my $formname='store';
+ my $file_content;
+ 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=$_;
+ $unikey=~/^([A-Za-z]+)/;
+ my $tag=$1;
+ $tag=~tr/A-Z/a-z/;
+ $file_content.= "\n\<$tag";
+ foreach (split(/\,/,
+ $Apache::lonpublisher::metadatakeys{$unikey})
+ ) {
+ my $value=
+ $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
+ $value=~s/\"/\'\'/g;
+ $file_content.=' '.$_.'="'.$value.'"' ;
+ # print $mfh ' '.$_.'="'.$value.'"';
+ }
+ $file_content.= '>'.
+ &HTML::Entities::encode
+ ($Apache::lonpublisher::metadatafields{$unikey},
+ '<>&"').
+ ''.$tag.'>';
+ }
+ &Apache::lonnet::logthis(" file ".$file_content);
+ if ($fn =~ m|/portfolio/|) {
+ my ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|);
+ $env{'form.'.$formname}=$file_content."\n";
+ $env{'form.'.$formname.'.filename'}=$new_fn;
+ my $result =&Apache::lonnet::userfileupload($formname,'',
+ $path);
+
+ if ($result =~ /(error|notfound)/) {
+ $r->print(''.
+ &mt('Could not write metadata').', '.
+ &mt('FAIL').'
');
+ } else {
$r->print(''.&mt('Wrote Metadata').
' '.&Apache::lonlocal::locallocaltime(time).
'
');
- }
- }
- }
+ }
+ } else {
+ if (! ($mfh=Apache::File->new('>'.$fn))) {
+ $r->print(''.
+ &mt('Could not write metadata').', '.
+ &mt('FAIL').'
');
+ } else {
+ print $mfh $file_content;
+ $r->print(''.&mt('Wrote Metadata').
+ ' '.&Apache::lonlocal::locallocaltime(time).
+ '
');
+ }
+ }
+ }
+
$r->print($output.'
');
+
}
$r->print('');
+
return;
}