--- loncom/interface/lonmeta.pm 2005/07/08 10:39:49 1.98
+++ loncom/interface/lonmeta.pm 2005/12/19 21:56:07 1.147
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Metadata display handler
#
-# $Id: lonmeta.pm,v 1.98 2005/07/08 10:39:49 www Exp $
+# $Id: lonmeta.pm,v 1.147 2005/12/19 21:56:07 albertel 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
#
@@ -33,7 +33,7 @@ use LONCAPA::lonmetadata();
use Apache::Constants qw(:common);
use Apache::lonnet;
use Apache::loncommon();
-use Apache::lonhtmlcommon();
+use Apache::lonhtmlcommon();
use Apache::lonmsg;
use Apache::lonpublisher;
use Apache::lonlocal;
@@ -243,16 +243,18 @@ sub fieldnames {
'authorspace' => 'Author Space',
'modifyinguser' => 'Last Modifying User',
'subject' => 'Subject',
+ 'standards' => 'Standards',
'keywords' => 'Keyword(s)',
'notes' => 'Notes',
'abstract' => 'Abstract',
'lowestgradelevel' => 'Lowest Grade Level',
- 'highestgradelevel' => 'Highest Grade Level');
+ 'highestgradelevel' => 'Highest Grade Level',
+ 'courserestricted' => 'Course Restricting Metadata');
+
if (! defined($file_type) || $file_type ne 'portfolio') {
%fields =
(%fields,
'domain' => 'Domain',
- 'standards' => 'Standards',
'mime' => 'MIME Type',
'language' => 'Language',
'creationdate' => 'Creation Date',
@@ -282,12 +284,109 @@ sub fieldnames {
'stdno' => 'Total number of students who have worked on this problem',
'difficulty' => 'Degree of difficulty',
'disc' => 'Degree of discrimination',
- 'dependencies' => 'Resources used by this resource',
+ 'dependencies' => 'Resources used by this resource',
);
}
return &Apache::lonlocal::texthash(%fields);
}
+sub portfolio_linked_path {
+ my ($path) = @_;
+ my $result = &Apache::portfolio::make_anchor('portfolio','/');
+ my $fullpath = '/';
+ my (undef,@tree) = split('/',$path);
+ my $filename = pop(@tree);
+ foreach my $dir (@tree) {
+ $fullpath .= $dir.'/';
+ $result .= '/';
+ $result .= &Apache::portfolio::make_anchor($dir,$fullpath);
+ }
+ $result .= "/$filename";
+ return $result;
+}
+
+sub portfolio_display_uri {
+ my ($uri,$as_links)=@_;
+ $uri =~ s|.*/(portfolio/.*)$|$1|;
+ my ($res_uri,$meta_uri) = ($uri,$uri);
+
+ if ($uri =~ /\.meta$/) {
+ $res_uri =~ s/\.meta//;
+ } else {
+ $meta_uri .= '.meta';
+ }
+
+ my ($path) = ($res_uri =~ m|(.*)/[^/]*$|);
+
+ if ($as_links) {
+ $res_uri = &portfolio_linked_path($res_uri);
+ $meta_uri = &portfolio_linked_path($meta_uri);
+ }
+ return ($res_uri,$meta_uri,$path);
+}
+
+sub pre_select_course {
+ my ($r,$uri) = @_;
+ my $output;
+ my $fn=&Apache::lonnet::filelocation('',$uri);
+ my ($res_uri,$meta_uri,$path) = &portfolio_display_uri($uri);
+ %Apache::lonpublisher::metadatafields=();
+ %Apache::lonpublisher::metadatakeys=();
+ my $result=&Apache::lonnet::getfile($fn);
+ if ($result == -1){
+ $r->print(&mt('Creating new file [_1]'),$meta_uri);
+ } else {
+ &Apache::lonpublisher::metaeval($result);
+ }
+ $r->print('
');
+
+ $r->print('
');
+
+ return;
+}
+sub select_course {
+ my %courses;
+ my $output;
+ my $selected;
+ 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;
+ }
+ }
+ my $meta_not_found = 1;
+ if ($Apache::lonpublisher::metadatafields{'courserestricted'} eq 'none') {
+ $selected = ' SELECTED ';
+ } else {
+ $selected = '';
+ }
+ $output .= '
';
+ return ($output);
+}
# Pretty printing of metadata field
sub prettyprint {
@@ -440,10 +539,71 @@ sub relatedfield {
sub prettyinput {
my ($type,$value,$fieldname,$formname,
- $relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
+ $relatedsearchflag,$relatedsep,$relatedvalue,$size,$course_key)=@_;
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.'.$type.'.values'};
+ if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/stuadd/) {
+ $stu_add = 'true';
+ }
+ if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/onlyone/) {
+ $only_one = 'true';
+ }
+ # need to take instructor values out of list where instructor and student
+ # values may be mixed.
+ if ($values) {
+ foreach my $item (split(/,/,$values)) {
+ $item =~ s/^\s+//;
+ $meta_options{$item} = $item;
+ }
+ foreach my $item (split(/,/,$value)) {
+ $item =~ s/^\s+//;
+ if ($meta_options{$item}) {
+ push(@cur_values_inst,$item);
+ } else {
+ $cur_values_stu .= $item.',';
+ }
+ }
+ } else {
+ $cur_values_stu = $value;
+ }
+ if ($type eq 'courserestricted') {
+ return (&select_course());
+ # return ('');
+ }
+ if (($type eq 'keywords') || ($type eq 'subject')
+ || ($type eq 'author')||($type eq 'notes')
+ || ($type eq 'abstract')|| ($type eq 'title')|| ($type eq 'standards')) {
+ if ($values) {
+ if ($only_one) {
+ $output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options));
+ } else {
+ $output .= (&Apache::loncommon::multiple_select_form('new_'.$type,\@cur_values_inst,undef,\%meta_options));
+ }
+ }
+ if ($stu_add) {
+ $output .= ''.
+ &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
+ $relatedvalue);
+ }
+ return ($output);
+ }
+ if (($type eq 'lowestgradelevel') ||
+ ($type eq 'highestgradelevel')) {
+ return &Apache::loncommon::select_level_form($value,$fieldname).
+ &relatedfield(0,$relatedsearchflag,$relatedsep);
+ }
+ return();
+ }
# Language
if ($type eq 'language') {
return &selectbox($fieldname,
@@ -504,6 +664,11 @@ sub prettyinput {
",'rights')\">".&mt('Select').''.
&relatedfield(0,$relatedsearchflag,$relatedsep);
}
+ if ($type eq 'courserestricted') {
+ return (&select_course());
+ #return ('');
+ }
+
# Dates
if (($type eq 'creationdate') ||
($type eq 'lastrevisiondate')) {
@@ -545,10 +710,15 @@ sub handler {
# Looking for all bombs?
&report_bombs($r,$uri);
} elsif ($uri=~/\/portfolio\//) {
+ ($resdomain,$resuser)=
+ (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
$r->print(&Apache::loncommon::bodytag
('Edit Portfolio File Information','','','',$resdomain));
- &present_editable_metadata($r,$uri,'portfolio');
-
+ if ($env{'form.store'}) {
+ &present_editable_metadata($r,$uri,'portfolio');
+ } else {
+ &pre_select_course($r,$uri);
+ }
} elsif ($uri=~/^\/\~/) {
# Construction space
$r->print(&Apache::loncommon::bodytag
@@ -883,6 +1053,8 @@ sub print_dynamic_metadata {
return;
}
+
+
#####################################################
#####################################################
### ###
@@ -898,14 +1070,21 @@ sub present_editable_metadata {
my $fn=&Apache::lonnet::filelocation('',$uri);
$disuri=~s/^\/\~/\/priv\//;
$disuri=~s/\.meta$//;
+ my $meta_uri = $disuri;
+ my $path;
+ if ($disuri =~ m|/portfolio/|) {
+ ($disuri, $meta_uri, $path) = &portfolio_display_uri($disuri,1);
+ }
my $target=$uri;
$target=~s/^\/\~/\/res\/$env{'request.role.domain'}\//;
$target=~s/\.meta$//;
my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
if ($bombs) {
+ my $showdel=1;
if ($env{'form.delmsg'}) {
if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
$bombs=&mt('Messages deleted.');
+ $showdel=0;
} else {
$bombs=&mt('Error deleting messages');
}
@@ -915,19 +1094,27 @@ sub present_editable_metadata {
$cleardir=~s/\/[^\/]+$/\//;
if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {
$bombs=&mt('Messages cleared.');
+ $showdel=0;
} else {
$bombs=&mt('Error clearing messages');
}
}
my $del=&mt('Delete Messages for this Resource');
my $clear=&mt('Clear all Messages in Subdirectory');
+ my $goback=&mt('Back to Source File');
$r->print(<$disuri
+
');
+
return;
}