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

raeburn raeburn at source.lon-capa.org
Tue Mar 28 19:17:18 EDT 2023


raeburn		Tue Mar 28 23:17:18 2023 EDT

  Modified files:              
    /loncom/publisher	lonpublisher.pm 
    /loncom/interface	lonmeta.pm 
  Log:
  - "In course" authoring.
    Copyright/Distibution field for resources in "course author" space is
    'custom', and Custom Distribution File is /res/domain/courseid/default.rights
  
  
-------------- next part --------------
Index: loncom/publisher/lonpublisher.pm
diff -u loncom/publisher/lonpublisher.pm:1.300 loncom/publisher/lonpublisher.pm:1.301
--- loncom/publisher/lonpublisher.pm:1.300	Fri Sep  9 19:20:55 2022
+++ loncom/publisher/lonpublisher.pm	Tue Mar 28 23:17:16 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Publication Handler
 #
-# $Id: lonpublisher.pm,v 1.300 2022/09/09 19:20:55 raeburn Exp $
+# $Id: lonpublisher.pm,v 1.301 2023/03/28 23:17:16 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -329,7 +329,7 @@
 #########################################
 #########################################
 sub textfield {
-    my ($title,$name,$value,$noline)=@_;
+    my ($title,$name,$value,$noline,$readonly)=@_;
     $value=~s/^\s+//gs;
     $value=~s/\s+$//gs;
     $value=~s/\s+/ /gs;
@@ -341,22 +341,31 @@
 }
 
 sub text_with_browse_field {
-    my ($title,$name,$value,$restriction,$noline)=@_;
+    my ($title,$name,$value,$restriction,$noline,$readonly)=@_;
     $value=~s/^\s+//gs;
     $value=~s/\s+$//gs;
     $value=~s/\s+/ /gs;
     $title=&mt($title);
     $env{'form.'.$name}=$value;
-    return "\n".&Apache::lonhtmlcommon::row_title($title)
-          .'<input type="text" name="'.$name.'" size="80" value="'.$value.'" />'
-          .'<br />'
+    my $disabled;
+    if ($readonly) {
+        $disabled = ' disabled="disabled"';
+    }
+    my $output =
+          "\n".&Apache::lonhtmlcommon::row_title($title)
+          .'<input type="text" name="'.$name.'" size="80" value="'.$value.'"'.$disabled.' />';
+    unless ($readonly) {
+        $output .=
+          '<br />'
 	  .'<a href="javascript:openbrowser(\'pubform\',\''.$name.'\',\''.$restriction.'\');">'
           .&mt('Select')
           .'</a> '
 	  .'<a href="javascript:opensearcher(\'pubform\',\''.$name.'\');">'
           .&mt('Search')
-          .'</a>'
-          .&Apache::lonhtmlcommon::row_closure($noline);
+          .'</a>';
+    }
+    $output .= &Apache::lonhtmlcommon::row_closure($noline);
+    return $output;
 }
 
 sub hiddenfield {
@@ -372,7 +381,7 @@
 }
 
 sub selectbox {
-    my ($title,$name,$value,$functionref, at idlist)=@_;
+    my ($title,$name,$value,$readonly,$functionref, at idlist)=@_;
     $title=&mt($title);
     $value=(split(/\s*,\s*/,$value))[-1];
     if (defined($value)) {
@@ -387,6 +396,9 @@
         if ($id eq $value) {
 	    $selout.=' selected="selected"';
         }
+        if ($readonly) {
+            $selout .= ' disabled="disabled"';
+        }
         $selout.='>'.&{$functionref}($id).'</option>';
     }
     $selout.='</select>'.&Apache::lonhtmlcommon::row_closure();
@@ -1199,6 +1211,20 @@
 	  $content=$outstring;
 
     }
+
+# ----------------------------------------------------- Course Authoring Space.
+    my ($courseauthor,$crsaurights,$readonly);
+    if ($env{'request.course.id'}) {
+        my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+        my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        my $docroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+        if ($source =~ m{^\Q$docroot/priv/$cdom/$cnum/\E}) {
+            $courseauthor = $cnum.':'.$cdom;
+            $crsaurights = "/res/$cdom/$cnum/default.rights";
+            $readonly = 1;
+        }
+    }
+
 # -------------------------------------------- Initial step done, now metadata.
 
 # --------------------------------------- Storage for metadata keys and fields.
