--- loncom/interface/lonmeta.pm 2006/08/16 18:06:47 1.170
+++ loncom/interface/lonmeta.pm 2006/11/04 01:50:31 1.186
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Metadata display handler
#
-# $Id: lonmeta.pm,v 1.170 2006/08/16 18:06:47 banghart Exp $
+# $Id: lonmeta.pm,v 1.186 2006/11/04 01:50:31 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -95,7 +95,8 @@ sub get_dynamic_metadata_from_sql {
while (my $result = <$fh>) {
chomp($result);
next if (! $result);
- my %hash=&LONCAPA::lonmetadata::metadata_col_to_hash(map { &unescape($_) } split(/\,/,$result));
+ my %hash=&LONCAPA::lonmetadata::metadata_col_to_hash('metadata',
+ map { &unescape($_) } split(/\,/,$result));
foreach my $key (keys(%hash)) {
$ReturnHash{$hash{'url'}}->{$key}=$hash{$key};
}
@@ -237,12 +238,6 @@ sub fieldnames {
if (! defined($file_type) || $file_type ne 'portfolio') {
%fields =
- (%fields,
- 'courserestricted' => 'Course Restricting Metadata');
- }
-
- if (! defined($file_type) || $file_type ne 'portfolio') {
- %fields =
(%fields,
'domain' => 'Domain',
'mime' => 'MIME Type',
@@ -474,7 +469,7 @@ sub prettyprint {
($type eq 'sequsage_list') ||
($type eq 'dependencies')) {
return ' '.$lt{$field_name}.': '.
&prettyinput($field_name,
$Apache::lonpublisher::metadatafields{$field_name},
@@ -1246,9 +1290,9 @@ ENDEDIT
} else {
$output.=(' '.$lt{$field_name}.': '.
- &prettyinput($field_name,
- $Apache::lonpublisher::metadatafields{$field_name},
- 'new_'.$field_name,'defaultmeta').''.join("\n",map {
- my $url = &Apache::lonnet::clutter($_);
+ my $url = &Apache::lonnet::clutter_with_no_wrapper($_);
my $title = &Apache::lonnet::gettitle($url);
if ($title eq '') {
$title = 'Untitled';
@@ -511,6 +506,7 @@ sub prettyprint {
if ($type=~/\_list/) {
my @Courses = split(/\s*\,\s*/,$value);
my $Str='
';
+ my %descriptions;
foreach my $course (@Courses) {
my %courseinfo =
&Apache::lonnet::coursedescription($course,
@@ -518,10 +514,16 @@ sub prettyprint {
if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
next;
}
- $Str .= '
';
}
# No pretty print found
@@ -607,9 +609,11 @@ sub prettyinput {
return (&select_course());
# return ('');
}
+ my $course = $env{'request.course.id'};
if (($type eq 'keywords') || ($type eq 'subject')
|| ($type eq 'author')||($type eq 'notes')
- || ($type eq 'abstract')|| ($type eq 'title')|| ($type eq 'standards')) {
+ || ($type eq 'abstract')|| ($type eq 'title')|| ($type eq 'standards')
+ || (exists($env{'course.'.$env{'request.course.id'}.'.metadata.'.$type.'.added'}))) {
if ($values) {
if ($only_one) {
$output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options));
@@ -624,7 +628,7 @@ sub prettyinput {
$relatedvalue);
}
return ($output);
- }
+ }
if (($type eq 'lowestgradelevel') ||
($type eq 'highestgradelevel')) {
return &Apache::loncommon::select_level_form($value,$fieldname).
@@ -719,7 +723,6 @@ sub prettyinput {
# Main Handler
sub handler {
my $r=shift;
- #
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['currentpath']);
my $uri=$r->uri;
@@ -728,7 +731,6 @@ sub handler {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
- #
my ($resdomain,$resuser)=
(&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
if ($uri=~m:/adm/bombs/(.*)$:) {
@@ -744,8 +746,23 @@ sub handler {
if ($env{'form.store'}) {
&present_editable_metadata($r,$uri,'portfolio');
} else {
- &pre_select_course($r,$uri);
+ my $fn=&Apache::lonnet::filelocation('',$uri);
+ %Apache::lonpublisher::metadatafields=();
+ %Apache::lonpublisher::metadatakeys=();
+ my $result=&Apache::lonnet::getfile($fn);
+ &Apache::lonpublisher::metaeval($result);
+ &Apache::lonnet::logthis("restricted is: ".$Apache::lonpublisher::metadatafields{'courserestricted'});
+ if (!$Apache::lonpublisher::metadatafields{'courserestricted'}) {
+ &pre_select_course($r,$uri);
+ } else {
+ &present_editable_metadata($r,$uri,'portfolio');
+ }
}
+ } elsif ($uri=~m|^/editupload/[^/]+/[^/]+/groups/|) {
+ $r->print(&Apache::loncommon::start_page('Edit Group Portfolio File Catalog Information',
+ undef,
+ {'domain' => $resdomain,}));
+ &present_editable_metadata($r,$uri,'groups');
} elsif ($uri=~m|^/~|) {
# Construction space
$r->print(&Apache::loncommon::start_page('Edit Catalog nformation',
@@ -822,8 +839,7 @@ sub present_uneditable_metadata {
# displayed url
my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
$uri=~s/\.meta$//;
- my $disuri=&Apache::lonnet::clutter($uri);
- $disuri=~s/^\/adm\/wrapper//;
+ my $disuri=&Apache::lonnet::clutter_with_no_wrapper($uri);
# version
my $versiondisplay='';
if (!$uploaded) {
@@ -1106,7 +1122,7 @@ sub print_dynamic_metadata {
#####################################################
#####################################################
sub present_editable_metadata {
- my ($r,$uri, $file_type) = @_;
+ my ($r,$uri,$file_type) = @_;
# Construction Space Call
# Header
my $disuri=$uri;
@@ -1185,19 +1201,36 @@ ENDEDIT
my %lt=&fieldnames($file_type);
my $output;
my @fields;
- if ($file_type eq 'portfolio') {
- @fields = ('author','title','subject','keywords','abstract',
- 'notes','lowestgradelevel',
- 'highestgradelevel','standards');
+ my $added_metadata_fields;
+ my @added_order;
+ if ($file_type eq 'portfolio' || $file_type eq 'groups') {
+ if(exists ($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'})) {
+ # retrieve fieldnames (in order) from the course restricted list
+ @fields = (split(/,/,$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'}));
+ } else {
+ # no saved field list, use default list
+ @fields = ('author','title','subject','keywords','abstract',
+ 'notes','lowestgradelevel',
+ 'highestgradelevel','standards');
+ $added_metadata_fields = &Apache::lonparmset::get_added_meta_fieldnames();
+ if ($env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'}) {
+ @added_order = split(/,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'});
+ }
+ $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'} = join(",",@fields);
+ }
} else {
@fields = ('author','title','subject','keywords','abstract','notes',
- 'copyright','customdistributionfile','language',
- 'standards',
- 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
- 'obsolete','obsoletereplacement');
+ 'copyright','customdistributionfile','language',
+ 'standards',
+ 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
+ 'obsolete','obsoletereplacement');
+ }
+ if ($file_type eq 'groups') {
+ $Apache::lonpublisher::metadatafields{'courserestricted'}=
+ 'course.'.$env{'request.course.id'};
}
if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
- (! $env{'form.new_courserestricted'})) {
+ (! $env{'form.new_courserestricted'}) && (! $file_type eq 'groups')) {
$Apache::lonpublisher::metadatafields{'courserestricted'}=
'none';
} elsif ($env{'form.new_courserestricted'}) {
@@ -1208,7 +1241,7 @@ ENDEDIT
$Apache::lonpublisher::metadatafields{'copyright'}=
'default';
}
- if ($file_type eq 'portfolio') {
+ if (($file_type eq 'portfolio') || ($file_type eq 'groups')) {
if (! $Apache::lonpublisher::metadatafields{'mime'}) {
($Apache::lonpublisher::metadatafields{'mime'}) =
( $target=~/\.(\w+)$/ );
@@ -1225,8 +1258,18 @@ ENDEDIT
$r->print("This resource is not associated with a course.
");
}
}
+ if (@added_order) {
+ foreach my $field_name (@added_order) {
+ push(@fields,$field_name);
+ $lt{$field_name} = $$added_metadata_fields{$field_name};
+ }
+ } else {
+ foreach my $field_name (keys(%$added_metadata_fields)) {
+ push(@fields,$field_name);
+ $lt{$field_name} = $$added_metadata_fields{$field_name};
+ }
+ }
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));
@@ -1234,8 +1277,9 @@ ENDEDIT
if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none'
&& exists($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'})) {
# handle restrictions here
- if (($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
- ($field_name eq 'courserestricted')){
+ if ((($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
+ ($field_name eq 'courserestricted'))&&
+ (!($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/))){
$output.=("\n".'
'. &mt('Could not write metadata').', '. &mt('FAIL').'
'); } else { - print $mfh $file_content; + print $mfh ($file_content); $r->print(''.&mt('Wrote Metadata'). ' '.&Apache::lonlocal::locallocaltime(time). '
'); } - unless ($env{'form.associate'}) { - $r->print(&Apache::portfolio::done("Return to Portfolio",'/adm/portfolio')); - return; - } } } - $r->print($output.'