version 1.190, 2006/12/05 02:55:53
|
version 1.195.2.1, 2007/01/18 23:20:56
|
Line 235 sub fieldnames {
|
Line 235 sub fieldnames {
|
'lowestgradelevel' => 'Lowest Grade Level', |
'lowestgradelevel' => 'Lowest Grade Level', |
'highestgradelevel' => 'Highest Grade Level'); |
'highestgradelevel' => 'Highest Grade Level'); |
|
|
if (! defined($file_type) || $file_type ne 'portfolio') { |
if ( !defined($file_type) || ($file_type ne 'portfolio' && $file_type ne 'groups') ) { |
%fields = |
%fields = |
(%fields, |
(%fields, |
'domain' => 'Domain', |
'domain' => 'Domain', |
Line 383 sub select_course {
|
Line 383 sub select_course {
|
$Apache::lonpublisher::metadatafields{'courserestricted'}; |
$Apache::lonpublisher::metadatafields{'courserestricted'}; |
my $selected = ($current_restriction eq 'none' ? 'selected="selected"' |
my $selected = ($current_restriction eq 'none' ? 'selected="selected"' |
: ''); |
: ''); |
|
if ($current_restriction =~ /^course\.($match_domain\_$match_courseid)$/) { |
|
my $assoc_crs = $1; |
|
my $added_metadata_fields = &Apache::lonparmset::get_added_meta_fieldnames($assoc_crs); |
|
if (ref($added_metadata_fields) eq 'HASH') { |
|
if (keys(%{$added_metadata_fields}) > 0) { |
|
my $transfernotes; |
|
foreach my $field_name (keys(%{$added_metadata_fields})) { |
|
my $value = $Apache::lonpublisher::metadatafields{$field_name}; |
|
if ($value) { |
|
$transfernotes .= |
|
&Apache::loncommon::start_data_table_row(). |
|
'<td><input type="checkbox" name="transfer_'. |
|
$field_name.'" value="1" /></td><td>'. |
|
$field_name.'</td><td>'.$value.'</td>'. |
|
&Apache::loncommon::end_data_table_row(); |
|
} |
|
} |
|
if ($transfernotes ne '') { |
|
my %courseinfo = &Apache::lonnet::coursedescription($assoc_crs,{'one_time' => 1}); |
|
my $assoc_crs_description = $courseinfo{'description'}; |
|
$output .= &mt('This resource is currently associated with a course ([_1]) which includes added metadata fields specific to the course.',$assoc_crs_description).'<br />'."\n". |
|
&mt('You can choose to transfer data from the added fields to the "Notes" field if you are planning to change the course association.').'<br /><br />'. |
|
&Apache::loncommon::start_data_table(). |
|
&Apache::loncommon::start_data_table_header_row(). |
|
'<th>Copy to notes?</th>'."\n". |
|
'<th>Field name</th>'."\n". |
|
'<th>Values</th>'."\n". |
|
&Apache::loncommon::end_data_table_header_row(). |
|
$transfernotes. |
|
&Apache::loncommon::end_data_table().'<br />'; |
|
} |
|
} |
|
} |
|
} |
$output .= '<select name="new_courserestricted" >'; |
$output .= '<select name="new_courserestricted" >'; |
$output .= '<option value="none" '.$selected.'>'. |
$output .= '<option value="none" '.$selected.'>'. |
&mt('None').'</option>'.$/; |
&mt('None').'</option>'.$/; |
Line 608 sub prettyinput {
|
Line 641 sub prettyinput {
|
return (&select_course()); |
return (&select_course()); |
# return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />'); |
# return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />'); |
} |
} |
my $course = $env{'request.course.id'}; |
|
if (($type eq 'keywords') || ($type eq 'subject') |
if (($type eq 'keywords') || ($type eq 'subject') |
|| ($type eq 'author')||($type eq 'notes') |
|| ($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'}))) { |
|| (exists($env{$course_key.'.metadata.'.$type.'.added'}))) { |
if ($values) { |
if ($values) { |
if ($only_one) { |
if ($only_one) { |
$output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options)); |
$output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options)); |
Line 1191 ENDDEL
|
Line 1223 ENDDEL
|
} else { |
} else { |
&Apache::lonpublisher::metaeval($result); |
&Apache::lonpublisher::metaeval($result); |
} |
} |
|
if ($env{'form.new_courserestricted'}) { |
|
my $new_assoc_course = $env{'form.new_courserestricted'}; |
|
my $prev_courserestricted = $Apache::lonpublisher::metadatafields{'courserestricted'}; |
|
if (($prev_courserestricted) && |
|
($prev_courserestricted ne $new_assoc_course)) { |
|
my $transfers = []; |
|
foreach my $key (keys(%env)) { |
|
if ($key =~ /^form\.transfer_(.+)$/) { |
|
push(@{$transfers},$1); |
|
} |
|
} |
|
if (@{$transfers} > 0) { |
|
&store_transferred_addedfields($fn,$uri,$transfers); |
|
} |
|
} |
|
} |
$r->print(<<ENDEDIT); |
$r->print(<<ENDEDIT); |
<h1>$displayfile</h1> |
<h1>$displayfile</h1> |
<form method="post" action="" name="defaultmeta"> |
<form method="post" action="" name="defaultmeta"> |
Line 1203 ENDEDIT
|
Line 1251 ENDEDIT
|
my @fields; |
my @fields; |
my $added_metadata_fields; |
my $added_metadata_fields; |
my @added_order; |
my @added_order; |
|
if ($file_type eq 'groups') { |
|
$Apache::lonpublisher::metadatafields{'courserestricted'}= |
|
'course.'.$env{'request.course.id'}; |
|
} |
|
if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) && |
|
(! $env{'form.new_courserestricted'}) && (! $file_type eq 'groups')) { |
|
$Apache::lonpublisher::metadatafields{'courserestricted'}= |
|
'none'; |
|
} elsif ($env{'form.new_courserestricted'}) { |
|
$Apache::lonpublisher::metadatafields{'courserestricted'}= |
|
$env{'form.new_courserestricted'}; |
|
} |
if ($file_type eq 'portfolio' || $file_type eq 'groups') { |
if ($file_type eq 'portfolio' || $file_type eq 'groups') { |
if(exists ($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'})) { |
if(exists ($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'})) { |
# retrieve fieldnames (in order) from the course restricted list |
# retrieve fieldnames (in order) from the course restricted list |
Line 1212 ENDEDIT
|
Line 1272 ENDEDIT
|
@fields = ('author','title','subject','keywords','abstract', |
@fields = ('author','title','subject','keywords','abstract', |
'notes','lowestgradelevel', |
'notes','lowestgradelevel', |
'highestgradelevel','standards'); |
'highestgradelevel','standards'); |
$added_metadata_fields = &Apache::lonparmset::get_added_meta_fieldnames(); |
if ($Apache::lonpublisher::metadatafields{'courserestricted'} =~ /^course\.($match_domain\_$match_courseid)$/) { |
if ($env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'}) { |
my $assoc_crs = $1; |
@added_order = split(/,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'}); |
$added_metadata_fields = &Apache::lonparmset::get_added_meta_fieldnames($assoc_crs); |
} |
if ($env{'course.'.$assoc_crs.'.metadata.addedorder'}) { |
$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'} = join(",",@fields); |
@added_order = split(/,/,$env{'course.'.$assoc_crs.'.metadata.addedorder'}); |
|
} |
|
$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'} = join(",",@fields); |
|
} |
} |
} |
} else { |
} else { |
@fields = ('author','title','subject','keywords','abstract','notes', |
@fields = ('author','title','subject','keywords','abstract','notes', |
Line 1225 ENDEDIT
|
Line 1288 ENDEDIT
|
'lowestgradelevel','highestgradelevel','sourceavail','sourcerights', |
'lowestgradelevel','highestgradelevel','sourceavail','sourcerights', |
'obsolete','obsoletereplacement'); |
'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'}) && (! $file_type eq 'groups')) { |
|
$Apache::lonpublisher::metadatafields{'courserestricted'}= |
|
'none'; |
|
} elsif ($env{'form.new_courserestricted'}) { |
|
$Apache::lonpublisher::metadatafields{'courserestricted'}= |
|
$env{'form.new_courserestricted'}; |
|
} |
|
if (! $Apache::lonpublisher::metadatafields{'copyright'}) { |
if (! $Apache::lonpublisher::metadatafields{'copyright'}) { |
$Apache::lonpublisher::metadatafields{'copyright'}= |
$Apache::lonpublisher::metadatafields{'copyright'}= |
'default'; |
'default'; |
Line 1252 ENDEDIT
|
Line 1303 ENDEDIT
|
} |
} |
|
|
if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') { |
if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') { |
$r->print(&mt('Associated with course [_1]', |
if ($file_type eq 'portfolio') { |
|
$r->print(&mt('Associated with course [_1]', |
'<strong><a href="'.$uri.'?changecourse=true">'. |
'<strong><a href="'.$uri.'?changecourse=true">'. |
$env{$Apache::lonpublisher::metadatafields{'courserestricted'}. |
$env{$Apache::lonpublisher::metadatafields{'courserestricted'}. |
".description"}. |
".description"}. |
'</a></strong>').'<br />'); |
'</a></strong>').'<br />'); |
|
} else { |
|
$r->print(&mt('Associated with course [_1]', |
|
'<strong>'. |
|
$env{$Apache::lonpublisher::metadatafields{'courserestricted'}. |
|
".description"}.'</strong>').'<br />'); |
|
} |
} else { |
} else { |
$r->print('<a href="'.$uri.'?changecourse=true">This resource is not associated with a course.</a><br />'); |
$r->print('<a href="'.$uri.'?changecourse=true">This resource is not associated with a course.</a><br />'); |
} |
} |
Line 1306 ENDEDIT
|
Line 1364 ENDEDIT
|
} |
} |
$output .= &Apache::loncommon::end_data_table(); |
$output .= &Apache::loncommon::end_data_table(); |
if ($env{'form.store'}) { |
if ($env{'form.store'}) { |
my $mfh; |
my ($outcome,$result) = &store_metadata($fn,$uri,'store'); |
my $formname='store'; |
$r->print($result); |
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 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 my $key (split(/\,/, |
|
$Apache::lonpublisher::metadatakeys{$unikey}) |
|
) { |
|
my $value= |
|
$Apache::lonpublisher::metadatafields{$unikey.'.'.$key}; |
|
$value=~s/\"/\'\'/g; |
|
$file_content.=' '.$key.'="'.$value.'"' ; |
|
} |
|
$file_content.= '>'. |
|
&HTML::Entities::encode |
|
($Apache::lonpublisher::metadatafields{$unikey}, |
|
'<>&"'). |
|
'</'.$tag.'>'; |
|
} |
|
if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles|) { |
|
my ($path, $new_fn); |
|
if ($fn =~ m|$match_name/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)); |
|
} else { |
|
if (! ($mfh=Apache::File->new('>'.$fn))) { |
|
$r->print('<p><font color="red">'. |
|
&mt('Could not write metadata').', '. |
|
&mt('FAIL').'</font></p>'); |
|
} else { |
|
print $mfh ($file_content); |
|
$r->print('<p><font color="blue">'.&mt('Wrote Metadata'). |
|
' '.&Apache::lonlocal::locallocaltime(time). |
|
'</font></p>'); |
|
} |
|
} |
|
} |
} |
$r->print($output.'<br /><input type="submit" name="store" value="'. |
$r->print($output.'<br /><input type="submit" name="store" value="'. |
&mt('Store Catalog Information').'" />'); |
&mt('Store Catalog Information').'" />'); |
|
|
if ($file_type eq 'portfolio') { |
if ($file_type eq 'portfolio' || $file_type eq 'groups') { |
my ($port_path,$group) = &get_port_path_and_group($uri); |
my ($port_path,$group) = &get_port_path_and_group($uri); |
if ($group) { |
if ($group ne '') { |
$r->print('<input type="hidden" name="group" value="'.$group.'" />'); |
$r->print('<input type="hidden" name="group" value="'.$group.'" />'); |
} |
} |
$r->print('<input type="hidden" name="currentpath" value="'.$env{'form.currentpath'}.'" />'); |
$r->print('<input type="hidden" name="currentpath" value="'.$env{'form.currentpath'}.'" />'); |
$r->print('</form><br /><br /><form method="post" action="'.$port_path.'">'); |
$r->print('</form><br /><br /><form method="post" action="'.$port_path.'">'); |
if ($group) { |
if ($group ne '') { |
$r->print('<input type="hidden" name="group" value="'.$group.'" />'); |
$r->print('<input type="hidden" name="group" value="'.$group.'" />'); |
} |
} |
$r->print('<input type="hidden" name="currentpath" value="'.$path.'" />'. |
$r->print('<input type="hidden" name="currentpath" value="'.$path.'" />'. |
'<input type="submit" name="cancel" value="'.&mt('Discard Edits and Return to Portfolio').'" />'); |
'<input type="submit" name="cancel" value="'.&mt('Discard Edits and Return to Portfolio').'" />'); |
} |
} |
Line 1379 ENDEDIT
|
Line 1390 ENDEDIT
|
return; |
return; |
} |
} |
|
|
|
sub store_metadata { |
|
my ($fn,$uri,$caller) = @_; |
|
my $mfh; |
|
my $formname='store'; |
|
my ($file_content,$output,$outcome); |
|
if (&Apache::loncommon::get_env_multiple('form.new_keywords')) { |
|
$Apache::lonpublisher::metadatafields{'keywords'} = |
|
join (',', &Apache::loncommon::get_env_multiple('form.new_keywords')); |
|
} |
|
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 my $key (split(/\,/,$Apache::lonpublisher::metadatakeys{$unikey})) { |
|
my $value = $Apache::lonpublisher::metadatafields{$unikey.'.'.$key}; |
|
$value=~s/\"/\'\'/g; |
|
$file_content.=' '.$key.'="'.$value.'"' ; |
|
} |
|
$file_content.= '>'. |
|
&HTML::Entities::encode |
|
($Apache::lonpublisher::metadatafields{$unikey},'<>&"'). |
|
'</'.$tag.'>'; |
|
} |
|
if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles|) { |
|
my ($path, $new_fn); |
|
if ($fn =~ m|$match_name/groups/\w+/portfolio/|) { |
|
($path, $new_fn) = ($fn =~ m|/(groups/\w+/portfolio.*)/([^/]*)$|); |
|
} else { |
|
($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|); |
|
} |
|
($outcome,my $result) = |
|
&store_portfolio_metadata($formname,$file_content, |
|
$path,$new_fn,$uri,$caller); |
|
$output .= $result; |
|
} else { |
|
if (! ($mfh=Apache::File->new('>'.$fn))) { |
|
$output .= '<p><font color="red">'; |
|
if ($caller eq 'transfer') { |
|
$output .= &mt('Could not transfer data in added fields to notes'); |
|
} else { |
|
$output .= &mt('Could not write metadata'); |
|
} |
|
$output .= ', '.&mt('FAIL').'</font></p>'; |
|
$outcome = 'fail'; |
|
} else { |
|
print $mfh ($file_content); |
|
close($mfh); |
|
&update_metadata_table($uri); |
|
$output .= '<p><font color="blue">'; |
|
if ($caller eq 'transfer') { |
|
$output .= &mt('Transferred data in added fields to notes'); |
|
} else { |
|
$output .= &mt('Wrote Metadata'); |
|
} |
|
$output .= ' '.&Apache::lonlocal::locallocaltime(time). |
|
'</font></p>'; |
|
$outcome = 'ok'; |
|
} |
|
} |
|
return ($outcome,$output); |
|
} |
|
|
|
sub store_transferred_addedfields { |
|
my ($fn,$uri,$transfers) = @_; |
|
foreach my $item (@{$transfers}) { |
|
$Apache::lonpublisher::metadatafields{'notes'} .= |
|
' '.$item.' = '.$Apache::lonpublisher::metadatafields{$item}; |
|
} |
|
my ($outcome,$output) = &store_metadata($fn,$uri,'transfer'); |
|
if ($outcome eq 'ok') { |
|
foreach my $item (@{$transfers}) { |
|
delete($Apache::lonpublisher::metadatafields{$item}); |
|
} |
|
} |
|
} |
|
|
sub store_portfolio_metadata { |
sub store_portfolio_metadata { |
my ($formname,$content,$path,$new_fn) = @_; |
my ($formname,$content,$path,$new_fn,$uri,$caller) = @_; |
|
my ($outcome,$output); |
$env{'form.'.$formname}=$content."\n"; |
$env{'form.'.$formname}=$content."\n"; |
$env{'form.'.$formname.'.filename'}=$new_fn; |
$env{'form.'.$formname.'.filename'}=$new_fn; |
my $result =&Apache::lonnet::userfileupload($formname,'',$path); |
my $result =&Apache::lonnet::userfileupload($formname,'',$path); |
if ($result =~ /(error|notfound)/) { |
if ($result =~ /(error|notfound)/) { |
return '<p><font color="red">'. |
$output = '<p><font color="red">'; |
&mt('Could not write metadata').', '. |
if ($caller eq 'transfer') { |
&mt('FAIL').'</font></p>'; |
$output .= |
|
&mt('Could not transfer data in added fields to notes'); |
|
} else { |
|
$output .= &mt('Could not write metadata'); |
|
} |
|
$output .= ', '.&mt('FAIL').'</font></p>'; |
|
$outcome = 'fail'; |
} else { |
} else { |
return '<p><font color="blue">'.&mt('Wrote Metadata'). |
&update_metadata_table($uri); |
' '.&Apache::lonlocal::locallocaltime(time).'</font></p>'; |
$output = '<p><font color="blue">'; |
|
if ($caller eq 'transfer') { |
|
$output .= &mt('Transferred data in added fields to notes'); |
|
} else { |
|
$output .= &mt('Wrote Metadata'); |
|
} |
|
$output .= ' '.&Apache::lonlocal::locallocaltime(time). |
|
'</font></p>'; |
|
$outcome = 'ok'; |
|
} |
|
return ($outcome,$output); |
|
} |
|
|
|
sub update_metadata_table { |
|
my ($uri) = @_; |
|
my ($group,$file_name); |
|
my ($udom,$uname,$remainder) = |
|
($uri=~m -^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$-); |
|
|
|
if ($remainder =~ /^groups\/(\w+)\/portfolio(\/.+)$/) { |
|
$group = $1; |
|
$file_name = $2; |
|
} elsif ($remainder =~ /^portfolio(\/.+)$/) { |
|
$file_name = $1; |
|
} |
|
$file_name =~ s/\.meta$//; |
|
my $current_permissions = |
|
&Apache::lonnet::get_portfile_permissions($udom,$uname); |
|
my %access_controls = |
|
&Apache::lonnet::get_access_controls($current_permissions,$group, |
|
$group.$file_name); |
|
my $access_hash = $access_controls{$file_name}; |
|
my $available = 0; |
|
if (ref($access_hash) eq 'HASH') { |
|
foreach my $key (keys(%{$access_hash})) { |
|
my ($num,$scope,$end,$start) = |
|
($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/); |
|
if ($scope eq 'public' || $scope eq 'guest') { |
|
$available = 1; |
|
last; |
|
} |
|
} |
|
} |
|
if ($available) { |
|
my $result = |
|
&Apache::lonnet::update_portfolio_table($uname,$udom, |
|
$file_name,'portfolio_metadata',$group,'update'); |
} |
} |
} |
} |
|
|
|
|
1; |
1; |
__END__ |
__END__ |
|
|