--- loncom/interface/lonmeta.pm 2006/07/19 15:31:05 1.160 +++ loncom/interface/lonmeta.pm 2006/09/29 18:11:49 1.180 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Metadata display handler # -# $Id: lonmeta.pm,v 1.160 2006/07/19 15:31:05 albertel Exp $ +# $Id: lonmeta.pm,v 1.180 2006/09/29 18:11:49 albertel 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}; } @@ -170,7 +171,7 @@ sub authordisplay { my ($aname,$adom)=@_; return &Apache::loncommon::aboutmewrapper (&Apache::loncommon::plainname($aname,$adom), - $aname,$adom,'preview').' ['.$aname.'@'.$adom.']'; + $aname,$adom,'preview').' ['.$aname.':'.$adom.']'; } # Pretty display @@ -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', @@ -287,15 +282,22 @@ sub portfolio_linked_path { if ($group) { $start = "groups/$group/".$start; } - my $result = &Apache::portfolio::make_anchor($port_path,$start,'/'); - + my %anchor_fields = ( + 'selectfile' => $start, + 'currentpath' => '/' + ); + my $result = &Apache::portfolio::make_anchor($port_path,\%anchor_fields,$start); my $fullpath = '/'; my (undef,@tree) = split('/',$path); my $filename = pop(@tree); foreach my $dir (@tree) { $fullpath .= $dir.'/'; $result .= '/'; - $result .= &Apache::portfolio::make_anchor($port_path,$dir,$fullpath); + my %anchor_fields = ( + 'selectfile' => $dir, + 'currentpath' => $fullpath + ); + $result .= &Apache::portfolio::make_anchor($port_path,\%anchor_fields,$dir); } $result .= "/$filename"; return $result; @@ -315,7 +317,7 @@ sub get_port_path_and_group { $port_path = '/adm/portfolio'; } if ($env{'form.group'} ne $group) { - $env{'form.group'} = $group) { + $env{'form.group'} = $group; } return ($port_path,$group); } @@ -358,14 +360,20 @@ sub pre_select_course { $r->print('

'.&mt('If you would like to associate this resource ([_1]) with a current or previous course, please select one from the list below, otherwise select, \'None\'',''.$res_uri.'').'

'); $output = &select_course(); $r->print($output.'
'); + &mt('Associate Resource With Selected Course').'" />'); + $r->print(''); + $r->print(''); $r->print(''); my ($port_path,$group) = &get_port_path_and_group($uri); - $r->print('

'. + my $group_input; + if ($group) { + $group_input = ''; + } + $r->print('