@@ -1485,7 +1511,7 @@
     $defaultlanguage =~ s/,\s*$//g;
 
     $intr_scrout.=&selectbox('Language','language',
-			     $defaultlanguage,
+			     $defaultlanguage,'',
 			     \&Apache::loncommon::languagedescription,
 			     (&Apache::loncommon::languageids),
 			     );
@@ -1502,8 +1528,11 @@
     if ($style eq 'prv') {
         $pubowner_last = 1;
     }
+    if ($courseauthor) {
+        $metadatafields{'owner'} = $courseauthor;
+    }
     $intr_scrout.=&textfield('Publisher/Owner','owner',
-			     $metadatafields{'owner'},$pubowner_last);
+			     $metadatafields{'owner'},$pubowner_last,$readonly);
 
 # ---------------------------------------------- Retrofix for unused copyright
     if ($metadatafields{'copyright'} eq 'free') {
@@ -1516,6 +1545,10 @@
 # ------------------------------------------------ Dial in reasonable defaults
     my $defaultoption=$metadatafields{'copyright'};
     unless ($defaultoption) { $defaultoption='default'; }
+    if ($courseauthor) {
+        $defaultoption='custom';
+        $metadatafields{'customdistributionfile'}=$crsaurights;
+    }
     my $defaultsourceoption=$metadatafields{'sourceavail'};
     unless ($defaultsourceoption) { $defaultsourceoption='closed'; }
     unless ($style eq 'prv') {
@@ -1527,12 +1560,12 @@
 		$defaultoption='default';
 	    }
 	    $intr_scrout.=&selectbox('Copyright/Distribution','copyright',
-				     $defaultoption,
+				     $defaultoption,$readonly,
 				     \&Apache::loncommon::copyrightdescription,
 				    (grep !/^(public|priv)$/,(&Apache::loncommon::copyrightids)));
 	} else {
 	    $intr_scrout.=&selectbox('Copyright/Distribution','copyright',
-				     $defaultoption,
+				     $defaultoption,$readonly,
 				     \&Apache::loncommon::copyrightdescription,
 				     (grep !/^priv$/,(&Apache::loncommon::copyrightids)));
 	}
@@ -1541,9 +1574,9 @@
         my $replace=&mt('Copyright/Distribution:');
 	$intr_scrout =~ s/$replace/$replace.' '.$copyright_help/ge;
 
-	$intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights');
+	$intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights','',$readonly);
 	$intr_scrout.=&selectbox('Source Distribution','sourceavail',
-				 $defaultsourceoption,
+				 $defaultsourceoption,'',
 				 \&Apache::loncommon::source_copyrightdescription,
 				 (&Apache::loncommon::source_copyrightids));
 #	$intr_scrout.=&text_with_browse_field('Source Custom Distribution File','sourcerights',$metadatafields{'sourcerights'},'rights');
Index: loncom/interface/lonmeta.pm
diff -u loncom/interface/lonmeta.pm:1.254 loncom/interface/lonmeta.pm:1.255
--- loncom/interface/lonmeta.pm:1.254	Sun Jun 22 19:46:48 2014
+++ loncom/interface/lonmeta.pm	Tue Mar 28 23:17:18 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Metadata display handler
 #
