--- loncom/publisher/lonpublisher.pm 2003/02/18 23:13:54 1.111 +++ loncom/publisher/lonpublisher.pm 2003/03/14 02:26:12 1.115 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Publication Handler # -# $Id: lonpublisher.pm,v 1.111 2003/02/18 23:13:54 albertel Exp $ +# $Id: lonpublisher.pm,v 1.115 2003/03/14 02:26:12 www 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); } @@ -948,9 +950,7 @@ sub publish { my $oldenv=$ENV{'request.uri'}; $ENV{'request.uri'}=$target; - $Apache::lonxml::debug=1; $allmeta=Apache::lonxml::xmlparse(undef,'meta',$content); - $Apache::lonxml::debug=0; $ENV{'request.uri'}=$oldenv; &metaeval($allmeta); @@ -1105,7 +1105,8 @@ END $metadatafields{'owner'}); # -------------------------------------------------- Correct copyright for rat. - if ($style eq 'rat') { + unless ($style eq 'prv') { + if ($style eq 'rat') { if ($metadatafields{'copyright'} eq 'public') { delete $metadatafields{'copyright'}; } @@ -1113,19 +1114,23 @@ END $metadatafields{'copyright'}, \&Apache::loncommon::copyrightdescription, (grep !/^public$/,(&Apache::loncommon::copyrightids))); - } - else { + } else { $scrout.=&selectbox('Copyright/Distribution','copyright', $metadatafields{'copyright'}, \&Apache::loncommon::copyrightdescription, - (&Apache::loncommon::copyrightids)); - } + (&Apache::loncommon::copyrightids)); + } - my $copyright_help = + my $copyright_help = Apache::loncommon::help_open_topic('Publishing_Copyright'); - $scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge; - return $scrout. - '

'; + $scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge; + $scrout.=&textfield('Custom Distribution File','customdistributionfile', + $metadatafields{'customdistributionfile'}). + $copyright_help; + } else { + $scrout.=&hiddenfield('copyright','private'); + } + return ($scrout.'

',0); # ============================================================================= # BATCH MODE # @@ -1153,7 +1158,7 @@ END $ENV{'form.copyright'}='default'; } $ENV{'form.allmeta'}=&Apache::lonnet::escape($allmeta); - return $scrout; + return ($scrout,0); } } @@ -1203,14 +1208,14 @@ sub phasetwo { if ($target=~/\_\_\_/) { $r->print( - 'Unsupported character combination "___" in filename, FAIL'); + 'Unsupported character combination "___" in filename, FAIL'); return 0; } $distarget=~s/\/+/\//g; my $logfile; unless ($logfile=Apache::File->new('>>'.$source.'.log')) { $r->print( - 'No write permission to user directory, FAIL'); + 'No write permission to user directory, FAIL'); return 0; } print $logfile @@ -1232,6 +1237,8 @@ sub phasetwo { $metadatafields{'lastrevisiondate'}=$ENV{'form.lastrevisiondate'}; $metadatafields{'owner'}=$ENV{'form.owner'}; $metadatafields{'copyright'}=$ENV{'form.copyright'}; + $metadatafields{'customdistributionfile'}= + $ENV{'form.customdistributionfile'}; $metadatafields{'dependencies'}=$ENV{'form.dependencies'}; my $allkeywords=$ENV{'form.addkey'}; @@ -1251,7 +1258,7 @@ sub phasetwo { my $mfh; unless ($mfh=Apache::File->new('>'.$source.'.meta')) { return - 'Could not write metadata, FAIL'; + 'Could not write metadata, FAIL'; } foreach (sort keys %metadatafields) { unless ($_=~/\./) { @@ -1303,7 +1310,7 @@ sub phasetwo { my $srcd=$1; unless ($srcd=~/^\/home\/httpd\/html\/res/) { print $logfile "\nPANIC: Target dir is ".$srcd; - return "Invalid target directory, FAIL"; + return "Invalid target directory, FAIL"; } opendir(DIR,$srcd); while ($filename=readdir(DIR)) { @@ -1328,7 +1335,7 @@ sub phasetwo { $r->print('

Copied old target file'); } else { print $logfile "Unable to write ".$copyfile.':'.$!."\n"; - return "Failed to copy old target, $!, FAIL"; + return "Failed to copy old target, $!, FAIL"; } # --------------------------------------------------------------- Copy Metadata @@ -1342,7 +1349,7 @@ sub phasetwo { print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n"; if (-e $target.'.meta') { return - "Failed to write old metadata copy, $!, FAIL"; + "Failed to write old metadata copy, $!, FAIL"; } } @@ -1373,7 +1380,7 @@ sub phasetwo { $r->print('

Copied source file'); } else { print $logfile "\nUnable to write ".$copyfile.':'.$!."\n"; - return "Failed to copy source, $!, FAIL"; + return "Failed to copy source, $!, FAIL"; } # --------------------------------------------------------------- Copy Metadata @@ -1386,7 +1393,7 @@ sub phasetwo { } else { print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n"; return - "Failed to write metadata copy, $!, FAIL"; + "Failed to write metadata copy, $!, FAIL"; } $r->rflush; # --------------------------------------------------- Send update notifications @@ -1474,13 +1481,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 ''; } @@ -1595,7 +1605,7 @@ sub handler { # -------------------------------------------------------------- Check filename - my $fn=$ENV{'form.filename'}; + my $fn=&Apache::lonnet::unescape($ENV{'form.filename'}); unless ($fn) { @@ -1725,13 +1735,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('');