'. ''. - ''. - ''. + $group_input. + ''. '
'); return; @@ -498,6 +506,7 @@ sub prettyprint { if ($type=~/\_list/) { my @Courses = split(/\s*\,\s*/,$value); my $Str=''; } # No pretty print found @@ -594,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)); @@ -611,7 +628,7 @@ sub prettyinput { $relatedvalue); } return ($output); - } + } if (($type eq 'lowestgradelevel') || ($type eq 'highestgradelevel')) { return &Apache::loncommon::select_level_form($value,$fieldname). @@ -706,24 +723,23 @@ sub prettyinput { # Main Handler sub handler { my $r=shift; - # + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['currentpath']); my $uri=$r->uri; # # Set document type &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/(.*)$:) { $r->print(&Apache::loncommon::start_page('Error Messages')); # Looking for all bombs? &report_bombs($r,$uri); - } elsif ($uri=~/\/portfolio\//) { + } elsif ($uri=~m|^/editupload/[^/]+/[^/]+/portfolio/|) { ($resdomain,$resuser)= - (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|); + (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|); $r->print(&Apache::loncommon::start_page('Edit Portfolio File Catalog Information', undef, {'domain' => $resdomain,})); @@ -732,7 +748,12 @@ sub handler { } else { &pre_select_course($r,$uri); } - } elsif ($uri=~/^\/\~/) { + } 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', undef, @@ -798,6 +819,7 @@ ENDCLEAR sub present_uneditable_metadata { my ($r,$uri) = @_; # + my $uploaded = ($uri =~ m|/uploaded/|); my %content=(); # Read file foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) { @@ -810,16 +832,18 @@ sub present_uneditable_metadata { my $disuri=&Apache::lonnet::clutter($uri); $disuri=~s/^\/adm\/wrapper//; # version - my $currentversion=&Apache::lonnet::getversion($disuri); my $versiondisplay=''; - if ($thisversion) { - $versiondisplay=&mt('Version').': '.$thisversion. - ' ('.&mt('most recent version').': '. - ($currentversion>0 ? - $currentversion : - &mt('information not available')).')'; - } else { - $versiondisplay='Version: '.$currentversion; + if (!$uploaded) { + my $currentversion=&Apache::lonnet::getversion($disuri); + if ($thisversion) { + $versiondisplay=&mt('Version').': '.$thisversion. + ' ('.&mt('most recent version').': '. + ($currentversion>0 ? + $currentversion : + &mt('information not available')).')'; + } else { + $versiondisplay='Version: '.$currentversion; + } } # crumbify displayed URL uri target prefix form size $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1'); @@ -839,30 +863,38 @@ sub present_uneditable_metadata { if (! defined($title)) { $title = 'Untitled Resource'; } - foreach ('title', - 'author', - 'subject', - 'keywords', - 'notes', - 'abstract', - 'lowestgradelevel', - 'highestgradelevel', - 'standards', - 'mime', - 'language', - 'creationdate', - 'lastrevisiondate', - 'owner', - 'copyright', - 'customdistributionfile', - 'sourceavail', - 'sourcerights', - 'obsolete', - 'obsoletereplacement') { - $table.=''.$lt{$_}. + my @fields; + if ($uploaded) { + @fields = ('title','author','subject','keywords','notes','abstract', + 'lowestgradelevel','highestgradelevel','standards','mime', + 'owner'); + } else { + @fields = ('title', + 'author', + 'subject', + 'keywords', + 'notes', + 'abstract', + 'lowestgradelevel', + 'highestgradelevel', + 'standards', + 'mime', + 'language', + 'creationdate', + 'lastrevisiondate', + 'owner', + 'copyright', + 'customdistributionfile', + 'sourceavail', + 'sourcerights', + 'obsolete', + 'obsoletereplacement'); + } + foreach my $field (@fields) { + $table.=''.$lt{$field}. ''. - &prettyprint($_,$content{$_}).''; - delete $content{$_}; + &prettyprint($field,$content{$field}).''; + delete($content{$field}); } # $r->print(< ENDHEAD - if ($env{'user.adv'}) { + if (!$uploaded && $env{'user.adv'}) { &print_dynamic_metadata($r,$uri,\%content); } return; @@ -1081,7 +1113,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; @@ -1122,7 +1154,7 @@ sub present_editable_metadata { my $goback=&mt('Back to Source File'); $r->print(<$disuri -
+ ENDBOMBS if ($showdel) { $r->print(<print(<$displayfile - + ENDEDIT - $r->print(''); 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; + 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(); + $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'} = join (",",@fields); + } } else { @fields = ('author','title','subject','keywords','abstract','notes', 'copyright','customdistributionfile','language', @@ -1170,8 +1212,12 @@ ENDEDIT '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'}) { @@ -1180,9 +1226,18 @@ ENDEDIT } if (! $Apache::lonpublisher::metadatafields{'copyright'}) { $Apache::lonpublisher::metadatafields{'copyright'}= - 'default'; + '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+)$/ ); + } + if (! $Apache::lonpublisher::metadatafields{'owner'}) { + $Apache::lonpublisher::metadatafields{'owner'} = + $env{'user.name'}.':'.$env{'user.domain'}; + } + if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') { $r->print(&mt('Associated with course [_1]',''.$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.".description"}. '').'
'); @@ -1190,8 +1245,11 @@ ENDEDIT $r->print("This resource is not associated with a course.
"); } } + 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)); @@ -1225,22 +1283,20 @@ ENDEDIT $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]+)/; + foreach my $field (sort keys %Apache::lonpublisher::metadatafields) { + next if ($field =~ /\./); + my $unikey=$field; + $unikey=~/^([A-Za-z_]+)/; my $tag=$1; $tag=~tr/A-Z/a-z/; $file_content.= "\n\<$tag"; - foreach (split(/\,/, + foreach my $key (split(/\,/, $Apache::lonpublisher::metadatakeys{$unikey}) ) { my $value= - $Apache::lonpublisher::metadatafields{$unikey.'.'.$_}; + $Apache::lonpublisher::metadatafields{$unikey.'.'.$key}; $value=~s/\"/\'\'/g; - $file_content.=' '.$_.'="'.$value.'"' ; - # print $mfh ' '.$_.'="'.$value.'"'; + $file_content.=' '.$key.'="'.$value.'"' ; } $file_content.= '>'. &HTML::Entities::encode @@ -1248,14 +1304,16 @@ ENDEDIT '<>&"'). ''; } - if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/portfolio/|) { - my ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|); + if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles|) { + my ($path, $new_fn); + if ($fn =~ m|\w+/groups/\w+/portfolio/|) { + ($path, $new_fn) = ($fn =~ m|/(groups/\w+/portfolio.*)/([^/]*)$|); + } else { + ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|); + } $r->print(&store_portfolio_metadata($formname,$file_content,$path, - $new_fn)); - } elsif ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/groups/\w+/portfolio/|) { - my ($path, $new_fn) = ($fn =~ m|/(groups/\w+/portfolio.*)/([^/]*)$|); - $r->print(&store_portfolio_metadata($formname,$file_content,$path,$new_fn)); - } else { + $new_fn)); + } else { if (! ($mfh=Apache::File->new('>'.$fn))) { $r->print('

'. &mt('Could not write metadata').', '. @@ -1268,20 +1326,21 @@ ENDEDIT } } } - $r->print($output.'
'); + &mt('Store Catalog Information').'" />'); if ($file_type eq 'portfolio') { my ($port_path,$group) = &get_port_path_and_group($uri); if ($group) { $r->print(''); } - $r->print(' -

'. - ''. - ''. - ''); + $r->print(''); + $r->print('

'); + if ($group) { + $r->print(''); + } + $r->print(''. + ''); } }