[LON-CAPA-cvs] cvs: loncom /interface lonmeta.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 04 Jan 2006 05:43:20 -0000


albertel		Wed Jan  4 00:43:20 2006 EDT

  Modified files:              
    /loncom/interface	lonmeta.pm 
  Log:
  - allowing a resource to be associated with any course 
  
  
Index: loncom/interface/lonmeta.pm
diff -u loncom/interface/lonmeta.pm:1.149 loncom/interface/lonmeta.pm:1.150
--- loncom/interface/lonmeta.pm:1.149	Thu Dec 29 14:42:44 2005
+++ loncom/interface/lonmeta.pm	Wed Jan  4 00:43:19 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Metadata display handler
 #
-# $Id: lonmeta.pm,v 1.149 2005/12/29 19:42:44 albertel Exp $
+# $Id: lonmeta.pm,v 1.150 2006/01/04 05:43:19 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -358,36 +358,31 @@
     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 = '';
-    }
+    my $output=$/;
+    my $current_restriction=
+	$Apache::lonpublisher::metadatafields{'courserestricted'};
+    my $selected = ($current_restriction eq 'none' ? 'selected="selected"' 
+		                                   : '');
+
     $output .= '<select name="new_courserestricted" >';
-    $output .= '<option value="none" '.$selected.'>None</option>';
-    foreach my $key (keys (%courses)) {    
-        $key =~ m/(^.+)\.description$/;
-        if ($Apache::lonpublisher::metadatafields{'courserestricted'} eq $1) {
-            $selected = ' SELECTED ';
-        } else {
-            $selected = '';
-        }
-        $output .= '<option value="'.$1.'"'.$selected.'>';
-        $output .= $courses{$key};
-        $output .= '</option>';
+    $output .= '<option value="none" '.$selected.'>'.
+	&mt('None').'</option>'.$/;
+    my %courses;
+    foreach my $key (keys(%env)) {
+        if ($key !~ m/^course\.(.+)\.description$/) { next; }
+	my $cid = $1;
+        if ($env{$key} !~ /\S/) { next; }
+	$courses{$key} = $cid;
+    }
+    foreach my $key (sort { lc($env{$a}) cmp lc($env{$b}) } (keys(%courses))) {
+	my $cid = 'course.'.$courses{$key};
+	my $selected = ($current_restriction eq $cid ? 'selected="selected"' 
+		                                     : '');
+        if ($env{$key} !~ /\S/) { next; }
+	$output .= '<option value="'.$cid.'" '.$selected.'>';
+	$output .= $env{$key};
+	$output .= '</option>'.$/;
+	$selected = '';
     }
     $output .= '</select><br />';
     return ($output);
@@ -549,7 +544,8 @@
         $size = 80;
     }
     my $output;
-    if (defined($course_key)) {
+    if (defined($course_key) 
+	&& exists($env{$course_key.'.metadata.'.$type.'.options'})) {
         my $stu_add;
         my $only_one;
         my %meta_options;
@@ -1183,7 +1179,8 @@
                 $Apache::lonpublisher::metadatafields{$field_name}=
                     join(',',&Apache::loncommon::get_env_multiple('form.new_'.$field_name));
             }
-            if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
+            if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none'
+		&& exists($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'})) {
                 # handle restrictions here
                 if (($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
                     ($field_name eq 'courserestricted')){