--- loncom/publisher/lonpublisher.pm 2003/12/22 21:57:25 1.148 +++ loncom/publisher/lonpublisher.pm 2004/01/05 22:29:51 1.161 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Publication Handler # -# $Id: lonpublisher.pm,v 1.148 2003/12/22 21:57:25 albertel Exp $ +# $Id: lonpublisher.pm,v 1.161 2004/01/05 22:29:51 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,24 +25,6 @@ # # http://www.lon-capa.org/ # -# -# (TeX Content Handler -# -# 05/29/00,05/30,10/11 Gerd Kortemeyer) -# -# 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer -# 03/23 Guy Albertelli -# 03/24,03/29,04/03 Gerd Kortemeyer -# 05/03,05/05,05/07 Gerd Kortemeyer -# 06/23,08/07,08/11,8/13,8/17,8/18,8/24,9/26,10/16 Gerd Kortemeyer -# 12/04,12/05 Guy Albertelli -# 12/05 Gerd Kortemeyer -# 12/05 Guy Albertelli -# 12/06,12/07 Gerd Kortemeyer -# 12/25 Gerd Kortemeyer -# YEAR=2002 -# 1/17 Gerd Kortemeyer -# ### ############################################################################### @@ -144,6 +126,8 @@ use Apache::loncommon(); use Apache::lonmysql; use Apache::lonlocal; use Apache::loncfile; +use Apache::lonmeta; +use Apache::lonmsg; use vars qw(%metadatafields %metadatakeys); my %addid; @@ -219,9 +203,8 @@ sub metaeval { $newentry=~s/^\s*//; if ($newentry !~m|^/res|) { $newentry=$prefix.$newentry; } } - unless ($metadatafields{$unikey}=~/\w/) { - $metadatafields{$unikey}=$newentry; - } +# actually store + $metadatafields{$unikey}=$newentry; } } } @@ -335,8 +318,7 @@ sub textfield { $value=~s/\s+$//gs; $value=~s/\s+/ /gs; $title=&mt($title); - my $uctitle=uc($title); - return "\n

$uctitle:". + return "\n

$title:". "


". ''; } @@ -349,9 +331,8 @@ sub hiddenfield { sub selectbox { my ($title,$name,$value,$functionref,@idlist)=@_; $title=&mt($title); - my $uctitle=uc($title); $value=(split(/\s*,\s*/,$value))[-1]; - my $selout="\n

$uctitle:". + my $selout="\n

$title:". '


'; $source=~/\.(\w+)$/; + + $scrout.= + "\n

". + &mt('Lowest Grade Level').':'. + "


". + &Apache::loncommon::select_level_form($metadatafields{'lowestgradelevel'},'lowestgradelevel'). + "\n

". + &mt('Highest Grade Level').':'. + "


". + &Apache::loncommon::select_level_form($metadatafields{'highestgradelevel'},'highestgradelevel'). + &textfield('Standards','standards',$metadatafields{'standards'}); + + + + $scrout.=&hiddenfield('mime',$1); my $defaultlanguage=$metadatafields{'language'}; @@ -1180,7 +1202,7 @@ END $metadatafields{'creationdate'}=time; } $scrout.=&hiddenfield('creationdate', - &Apache::loncommon::unsqltime($metadatafields{'creationdate'})); + &Apache::lonmysql::unsqltime($metadatafields{'creationdate'})); $scrout.=&hiddenfield('lastrevisiondate',time); @@ -1214,7 +1236,7 @@ END $scrout.=&textfield('Custom Distribution File','customdistributionfile', $metadatafields{'customdistributionfile'}). $copyright_help; - my $uctitle=uc(&mt('Obsolete')); + my $uctitle=&mt('Obsolete'); $scrout.= "\n

$uctitle:". ' '.&mt('No valid custom distribution rights file specified, FAIL'). + ''; + } + } { print $logfile "\nWrite metadata file for ".$source; my $mfh; @@ -1390,21 +1427,19 @@ sub phasetwo { $metadatafields{'url'} = $distarget; $metadatafields{'version'} = 'current'; - unless ($metadatafields{'copyright'} eq 'priv') { - my ($error,$success) = &store_metadata(\%metadatafields); - if ($success) { - $r->print('

'.&mt('Synchronized SQL metadata database').'

'); - print $logfile "\nSynchronized SQL metadata database"; - } else { - $r->print($error); - print $logfile "\n".$error; - } + + my ($error,$success) = &store_metadata(%metadatafields); + if ($success) { + $r->print('

'.&mt('Synchronized SQL metadata database').'

'); + print $logfile "\nSynchronized SQL metadata database"; } else { - $r->print('

