File:  [LON-CAPA] / loncom / publisher / lonpublisher.pm
Revision 1.281: download - view: text, annotated - select for diffs
Tue Jan 15 18:21:31 2013 UTC (11 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Use correct module for &display() routine.

    1: # The LearningOnline Network with CAPA
    2: # Publication Handler
    3: #
    4: # $Id: lonpublisher.pm,v 1.281 2013/01/15 18:21:31 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: ###############################################################################
   31: ##                                                                           ##
   32: ## ORGANIZATION OF THIS PERL MODULE                                          ##
   33: ##                                                                           ##
   34: ## 1. Modules used by this module                                            ##
   35: ## 2. Various subroutines                                                    ##
   36: ## 3. Publication Step One                                                   ##
   37: ## 4. Phase Two                                                              ##
   38: ## 5. Main Handler                                                           ##
   39: ##                                                                           ##
   40: ###############################################################################
   41: 
   42: 
   43: ######################################################################
   44: ######################################################################
   45: 
   46: =pod 
   47: 
   48: =head1 NAME
   49: 
   50: lonpublisher - LON-CAPA publishing handler
   51: 
   52: =head1 SYNOPSIS
   53: 
   54: B<lonpublisher> is used by B<mod_perl> inside B<Apache>.  This is the
   55: invocation by F<loncapa_apache.conf>:
   56: 
   57:   <Location /adm/publish>
   58:   PerlAccessHandler       Apache::lonacc
   59:   SetHandler perl-script
   60:   PerlHandler Apache::lonpublisher
   61:   ErrorDocument     403 /adm/login
   62:   ErrorDocument     404 /adm/notfound.html
   63:   ErrorDocument     406 /adm/unauthorized.html
   64:   ErrorDocument     500 /adm/errorhandler
   65:   </Location>
   66: 
   67: =head1 OVERVIEW
   68: 
   69: Authors can only write-access the C</priv/domain/authorname/> space. 
   70: They can copy resources into the resource area through the 
   71: publication step, and move them back through a recover step. 
   72: Authors do not have direct write-access to their resource space.
   73: 
   74: During the publication step, several events will be
   75: triggered. Metadata is gathered, where a wizard manages default
   76: entries on a hierarchical per-directory base: The wizard imports the
   77: metadata (including access privileges and royalty information) from
   78: the most recent published resource in the current directory, and if
   79: that is not available, from the next directory above, etc. The Network
   80: keeps all previous versions of a resource and makes them available by
   81: an explicit version number, which is inserted between the file name
   82: and extension, for example C<foo.2.html>, while the most recent
   83: version does not carry a version number (C<foo.html>). Servers
   84: subscribing to a changed resource are notified that a new version is
   85: available.
   86: 
   87: =head1 DESCRIPTION
   88: 
   89: B<lonpublisher> takes the proper steps to add resources to the LON-CAPA
   90: digital library.  This includes updating the metadata table in the
   91: LON-CAPA database.
   92: 
   93: B<lonpublisher> is many things to many people.  
   94: 
   95: This module publishes a file.  This involves gathering metadata,
   96: versioning the file, copying file from construction space to
   97: publication space, and copying metadata from construction space
   98: to publication space.
   99: 
  100: =head2 SUBROUTINES
  101: 
  102: Many of the undocumented subroutines implement various magical
  103: parsing shortcuts.
  104: 
  105: =over 4
  106: 
  107: =cut
  108: 
  109: ######################################################################
  110: ######################################################################
  111: 
  112: 
  113: package Apache::lonpublisher;
  114: 
  115: # ------------------------------------------------- modules used by this module
  116: use strict;
  117: use Apache::File;
  118: use File::Copy;
  119: use Apache::Constants qw(:common :http :methods);
  120: use HTML::LCParser;
  121: use HTML::Entities;
  122: use Encode::Encoder;
  123: use Apache::lonxml;
  124: use DBI;
  125: use Apache::lonnet;
  126: use Apache::loncommon();
  127: use Apache::lonhtmlcommon;
  128: use Apache::lonmysql;
  129: use Apache::lonlocal;
  130: use Apache::loncfile;
  131: use LONCAPA::lonmetadata;
  132: use Apache::lonmsg;
  133: use vars qw(%metadatafields %metadatakeys);
  134: use LONCAPA qw(:DEFAULT :match);
  135:  
  136: 
  137: my %addid;
  138: my %nokey;
  139: 
  140: my $docroot;
  141: 
  142: my $cuname;
  143: my $cudom;
  144: 
  145: my $registered_cleanup;
  146: my $modified_urls;
  147: 
  148: my $lock;
  149: 
  150: =pod
  151: 
  152: =item B<metaeval>
  153: 
  154: Evaluates a string that contains metadata.  This subroutine
  155: stores values inside I<%metadatafields> and I<%metadatakeys>.
  156: The hash key is a I<$unikey> corresponding to a unique id
  157: that is descriptive of the parser location inside the XML tree.
  158: 
  159: Parameters:
  160: 
  161: =over 4
  162: 
  163: =item I<$metastring>
  164: 
  165: A string that contains metadata.
  166: 
  167: =back
  168: 
  169: Returns:
  170: 
  171: nothing
  172: 
  173: =cut
  174: 
  175: #########################################
  176: #########################################
  177: #
  178: # Modifies global %metadatafields %metadatakeys 
  179: #
  180: 
  181: sub metaeval {
  182:     my ($metastring,$prefix)=@_;
  183:    
  184:     my $parser=HTML::LCParser->new(\$metastring);
  185:     my $token;
  186:     while ($token=$parser->get_token) {
  187: 	if ($token->[0] eq 'S') {
  188: 	    my $entry=$token->[1];
  189: 	    my $unikey=$entry;
  190: 	    next if ($entry =~ m/^(?:parameter|stores)_/);
  191: 	    if (defined($token->[2]->{'package'})) { 
  192: 		$unikey.="\0package\0".$token->[2]->{'package'};
  193: 	    } 
  194: 	    if (defined($token->[2]->{'part'})) { 
  195: 		$unikey.="\0".$token->[2]->{'part'}; 
  196: 	    }
  197: 	    if (defined($token->[2]->{'id'})) { 
  198: 		$unikey.="\0".$token->[2]->{'id'};
  199: 	    } 
  200: 	    if (defined($token->[2]->{'name'})) { 
  201: 		$unikey.="\0".$token->[2]->{'name'}; 
  202: 	    }
  203: 	    foreach (@{$token->[3]}) {
  204: 		$metadatafields{$unikey.'.'.$_}=$token->[2]->{$_};
  205: 		if ($metadatakeys{$unikey}) {
  206: 		    $metadatakeys{$unikey}.=','.$_;
  207: 		} else {
  208: 		    $metadatakeys{$unikey}=$_;
  209: 		}
  210: 	    }
  211: 	    my $newentry=$parser->get_text('/'.$entry);
  212: 	    if (($entry eq 'customdistributionfile') ||
  213: 		($entry eq 'sourcerights')) {
  214: 		$newentry=~s/^\s*//;
  215: 		if ($newentry !~m|^/res|) { $newentry=$prefix.$newentry; }
  216: 	    }
  217: # actually store
  218: 	    if ( $entry eq 'rule' && exists($metadatafields{$unikey})) {
  219: 		$metadatafields{$unikey}.=','.$newentry;
  220: 	    } else {
  221: 		$metadatafields{$unikey}=$newentry;
  222: 	    }
  223: 	}
  224:     }
  225: }
  226: 
  227: #########################################
  228: #########################################
  229: 
  230: =pod
  231: 
  232: =item B<metaread>
  233: 
  234: Read a metadata file
  235: 
  236: Parameters:
  237: 
  238: =over
  239: 
  240: =item I<$logfile>
  241: 
  242: File output stream to output errors and warnings to.
  243: 
  244: =item I<$fn>
  245: 
  246: File name (including path).
  247: 
  248: =back
  249: 
  250: Returns:
  251: 
  252: =over 4
  253: 
  254: =item Scalar string (if successful)
  255: 
  256: XHTML text that indicates successful reading of the metadata.
  257: 
  258: =back
  259: 
  260: =cut
  261: 
  262: #########################################
  263: #########################################
  264: sub metaread {
  265:     my ($logfile,$fn,$prefix)=@_;
  266:     unless (-e $fn) {
  267: 	print($logfile 'No file '.$fn."\n");
  268:         return '<p class="LC_warning">'
  269:               .&mt('No file: [_1]',&Apache::loncfile::display($fn))
  270:               .'</p>';
  271:     }
  272:     print($logfile 'Processing '.$fn."\n");
  273:     my $metastring;
  274:     {
  275: 	my $metafh=Apache::File->new($fn);
  276: 	$metastring=join('',<$metafh>);
  277:     }
  278:     &metaeval($metastring,$prefix);
  279:     return '<p class="LC_info">'
  280:           .&mt('Processed file: [_1]',&Apache::loncfile::display($fn))
  281:           .'</p>';
  282: }
  283: 
  284: #########################################
  285: #########################################
  286: 
  287: sub coursedependencies {
  288:     my $url=&Apache::lonnet::declutter(shift);
  289:     $url=~s/\.meta$//;
  290:     my ($adomain,$aauthor)=($url=~ m{^($match_domain)/($match_username)/});
  291:     my $regexp=quotemeta($url);
  292:     $regexp='___'.$regexp.'___course';
  293:     my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
  294: 				       $aauthor,$regexp);
  295:     my %courses=();
  296:     foreach (keys %evaldata) {
  297: 	if ($_=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
  298: 	    $courses{$1}=1;
  299:         }
  300:     }
  301:     return %courses;
  302: }
  303: #########################################
  304: #########################################
  305: 
  306: 
  307: =pod
  308: 
  309: =item Form-field-generating subroutines.
  310: 
  311: For input parameters, these subroutines take in values
  312: such as I<$name>, I<$value> and other form field metadata.
  313: The output (scalar string that is returned) is an XHTML
  314: string which presents the form field (foreseeably inside
  315: <form></form> tags).
  316: 
  317: =over 4
  318: 
  319: =item B<textfield>
  320: 
  321: =item B<hiddenfield>
  322: 
  323: =item B<selectbox>
  324: 
  325: =back
  326: 
  327: =cut
  328: 
  329: #########################################
  330: #########################################
  331: sub textfield {
  332:     my ($title,$name,$value,$noline)=@_;
  333:     $value=~s/^\s+//gs;
  334:     $value=~s/\s+$//gs;
  335:     $value=~s/\s+/ /gs;
  336:     $title=&mt($title);
  337:     $env{'form.'.$name}=$value;
  338:     return "\n".&Apache::lonhtmlcommon::row_title($title)
  339:            .'<input type="text" name="'.$name.'" size="80" value="'.$value.'" />'
  340:            .&Apache::lonhtmlcommon::row_closure($noline);
  341: }
  342: 
  343: sub text_with_browse_field {
  344:     my ($title,$name,$value,$restriction,$noline)=@_;
  345:     $value=~s/^\s+//gs;
  346:     $value=~s/\s+$//gs;
  347:     $value=~s/\s+/ /gs;
  348:     $title=&mt($title);
  349:     $env{'form.'.$name}=$value;
  350:     return "\n".&Apache::lonhtmlcommon::row_title($title)
  351:           .'<input type="text" name="'.$name.'" size="80" value="'.$value.'" />'
  352:           .'<br />'
  353: 	  .'<a href="javascript:openbrowser(\'pubform\',\''.$name.'\',\''.$restriction.'\');">'
  354:           .&mt('Select')
  355:           .'</a>&nbsp;'
  356: 	  .'<a href="javascript:opensearcher(\'pubform\',\''.$name.'\');">'
  357:           .&mt('Search')
  358:           .'</a>'
  359:           .&Apache::lonhtmlcommon::row_closure($noline);
  360: }
  361: 
  362: sub hiddenfield {
  363:     my ($name,$value)=@_;
  364:     $env{'form.'.$name}=$value;
  365:     return "\n".'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
  366: }
  367: 
  368: sub checkbox {
  369:     my ($name,$text)=@_;
  370:     return "\n<br /><label><input type='checkbox' name='$name' /> ".
  371: 	&mt($text)."</label>";
  372: }
  373: 
  374: sub selectbox {
  375:     my ($title,$name,$value,$functionref,@idlist)=@_;
  376:     $title=&mt($title);
  377:     $value=(split(/\s*,\s*/,$value))[-1];
  378:     if (defined($value)) {
  379: 	$env{'form.'.$name}=$value;
  380:     } else {
  381: 	$env{'form.'.$name}=$idlist[0];
  382:     }
  383:     my $selout="\n".&Apache::lonhtmlcommon::row_title($title)
  384:               .'<select name="'.$name.'">';
  385:     foreach (@idlist) {
  386:         $selout.='<option value="'.$_.'"';
  387:         if ($_ eq $value) {
  388: 	    $selout.=' selected="selected"';
  389:         }
  390:         $selout.='>'.&{$functionref}($_).'</option>';
  391:     }
  392:     $selout.='</select>'.&Apache::lonhtmlcommon::row_closure();
  393:     return $selout;
  394: }
  395: 
  396: sub select_level_form {
  397:     my ($value,$name)=@_;
  398:     $env{'form.'.$name}=$value;
  399:     if (!defined($value)) { $env{'form.'.$name}=0; }
  400:     return  &Apache::loncommon::select_level_form($value,$name);
  401: }
  402: #########################################
  403: #########################################
  404: 
  405: =pod
  406: 
  407: =item B<urlfixup>
  408: 
  409: Fix up a url?  First step of publication
  410: 
  411: =cut
  412: 
  413: #########################################
  414: #########################################
  415: sub urlfixup {
  416:     my ($url,$target)=@_;
  417:     unless ($url) { return ''; }
  418:     #javascript code needs no fixing
  419:     if ($url =~ /^javascript:/i) { return $url; }
  420:     if ($url =~ /^mailto:/i) { return $url; }
  421:     #internal document links need no fixing
  422:     if ($url =~ /^\#/) { return $url; } 
  423:     my ($host)=($url=~m{(?:(?:http|https|ftp)://)*([^/]+)});
  424:     my @lonids = &Apache::lonnet::machine_ids($host);
  425:     if (@lonids) {
  426: 	$url=~s{^(?:http|https|ftp)://}{};
  427: 	$url=~s/^\Q$host\E//;
  428:     }
  429:     if ($url=~m{^(?:http|https|ftp)://}) { return $url; }
  430:     $url=~s{\Q~$cuname\E}{res/$cudom/$cuname};
  431:     return $url;
  432: }
  433: 
  434: #########################################
  435: #########################################
  436: 
  437: =pod
  438: 
  439: =item B<absoluteurl>
  440: 
  441: Currently undocumented.
  442: 
  443: =cut
  444: 
  445: #########################################
  446: #########################################
  447: sub absoluteurl {
  448:     my ($url,$target)=@_;
  449:     unless ($url) { return ''; }
  450:     if ($target) {
  451: 	$target=~s/\/[^\/]+$//;
  452:        $url=&Apache::lonnet::hreflocation($target,$url);
  453:     }
  454:     return $url;
  455: }
  456: 
  457: #########################################
  458: #########################################
  459: 
  460: =pod
  461: 
  462: =item B<set_allow>
  463: 
  464: Currently undocumented    
  465: 
  466: =cut
  467: 
  468: #########################################
  469: #########################################
  470: sub set_allow {
  471:     my ($allow,$logfile,$target,$tag,$oldurl)=@_;
  472:     my $newurl=&urlfixup($oldurl,$target);
  473:     my $return_url=$oldurl;
  474:     print $logfile 'GUYURL: '.$tag.':'.$oldurl.' - '.$newurl."\n";
  475:     if ($newurl ne $oldurl) {
  476: 	$return_url=$newurl;
  477: 	print $logfile 'URL: '.$tag.':'.$oldurl.' - '.$newurl."\n";
  478:     }
  479:     if (($newurl !~ /^javascript:/i) &&
  480: 	($newurl !~ /^mailto:/i) &&
  481: 	($newurl !~ /^(?:http|https|ftp):/i) &&
  482: 	($newurl !~ /^\#/)) {
  483: 	$$allow{&absoluteurl($newurl,$target)}=1;
  484:     }
  485:     return $return_url;
  486: }
  487: 
  488: #########################################
  489: #########################################
  490: 
  491: =pod
  492: 
  493: =item B<get_subscribed_hosts>
  494: 
  495: Currently undocumented    
  496: 
  497: =cut
  498: 
  499: #########################################
  500: #########################################
  501: sub get_subscribed_hosts {
  502:     my ($target)=@_;
  503:     my @subscribed;
  504:     my $filename;
  505:     $target=~/(.*)\/([^\/]+)$/;
  506:     my $srcf=$2;
  507:     opendir(DIR,$1);
  508:     # cycle through listed files, subscriptions used to exist
  509:     # as "filename.lonid"
  510:     while ($filename=readdir(DIR)) {
  511: 	if ($filename=~/\Q$srcf\E\.($match_lonid)$/) {
  512: 	    my $subhost=$1;
  513: 	    if (($subhost ne 'meta' 
  514: 		 && $subhost ne 'subscription' 
  515: 		 && $subhost ne 'meta.subscription'
  516: 		 && $subhost ne 'tmp') &&
  517:                 ($subhost ne $Apache::lonnet::perlvar{'lonHostID'})) {
  518: 		push(@subscribed,$subhost);
  519: 	    }
  520: 	}
  521:     }
  522:     closedir(DIR);
  523:     my $sh;
  524:     if ( $sh=Apache::File->new("$target.subscription") ) {
  525: 	while (my $subline=<$sh>) {
  526: 	    if ($subline =~ /^($match_lonid):/) { 
  527:                 if ($1 ne $Apache::lonnet::perlvar{'lonHostID'}) { 
  528:                    push(@subscribed,$1);
  529: 	        }
  530: 	    }
  531: 	}
  532:     }
  533:     return @subscribed;
  534: }
  535: 
  536: 
  537: #########################################
  538: #########################################
  539: 
  540: =pod
  541: 
  542: =item B<get_max_ids_indices>
  543: 
  544: Currently undocumented    
  545: 
  546: =cut
  547: 
  548: #########################################
  549: #########################################
  550: sub get_max_ids_indices {
  551:     my ($content)=@_;
  552:     my $maxindex=10;
  553:     my $maxid=10;
  554:     my $needsfixup=0;
  555:     my $duplicateids=0;
  556: 
  557:     my %allids;
  558:     my %duplicatedids;
  559: 
  560:     my $parser=HTML::LCParser->new($content);
  561:     $parser->xml_mode(1);
  562:     my $token;
  563:     while ($token=$parser->get_token) {
  564: 	if ($token->[0] eq 'S') {
  565: 	    my $counter;
  566: 	    if ($counter=$addid{$token->[1]}) {
  567: 		if ($counter eq 'id') {
  568: 		    if (defined($token->[2]->{'id'}) &&
  569: 			$token->[2]->{'id'} !~ /^\s*$/) {
  570: 			$maxid=($token->[2]->{'id'}>$maxid)?$token->[2]->{'id'}:$maxid;
  571: 			if (exists($allids{$token->[2]->{'id'}})) {
  572: 			    $duplicateids=1;
  573: 			    $duplicatedids{$token->[2]->{'id'}}=1;
  574: 			} else {
  575: 			    $allids{$token->[2]->{'id'}}=1;
  576: 			}
  577: 		    } else {
  578: 			$needsfixup=1;
  579: 		    }
  580: 		} else {
  581: 		    if (defined($token->[2]->{'index'}) &&
  582: 			$token->[2]->{'index'} !~ /^\s*$/) {
  583: 			$maxindex=($token->[2]->{'index'}>$maxindex)?$token->[2]->{'index'}:$maxindex;
  584: 		    } else {
  585: 			$needsfixup=1;
  586: 		    }
  587: 		}
  588: 	    }
  589: 	}
  590:     }
  591:     return ($needsfixup,$maxid,$maxindex,$duplicateids,
  592: 	    (keys(%duplicatedids)));
  593: }
  594: 
  595: #########################################
  596: #########################################
  597: 
  598: =pod
  599: 
  600: =item B<get_all_text_unbalanced>
  601: 
  602: Currently undocumented    
  603: 
  604: =cut
  605: 
  606: #########################################
  607: #########################################
  608: sub get_all_text_unbalanced {
  609:     #there is a copy of this in lonxml.pm
  610:     my($tag,$pars)= @_;
  611:     my $token;
  612:     my $result='';
  613:     $tag='<'.$tag.'>';
  614:     while ($token = $$pars[-1]->get_token) {
  615: 	if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
  616: 	    $result.=$token->[1];
  617: 	} elsif ($token->[0] eq 'PI') {
  618: 	    $result.=$token->[2];
  619: 	} elsif ($token->[0] eq 'S') {
  620: 	    $result.=$token->[4];
  621: 	} elsif ($token->[0] eq 'E')  {
  622: 	    $result.=$token->[2];
  623: 	}
  624: 	if ($result =~ /\Q$tag\E/s) {
  625: 	    ($result,my $redo)=$result =~ /(.*)\Q$tag\E(.*)/is;
  626: 	    #&Apache::lonnet::logthis('Got a winner with leftovers ::'.$2);
  627: 	    #&Apache::lonnet::logthis('Result is :'.$1);
  628: 	    $redo=$tag.$redo;
  629: 	    push (@$pars,HTML::LCParser->new(\$redo));
  630: 	    $$pars[-1]->xml_mode('1');
  631: 	    last;
  632: 	}
  633:     }
  634:     return $result
  635: }
  636: 
  637: #########################################
  638: #########################################
  639: 
  640: =pod
  641: 
  642: =item B<fix_ids_and_indices>
  643: 
  644: Currently undocumented    
  645: 
  646: =cut
  647: 
  648: #########################################
  649: #########################################
  650: #Arguably this should all be done as a lonnet::ssi instead
  651: sub fix_ids_and_indices {
  652:     my ($logfile,$source,$target)=@_;
  653: 
  654:     my %allow;
  655:     my $content;
  656:     {
  657: 	my $org=Apache::File->new($source);
  658: 	$content=join('',<$org>);
  659:     }
  660: 
  661:     my ($needsfixup,$maxid,$maxindex,$duplicateids,@duplicatedids)=
  662: 	&get_max_ids_indices(\$content);
  663: 
  664:     print $logfile ("Got $needsfixup,$maxid,$maxindex,$duplicateids--".
  665: 			   join(', ',@duplicatedids));
  666:     if ($duplicateids) {
  667: 	print $logfile "Duplicate ID(s) exist, ".join(', ',@duplicatedids)."\n";
  668: 	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>';
  669: 	return ($outstring,1);
  670:     }
  671:     if ($needsfixup) {
  672: 	print $logfile "Needs ID and/or index fixup\n".
  673: 	    "Max ID   : $maxid (min 10)\n".
  674:                 "Max Index: $maxindex (min 10)\n";
  675:     }
  676:     my $outstring='';
  677:     my $responsecounter=1;
  678:     my @parser;
  679:     $parser[0]=HTML::LCParser->new(\$content);
  680:     $parser[-1]->xml_mode(1);
  681:     my $token;
  682:     while (@parser) {
  683: 	while ($token=$parser[-1]->get_token) {
  684: 	    if ($token->[0] eq 'S') {
  685: 		my $counter;
  686: 		my $tag=$token->[1];
  687: 		my $lctag=lc($tag);
  688: 		if ($lctag eq 'allow') {
  689: 		    $allow{$token->[2]->{'src'}}=1;
  690: 		    next;
  691: 		}
  692: 		if ($lctag eq 'base') { next; }
  693:                 if (($lctag eq 'part') || ($lctag eq 'problem')) {
  694:                     $responsecounter=0;
  695:                 }
  696:                 if ($lctag=~/response$/) { $responsecounter++; }
  697:                 if ($lctag eq 'import') { $responsecounter++; }
  698: 		my %parms=%{$token->[2]};
  699: 		$counter=$addid{$tag};
  700: 		if (!$counter) { $counter=$addid{$lctag}; }
  701: 		if ($counter) {
  702: 		    if ($counter eq 'id') {
  703: 			unless (defined($parms{'id'}) &&
  704: 				$parms{'id'}!~/^\s*$/) {
  705: 			    $maxid++;
  706: 			    $parms{'id'}=$maxid;
  707: 			    print $logfile 'ID(new) : '.$tag.':'.$maxid."\n";
  708: 			} else {
  709: 			    print $logfile 'ID(kept): '.$tag.':'.$parms{'id'}."\n";
  710: 			}
  711: 		    } elsif ($counter eq 'index') {
  712: 			unless (defined($parms{'index'}) &&
  713: 				$parms{'index'}!~/^\s*$/) {
  714: 			    $maxindex++;
  715: 			    $parms{'index'}=$maxindex;
  716: 			    print $logfile 'Index: '.$tag.':'.$maxindex."\n";
  717: 			}
  718: 		    }
  719: 		}
  720:                 unless ($parms{'type'} eq 'zombie') {
  721: 		    foreach my $type ('src','href','background','bgimg') {
  722: 			foreach my $key (keys(%parms)) {
  723: 			    if ($key =~ /^$type$/i) {
  724: 				$parms{$key}=&set_allow(\%allow,$logfile,
  725: 							$target,$tag,
  726: 							$parms{$key});
  727: 			    }
  728: 			}
  729: 		    }
  730: 		}
  731: 		# probably a <randomlabel> image type <label>
  732: 		# or a <image> tag inside <imageresponse>
  733: 		if (($lctag eq 'label' && defined($parms{'description'}))
  734: 		    ||
  735: 		    ($lctag eq 'image')) {
  736: 		    my $next_token=$parser[-1]->get_token();
  737: 		    if ($next_token->[0] eq 'T') {
  738:                         $next_token->[1] =~ s/[\n\r\f]+//g;
  739: 			$next_token->[1]=&set_allow(\%allow,$logfile,
  740: 						    $target,$tag,
  741: 						    $next_token->[1]);
  742: 		    }
  743: 		    $parser[-1]->unget_token($next_token);
  744: 		}
  745: 		if ($lctag eq 'applet') {
  746: 		    my $codebase='';
  747: 		    my $havecodebase=0;
  748: 		    foreach my $key (keys(%parms)) {
  749: 			if (lc($key) eq 'codebase') { 
  750: 			    $codebase=$parms{$key};
  751: 			    $havecodebase=1; 
  752: 			}
  753: 		    }
  754: 		    if ($havecodebase) {
  755: 			my $oldcodebase=$codebase;
  756: 			unless ($oldcodebase=~/\/$/) {
  757: 			    $oldcodebase.='/';
  758: 			}
  759: 			$codebase=&urlfixup($oldcodebase,$target);
  760: 			$codebase=~s/\/$//;    
  761: 			if ($codebase ne $oldcodebase) {
  762: 			    $parms{'codebase'}=$codebase;
  763: 			    print $logfile 'URL codebase: '.$tag.':'.
  764: 				$oldcodebase.' - '.
  765: 				    $codebase."\n";
  766: 			}
  767: 			$allow{&absoluteurl($codebase,$target).'/*'}=1;
  768: 		    } else {
  769: 			foreach my $key (keys(%parms)) {
  770: 			    if ($key =~ /(archive|code|object)/i) {
  771: 				my $oldurl=$parms{$key};
  772: 				my $newurl=&urlfixup($oldurl,$target);
  773: 				$newurl=~s/\/[^\/]+$/\/\*/;
  774: 				print $logfile 'Allow: applet '.lc($key).':'.
  775: 				    $oldurl.' allows '.$newurl."\n";
  776: 				$allow{&absoluteurl($newurl,$target)}=1;
  777: 			    }
  778: 			}
  779: 		    }
  780: 		}
  781: 		my $newparmstring='';
  782: 		my $endtag='';
  783: 		foreach (keys %parms) {
  784: 		    if ($_ eq '/') {
  785: 			$endtag=' /';
  786: 		    } else { 
  787: 			my $quote=($parms{$_}=~/\"/?"'":'"');
  788: 			$newparmstring.=' '.$_.'='.$quote.$parms{$_}.$quote;
  789: 		    }
  790: 		}
  791: 		if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
  792: 		$outstring.='<'.$tag.$newparmstring.$endtag.'>';
  793: 		if ($lctag eq 'm' || $lctag eq 'script' || $lctag eq 'answer' 
  794:                     || $lctag eq 'display' || $lctag eq 'tex') {
  795: 		    $outstring.=&get_all_text_unbalanced('/'.$lctag,\@parser);
  796: 		}
  797: 	    } elsif ($token->[0] eq 'E') {
  798: 		if ($token->[2]) {
  799: 		    unless ($token->[1] eq 'allow') {
  800: 			$outstring.='</'.$token->[1].'>';
  801: 		    }
  802:                 }
  803:                 if ((($token->[1] eq 'part') || ($token->[1] eq 'problem'))
  804:                     && (!$responsecounter)) {
  805:                     my $outstring='<span class="LC_error">'.&mt('Found [_1] without responses. This resource cannot be published.',$token->[1]).'</span>';
  806:                     return ($outstring,1);
  807:                 }
  808: 	    } else {
  809: 		$outstring.=$token->[1];
  810: 	    }
  811: 	}
  812: 	pop(@parser);
  813:     }
  814: 
  815:     if ($needsfixup) {
  816: 	print $logfile "End of ID and/or index fixup\n".
  817: 	    "Max ID   : $maxid (min 10)\n".
  818: 		"Max Index: $maxindex (min 10)\n";
  819:     } else {
  820: 	print $logfile "Does not need ID and/or index fixup\n";
  821:     }
  822: 
  823:     return ($outstring,0,%allow);
  824: }
  825: 
  826: #########################################
  827: #########################################
  828: 
  829: =pod
  830: 
  831: =item B<store_metadata>
  832: 
  833: Store the metadata in the metadata table in the loncapa database.
  834: Uses lonmysql to access the database.
  835: 
  836: Inputs: \%metadata
  837: 
  838: Returns: (error,status).  error is undef on success, status is undef on error.
  839: 
  840: =cut
  841: 
  842: #########################################
  843: #########################################
  844: sub store_metadata {
  845:     my %metadata = @_;
  846:     my $error;
  847:     # Determine if the table exists
  848:     my $status = &Apache::lonmysql::check_table('metadata');
  849:     if (! defined($status)) {
  850:         $error='<span class="LC_error">'
  851:               .&mt('WARNING: Cannot connect to database!')
  852:               .'</span>';
  853:         &Apache::lonnet::logthis($error);
  854:         return ($error,undef);
  855:     }
  856:     if ($status == 0) {
  857:         # It would be nice to actually create the table....
  858:         $error ='<span class="LC_error">'
  859:                .&mt('WARNING: The metadata table does not exist in the LON-CAPA database!')
  860:                .'</span>';
  861:         &Apache::lonnet::logthis($error);
  862:         return ($error,undef);
  863:     }
  864:     my $dbh = &Apache::lonmysql::get_dbh();
  865:     if (($metadata{'obsolete'}) || ($metadata{'copyright'} eq 'priv')) {
  866:         # remove this entry
  867: 	my $delitem = 'url = '.$dbh->quote($metadata{'url'});
  868: 	$status = &LONCAPA::lonmetadata::delete_metadata($dbh,undef,$delitem);
  869:                                                        
  870:     } else {
  871:         $status = &LONCAPA::lonmetadata::update_metadata($dbh,undef,undef,
  872:                                                          \%metadata);
  873:     }
  874:     if (defined($status) && $status ne '') {
  875:         $error='<span class="LC_error">'
  876:               .&mt('Error occurred saving new values in metadata table in LON-CAPA database!')
  877:               .'</span>';
  878:         &Apache::lonnet::logthis($error);
  879:         &Apache::lonnet::logthis($status);
  880:         return ($error,undef);
  881:     }
  882:     return (undef,'success');
  883: }
  884: 
  885: 
  886: # ========================================== Parse file for errors and warnings
  887: 
  888: sub checkonthis {
  889:     my ($r,$source)=@_;
  890:     my $uri=&Apache::lonnet::hreflocation($source);
  891:     $uri=~s/\/$//;
  892:     my $result=&Apache::lonnet::ssi_body($uri,
  893: 					 ('grade_target'=>'web',
  894: 					  'return_only_error_and_warning_counts' => 1));
  895:     my ($errorcount,$warningcount)=split(':',$result);
  896:     if (($errorcount) || ($warningcount)) {
  897:         $r->print('<h3>'.&mt('Warnings and Errors').'</h3>');
  898:         $r->print('<tt>'.$uri.'</tt>:');
  899:         $r->print('<ul>');
  900:         if ($warningcount) {
  901:             $r->print('<li><div class="LC_warning">'
  902:                      .&mt('[quant,_1,warning]',$warningcount)
  903:                      .'</div></li>');
  904:         }
  905:         if ($errorcount) {
  906:             $r->print('<li><div class="LC_error">'
  907:                      .&mt('[quant,_1,error]',$errorcount)
  908:                      .' <img src="/adm/lonMisc/bomb.gif" />'
  909:                      .'</div></li>');
  910:         }
  911:         $r->print('</ul>');
  912:     } else {
  913: 	#$r->print('<font color="green">'.&mt('ok').'</font>');
  914:     }
  915:     $r->rflush();
  916:     return ($warningcount,$errorcount);
  917: }
  918: 
  919: # ============================================== Parse file itself for metadata
  920: #
  921: # parses a file with target meta, sets global %metadatafields %metadatakeys 
  922: 
  923: sub parseformeta {
  924:     my ($source,$style)=@_;
  925:     my $allmeta='';
  926:     if (($style eq 'ssi') || ($style eq 'prv')) {
  927: 	my $dir=$source;
  928: 	$dir=~s-/[^/]*$--;
  929: 	my $file=$source;
  930: 	$file=(split('/',$file))[-1];
  931:         $source=&Apache::lonnet::hreflocation($dir,$file);
  932: 	$allmeta=&Apache::lonnet::ssi_body($source,('grade_target' => 'meta'));
  933:         &metaeval($allmeta);
  934:     }
  935:     return $allmeta;
  936: }
  937: 
  938: #########################################
  939: #########################################
  940: 
  941: =pod
  942: 
  943: =item B<publish>
  944: 
  945: This is the workhorse function of this module.  This subroutine generates
  946: backup copies, performs any automatic processing (prior to publication,
  947: especially for rat and ssi files),
  948: 
  949: Returns a 2 element array, the first is the string to be shown to the
  950: user, the second is an error code, either 1 (an error occurred) or 0
  951: (no error occurred)
  952: 
  953: I<Additional documentation needed.>
  954: 
  955: =cut
  956: 
  957: #########################################
  958: #########################################
  959: sub publish {
  960: 
  961:     my ($source,$target,$style,$batch)=@_;
  962:     my $logfile;
  963:     my $scrout='';
  964:     my $allmeta='';
  965:     my $content='';
  966:     my %allow=();
  967: 
  968:     unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
  969: 	return ('<span class="LC_error">'.&mt('No write permission to user directory, FAIL').'</span>',1);
  970:     }
  971:     print $logfile 
  972: "\n\n================= Publish ".localtime()." Phase One  ================\n".$env{'user.name'}.':'.$env{'user.domain'}."\n";
  973: 
  974:     if (($style eq 'ssi') || ($style eq 'rat') || ($style eq 'prv')) {
  975: # ------------------------------------------------------- This needs processing
  976: 
  977: # ----------------------------------------------------------------- Backup Copy
  978: 	my $copyfile=$source.'.save';
  979:         if (copy($source,$copyfile)) {
  980: 	    print $logfile "Copied original file to ".$copyfile."\n";
  981:         } else {
  982: 	    print $logfile "Unable to write backup ".$copyfile.':'.$!."\n";
  983: 	    return ("<span class=\"LC_error\">".&mt("Failed to write backup copy, [_1], FAIL",$1)."</span>",1);
  984:         }
  985: # ------------------------------------------------------------- IDs and indices
  986: 	
  987: 	my ($outstring,$error);
  988: 	($outstring,$error,%allow)=&fix_ids_and_indices($logfile,$source,
  989: 							$target);
  990: 	if ($error) { return ($outstring,$error); }
  991: # ------------------------------------------------------------ Construct Allows
  992:     
  993:         my $outdep=''; # Collect dependencies output data
  994:         my $allowstr='';
  995:         foreach my $thisdep (sort(keys(%allow))) {
  996: 	   if ($thisdep !~ /[^\s]/) { next; }
  997:            if ($thisdep =~/\$/) {
  998:               $outdep.='<div class="LC_warning">'
  999:                        .&mt('The resource depends on another resource with variable filename, i.e., [_1].','<tt>'.$thisdep.'</tt>').'<br />'
 1000:                        .&mt('You likely need to explicitly allow access to all possible dependencies using the [_1]-tag.','<tt>&lt;allow&gt;</tt>')
 1001:                        ."</div>\n";
 1002:            }
 1003:            unless ($style eq 'rat') { 
 1004:               $allowstr.="\n".'<allow src="'.$thisdep.'" />';
 1005: 	   }
 1006:           $outdep.='<div>';
 1007:            if ($thisdep!~/[\*\$]/ && $thisdep!~m|^/adm/|) {
 1008: 	       $outdep.='<a href="'.$thisdep.'">';
 1009:            }
 1010:            $outdep.='<tt>'.$thisdep.'</tt>';
 1011:            if ($thisdep!~/[\*\$]/ && $thisdep!~m|^/adm/|) {
 1012: 	       $outdep.='</a>';
 1013:                if (
 1014:        &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
 1015:                                             $thisdep.'.meta') eq '-1') {
 1016: 		   $outdep.= ' - <span class="LC_error">'.&mt('Currently not available').
 1017: 		       '</span>';
 1018:                } else {
 1019: #
 1020: # Store the fact that the dependency has been used by the target file
 1021: # Unfortunately, usage is erroneously named sequsage in lonmeta.pm
 1022: # The translation happens in lonmetadata.pm
 1023: #
 1024:                    my %temphash=(&Apache::lonnet::declutter($target).'___'.
 1025:                              &Apache::lonnet::declutter($thisdep).'___usage'
 1026:                                  => time);
 1027:                    $thisdep=~m{^/res/($match_domain)/($match_username)/};
 1028:                    if ((defined($1)) && (defined($2))) {
 1029:                       &Apache::lonnet::put('nohist_resevaldata',\%temphash,
 1030: 					   $1,$2);
 1031: 		   }
 1032: 	       }
 1033:            }
 1034:            $outdep.='</div><br />';
 1035:         }
 1036: 
 1037:         if ($outdep) {
 1038:             $scrout.='<h3>'.&mt('Dependencies').'</h3>'
 1039:                     .$outdep
 1040:         }
 1041:         $outstring=~s/\n*(\<\/[^\>]+\>[^<]*)$/$allowstr\n$1\n/s;
 1042: 
 1043: # ------------------------------------------------------------- Write modified.
 1044: 
 1045:         {
 1046:           my $org;
 1047:           unless ($org=Apache::File->new('>'.$source)) {
 1048:              print $logfile "No write permit to $source\n";
 1049:              return ('<span class="LC_error">'.&mt('No write permission to').
 1050: 		     ' '.$source.
 1051: 		     ', '.&mt('FAIL').'</span>',1);
 1052: 	  }
 1053:           print($org $outstring);
 1054:         }
 1055: 	  $content=$outstring;
 1056: 
 1057:     }
 1058: # -------------------------------------------- Initial step done, now metadata.
 1059: 
 1060: # --------------------------------------- Storage for metadata keys and fields.
 1061: # these are globals
 1062: #
 1063:      %metadatafields=();
 1064:      %metadatakeys=();
 1065:      
 1066:      my %oldparmstores=();
 1067:      
 1068:     unless ($batch) {
 1069:      $scrout.='<h3>'.&mt('Metadata').' ' .
 1070:        &Apache::loncommon::help_open_topic("Metadata_Description")
 1071:        . '</h3>';
 1072:     }
 1073: 
 1074: # ------------------------------------------------ First, check out environment
 1075:      if ((!(-e $source.'.meta')) || ($env{'form.forceoverride'})) {
 1076:         $metadatafields{'author'}=$env{'environment.firstname'}.' '.
 1077: 	                          $env{'environment.middlename'}.' '.
 1078: 		                  $env{'environment.lastname'}.' '.
 1079: 		                  $env{'environment.generation'};
 1080:         $metadatafields{'author'}=~s/\s+/ /g;
 1081:         $metadatafields{'author'}=~s/\s+$//;
 1082:         $metadatafields{'owner'}=$cuname.':'.$cudom;
 1083: 
 1084: # ------------------------------------------------ Check out directory hierachy
 1085: 
 1086:         my $thisdisfn=$source;
 1087: 
 1088:         $thisdisfn=~s/^\Q$docroot\E\/priv\/\Q$cudom\E\/\Q$cuname\E\///;
 1089:         my @urlparts=('.',split(/\//,$thisdisfn));
 1090:         $#urlparts--;
 1091: 
 1092:         my $currentpath=$docroot.'/priv/'.$cudom.'/'.$cuname.'/';
 1093: 
 1094: 	my $prefix='../'x($#urlparts);
 1095:         foreach my $subdir (@urlparts) {
 1096: 	    $currentpath.=$subdir.'/';
 1097:             $scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix);
 1098: 	    $prefix=~s|^\.\./||;
 1099:         }
 1100: 
 1101: # ----------------------------------------------------------- Parse file itself
 1102: # read %metadatafields from file itself
 1103:  
 1104: 	$allmeta=&parseformeta($source,$style);
 1105: 
 1106: # ------------------- Clear out parameters and stores (there should not be any)
 1107: 
 1108:         foreach (keys %metadatafields) {
 1109: 	    if (($_=~/^parameter/) || ($_=~/^stores/)) {
 1110: 		delete $metadatafields{$_};
 1111:             }
 1112:         }
 1113: 
 1114:     } else {
 1115: # ---------------------- Read previous metafile, remember parameters and stores
 1116: 
 1117:         $scrout.=&metaread($logfile,$source.'.meta');
 1118: 
 1119:         foreach (keys %metadatafields) {
 1120: 	    if (($_=~/^parameter/) || ($_=~/^stores/)) {
 1121:                 $oldparmstores{$_}=1;
 1122: 		delete $metadatafields{$_};
 1123:             }
 1124:         }
 1125: # ------------------------------------------------------------- Save some stuff
 1126:         my %savemeta=();
 1127:         foreach ('title') {
 1128:             if ($metadatafields{$_}) { $savemeta{$_}=$metadatafields{$_}; }
 1129: 	}
 1130: # ------------------------------------------ See if anything new in file itself
 1131:  
 1132: 	$allmeta=&parseformeta($source,$style);
 1133: # ----------------------------------------------------------- Restore the stuff
 1134:         foreach (keys %savemeta) {
 1135: 	    $metadatafields{$_}=$savemeta{$_};
 1136: 	}
 1137:    }
 1138: 
 1139:        
 1140: # ---------------- Find and document discrepancies in the parameters and stores
 1141: 
 1142:     my $chparms='';
 1143:     foreach (sort keys %metadatafields) {
 1144: 	if (($_=~/^parameter/) || ($_=~/^stores/)) {
 1145: 	    unless ($_=~/\.\w+$/) { 
 1146: 		unless ($oldparmstores{$_}) {
 1147: 		    my $disp_key = $_;
 1148: 		    $disp_key =~ tr/\0/_/;
 1149: 		    print $logfile ('New: '.$disp_key."\n");
 1150: 		    $chparms .= $disp_key.' ';
 1151: 		}
 1152: 	    }
 1153: 	}
 1154:     }
 1155:     if ($chparms) {
 1156: 	$scrout.='<p><b>'.&mt('New parameters or saved values').
 1157: 	    ':</b> '.$chparms.'</p>';
 1158:     }
 1159: 
 1160:     $chparms='';
 1161:     foreach (sort keys %oldparmstores) {
 1162: 	if (($_=~/^parameter/) || ($_=~/^stores/)) {
 1163: 	    unless (($metadatafields{$_.'.name'}) ||
 1164: 		    ($metadatafields{$_.'.package'}) || ($_=~/\.\w+$/)) {
 1165: 		my $disp_key = $_;
 1166: 		$disp_key =~ tr/\0/_/;
 1167: 		print $logfile ('Obsolete: '.$disp_key."\n");
 1168: 		$chparms.=$disp_key.' ';
 1169: 	    }
 1170: 	}
 1171:     }
 1172:     if ($chparms) {
 1173:         $scrout.='<p><b>'.&mt('Obsolete parameters or saved values').':</b> '
 1174: 	        .$chparms.'</p>'
 1175:                 .'<p class="LC_warning"><b>'.&mt('Warning!').'</b><br />'
 1176:                 .&mt('If this resource is in active use, student performance data from the previous version may become inaccessible.')
 1177:                 .'</p><hr />';
 1178:     }
 1179:     if ($metadatafields{'copyright'} eq 'priv') {
 1180:         $scrout.='<p class="LC_warning"><b>'.&mt('Warning!').'</b><br />'
 1181:                 .&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.')
 1182:                 .'</p><hr />';
 1183:     }
 1184: 
 1185: # ------------------------------------------------------- Now have all metadata
 1186: 
 1187:     my %keywords=();
 1188:         
 1189:     if (length($content)<500000) {
 1190: 	my $textonly=$content;
 1191: 	$textonly=~s/\<script[^\<]+\<\/script\>//g;
 1192: 	$textonly=~s/\<m\>[^\<]+\<\/m\>//g;
 1193: 	$textonly=~s/\<[^\>]*\>//g;
 1194: 
 1195:         #this is a work simplification for german authors for present
 1196:         $textonly=HTML::Entities::decode($textonly);           #decode HTML-character
 1197:         $textonly=Encode::Encoder::encode('utf8', $textonly);  #encode to perl internal unicode
 1198:         $textonly=~tr/A-ZÜÄÖ/a-züäö/;      #add lowercase rule for german "Umlaute"
 1199:         $textonly=~s/[\$\&][a-z]\w*//g;
 1200:         $textonly=~s/[^a-z^ü^ä^ö^ß\s]//g;  #dont delete german "Umlaute"
 1201: 
 1202:         foreach ($textonly=~m/[^\s]+/g) {  #match all but whitespaces
 1203:             unless ($nokey{$_}) {
 1204:                 $keywords{$_}=1;
 1205:             }
 1206:         }
 1207: 
 1208: 
 1209:     }
 1210:             
 1211:     foreach my $addkey (split(/[\"\'\,\;]/,$metadatafields{'keywords'})) {
 1212: 	$addkey=~s/\s+/ /g;
 1213: 	$addkey=~s/^\s//;
 1214: 	$addkey=~s/\s$//;
 1215: 	if ($addkey=~/\w/) {
 1216: 	    $keywords{$addkey}=1;
 1217: 	}
 1218:     }
 1219: # --------------------------------------------------- Now we also have keywords
 1220: # =============================================================================
 1221: # interactive mode html goes into $intr_scrout
 1222: # batch mode throws away this HTML
 1223: # additionally all of the field functions have a by product of setting
 1224: #   $env{'from.'..} so that it can be used by the phase two handler in
 1225: #    batch mode
 1226: 
 1227:     my $intr_scrout.='<br />'
 1228:                     .'<form name="pubform" action="/adm/publish" method="post">';
 1229:     unless ($env{'form.makeobsolete'}) {
 1230:        $intr_scrout.='<p class="LC_warning">'
 1231:                     .&mt('Searching for your resource will be based on the following metadata. Please provide as much data as possible.')
 1232:                     .'</p>'
 1233:                     .'<p><input type="submit" value="'
 1234:                     .&mt('Finalize Publication')
 1235:                     .'" /> <a href="'.&Apache::loncfile::url($source).'">'.&mt('Cancel').'</a></p>';
 1236:     }
 1237:     $intr_scrout.=&Apache::lonhtmlcommon::start_pick_box();
 1238:     $intr_scrout.=
 1239: 	&hiddenfield('phase','two').
 1240: 	&hiddenfield('filename',$env{'form.filename'}).
 1241: 	&hiddenfield('allmeta',&escape($allmeta)).
 1242: 	&hiddenfield('dependencies',join(',',keys %allow));
 1243:     unless ($env{'form.makeobsolete'}) {
 1244:        $intr_scrout.=
 1245: 	&textfield('Title','title',$metadatafields{'title'}).
 1246: 	&textfield('Author(s)','author',$metadatafields{'author'}).
 1247: 	&textfield('Subject','subject',$metadatafields{'subject'});
 1248:  # --------------------------------------------------- Scan content for keywords
 1249: 
 1250:     my $keywords_help = &Apache::loncommon::help_open_topic("Publishing_Keywords");
 1251:     my $keywordout=<<"END";
 1252: <script>
 1253: function checkAll(field) {
 1254:     for (i = 0; i < field.length; i++)
 1255:         field[i].checked = true ;
 1256: }
 1257: 
 1258: function uncheckAll(field) {
 1259:     for (i = 0; i < field.length; i++)
 1260:         field[i].checked = false ;
 1261: }
 1262: </script>
 1263: END
 1264:     $keywordout.="\n".&Apache::lonhtmlcommon::row_title(&mt('Keywords'))
 1265:                 .$keywords_help
 1266:                 .'<input type="button" value="'.&mt('check all').'" onclick="javascript:checkAll(document.pubform.keywords)" />'
 1267:                 .'<input type="button" value="'.&mt('uncheck all').'" onclick="javascript:uncheckAll(document.pubform.keywords)" />'
 1268:                 .'</p><br />'
 1269:                 .&Apache::loncommon::start_data_table();
 1270:     my $cols_per_row = 10;
 1271:     my $colcount=0;
 1272:     my $wordcount=0;
 1273:     my $numkeywords = scalar(keys(%keywords));
 1274: 
 1275:     foreach my $word (sort(keys(%keywords))) {
 1276:         if ($colcount == 0) {
 1277:             $keywordout .= &Apache::loncommon::start_data_table_row();
 1278:         }
 1279:         $colcount++;
 1280:         $wordcount++;
 1281:         if (($wordcount == $numkeywords) && ($colcount < $cols_per_row)) {
 1282:             my $colspan = 1+$cols_per_row-$colcount;
 1283:             $keywordout .= '<td colspan="'.$colspan.'">';
 1284:         } else {
 1285:             $keywordout .= '<td>';
 1286:         }
 1287:         $keywordout.='<label><input type="checkbox" name="keywords" value="'.$word.'"';
 1288:         if ($metadatafields{'keywords'}) {
 1289:             if ($metadatafields{'keywords'}=~/\Q$word\E/) {
 1290:                 $keywordout.=' checked="checked"';
 1291:                 $env{'form.keywords'}.=$word.',';
 1292:             }
 1293:         } elsif (&Apache::loncommon::keyword($word)) {
 1294:             $keywordout.=' checked="checked"';
 1295:             $env{'form.keywords'}.=$word.',';
 1296:         }
 1297:         $keywordout.=' />'.$word.'</label></td>';
 1298:         if ($colcount == $cols_per_row) {
 1299:             $keywordout.=&Apache::loncommon::end_data_table_row();
 1300:             $colcount=0;
 1301:         }
 1302:     }
 1303:     if ($colcount > 0) {
 1304:         $keywordout .= &Apache::loncommon::end_data_table_row();
 1305:     }
 1306: 
 1307:     $env{'form.keywords'}=~s/\,$//;
 1308: 
 1309:     $keywordout.=&Apache::loncommon::end_data_table_row()
 1310:                  .&Apache::loncommon::end_data_table()
 1311:                  .&Apache::lonhtmlcommon::row_closure();
 1312: 
 1313:     $intr_scrout.=$keywordout;
 1314: 
 1315:     $intr_scrout.=&textfield('Additional Keywords','addkey','');
 1316: 
 1317:     $intr_scrout.=&textfield('Notes','notes',$metadatafields{'notes'});
 1318: 
 1319:     $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title(&mt('Abstract'))
 1320:                  .'<textarea cols="80" rows="5" name="abstract">'
 1321:                  .$metadatafields{'abstract'}
 1322:                  .'</textarea>'
 1323:                  .&Apache::lonhtmlcommon::row_closure();
 1324: 
 1325:     $source=~/\.(\w+)$/;
 1326: 
 1327:     $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title(&mt('Grade Levels'))
 1328:                  .&mt('Lowest Grade Level:').'&nbsp;'
 1329:                  .&select_level_form($metadatafields{'lowestgradelevel'},'lowestgradelevel')
 1330: #                .&Apache::lonhtmlcommon::row_closure();
 1331: #   $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title(&mt('Highest Grade Level'))
 1332:                  .' '.&mt('Highest Grade Level:').'&nbsp;'
 1333:                  .&select_level_form($metadatafields{'highestgradelevel'},'highestgradelevel')
 1334:                  .&Apache::lonhtmlcommon::row_closure();
 1335: 
 1336:     $intr_scrout.=&textfield('Standards','standards',$metadatafields{'standards'});
 1337: 
 1338:     $intr_scrout.=&hiddenfield('mime',$1);
 1339: 
 1340:     my $defaultlanguage=$metadatafields{'language'};
 1341:     $defaultlanguage =~ s/\s*notset\s*//g;
 1342:     $defaultlanguage =~ s/^,\s*//g;
 1343:     $defaultlanguage =~ s/,\s*$//g;
 1344: 
 1345:     $intr_scrout.=&selectbox('Language','language',
 1346: 			     $defaultlanguage,
 1347: 			     \&Apache::loncommon::languagedescription,
 1348: 			     (&Apache::loncommon::languageids),
 1349: 			     );
 1350: 
 1351:     unless ($metadatafields{'creationdate'}) {
 1352: 	$metadatafields{'creationdate'}=time;
 1353:     }
 1354:     $intr_scrout.=&hiddenfield('creationdate',
 1355: 			       &Apache::lonmysql::unsqltime($metadatafields{'creationdate'}));
 1356: 
 1357:     $intr_scrout.=&hiddenfield('lastrevisiondate',time);
 1358: 
 1359:     my $pubowner_last;
 1360:     if ($style eq 'prv') {
 1361:         $pubowner_last = 1;
 1362:     }
 1363:     $intr_scrout.=&textfield('Publisher/Owner','owner',
 1364: 			     $metadatafields{'owner'},$pubowner_last);
 1365: 
 1366: # ---------------------------------------------- Retrofix for unused copyright
 1367:     if ($metadatafields{'copyright'} eq 'free') {
 1368: 	$metadatafields{'copyright'}='default';
 1369: 	$metadatafields{'sourceavail'}='open';
 1370:     }
 1371:     if ($metadatafields{'copyright'} eq 'priv') {
 1372:         $metadatafields{'copyright'}='domain';
 1373:     }
 1374: # ------------------------------------------------ Dial in reasonable defaults
 1375:     my $defaultoption=$metadatafields{'copyright'};
 1376:     unless ($defaultoption) { $defaultoption='default'; }
 1377:     my $defaultsourceoption=$metadatafields{'sourceavail'};
 1378:     unless ($defaultsourceoption) { $defaultsourceoption='closed'; }
 1379:     unless ($style eq 'prv') {
 1380: # -------------------------------------------------- Correct copyright for rat.
 1381: 	if ($style eq 'rat') {
 1382: # -------------------------------------- Retrofix for non-applicable copyright
 1383: 	    if ($metadatafields{'copyright'} eq 'public') { 
 1384: 		delete $metadatafields{'copyright'};
 1385: 		$defaultoption='default';
 1386: 	    }
 1387: 	    $intr_scrout.=&selectbox('Copyright/Distribution','copyright',
 1388: 				     $defaultoption,
 1389: 				     \&Apache::loncommon::copyrightdescription,
 1390: 				    (grep !/^(public|priv)$/,(&Apache::loncommon::copyrightids)));
 1391: 	} else {
 1392: 	    $intr_scrout.=&selectbox('Copyright/Distribution','copyright',
 1393: 				     $defaultoption,
 1394: 				     \&Apache::loncommon::copyrightdescription,
 1395: 				     (grep !/^priv$/,(&Apache::loncommon::copyrightids)));
 1396: 	}
 1397: 	my $copyright_help =
 1398: 	    &Apache::loncommon::help_open_topic('Publishing_Copyright');
 1399:         my $replace=&mt('Copyright/Distribution:');
 1400: 	$intr_scrout =~ s/$replace/$replace.' '.$copyright_help/ge;
 1401: 
 1402: 	$intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights');
 1403: 	$intr_scrout.=&selectbox('Source Distribution','sourceavail',
 1404: 				 $defaultsourceoption,
 1405: 				 \&Apache::loncommon::source_copyrightdescription,
 1406: 				 (&Apache::loncommon::source_copyrightids));
 1407: #	$intr_scrout.=&text_with_browse_field('Source Custom Distribution File','sourcerights',$metadatafields{'sourcerights'},'rights');
 1408: 	my $uctitle=&mt('Obsolete');
 1409:         my $obsolete_checked=($metadatafields{'obsolete'})?' checked="checked"':'';
 1410:         $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title($uctitle)
 1411:                      .'<input type="checkbox" name="obsolete"'.$obsolete_checked.' />'
 1412:                      .&Apache::lonhtmlcommon::row_closure(1);
 1413:         $intr_scrout.=&text_with_browse_field('Suggested Replacement for Obsolete File',
 1414: 				    'obsoletereplacement',
 1415: 				    $metadatafields{'obsoletereplacement'},'',1);
 1416:     } else {
 1417: 	$intr_scrout.=&hiddenfield('copyright','private');
 1418:     }
 1419:    } else {
 1420:        $intr_scrout.=
 1421: 	&hiddenfield('title',$metadatafields{'title'}).
 1422: 	&hiddenfield('author',$metadatafields{'author'}).
 1423: 	&hiddenfield('subject',$metadatafields{'subject'}).
 1424: 	&hiddenfield('keywords',$metadatafields{'keywords'}).
 1425: 	&hiddenfield('abstract',$metadatafields{'abstract'}).
 1426: 	&hiddenfield('notes',$metadatafields{'notes'}).
 1427: 	&hiddenfield('mime',$metadatafields{'mime'}).
 1428: 	&hiddenfield('creationdate',$metadatafields{'creationdate'}).
 1429: 	&hiddenfield('lastrevisiondate',time).
 1430: 	&hiddenfield('owner',$metadatafields{'owner'}).
 1431: 	&hiddenfield('lowestgradelevel',$metadatafields{'lowestgradelevel'}).
 1432: 	&hiddenfield('standards',$metadatafields{'standards'}).
 1433: 	&hiddenfield('highestgradelevel',$metadatafields{'highestgradelevel'}).
 1434: 	&hiddenfield('language',$metadatafields{'language'}).
 1435: 	&hiddenfield('copyright',$metadatafields{'copyright'}).
 1436: 	&hiddenfield('sourceavail',$metadatafields{'sourceavail'}).
 1437: 	&hiddenfield('customdistributionfile',$metadatafields{'customdistributionfile'}).
 1438: 	&hiddenfield('obsolete',1).
 1439: 	&text_with_browse_field('Suggested Replacement for Obsolete File',
 1440: 				    'obsoletereplacement',
 1441: 				    $metadatafields{'obsoletereplacement'},'',1);
 1442:    }
 1443:     if (!$batch) {
 1444: 	$scrout.=$intr_scrout
 1445:             .&Apache::lonhtmlcommon::end_pick_box()
 1446:             .'<p><input type="submit" value="'
 1447: 	    .&mt($env{'form.makeobsolete'}?'Make Obsolete':'Finalize Publication')
 1448:             .'" /></p>'
 1449:             .'</form>';
 1450:     }
 1451:     return($scrout,0);
 1452: }
 1453: 
 1454: #########################################
 1455: #########################################
 1456: 
 1457: =pod 
 1458: 
 1459: =item B<phasetwo>
 1460: 
 1461: Render second interface showing status of publication steps.
 1462: This is publication step two.
 1463: 
 1464: Parameters:
 1465: 
 1466: =over 4
 1467: 
 1468: =item I<$source>
 1469: 
 1470: =item I<$target>
 1471: 
 1472: =item I<$style>
 1473: 
 1474: =item I<$distarget>
 1475: 
 1476: =back
 1477: 
 1478: Returns:
 1479: 
 1480: =over 4
 1481: 
 1482: =item integer
 1483: 
 1484: 0: fail
 1485: 1: success
 1486: 
 1487: =cut
 1488: 
 1489: #'stupid emacs
 1490: #########################################
 1491: #########################################
 1492: sub phasetwo {
 1493: 
 1494:     my ($r,$source,$target,$style,$distarget,$batch)=@_;
 1495:     $source=~s/\/+/\//g;
 1496:     $target=~s/\/+/\//g;
 1497: #
 1498: # Unless trying to get rid of something, check name validity
 1499: #
 1500:     unless ($env{'form.obsolete'}) {
 1501: 	if ($target=~/(\_\_\_|\&\&\&|\:\:\:)/) {
 1502: 	    $r->print('<span class="LC_error">'.
 1503: 		      &mt('Unsupported character combination [_1] in filename, FAIL.',"<tt>'.$1.'</tt>").
 1504: 		      '</span>');
 1505: 	    return 0;
 1506: 	}
 1507: 	unless ($target=~/\.(\w+)$/) {
 1508: 	    $r->print('<span class="LC_error">'.&mt('No valid extension found in filename, FAIL').'</span>');
 1509: 	    return 0;
 1510: 	}
 1511: 	if ($target=~/\.(\d+)\.(\w+)$/) {
 1512: 	    $r->print('<span class="LC_error">'.&mt('Filename of resource contains internal version number. Cannot publish such resources, FAIL').'</span>');
 1513: 	    return 0;
 1514: 	}
 1515:     }
 1516: 
 1517: #
 1518: # End name check
 1519: #
 1520:     $distarget=~s/\/+/\//g;
 1521:     my $logfile;
 1522:     unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
 1523: 	$r->print(
 1524:         '<span class="LC_error">'.
 1525: 		&mt('No write permission to user directory, FAIL').'</span>');
 1526:         return 0;
 1527:     }
 1528:     
 1529:     if ($source =~ /\.rights$/) {
 1530: 	$r->print('<p><span class="LC_warning">'.&mt('Warning: It can take up to 1 hour for rights changes to fully propagate.').'</span></p>');
 1531:     }
 1532: 
 1533:     print $logfile 
 1534:         "\n================= Publish ".localtime()." Phase Two  ================\n".$env{'user.name'}.':'.$env{'user.domain'}."\n";
 1535:     
 1536:     %metadatafields=();
 1537:     %metadatakeys=();
 1538: 
 1539:     &metaeval(&unescape($env{'form.allmeta'}));
 1540:     
 1541:     $metadatafields{'title'}=$env{'form.title'};
 1542:     $metadatafields{'author'}=$env{'form.author'};
 1543:     $metadatafields{'subject'}=$env{'form.subject'};
 1544:     $metadatafields{'notes'}=$env{'form.notes'};
 1545:     $metadatafields{'abstract'}=$env{'form.abstract'};
 1546:     $metadatafields{'mime'}=$env{'form.mime'};
 1547:     $metadatafields{'language'}=$env{'form.language'};
 1548:     $metadatafields{'creationdate'}=$env{'form.creationdate'};
 1549:     $metadatafields{'lastrevisiondate'}=$env{'form.lastrevisiondate'};
 1550:     $metadatafields{'owner'}=$env{'form.owner'};
 1551:     $metadatafields{'copyright'}=$env{'form.copyright'};
 1552:     $metadatafields{'standards'}=$env{'form.standards'};
 1553:     $metadatafields{'lowestgradelevel'}=$env{'form.lowestgradelevel'};
 1554:     $metadatafields{'highestgradelevel'}=$env{'form.highestgradelevel'};
 1555:     $metadatafields{'customdistributionfile'}=
 1556:                                  $env{'form.customdistributionfile'};
 1557:     $metadatafields{'sourceavail'}=$env{'form.sourceavail'};
 1558:     $metadatafields{'obsolete'}=$env{'form.obsolete'};
 1559:     $metadatafields{'obsoletereplacement'}=
 1560: 	                        $env{'form.obsoletereplacement'};
 1561:     $metadatafields{'dependencies'}=$env{'form.dependencies'};
 1562:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 1563: 	                                 $env{'user.domain'};
 1564:     $metadatafields{'authorspace'}=$cuname.':'.$cudom;
 1565:     $metadatafields{'domain'}=$cudom;
 1566:     
 1567:     my $allkeywords=$env{'form.addkey'};
 1568:     if (exists($env{'form.keywords'})) {
 1569:         if (ref($env{'form.keywords'})) {
 1570:             $allkeywords .= ','.join(',',@{$env{'form.keywords'}});
 1571:         } else {
 1572:             $allkeywords .= ','.$env{'form.keywords'};
 1573:         }
 1574:     }
 1575:     $allkeywords=~s/[\"\']//g;
 1576:     $allkeywords=~s/\s*[\;\,]\s*/\,/g;
 1577:     $allkeywords=~s/\s+/ /g;
 1578:     $allkeywords=~s/^[ \,]//;
 1579:     $allkeywords=~s/[ \,]$//;
 1580:     $metadatafields{'keywords'}=$allkeywords;
 1581:     
 1582: # check if custom distribution file is specified
 1583:     if ($metadatafields{'copyright'} eq 'custom') {
 1584: 	my $file=$metadatafields{'customdistributionfile'};
 1585: 	unless ($file=~/\.rights$/) {
 1586:             $r->print(
 1587:                 '<span class="LC_error">'.&mt('No valid custom distribution rights file specified, FAIL').
 1588: 		'</span>');
 1589: 	    return 0;
 1590:         }
 1591:     }
 1592:     {
 1593:         print $logfile "\nWrite metadata file for ".$source;
 1594:         my $mfh;
 1595:         unless ($mfh=Apache::File->new('>'.$source.'.meta')) {
 1596:             $r->print( 
 1597:                 '<span class="LC_error">'.&mt('Could not write metadata, FAIL').
 1598: 		'</span>');
 1599: 	    return 0;
 1600:         }
 1601:         foreach (sort keys %metadatafields) {
 1602:             unless ($_=~/\./) {
 1603:                 my $unikey=$_;
 1604:                 $unikey=~/^([A-Za-z]+)/;
 1605:                 my $tag=$1;
 1606:                 $tag=~tr/A-Z/a-z/;
 1607:                 print $mfh "\n\<$tag";
 1608:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
 1609:                     my $value=$metadatafields{$unikey.'.'.$_};
 1610:                     $value=~s/\"/\'\'/g;
 1611:                     print $mfh ' '.$_.'="'.$value.'"';
 1612:                 }
 1613:                 print $mfh '>'.
 1614:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 1615:                         .'</'.$tag.'>';
 1616:             }
 1617:         }
 1618:         $r->print('<p>'.&mt('Wrote Metadata').'</p>');
 1619:         print $logfile "\nWrote metadata";
 1620:     }
 1621:     
 1622: # -------------------------------- Synchronize entry with SQL metadata database
 1623: 
 1624:     $metadatafields{'url'} = $distarget;
 1625:     $metadatafields{'version'} = 'current';
 1626: 
 1627:     my ($error,$success) = &store_metadata(%metadatafields);
 1628:     if ($success) {
 1629: 	$r->print('<p>'.&mt('Synchronized SQL metadata database').'</p>');
 1630: 	print $logfile "\nSynchronized SQL metadata database";
 1631:     } else {
 1632: 	$r->print($error);
 1633: 	print $logfile "\n".$error;
 1634:     }
 1635: # --------------------------------------------- Delete author resource messages
 1636:     my $delresult=&Apache::lonmsg::del_url_author_res_msg($target); 
 1637:     $r->print('<p>'.&mt('Removing error messages:').' '.$delresult.'</p>');
 1638:     print $logfile "\nRemoving error messages: $delresult";
 1639: # ----------------------------------------------------------- Copy old versions
 1640:    
 1641:     if (-e $target) {
 1642:         my $filename;
 1643:         my $maxversion=0;
 1644:         $target=~/(.*)\/([^\/]+)\.(\w+)$/;
 1645:         my $srcf=$2;
 1646:         my $srct=$3;
 1647:         my $srcd=$1;
 1648:         my $docroot = $Apache::lonnet::perlvar{'lonDocRoot'};
 1649:         unless ($srcd=~/^\Q$docroot\E\/res/) {
 1650:             print $logfile "\nPANIC: Target dir is ".$srcd;
 1651:             $r->print(
 1652: 	 "<span class=\"LC_error\">".&mt('Invalid target directory, FAIL')."</span>");
 1653: 	    return 0;
 1654:         }
 1655:         opendir(DIR,$srcd);
 1656:         while ($filename=readdir(DIR)) {
 1657:             if (-l $srcd.'/'.$filename) {
 1658:                 unlink($srcd.'/'.$filename);
 1659:                 unlink($srcd.'/'.$filename.'.meta');
 1660:             } else {
 1661:                 if ($filename=~/^\Q$srcf\E\.(\d+)\.\Q$srct\E$/) {
 1662:                     $maxversion=($1>$maxversion)?$1:$maxversion;
 1663:                 }
 1664:             }
 1665:         }
 1666:         closedir(DIR);
 1667:         $maxversion++;
 1668:         $r->print('<p>'.&mt('Creating old version [_1]',$maxversion).'</p>');
 1669:         print $logfile "\nCreating old version ".$maxversion."\n";
 1670:         
 1671:         my $copyfile=$srcd.'/'.$srcf.'.'.$maxversion.'.'.$srct;
 1672:         
 1673:         if (copy($target,$copyfile)) {
 1674: 	    print $logfile "Copied old target to ".$copyfile."\n";
 1675:             $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied old target file')));
 1676:         } else {
 1677: 	    print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 1678:             $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Failed to copy old target').", $!",1));
 1679: 	    return 0;
 1680:         }
 1681:         
 1682: # --------------------------------------------------------------- Copy Metadata
 1683: 
 1684: 	$copyfile=$copyfile.'.meta';
 1685:         
 1686:         if (copy($target.'.meta',$copyfile)) {
 1687: 	    print $logfile "Copied old target metadata to ".$copyfile."\n";
 1688:             $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied old metadata')));
 1689:         } else {
 1690: 	    print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 1691:             if (-e $target.'.meta') {
 1692:                 $r->print(&Apache::lonhtmlcommon::confirm_success(
 1693:                            &mt('Failed to write old metadata copy').", $!",1));
 1694: 		return 0;
 1695: 	    }
 1696:         }
 1697:         
 1698:         
 1699:     } else {
 1700:         $r->print('<p>'.&mt('Initial version').'</p>');
 1701:         print $logfile "\nInitial version";
 1702:     }
 1703: 
 1704: # ---------------------------------------------------------------- Write Source
 1705:     my $copyfile=$target;
 1706:     
 1707:     my @parts=split(/\//,$copyfile);
 1708:     my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 1709:     
 1710:     my $count;
 1711:     for ($count=5;$count<$#parts;$count++) {
 1712:         $path.="/$parts[$count]";
 1713:         if ((-e $path)!=1) {
 1714:             print $logfile "\nCreating directory ".$path;
 1715:             mkdir($path,0777);
 1716:             $r->print('<p>'
 1717:                      .&mt('Created directory [_1]'
 1718:                          ,'<span class="LC_filename">'.$parts[$count].'</span>')
 1719:                      .'</p>'
 1720:             );
 1721:         }
 1722:     }
 1723:     
 1724:     if (copy($source,$copyfile)) {
 1725:         print $logfile "\nCopied original source to ".$copyfile."\n";
 1726:         $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied source file')));
 1727:     } else {
 1728:         print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 1729:         $r->print(&Apache::lonhtmlcommon::confirm_success(
 1730: 	    &mt('Failed to copy source').", $!",1));
 1731: 	return 0;
 1732:     }
 1733:     
 1734: # ---------------------------------------------- Delete local tmp-preview files
 1735:     unlink($copyfile.'.tmp');
 1736: # --------------------------------------------------------------- Copy Metadata
 1737: 
 1738:     $copyfile=$copyfile.'.meta';
 1739:     
 1740:     if (copy($source.'.meta',$copyfile)) {
 1741:         print $logfile "\nCopied original metadata to ".$copyfile."\n";
 1742:         $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied metadata')));
 1743:     } else {
 1744:         print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n";
 1745:         $r->print(&Apache::lonhtmlcommon::confirm_success(
 1746:                   &mt('Failed to write metadata copy').", $!",1));
 1747: 	return 0;
 1748:     }
 1749:     $r->rflush;
 1750: 
 1751: # ------------------------------------------------------------- Trigger updates
 1752:     push(@{$modified_urls},[$target,$source]);
 1753:     unless ($registered_cleanup) {
 1754:         my $handlers = $r->get_handlers('PerlCleanupHandler');
 1755:         $r->set_handlers('PerlCleanupHandler' => [\&notify,@{$handlers}]);
 1756: 	$registered_cleanup=1;
 1757:     }
 1758: 
 1759: # ---------------------------------------------------------- Clear local caches
 1760:     my $thisdistarget=$target;
 1761:     $thisdistarget=~s/^\Q$docroot\E//;
 1762:     &Apache::lonnet::devalidate_cache_new('resversion',$target);
 1763:     &Apache::lonnet::devalidate_cache_new('meta',
 1764: 			 &Apache::lonnet::declutter($thisdistarget));
 1765: 
 1766: # ------------------------------------------------------------- Everything done
 1767:     $logfile->close();
 1768:     $r->print('<p class="LC_success">'.&mt('Done').'</p>');
 1769: 
 1770: # ------------------------------------------------ Provide link to new resource
 1771:     unless ($batch) {
 1772:         
 1773:         my $thissrc=&Apache::loncfile::url($source);
 1774:         my $thissrcdir=$thissrc;
 1775:         $thissrcdir=~s/\/[^\/]+$/\//;
 1776:         
 1777:         $r->print(&Apache::loncommon::head_subbox(
 1778:             &Apache::lonhtmlcommon::start_funclist().
 1779:             &Apache::lonhtmlcommon::add_item_funclist(
 1780:                 '<a href="'.$thisdistarget.'">'.
 1781:                 &mt('View Published Version').
 1782:                 '</a>').
 1783:             &Apache::lonhtmlcommon::add_item_funclist(
 1784:                 '<a href="'.$thissrc.'">'.
 1785:                 &mt('Back to Source').
 1786:                 '</a>').
 1787:             &Apache::lonhtmlcommon::add_item_funclist(
 1788:                 '<a href="'.$thissrcdir.'">'.
 1789:                 &mt('Back to Source Directory').
 1790:                 '</a>').
 1791:             &Apache::lonhtmlcommon::end_funclist())
 1792:         );
 1793:     }
 1794:     return 1;
 1795: }
 1796: 
 1797: # =============================================================== Notifications
 1798: sub notify {  
 1799: # --------------------------------------------------- Send update notifications
 1800:     foreach my $targetsource (@{$modified_urls}){
 1801: 	my ($target,$source)=@{$targetsource};
 1802: 	my $logfile=Apache::File->new('>>'.$source.'.log');
 1803: 	print $logfile "\nCleanup phase: Notifications\n";
 1804: 	my @subscribed=&get_subscribed_hosts($target);
 1805: 	foreach my $subhost (@subscribed) {
 1806: 	    print $logfile "\nNotifying host ".$subhost.':';
 1807: 	    my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
 1808: 	    print $logfile $reply;
 1809: 	}
 1810: # ---------------------------------------- Send update notifications, meta only
 1811: 	my @subscribedmeta=&get_subscribed_hosts("$target.meta");
 1812: 	foreach my $subhost (@subscribedmeta) {
 1813: 	    print $logfile "\nNotifying host for metadata only ".$subhost.':';
 1814: 	    my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
 1815: 						$subhost);
 1816: 	    print $logfile $reply;
 1817: 	} 
 1818: # --------------------------------------------------- Notify subscribed courses
 1819: 	my %courses=&coursedependencies($target);
 1820: 	my $now=time;
 1821: 	foreach (keys %courses) {
 1822: 	    print $logfile "\nNotifying course ".$_.':';
 1823: 	    my ($cdom,$cname)=split(/\_/,$_);
 1824: 	    my $reply=&Apache::lonnet::cput
 1825: 		('versionupdate',{$target => $now},$cdom,$cname);
 1826: 	    print $logfile $reply;
 1827: 	}
 1828: 	print $logfile "\n============ Done ============\n";
 1829: 	$logfile->close();
 1830:     }
 1831:     if ($lock) { &Apache::lonnet::remove_lock($lock); }
 1832:     return OK;
 1833: }
 1834: 
 1835: #########################################
 1836: 
 1837: sub batchpublish {
 1838:     my ($r,$srcfile,$targetfile)=@_;
 1839:     #publication pollutes %env with form.* values
 1840:     my %oldenv=%env;
 1841:     $srcfile=~s/\/+/\//g;
 1842:     $targetfile=~s/\/+/\//g;
 1843:     $srcfile=~s/\/+/\//g;
 1844: 
 1845:     my $docroot=$r->dir_config('lonDocRoot');
 1846:     my $thisdistarget=$targetfile;
 1847:     $thisdistarget=~s/^\Q$docroot\E//;
 1848: 
 1849: 
 1850:     %metadatafields=();
 1851:     %metadatakeys=();
 1852:     $srcfile=~/\.(\w+)$/;
 1853:     my $thistype=$1;
 1854: 
 1855: 
 1856:     my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
 1857:      
 1858:     $r->print('<h2>'
 1859:              .&mt('Publishing [_1]',&Apache::loncfile::display($srcfile))
 1860:              .'</h2>'
 1861:     );
 1862: 
 1863: # phase one takes
 1864: #  my ($source,$target,$style,$batch)=@_;
 1865:     my ($outstring,$error)=&publish($srcfile,$targetfile,$thisembstyle,1);
 1866:     $r->print('<p>'.$outstring.'</p>');
 1867: # phase two takes
 1868: # my ($source,$target,$style,$distarget,batch)=@_;
 1869: # $env{'form.allmeta'},$env{'form.title'},$env{'form.author'},...
 1870:     if (!$error) {
 1871: 	$r->print('<p>');
 1872: 	&phasetwo($r,$srcfile,$targetfile,$thisembstyle,$thisdistarget,1);
 1873: 	$r->print('</p>');
 1874:     }
 1875:     %env=%oldenv;
 1876:     return '';
 1877: }
 1878: 
 1879: #########################################
 1880: 
 1881: sub publishdirectory {
 1882:     my ($r,$fn,$thisdisfn)=@_;
 1883:     $fn=~s/\/+/\//g;
 1884:     $thisdisfn=~s/\/+/\//g;
 1885:     my $thisdisresdir=$thisdisfn;
 1886:     $thisdisresdir=~s/^\/priv\//\/res\//;
 1887:     my $resdir = $r->dir_config('lonDocRoot').$thisdisresdir;
 1888:     $r->print(&Apache::lonhtmlcommon::start_pick_box()
 1889:              .&Apache::lonhtmlcommon::row_title(&mt('Directory'))
 1890:             .'<span class="LC_filename">'.$thisdisfn.'</span>'
 1891:             .&Apache::lonhtmlcommon::row_closure()
 1892:             .&Apache::lonhtmlcommon::row_title(&mt('Target'))
 1893:             .'<span class="LC_filename">'.$thisdisresdir.'</span>'
 1894:     );
 1895: 
 1896:     my $dirptr=16384;		# Mask indicating a directory in stat.cmode.
 1897:     unless ($env{'form.phase'} eq 'two') {
 1898: # ask user what they want
 1899:         $r->print(&Apache::lonhtmlcommon::row_closure()
 1900:                  .&Apache::lonhtmlcommon::row_title(&mt('Options'))
 1901:         );
 1902:         $r->print('<form name="pubdirpref" method="post">'.
 1903: 		  &hiddenfield('phase','two').
 1904: 		  &hiddenfield('filename',$env{'form.filename'}).
 1905: 		  &checkbox('pubrec','include subdirectories').
 1906: 		  &checkbox('forcerepub','force republication of previously published files').
 1907:                   &checkbox('obsolete','make file(s) obsolete').
 1908: 		  &checkbox('forceoverride','force directory level metadata over existing').
 1909: 		  '<br /><input type="submit" value="'.&mt('Publish Directory').'" /></form>');
 1910:         $r->print(&Apache::lonhtmlcommon::row_closure(1)
 1911:                  .&Apache::lonhtmlcommon::end_pick_box()
 1912:         );
 1913:         $lock=0;
 1914:     } else {
 1915:         $r->print(&Apache::lonhtmlcommon::row_closure(1)
 1916:                  .&Apache::lonhtmlcommon::end_pick_box()
 1917:         );
 1918:         unless ($lock) { $lock=&Apache::lonnet::set_lock(&mt('Publishing [_1]',$fn)); }
 1919: # actually publish things
 1920: 	opendir(DIR,$fn);
 1921: 	my @files=sort(readdir(DIR));
 1922: 	foreach my $filename (@files) {
 1923: 	    my ($cdev,$cino,$cmode,$cnlink,
 1924: 		$cuid,$cgid,$crdev,$csize,
 1925: 		$catime,$cmtime,$cctime,
 1926: 		$cblksize,$cblocks)=stat($fn.'/'.$filename);
 1927: 	    
 1928: 	    my $extension='';
 1929: 	    if ($filename=~/\.(\w+)$/) { $extension=$1; }
 1930: 	    if ($cmode&$dirptr) {
 1931: 		if (($filename!~/^\./) && ($env{'form.pubrec'})) {
 1932: 		    &publishdirectory($r,$docroot.$fn.'/'.$filename,$thisdisfn.'/'.$filename);
 1933: 		}
 1934: 	    } elsif ((&Apache::loncommon::fileembstyle($extension) ne 'hdn') &&
 1935: 		     ($filename!~/^[\#\.]/) && ($filename!~/\~$/)) {
 1936: # find out publication status and/or exiting metadata
 1937: 		my $publishthis=0;
 1938: 		if (-e $resdir.'/'.$filename) {
 1939: 		    my ($rdev,$rino,$rmode,$rnlink,
 1940: 			$ruid,$rgid,$rrdev,$rsize,
 1941: 			$ratime,$rmtime,$rctime,
 1942: 			$rblksize,$rblocks)=stat($resdir.'/'.$filename);
 1943: 		    if (($rmtime<$cmtime) || ($env{'form.forcerepub'})) {
 1944: # previously published, modified now
 1945: 			$publishthis=1;
 1946: 		    }
 1947: 		    my $meta_cmtime = (stat($fn.'/'.$filename.'.meta'))[9];
 1948: 		    my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
 1949: 		    if ( $meta_rmtime<$meta_cmtime ) {
 1950: 			$publishthis=1;
 1951: 		    }
 1952: 		} else {
 1953: # never published
 1954: 		    $publishthis=1;
 1955: 		}
 1956: 		
 1957: 		if ($publishthis) {
 1958: 		    &batchpublish($r,$fn.'/'.$filename,$resdir.'/'.$filename);
 1959: 		} else {
 1960: 		    $r->print('<br />'.&mt('Skipping').' '.$filename.'<br />');
 1961: 		}
 1962: 		$r->rflush();
 1963: 	    }
 1964: 	}
 1965: 	closedir(DIR);
 1966:     }
 1967: }
 1968: 
 1969: #########################################
 1970: # publish a default.meta file
 1971: 
 1972: sub defaultmetapublish {
 1973:     my ($r,$fn,$cuname,$cudom)=@_;
 1974:     unless (-e $fn) {
 1975:        return HTTP_NOT_FOUND;
 1976:     }
 1977:     my $target=$fn;
 1978:     $target=~s/^\Q$Apache::lonnet::perlvar{'lonDocRoot'}\E\/priv\//\Q$Apache::lonnet::perlvar{'lonDocRoot'}\E\/res\//;
 1979: 
 1980: 
 1981:     &Apache::loncommon::content_type($r,'text/html');
 1982:     $r->send_http_header;
 1983: 
 1984:     $r->print(&Apache::loncommon::start_page('Metadata Publication'));
 1985: 
 1986: # ---------------------------------------------------------------- Write Source
 1987:     my $copyfile=$target;
 1988:     
 1989:     my @parts=split(/\//,$copyfile);
 1990:     my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 1991:     
 1992:     my $count;
 1993:     for ($count=5;$count<$#parts;$count++) {
 1994:         $path.="/$parts[$count]";
 1995:         if ((-e $path)!=1) {
 1996:             mkdir($path,0777);
 1997:             $r->print('<p>'
 1998:                      .&mt('Created directory [_1]'
 1999:                          ,'<span class="LC_filename">'.$parts[$count].'</span>')
 2000:                      .'</p>'
 2001:             );
 2002:         }
 2003:     }
 2004:     
 2005:     if (copy($fn,$copyfile)) {
 2006:         $r->print('<p>'.&mt('Copied source file').'</p>');
 2007:     } else {
 2008:         return "<span class=\"LC_error\">".
 2009: 	    &mt('Failed to copy source').", $!, ".&mt('FAIL')."</span>";
 2010:     }
 2011: 
 2012: # --------------------------------------------------- Send update notifications
 2013: 
 2014:     my @subscribed=&get_subscribed_hosts($target);
 2015:     foreach my $subhost (@subscribed) {
 2016: 	$r->print('<p>'.&mt('Notifying host').' '.$subhost.':');$r->rflush;
 2017: 	my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
 2018: 	$r->print($reply.'</p><br />');$r->rflush;
 2019:     }
 2020: # ------------------------------------------------------------------- Link back
 2021:     $r->print("<a href='".&Apache::loncfile::display($fn)."'>".&mt('Back to Metadata').'</a>');
 2022:     $r->print(&Apache::loncommon::end_page());
 2023:     return OK;
 2024: }
 2025: #########################################
 2026: 
 2027: =pod
 2028: 
 2029: =item B<handler>
 2030: 
 2031: A basic outline of the handler subroutine follows.
 2032: 
 2033: =over 4
 2034: 
 2035: =item *
 2036: 
 2037: Get query string for limited number of parameters.
 2038: 
 2039: =item *
 2040: 
 2041: Check filename.
 2042: 
 2043: =item *
 2044: 
 2045: File is there and owned, init lookup tables.
 2046: 
 2047: =item *
 2048: 
 2049: Start page output.
 2050: 
 2051: =item *
 2052: 
 2053: Evaluate individual file, and then output information.
 2054: 
 2055: =item *
 2056: 
 2057: Publishing from $thisfn to $thistarget with $thisembstyle.
 2058: 
 2059: =back
 2060: 
 2061: =cut
 2062: 
 2063: #########################################
 2064: #########################################
 2065: sub handler {
 2066:     my $r=shift;
 2067: 
 2068:     if ($r->header_only) {
 2069: 	&Apache::loncommon::content_type($r,'text/html');
 2070: 	$r->send_http_header;
 2071: 	return OK;
 2072:     }
 2073: 
 2074: # Get query string for limited number of parameters
 2075: 
 2076:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 2077:                                             ['filename']);
 2078: 
 2079: # -------------------------------------- Flag and buffer for registered cleanup
 2080:     $registered_cleanup=0;
 2081:     @{$modified_urls}=();
 2082: # -------------------------------------------------------------- Check filename
 2083: 
 2084:     my $fn=&unescape($env{'form.filename'});
 2085:     ($cuname,$cudom)=&Apache::lonnet::constructaccess($fn);
 2086: # ----------------------------------------------------- Do we have permissions?
 2087:      unless (($cuname) && ($cudom)) {
 2088:        $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
 2089:                       ' trying to publish file '.$env{'form.filename'}.
 2090:                       ' - not authorized', 
 2091:                       $r->filename); 
 2092:        return HTTP_NOT_ACCEPTABLE;
 2093:      }
 2094: # ----------------------------------------------------------------- Get docroot
 2095:     $docroot=$r->dir_config('lonDocRoot');
 2096: 
 2097: 
 2098: # special publication: default.meta file
 2099:     if ($fn=~/\/default.meta$/) {
 2100: 	return &defaultmetapublish($r,$fn,$cuname,$cudom); 
 2101:     }
 2102:     $fn=~s/\.meta$//;
 2103: 
 2104: # sanity test on the filename 
 2105:  
 2106:     unless ($fn) { 
 2107: 	$r->log_reason($cuname.' at '.$cudom.
 2108: 		       ' trying to publish empty filename', $r->filename); 
 2109: 	return HTTP_NOT_FOUND;
 2110:     } 
 2111: 
 2112:     unless (-e $docroot.$fn) { 
 2113: 	$r->log_reason($cuname.' at '.$cudom.
 2114: 		       ' trying to publish non-existing file '.
 2115: 		       $env{'form.filename'}.' ('.$fn.')', 
 2116: 		       $r->filename); 
 2117: 	return HTTP_NOT_FOUND;
 2118:     } 
 2119: 
 2120: # -------------------------------- File is there and owned, init lookup tables.
 2121: 
 2122:     %addid=();
 2123:     
 2124:     {
 2125: 	my $fh=Apache::File->new($r->dir_config('lonTabDir').'/addid.tab');
 2126: 	while (<$fh>=~/(\w+)\s+(\w+)/) {
 2127: 	    $addid{$1}=$2;
 2128: 	}
 2129:     }
 2130: 
 2131:     %nokey=();
 2132: 
 2133:     {
 2134: 	my $fh=Apache::File->new($r->dir_config('lonIncludes').'/un_keyword.tab');
 2135: 	while (<$fh>) {
 2136: 	    my $word=$_;
 2137: 	    chomp($word);
 2138: 	    $nokey{$word}=1;
 2139: 	}
 2140:     }
 2141: 
 2142: # ---------------------------------------------------------- Start page output.
 2143: 
 2144:     &Apache::loncommon::content_type($r,'text/html');
 2145:     $r->send_http_header;
 2146:     
 2147:     # Breadcrumbs
 2148:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 2149:     &Apache::lonhtmlcommon::add_breadcrumb({
 2150:         'text'  => 'Construction Space',
 2151:         'href'  => &Apache::loncommon::authorspace($fn),
 2152:     });
 2153:     &Apache::lonhtmlcommon::add_breadcrumb({
 2154:         'text'  => 'Resource Publication',
 2155:         'href'  => '',
 2156:     });
 2157: 
 2158:     my $js='<script type="text/javascript">'.
 2159: 	&Apache::loncommon::browser_and_searcher_javascript().
 2160: 	'</script>';
 2161:     $r->print(&Apache::loncommon::start_page('Resource Publication',$js)
 2162:              .&Apache::lonhtmlcommon::breadcrumbs()
 2163:              .&Apache::loncommon::head_subbox(
 2164:                   &Apache::loncommon::CSTR_pageheader($docroot.$fn))
 2165:     );
 2166: 
 2167:     my $thisdisfn=&HTML::Entities::encode($fn,'<>&"');
 2168:     my $thistarget=$fn;
 2169:     $thistarget=~s/^\/priv\//\/res\//;
 2170:     my $thisdistarget=&HTML::Entities::encode($thistarget,'<>&"');
 2171: 
 2172:     if ($fn=~/\/$/) {
 2173: # -------------------------------------------------------- This is a directory
 2174: 	&publishdirectory($r,$docroot.$fn,$thisdisfn);
 2175: 	$r->print('<hr /><a href="'.$thisdisfn.'">'.&mt('Return to Directory').'</a>');
 2176:     } else {
 2177: # ---------------------- Evaluate individual file, and then output information.
 2178: 	$fn=~/\.(\w+)$/;
 2179: 	my $thistype=$1;
 2180: 	my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
 2181:         if ($thistype eq 'page') {  $thisembstyle = 'rat'; }
 2182: 
 2183:         $r->print('<h2>'
 2184:                  .&mt('Publishing [_1]'
 2185:                      ,'<span class="LC_filename">'.$thisdisfn.'</span>')
 2186:                  .'</h2>'
 2187:         );
 2188: 
 2189:         $r->print('<h3>'.&mt('Resource Details').'</h3>');
 2190: 
 2191:         $r->print(&Apache::lonhtmlcommon::start_pick_box());
 2192: 
 2193:         $r->print(&Apache::lonhtmlcommon::row_title(&mt('Type'))
 2194:                  .&Apache::loncommon::filedescription($thistype)
 2195:                  .&Apache::lonhtmlcommon::row_closure()
 2196:                  );
 2197: 
 2198:         $r->print(&Apache::lonhtmlcommon::row_title(&mt('Link to Resource'))
 2199:                  .'<tt>'
 2200:                  );
 2201: 	$r->print(<<ENDCAPTION);
 2202: <a href='javascript:void(window.open("$thisdisfn","cat","height=300,width=500,scrollbars=1,resizable=1,menubar=0,location=1"))'>
 2203: $thisdisfn</a>
 2204: ENDCAPTION
 2205:         $r->print('</tt>'
 2206:                  .&Apache::lonhtmlcommon::row_closure()
 2207:                  );
 2208: 
 2209:         $r->print(&Apache::lonhtmlcommon::row_title(&mt('Target'))
 2210:                  .'<tt>'.$thisdistarget.'</tt>'
 2211:                  );
 2212: 	if (($cuname ne $env{'user.name'})||($cudom ne $env{'user.domain'})) {
 2213:             $r->print(&Apache::lonhtmlcommon::row_closure()
 2214:                      .&Apache::lonhtmlcommon::row_title(&mt('Co-Author'))
 2215:                      .'<span class="LC_warning">'
 2216: 		     .&Apache::loncommon::plainname($cuname,$cudom) .' ('.$cuname.':'.$cudom.')'
 2217:                      .'</span>'
 2218:                      );
 2219: 	}
 2220: 
 2221: 	if (&Apache::loncommon::fileembstyle($thistype) eq 'ssi') {
 2222:             $r->print(&Apache::lonhtmlcommon::row_closure()
 2223:                      .&Apache::lonhtmlcommon::row_title(&mt('Diffs')));
 2224: 	    $r->print(<<ENDDIFF);
 2225: <a href='javascript:void(window.open("/adm/diff?filename=$thisdisfn&versiontwo=priv","cat","height=300,width=500,scrollbars=1,resizable=1,menubar=0,location=1"))'>
 2226: ENDDIFF
 2227:             $r->print(&mt('Diffs with Current Version').'</a>');
 2228: 	}
 2229:         
 2230:         $r->print(&Apache::lonhtmlcommon::row_closure(1)
 2231:                  .&Apache::lonhtmlcommon::end_pick_box()
 2232:                  );
 2233:   
 2234: # ---------------------- Publishing from $fn to $thistarget with $thisembstyle.
 2235: 
 2236: 	unless ($env{'form.phase'} eq 'two') {
 2237: # ---------------------------------------------------------- Parse for problems
 2238: 	    my ($warningcount,$errorcount);
 2239: 	    if ($thisembstyle eq 'ssi') {
 2240: 		($warningcount,$errorcount)=&checkonthis($r,$fn);
 2241: 	    }
 2242: 	    unless ($errorcount) {
 2243: 		my ($outstring,$error)=
 2244: 		    &publish($docroot.$fn,$docroot.$thistarget,$thisembstyle);
 2245: 		$r->print($outstring);
 2246: 	    } else {
 2247: 		$r->print('<h3 class="LC_error">'.
 2248: 			  &mt('The document contains errors and cannot be published.').
 2249: 			  '</h3>');
 2250: 	    }
 2251: 	} else {
 2252: 	    &phasetwo($r,$docroot.$fn,$docroot.$thistarget,$thisembstyle,$thisdistarget); 
 2253: 	}
 2254:     }
 2255:     $r->print(&Apache::loncommon::end_page());
 2256: 
 2257:     return OK;
 2258: }
 2259: 
 2260: 1;
 2261: __END__
 2262: 
 2263: =pod
 2264: 
 2265: =back
 2266: 
 2267: =back
 2268: 
 2269: =cut
 2270: 

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