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

banghart lon-capa-cvs@mail.lon-capa.org
Wed, 14 Dec 2005 00:12:13 -0000


This is a MIME encoded message

--banghart1134519133
Content-Type: text/plain

banghart		Tue Dec 13 19:12:13 2005 EDT

  Modified files:              
    /loncom/interface	lonmeta.pm 
  Log:
  	Move 'courserestricted' in with other metadata', add 'none' 
  	option.  Still odd problems with displaying reliably.
  
  
--banghart1134519133
Content-Type: text/plain
Content-Disposition: attachment; filename="banghart-20051213191213.txt"

Index: loncom/interface/lonmeta.pm
diff -u loncom/interface/lonmeta.pm:1.137 loncom/interface/lonmeta.pm:1.138
--- loncom/interface/lonmeta.pm:1.137	Tue Dec 13 06:52:37 2005
+++ loncom/interface/lonmeta.pm	Tue Dec 13 19:12:13 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Metadata display handler
 #
-# $Id: lonmeta.pm,v 1.137 2005/12/13 11:52:37 banghart Exp $
+# $Id: lonmeta.pm,v 1.138 2005/12/14 00:12:13 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -293,6 +293,7 @@
 sub select_course {
     my %courses;
     my $output;
+    my $selected;
     foreach my $key (keys (%env)) { 
         if ($key =~ m/\.metadata\./) {
             $key =~ m/^course\.(.+)(\.metadata.+$)/;
@@ -302,29 +303,26 @@
             $courses{$coursekey} = $value;
         }
     }
-    $output = '<h3>Associate resource with a course</h3><br />';
-    $output .= '<form action="" method="post">';
-    $output .= 'Select course <br />';
-    $output .= '<select name="metacourse" >';
     my $meta_not_found = 1;
+    if ($Apache::lonpublisher::metadatafields{'courserestricted'} eq 'none') {
+        $selected = ' SELECTED ';
+    } else {
+        $selected = '';
+    }
+    $output .= '<select name="new_courserestricted" >';
+    $output .= '<option value="none" '.$selected.'>None</option>';
     foreach my $key (keys (%courses)) {    
-        if ($meta_not_found) {
-            undef($meta_not_found);
-            $output .= '<h3>Portfolio Meta-Data</h3><br />';
-            $output .= '<form action="" method="post">';
-            $output .= 'Select your course<br />';
-            $output .= '<select name="metacourse" >';
-        }
         $key =~ m/(^.+)\.description$/;
-        $output .= '<option value="'.$1.'">';
+        if ($Apache::lonpublisher::metadatafields{'courserestricted'} eq $1) {
+            $selected = ' SELECTED ';
+        } else {
+            $selected = '';
+        }
+        $output .= '<option value="'.$1.'"'.$selected.'>';
         $output .= $courses{$key};
         $output .= '</option>';
     }
-    unless ($meta_not_found) {
-        $output .= '</select><br />';
-        $output .= '<input type="submit" value="Associate" />';
-        $output .= '</form>';
-    }
+    $output .= '</select><br />';
     return ($output);
 }
 # Pretty printing of metadata field
@@ -516,7 +514,8 @@
             $cur_values_stu = $value;
         }
         if ($type eq 'courserestricted') {
-            return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
+            return (&select_course());
+            # return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
         }
         if (($type eq 'keywords') || ($type eq 'subject')
              || ($type eq 'author')||($type eq  'notes')
@@ -604,7 +603,8 @@
             &relatedfield(0,$relatedsearchflag,$relatedsep); 
     }
     if ($type eq 'courserestricted') {
-            return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
+        return (&select_course());
+        #return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
     }
 
     # Dates
@@ -1002,7 +1002,6 @@
     # Header
     my $disuri=$uri;
     my $fn=&Apache::lonnet::filelocation('',$uri);
-    my $metacourse;
     $disuri=~s/^\/\~/\/priv\//;
     $disuri=~s/\.meta$//;
     $disuri=~s|^/editupload||;
@@ -1047,6 +1046,67 @@
 	}
 	$r->print('<br />'.$bombs);
     } else {
+        if ($env{'form.store'}) {
+            my $mfh;
+            my $formname='store'; 
+            my $file_content;
+            foreach my $meta_field (keys %env) {
+                if (&Apache::loncommon::get_env_multiple('form.new_keywords')) {
+                    $Apache::lonpublisher::metadatafields{'keywords'} = 
+                        join (',', &Apache::loncommon::get_env_multiple('form.new_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."\n";
+                $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('<p><font color="red">'.
+                      &mt('Could not write metadata').', '.
+                     &mt('FAIL').'</font></p>');
+                } else {
+                    $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
+		  ' '.&Apache::lonlocal::locallocaltime(time).
+		  '</font></p>');
+                }
+            } 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>');
+                }
+            }
+        }        
         my $displayfile='Catalog Information for '.$disuri;
         if ($disuri=~/\/default$/) {
             my $dir=$disuri;
@@ -1083,27 +1143,19 @@
                  'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
                  'obsolete','obsoletereplacement');
         }