'. - &mt('Private Publication - did not synchronize database').'

'); - print $logfile "\nPrivate: Did not synchronize data into ". - "SQL metadata database"; + $r->print($error); + print $logfile "\n".$error; } +# --------------------------------------------- Delete author resource messages + my $delresult=&Apache::lonmsg::del_url_author_res_msg($target); + $r->print('

'.&mt('Removing error messages:').' '.$delresult.'

'); + print $logfile "\nRemoving error messages: $delresult"; # ----------------------------------------------------------- Copy old versions if (-e $target) { @@ -1562,6 +1597,7 @@ sub phasetwo { '">'. &mt('Back to Source Directory').'

'); } + return '

'.&mt('Done').'

'; } ######################################### @@ -1616,8 +1652,8 @@ sub publishdirectory { my $resdir= $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cudom.'/'.$cuname.'/'. $thisdisfn; - $r->print('

Directory '.$thisdisfn.'

'. - 'Target: '.$resdir.'
'); + $r->print('

'.&mt('Directory').' '.$thisdisfn.'

'. + &mt('Target').': '.$resdir.'
'); my $dirptr=16384; # Mask indicating a directory in stat.cmode. @@ -1655,13 +1691,70 @@ sub publishdirectory { if ($publishthis) { &batchpublish($r,$fn.'/'.$filename,$resdir.'/'.$filename); } else { - $r->print('
Skipping '.$filename.'
'); + $r->print('
'.&mt('Skipping').' '.$filename.'
'); } $r->rflush(); } } closedir(DIR); } + +######################################### +# publish a default.meta file + +sub defaultmetapublish { + my ($r,$fn,$cuname,$cudom)=@_; + $fn=~s/^\/\~$cuname\//\/home\/$cuname\/public_html\//; + unless (-e $fn) { + return HTTP_NOT_FOUND; + } + my $target=$fn; + $target=~s/^\/home\/$cuname\/public_html\//$Apache::lonnet::perlvar{'lonDocRoot'}\/res\/$cudom\/$cuname\//; + + + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + + $r->print('LON-CAPA Publishing'); + $r->print(&Apache::loncommon::bodytag('Catalog Information Publication')); + +# ---------------------------------------------------------------- Write Source + my $copyfile=$target; + + my @parts=split(/\//,$copyfile); + my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]"; + + my $count; + for ($count=5;$count<$#parts;$count++) { + $path.="/$parts[$count]"; + if ((-e $path)!=1) { + $r->print('

'.&mt('Created directory').' '.$parts[$count].'

'); + mkdir($path,0777); + } + } + + if (copy($fn,$copyfile)) { + $r->print('

'.&mt('Copied source file').'

'); + } else { + return "". + &mt('Failed to copy source').", $!, ".&mt('FAIL').""; + } + +# --------------------------------------------------- Send update notifications + + my @subscribed=&get_subscribed_hosts($target); + foreach my $subhost (@subscribed) { + $r->print('

'.&mt('Notifying host').' '.$subhost.':');$r->rflush; + my $reply=&Apache::lonnet::critical('update:'.$target,$subhost); + $r->print($reply.'


');$r->rflush; + } +# ------------------------------------------------------------------- Link back + my $link=$fn; + $link=~s/^\/home\/$cuname\/public_html\//\/priv\/$cuname\//; + $r->print("".&mt('Back to Catalog Information').''); + $r->print(''); + return OK; +} ######################################### =pod @@ -1720,6 +1813,14 @@ sub handler { my $fn=&Apache::lonnet::unescape($ENV{'form.filename'}); + ($cuname,$cudom)= + &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); + +# special publication: default.meta file + if ($fn=~/\/default.meta$/) { + return &defaultmetapublish($r,$fn,$cuname,$cudom); + } + $fn=~s/\.meta$//; unless ($fn) { $r->log_reason($cuname.' at '.$cudom. @@ -1727,8 +1828,6 @@ sub handler { return HTTP_NOT_FOUND; } - ($cuname,$cudom)= - &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); unless (($cuname) && ($cudom)) { $r->log_reason($cuname.' at '.$cudom. ' trying to publish file '.$ENV{'form.filename'}. @@ -1861,8 +1960,8 @@ ENDDIFF my ($outstring,$error)=&publish($thisfn,$thistarget,$thisembstyle); $r->print('
'.$outstring); } else { - $r->print('
'); - &phasetwo($r,$thisfn,$thistarget,$thisembstyle,$thisdistarget); + $r->print('
'. + &phasetwo($r,$thisfn,$thistarget,$thisembstyle,$thisdistarget)); } } $r->print('');