--- loncom/interface/lonmeta.pm 2005/11/08 03:08:15 1.124 +++ loncom/interface/lonmeta.pm 2005/11/19 00:00:38 1.129 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Metadata display handler # -# $Id: lonmeta.pm,v 1.124 2005/11/08 03:08:15 albertel Exp $ +# $Id: lonmeta.pm,v 1.129 2005/11/19 00:00:38 banghart Exp $ # # Copyright Michigan State University Board of Trustees # @@ -304,7 +304,7 @@ sub select_course { } $r->print('<h3>Course Related Meta-Data</h3><br />'); $r->print('<form action="" method="post">'); - $r->print('Select your test course<br />'); + $r->print('Select course restrictions<br />'); $r->print('<select name="metacourse" >'); my $meta_not_found = 1; foreach my $key (keys (%courses)) { @@ -483,9 +483,13 @@ sub prettyinput { 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.'.$_.'.values'}; if ($env{$course_key.'.metadata.'.$_.'.options'} =~ m/stuadd/) { $stu_add = 'true'; @@ -493,7 +497,31 @@ sub prettyinput { if ($env{$course_key.'.metadata.'.$_.'.options'} =~ m/onlyone/) { $only_one = 'true'; } + # need to take instructor values out of list where instructor and student + # values may be mixed. + if ($values && $stu_add) { + foreach (split(/,/,$values)) { + $_ =~ s/^\s+//; + $meta_options{$_} = $_; + } + foreach (split(/,/,$value)) { + $_ =~ s/^\s+//; + if ($meta_options{$_}) { + push(@cur_values_inst,$_); + } else { + $cur_values_stu .= $_.','; + } + } + } else { + $cur_values_stu = $value; + } if ($type eq 'author') { + return + '<input type="text" name="'.$fieldname.'" size="'.$size.'" '. + 'value="'.$value.'" />'. + &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname, + $relatedvalue); + } if ($type eq 'courserestricted') { return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />'); @@ -505,22 +533,20 @@ sub prettyinput { if ($type eq 'subject') { } if ($type eq 'keywords') { - my %hash; - my $def; - my @cur_values; - foreach (split(/,/,$value)) { - $_ =~ s/^\s+//; - push(@cur_values,$_); - } - foreach (split(/,/,$values)) { - $_ =~ s/^\s+//; - $hash{$_} = $_; + if ($values) { + if ($only_one) { + $output .= (&Apache::loncommon::select_form($value,'new_keywords',%meta_options)); + } else { + $output .= (&Apache::loncommon::multiple_select_form('new_keywords',\@cur_values_inst,undef,\%meta_options)); + } } - if ($only_one) { - return(&Apache::loncommon::select_form($def,'new_keywords',%hash)); - } else { - return(&Apache::loncommon::multiple_select_form('new_keywords',\@cur_values,undef,\%hash)); + if ($stu_add) { + $output .= '<input type="text" name="'.$fieldname.'" size="'.$size.'" '. + 'value="'.$cur_values_stu.'" />'. + &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname, + $relatedvalue); } + return ($output); } if ($type eq 'notes') { } @@ -1087,27 +1113,47 @@ ENDEDIT $Apache::lonpublisher::metadatafields{'copyright'}= 'default'; } + if ($metacourse ne 'none') { + $r->print('Document metadata restricted by :<strong> '.$env{$metacourse.".description"}."</strong><br />"); + } + foreach (@fields) { if (defined($env{'form.new_'.$_})) { $Apache::lonpublisher::metadatafields{$_}= join(',',&Apache::loncommon::get_env_multiple('form.new_'.$_)); } + my $field_name = $_; if ($metacourse ne 'none') { # handle restrictions here - if (($env{$metacourse.'.metadata.'.$_.'.options'} =~ m/active/)|| - ($_ eq 'courserestricted')) { + if ($env{$metacourse.'.metadata.'.$_.'.options'} =~ m/active/){ $output.=('<p>'.$lt{$_}.': '. - &prettyinput($_, + &prettyinput($_, $Apache::lonpublisher::metadatafields{$_}, 'new_'.$_,'defaultmeta',undef,undef,undef,undef,$metacourse).'</p>'); - } + } elsif ($_ eq 'courserestricted') { + $output.=( + &prettyinput($field_name, + $Apache::lonpublisher::metadatafields{$_}, + 'new_'.$field_name,'defaultmeta',undef,undef,undef,undef,$metacourse)); + } } else { - $output.=('<p>'.$lt{$_}.': '. + if ($_ ne 'courserestricted') { + $output.=('<p>'.$lt{$_}.': '. &prettyinput($_, $Apache::lonpublisher::metadatafields{$_}, 'new_'.$_,'defaultmeta').'</p>'); + } else { + $output.=&prettyinput($field_name, + $Apache::lonpublisher::metadatafields{$_}, + 'new_'.$field_name,'defaultmeta'); + } } } + $output.=('<p>'.$lt{$_}.': '. + &prettyinput($_, + $Apache::lonpublisher::metadatafields{$_}, + 'new_'.$_,'defaultmeta',undef,undef,undef,undef,$metacourse).'</p>'); + if ($env{'form.store'}) { my $mfh; my $formname='store';