-# $Id: lonmeta.pm,v 1.254 2014/06/22 19:46:48 raeburn Exp $
+# $Id: lonmeta.pm,v 1.255 2023/03/28 23:17:18 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -550,13 +550,17 @@
 }
 
 sub selectbox {
-    my ($name,$value,$functionref, at idlist)=@_;
+    my ($name,$value,$readonly,$functionref, at idlist)=@_;
     if (! defined($functionref)) {
         $functionref=\&direct;
     }
+    my $disabled;
+    if ($readonly) {
+        $disabled = ' disabled="disabled"';
+    }
     my $selout='<select name="'.$name.'">';
     foreach my $id (@idlist) {
-        $selout.='<option value="'.$id.'"';
+        $selout.='<option value="'.$id.'"'.$disabled;
         if ($id eq $value) {
 	    $selout.=' selected="selected">'.&{$functionref}($id).'</option>';
         } else {
@@ -582,7 +586,7 @@
 }
 
 sub prettyinput {
-    my ($type,$value,$fieldname,$formname,
+    my ($type,$value,$readonly,$fieldname,$formname,
 	$relatedsearchflag,$relatedsep,$relatedvalue,$size,$course_key)=@_;
     if (! defined($size)) {
         $size = 80;
@@ -661,7 +665,7 @@
     # Language
     if ($type eq 'language') {
 	return &selectbox($fieldname,
-			  $value,
+			  $value,'',
 			  \&Apache::loncommon::languagedescription,
 			  (&Apache::loncommon::languageids)).
                               &relatedfield(0,$relatedsearchflag,$relatedsep);
@@ -669,7 +673,7 @@
     # Copyright
     if ($type eq 'copyright') {
 	return &selectbox($fieldname,
-			  $value,
+			  $value,$readonly,
 			  \&Apache::loncommon::copyrightdescription,
 			  (&Apache::loncommon::copyrightids)).
                               &relatedfield(0,$relatedsearchflag,$relatedsep);
@@ -677,7 +681,7 @@
     # Source Copyright
     if ($type eq 'sourceavail') {
 	return &selectbox($fieldname,
-			  $value,
+			  $value,'',
 			  \&Apache::loncommon::source_copyrightdescription,
 			  (&Apache::loncommon::source_copyrightids)).
                               &relatedfield(0,$relatedsearchflag,$relatedsep);
@@ -704,11 +708,20 @@
     }
     # Customdistribution file
     if ($type eq 'customdistributionfile') {
-	return '<input type="text" name="'.$fieldname.
-	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
-	    "('".$formname."','".$fieldname."'".
-	    ",'rights')\">".&mt('Select').'</a>'.
-            &relatedfield(0,$relatedsearchflag,$relatedsep); 
+        my $disabled;
+        if ($readonly) {
+            $disabled = ' disabled="disabled"';
+        }
+        my $output;
+	$output = '<input type="text" name="'.$fieldname.
+	    '" size="60" value="'.$value.'"'.$disabled.' />';
+        unless ($readonly) {
+            $output .= '<a href="javascript:openbrowser'.
+	               "('".$formname."','".$fieldname."'".
+	               ",'rights')\">".&mt('Select').'</a>';
+        }
+        $output .= &relatedfield(0,$relatedsearchflag,$relatedsep);
+        return $output;
     }
     # Source Customdistribution file
     if ($type eq 'sourcerights') {
@@ -1312,6 +1325,16 @@
     # Authoring Space Call
     # Header
     my $disuri=$uri;
+    my ($courseauthor,$crsaurights,$readonly);
+    if ($env{'request.course.id'}) {
+        my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+        my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        if ($uri =~ m{^\Q/priv/$cdom/$cnum/\E}) {
+            $courseauthor = $cnum.':'.$cdom;
+            $crsaurights = "/res/$cdom/$cnum/default.rights";
+            $readonly = 1;
+        }
+    }
     my $fn=&Apache::lonnet::filelocation('',$uri);
     $disuri=~s{^/\~}{/priv/};
     $disuri=~s/\.meta$//;
@@ -1473,6 +1496,10 @@
 		       'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
 		       'obsolete','obsoletereplacement');
         }
+        if ($courseauthor) {
+            $Apache::lonpublisher::metadatafields{'copyright'}='custom';
+            $Apache::lonpublisher::metadatafields{'customdistributionfile'}=$crsaurights;
+        }
         if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
                 $Apache::lonpublisher::metadatafields{'copyright'}=
 		    'default';
@@ -1554,17 +1581,16 @@
                     $output .= &Apache::lonhtmlcommon::row_title($lt{$field_name})
                               .&prettyinput($field_name,
 				   $Apache::lonpublisher::metadatafields{$field_name},
-				                    'new_'.$field_name,'defaultmeta',
+				                    $readonly,'new_'.$field_name,'defaultmeta',
 				                    undef,undef,undef,undef,
                                                     $Apache::lonpublisher::metadatafields{'courserestricted'});
                     $output .= &Apache::lonhtmlcommon::row_closure($rowcount == $last?1:0);
                  }
             } else {
-
                     $output .= &Apache::lonhtmlcommon::row_title($lt{$field_name})
                               .&prettyinput($field_name,
 					   $Apache::lonpublisher::metadatafields{$field_name},
-                                           'new_'.$field_name,'defaultmeta')
+                                           $readonly,'new_'.$field_name,'defaultmeta')
                               .&Apache::lonhtmlcommon::row_closure($rowcount == $last?1:0);
                
             }


More information about the LON-CAPA-cvs mailing list