Diff for /loncom/publisher/lonpublisher.pm between versions 1.166 and 1.187

version 1.166, 2004/04/14 18:29:32 version 1.187, 2005/03/10 02:34:58
Line 138  my $docroot; Line 138  my $docroot;
 my $cuname;  my $cuname;
 my $cudom;  my $cudom;
   
   my $registered_cleanup;
   my $modified_urls;
   
 =pod  =pod
   
 =item B<metaeval>  =item B<metaeval>
Line 199  sub metaeval { Line 202  sub metaeval {
  }   }
     }      }
     my $newentry=$parser->get_text('/'.$entry);      my $newentry=$parser->get_text('/'.$entry);
     if ($entry eq 'customdistributionfile') {      if (($entry eq 'customdistributionfile') ||
    ($entry eq 'sourcerights')) {
  $newentry=~s/^\s*//;   $newentry=~s/^\s*//;
  if ($newentry !~m|^/res|) { $newentry=$prefix.$newentry; }   if ($newentry !~m|^/res|) { $newentry=$prefix.$newentry; }
     }      }
Line 322  sub textfield { Line 326  sub textfield {
     $value=~s/\s+$//gs;      $value=~s/\s+$//gs;
     $value=~s/\s+/ /gs;      $value=~s/\s+/ /gs;
     $title=&mt($title);      $title=&mt($title);
       $ENV{'form.'.$name}=$value;
     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.'" />';
 }  }
   
   sub text_with_browse_field {
       my ($title,$name,$value,$restriction)=@_;
       $value=~s/^\s+//gs;
       $value=~s/\s+$//gs;
       $value=~s/\s+/ /gs;
       $title=&mt($title);
       $ENV{'form.'.$name}=$value;
       return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$title:".
              "</b></font></p><br />".
              '<input type="text" name="'.$name.'" size=80 value="'.$value.'" />'.
      '<a href="javascript:openbrowser(\'pubform\',\''.$name.'\',\''.$restriction.'\');">Select</a>&nbsp;'.
      '<a href="javascript:opensearcher(\'pubform\',\''.$name.'\');">Search</a>';
      
   }
   
 sub hiddenfield {  sub hiddenfield {
     my ($name,$value)=@_;      my ($name,$value)=@_;
       $ENV{'form.'.$name}=$value;
     return "\n".'<input type="hidden" name="'.$name.'" value="'.$value.'" />';      return "\n".'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
 }  }
   
