--- loncom/interface/lonmeta.pm 2005/02/10 22:01:40 1.91 +++ loncom/interface/lonmeta.pm 2005/10/25 01:23:47 1.116 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Metadata display handler # -# $Id: lonmeta.pm,v 1.91 2005/02/10 22:01:40 banghart Exp $ +# $Id: lonmeta.pm,v 1.116 2005/10/25 01:23:47 banghart Exp $ # # Copyright Michigan State University Board of Trustees # @@ -17,7 +17,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License +# You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # @@ -31,9 +31,9 @@ package Apache::lonmeta; use strict; use LONCAPA::lonmetadata(); use Apache::Constants qw(:common); -use Apache::lonnet(); +use Apache::lonnet; use Apache::loncommon(); -use Apache::lonhtmlcommon(); +use Apache::lonhtmlcommon(); use Apache::lonmsg; use Apache::lonpublisher; use Apache::lonlocal; @@ -237,10 +237,8 @@ sub diffgraph { # The field names sub fieldnames { my $file_type=shift; - if ($file_type eq 'portfolio') { - return &Apache::lonlocal::texthash - ( - 'title' => 'Title', + my %fields = + ('title' => 'Title', 'author' =>'Author(s)', 'authorspace' => 'Author Space', 'modifyinguser' => 'Last Modifying User', @@ -250,19 +248,10 @@ sub fieldnames { 'abstract' => 'Abstract', 'lowestgradelevel' => 'Lowest Grade Level', 'highestgradelevel' => 'Highest Grade Level'); - } else { - return &Apache::lonlocal::texthash - ( - 'title' => 'Title', - 'author' =>'Author(s)', - 'authorspace' => 'Author Space', - 'modifyinguser' => 'Last Modifying User', - 'subject' => 'Subject', - 'keywords' => 'Keyword(s)', - 'notes' => 'Notes', - 'abstract' => 'Abstract', - 'lowestgradelevel' => 'Lowest Grade Level', - 'highestgradelevel' => 'Highest Grade Level', + if (! defined($file_type) || $file_type ne 'portfolio') { + %fields = + (%fields, + 'domain' => 'Domain', 'standards' => 'Standards', 'mime' => 'MIME Type', 'language' => 'Language', @@ -295,9 +284,46 @@ sub fieldnames { 'disc' => 'Degree of discrimination', 'dependencies' => 'Resources used by this resource', ); - } + } + return &Apache::lonlocal::texthash(%fields); } +sub select_course { + my ($r)=@_; + my %courses; + foreach my $key (keys (%env)) { + if ($key =~ m/\.metadata\./) { + $key =~ m/^course\.(.+)(\.metadata.+$)/; + my $course = $1; + my $coursekey = 'course.'.$course.'.description'; + my $value = $env{$coursekey}; + $courses{$coursekey} = $value; + } + } + $r->print('
'. &mt('This resource has been marked obsolete by the author(s)'). '
'; @@ -690,7 +758,7 @@ $versiondisplay $table ENDHEAD - if ($ENV{'user.adv'}) { + if ($env{'user.adv'}) { &print_dynamic_metadata($r,$uri,\%content); } return; @@ -831,8 +899,8 @@ sub print_dynamic_metadata { $r->print(''.$lt{$_}.': '. - &prettyinput($_, + if ($env{'form.metacourse'}) { + # handle restrictions here + $env{'form.metacourse'} =~ m/(^.+)\.description$/; + my $key_base = $1; + if ($env{$key_base.'.metadata.'.$_.'.options'} =~ m/active/) { + $output.=('
'.$lt{$_}.': '. + &prettyinput($_, + $Apache::lonpublisher::metadatafields{$_}, + 'new_'.$_,'defaultmeta',undef,undef,undef,undef,$key_base).'
'); + } + } else { + $output.=(''.$lt{$_}.': '. + &prettyinput($_, $Apache::lonpublisher::metadatafields{$_}, 'new_'.$_,'defaultmeta').'
'); + } } - if ($ENV{'form.store'}) { + if ($env{'form.store'}) { my $mfh; - if (! ($mfh=Apache::File->new('>'.$fn))) { - $r->print(''. - &mt('Could not write metadata').', '. - &mt('FAIL').'
'); + my $formname='store'; + my $file_content; + foreach my $meta_field (keys %env) { + if (&Apache::loncommon::get_env_multiple('form.keywords')) { + $Apache::lonpublisher::metadatafields{'coursekeyword'} = + join (', ', &Apache::loncommon::get_env_multiple('form.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.'>'; + } + 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'}); + 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). + '
'); + } } else { - foreach (sort keys %Apache::lonpublisher::metadatafields) { - next if ($_ =~ /\./); - my $unikey=$_; - $unikey=~/^([A-Za-z]+)/; - my $tag=$1; - $tag=~tr/A-Z/a-z/; - print $mfh "\n\<$tag"; - foreach (split(/\,/, - $Apache::lonpublisher::metadatakeys{$unikey}) - ) { - my $value= - $Apache::lonpublisher::metadatafields{$unikey.'.'.$_}; - $value=~s/\"/\'\'/g; - print $mfh ' '.$_.'="'.$value.'"'; - } - print $mfh '>'. - &HTML::Entities::encode - ($Apache::lonpublisher::metadatafields{$unikey}, - '<>&"'). - ''.$tag.'>'; + 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(''.&mt('Wrote Metadata'). - ' '.&Apache::lonlocal::locallocaltime(time). - '
'); } } $r->print($output.'