-        if ($env{'form.metacourse'} ) {
-            $Apache::lonpublisher::metadatafields{'courserestricted'} = $env{'form.metacourse'};
-            $metacourse = $env{'form.metacourse'};
-         } else {
-            if (! $Apache::lonpublisher::metadatafields{'courserestricted'}) {
-                $Apache::lonpublisher::metadatafields{'courserestricted'}=
-                    'none';
-                $metacourse = 'none';
-            } else {
-                $metacourse = $Apache::lonpublisher::metadatafields{'courserestricted'};
-            }
-        }
+        if (! $Apache::lonpublisher::metadatafields{'courserestricted'}) {
+            $Apache::lonpublisher::metadatafields{'courserestricted'}=
+                'none';
+        } 
         if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
                 $Apache::lonpublisher::metadatafields{'copyright'}=
                 'default';
         }
-        if ($metacourse ne 'none') {
-            $r->print('Using: <strong> '.$env{$metacourse.".description"}.
+        if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
+            $r->print('Using: <strong> '.$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.".description"}.
                         "</strong> metadata framework<br />");
         } else {
-            $r->print("This resources is not associated with a metadata framework<br />");
+            $r->print("This resource is not associated with a metadata framework<br />");
         }
         foreach my $field_name(@fields) {
 
@@ -1111,102 +1163,32 @@
                 $Apache::lonpublisher::metadatafields{$field_name}=
                     join(',',&Apache::loncommon::get_env_multiple('form.new_'.$field_name));
             }
-            if ($metacourse ne 'none') {
+            if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
                 # handle restrictions here
-                if ($env{$metacourse.'.metadata.'.$field_name.'.options'} =~ m/active/){
+                if (($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
+                    ($field_name eq 'courserestricted')){
                     $output.=('<p>'.$lt{$field_name}.': '.
                               &prettyinput($field_name,
 				   $Apache::lonpublisher::metadatafields{$field_name},
-				   'new_'.$field_name,'defaultmeta',undef,undef,undef,undef,$metacourse).'</p>');
-                 } elsif ($field_name eq 'courserestricted') {
-                            $output.=(
-                                &prettyinput($field_name,
-				    $Apache::lonpublisher::metadatafields{$field_name},
-				    'new_'.$field_name,'defaultmeta',undef,undef,undef,undef,$metacourse));
+				                    'new_'.$field_name,'defaultmeta',
+				                    undef,undef,undef,undef,
+				                    $Apache::lonpublisher::metadatafields{'courserestricted'}).'</p>');
                  }
             } else {
-                if ($field_name ne 'courserestricted') {
+
                     $output.=('<p>'.$lt{$field_name}.': '.
                             &prettyinput($field_name,
 				   $Apache::lonpublisher::metadatafields{$field_name},
 				   'new_'.$field_name,'defaultmeta').'</p>');
-	        } else {
-                    $output.=&prettyinput($field_name,
-				   $Apache::lonpublisher::metadatafields{$field_name},
-				   'new_'.$field_name,'defaultmeta');
-                }
+               
             }
         }
 
-        if ($env{'form.store'}) {
-            my $mfh;
-            my $formname='store'; 
-            my $file_content;
-            foreach my $meta_field (keys %env) {
-                if (&Apache::loncommon::get_env_multiple('form.new_keywords')) {
-                    $Apache::lonpublisher::metadatafields{'keywords'} = 
-                        join (',', &Apache::loncommon::get_env_multiple('form.new_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."\n";
-                $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('<p><font color="red">'.
-                      &mt('Could not write metadata').', '.
-                     &mt('FAIL').'</font></p>');
-                } else {
-                    $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
-		  ' '.&Apache::lonlocal::locallocaltime(time).
-		  '</font></p>');
-                }
-            } 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="'.
                   &mt('Store Catalog Information').'">');
         
     }
     $r->print('</form>');
-    if ($metacourse eq 'none') {
-        $r->print(&select_course());
-    }
     return;
 }
 

--banghart1134519133--