Diff for /loncom/publisher/lonpublisher.pm between versions 1.222 and 1.231

version 1.222, 2007/03/02 23:20:17 version 1.231, 2008/02/14 21:29:08
Line 344  sub text_with_browse_field { Line 344  sub text_with_browse_field {
     return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$title:".      return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$title:".
            "</b></font></p><br />".             "</b></font></p><br />".
            '<input type="text" name="'.$name.'" size=80 value="'.$value.'" />'.             '<input type="text" name="'.$name.'" size=80 value="'.$value.'" />'.
    '<a href="javascript:openbrowser(\'pubform\',\''.$name.'\',\''.$restriction.'\');">Select</a>&nbsp;'.     '<a href="javascript:openbrowser(\'pubform\',\''.$name.'\',\''.$restriction.'\');">'.&mt('Select').'</a>&nbsp;'.
    '<a href="javascript:opensearcher(\'pubform\',\''.$name.'\');">Search</a>';     '<a href="javascript:opensearcher(\'pubform\',\''.$name.'\');">'.&mt('Search').'</a>';
         
 }  }
   
Line 409  sub urlfixup { Line 409  sub urlfixup {
     if ($url =~ /^mailto:/i) { return $url; }      if ($url =~ /^mailto:/i) { return $url; }
     #internal document links need no fixing      #internal document links need no fixing
     if ($url =~ /^\#/) { return $url; }       if ($url =~ /^\#/) { return $url; } 
     my ($host)=($url=~/(?:(?:http|https|ftp)\:\/\/)*([^\/]+)/);      my ($host)=($url=~m{(?:(?:http|https|ftp)://)*([^/]+)});
     my %all_hostnames = &Apache::lonnet::all_hostnames();      my @lonids = &Apache::lonnet::machine_ids($host);
     foreach my $hostname (values(%all_hostnames)) {      if (@lonids) {
  if ($hostname eq $host) {   $url=~s{^(?:http|https|ftp)://}{};
     $url=~s/^(?:http|https|ftp)\:\/\///;   $url=~s/^\Q$host\E//;
             $url=~s/^\Q$host\E//;  
         }  
     }      }
     if ($url=~/^(?:http|https|ftp)\:\/\//) { return $url; }      if ($url=~m{^(?:http|https|ftp)://}) { return $url; }
     $url=~s{\Q~$cuname\E}{res/$cudom/$cuname};      $url=~s{\Q~$cuname\E}{res/$cudom/$cuname};
     return $url;      return $url;
 }  }
Line 496  sub get_subscribed_hosts { Line 494  sub get_subscribed_hosts {
     $target=~/(.*)\/([^\/]+)$/;      $target=~/(.*)\/([^\/]+)$/;
     my $srcf=$2;      my $srcf=$2;
     opendir(DIR,$1);      opendir(DIR,$1);
       # cycle through listed files, subscriptions used to exist
       # as "filename.lonid"
     while ($filename=readdir(DIR)) {      while ($filename=readdir(DIR)) {
  if ($filename=~/\Q$srcf\E\.($match_lonid)$/) {   if ($filename=~/\Q$srcf\E\.($match_lonid)$/) {
     my $subhost=$1;      my $subhost=$1;
     if (($subhost ne 'meta' && $subhost ne 'subscription' &&      if (($subhost ne 'meta' 
  $subhost ne 'tmp') &&   && $subhost ne 'subscription' 
    && $subhost ne 'meta.subscription'
    && $subhost ne 'tmp') &&
                 ($subhost ne $Apache::lonnet::perlvar{'lonHostID'})) {                  ($subhost ne $Apache::lonnet::perlvar{'lonHostID'})) {
  push(@subscribed,$subhost);   push(@subscribed,$subhost);
     }      }
Line 652  sub fix_ids_and_indices { Line 654  sub fix_ids_and_indices {
    join(', ',@duplicatedids));     join(', ',@duplicatedids));
     if ($duplicateids) {      if ($duplicateids) {
  print $logfile "Duplicate ID(s) exist, ".join(', ',@duplicatedids)."\n";   print $logfile "Duplicate ID(s) exist, ".join(', ',@duplicatedids)."\n";
  my $outstring='<font color="red">'.&mt('Unable to publish file, it contains duplicated ID(s), ID(s) need to be unique. The duplicated ID(s) are').': '.join(', ',@duplicatedids).'</font>';   my $outstring='<span class="LC_error">'.&mt('Unable to publish file, it contains duplicated ID(s), ID(s) need to be unique. The duplicated ID(s) are').': '.join(', ',@duplicatedids).'</span>';
  return ($outstring,1);   return ($outstring,1);
     }      }
     if ($needsfixup) {      if ($needsfixup) {
Line 823  sub store_metadata { Line 825  sub store_metadata {
     # Determine if the table exists      # Determine if the table exists
     my $status = &Apache::lonmysql::check_table('metadata');      my $status = &Apache::lonmysql::check_table('metadata');
     if (! defined($status)) {      if (! defined($status)) {
         $error='<font color="red">WARNING: Cannot connect to '.          $error='<span class="LC_error">WARNING: Cannot connect to '.
             'database!</font>';              'database!</span>';
         &Apache::lonnet::logthis($error);          &Apache::lonnet::logthis($error);
         return ($error,undef);          return ($error,undef);
     }      }
     if ($status == 0) {      if ($status == 0) {
         # It would be nice to actually create the table....          # It would be nice to actually create the table....
         $error ='<font color="red">WARNING: The metadata table does not '.          $error ='<span class="LC_error">WARNING: The metadata table does not '.
             'exist in the LON-CAPA database.</font>';              'exist in the LON-CAPA database.</span>';
         &Apache::lonnet::logthis($error);          &Apache::lonnet::logthis($error);
         return ($error,undef);          return ($error,undef);
     }      }
Line 839  sub store_metadata { Line 841  sub store_metadata {
     if (($metadata{'obsolete'}) || ($metadata{'copyright'} eq 'priv') ||      if (($metadata{'obsolete'}) || ($metadata{'copyright'} eq 'priv') ||
  ($metadata{'copyright'} eq 'custom')) {   ($metadata{'copyright'} eq 'custom')) {
         # remove this entry          # remove this entry
  $status=&LONCAPA::lonmetadata::delete_metadata($dbh,undef,   my $delitem = 'url = '.$dbh->quote($metadata{'url'});
                                                        $metadata{'url'});   $status = &LONCAPA::lonmetadata::delete_metadata($dbh,undef,$delitem);
                                                          
     } else {      } else {
         $status = &LONCAPA::lonmetadata::update_metadata($dbh,undef,undef,          $status = &LONCAPA::lonmetadata::update_metadata($dbh,undef,undef,
                                                          \%metadata);                                                           \%metadata);
     }      }
     if (defined($status) && $status ne '') {      if (defined($status) && $status ne '') {
         $error='<font color="red">Error occured storing new values in '.          $error='<span class="LC_error">Error occured saving new values in '.
             'metadata table in LON-CAPA database</font>';              'metadata table in LON-CAPA database</span>';
         &Apache::lonnet::logthis($error);          &Apache::lonnet::logthis($error);
         &Apache::lonnet::logthis($status);          &Apache::lonnet::logthis($status);
         return ($error,undef);          return ($error,undef);
Line 869  sub checkonthis { Line 872  sub checkonthis {
     if (($errorcount) || ($warningcount)) {      if (($errorcount) || ($warningcount)) {
         $r->print('<br /><tt>'.$uri.'</tt>: ');          $r->print('<br /><tt>'.$uri.'</tt>: ');
  if ($errorcount) {   if ($errorcount) {
     $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.      $r->print('<img src="/adm/lonMisc/bomb.gif" /><span class="LC_error"><b>'.
       $errorcount.' '.        $errorcount.' '.
       &mt('error(s)').'</b></font> ');        &mt('error(s)').'</b></span> ');
  }   }
  if ($warningcount) {   if ($warningcount) {
     $r->print('<font color="blue">'.      $r->print('<font color="blue">'.
Line 935  sub publish { Line 938  sub publish {
     my %allow=();      my %allow=();
   
     unless ($logfile=Apache::File->new('>>'.$source.'.log')) {      unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
  return ('<font color="red">'.&mt('No write permission to user directory, FAIL').'</font>',1);   return ('<span class="LC_error">'.&mt('No write permission to user directory, FAIL').'</span>',1);
     }      }
     print $logfile       print $logfile 
 "\n\n================= Publish ".localtime()." Phase One  ================\n".$env{'user.name'}.':'.$env{'user.domain'}."\n";  "\n\n================= Publish ".localtime()." Phase One  ================\n".$env{'user.name'}.':'.$env{'user.domain'}."\n";
Line 949  sub publish { Line 952  sub publish {
     print $logfile "Copied original file to ".$copyfile."\n";      print $logfile "Copied original file to ".$copyfile."\n";
         } else {          } else {
     print $logfile "Unable to write backup ".$copyfile.':'.$!."\n";      print $logfile "Unable to write backup ".$copyfile.':'.$!."\n";
     return ("<font color=\"red\">Failed to write backup copy, $!,FAIL</font>",1);      return ("<span class=\"LC_error\">Failed to write backup copy, $!,FAIL</span>",1);
         }          }
 # ------------------------------------------------------------- IDs and indices  # ------------------------------------------------------------- IDs and indices
   
Line 964  sub publish { Line 967  sub publish {
         foreach (sort(keys(%allow))) {          foreach (sort(keys(%allow))) {
    my $thisdep=$_;     my $thisdep=$_;
    if ($thisdep !~ /[^\s]/) { next; }     if ($thisdep !~ /[^\s]/) { next; }
              if ($thisdep =~/\$/) {
                 $scrout.='<br /><span class="LC_warning">'.
                          &mt('The resource depends on another resource with variable filename, i.e., [_1]. '.
                              'You likely need to explicitly allow access to all possible dependencies using the [_2]-tag',
                              '<tt>'.$thisdep.'</tt>','<tt>&lt;allow&gt;</tt>').'</span>'; 
              }
            unless ($style eq 'rat') {              unless ($style eq 'rat') { 
               $allowstr.="\n".'<allow src="'.$thisdep.'" />';                $allowstr.="\n".'<allow src="'.$thisdep.'" />';
    }     }
            $scrout.='<br />';             $scrout.='<br />';
            if ($thisdep!~/\*/ && $thisdep!~m|^/adm/|) {             if ($thisdep!~/[\*\$]/ && $thisdep!~m|^/adm/|) {
        $scrout.='<a href="'.$thisdep.'">';         $scrout.='<a href="'.$thisdep.'">';
            }             }
            $scrout.='<tt>'.$thisdep.'</tt>';             $scrout.='<tt>'.$thisdep.'</tt>';
            if ($thisdep!~/\*/ && $thisdep!~m|^/adm/|) {             if ($thisdep!~/[\*\$]/ && $thisdep!~m|^/adm/|) {
        $scrout.='</a>';         $scrout.='</a>';
                if (                 if (
        &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.'/'.         &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                                             $thisdep.'.meta') eq '-1') {                                              $thisdep.'.meta') eq '-1') {
    $scrout.= ' - <font color="red">'.&mt('Currently not available').     $scrout.= ' - <span class="LC_error">'.&mt('Currently not available').
        '</font>';         '</span>';
                } else {                 } else {
                    my %temphash=(&Apache::lonnet::declutter($target).'___'.                     my %temphash=(&Apache::lonnet::declutter($target).'___'.
                              &Apache::lonnet::declutter($thisdep).'___usage'                               &Apache::lonnet::declutter($thisdep).'___usage'
Line 999  sub publish { Line 1008  sub publish {
           my $org;            my $org;
           unless ($org=Apache::File->new('>'.$source)) {            unless ($org=Apache::File->new('>'.$source)) {
              print $logfile "No write permit to $source\n";               print $logfile "No write permit to $source\n";
              return ('<font color="red">'.&mt('No write permission to').               return ('<span class="LC_error">'.&mt('No write permission to').
      ' '.$source.       ' '.$source.
      ', '.&mt('FAIL').'</font>',1);       ', '.&mt('FAIL').'</span>',1);
   }    }
           print($org $outstring);            print($org $outstring);
         }          }
Line 1106  sub publish { Line 1115  sub publish {
  }   }
     }      }
     if ($chparms) {      if ($chparms) {
  $scrout.='<p><b>'.&mt('New parameters or stored values').   $scrout.='<p><b>'.&mt('New parameters or saved values').
     ':</b> '.$chparms.'</p>';      ':</b> '.$chparms.'</p>';
     }      }
   
Line 1123  sub publish { Line 1132  sub publish {
  }   }
     }      }
     if ($chparms) {      if ($chparms) {
  $scrout.='<p><b>'.&mt('Obsolete parameters or stored values').':</b> '.   $scrout.='<p><b>'.&mt('Obsolete parameters or saved values').':</b> '.
     $chparms.'</p><h1><span class="LC_warning">'.&mt('Warning!').      $chparms.'</p><h1><span class="LC_warning">'.&mt('Warning!').
     '</span></h1><p><span class="LC_warning">'.      '</span></h1><p><span class="LC_warning">'.
     &mt('If this resource is in active use, student performance data from the previous version may become inaccessible.').'</span></p><hr />';      &mt('If this resource is in active use, student performance data from the previous version may become inaccessible.').'</span></p><hr />';
     }      }
       if ($metadatafields{'copyright'} eq 'priv') {
           $scrout.='</p><h1><span class="LC_warning">'.&mt('Warning!').
               '</span></h1><p><span class="LC_warning">'.
               &mt('Copyright/distribution option "Private" is no longer supported. Select another option from below. Consider "Custom Rights" for maximum control over the usage of your resource.').'</span></p><hr />';
       }
   
 # ------------------------------------------------------- Now have all metadata  # ------------------------------------------------------- Now have all metadata
   
Line 1287  END Line 1301  END
  $metadatafields{'copyright'}='default';   $metadatafields{'copyright'}='default';
  $metadatafields{'sourceavail'}='open';   $metadatafields{'sourceavail'}='open';
     }      }
       if ($metadatafields{'copyright'} eq 'priv') {
           $metadatafields{'copyright'}='domain';
       }
 # ------------------------------------------------ Dial in reasonable defaults  # ------------------------------------------------ Dial in reasonable defaults
     my $defaultoption=$metadatafields{'copyright'};      my $defaultoption=$metadatafields{'copyright'};
     unless ($defaultoption) { $defaultoption='default'; }      unless ($defaultoption) { $defaultoption='default'; }
Line 1303  END Line 1320  END
     $intr_scrout.=&selectbox('Copyright/Distribution','copyright',      $intr_scrout.=&selectbox('Copyright/Distribution','copyright',
      $defaultoption,       $defaultoption,
      \&Apache::loncommon::copyrightdescription,       \&Apache::loncommon::copyrightdescription,
     (grep !/^public$/,(&Apache::loncommon::copyrightids)));      (grep !/^(public|priv)$/,(&Apache::loncommon::copyrightids)));
  } else {   } else {
     $intr_scrout.=&selectbox('Copyright/Distribution','copyright',      $intr_scrout.=&selectbox('Copyright/Distribution','copyright',
      $defaultoption,       $defaultoption,
      \&Apache::loncommon::copyrightdescription,       \&Apache::loncommon::copyrightdescription,
      (&Apache::loncommon::copyrightids));       (grep !/^priv$/,(&Apache::loncommon::copyrightids)));
  }   }
  my $copyright_help =   my $copyright_help =
     Apache::loncommon::help_open_topic('Publishing_Copyright');      Apache::loncommon::help_open_topic('Publishing_Copyright');
Line 1412  sub phasetwo { Line 1429  sub phasetwo {
 #  #
     unless ($env{'form.obsolete'}) {      unless ($env{'form.obsolete'}) {
  if ($target=~/(\_\_\_|\&\&\&|\:\:\:)/) {   if ($target=~/(\_\_\_|\&\&\&|\:\:\:)/) {
     $r->print(      $r->print('<span class="LC_error">'.
       '<font color="red">'.&mt('Unsupported character combination').        &mt('Unsupported character combination [_1] in filename, FAIL.',"<tt>'.$1.'</tt>").
       ' "<tt>'.$1.'</tt>" '.&mt('in filename, FAIL').'</font>');        '</span>');
     return 0;      return 0;
  }   }
  unless ($target=~/\.(\w+)$/) {   unless ($target=~/\.(\w+)$/) {
     $r->print('<font color="red">'.&mt('No valid extension found in filename, FAIL').'</font>');      $r->print('<span class="LC_error">'.&mt('No valid extension found in filename, FAIL').'</span>');
     return 0;      return 0;
  }   }
  if ($target=~/\.(\d+)\.(\w+)$/) {   if ($target=~/\.(\d+)\.(\w+)$/) {
     $r->print('<font color="red">'.&mt('Cannot publish versioned resource, FAIL').'</font>');      $r->print('<span class="LC_error">'.&mt('Cannot publish versioned resource, FAIL').'</span>');
     return 0;      return 0;
  }   }
     }      }
Line 1434  sub phasetwo { Line 1451  sub phasetwo {
     my $logfile;      my $logfile;
     unless ($logfile=Apache::File->new('>>'.$source.'.log')) {      unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
  $r->print(   $r->print(
         '<font color="red">'.          '<span class="LC_error">'.
  &mt('No write permission to user directory, FAIL').'</font>');   &mt('No write permission to user directory, FAIL').'</span>');
         return 0;          return 0;
     }      }
       
       if ($source =~ /\.rights$/) {
    $r->print('<p><span class="LC_warning">'.&mt('Warning: It can take up to 1 hour for rights changes to fully propagate.').'</span></p>');
       }
   
     print $logfile       print $logfile 
         "\n================= Publish ".localtime()." Phase Two  ================\n".$env{'user.name'}.':'.$env{'user.domain'}."\n";          "\n================= Publish ".localtime()." Phase Two  ================\n".$env{'user.name'}.':'.$env{'user.domain'}."\n";
           
Line 1492  sub phasetwo { Line 1514  sub phasetwo {
  my $file=$metadatafields{'customdistributionfile'};   my $file=$metadatafields{'customdistributionfile'};
  unless ($file=~/\.rights$/) {   unless ($file=~/\.rights$/) {
             $r->print(              $r->print(
                 '<font color="red">'.&mt('No valid custom distribution rights file specified, FAIL').                  '<span class="LC_error">'.&mt('No valid custom distribution rights file specified, FAIL').
  '</font>');   '</span>');
     return 0;      return 0;
         }          }
     }      }
Line 1502  sub phasetwo { Line 1524  sub phasetwo {
         my $mfh;          my $mfh;
         unless ($mfh=Apache::File->new('>'.$source.'.meta')) {          unless ($mfh=Apache::File->new('>'.$source.'.meta')) {
             $r->print(               $r->print( 
                 '<font color="red">'.&mt('Could not write metadata, FAIL').                  '<span class="LC_error">'.&mt('Could not write metadata, FAIL').
  '</font>');   '</span>');
     return 0;      return 0;
         }          }
         foreach (sort keys %metadatafields) {          foreach (sort keys %metadatafields) {
Line 1556  sub phasetwo { Line 1578  sub phasetwo {
         unless ($srcd=~/^\/home\/httpd\/html\/res/) {          unless ($srcd=~/^\/home\/httpd\/html\/res/) {
             print $logfile "\nPANIC: Target dir is ".$srcd;              print $logfile "\nPANIC: Target dir is ".$srcd;
             $r->print(              $r->print(
  "<font color=\"red\">Invalid target directory, FAIL</font>");   "<span class=\"LC_error\">Invalid target directory, FAIL</span>");
     return 0;      return 0;
         }          }
         opendir(DIR,$srcd);          opendir(DIR,$srcd);
Line 1582  sub phasetwo { Line 1604  sub phasetwo {
             $r->print('<p>'.&mt('Copied old target file').'</p>');              $r->print('<p>'.&mt('Copied old target file').'</p>');
         } else {          } else {
     print $logfile "Unable to write ".$copyfile.':'.$!."\n";      print $logfile "Unable to write ".$copyfile.':'.$!."\n";
             $r->print("<font color=\"red\">".&mt('Failed to copy old target').              $r->print("<span class=\"LC_error\">".&mt('Failed to copy old target').
  ", $!, ".&mt('FAIL')."</font>");   ", $!, ".&mt('FAIL')."</span>");
     return 0;      return 0;
         }          }
                   
Line 1598  sub phasetwo { Line 1620  sub phasetwo {
     print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";      print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
             if (-e $target.'.meta') {              if (-e $target.'.meta') {
                 $r->print(                   $r->print( 
                     "<font color=\"red\">".                      "<span class=\"LC_error\">".
 &mt('Failed to write old metadata copy').", $!, ".&mt('FAIL')."</font>");  &mt('Failed to write old metadata copy').", $!, ".&mt('FAIL')."</span>");
  return 0;   return 0;
     }      }
         }          }
Line 1631  sub phasetwo { Line 1653  sub phasetwo {
         $r->print('<p>'.&mt('Copied source file').'</p>');          $r->print('<p>'.&mt('Copied source file').'</p>');
     } else {      } else {
         print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";          print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
         $r->print("<font color=\"red\">".          $r->print("<span class=\"LC_error\">".
     &mt('Failed to copy source').", $!, ".&mt('FAIL')."</font>");      &mt('Failed to copy source').", $!, ".&mt('FAIL')."</span>");
  return 0;   return 0;
     }      }
           
Line 1646  sub phasetwo { Line 1668  sub phasetwo {
     } else {      } else {
         print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n";          print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n";
         $r->print(          $r->print(
             "<font color=\"red\">".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL')."</font>");              "<span class=\"LC_error\">".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL')."</span>");
  return 0;   return 0;
     }      }
     $r->rflush;      $r->rflush;
Line 1879  sub defaultmetapublish { Line 1901  sub defaultmetapublish {
     if (copy($fn,$copyfile)) {      if (copy($fn,$copyfile)) {
         $r->print('<p>'.&mt('Copied source file').'</p>');          $r->print('<p>'.&mt('Copied source file').'</p>');
     } else {      } else {
         return "<font color=\"red\">".          return "<span class=\"LC_error\">".
     &mt('Failed to copy source').", $!, ".&mt('FAIL')."</font>";      &mt('Failed to copy source').", $!, ".&mt('FAIL')."</span>";
     }      }
   
 # --------------------------------------------------- Send update notifications  # --------------------------------------------------- Send update notifications

Removed from v.1.222  
changed lines
  Added in v.1.231


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>