--- loncom/publisher/lonpublisher.pm 2008/06/27 18:52:35 1.238 +++ loncom/publisher/lonpublisher.pm 2008/12/07 23:49:40 1.249 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Publication Handler # -# $Id: lonpublisher.pm,v 1.238 2008/06/27 18:52:35 bisitz Exp $ +# $Id: lonpublisher.pm,v 1.249 2008/12/07 23:49:40 www 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; @@ -263,8 +266,9 @@ sub metaread { my ($logfile,$fn,$prefix)=@_; unless (-e $fn) { print($logfile 'No file '.$fn."\n"); - return '
'.&mt('No file').': '. - &Apache::loncfile::display($fn).''; + return '
' + .&mt('No file: [_1]' + ,' '.&Apache::loncfile::display($fn).'
'); } print($logfile 'Processing '.$fn."\n"); my $metastring; @@ -273,8 +277,9 @@ sub metaread { $metastring=join('',<$metafh>); } &metaeval($metastring,$prefix); - return '
'.&mt('Processed file').': '. - &Apache::loncfile::display($fn).''; + return '
' + .&mt('Processed file: [_1]' + ,' '.&Apache::loncfile::display($fn).'
'); } ######################################### @@ -325,7 +330,7 @@ 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; @@ -333,11 +338,11 @@ sub textfield { $env{'form.'.$name}=$value; return "\n".&Apache::lonhtmlcommon::row_title($title) .'' - .&Apache::lonhtmlcommon::row_closure(); + .&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; @@ -352,7 +357,7 @@ sub text_with_browse_field { .'' .&mt('Search') .'' - .&Apache::lonhtmlcommon::row_closure(); + .&Apache::lonhtmlcommon::row_closure($noline); } sub hiddenfield { @@ -690,6 +695,7 @@ sub fix_ids_and_indices { $responsecounter=0; } if ($lctag=~/response$/) { $responsecounter++; } + if ($lctag eq 'import') { $responsecounter++; } my %parms=%{$token->[2]}; $counter=$addid{$tag}; if (!$counter) { $counter=$addid{$lctag}; } @@ -797,7 +803,7 @@ sub fix_ids_and_indices { } if ((($token->[1] eq 'part') || ($token->[1] eq 'problem')) && (!$responsecounter)) { - my $outstring=''.&mt('Found [_1] without responses',$token->[1]).''; + my $outstring=''.&mt('Found [_1] without responses. This resource cannot be published.',$token->[1]).''; return ($outstring,1); } } else { @@ -842,15 +848,17 @@ sub store_metadata { # Determine if the table exists my $status = &Apache::lonmysql::check_table('metadata'); if (! defined($status)) { - $error='WARNING: Cannot connect to '. - 'database!'; + $error='' + .&mt('WARNING: Cannot connect to database!') + .''; &Apache::lonnet::logthis($error); return ($error,undef); } if ($status == 0) { # It would be nice to actually create the table.... - $error ='WARNING: The metadata table does not '. - 'exist in the LON-CAPA database.'; + $error ='' + .&mt('WARNING: The metadata table does not exist in the LON-CAPA database!') + .''; &Apache::lonnet::logthis($error); return ($error,undef); } @@ -865,8 +873,9 @@ sub store_metadata { \%metadata); } if (defined($status) && $status ne '') { - $error='Error occured saving new values in '. - 'metadata table in LON-CAPA database'; + $error='' + .&mt('Error occurred saving new values in metadata table in LON-CAPA database!') + .''; &Apache::lonnet::logthis($error); &Apache::lonnet::logthis($status); return ($error,undef); @@ -886,17 +895,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').''); } @@ -935,7 +948,7 @@ backup copies, performs any automatic pr 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 +user, the second is an error code, either 1 (an error occurred) or 0 (no error occurred) I @@ -968,7 +981,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 @@ -978,30 +991,30 @@ sub publish { if ($error) { return ($outstring,$error); } # ------------------------------------------------------------ Construct Allows - $scrout.='

'.&mt('Dependencies').'

'; + my $outdep=''; # Collect dependencies output data my $allowstr=''; foreach my $thisdep (sort(keys(%allow))) { if ($thisdep !~ /[^\s]/) { next; } if ($thisdep =~/\$/) { - $scrout.='
' + $outdep.='
' .&mt('The resource depends on another resource with variable filename, i.e., [_1].',''.$thisdep.'').'
' .&mt('You likely need to explicitly allow access to all possible dependencies using the [_1]-tag.','<allow>') - .'
'; + ."
\n"; } unless ($style eq 'rat') { $allowstr.="\n".''; } - $scrout.='
'; + $outdep.='
'; if ($thisdep!~/[\*\$]/ && $thisdep!~m|^/adm/|) { - $scrout.=''; + $outdep.=''; } - $scrout.=''.$thisdep.''; + $outdep.=''.$thisdep.''; if ($thisdep!~/[\*\$]/ && $thisdep!~m|^/adm/|) { - $scrout.=''; + $outdep.=''; if ( &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.'/'. $thisdep.'.meta') eq '-1') { - $scrout.= ' - '.&mt('Currently not available'). + $outdep.= ' - '.&mt('Currently not available'). ''; } else { my %temphash=(&Apache::lonnet::declutter($target).'___'. @@ -1014,6 +1027,12 @@ sub publish { } } } + $outdep.='

'; + } + + if ($outdep) { + $scrout.='

'.&mt('Dependencies').'

' + .$outdep } $outstring=~s/\n*(\<\/[^\>]+\>[^<]*)$/$allowstr\n$1\n/s; @@ -1044,7 +1063,7 @@ sub publish { unless ($batch) { $scrout.='

'.&mt('Metadata Information').' ' . - Apache::loncommon::help_open_topic("Metadata_Description") + &Apache::loncommon::help_open_topic("Metadata_Description") . '

'; } @@ -1167,17 +1186,22 @@ sub publish { $textonly=~s/\//g; $textonly=~s/\[^\<]+\<\/m\>//g; $textonly=~s/\<[^\>]*\>//g; - $textonly=~tr/A-Z/a-z/; - $textonly=~s/[\$\&][a-z]\w*//g; - $textonly=~s/[^a-z\s]//g; - - foreach ($textonly=~m/(\w+)/g) { - unless ($nokey{$_}) { - $keywords{$_}=1; - } - } - } + #this is a work simplification for german authors for present + $textonly=HTML::Entities::decode($textonly); #decode HTML-character + $textonly=Encode::Encoder::encode('utf8', $textonly); #encode to perl internal unicode + $textonly=~tr/A-ZÜÄÖ/a-züäö/; #add lowercase rule for german "Umlaute" + $textonly=~s/[\$\&][a-z]\w*//g; + $textonly=~s/[^a-z^ü^ä^ö^ß\s]//g; #dont delete german "Umlaute" + + foreach ($textonly=~m/[^\s]+/g) { #match all but whitespaces + unless ($nokey{$_}) { + $keywords{$_}=1; + } + } + + + } foreach my $addkey (split(/[\"\'\,\;]/,$metadatafields{'keywords'})) { $addkey=~s/\s+/ /g; @@ -1195,15 +1219,17 @@ sub publish { # $env{'from.'..} so that it can be used by the phase two handler in # batch mode - my $intr_scrout.=&Apache::lonhtmlcommon::start_pick_box() + my $intr_scrout.='
' .'
'; unless ($env{'form.makeobsolete'}) { - $intr_scrout.=&Apache::lonhtmlcommon::row_title() - .'' + .&mt('Searching for your resource will be based on the following metadata. Please provide as much data as possible.') + .'

' + .'

' - .&Apache::lonhtmlcommon::row_closure() + .'" />

'; } + $intr_scrout.=&Apache::lonhtmlcommon::start_pick_box(); $intr_scrout.= &hiddenfield('phase','two'). &hiddenfield('filename',$env{'form.filename'}). @@ -1235,30 +1261,48 @@ END .'' .'' .'


' - .''; + .&Apache::loncommon::start_data_table(); + my $cols_per_row = 10; my $colcount=0; + my $wordcount=0; + my $numkeywords = scalar(keys(%keywords)); - foreach (sort keys %keywords) { - $keywordout.=''; - if ($colcount>10) { - $keywordout.="\n"; - $colcount=0; - } - $colcount++; + foreach my $word (sort(keys(%keywords))) { + if ($colcount == 0) { + $keywordout .= &Apache::loncommon::start_data_table_row(); + } + $colcount++; + $wordcount++; + if (($wordcount == $numkeywords) && ($colcount < $cols_per_row)) { + my $colspan = 1+$cols_per_row-$colcount; + $keywordout .= ''; + if ($colcount == $cols_per_row) { + $keywordout.=&Apache::loncommon::end_data_table_row(); + $colcount=0; + } } + if ($colcount > 0) { + $keywordout .= &Apache::loncommon::end_data_table_row(); + } + $env{'form.keywords'}=~s/\,$//; - $keywordout.='
'; + } else { + $keywordout .= ''; + } + $keywordout.='
' + $keywordout.=&Apache::loncommon::end_data_table_row() + .&Apache::loncommon::end_data_table() .&Apache::lonhtmlcommon::row_closure(); $intr_scrout.=$keywordout; @@ -1307,9 +1351,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') { @@ -1360,7 +1407,7 @@ END .&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'); } @@ -1386,16 +1433,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 - .&Apache::lonhtmlcommon::row_title() - .''.&Apache::lonhtmlcommon::row_closure() - .'
' - .&Apache::lonhtmlcommon::end_pick_box(); + .'" />

' + .''; } return($scrout,0); } @@ -1597,7 +1643,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); @@ -2122,28 +2168,53 @@ 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.'' + ); 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_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. @@ -2156,9 +2227,9 @@ ENDDIFF unless ($errorcount) { my ($outstring,$error)= &publish($thisfn,$thistarget,$thisembstyle); - $r->print('
'.$outstring); + $r->print($outstring); } else { - $r->print('

'. + $r->print('

'. &mt('The document contains errors and cannot be published.'). '

'); }