--- loncom/publisher/lonpublisher.pm 2008/05/12 23:47:49 1.234
+++ loncom/publisher/lonpublisher.pm 2008/08/14 13:39:02 1.245
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.234 2008/05/12 23:47:49 www Exp $
+# $Id: lonpublisher.pm,v 1.245 2008/08/14 13:39:02 onken Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -118,11 +118,14 @@ use Apache::File;
use File::Copy;
use Apache::Constants qw(:common :http :methods);
use HTML::LCParser;
+use HTML::Entities;
+use Encode::Encoder;
use Apache::lonxml;
use Apache::loncacc;
use DBI;
use Apache::lonnet;
use Apache::loncommon();
+use Apache::lonhtmlcommon;
use Apache::lonmysql;
use Apache::lonlocal;
use Apache::loncfile;
@@ -274,7 +277,7 @@ sub metaread {
}
&metaeval($metastring,$prefix);
return ''.&mt('Processed file').': '.
- &Apache::loncfile::display($fn).' ';
+ &Apache::loncfile::display($fn).' ';
}
#########################################
@@ -325,30 +328,34 @@ string which presents the form field (fo
#########################################
#########################################
sub textfield {
- my ($title,$name,$value)=@_;
+ my ($title,$name,$value,$noline)=@_;
$value=~s/^\s+//gs;
$value=~s/\s+$//gs;
$value=~s/\s+/ /gs;
$title=&mt($title);
$env{'form.'.$name}=$value;
- return "\n
$title:".
- "
".
- ' ';
+ return "\n".&Apache::lonhtmlcommon::row_title($title)
+ .' '
+ .&Apache::lonhtmlcommon::row_closure($noline);
}
sub text_with_browse_field {
- my ($title,$name,$value,$restriction)=@_;
+ my ($title,$name,$value,$restriction,$noline)=@_;
$value=~s/^\s+//gs;
$value=~s/\s+$//gs;
$value=~s/\s+/ /gs;
$title=&mt($title);
$env{'form.'.$name}=$value;
- return "\n$title:".
- "
".
- ' '.
- ''.&mt('Select').' '.
- ''.&mt('Search').' ';
-
+ return "\n".&Apache::lonhtmlcommon::row_title($title)
+ .' '
+ .' '
+ .''
+ .&mt('Select')
+ .' '
+ .''
+ .&mt('Search')
+ .' '
+ .&Apache::lonhtmlcommon::row_closure($noline);
}
sub hiddenfield {
@@ -372,8 +379,8 @@ sub selectbox {
} else {
$env{'form.'.$name}=$idlist[0];
}
- my $selout="\n$title:".
- '
';
+ my $selout="\n".&Apache::lonhtmlcommon::row_title($title)
+ .'';
foreach (@idlist) {
$selout.=''.&{$functionref}($_).' ';}
}
- return $selout.' ';
+ $selout.=' '.&Apache::lonhtmlcommon::row_closure();
+ return $selout;
}
sub select_level_form {
@@ -665,6 +673,7 @@ sub fix_ids_and_indices {
"Max Index: $maxindex (min 10)\n";
}
my $outstring='';
+ my $responsecounter=1;
my @parser;
$parser[0]=HTML::LCParser->new(\$content);
$parser[-1]->xml_mode(1);
@@ -680,6 +689,10 @@ sub fix_ids_and_indices {
next;
}
if ($lctag eq 'base') { next; }
+ if (($lctag eq 'part') || ($lctag eq 'problem')) {
+ $responsecounter=0;
+ }
+ if ($lctag=~/response$/) { $responsecounter++; }
my %parms=%{$token->[2]};
$counter=$addid{$tag};
if (!$counter) { $counter=$addid{$lctag}; }
@@ -775,7 +788,7 @@ sub fix_ids_and_indices {
}
if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
$outstring.='<'.$tag.$newparmstring.$endtag.'>';
- if ($lctag eq 'm' || $lctag eq 'script'
+ if ($lctag eq 'm' || $lctag eq 'script' || $lctag eq 'answer'
|| $lctag eq 'display' || $lctag eq 'tex') {
$outstring.=&get_all_text_unbalanced('/'.$lctag,\@parser);
}
@@ -784,7 +797,12 @@ sub fix_ids_and_indices {
unless ($token->[1] eq 'allow') {
$outstring.=''.$token->[1].'>';
}
- }
+ }
+ if ((($token->[1] eq 'part') || ($token->[1] eq 'problem'))
+ && (!$responsecounter)) {
+ my $outstring=''.&mt('Found [_1] without responses. This resource cannot be published.',$token->[1]).' ';
+ return ($outstring,1);
+ }
} else {
$outstring.=$token->[1];
}
@@ -840,8 +858,7 @@ sub store_metadata {
return ($error,undef);
}
my $dbh = &Apache::lonmysql::get_dbh();
- if (($metadata{'obsolete'}) || ($metadata{'copyright'} eq 'priv') ||
- ($metadata{'copyright'} eq 'custom')) {
+ if (($metadata{'obsolete'}) || ($metadata{'copyright'} eq 'priv')) {
# remove this entry
my $delitem = 'url = '.$dbh->quote($metadata{'url'});
$status = &LONCAPA::lonmetadata::delete_metadata($dbh,undef,$delitem);
@@ -872,17 +889,21 @@ sub checkonthis {
'return_only_error_and_warning_counts' => 1));
my ($errorcount,$warningcount)=split(':',$result);
if (($errorcount) || ($warningcount)) {
- $r->print(''.$uri.' : ');
- if ($errorcount) {
- $r->print(''.
- $errorcount.' '.
- &mt('error(s)').' ');
- }
- if ($warningcount) {
- $r->print(''.
- $warningcount.' '.
- &mt('warning(s)').' ');
- }
+ $r->print(''.&mt('Warnings and Errors').' ');
+ $r->print(''.$uri.' :');
+ $r->print('');
} else {
#$r->print(''.&mt('ok').' ');
}
@@ -954,7 +975,7 @@ 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 ",1);
+ return ("".&mt("Failed to write backup copy, [_1], FAIL",$1)." ",1);
}
# ------------------------------------------------------------- IDs and indices
@@ -1030,7 +1051,7 @@ sub publish {
unless ($batch) {
$scrout.=''.&mt('Metadata Information').' ' .
- Apache::loncommon::help_open_topic("Metadata_Description")
+ &Apache::loncommon::help_open_topic("Metadata_Description")
. ' ';
}
@@ -1153,17 +1174,22 @@ sub publish {
$textonly=~s/\
-$KEYWORDS:
- $keywords_help
-
-
-
-
END
- $keywordout.='';
+ $keywordout.=&Apache::loncommon::end_data_table_row()
+ .&Apache::loncommon::end_data_table()
+ .&Apache::lonhtmlcommon::row_closure();
$intr_scrout.=$keywordout;
@@ -1249,28 +1293,24 @@ END
$intr_scrout.=&textfield('Notes','notes',$metadatafields{'notes'});
- $intr_scrout.=
- "\n".&mt('Abstract').":".
- "
".
- '';
+ $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title(&mt('Abstract'))
+ .''
+ .&Apache::lonhtmlcommon::row_closure();
$source=~/\.(\w+)$/;
+ $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title(&mt('Grade Levels'))
+ .&mt('Lowest Grade Level:').' '
+ .&select_level_form($metadatafields{'lowestgradelevel'},'lowestgradelevel')
+# .&Apache::lonhtmlcommon::row_closure();
+# $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title(&mt('Highest Grade Level'))
+ .' '.&mt('Highest Grade Level:').' '
+ .&select_level_form($metadatafields{'highestgradelevel'},'highestgradelevel')
+ .&Apache::lonhtmlcommon::row_closure();
- $intr_scrout.=
- "\n".
- &mt('Lowest Grade Level').':'.
- "
".
- &select_level_form($metadatafields{'lowestgradelevel'},'lowestgradelevel').
- "\n".
- &mt('Highest Grade Level').':'.
- "
".
- &select_level_form($metadatafields{'highestgradelevel'},'highestgradelevel').
- &textfield('Standards','standards',$metadatafields{'standards'});
-
-
-
+ $intr_scrout.=&textfield('Standards','standards',$metadatafields{'standards'});
$intr_scrout.=&hiddenfield('mime',$1);
@@ -1293,9 +1333,12 @@ END
$intr_scrout.=&hiddenfield('lastrevisiondate',time);
-
+ my $pubowner_last;
+ if ($style eq 'prv') {
+ $pubowner_last = 1;
+ }
$intr_scrout.=&textfield('Publisher/Owner','owner',
- $metadatafields{'owner'});
+ $metadatafields{'owner'},$pubowner_last);
# ---------------------------------------------- Retrofix for unused copyright
if ($metadatafields{'copyright'} eq 'free') {
@@ -1329,25 +1372,24 @@ END
(grep !/^priv$/,(&Apache::loncommon::copyrightids)));
}
my $copyright_help =
- Apache::loncommon::help_open_topic('Publishing_Copyright');
- $intr_scrout =~ s/Distribution:/'Distribution: ' . $copyright_help/ge;
- $intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights').$copyright_help;
+ &Apache::loncommon::help_open_topic('Publishing_Copyright');
+ my $replace=&mt('Copyright/Distribution:');
+ $intr_scrout =~ s/$replace/$replace.' '.$copyright_help/ge;
+
+ $intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights');
$intr_scrout.=&selectbox('Source Distribution','sourceavail',
$defaultsourceoption,
\&Apache::loncommon::source_copyrightdescription,
(&Apache::loncommon::source_copyrightids));
# $intr_scrout.=&text_with_browse_field('Source Custom Distribution File','sourcerights',$metadatafields{'sourcerights'},'rights');
my $uctitle=&mt('Obsolete');
- $intr_scrout.=
- "\n$uctitle:".
- '
'.
- &text_with_browse_field('Suggested Replacement for Obsolete File',
+ my $obsolete_checked=($metadatafields{'obsolete'})?' checked="1" ':'';
+ $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title($uctitle)
+ .' '
+ .&Apache::lonhtmlcommon::row_closure(1);
+ $intr_scrout.=&text_with_browse_field('Suggested Replacement for Obsolete File',
'obsoletereplacement',
- $metadatafields{'obsoletereplacement'});
+ $metadatafields{'obsoletereplacement'},'',1);
} else {
$intr_scrout.=&hiddenfield('copyright','private');
}
@@ -1373,11 +1415,15 @@ END
&hiddenfield('obsolete',1).
&text_with_browse_field('Suggested Replacement for Obsolete File',
'obsoletereplacement',
- $metadatafields{'obsoletereplacement'});
+ $metadatafields{'obsoletereplacement'},'',1);
}
if (!$batch) {
- $scrout.=$intr_scrout.'
';
+ $scrout.=$intr_scrout
+ .&Apache::lonhtmlcommon::end_pick_box()
+ .'
'
+ .'';
}
return($scrout,0);
}
@@ -1579,7 +1625,7 @@ sub phasetwo {
unless ($srcd=~/^\/home\/httpd\/html\/res/) {
print $logfile "\nPANIC: Target dir is ".$srcd;
$r->print(
- "Invalid target directory, FAIL ");
+ "".&mt('Invalid target directory, FAIL')." ");
return 0;
}
opendir(DIR,$srcd);
@@ -1701,7 +1747,7 @@ sub phasetwo {
$r->print(
''.
&mt('View Published Version').' '.
- ''.
+ ''.
&mt('Back to Source').'
'.
''.
@@ -2104,28 +2150,55 @@ sub handler {
my $thistype=$1;
my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
if ($thistype eq 'page') { $thisembstyle = 'rat'; }
- $r->print(''.&mt('Publishing').' '.
- &Apache::loncommon::filedescription($thistype).' ');
+ $r->print(''.&mt('Publishing [_1]',''.$thisdisfn.' ').' ');
+
+ $r->print(''.&mt('Resource Details').' ');
+
+ $r->print(&Apache::lonhtmlcommon::start_pick_box());
+
+ $r->print(&Apache::lonhtmlcommon::row_title(&mt('Type'))
+ .&Apache::loncommon::filedescription($thistype)
+ .&Apache::lonhtmlcommon::row_closure()
+ );
+
+ $r->print(&Apache::lonhtmlcommon::row_title(&mt('Link to Resource'))
+ .''
+ );
$r->print(<
$thisdisfn
ENDCAPTION
- $r->print(''.&mt('Target').': '.
- $thisdistarget.' ');
-
+ $r->print(''
+ .&Apache::lonhtmlcommon::row_closure()
+ );
+
+ $r->print(&Apache::lonhtmlcommon::row_title(&mt('Target'))
+ .''.$thisdistarget.' '
+ );
+# SB - ToDo:
if (($cuname ne $env{'user.name'})||($cudom ne $env{'user.domain'})) {
- $r->print('
'.&mt('Co-Author').': '.
- $cuname.&mt(' at ').$cudom.' ');
+# $r->print(&Apache::lonhtmlcommon::row_title(''.&mt('Co-Author').' ')
+ $r->print(&Apache::lonhtmlcommon::row_closure()
+ .&Apache::lonhtmlcommon::row_title(&mt('Co-Author'))
+ .''
+ .&mt('[_1] at [_2]',$cuname,$cudom)
+ .' '
+ );
}
if (&Apache::loncommon::fileembstyle($thistype) eq 'ssi') {
+ $r->print(&Apache::lonhtmlcommon::row_closure()
+ .&Apache::lonhtmlcommon::row_title(&mt('Diffs')));
$r->print(<
ENDDIFF
- $r->print(&mt('Diffs with Current Version').' ');
+ $r->print(&mt('Diffs with Current Version').' ');
}
+
+ $r->print(&Apache::lonhtmlcommon::row_closure(1)
+ .&Apache::lonhtmlcommon::end_pick_box()
+ );
# ------------------ Publishing from $thisfn to $thistarget with $thisembstyle.
@@ -2140,7 +2213,7 @@ ENDDIFF
&publish($thisfn,$thistarget,$thisembstyle);
$r->print('
'.$outstring);
} else {
- $r->print(''.
+ $r->print(''.
&mt('The document contains errors and cannot be published.').
' ');
}