--- loncom/publisher/lonpublisher.pm 2003/02/18 23:18:50 1.112 +++ loncom/publisher/lonpublisher.pm 2003/03/07 17:52:37 1.113 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Publication Handler # -# $Id: lonpublisher.pm,v 1.112 2003/02/18 23:18:50 albertel Exp $ +# $Id: lonpublisher.pm,v 1.113 2003/03/07 17:52:37 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -789,6 +789,10 @@ This is the workhorse function of this m backup copies, performs any automatic processing (prior to publication, especially for rat and ssi files), +Returns a 2 element array, the first is the string to be shown to the +user, the second is an error code, either 1 (an error occured) or 0 +(no error occurred) + I =cut @@ -805,8 +809,7 @@ sub publish { my %allow=(); unless ($logfile=Apache::File->new('>>'.$source.'.log')) { - return - 'No write permission to user directory, FAIL'; + return ('No write permission to user directory, FAIL',1); } print $logfile "\n\n================= Publish ".localtime()." Phase One ================\n"; @@ -820,14 +823,14 @@ sub publish { print $logfile "Copied original file to ".$copyfile."\n"; } else { print $logfile "Unable to write backup ".$copyfile.':'.$!."\n"; - return "Failed to write backup copy, $!,FAIL"; + return ("Failed to write backup copy, $!,FAIL",1); } # ------------------------------------------------------------- IDs and indices my ($outstring,$error); ($outstring,$error,%allow)=&fix_ids_and_indices($logfile,$source, $target); - if ($error) { return $outstring; } + if ($error) { return ($outstring,$error); } # ------------------------------------------------------------ Construct Allows $scrout.='

Dependencies

'; @@ -872,9 +875,8 @@ sub publish { my $org; unless ($org=Apache::File->new('>'.$source)) { print $logfile "No write permit to $source\n"; - return - 'No write permission to '.$source. - ', FAIL'; + return ('No write permission to '.$source. + ', FAIL',1); } print($org $outstring); } @@ -1122,8 +1124,7 @@ END my $copyright_help = Apache::loncommon::help_open_topic('Publishing_Copyright'); $scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge; - return $scrout. - '

'; + return ($scrout.'

',0); # ============================================================================= # BATCH MODE # @@ -1151,7 +1152,7 @@ END $ENV{'form.copyright'}='default'; } $ENV{'form.allmeta'}=&Apache::lonnet::escape($allmeta); - return $scrout; + return ($scrout,0); } } @@ -1472,13 +1473,16 @@ sub batchpublish { # phase one takes # my ($source,$target,$style,$batch)=@_; - $r->print('

'.&publish($srcfile,$targetfile,$thisembstyle,1).'

'); + my ($outstring,$error)=&publish($srcfile,$targetfile,$thisembstyle,1); + $r->print('

'.$outstring.'

'); # phase two takes # my ($source,$target,$style,$distarget,batch)=@_; # $ENV{'form.allmeta'},$ENV{'form.title'},$ENV{'form.author'},... - $r->print('

'); - &phasetwo($r,$srcfile,$targetfile,$thisembstyle,$thisdistarget,1); - $r->print('

'); + if (!$error) { + $r->print('

'); + &phasetwo($r,$srcfile,$targetfile,$thisembstyle,$thisdistarget,1); + $r->print('

'); + } return ''; } @@ -1593,7 +1597,7 @@ sub handler { # -------------------------------------------------------------- Check filename - my $fn=$ENV{'form.filename'}; + my $fn=&Apache::lonnet::unescape($ENV{'form.filename'}); unless ($fn) { @@ -1723,13 +1727,12 @@ unless ($ENV{'form.phase'} eq 'two') { # ------------------ Publishing from $thisfn to $thistarget with $thisembstyle. unless ($ENV{'form.phase'} eq 'two') { - $r->print( - '
'.&publish($thisfn,$thistarget,$thisembstyle)); + my ($outstring,$error)=&publish($thisfn,$thistarget,$thisembstyle); + $r->print('
'.$outstring); } else { $r->print('
'); &phasetwo($r,$thisfn,$thistarget,$thisembstyle,$thisdistarget); - } - + } } $r->print('');