Line 336  sub selectbox { Line 357  sub selectbox {
     my ($title,$name,$value,$functionref,@idlist)=@_;      my ($title,$name,$value,$functionref,@idlist)=@_;
     $title=&mt($title);      $title=&mt($title);
     $value=(split(/\s*,\s*/,$value))[-1];      $value=(split(/\s*,\s*/,$value))[-1];
       if (defined($value)) {
    $ENV{'form.'.$name}=$value;
       } else {
    $ENV{'form.'.$name}=$idlist[0];
       }
     my $selout="\n<p><font color=\"#800000\" face=\"helvetica\"><b>$title:".      my $selout="\n<p><font color=\"#800000\" face=\"helvetica\"><b>$title:".
  '</b></font></p><br /><select name="'.$name.'">';   '</b></font></p><br /><select name="'.$name.'">';
     foreach (@idlist) {      foreach (@idlist) {
Line 348  sub selectbox { Line 374  sub selectbox {
     return $selout.'</select>';      return $selout.'</select>';
 }  }
   
   sub select_level_form {
       my ($value,$name)=@_;
       $ENV{'form.'.$name}=$value;
       if (!defined($value)) { $ENV{'form.'.$name}=0; }
       return  &Apache::loncommon::select_level_form($value,$name);
   }
 #########################################  #########################################
 #########################################  #########################################
   
Line 458  sub get_subscribed_hosts { Line 490  sub get_subscribed_hosts {
     while ($filename=readdir(DIR)) {      while ($filename=readdir(DIR)) {
  if ($filename=~/\Q$srcf\E\.(\w+)$/) {   if ($filename=~/\Q$srcf\E\.(\w+)$/) {
     my $subhost=$1;      my $subhost=$1;
     if (($subhost ne 'meta' && $subhost ne 'subscription') &&      if (($subhost ne 'meta' && $subhost ne 'subscription' &&
    $subhost ne 'tmp') &&
                 ($subhost ne $Apache::lonnet::perlvar{'lonHostID'})) {                  ($subhost ne $Apache::lonnet::perlvar{'lonHostID'})) {
  push(@subscribed,$subhost);   push(@subscribed,$subhost);
     }      }
Line 515  sub get_max_ids_indices { Line 548  sub get_max_ids_indices {
     my $counter;      my $counter;
     if ($counter=$addid{$token->[1]}) {      if ($counter=$addid{$token->[1]}) {
  if ($counter eq 'id') {   if ($counter eq 'id') {
     if (defined($token->[2]->{'id'})) {      if (defined($token->[2]->{'id'}) &&
    $token->[2]->{'id'} !~ /^\s*$/) {
  $maxid=($token->[2]->{'id'}>$maxid)?$token->[2]->{'id'}:$maxid;   $maxid=($token->[2]->{'id'}>$maxid)?$token->[2]->{'id'}:$maxid;
  if (exists($allids{$token->[2]->{'id'}})) {   if (exists($allids{$token->[2]->{'id'}})) {
     $duplicateids=1;      $duplicateids=1;
Line 527  sub get_max_ids_indices { Line 561  sub get_max_ids_indices {
  $needsfixup=1;   $needsfixup=1;
     }      }
  } else {   } else {
     if (defined($token->[2]->{'index'})) {      if (defined($token->[2]->{'index'}) &&
    $token->[2]->{'index'} !~ /^\s*$/) {
  $maxindex=($token->[2]->{'index'}>$maxindex)?$token->[2]->{'index'}:$maxindex;   $maxindex=($token->[2]->{'index'}>$maxindex)?$token->[2]->{'index'}:$maxindex;
     } else {      } else {
  $needsfixup=1;   $needsfixup=1;
Line 569  sub get_all_text_unbalanced { Line 604  sub get_all_text_unbalanced {
  } elsif ($token->[0] eq 'E')  {   } elsif ($token->[0] eq 'E')  {
     $result.=$token->[2];      $result.=$token->[2];
  }   }
  if ($result =~ /(.*)\Q$tag\E(.*)/s) {   if ($result =~ /\Q$tag\E/s) {
       ($result,my $redo)=$result =~ /(.*)\Q$tag\E(.*)/is;
     #&Apache::lonnet::logthis('Got a winner with leftovers ::'.$2);      #&Apache::lonnet::logthis('Got a winner with leftovers ::'.$2);
     #&Apache::lonnet::logthis('Result is :'.$1);      #&Apache::lonnet::logthis('Result is :'.$1);
     $result=$1;      $redo=$tag.$redo;
     my $redo=$tag.$2;  
     push (@$pars,HTML::LCParser->new(\$redo));      push (@$pars,HTML::LCParser->new(\$redo));
     $$pars[-1]->xml_mode('1');      $$pars[-1]->xml_mode('1');
     last;      last;
Line 641  sub fix_ids_and_indices { Line 676  sub fix_ids_and_indices {
  if (!$counter) { $counter=$addid{$lctag}; }   if (!$counter) { $counter=$addid{$lctag}; }
  if ($counter) {   if ($counter) {
     if ($counter eq 'id') {      if ($counter eq 'id') {
  unless (defined($parms{'id'})) {   unless (defined($parms{'id'}) &&
    $parms{'id'}!~/^\s*$/) {
     $maxid++;      $maxid++;
     $parms{'id'}=$maxid;      $parms{'id'}=$maxid;
     print $logfile 'ID: '.$tag.':'.$maxid."\n";      print $logfile 'ID: '.$tag.':'.$maxid."\n";
  }   }
     } elsif ($counter eq 'index') {      } elsif ($counter eq 'index') {
  unless (defined($parms{'index'})) {   unless (defined($parms{'index'}) &&
    $parms{'index'}!~/^\s*$/) {
     $maxindex++;      $maxindex++;
     $parms{'index'}=$maxindex;      $parms{'index'}=$maxindex;
     print $logfile 'Index: '.$tag.':'.$maxindex."\n";      print $logfile 'Index: '.$tag.':'.$maxindex."\n";
Line 788  sub store_metadata { Line 825  sub store_metadata {
         &Apache::lonnet::logthis($error);          &Apache::lonnet::logthis($error);
         return ($error,undef);          return ($error,undef);
     }      }
       my $dbh = &Apache::lonmysql::get_dbh();
     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=&Apache::lonmysql::remove_from_table   $status=&LONCAPA::lonmetadata::delete_metadata($dbh,undef,
     ('metadata','url',$metadata{'url'});                                                         $metadata{'url'});
     } else {      } else {
 # store new data          $status = &LONCAPA::lonmetadata::update_metadata($dbh,undef,
 # adjust some values to metadatadatabase (e.g., "usage" is a reserved word)                                                           \%metadata);
  $metadata{'creationdate'}=  
     &Apache::lonmysql::sqltime($metadata{'creationdate'});   
  $metadata{'lastrevisiondate'}=  
     &Apache::lonmysql::sqltime($metadata{'lastrevisiondate'});  
  $metadata{'sequsage'}=$metadata{'usage'};  
  $metadata{'sequsage_list'}=$metadata{'usage_list'};  
  my %newmetadata=();  
 # see if we have old entries  
  my @oldmeta=&Apache::lonmysql::get_rows('metadata',  
  "url LIKE BINARY '".  
  $metadata{'url'}."'");  
  if ($#oldmeta==0) {  
 # yes, there is one old entry, transfer to newmetadata  
     %newmetadata=&LONCAPA::lonmetadata::metadata_col_to_hash(@{$oldmeta[0]});  
 # remove old entry  
     $status=&Apache::lonmysql::remove_from_table  
  ('metadata','url',$metadata{'url'});  
  } elsif ($#oldmeta>0) {  
 # more than one entry fit - how did that happen?  
     $error='<font color="red">Error occured retrieving old values in '.  
       'metadata table in LON-CAPA database: '.$#oldmeta.  
       ' matches</font>';  
     &Apache::lonnet::logthis($error);  
     return ($error,undef);  
  }  
 # store new data on top of it  
  foreach (keys %metadata) {  
     $newmetadata{$_}=$metadata{$_};  
  }  
  $status = &Apache::lonmysql::store_row('metadata',\%newmetadata);  
     }      }
     if (! defined($status)) {      if (defined($status) && $status ne '') {
         $error='<font color="red">Error occured storing new values in '.          $error='<font color="red">Error occured storing new values in '.
             'metadata table in LON-CAPA database</font>';              'metadata table in LON-CAPA database</font>';
         &Apache::lonnet::logthis($error);          &Apache::lonnet::logthis($error);
           &Apache::lonnet::logthis($status);
         return ($error,undef);          return ($error,undef);
     }      }
     return (undef,$status);      return (undef,$status);
 }  }
   
   
   # ========================================== Parse file for errors and warnings
   
   sub checkonthis {
       my ($r,$source)=@_;
       my $uri=&Apache::lonnet::hreflocation($source);
       $uri=~s/\/$//;
       my ($errorcount,$warningcount)=split(/:/,
          &Apache::lonnet::ssi_body($uri,
    ('return_only_error_and_warning_counts' => 1)));
       if (($errorcount) || ($warningcount)) {
           $r->print('<br /><tt>'.$uri.'</tt>: ');
    if ($errorcount) {
       $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
         $errorcount.' '.
         &mt('error(s)').'</b></font> ');
    }
    if ($warningcount) {
       $r->print('<font color="blue">'.
         $warningcount.' '.
         &mt('warning(s)').'</font>');
    }
       } else {
    $r->print('<font color="green">'.&mt('ok').'</font>');
       }
       $r->rflush();
       return ($warningcount,$errorcount);
   }
   
 # ============================================== Parse file itself for metadata  # ============================================== Parse file itself for metadata
 #  #
 # parses a file with target meta, sets global %metadatafields %metadatakeys   # parses a file with target meta, sets global %metadatafields %metadatakeys 
Line 943  sub publish { Line 980  sub publish {
        }         }
            }             }
         }          }
         $outstring=~s/\n*(\<\/[^\>]+\>)\s*$/$allowstr\n$1\n/s;          $outstring=~s/\n*(\<\/[^\>]+\>[^<]*)$/$allowstr\n$1\n/s;
   
 # ------------------------------------------------------------- Write modified.  # ------------------------------------------------------------- Write modified.
   
Line 1002  sub publish { Line 1039  sub publish {
             $scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix);              $scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix);
     $prefix=~s|^\.\./||;      $prefix=~s|^\.\./||;
         }          }
   
 # ----------------------------------------------------------- Parse file itself  # ----------------------------------------------------------- Parse file itself
 # read %metadatafields from file itself  # read %metadatafields from file itself
     
Line 1089  sub publish { Line 1127  sub publish {
     }      }
   
                           
     foreach (split(/\W+/,$metadatafields{'keywords'})) {      foreach my $addkey (split(/[\"\'\,\;]/,$metadatafields{'keywords'})) {
  $keywords{$_}=1;   $addkey=~s/\s+/ /g;
    $addkey=~s/^\s//;
    $addkey=~s/\s$//;
    if ($addkey=~/\w/) {
       $keywords{$addkey}=1;
    }
     }      }
 # --------------------------------------------------- Now we also have keywords  # --------------------------------------------------- Now we also have keywords
 # =============================================================================  # =============================================================================
 # INTERACTIVE MODE  # interactive mode html goes into $intr_scrout
 #  # batch mode throws away this HTML
     unless ($batch) {  # additionally all of the field functions have a by product of setting
         $scrout.=  #   $ENV{'from.'..} so that it can be used by the phase two handler in
     '<form name="pubform" action="/adm/publish" method="post">'.  #    batch mode
             '<p><input type="submit" value="'.&mt('Finalize Publication').'" /></p>'.  
             &hiddenfield('phase','two').      my $intr_scrout.=
             &hiddenfield('filename',$ENV{'form.filename'}).   '<form name="pubform" action="/adm/publish" method="post">'.
     &hiddenfield('allmeta',&Apache::lonnet::escape($allmeta)).   '<p><input type="submit" value="'.&mt('Finalize Publication').'" /></p>'.
             &hiddenfield('dependencies',join(',',keys %allow)).   &hiddenfield('phase','two').
             &textfield('Title','title',$metadatafields{'title'}).   &hiddenfield('filename',$ENV{'form.filename'}).
             &textfield('Author(s)','author',$metadatafields{'author'}).   &hiddenfield('allmeta',&Apache::lonnet::escape($allmeta)).
     &textfield('Subject','subject',$metadatafields{'subject'});   &hiddenfield('dependencies',join(',',keys %allow)).
    &textfield('Title','title',$metadatafields{'title'}).
    &textfield('Author(s)','author',$metadatafields{'author'}).
    &textfield('Subject','subject',$metadatafields{'subject'});
   
 # --------------------------------------------------- Scan content for keywords  # --------------------------------------------------- Scan content for keywords
   
         my $keywords_help = Apache::loncommon::help_open_topic("Publishing_Keywords");      my $keywords_help = Apache::loncommon::help_open_topic("Publishing_Keywords");
         my $KEYWORDS=&mt('Keywords');      my $KEYWORDS=&mt('Keywords');
  my $CheckAll=&mt('check all');      my $CheckAll=&mt('check all');
  my $UncheckAll=&mt('uncheck all');      my $UncheckAll=&mt('uncheck all');
  my $keywordout=<<"END";      my $keywordout=<<"END";
 <script>  <script>
 function checkAll(field) {  function checkAll(field) {
     for (i = 0; i < field.length; i++)      for (i = 0; i < field.length; i++)
Line 1133  function uncheckAll(field) { Line 1179  function uncheckAll(field) {
 </p>  </p>
 <br />  <br />
 END  END
  $keywordout.='<table border="2"><tr>';      $keywordout.='<table border="2"><tr>';
  my $colcount=0;      my $colcount=0;
   
  foreach (sort keys %keywords) {      foreach (sort keys %keywords) {
     $keywordout.='<td><input type="checkbox" name="keywords" value="'.$_.'"';   $keywordout.='<td><label><input type="checkbox" name="keywords" value="'.$_.'"';
     if ($metadatafields{'keywords'}) {   if ($metadatafields{'keywords'}) {
  if ($metadatafields{'keywords'}=~/\Q$_\E/) {      if ($metadatafields{'keywords'}=~/\Q$_\E/) {
     $keywordout.=' checked="on"';  
  }  
     } elsif (&Apache::loncommon::keyword($_)) {  
  $keywordout.=' checked="on"';   $keywordout.=' checked="on"';
    $ENV{'form.keywords'}.=$_.',';
     }      }
     $keywordout.=' />'.$_.'</td>';   } elsif (&Apache::loncommon::keyword($_)) {
     if ($colcount>10) {      $keywordout.=' checked="on"';
  $keywordout.="</tr><tr>\n";      $ENV{'form.keywords'}.=$_.',';
  $colcount=0;   }
     }   $keywordout.=' />'.$_.'</label></td>';
     $colcount++;   if ($colcount>10) {
       $keywordout.="</tr><tr>\n";
       $colcount=0;
  }   }
    $colcount++;
       }
       $ENV{'form.keywords'}=~s/\,$//;
   
  $keywordout.='</tr></table>';      $keywordout.='</tr></table>';
   
  $scrout.=$keywordout;      $intr_scrout.=$keywordout;
   
  $scrout.=&textfield('Additional Keywords','addkey','');      $intr_scrout.=&textfield('Additional Keywords','addkey','');
   
  $scrout.=&textfield('Notes','notes',$metadatafields{'notes'});      $intr_scrout.=&textfield('Notes','notes',$metadatafields{'notes'});
   
  $scrout.=      $intr_scrout.=
     "\n<p><font color=\"#800000\" face=\"helvetica\"><b>".&mt('Abstract').":".   "\n<p><font color=\"#800000\" face=\"helvetica\"><b>".&mt('Abstract').":".
     "</b></font></p><br />".   "</b></font></p><br />".
     '<textarea cols="80" rows="5" name="abstract">'.   '<textarea cols="80" rows="5" name="abstract">'.
     $metadatafields{'abstract'}.'</textarea></p>';   $metadatafields{'abstract'}.'</textarea></p>';
   
  $source=~/\.(\w+)$/;      $source=~/\.(\w+)$/;
   
   
  $scrout.=      $intr_scrout.=
     "\n<p><font color=\"#800000\" face=\"helvetica\"><b>".   "\n<p><font color=\"#800000\" face=\"helvetica\"><b>".
     &mt('Lowest Grade Level').':'.   &mt('Lowest Grade Level').':'.
            "</b></font></p><br />".   "</b></font></p><br />".
    &Apache::loncommon::select_level_form($metadatafields{'lowestgradelevel'},'lowestgradelevel').   &select_level_form($metadatafields{'lowestgradelevel'},'lowestgradelevel').
     "\n<p><font color=\"#800000\" face=\"helvetica\"><b>".   "\n<p><font color=\"#800000\" face=\"helvetica\"><b>".
     &mt('Highest Grade Level').':'.   &mt('Highest Grade Level').':'.
            "</b></font></p><br />".   "</b></font></p><br />".
    &Apache::loncommon::select_level_form($metadatafields{'highestgradelevel'},'highestgradelevel').   &select_level_form($metadatafields{'highestgradelevel'},'highestgradelevel').
            &textfield('Standards','standards',$metadatafields{'standards'});   &textfield('Standards','standards',$metadatafields{'standards'});
   
   
   
   
  $scrout.=&hiddenfield('mime',$1);      $intr_scrout.=&hiddenfield('mime',$1);
   
  my $defaultlanguage=$metadatafields{'language'};      my $defaultlanguage=$metadatafields{'language'};
  $defaultlanguage =~ s/\s*notset\s*//g;      $defaultlanguage =~ s/\s*notset\s*//g;
  $defaultlanguage =~ s/^,\s*//g;      $defaultlanguage =~ s/^,\s*//g;
  $defaultlanguage =~ s/,\s*$//g;      $defaultlanguage =~ s/,\s*$//g;
   
  $scrout.=&selectbox('Language','language',      $intr_scrout.=&selectbox('Language','language',
     $defaultlanguage,       $defaultlanguage,
     \&Apache::loncommon::languagedescription,       \&Apache::loncommon::languagedescription,
     (&Apache::loncommon::languageids),       (&Apache::loncommon::languageids),
    );       );
   
  unless ($metadatafields{'creationdate'}) {      unless ($metadatafields{'creationdate'}) {
     $metadatafields{'creationdate'}=time;   $metadatafields{'creationdate'}=time;
  }      }
  $scrout.=&hiddenfield('creationdate',      $intr_scrout.=&hiddenfield('creationdate',
       &Apache::lonmysql::unsqltime($metadatafields{'creationdate'}));         &Apache::lonmysql::unsqltime($metadatafields{'creationdate'}));
   
  $scrout.=&hiddenfield('lastrevisiondate',time);      $intr_scrout.=&hiddenfield('lastrevisiondate',time);
   
   
  $scrout.=&textfield('Publisher/Owner','owner',      $intr_scrout.=&textfield('Publisher/Owner','owner',
     $metadatafields{'owner'});       $metadatafields{'owner'});
   
   # ---------------------------------------------- Retrofix for unused copyright
       if ($metadatafields{'copyright'} eq 'free') {
    $metadatafields{'copyright'}='default';
    $metadatafields{'sourceavail'}='open';
       }
   # ------------------------------------------------ Dial in reasonable defaults
       my $defaultoption=$metadatafields{'copyright'};
       unless ($defaultoption) { $defaultoption='default'; }
       my $defaultsourceoption=$metadatafields{'sourceavail'};
       unless ($defaultsourceoption) { $defaultsourceoption='closed'; }
       unless ($style eq 'prv') {
 # -------------------------------------------------- Correct copyright for rat.  # -------------------------------------------------- Correct copyright for rat.
         my $defaultoption=$metadatafields{'copyright'};   if ($style eq 'rat') {
         unless ($defaultoption) { $defaultoption='default'; }  # -------------------------------------- Retrofix for non-applicable copyright
  unless ($style eq 'prv') {      if ($metadatafields{'copyright'} eq 'public') { 
     if ($style eq 'rat') {   delete $metadatafields{'copyright'};
  if ($metadatafields{'copyright'} eq 'public') {    $defaultoption='default';
     delete $metadatafields{'copyright'};      }
                     $defaultoption='default';      $intr_scrout.=&selectbox('Copyright/Distribution','copyright',
  }       $defaultoption,
  $scrout.=&selectbox('Copyright/Distribution','copyright',       \&Apache::loncommon::copyrightdescription,
     $defaultoption,  
     \&Apache::loncommon::copyrightdescription,  
     (grep !/^public$/,(&Apache::loncommon::copyrightids)));      (grep !/^public$/,(&Apache::loncommon::copyrightids)));
     } else {  
  $scrout.=&selectbox('Copyright/Distribution','copyright',  
     $defaultoption,  
     \&Apache::loncommon::copyrightdescription,  
     (&Apache::loncommon::copyrightids));  
     }  
       
     my $copyright_help =  
  Apache::loncommon::help_open_topic('Publishing_Copyright');  
     $scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge;  
     $scrout.=&textfield('Custom Distribution File','customdistributionfile',  
  $metadatafields{'customdistributionfile'}).  
     $copyright_help;  
     my $uctitle=&mt('Obsolete');  
             $scrout.=  
  "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:".  
  '</b></font> <input type="checkbox" name="obsolete" ';  
     if ($metadatafields{'obsolete'}) {  
  $scrout.=' checked="1" ';  
     }  
     $scrout.='/ ></p>'.  
  &textfield('Suggested Replacement for Obsolete File',  
     'obsoletereplacement',  
     $metadatafields{'obsoletereplacement'});  
  } else {   } else {
     $scrout.=&hiddenfield('copyright','private');      $intr_scrout.=&selectbox('Copyright/Distribution','copyright',
        $defaultoption,
        \&Apache::loncommon::copyrightdescription,
        (&Apache::loncommon::copyrightids));
    }
    my $copyright_help =
       Apache::loncommon::help_open_topic('Publishing_Copyright');
    $intr_scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge;
    $intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights').$copyright_help;
    $intr_scrout.=&selectbox('Source Distribution','sourceavail',
    $defaultsourceoption,
    \&Apache::loncommon::source_copyrightdescription,
    (&Apache::loncommon::source_copyrightids));
    $intr_scrout.=&text_with_browse_field('Source Custom Distribution File','sourcerights',$metadatafields{'sourcerights'},'rights');
    my $uctitle=&mt('Obsolete');
    $intr_scrout.=
       "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:".
       '</b></font> <input type="checkbox" name="obsolete" ';
    if ($metadatafields{'obsolete'}) {
       $intr_scrout.=' checked="1" ';
  }   }
  return ($scrout.'<p><input type="submit" value="'.   $intr_scrout.='/ ></p>'.
  &mt('Finalize Publication').'" /></p></form>',0);      &text_with_browse_field('Suggested Replacement for Obsolete File',
 # =============================================================================      'obsoletereplacement',
 # BATCH MODE      $metadatafields{'obsoletereplacement'});
 #  
     } else {      } else {
 # Transfer metadata directly to environment for stage 2   $intr_scrout.=&hiddenfield('copyright','private');
  foreach (keys %metadatafields) {  
     $ENV{'form.'.$_}=$metadatafields{$_};  
  }  
  $ENV{'form.addkey'}='';  
  $ENV{'form.keywords'}='';  
  foreach (keys %keywords) {  
     if ($metadatafields{'keywords'}) {  
  if ($metadatafields{'keywords'}=~/\Q$_\E/) {   
     $ENV{'form.keywords'}.=$_.',';   
  }  
     } elsif (&Apache::loncommon::keyword($_)) {  
  $ENV{'form.keywords'}.=$_.',';  
     }  
  }  
  $ENV{'form.keywords'}=~s/\,$//;  
  unless ($ENV{'form.creationdate'}) { $ENV{'form.creationdate'}=time; }  
  $ENV{'form.lastrevisiondate'}=time;  
  if ((($style eq 'rat') && ($ENV{'form.copyright'} eq 'public')) ||  
     (!$ENV{'form.copyright'})) {   
     $ENV{'form.copyright'}='default';  
  }  
  $ENV{'form.allmeta'}=&Apache::lonnet::escape($allmeta);  
  return ($scrout,0);  
     }      }
       if (!$batch) {
    $scrout.=$intr_scrout.'<p><input type="submit" value="'.
       &mt('Finalize Publication').'" /></p></form>';
       }
       return($scrout,0);
 }  }
   
 #########################################  #########################################
Line 1345  sub phasetwo { Line 1379  sub phasetwo {
           
     %metadatafields=();      %metadatafields=();
     %metadatakeys=();      %metadatakeys=();
       
     &metaeval(&Apache::lonnet::unescape($ENV{'form.allmeta'}));      &metaeval(&Apache::lonnet::unescape($ENV{'form.allmeta'}));
           
     $metadatafields{'title'}=$ENV{'form.title'};      $metadatafields{'title'}=$ENV{'form.title'};
Line 1364  sub phasetwo { Line 1398  sub phasetwo {
     $metadatafields{'highestgradelevel'}=$ENV{'form.highestgradelevel'};      $metadatafields{'highestgradelevel'}=$ENV{'form.highestgradelevel'};
     $metadatafields{'customdistributionfile'}=      $metadatafields{'customdistributionfile'}=
                                  $ENV{'form.customdistributionfile'};                                   $ENV{'form.customdistributionfile'};
       $metadatafields{'sourceavail'}=$ENV{'form.sourceavail'};
     $metadatafields{'obsolete'}=$ENV{'form.obsolete'};      $metadatafields{'obsolete'}=$ENV{'form.obsolete'};
     $metadatafields{'obsoletereplacement'}=      $metadatafields{'obsoletereplacement'}=
                         $ENV{'form.obsoletereplacement'};                          $ENV{'form.obsoletereplacement'};
Line 1380  sub phasetwo { Line 1415  sub phasetwo {
             $allkeywords .= ','.$ENV{'form.keywords'};              $allkeywords .= ','.$ENV{'form.keywords'};
         }          }
     }      }
     $allkeywords=~s/\W+/\,/;      $allkeywords=~s/[\"\']//g;
     $allkeywords=~s/^\,//;      $allkeywords=~s/\s*[\;\,]\s*/\,/g;
       $allkeywords=~s/\s+/ /g;
       $allkeywords=~s/^[ \,]//;
       $allkeywords=~s/[ \,]$//;
     $metadatafields{'keywords'}=$allkeywords;      $metadatafields{'keywords'}=$allkeywords;
           
 # check if custom distribution file is specified  # check if custom distribution file is specified
Line 1539  sub phasetwo { Line 1577  sub phasetwo {
             "<font color=\"red\">".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL')."</font>";              "<font color=\"red\">".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL')."</font>";
     }      }
     $r->rflush;      $r->rflush;
 # --------------------------------------------------- Send update notifications  
   
     my @subscribed=&get_subscribed_hosts($target);  # ------------------------------------------------------------- Trigger updates
     foreach my $subhost (@subscribed) {      push(@{$modified_urls},[$target,$source]);
  $r->print('<p>'.&mt('Notifying host').' '.$subhost.':');$r->rflush;      unless ($registered_cleanup) {
  print $logfile "\nNotifying host ".$subhost.':';   $r->register_cleanup(\&notify);
  my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);   $registered_cleanup=1;
  $r->print($reply.'</p><br />');$r->rflush;  
  print $logfile $reply;  
     }  
       
 # ---------------------------------------- Send update notifications, meta only  
   
     my @subscribedmeta=&get_subscribed_hosts("$target.meta");  
     foreach my $subhost (@subscribedmeta) {  
  $r->print('<p>'.  
 &mt('Notifying host for metadata only').' '.$subhost.':');$r->rflush;  
  print $logfile "\nNotifying host for metadata only ".$subhost.':';  
  my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',  
     $subhost);  
  $r->print($reply.'</p><br />');$r->rflush;  
  print $logfile $reply;  
     }  
       
 # --------------------------------------------------- Notify subscribed courses  
     my %courses=&coursedependencies($target);  
     my $now=time;  
     foreach (keys %courses) {  
  $r->print('<p>'.&mt('Notifying course').' '.$_.':');$r->rflush;  
  print $logfile "\nNotifying host ".$_.':';  
         my ($cdom,$cname)=split(/\_/,$_);  
  my $reply=&Apache::lonnet::cput  
                   ('versionupdate',{$target => $now},$cdom,$cname);  
  $r->print($reply.'</p><br />');$r->rflush;  
  print $logfile $reply;  
     }      }
 # ------------------------------------------------ Provide link to new resource  # ------------------------------------------------ Provide link to new resource
     unless ($batch) {      unless ($batch) {
Line 1596  sub phasetwo { Line 1605  sub phasetwo {
                    '"><font size="+2">'.                     '"><font size="+2">'.
   &mt('Back to Source Directory').'</font></a></p>');    &mt('Back to Source Directory').'</font></a></p>');
     }      }
       $logfile->close();
     return '<p><font color="green">'.&mt('Done').'</font></p>';      return '<p><font color="green">'.&mt('Done').'</font></p>';
 }  }
   
   # =============================================================== Notifications
   sub notify {  
   # --------------------------------------------------- Send update notifications
       foreach my $targetsource (@{$modified_urls}){
    my ($target,$source)=@{$targetsource};
    my $logfile=Apache::File->new('>>'.$source.'.log');
    print $logfile "\nCleanup phase: Notifications\n";
    my @subscribed=&get_subscribed_hosts($target);
    foreach my $subhost (@subscribed) {
       print $logfile "\nNotifying host ".$subhost.':';
       my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
       print $logfile $reply;
    }
   # ---------------------------------------- Send update notifications, meta only
    my @subscribedmeta=&get_subscribed_hosts("$target.meta");
    foreach my $subhost (@subscribedmeta) {
       print $logfile "\nNotifying host for metadata only ".$subhost.':';
       my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
    $subhost);
       print $logfile $reply;
    } 
   # --------------------------------------------------- Notify subscribed courses
    my %courses=&coursedependencies($target);
    my $now=time;
    foreach (keys %courses) {
       print $logfile "\nNotifying course ".$_.':';
       my ($cdom,$cname)=split(/\_/,$_);
       my $reply=&Apache::lonnet::cput
    ('versionupdate',{$target => $now},$cdom,$cname);
       print $logfile $reply;
    }
    print $logfile "\n============ Done ============\n";
    $logfile->close();
       }
       return OK;
   }
   
 #########################################  #########################################
   
 sub batchpublish {  sub batchpublish {
Line 1679  sub publishdirectory { Line 1726  sub publishdirectory {
     $ruid,$rgid,$rrdev,$rsize,      $ruid,$rgid,$rrdev,$rsize,
     $ratime,$rmtime,$rctime,      $ratime,$rmtime,$rctime,
     $rblksize,$rblocks)=stat($resdir.'/'.$filename);      $rblksize,$rblocks)=stat($resdir.'/'.$filename);
         if (($rmtime<$cmtime) || ($ENV{'form.forcerepub'})) {          if (($rmtime<$cmtime) || ($ENV{'form.forcerepub'} eq 'ON')) {
 # previously published, modified now  # previously published, modified now
     $publishthis=1;      $publishthis=1;
                 }                  }
Line 1808  sub handler { Line 1855  sub handler {
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                             ['filename']);                                              ['filename']);
   
   # -------------------------------------- Flag and buffer for registered cleanup
       $registered_cleanup=0;
       @{$modified_urls}=();
 # -------------------------------------------------------------- Check filename  # -------------------------------------------------------------- Check filename
   
     my $fn=&Apache::lonnet::unescape($ENV{'form.filename'});      my $fn=&Apache::lonnet::unescape($ENV{'form.filename'});
Line 1901  sub handler { Line 1951  sub handler {
   
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
       
     $r->print('<html><head><title>LON-CAPA Publishing</title></head>');      my $js=&Apache::loncommon::browser_and_searcher_javascript();
       $r->print('<html><head><title>LON-CAPA Publishing</title>
                 <script type="text/javascript">'.$js.'
                 </script></head>');
     $r->print(&Apache::loncommon::bodytag('Resource Publication'));      $r->print(&Apache::loncommon::bodytag('Resource Publication'));
   
   
Line 1958  ENDDIFF Line 2011  ENDDIFF
 # ------------------ Publishing from $thisfn to $thistarget with $thisembstyle.  # ------------------ Publishing from $thisfn to $thistarget with $thisembstyle.
   
  unless ($ENV{'form.phase'} eq 'two') {   unless ($ENV{'form.phase'} eq 'two') {
     my ($outstring,$error)=&publish($thisfn,$thistarget,$thisembstyle);  # ---------------------------------------------------------- Parse for problems
     $r->print('<hr />'.$outstring);      my ($warningcount,$errorcount)=&checkonthis($r,$thisfn);
               unless ($errorcount) {
    my ($outstring,$error)=
       &publish($thisfn,$thistarget,$thisembstyle);
    $r->print('<hr />'.$outstring);
       } else {
                   $r->print('<h3>'.
    &mt('The document contains errors and cannot be published.').
     '</h3>');
       }
  } else {   } else {
     $r->print('<hr />'.      $r->print('<hr />'.
     &phasetwo($r,$thisfn,$thistarget,$thisembstyle,$thisdistarget));       &phasetwo($r,$thisfn,$thistarget,$thisembstyle,$thisdistarget)); 

Removed from v.1.166  
changed lines
  Added in v.1.187


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