Annotation of loncom/publisher/lonpublisher.pm, revision 1.287
1.1 www 1: # The LearningOnline Network with CAPA
2: # Publication Handler
1.54 albertel 3: #
1.287 ! raeburn 4: # $Id: lonpublisher.pm,v 1.286 2013/10/16 18:28:18 raeburn Exp $
1.54 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.65 harris41 28: ###
29:
30: ###############################################################################
31: ## ##
32: ## ORGANIZATION OF THIS PERL MODULE ##
33: ## ##
34: ## 1. Modules used by this module ##
35: ## 2. Various subroutines ##
36: ## 3. Publication Step One ##
37: ## 4. Phase Two ##
38: ## 5. Main Handler ##
39: ## ##
40: ###############################################################################
1.1 www 41:
1.90 matthew 42:
43: ######################################################################
44: ######################################################################
45:
46: =pod
47:
1.94 harris41 48: =head1 NAME
1.90 matthew 49:
50: lonpublisher - LON-CAPA publishing handler
51:
1.94 harris41 52: =head1 SYNOPSIS
1.90 matthew 53:
1.94 harris41 54: B<lonpublisher> is used by B<mod_perl> inside B<Apache>. This is the
55: invocation by F<loncapa_apache.conf>:
56:
57: <Location /adm/publish>
58: PerlAccessHandler Apache::lonacc
59: SetHandler perl-script
60: PerlHandler Apache::lonpublisher
61: ErrorDocument 403 /adm/login
62: ErrorDocument 404 /adm/notfound.html
63: ErrorDocument 406 /adm/unauthorized.html
64: ErrorDocument 500 /adm/errorhandler
65: </Location>
1.127 bowersj2 66:
67: =head1 OVERVIEW
68:
1.274 raeburn 69: Authors can only write-access the C</priv/domain/authorname/> space.
70: They can copy resources into the resource area through the
71: publication step, and move them back through a recover step.
72: Authors do not have direct write-access to their resource space.
1.127 bowersj2 73:
74: During the publication step, several events will be
75: triggered. Metadata is gathered, where a wizard manages default
76: entries on a hierarchical per-directory base: The wizard imports the
77: metadata (including access privileges and royalty information) from
78: the most recent published resource in the current directory, and if
79: that is not available, from the next directory above, etc. The Network
80: keeps all previous versions of a resource and makes them available by
81: an explicit version number, which is inserted between the file name
82: and extension, for example C<foo.2.html>, while the most recent
83: version does not carry a version number (C<foo.html>). Servers
84: subscribing to a changed resource are notified that a new version is
85: available.
1.94 harris41 86:
87: =head1 DESCRIPTION
88:
89: B<lonpublisher> takes the proper steps to add resources to the LON-CAPA
1.90 matthew 90: digital library. This includes updating the metadata table in the
91: LON-CAPA database.
92:
1.94 harris41 93: B<lonpublisher> is many things to many people.
1.90 matthew 94:
95: This module publishes a file. This involves gathering metadata,
96: versioning the file, copying file from construction space to
97: publication space, and copying metadata from construction space
98: to publication space.
99:
1.94 harris41 100: =head2 SUBROUTINES
101:
102: Many of the undocumented subroutines implement various magical
103: parsing shortcuts.
1.90 matthew 104:
105: =cut
106:
107: ######################################################################
108: ######################################################################
109:
110:
1.1 www 111: package Apache::lonpublisher;
112:
1.65 harris41 113: # ------------------------------------------------- modules used by this module
1.1 www 114: use strict;
115: use Apache::File;
1.13 www 116: use File::Copy;
1.2 www 117: use Apache::Constants qw(:common :http :methods);
1.76 albertel 118: use HTML::LCParser;
1.245 onken 119: use HTML::Entities;
120: use Encode::Encoder;
1.4 www 121: use Apache::lonxml;
1.24 harris41 122: use DBI;
1.192 albertel 123: use Apache::lonnet;
1.65 harris41 124: use Apache::loncommon();
1.241 raeburn 125: use Apache::lonhtmlcommon;
1.89 matthew 126: use Apache::lonmysql;
1.134 www 127: use Apache::lonlocal;
1.145 albertel 128: use Apache::loncfile;
1.166 matthew 129: use LONCAPA::lonmetadata;
1.159 www 130: use Apache::lonmsg;
1.105 www 131: use vars qw(%metadatafields %metadatakeys);
1.215 albertel 132: use LONCAPA qw(:DEFAULT :match);
1.209 www 133:
1.2 www 134:
1.3 www 135: my %addid;
1.5 www 136: my %nokey;
1.10 www 137:
1.12 www 138: my $docroot;
139:
1.27 www 140: my $cuname;
141: my $cudom;
142:
1.182 www 143: my $registered_cleanup;
1.183 www 144: my $modified_urls;
1.182 www 145:
1.233 www 146: my $lock;
147:
1.90 matthew 148: =pod
149:
1.287 ! raeburn 150: =over 4
! 151:
1.94 harris41 152: =item B<metaeval>
153:
154: Evaluates a string that contains metadata. This subroutine
155: stores values inside I<%metadatafields> and I<%metadatakeys>.
156: The hash key is a I<$unikey> corresponding to a unique id
157: that is descriptive of the parser location inside the XML tree.
158:
159: Parameters:
160:
161: =over 4
1.90 matthew 162:
1.94 harris41 163: =item I<$metastring>
164:
165: A string that contains metadata.
166:
167: =back
168:
169: Returns:
170:
171: nothing
1.90 matthew 172:
173: =cut
174:
175: #########################################
176: #########################################
1.144 www 177: #
178: # Modifies global %metadatafields %metadatakeys
179: #
180:
1.7 www 181: sub metaeval {
1.140 albertel 182: my ($metastring,$prefix)=@_;
1.7 www 183:
1.139 albertel 184: my $parser=HTML::LCParser->new(\$metastring);
185: my $token;
186: while ($token=$parser->get_token) {
187: if ($token->[0] eq 'S') {
188: my $entry=$token->[1];
189: my $unikey=$entry;
1.219 albertel 190: next if ($entry =~ m/^(?:parameter|stores)_/);
1.139 albertel 191: if (defined($token->[2]->{'package'})) {
1.219 albertel 192: $unikey.="\0package\0".$token->[2]->{'package'};
1.139 albertel 193: }
194: if (defined($token->[2]->{'part'})) {
1.219 albertel 195: $unikey.="\0".$token->[2]->{'part'};
1.139 albertel 196: }
197: if (defined($token->[2]->{'id'})) {
1.219 albertel 198: $unikey.="\0".$token->[2]->{'id'};
1.139 albertel 199: }
200: if (defined($token->[2]->{'name'})) {
1.219 albertel 201: $unikey.="\0".$token->[2]->{'name'};
1.139 albertel 202: }
203: foreach (@{$token->[3]}) {
204: $metadatafields{$unikey.'.'.$_}=$token->[2]->{$_};
205: if ($metadatakeys{$unikey}) {
206: $metadatakeys{$unikey}.=','.$_;
207: } else {
208: $metadatakeys{$unikey}=$_;
209: }
210: }
1.140 albertel 211: my $newentry=$parser->get_text('/'.$entry);
1.174 www 212: if (($entry eq 'customdistributionfile') ||
213: ($entry eq 'sourcerights')) {
1.140 albertel 214: $newentry=~s/^\s*//;
215: if ($newentry !~m|^/res|) { $newentry=$prefix.$newentry; }
216: }
1.149 www 217: # actually store
1.162 albertel 218: if ( $entry eq 'rule' && exists($metadatafields{$unikey})) {
219: $metadatafields{$unikey}.=','.$newentry;
220: } else {
221: $metadatafields{$unikey}=$newentry;
222: }
1.139 albertel 223: }
224: }
1.7 www 225: }
226:
1.90 matthew 227: #########################################
228: #########################################
229:
230: =pod
231:
1.94 harris41 232: =item B<metaread>
1.90 matthew 233:
234: Read a metadata file
235:
1.94 harris41 236: Parameters:
237:
238: =over
239:
240: =item I<$logfile>
241:
242: File output stream to output errors and warnings to.
243:
244: =item I<$fn>
245:
246: File name (including path).
247:
248: =back
249:
250: Returns:
251:
252: =over 4
253:
254: =item Scalar string (if successful)
255:
256: XHTML text that indicates successful reading of the metadata.
257:
258: =back
259:
1.90 matthew 260: =cut
261:
262: #########################################
263: #########################################
1.7 www 264: sub metaread {
1.140 albertel 265: my ($logfile,$fn,$prefix)=@_;
1.7 www 266: unless (-e $fn) {
1.94 harris41 267: print($logfile 'No file '.$fn."\n");
1.271 www 268: return '<p class="LC_warning">'
269: .&mt('No file: [_1]',&Apache::loncfile::display($fn))
270: .'</p>';
1.7 www 271: }
1.94 harris41 272: print($logfile 'Processing '.$fn."\n");
1.7 www 273: my $metastring;
274: {
1.140 albertel 275: my $metafh=Apache::File->new($fn);
276: $metastring=join('',<$metafh>);
1.7 www 277: }
1.140 albertel 278: &metaeval($metastring,$prefix);
1.271 www 279: return '<p class="LC_info">'
280: .&mt('Processed file: [_1]',&Apache::loncfile::display($fn))
281: .'</p>';
1.7 www 282: }
1.12 www 283:
1.90 matthew 284: #########################################
285: #########################################
286:
1.101 www 287: sub coursedependencies {
288: my $url=&Apache::lonnet::declutter(shift);
289: $url=~s/\.meta$//;
1.215 albertel 290: my ($adomain,$aauthor)=($url=~ m{^($match_domain)/($match_username)/});
291: my $regexp=quotemeta($url);
1.101 www 292: $regexp='___'.$regexp.'___course';
293: my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
294: $aauthor,$regexp);
295: my %courses=();
296: foreach (keys %evaldata) {
297: if ($_=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
298: $courses{$1}=1;
299: }
300: }
301: return %courses;
302: }
303: #########################################
304: #########################################
305:
306:
1.90 matthew 307: =pod
308:
1.94 harris41 309: =item Form-field-generating subroutines.
310:
311: For input parameters, these subroutines take in values
312: such as I<$name>, I<$value> and other form field metadata.
313: The output (scalar string that is returned) is an XHTML
314: string which presents the form field (foreseeably inside
315: <form></form> tags).
1.90 matthew 316:
317: =over 4
318:
1.94 harris41 319: =item B<textfield>
1.90 matthew 320:
1.94 harris41 321: =item B<hiddenfield>
1.90 matthew 322:
1.94 harris41 323: =item B<selectbox>
1.90 matthew 324:
325: =back
326:
327: =cut
328:
329: #########################################
330: #########################################
1.8 www 331: sub textfield {
1.240 raeburn 332: my ($title,$name,$value,$noline)=@_;
1.141 www 333: $value=~s/^\s+//gs;
334: $value=~s/\s+$//gs;
335: $value=~s/\s+/ /gs;
1.134 www 336: $title=&mt($title);
1.192 albertel 337: $env{'form.'.$name}=$value;
1.238 bisitz 338: return "\n".&Apache::lonhtmlcommon::row_title($title)
339: .'<input type="text" name="'.$name.'" size="80" value="'.$value.'" />'
1.240 raeburn 340: .&Apache::lonhtmlcommon::row_closure($noline);
1.11 www 341: }
342:
1.180 albertel 343: sub text_with_browse_field {
1.240 raeburn 344: my ($title,$name,$value,$restriction,$noline)=@_;
1.180 albertel 345: $value=~s/^\s+//gs;
346: $value=~s/\s+$//gs;
347: $value=~s/\s+/ /gs;
348: $title=&mt($title);
1.192 albertel 349: $env{'form.'.$name}=$value;
1.238 bisitz 350: return "\n".&Apache::lonhtmlcommon::row_title($title)
351: .'<input type="text" name="'.$name.'" size="80" value="'.$value.'" />'
352: .'<br />'
353: .'<a href="javascript:openbrowser(\'pubform\',\''.$name.'\',\''.$restriction.'\');">'
354: .&mt('Select')
355: .'</a> '
356: .'<a href="javascript:opensearcher(\'pubform\',\''.$name.'\');">'
357: .&mt('Search')
358: .'</a>'
1.240 raeburn 359: .&Apache::lonhtmlcommon::row_closure($noline);
1.180 albertel 360: }
361:
1.11 www 362: sub hiddenfield {
363: my ($name,$value)=@_;
1.192 albertel 364: $env{'form.'.$name}=$value;
1.94 harris41 365: return "\n".'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
1.8 www 366: }
367:
1.193 www 368: sub checkbox {
369: my ($name,$text)=@_;
1.201 albertel 370: return "\n<br /><label><input type='checkbox' name='$name' /> ".
371: &mt($text)."</label>";
1.193 www 372: }
373:
1.9 www 374: sub selectbox {
1.65 harris41 375: my ($title,$name,$value,$functionref,@idlist)=@_;
1.134 www 376: $title=&mt($title);
1.123 albertel 377: $value=(split(/\s*,\s*/,$value))[-1];
1.167 albertel 378: if (defined($value)) {
1.192 albertel 379: $env{'form.'.$name}=$value;
1.167 albertel 380: } else {
1.192 albertel 381: $env{'form.'.$name}=$idlist[0];
1.167 albertel 382: }
1.238 bisitz 383: my $selout="\n".&Apache::lonhtmlcommon::row_title($title)
384: .'<select name="'.$name.'">';
1.65 harris41 385: foreach (@idlist) {
1.257 bisitz 386: $selout.='<option value="'.$_.'"';
1.65 harris41 387: if ($_ eq $value) {
1.257 bisitz 388: $selout.=' selected="selected"';
389: }
390: $selout.='>'.&{$functionref}($_).'</option>';
1.65 harris41 391: }
1.238 bisitz 392: $selout.='</select>'.&Apache::lonhtmlcommon::row_closure();
393: return $selout;
1.9 www 394: }
395:
1.167 albertel 396: sub select_level_form {
397: my ($value,$name)=@_;
1.192 albertel 398: $env{'form.'.$name}=$value;
399: if (!defined($value)) { $env{'form.'.$name}=0; }
1.167 albertel 400: return &Apache::loncommon::select_level_form($value,$name);
401: }
1.90 matthew 402: #########################################
403: #########################################
404:
405: =pod
406:
1.94 harris41 407: =item B<urlfixup>
1.90 matthew 408:
409: Fix up a url? First step of publication
1.12 www 410:
1.90 matthew 411: =cut
412:
413: #########################################
414: #########################################
1.34 www 415: sub urlfixup {
1.35 www 416: my ($url,$target)=@_;
1.39 www 417: unless ($url) { return ''; }
1.68 albertel 418: #javascript code needs no fixing
419: if ($url =~ /^javascript:/i) { return $url; }
1.69 albertel 420: if ($url =~ /^mailto:/i) { return $url; }
1.68 albertel 421: #internal document links need no fixing
422: if ($url =~ /^\#/) { return $url; }
1.223 albertel 423: my ($host)=($url=~m{(?:(?:http|https|ftp)://)*([^/]+)});
424: my @lonids = &Apache::lonnet::machine_ids($host);
425: if (@lonids) {
426: $url=~s{^(?:http|https|ftp)://}{};
427: $url=~s/^\Q$host\E//;
1.65 harris41 428: }
1.223 albertel 429: if ($url=~m{^(?:http|https|ftp)://}) { return $url; }
1.222 albertel 430: $url=~s{\Q~$cuname\E}{res/$cudom/$cuname};
1.71 www 431: return $url;
432: }
433:
1.90 matthew 434: #########################################
435: #########################################
436:
437: =pod
438:
1.94 harris41 439: =item B<absoluteurl>
1.90 matthew 440:
1.94 harris41 441: Currently undocumented.
1.90 matthew 442:
443: =cut
1.71 www 444:
1.90 matthew 445: #########################################
446: #########################################
1.71 www 447: sub absoluteurl {
448: my ($url,$target)=@_;
449: unless ($url) { return ''; }
1.35 www 450: if ($target) {
451: $target=~s/\/[^\/]+$//;
452: $url=&Apache::lonnet::hreflocation($target,$url);
453: }
454: return $url;
1.34 www 455: }
456:
1.90 matthew 457: #########################################
458: #########################################
459:
460: =pod
461:
1.94 harris41 462: =item B<set_allow>
1.90 matthew 463:
464: Currently undocumented
465:
466: =cut
467:
468: #########################################
469: #########################################
1.81 albertel 470: sub set_allow {
471: my ($allow,$logfile,$target,$tag,$oldurl)=@_;
472: my $newurl=&urlfixup($oldurl,$target);
473: my $return_url=$oldurl;
474: print $logfile 'GUYURL: '.$tag.':'.$oldurl.' - '.$newurl."\n";
475: if ($newurl ne $oldurl) {
476: $return_url=$newurl;
477: print $logfile 'URL: '.$tag.':'.$oldurl.' - '.$newurl."\n";
478: }
479: if (($newurl !~ /^javascript:/i) &&
480: ($newurl !~ /^mailto:/i) &&
1.220 albertel 481: ($newurl !~ /^(?:http|https|ftp):/i) &&
1.81 albertel 482: ($newurl !~ /^\#/)) {
483: $$allow{&absoluteurl($newurl,$target)}=1;
484: }
1.218 raeburn 485: return $return_url;
1.81 albertel 486: }
487:
1.90 matthew 488: #########################################
489: #########################################
490:
491: =pod
492:
1.94 harris41 493: =item B<get_subscribed_hosts>
1.90 matthew 494:
495: Currently undocumented
496:
497: =cut
498:
499: #########################################
500: #########################################
1.85 albertel 501: sub get_subscribed_hosts {
502: my ($target)=@_;
503: my @subscribed;
504: my $filename;
505: $target=~/(.*)\/([^\/]+)$/;
506: my $srcf=$2;
507: opendir(DIR,$1);
1.225 albertel 508: # cycle through listed files, subscriptions used to exist
509: # as "filename.lonid"
1.85 albertel 510: while ($filename=readdir(DIR)) {
1.216 albertel 511: if ($filename=~/\Q$srcf\E\.($match_lonid)$/) {
1.85 albertel 512: my $subhost=$1;
1.225 albertel 513: if (($subhost ne 'meta'
514: && $subhost ne 'subscription'
515: && $subhost ne 'meta.subscription'
516: && $subhost ne 'tmp') &&
1.98 www 517: ($subhost ne $Apache::lonnet::perlvar{'lonHostID'})) {
1.85 albertel 518: push(@subscribed,$subhost);
519: }
520: }
521: }
522: closedir(DIR);
523: my $sh;
524: if ( $sh=Apache::File->new("$target.subscription") ) {
525: while (my $subline=<$sh>) {
1.216 albertel 526: if ($subline =~ /^($match_lonid):/) {
1.98 www 527: if ($1 ne $Apache::lonnet::perlvar{'lonHostID'}) {
528: push(@subscribed,$1);
529: }
1.85 albertel 530: }
531: }
532: }
533: return @subscribed;
534: }
535:
1.86 albertel 536:
1.90 matthew 537: #########################################
538: #########################################
539:
540: =pod
541:
1.94 harris41 542: =item B<get_max_ids_indices>
1.90 matthew 543:
544: Currently undocumented
545:
546: =cut
547:
548: #########################################
549: #########################################
1.86 albertel 550: sub get_max_ids_indices {
551: my ($content)=@_;
552: my $maxindex=10;
553: my $maxid=10;
554: my $needsfixup=0;
1.106 albertel 555: my $duplicateids=0;
556:
557: my %allids;
558: my %duplicatedids;
1.86 albertel 559:
560: my $parser=HTML::LCParser->new($content);
1.207 albertel 561: $parser->xml_mode(1);
1.86 albertel 562: my $token;
563: while ($token=$parser->get_token) {
564: if ($token->[0] eq 'S') {
565: my $counter;
566: if ($counter=$addid{$token->[1]}) {
567: if ($counter eq 'id') {
1.186 albertel 568: if (defined($token->[2]->{'id'}) &&
569: $token->[2]->{'id'} !~ /^\s*$/) {
1.86 albertel 570: $maxid=($token->[2]->{'id'}>$maxid)?$token->[2]->{'id'}:$maxid;
1.106 albertel 571: if (exists($allids{$token->[2]->{'id'}})) {
572: $duplicateids=1;
573: $duplicatedids{$token->[2]->{'id'}}=1;
574: } else {
575: $allids{$token->[2]->{'id'}}=1;
576: }
1.86 albertel 577: } else {
578: $needsfixup=1;
579: }
580: } else {
1.186 albertel 581: if (defined($token->[2]->{'index'}) &&
582: $token->[2]->{'index'} !~ /^\s*$/) {
1.86 albertel 583: $maxindex=($token->[2]->{'index'}>$maxindex)?$token->[2]->{'index'}:$maxindex;
584: } else {
585: $needsfixup=1;
586: }
587: }
588: }
589: }
590: }
1.106 albertel 591: return ($needsfixup,$maxid,$maxindex,$duplicateids,
592: (keys(%duplicatedids)));
1.86 albertel 593: }
594:
1.90 matthew 595: #########################################
596: #########################################
597:
598: =pod
599:
1.94 harris41 600: =item B<get_all_text_unbalanced>
1.90 matthew 601:
602: Currently undocumented
603:
604: =cut
605:
606: #########################################
607: #########################################
1.87 albertel 608: sub get_all_text_unbalanced {
609: #there is a copy of this in lonxml.pm
610: my($tag,$pars)= @_;
611: my $token;
612: my $result='';
613: $tag='<'.$tag.'>';
614: while ($token = $$pars[-1]->get_token) {
615: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
616: $result.=$token->[1];
617: } elsif ($token->[0] eq 'PI') {
618: $result.=$token->[2];
619: } elsif ($token->[0] eq 'S') {
620: $result.=$token->[4];
621: } elsif ($token->[0] eq 'E') {
622: $result.=$token->[2];
623: }
1.177 albertel 624: if ($result =~ /\Q$tag\E/s) {
1.176 albertel 625: ($result,my $redo)=$result =~ /(.*)\Q$tag\E(.*)/is;
1.88 albertel 626: #&Apache::lonnet::logthis('Got a winner with leftovers ::'.$2);
627: #&Apache::lonnet::logthis('Result is :'.$1);
1.176 albertel 628: $redo=$tag.$redo;
1.87 albertel 629: push (@$pars,HTML::LCParser->new(\$redo));
630: $$pars[-1]->xml_mode('1');
631: last;
632: }
633: }
634: return $result
635: }
636:
1.90 matthew 637: #########################################
638: #########################################
639:
640: =pod
641:
1.94 harris41 642: =item B<fix_ids_and_indices>
1.90 matthew 643:
644: Currently undocumented
645:
646: =cut
647:
648: #########################################
649: #########################################
1.87 albertel 650: #Arguably this should all be done as a lonnet::ssi instead
1.86 albertel 651: sub fix_ids_and_indices {
652: my ($logfile,$source,$target)=@_;
653:
654: my %allow;
655: my $content;
656: {
657: my $org=Apache::File->new($source);
658: $content=join('',<$org>);
659: }
660:
1.106 albertel 661: my ($needsfixup,$maxid,$maxindex,$duplicateids,@duplicatedids)=
662: &get_max_ids_indices(\$content);
1.86 albertel 663:
1.106 albertel 664: print $logfile ("Got $needsfixup,$maxid,$maxindex,$duplicateids--".
665: join(', ',@duplicatedids));
666: if ($duplicateids) {
667: print $logfile "Duplicate ID(s) exist, ".join(', ',@duplicatedids)."\n";
1.226 albertel 668: my $outstring='<span class="LC_error">'.&mt('Unable to publish file, it contains duplicated ID(s), ID(s) need to be unique. The duplicated ID(s) are').': '.join(', ',@duplicatedids).'</span>';
1.106 albertel 669: return ($outstring,1);
670: }
1.86 albertel 671: if ($needsfixup) {
672: print $logfile "Needs ID and/or index fixup\n".
673: "Max ID : $maxid (min 10)\n".
674: "Max Index: $maxindex (min 10)\n";
675: }
676: my $outstring='';
1.236 www 677: my $responsecounter=1;
1.86 albertel 678: my @parser;
679: $parser[0]=HTML::LCParser->new(\$content);
680: $parser[-1]->xml_mode(1);
681: my $token;
682: while (@parser) {
683: while ($token=$parser[-1]->get_token) {
684: if ($token->[0] eq 'S') {
685: my $counter;
686: my $tag=$token->[1];
687: my $lctag=lc($tag);
688: if ($lctag eq 'allow') {
689: $allow{$token->[2]->{'src'}}=1;
690: next;
691: }
1.202 albertel 692: if ($lctag eq 'base') { next; }
1.236 www 693: if (($lctag eq 'part') || ($lctag eq 'problem')) {
694: $responsecounter=0;
695: }
696: if ($lctag=~/response$/) { $responsecounter++; }
1.249 www 697: if ($lctag eq 'import') { $responsecounter++; }
1.86 albertel 698: my %parms=%{$token->[2]};
699: $counter=$addid{$tag};
700: if (!$counter) { $counter=$addid{$lctag}; }
701: if ($counter) {
702: if ($counter eq 'id') {
1.186 albertel 703: unless (defined($parms{'id'}) &&
704: $parms{'id'}!~/^\s*$/) {
1.86 albertel 705: $maxid++;
706: $parms{'id'}=$maxid;
1.205 albertel 707: print $logfile 'ID(new) : '.$tag.':'.$maxid."\n";
708: } else {
709: print $logfile 'ID(kept): '.$tag.':'.$parms{'id'}."\n";
1.86 albertel 710: }
711: } elsif ($counter eq 'index') {
1.186 albertel 712: unless (defined($parms{'index'}) &&
713: $parms{'index'}!~/^\s*$/) {
1.86 albertel 714: $maxindex++;
715: $parms{'index'}=$maxindex;
716: print $logfile 'Index: '.$tag.':'.$maxindex."\n";
717: }
718: }
719: }
1.203 www 720: unless ($parms{'type'} eq 'zombie') {
721: foreach my $type ('src','href','background','bgimg') {
722: foreach my $key (keys(%parms)) {
723: if ($key =~ /^$type$/i) {
724: $parms{$key}=&set_allow(\%allow,$logfile,
725: $target,$tag,
726: $parms{$key});
727: }
1.86 albertel 728: }
729: }
730: }
731: # probably a <randomlabel> image type <label>
1.135 albertel 732: # or a <image> tag inside <imageresponse>
733: if (($lctag eq 'label' && defined($parms{'description'}))
734: ||
735: ($lctag eq 'image')) {
1.86 albertel 736: my $next_token=$parser[-1]->get_token();
737: if ($next_token->[0] eq 'T') {
1.218 raeburn 738: $next_token->[1] =~ s/[\n\r\f]+//g;
1.86 albertel 739: $next_token->[1]=&set_allow(\%allow,$logfile,
740: $target,$tag,
741: $next_token->[1]);
742: }
743: $parser[-1]->unget_token($next_token);
744: }
745: if ($lctag eq 'applet') {
746: my $codebase='';
1.148 albertel 747: my $havecodebase=0;
748: foreach my $key (keys(%parms)) {
749: if (lc($key) eq 'codebase') {
750: $codebase=$parms{$key};
751: $havecodebase=1;
752: }
753: }
754: if ($havecodebase) {
755: my $oldcodebase=$codebase;
1.86 albertel 756: unless ($oldcodebase=~/\/$/) {
757: $oldcodebase.='/';
758: }
759: $codebase=&urlfixup($oldcodebase,$target);
760: $codebase=~s/\/$//;
761: if ($codebase ne $oldcodebase) {
762: $parms{'codebase'}=$codebase;
763: print $logfile 'URL codebase: '.$tag.':'.
764: $oldcodebase.' - '.
765: $codebase."\n";
766: }
767: $allow{&absoluteurl($codebase,$target).'/*'}=1;
768: } else {
1.148 albertel 769: foreach my $key (keys(%parms)) {
770: if ($key =~ /(archive|code|object)/i) {
771: my $oldurl=$parms{$key};
1.86 albertel 772: my $newurl=&urlfixup($oldurl,$target);
773: $newurl=~s/\/[^\/]+$/\/\*/;
1.148 albertel 774: print $logfile 'Allow: applet '.lc($key).':'.
775: $oldurl.' allows '.$newurl."\n";
1.86 albertel 776: $allow{&absoluteurl($newurl,$target)}=1;
777: }
778: }
779: }
780: }
781: my $newparmstring='';
782: my $endtag='';
783: foreach (keys %parms) {
784: if ($_ eq '/') {
785: $endtag=' /';
786: } else {
787: my $quote=($parms{$_}=~/\"/?"'":'"');
788: $newparmstring.=' '.$_.'='.$quote.$parms{$_}.$quote;
789: }
790: }
791: if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
792: $outstring.='<'.$tag.$newparmstring.$endtag.'>';
1.286 raeburn 793: if ($lctag eq 'm' || $lctag eq 'answer' || $lctag eq 'display' ||
794: $lctag eq 'tex') {
1.130 albertel 795: $outstring.=&get_all_text_unbalanced('/'.$lctag,\@parser);
1.286 raeburn 796: } elsif ($lctag eq 'script') {
797: if ($parms{'type'} eq 'loncapa/perl') {
798: $outstring.=&get_all_text_unbalanced('/'.$lctag,\@parser);
799: } else {
800: my $script = &get_all_text_unbalanced('/'.$lctag,\@parser);
801: if ($script =~ m{\.set\w+(Src|Swf)\(["']}i) {
802: my @srcs = split(/\.set/i,$script);
803: if (scalar(@srcs) > 1) {
804: foreach my $item (@srcs) {
805: if ($item =~ m{^(FlashPlayerSwf|MediaSrc|XMPSrc|ConfigurationSrc|PosterImageSrc)\((['"])(?:(?!\2).)+\2\)}is) {
806: my $srctype = $1;
807: my $quote = $2;
808: my ($url) = ($item =~ m{^\Q$srctype($quote\E([^$quote]+)\Q$quote)\E});
809: $url = &urlfixup($url);
810: unless ($url=~m{^(?:http|https|ftp)://}) {
811: $allow{&absoluteurl($url,$target)}=1;
812: if ($srctype eq 'ConfigurationSrc') {
813: if ($url =~ m{^(.+/)configuration_express\.xml$}) {
814: #
815: # Camtasia 8.1: express_show/spritesheet.png needed, and included in zip archive.
816: # Not referenced directly in <main>.html or <main>_player.html files,
817: # so add this file to %allow (where <main> is name user gave to file/archive).
818: #
819: my $spritesheet = $1.'express_show/spritesheet.png';
820: $allow{&absoluteurl($spritesheet,$target)}=1;
821: }
822: } elsif ($srctype eq 'PosterImageSrc') {
823: if ($url =~ m{^(.+)_First_Frame\.png$}) {
824: my $prefix = $1;
825: #
826: # Camtasia 8.1: <main>_Thumbnails.png needed, and included in zip archive.
827: # Not referenced directly in <main>.html or <main>_player.html files,
828: # so add this file to %allow (where <main> is name user gave to file/archive).
829: #
830: my $thumbnail = $prefix.'_Thumbnails.png';
831: $allow{&absoluteurl($thumbnail,$target)}=1;
832: }
833: }
834: }
835: }
836: }
837: }
838: }
839: $outstring .= $script
840: }
841: }
1.86 albertel 842: } elsif ($token->[0] eq 'E') {
843: if ($token->[2]) {
844: unless ($token->[1] eq 'allow') {
845: $outstring.='</'.$token->[1].'>';
846: }
1.236 www 847: }
848: if ((($token->[1] eq 'part') || ($token->[1] eq 'problem'))
849: && (!$responsecounter)) {
1.239 bisitz 850: my $outstring='<span class="LC_error">'.&mt('Found [_1] without responses. This resource cannot be published.',$token->[1]).'</span>';
1.236 www 851: return ($outstring,1);
852: }
1.86 albertel 853: } else {
854: $outstring.=$token->[1];
855: }
856: }
857: pop(@parser);
858: }
859:
860: if ($needsfixup) {
861: print $logfile "End of ID and/or index fixup\n".
862: "Max ID : $maxid (min 10)\n".
863: "Max Index: $maxindex (min 10)\n";
864: } else {
865: print $logfile "Does not need ID and/or index fixup\n";
866: }
867:
1.106 albertel 868: return ($outstring,0,%allow);
1.86 albertel 869: }
870:
1.89 matthew 871: #########################################
872: #########################################
873:
874: =pod
875:
1.94 harris41 876: =item B<store_metadata>
1.89 matthew 877:
878: Store the metadata in the metadata table in the loncapa database.
879: Uses lonmysql to access the database.
880:
881: Inputs: \%metadata
882:
883: Returns: (error,status). error is undef on success, status is undef on error.
884:
885: =cut
886:
887: #########################################
888: #########################################
889: sub store_metadata {
1.151 www 890: my %metadata = @_;
1.89 matthew 891: my $error;
892: # Determine if the table exists
893: my $status = &Apache::lonmysql::check_table('metadata');
894: if (! defined($status)) {
1.246 bisitz 895: $error='<span class="LC_error">'
896: .&mt('WARNING: Cannot connect to database!')
897: .'</span>';
1.89 matthew 898: &Apache::lonnet::logthis($error);
899: return ($error,undef);
900: }
901: if ($status == 0) {
902: # It would be nice to actually create the table....
1.246 bisitz 903: $error ='<span class="LC_error">'
904: .&mt('WARNING: The metadata table does not exist in the LON-CAPA database!')
905: .'</span>';
1.89 matthew 906: &Apache::lonnet::logthis($error);
907: return ($error,undef);
908: }
1.172 matthew 909: my $dbh = &Apache::lonmysql::get_dbh();
1.237 www 910: if (($metadata{'obsolete'}) || ($metadata{'copyright'} eq 'priv')) {
1.172 matthew 911: # remove this entry
1.228 albertel 912: my $delitem = 'url = '.$dbh->quote($metadata{'url'});
913: $status = &LONCAPA::lonmetadata::delete_metadata($dbh,undef,$delitem);
914:
1.152 www 915: } else {
1.213 albertel 916: $status = &LONCAPA::lonmetadata::update_metadata($dbh,undef,undef,
1.172 matthew 917: \%metadata);
1.152 www 918: }
1.172 matthew 919: if (defined($status) && $status ne '') {
1.246 bisitz 920: $error='<span class="LC_error">'
1.248 raeburn 921: .&mt('Error occurred saving new values in metadata table in LON-CAPA database!')
1.246 bisitz 922: .'</span>';
1.89 matthew 923: &Apache::lonnet::logthis($error);
1.172 matthew 924: &Apache::lonnet::logthis($status);
1.89 matthew 925: return ($error,undef);
926: }
1.213 albertel 927: return (undef,'success');
1.89 matthew 928: }
929:
1.142 www 930:
1.185 www 931: # ========================================== Parse file for errors and warnings
932:
933: sub checkonthis {
934: my ($r,$source)=@_;
1.187 www 935: my $uri=&Apache::lonnet::hreflocation($source);
936: $uri=~s/\/$//;
1.190 albertel 937: my $result=&Apache::lonnet::ssi_body($uri,
938: ('grade_target'=>'web',
939: 'return_only_error_and_warning_counts' => 1));
940: my ($errorcount,$warningcount)=split(':',$result);
1.187 www 941: if (($errorcount) || ($warningcount)) {
1.242 bisitz 942: $r->print('<h3>'.&mt('Warnings and Errors').'</h3>');
943: $r->print('<tt>'.$uri.'</tt>:');
944: $r->print('<ul>');
945: if ($warningcount) {
946: $r->print('<li><div class="LC_warning">'
947: .&mt('[quant,_1,warning]',$warningcount)
948: .'</div></li>');
949: }
950: if ($errorcount) {
951: $r->print('<li><div class="LC_error">'
952: .&mt('[quant,_1,error]',$errorcount)
953: .' <img src="/adm/lonMisc/bomb.gif" />'
954: .'</div></li>');
955: }
956: $r->print('</ul>');
1.185 www 957: } else {
1.190 albertel 958: #$r->print('<font color="green">'.&mt('ok').'</font>');
1.185 www 959: }
960: $r->rflush();
1.187 www 961: return ($warningcount,$errorcount);
1.185 www 962: }
963:
1.142 www 964: # ============================================== Parse file itself for metadata
1.144 www 965: #
966: # parses a file with target meta, sets global %metadatafields %metadatakeys
1.142 www 967:
968: sub parseformeta {
969: my ($source,$style)=@_;
1.143 www 970: my $allmeta='';
1.142 www 971: if (($style eq 'ssi') || ($style eq 'prv')) {
972: my $dir=$source;
973: $dir=~s-/[^/]*$--;
974: my $file=$source;
975: $file=(split('/',$file))[-1];
976: $source=&Apache::lonnet::hreflocation($dir,$file);
1.143 www 977: $allmeta=&Apache::lonnet::ssi_body($source,('grade_target' => 'meta'));
1.142 www 978: &metaeval($allmeta);
979: }
1.143 www 980: return $allmeta;
1.142 www 981: }
982:
1.90 matthew 983: #########################################
984: #########################################
985:
986: =pod
987:
1.94 harris41 988: =item B<publish>
989:
990: This is the workhorse function of this module. This subroutine generates
991: backup copies, performs any automatic processing (prior to publication,
992: especially for rat and ssi files),
1.90 matthew 993:
1.113 albertel 994: Returns a 2 element array, the first is the string to be shown to the
1.248 raeburn 995: user, the second is an error code, either 1 (an error occurred) or 0
1.113 albertel 996: (no error occurred)
997:
1.94 harris41 998: I<Additional documentation needed.>
1.90 matthew 999:
1000: =cut
1001:
1002: #########################################
1003: #########################################
1.2 www 1004: sub publish {
1.50 www 1005:
1.97 www 1006: my ($source,$target,$style,$batch)=@_;
1.2 www 1007: my $logfile;
1.4 www 1008: my $scrout='';
1.23 www 1009: my $allmeta='';
1010: my $content='';
1.36 www 1011: my %allow=();
1.4 www 1012:
1.2 www 1013: unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
1.226 albertel 1014: return ('<span class="LC_error">'.&mt('No write permission to user directory, FAIL').'</span>',1);
1.2 www 1015: }
1016: print $logfile
1.211 albertel 1017: "\n\n================= Publish ".localtime()." Phase One ================\n".$env{'user.name'}.':'.$env{'user.domain'}."\n";
1.2 www 1018:
1.119 www 1019: if (($style eq 'ssi') || ($style eq 'rat') || ($style eq 'prv')) {
1.3 www 1020: # ------------------------------------------------------- This needs processing
1.4 www 1021:
1022: # ----------------------------------------------------------------- Backup Copy
1.3 www 1023: my $copyfile=$source.'.save';
1.13 www 1024: if (copy($source,$copyfile)) {
1.3 www 1025: print $logfile "Copied original file to ".$copyfile."\n";
1026: } else {
1.13 www 1027: print $logfile "Unable to write backup ".$copyfile.':'.$!."\n";
1.239 bisitz 1028: return ("<span class=\"LC_error\">".&mt("Failed to write backup copy, [_1], FAIL",$1)."</span>",1);
1.3 www 1029: }
1.4 www 1030: # ------------------------------------------------------------- IDs and indices
1.86 albertel 1031:
1.106 albertel 1032: my ($outstring,$error);
1033: ($outstring,$error,%allow)=&fix_ids_and_indices($logfile,$source,
1034: $target);
1.113 albertel 1035: if ($error) { return ($outstring,$error); }
1.36 www 1036: # ------------------------------------------------------------ Construct Allows
1.62 www 1037:
1.246 bisitz 1038: my $outdep=''; # Collect dependencies output data
1.62 www 1039: my $allowstr='';
1.232 raeburn 1040: foreach my $thisdep (sort(keys(%allow))) {
1.73 albertel 1041: if ($thisdep !~ /[^\s]/) { next; }
1.231 www 1042: if ($thisdep =~/\$/) {
1.246 bisitz 1043: $outdep.='<div class="LC_warning">'
1.232 raeburn 1044: .&mt('The resource depends on another resource with variable filename, i.e., [_1].','<tt>'.$thisdep.'</tt>').'<br />'
1045: .&mt('You likely need to explicitly allow access to all possible dependencies using the [_1]-tag.','<tt><allow></tt>')
1.246 bisitz 1046: ."</div>\n";
1.231 www 1047: }
1.62 www 1048: unless ($style eq 'rat') {
1049: $allowstr.="\n".'<allow src="'.$thisdep.'" />';
1050: }
1.246 bisitz 1051: $outdep.='<div>';
1.231 www 1052: if ($thisdep!~/[\*\$]/ && $thisdep!~m|^/adm/|) {
1.246 bisitz 1053: $outdep.='<a href="'.$thisdep.'">';
1.44 www 1054: }
1.246 bisitz 1055: $outdep.='<tt>'.$thisdep.'</tt>';
1.231 www 1056: if ($thisdep!~/[\*\$]/ && $thisdep!~m|^/adm/|) {
1.246 bisitz 1057: $outdep.='</a>';
1.59 www 1058: if (
1059: &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
1060: $thisdep.'.meta') eq '-1') {
1.246 bisitz 1061: $outdep.= ' - <span class="LC_error">'.&mt('Currently not available').
1.226 albertel 1062: '</span>';
1.59 www 1063: } else {
1.279 www 1064: #
1065: # Store the fact that the dependency has been used by the target file
1066: # Unfortunately, usage is erroneously named sequsage in lonmeta.pm
1067: # The translation happens in lonmetadata.pm
1068: #
1.59 www 1069: my %temphash=(&Apache::lonnet::declutter($target).'___'.
1070: &Apache::lonnet::declutter($thisdep).'___usage'
1071: => time);
1.215 albertel 1072: $thisdep=~m{^/res/($match_domain)/($match_username)/};
1.59 www 1073: if ((defined($1)) && (defined($2))) {
1.92 albertel 1074: &Apache::lonnet::put('nohist_resevaldata',\%temphash,
1075: $1,$2);
1.59 www 1076: }
1077: }
1.44 www 1078: }
1.246 bisitz 1079: $outdep.='</div><br />';
1080: }
1081:
1082: if ($outdep) {
1083: $scrout.='<h3>'.&mt('Dependencies').'</h3>'
1084: .$outdep
1.65 harris41 1085: }
1.175 albertel 1086: $outstring=~s/\n*(\<\/[^\>]+\>[^<]*)$/$allowstr\n$1\n/s;
1.62 www 1087:
1.94 harris41 1088: # ------------------------------------------------------------- Write modified.
1.37 www 1089:
1.4 www 1090: {
1091: my $org;
1092: unless ($org=Apache::File->new('>'.$source)) {
1093: print $logfile "No write permit to $source\n";
1.226 albertel 1094: return ('<span class="LC_error">'.&mt('No write permission to').
1.136 www 1095: ' '.$source.
1.226 albertel 1096: ', '.&mt('FAIL').'</span>',1);
1.4 www 1097: }
1.94 harris41 1098: print($org $outstring);
1.4 www 1099: }
1100: $content=$outstring;
1.34 www 1101:
1.37 www 1102: }
1.94 harris41 1103: # -------------------------------------------- Initial step done, now metadata.
1.7 www 1104:
1.94 harris41 1105: # --------------------------------------- Storage for metadata keys and fields.
1.144 www 1106: # these are globals
1107: #
1.8 www 1108: %metadatafields=();
1109: %metadatakeys=();
1110:
1111: my %oldparmstores=();
1.44 www 1112:
1.97 www 1113: unless ($batch) {
1.254 bisitz 1114: $scrout.='<h3>'.&mt('Metadata').' ' .
1.239 bisitz 1115: &Apache::loncommon::help_open_topic("Metadata_Description")
1.84 bowersj2 1116: . '</h3>';
1.97 www 1117: }
1.7 www 1118:
1119: # ------------------------------------------------ First, check out environment
1.195 www 1120: if ((!(-e $source.'.meta')) || ($env{'form.forceoverride'})) {
1.192 albertel 1121: $metadatafields{'author'}=$env{'environment.firstname'}.' '.
1122: $env{'environment.middlename'}.' '.
1123: $env{'environment.lastname'}.' '.
1124: $env{'environment.generation'};
1.8 www 1125: $metadatafields{'author'}=~s/\s+/ /g;
1126: $metadatafields{'author'}=~s/\s+$//;
1.211 albertel 1127: $metadatafields{'owner'}=$cuname.':'.$cudom;
1.7 www 1128:
1129: # ------------------------------------------------ Check out directory hierachy
1130:
1131: my $thisdisfn=$source;
1132:
1.269 www 1133: $thisdisfn=~s/^\Q$docroot\E\/priv\/\Q$cudom\E\/\Q$cuname\E\///;
1134: my @urlparts=('.',split(/\//,$thisdisfn));
1.7 www 1135: $#urlparts--;
1136:
1.269 www 1137: my $currentpath=$docroot.'/priv/'.$cudom.'/'.$cuname.'/';
1.7 www 1138:
1.140 albertel 1139: my $prefix='../'x($#urlparts);
1.269 www 1140: foreach my $subdir (@urlparts) {
1141: $currentpath.=$subdir.'/';
1.140 albertel 1142: $scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix);
1143: $prefix=~s|^\.\./||;
1.65 harris41 1144: }
1.185 www 1145:
1.149 www 1146: # ----------------------------------------------------------- Parse file itself
1147: # read %metadatafields from file itself
1148:
1149: $allmeta=&parseformeta($source,$style);
1.7 www 1150:
1151: # ------------------- Clear out parameters and stores (there should not be any)
1152:
1.65 harris41 1153: foreach (keys %metadatafields) {
1.7 www 1154: if (($_=~/^parameter/) || ($_=~/^stores/)) {
1155: delete $metadatafields{$_};
1156: }
1.65 harris41 1157: }
1.7 www 1158:
1.8 www 1159: } else {
1.7 www 1160: # ---------------------- Read previous metafile, remember parameters and stores
1161:
1162: $scrout.=&metaread($logfile,$source.'.meta');
1163:
1.65 harris41 1164: foreach (keys %metadatafields) {
1.7 www 1165: if (($_=~/^parameter/) || ($_=~/^stores/)) {
1166: $oldparmstores{$_}=1;
1167: delete $metadatafields{$_};
1168: }
1.65 harris41 1169: }
1.195 www 1170: # ------------------------------------------------------------- Save some stuff
1171: my %savemeta=();
1172: foreach ('title') {
1.267 www 1173: if ($metadatafields{$_}) { $savemeta{$_}=$metadatafields{$_}; }
1.195 www 1174: }
1.161 albertel 1175: # ------------------------------------------ See if anything new in file itself
1176:
1177: $allmeta=&parseformeta($source,$style);
1.195 www 1178: # ----------------------------------------------------------- Restore the stuff
1179: foreach (keys %savemeta) {
1180: $metadatafields{$_}=$savemeta{$_};
1181: }
1.144 www 1182: }
1.7 www 1183:
1.144 www 1184:
1.7 www 1185: # ---------------- Find and document discrepancies in the parameters and stores
1186:
1.116 albertel 1187: my $chparms='';
1188: foreach (sort keys %metadatafields) {
1189: if (($_=~/^parameter/) || ($_=~/^stores/)) {
1190: unless ($_=~/\.\w+$/) {
1191: unless ($oldparmstores{$_}) {
1.219 albertel 1192: my $disp_key = $_;
1193: $disp_key =~ tr/\0/_/;
1194: print $logfile ('New: '.$disp_key."\n");
1195: $chparms .= $disp_key.' ';
1.116 albertel 1196: }
1197: }
1198: }
1199: }
1200: if ($chparms) {
1.224 albertel 1201: $scrout.='<p><b>'.&mt('New parameters or saved values').
1.136 www 1202: ':</b> '.$chparms.'</p>';
1.116 albertel 1203: }
1.7 www 1204:
1.116 albertel 1205: $chparms='';
1206: foreach (sort keys %oldparmstores) {
1207: if (($_=~/^parameter/) || ($_=~/^stores/)) {
1208: unless (($metadatafields{$_.'.name'}) ||
1209: ($metadatafields{$_.'.package'}) || ($_=~/\.\w+$/)) {
1.219 albertel 1210: my $disp_key = $_;
1211: $disp_key =~ tr/\0/_/;
1212: print $logfile ('Obsolete: '.$disp_key."\n");
1213: $chparms.=$disp_key.' ';
1.116 albertel 1214: }
1215: }
1216: }
1217: if ($chparms) {
1.258 bisitz 1218: $scrout.='<p><b>'.&mt('Obsolete parameters or saved values').':</b> '
1219: .$chparms.'</p>'
1220: .'<p class="LC_warning"><b>'.&mt('Warning!').'</b><br />'
1221: .&mt('If this resource is in active use, student performance data from the previous version may become inaccessible.')
1222: .'</p><hr />';
1.116 albertel 1223: }
1.229 www 1224: if ($metadatafields{'copyright'} eq 'priv') {
1.258 bisitz 1225: $scrout.='<p class="LC_warning"><b>'.&mt('Warning!').'</b><br />'
1226: .&mt('Copyright/distribution option "Private" is no longer supported. Select another option from below. Consider "Custom Rights" for maximum control over the usage of your resource.')
1227: .'</p><hr />';
1.229 www 1228: }
1.37 www 1229:
1.8 www 1230: # ------------------------------------------------------- Now have all metadata
1.5 www 1231:
1.116 albertel 1232: my %keywords=();
1.97 www 1233:
1.116 albertel 1234: if (length($content)<500000) {
1235: my $textonly=$content;
1236: $textonly=~s/\<script[^\<]+\<\/script\>//g;
1237: $textonly=~s/\<m\>[^\<]+\<\/m\>//g;
1238: $textonly=~s/\<[^\>]*\>//g;
1.245 onken 1239:
1240: #this is a work simplification for german authors for present
1241: $textonly=HTML::Entities::decode($textonly); #decode HTML-character
1242: $textonly=Encode::Encoder::encode('utf8', $textonly); #encode to perl internal unicode
1243: $textonly=~tr/A-ZÜÄÖ/a-züäö/; #add lowercase rule for german "Umlaute"
1244: $textonly=~s/[\$\&][a-z]\w*//g;
1245: $textonly=~s/[^a-z^ü^ä^ö^ß\s]//g; #dont delete german "Umlaute"
1246:
1247: foreach ($textonly=~m/[^\s]+/g) { #match all but whitespaces
1248: unless ($nokey{$_}) {
1249: $keywords{$_}=1;
1250: }
1251: }
1252:
1253:
1.116 albertel 1254: }
1.97 www 1255:
1.168 www 1256: foreach my $addkey (split(/[\"\'\,\;]/,$metadatafields{'keywords'})) {
1257: $addkey=~s/\s+/ /g;
1258: $addkey=~s/^\s//;
1259: $addkey=~s/\s$//;
1260: if ($addkey=~/\w/) {
1261: $keywords{$addkey}=1;
1262: }
1.116 albertel 1263: }
1.97 www 1264: # --------------------------------------------------- Now we also have keywords
1265: # =============================================================================
1.167 albertel 1266: # interactive mode html goes into $intr_scrout
1267: # batch mode throws away this HTML
1268: # additionally all of the field functions have a by product of setting
1.192 albertel 1269: # $env{'from.'..} so that it can be used by the phase two handler in
1.167 albertel 1270: # batch mode
1271:
1.239 bisitz 1272: my $intr_scrout.='<br />'
1.238 bisitz 1273: .'<form name="pubform" action="/adm/publish" method="post">';
1274: unless ($env{'form.makeobsolete'}) {
1.246 bisitz 1275: $intr_scrout.='<p class="LC_warning">'
1.239 bisitz 1276: .&mt('Searching for your resource will be based on the following metadata. Please provide as much data as possible.')
1277: .'</p>'
1278: .'<p><input type="submit" value="'
1.238 bisitz 1279: .&mt('Finalize Publication')
1.271 www 1280: .'" /> <a href="'.&Apache::loncfile::url($source).'">'.&mt('Cancel').'</a></p>';
1.238 bisitz 1281: }
1.239 bisitz 1282: $intr_scrout.=&Apache::lonhtmlcommon::start_pick_box();
1.238 bisitz 1283: $intr_scrout.=
1.167 albertel 1284: &hiddenfield('phase','two').
1.192 albertel 1285: &hiddenfield('filename',$env{'form.filename'}).
1.209 www 1286: &hiddenfield('allmeta',&escape($allmeta)).
1.194 www 1287: &hiddenfield('dependencies',join(',',keys %allow));
1288: unless ($env{'form.makeobsolete'}) {
1289: $intr_scrout.=
1.167 albertel 1290: &textfield('Title','title',$metadatafields{'title'}).
1291: &textfield('Author(s)','author',$metadatafields{'author'}).
1292: &textfield('Subject','subject',$metadatafields{'subject'});
1.194 www 1293: # --------------------------------------------------- Scan content for keywords
1.7 www 1294:
1.238 bisitz 1295: my $keywords_help = &Apache::loncommon::help_open_topic("Publishing_Keywords");
1.167 albertel 1296: my $keywordout=<<"END";
1.77 matthew 1297: <script>
1.116 albertel 1298: function checkAll(field) {
1.77 matthew 1299: for (i = 0; i < field.length; i++)
1300: field[i].checked = true ;
1301: }
1302:
1.116 albertel 1303: function uncheckAll(field) {
1.77 matthew 1304: for (i = 0; i < field.length; i++)
1305: field[i].checked = false ;
1306: }
1307: </script>
1.117 albertel 1308: END
1.238 bisitz 1309: $keywordout.="\n".&Apache::lonhtmlcommon::row_title(&mt('Keywords'))
1310: .$keywords_help
1311: .'<input type="button" value="'.&mt('check all').'" onclick="javascript:checkAll(document.pubform.keywords)" />'
1312: .'<input type="button" value="'.&mt('uncheck all').'" onclick="javascript:uncheckAll(document.pubform.keywords)" />'
1313: .'</p><br />'
1.247 raeburn 1314: .&Apache::loncommon::start_data_table();
1315: my $cols_per_row = 10;
1.167 albertel 1316: my $colcount=0;
1.247 raeburn 1317: my $wordcount=0;
1318: my $numkeywords = scalar(keys(%keywords));
1.116 albertel 1319:
1.247 raeburn 1320: foreach my $word (sort(keys(%keywords))) {
1321: if ($colcount == 0) {
1322: $keywordout .= &Apache::loncommon::start_data_table_row();
1323: }
1324: $colcount++;
1325: $wordcount++;
1326: if (($wordcount == $numkeywords) && ($colcount < $cols_per_row)) {
1327: my $colspan = 1+$cols_per_row-$colcount;
1328: $keywordout .= '<td colspan="'.$colspan.'">';
1329: } else {
1330: $keywordout .= '<td>';
1331: }
1332: $keywordout.='<label><input type="checkbox" name="keywords" value="'.$word.'"';
1333: if ($metadatafields{'keywords'}) {
1334: if ($metadatafields{'keywords'}=~/\Q$word\E/) {
1.253 bisitz 1335: $keywordout.=' checked="checked"';
1.247 raeburn 1336: $env{'form.keywords'}.=$word.',';
1337: }
1338: } elsif (&Apache::loncommon::keyword($word)) {
1.253 bisitz 1339: $keywordout.=' checked="checked"';
1.247 raeburn 1340: $env{'form.keywords'}.=$word.',';
1341: }
1342: $keywordout.=' />'.$word.'</label></td>';
1343: if ($colcount == $cols_per_row) {
1344: $keywordout.=&Apache::loncommon::end_data_table_row();
1345: $colcount=0;
1.243 bisitz 1346: }
1347: }
1.247 raeburn 1348: if ($colcount > 0) {
1349: $keywordout .= &Apache::loncommon::end_data_table_row();
1350: }
1.243 bisitz 1351:
1.192 albertel 1352: $env{'form.keywords'}=~s/\,$//;
1.116 albertel 1353:
1.241 raeburn 1354: $keywordout.=&Apache::loncommon::end_data_table_row()
1355: .&Apache::loncommon::end_data_table()
1.238 bisitz 1356: .&Apache::lonhtmlcommon::row_closure();
1.51 www 1357:
1.167 albertel 1358: $intr_scrout.=$keywordout;
1.9 www 1359:
1.167 albertel 1360: $intr_scrout.=&textfield('Additional Keywords','addkey','');
1.12 www 1361:
1.167 albertel 1362: $intr_scrout.=&textfield('Notes','notes',$metadatafields{'notes'});
1.9 www 1363:
1.238 bisitz 1364: $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title(&mt('Abstract'))
1365: .'<textarea cols="80" rows="5" name="abstract">'
1366: .$metadatafields{'abstract'}
1367: .'</textarea>'
1368: .&Apache::lonhtmlcommon::row_closure();
1.9 www 1369:
1.167 albertel 1370: $source=~/\.(\w+)$/;
1.150 www 1371:
1.238 bisitz 1372: $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title(&mt('Grade Levels'))
1373: .&mt('Lowest Grade Level:').' '
1374: .&select_level_form($metadatafields{'lowestgradelevel'},'lowestgradelevel')
1375: # .&Apache::lonhtmlcommon::row_closure();
1376: # $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title(&mt('Highest Grade Level'))
1377: .' '.&mt('Highest Grade Level:').' '
1378: .&select_level_form($metadatafields{'highestgradelevel'},'highestgradelevel')
1379: .&Apache::lonhtmlcommon::row_closure();
1.150 www 1380:
1.238 bisitz 1381: $intr_scrout.=&textfield('Standards','standards',$metadatafields{'standards'});
1.11 www 1382:
1.167 albertel 1383: $intr_scrout.=&hiddenfield('mime',$1);
1.11 www 1384:
1.167 albertel 1385: my $defaultlanguage=$metadatafields{'language'};
1386: $defaultlanguage =~ s/\s*notset\s*//g;
1387: $defaultlanguage =~ s/^,\s*//g;
1388: $defaultlanguage =~ s/,\s*$//g;
1.123 albertel 1389:
1.167 albertel 1390: $intr_scrout.=&selectbox('Language','language',
1391: $defaultlanguage,
1392: \&Apache::loncommon::languagedescription,
1393: (&Apache::loncommon::languageids),
1394: );
1.11 www 1395:
1.167 albertel 1396: unless ($metadatafields{'creationdate'}) {
1397: $metadatafields{'creationdate'}=time;
1398: }
1399: $intr_scrout.=&hiddenfield('creationdate',
1400: &Apache::lonmysql::unsqltime($metadatafields{'creationdate'}));
1.116 albertel 1401:
1.167 albertel 1402: $intr_scrout.=&hiddenfield('lastrevisiondate',time);
1.11 www 1403:
1.240 raeburn 1404: my $pubowner_last;
1405: if ($style eq 'prv') {
1406: $pubowner_last = 1;
1407: }
1.167 albertel 1408: $intr_scrout.=&textfield('Publisher/Owner','owner',
1.240 raeburn 1409: $metadatafields{'owner'},$pubowner_last);
1.84 bowersj2 1410:
1.173 www 1411: # ---------------------------------------------- Retrofix for unused copyright
1412: if ($metadatafields{'copyright'} eq 'free') {
1413: $metadatafields{'copyright'}='default';
1414: $metadatafields{'sourceavail'}='open';
1415: }
1.229 www 1416: if ($metadatafields{'copyright'} eq 'priv') {
1417: $metadatafields{'copyright'}='domain';
1418: }
1.174 www 1419: # ------------------------------------------------ Dial in reasonable defaults
1.167 albertel 1420: my $defaultoption=$metadatafields{'copyright'};
1421: unless ($defaultoption) { $defaultoption='default'; }
1.174 www 1422: my $defaultsourceoption=$metadatafields{'sourceavail'};
1423: unless ($defaultsourceoption) { $defaultsourceoption='closed'; }
1.167 albertel 1424: unless ($style eq 'prv') {
1.174 www 1425: # -------------------------------------------------- Correct copyright for rat.
1.167 albertel 1426: if ($style eq 'rat') {
1.174 www 1427: # -------------------------------------- Retrofix for non-applicable copyright
1.167 albertel 1428: if ($metadatafields{'copyright'} eq 'public') {
1429: delete $metadatafields{'copyright'};
1430: $defaultoption='default';
1431: }
1432: $intr_scrout.=&selectbox('Copyright/Distribution','copyright',
1433: $defaultoption,
1434: \&Apache::loncommon::copyrightdescription,
1.229 www 1435: (grep !/^(public|priv)$/,(&Apache::loncommon::copyrightids)));
1.116 albertel 1436: } else {
1.174 www 1437: $intr_scrout.=&selectbox('Copyright/Distribution','copyright',
1438: $defaultoption,
1439: \&Apache::loncommon::copyrightdescription,
1.229 www 1440: (grep !/^priv$/,(&Apache::loncommon::copyrightids)));
1.65 harris41 1441: }
1.174 www 1442: my $copyright_help =
1.238 bisitz 1443: &Apache::loncommon::help_open_topic('Publishing_Copyright');
1444: my $replace=&mt('Copyright/Distribution:');
1445: $intr_scrout =~ s/$replace/$replace.' '.$copyright_help/ge;
1446:
1447: $intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights');
1.174 www 1448: $intr_scrout.=&selectbox('Source Distribution','sourceavail',
1449: $defaultsourceoption,
1450: \&Apache::loncommon::source_copyrightdescription,
1451: (&Apache::loncommon::source_copyrightids));
1.198 www 1452: # $intr_scrout.=&text_with_browse_field('Source Custom Distribution File','sourcerights',$metadatafields{'sourcerights'},'rights');
1.174 www 1453: my $uctitle=&mt('Obsolete');
1.257 bisitz 1454: my $obsolete_checked=($metadatafields{'obsolete'})?' checked="checked"':'';
1.238 bisitz 1455: $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title($uctitle)
1.256 bisitz 1456: .'<input type="checkbox" name="obsolete"'.$obsolete_checked.' />'
1.238 bisitz 1457: .&Apache::lonhtmlcommon::row_closure(1);
1458: $intr_scrout.=&text_with_browse_field('Suggested Replacement for Obsolete File',
1.180 albertel 1459: 'obsoletereplacement',
1.240 raeburn 1460: $metadatafields{'obsoletereplacement'},'',1);
1.174 www 1461: } else {
1462: $intr_scrout.=&hiddenfield('copyright','private');
1463: }
1.194 www 1464: } else {
1465: $intr_scrout.=
1466: &hiddenfield('title',$metadatafields{'title'}).
1467: &hiddenfield('author',$metadatafields{'author'}).
1468: &hiddenfield('subject',$metadatafields{'subject'}).
1469: &hiddenfield('keywords',$metadatafields{'keywords'}).
1470: &hiddenfield('abstract',$metadatafields{'abstract'}).
1471: &hiddenfield('notes',$metadatafields{'notes'}).
1472: &hiddenfield('mime',$metadatafields{'mime'}).
1473: &hiddenfield('creationdate',$metadatafields{'creationdate'}).
1474: &hiddenfield('lastrevisiondate',time).
1475: &hiddenfield('owner',$metadatafields{'owner'}).
1476: &hiddenfield('lowestgradelevel',$metadatafields{'lowestgradelevel'}).
1477: &hiddenfield('standards',$metadatafields{'standards'}).
1478: &hiddenfield('highestgradelevel',$metadatafields{'highestgradelevel'}).
1479: &hiddenfield('language',$metadatafields{'language'}).
1480: &hiddenfield('copyright',$metadatafields{'copyright'}).
1481: &hiddenfield('sourceavail',$metadatafields{'sourceavail'}).
1482: &hiddenfield('customdistributionfile',$metadatafields{'customdistributionfile'}).
1.195 www 1483: &hiddenfield('obsolete',1).
1.194 www 1484: &text_with_browse_field('Suggested Replacement for Obsolete File',
1485: 'obsoletereplacement',
1.240 raeburn 1486: $metadatafields{'obsoletereplacement'},'',1);
1.194 www 1487: }
1.167 albertel 1488: if (!$batch) {
1.238 bisitz 1489: $scrout.=$intr_scrout
1.239 bisitz 1490: .&Apache::lonhtmlcommon::end_pick_box()
1491: .'<p><input type="submit" value="'
1.238 bisitz 1492: .&mt($env{'form.makeobsolete'}?'Make Obsolete':'Finalize Publication')
1.239 bisitz 1493: .'" /></p>'
1494: .'</form>';
1.97 www 1495: }
1.167 albertel 1496: return($scrout,0);
1.2 www 1497: }
1.1 www 1498:
1.90 matthew 1499: #########################################
1500: #########################################
1501:
1502: =pod
1503:
1.94 harris41 1504: =item B<phasetwo>
1.90 matthew 1505:
1506: Render second interface showing status of publication steps.
1507: This is publication step two.
1508:
1.94 harris41 1509: Parameters:
1510:
1511: =over 4
1512:
1513: =item I<$source>
1514:
1515: =item I<$target>
1516:
1517: =item I<$style>
1518:
1519: =item I<$distarget>
1520:
1521: =back
1522:
1523: Returns:
1524:
1525: =over 4
1526:
1.197 www 1527: =item integer
1.94 harris41 1528:
1.197 www 1529: 0: fail
1530: 1: success
1.94 harris41 1531:
1.90 matthew 1532: =cut
1.12 www 1533:
1.100 matthew 1534: #'stupid emacs
1.90 matthew 1535: #########################################
1536: #########################################
1.11 www 1537: sub phasetwo {
1538:
1.100 matthew 1539: my ($r,$source,$target,$style,$distarget,$batch)=@_;
1.102 www 1540: $source=~s/\/+/\//g;
1541: $target=~s/\/+/\//g;
1.196 www 1542: #
1543: # Unless trying to get rid of something, check name validity
1544: #
1545: unless ($env{'form.obsolete'}) {
1546: if ($target=~/(\_\_\_|\&\&\&|\:\:\:)/) {
1.226 albertel 1547: $r->print('<span class="LC_error">'.
1548: &mt('Unsupported character combination [_1] in filename, FAIL.',"<tt>'.$1.'</tt>").
1549: '</span>');
1.196 www 1550: return 0;
1551: }
1552: unless ($target=~/\.(\w+)$/) {
1.226 albertel 1553: $r->print('<span class="LC_error">'.&mt('No valid extension found in filename, FAIL').'</span>');
1.196 www 1554: return 0;
1555: }
1556: if ($target=~/\.(\d+)\.(\w+)$/) {
1.254 bisitz 1557: $r->print('<span class="LC_error">'.&mt('Filename of resource contains internal version number. Cannot publish such resources, FAIL').'</span>');
1.196 www 1558: return 0;
1559: }
1560: }
1.109 www 1561:
1.196 www 1562: #
1563: # End name check
1564: #
1.102 www 1565: $distarget=~s/\/+/\//g;
1.11 www 1566: my $logfile;
1567: unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
1.110 www 1568: $r->print(
1.226 albertel 1569: '<span class="LC_error">'.
1570: &mt('No write permission to user directory, FAIL').'</span>');
1.110 www 1571: return 0;
1.11 www 1572: }
1.227 albertel 1573:
1574: if ($source =~ /\.rights$/) {
1575: $r->print('<p><span class="LC_warning">'.&mt('Warning: It can take up to 1 hour for rights changes to fully propagate.').'</span></p>');
1576: }
1577:
1.11 www 1578: print $logfile
1.211 albertel 1579: "\n================= Publish ".localtime()." Phase Two ================\n".$env{'user.name'}.':'.$env{'user.domain'}."\n";
1.100 matthew 1580:
1581: %metadatafields=();
1582: %metadatakeys=();
1.167 albertel 1583:
1.209 www 1584: &metaeval(&unescape($env{'form.allmeta'}));
1.100 matthew 1585:
1.192 albertel 1586: $metadatafields{'title'}=$env{'form.title'};
1587: $metadatafields{'author'}=$env{'form.author'};
1588: $metadatafields{'subject'}=$env{'form.subject'};
1589: $metadatafields{'notes'}=$env{'form.notes'};
1590: $metadatafields{'abstract'}=$env{'form.abstract'};
1591: $metadatafields{'mime'}=$env{'form.mime'};
1592: $metadatafields{'language'}=$env{'form.language'};
1593: $metadatafields{'creationdate'}=$env{'form.creationdate'};
1594: $metadatafields{'lastrevisiondate'}=$env{'form.lastrevisiondate'};
1595: $metadatafields{'owner'}=$env{'form.owner'};
1596: $metadatafields{'copyright'}=$env{'form.copyright'};
1597: $metadatafields{'standards'}=$env{'form.standards'};
1598: $metadatafields{'lowestgradelevel'}=$env{'form.lowestgradelevel'};
1599: $metadatafields{'highestgradelevel'}=$env{'form.highestgradelevel'};
1.115 www 1600: $metadatafields{'customdistributionfile'}=
1.192 albertel 1601: $env{'form.customdistributionfile'};
1602: $metadatafields{'sourceavail'}=$env{'form.sourceavail'};
1603: $metadatafields{'obsolete'}=$env{'form.obsolete'};
1.138 www 1604: $metadatafields{'obsoletereplacement'}=
1.192 albertel 1605: $env{'form.obsoletereplacement'};
1606: $metadatafields{'dependencies'}=$env{'form.dependencies'};
1.211 albertel 1607: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
1.192 albertel 1608: $env{'user.domain'};
1.211 albertel 1609: $metadatafields{'authorspace'}=$cuname.':'.$cudom;
1.214 albertel 1610: $metadatafields{'domain'}=$cudom;
1.100 matthew 1611:
1.192 albertel 1612: my $allkeywords=$env{'form.addkey'};
1613: if (exists($env{'form.keywords'})) {
1614: if (ref($env{'form.keywords'})) {
1615: $allkeywords .= ','.join(',',@{$env{'form.keywords'}});
1.100 matthew 1616: } else {
1.192 albertel 1617: $allkeywords .= ','.$env{'form.keywords'};
1.100 matthew 1618: }
1619: }
1.168 www 1620: $allkeywords=~s/[\"\']//g;
1.170 www 1621: $allkeywords=~s/\s*[\;\,]\s*/\,/g;
1.168 www 1622: $allkeywords=~s/\s+/ /g;
1623: $allkeywords=~s/^[ \,]//;
1624: $allkeywords=~s/[ \,]$//;
1.100 matthew 1625: $metadatafields{'keywords'}=$allkeywords;
1626:
1.149 www 1627: # check if custom distribution file is specified
1628: if ($metadatafields{'copyright'} eq 'custom') {
1629: my $file=$metadatafields{'customdistributionfile'};
1630: unless ($file=~/\.rights$/) {
1.197 www 1631: $r->print(
1.226 albertel 1632: '<span class="LC_error">'.&mt('No valid custom distribution rights file specified, FAIL').
1633: '</span>');
1.197 www 1634: return 0;
1.149 www 1635: }
1636: }
1.100 matthew 1637: {
1638: print $logfile "\nWrite metadata file for ".$source;
1639: my $mfh;
1640: unless ($mfh=Apache::File->new('>'.$source.'.meta')) {
1.197 www 1641: $r->print(
1.226 albertel 1642: '<span class="LC_error">'.&mt('Could not write metadata, FAIL').
1643: '</span>');
1.197 www 1644: return 0;
1.100 matthew 1645: }
1646: foreach (sort keys %metadatafields) {
1647: unless ($_=~/\./) {
1648: my $unikey=$_;
1649: $unikey=~/^([A-Za-z]+)/;
1650: my $tag=$1;
1651: $tag=~tr/A-Z/a-z/;
1652: print $mfh "\n\<$tag";
1653: foreach (split(/\,/,$metadatakeys{$unikey})) {
1654: my $value=$metadatafields{$unikey.'.'.$_};
1655: $value=~s/\"/\'\'/g;
1656: print $mfh ' '.$_.'="'.$value.'"';
1657: }
1658: print $mfh '>'.
1.165 albertel 1659: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
1.100 matthew 1660: .'</'.$tag.'>';
1661: }
1662: }
1.136 www 1663: $r->print('<p>'.&mt('Wrote Metadata').'</p>');
1.100 matthew 1664: print $logfile "\nWrote metadata";
1665: }
1666:
1667: # -------------------------------- Synchronize entry with SQL metadata database
1.12 www 1668:
1.89 matthew 1669: $metadatafields{'url'} = $distarget;
1670: $metadatafields{'version'} = 'current';
1.152 www 1671:
1672: my ($error,$success) = &store_metadata(%metadatafields);
1673: if ($success) {
1674: $r->print('<p>'.&mt('Synchronized SQL metadata database').'</p>');
1675: print $logfile "\nSynchronized SQL metadata database";
1.89 matthew 1676: } else {
1.152 www 1677: $r->print($error);
1678: print $logfile "\n".$error;
1.24 harris41 1679: }
1.159 www 1680: # --------------------------------------------- Delete author resource messages
1681: my $delresult=&Apache::lonmsg::del_url_author_res_msg($target);
1682: $r->print('<p>'.&mt('Removing error messages:').' '.$delresult.'</p>');
1683: print $logfile "\nRemoving error messages: $delresult";
1.12 www 1684: # ----------------------------------------------------------- Copy old versions
1685:
1.100 matthew 1686: if (-e $target) {
1687: my $filename;
1688: my $maxversion=0;
1689: $target=~/(.*)\/([^\/]+)\.(\w+)$/;
1690: my $srcf=$2;
1691: my $srct=$3;
1692: my $srcd=$1;
1.261 raeburn 1693: my $docroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1694: unless ($srcd=~/^\Q$docroot\E\/res/) {
1.100 matthew 1695: print $logfile "\nPANIC: Target dir is ".$srcd;
1.197 www 1696: $r->print(
1.239 bisitz 1697: "<span class=\"LC_error\">".&mt('Invalid target directory, FAIL')."</span>");
1.197 www 1698: return 0;
1.100 matthew 1699: }
1700: opendir(DIR,$srcd);
1701: while ($filename=readdir(DIR)) {
1702: if (-l $srcd.'/'.$filename) {
1703: unlink($srcd.'/'.$filename);
1704: unlink($srcd.'/'.$filename.'.meta');
1705: } else {
1.252 raeburn 1706: if ($filename=~/^\Q$srcf\E\.(\d+)\.\Q$srct\E$/) {
1.100 matthew 1707: $maxversion=($1>$maxversion)?$1:$maxversion;
1708: }
1709: }
1710: }
1711: closedir(DIR);
1712: $maxversion++;
1.254 bisitz 1713: $r->print('<p>'.&mt('Creating old version [_1]',$maxversion).'</p>');
1.125 www 1714: print $logfile "\nCreating old version ".$maxversion."\n";
1.100 matthew 1715:
1716: my $copyfile=$srcd.'/'.$srcf.'.'.$maxversion.'.'.$srct;
1717:
1.13 www 1718: if (copy($target,$copyfile)) {
1.12 www 1719: print $logfile "Copied old target to ".$copyfile."\n";
1.265 www 1720: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied old target file')));
1.12 www 1721: } else {
1.13 www 1722: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
1.265 www 1723: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Failed to copy old target').", $!",1));
1.197 www 1724: return 0;
1.12 www 1725: }
1.100 matthew 1726:
1.12 www 1727: # --------------------------------------------------------------- Copy Metadata
1728:
1729: $copyfile=$copyfile.'.meta';
1.100 matthew 1730:
1.13 www 1731: if (copy($target.'.meta',$copyfile)) {
1.14 www 1732: print $logfile "Copied old target metadata to ".$copyfile."\n";
1.265 www 1733: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied old metadata')));
1.12 www 1734: } else {
1.13 www 1735: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1.14 www 1736: if (-e $target.'.meta') {
1.265 www 1737: $r->print(&Apache::lonhtmlcommon::confirm_success(
1738: &mt('Failed to write old metadata copy').", $!",1));
1.197 www 1739: return 0;
1.14 www 1740: }
1.12 www 1741: }
1.100 matthew 1742:
1743:
1744: } else {
1.138 www 1745: $r->print('<p>'.&mt('Initial version').'</p>');
1.100 matthew 1746: print $logfile "\nInitial version";
1747: }
1.12 www 1748:
1749: # ---------------------------------------------------------------- Write Source
1.100 matthew 1750: my $copyfile=$target;
1751:
1752: my @parts=split(/\//,$copyfile);
1753: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
1754:
1755: my $count;
1756: for ($count=5;$count<$#parts;$count++) {
1757: $path.="/$parts[$count]";
1758: if ((-e $path)!=1) {
1759: print $logfile "\nCreating directory ".$path;
1760: mkdir($path,0777);
1.255 bisitz 1761: $r->print('<p>'
1762: .&mt('Created directory [_1]'
1763: ,'<span class="LC_filename">'.$parts[$count].'</span>')
1764: .'</p>'
1765: );
1.12 www 1766: }
1.100 matthew 1767: }
1768:
1769: if (copy($source,$copyfile)) {
1770: print $logfile "\nCopied original source to ".$copyfile."\n";
1.265 www 1771: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied source file')));
1.100 matthew 1772: } else {
1773: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
1.265 www 1774: $r->print(&Apache::lonhtmlcommon::confirm_success(
1775: &mt('Failed to copy source').", $!",1));
1.197 www 1776: return 0;
1.100 matthew 1777: }
1778:
1.265 www 1779: # ---------------------------------------------- Delete local tmp-preview files
1780: unlink($copyfile.'.tmp');
1.12 www 1781: # --------------------------------------------------------------- Copy Metadata
1782:
1.100 matthew 1783: $copyfile=$copyfile.'.meta';
1784:
1785: if (copy($source.'.meta',$copyfile)) {
1786: print $logfile "\nCopied original metadata to ".$copyfile."\n";
1.265 www 1787: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied metadata')));
1.100 matthew 1788: } else {
1789: print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n";
1.265 www 1790: $r->print(&Apache::lonhtmlcommon::confirm_success(
1791: &mt('Failed to write metadata copy').", $!",1));
1.197 www 1792: return 0;
1.100 matthew 1793: }
1794: $r->rflush;
1.12 www 1795:
1.181 www 1796: # ------------------------------------------------------------- Trigger updates
1.183 www 1797: push(@{$modified_urls},[$target,$source]);
1.182 www 1798: unless ($registered_cleanup) {
1.263 raeburn 1799: my $handlers = $r->get_handlers('PerlCleanupHandler');
1800: $r->set_handlers('PerlCleanupHandler' => [\¬ify,@{$handlers}]);
1.182 www 1801: $registered_cleanup=1;
1802: }
1.199 www 1803:
1804: # ---------------------------------------------------------- Clear local caches
1805: my $thisdistarget=$target;
1806: $thisdistarget=~s/^\Q$docroot\E//;
1807: &Apache::lonnet::devalidate_cache_new('resversion',$target);
1808: &Apache::lonnet::devalidate_cache_new('meta',
1809: &Apache::lonnet::declutter($thisdistarget));
1810:
1.255 bisitz 1811: # ------------------------------------------------------------- Everything done
1812: $logfile->close();
1813: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1814:
1.12 www 1815: # ------------------------------------------------ Provide link to new resource
1.100 matthew 1816: unless ($batch) {
1817:
1.271 www 1818: my $thissrc=&Apache::loncfile::url($source);
1.100 matthew 1819: my $thissrcdir=$thissrc;
1820: $thissrcdir=~s/\/[^\/]+$/\//;
1821:
1.284 bisitz 1822: $r->print(
1823: &Apache::lonhtmlcommon::actionbox([
1.264 raeburn 1824: '<a href="'.$thisdistarget.'">'.
1825: &mt('View Published Version').
1.284 bisitz 1826: '</a>',
1.264 raeburn 1827: '<a href="'.$thissrc.'">'.
1828: &mt('Back to Source').
1.284 bisitz 1829: '</a>',
1.264 raeburn 1830: '<a href="'.$thissrcdir.'">'.
1831: &mt('Back to Source Directory').
1.284 bisitz 1832: '</a>'])
1.262 bisitz 1833: );
1.100 matthew 1834: }
1.197 www 1835: return 1;
1.11 www 1836: }
1837:
1.181 www 1838: # =============================================================== Notifications
1839: sub notify {
1840: # --------------------------------------------------- Send update notifications
1.183 www 1841: foreach my $targetsource (@{$modified_urls}){
1.182 www 1842: my ($target,$source)=@{$targetsource};
1843: my $logfile=Apache::File->new('>>'.$source.'.log');
1844: print $logfile "\nCleanup phase: Notifications\n";
1845: my @subscribed=&get_subscribed_hosts($target);
1846: foreach my $subhost (@subscribed) {
1847: print $logfile "\nNotifying host ".$subhost.':';
1848: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
1849: print $logfile $reply;
1850: }
1.181 www 1851: # ---------------------------------------- Send update notifications, meta only
1.182 www 1852: my @subscribedmeta=&get_subscribed_hosts("$target.meta");
1853: foreach my $subhost (@subscribedmeta) {
1854: print $logfile "\nNotifying host for metadata only ".$subhost.':';
1855: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
1856: $subhost);
1857: print $logfile $reply;
1858: }
1.181 www 1859: # --------------------------------------------------- Notify subscribed courses
1.182 www 1860: my %courses=&coursedependencies($target);
1861: my $now=time;
1862: foreach (keys %courses) {
1863: print $logfile "\nNotifying course ".$_.':';
1864: my ($cdom,$cname)=split(/\_/,$_);
1865: my $reply=&Apache::lonnet::cput
1866: ('versionupdate',{$target => $now},$cdom,$cname);
1867: print $logfile $reply;
1868: }
1869: print $logfile "\n============ Done ============\n";
1870: $logfile->close();
1.181 www 1871: }
1.233 www 1872: if ($lock) { &Apache::lonnet::remove_lock($lock); }
1.182 www 1873: return OK;
1.181 www 1874: }
1875:
1.95 www 1876: #########################################
1877:
1878: sub batchpublish {
1.97 www 1879: my ($r,$srcfile,$targetfile)=@_;
1.192 albertel 1880: #publication pollutes %env with form.* values
1881: my %oldenv=%env;
1.102 www 1882: $srcfile=~s/\/+/\//g;
1883: $targetfile=~s/\/+/\//g;
1.95 www 1884: $srcfile=~s/\/+/\//g;
1.96 www 1885:
1.97 www 1886: my $docroot=$r->dir_config('lonDocRoot');
1887: my $thisdistarget=$targetfile;
1.122 albertel 1888: $thisdistarget=~s/^\Q$docroot\E//;
1.97 www 1889:
1.96 www 1890:
1.139 albertel 1891: %metadatafields=();
1892: %metadatakeys=();
1893: $srcfile=~/\.(\w+)$/;
1894: my $thistype=$1;
1.97 www 1895:
1896:
1.139 albertel 1897: my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
1.96 www 1898:
1.254 bisitz 1899: $r->print('<h2>'
1.271 www 1900: .&mt('Publishing [_1]',&Apache::loncfile::display($srcfile))
1.254 bisitz 1901: .'</h2>'
1902: );
1.97 www 1903:
1904: # phase one takes
1905: # my ($source,$target,$style,$batch)=@_;
1.113 albertel 1906: my ($outstring,$error)=&publish($srcfile,$targetfile,$thisembstyle,1);
1907: $r->print('<p>'.$outstring.'</p>');
1.96 www 1908: # phase two takes
1909: # my ($source,$target,$style,$distarget,batch)=@_;
1.192 albertel 1910: # $env{'form.allmeta'},$env{'form.title'},$env{'form.author'},...
1.113 albertel 1911: if (!$error) {
1912: $r->print('<p>');
1913: &phasetwo($r,$srcfile,$targetfile,$thisembstyle,$thisdistarget,1);
1914: $r->print('</p>');
1915: }
1.192 albertel 1916: %env=%oldenv;
1.97 www 1917: return '';
1.95 www 1918: }
1.1 www 1919:
1.90 matthew 1920: #########################################
1.95 www 1921:
1922: sub publishdirectory {
1923: my ($r,$fn,$thisdisfn)=@_;
1.102 www 1924: $fn=~s/\/+/\//g;
1925: $thisdisfn=~s/\/+/\//g;
1.273 www 1926: my $thisdisresdir=$thisdisfn;
1927: $thisdisresdir=~s/^\/priv\//\/res\//;
1.276 raeburn 1928: my $resdir = $r->dir_config('lonDocRoot').$thisdisresdir;
1.258 bisitz 1929: $r->print(&Apache::lonhtmlcommon::start_pick_box()
1930: .&Apache::lonhtmlcommon::row_title(&mt('Directory'))
1931: .'<span class="LC_filename">'.$thisdisfn.'</span>'
1932: .&Apache::lonhtmlcommon::row_closure()
1933: .&Apache::lonhtmlcommon::row_title(&mt('Target'))
1.273 www 1934: .'<span class="LC_filename">'.$thisdisresdir.'</span>'
1.258 bisitz 1935: );
1.139 albertel 1936:
1937: my $dirptr=16384; # Mask indicating a directory in stat.cmode.
1.193 www 1938: unless ($env{'form.phase'} eq 'two') {
1939: # ask user what they want
1.258 bisitz 1940: $r->print(&Apache::lonhtmlcommon::row_closure()
1941: .&Apache::lonhtmlcommon::row_title(&mt('Options'))
1942: );
1.283 bisitz 1943: $r->print('<form name="pubdirpref" method="post" action="">'.
1.193 www 1944: &hiddenfield('phase','two').
1945: &hiddenfield('filename',$env{'form.filename'}).
1946: &checkbox('pubrec','include subdirectories').
1.194 www 1947: &checkbox('forcerepub','force republication of previously published files').
1.206 albertel 1948: &checkbox('obsolete','make file(s) obsolete').
1.250 schafran 1949: &checkbox('forceoverride','force directory level metadata over existing').
1.195 www 1950: '<br /><input type="submit" value="'.&mt('Publish Directory').'" /></form>');
1.258 bisitz 1951: $r->print(&Apache::lonhtmlcommon::row_closure(1)
1952: .&Apache::lonhtmlcommon::end_pick_box()
1953: );
1.233 www 1954: $lock=0;
1.193 www 1955: } else {
1.258 bisitz 1956: $r->print(&Apache::lonhtmlcommon::row_closure(1)
1957: .&Apache::lonhtmlcommon::end_pick_box()
1958: );
1.234 www 1959: unless ($lock) { $lock=&Apache::lonnet::set_lock(&mt('Publishing [_1]',$fn)); }
1.193 www 1960: # actually publish things
1961: opendir(DIR,$fn);
1962: my @files=sort(readdir(DIR));
1963: foreach my $filename (@files) {
1964: my ($cdev,$cino,$cmode,$cnlink,
1965: $cuid,$cgid,$crdev,$csize,
1966: $catime,$cmtime,$cctime,
1967: $cblksize,$cblocks)=stat($fn.'/'.$filename);
1968:
1969: my $extension='';
1970: if ($filename=~/\.(\w+)$/) { $extension=$1; }
1971: if ($cmode&$dirptr) {
1972: if (($filename!~/^\./) && ($env{'form.pubrec'})) {
1.285 raeburn 1973: &publishdirectory($r,$fn.'/'.$filename,$thisdisfn.'/'.$filename);
1.193 www 1974: }
1975: } elsif ((&Apache::loncommon::fileembstyle($extension) ne 'hdn') &&
1976: ($filename!~/^[\#\.]/) && ($filename!~/\~$/)) {
1.96 www 1977: # find out publication status and/or exiting metadata
1.193 www 1978: my $publishthis=0;
1979: if (-e $resdir.'/'.$filename) {
1980: my ($rdev,$rino,$rmode,$rnlink,
1981: $ruid,$rgid,$rrdev,$rsize,
1982: $ratime,$rmtime,$rctime,
1983: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
1984: if (($rmtime<$cmtime) || ($env{'form.forcerepub'})) {
1.96 www 1985: # previously published, modified now
1.193 www 1986: $publishthis=1;
1987: }
1.212 albertel 1988: my $meta_cmtime = (stat($fn.'/'.$filename.'.meta'))[9];
1989: my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
1990: if ( $meta_rmtime<$meta_cmtime ) {
1991: $publishthis=1;
1992: }
1.193 www 1993: } else {
1994: # never published
1.96 www 1995: $publishthis=1;
1.193 www 1996: }
1.212 albertel 1997:
1.193 www 1998: if ($publishthis) {
1999: &batchpublish($r,$fn.'/'.$filename,$resdir.'/'.$filename);
2000: } else {
2001: $r->print('<br />'.&mt('Skipping').' '.$filename.'<br />');
2002: }
2003: $r->rflush();
1.139 albertel 2004: }
2005: }
1.193 www 2006: closedir(DIR);
1.139 albertel 2007: }
1.95 www 2008: }
1.160 www 2009:
2010: #########################################
2011: # publish a default.meta file
2012:
2013: sub defaultmetapublish {
2014: my ($r,$fn,$cuname,$cudom)=@_;
2015: unless (-e $fn) {
2016: return HTTP_NOT_FOUND;
2017: }
2018: my $target=$fn;
1.270 www 2019: $target=~s/^\Q$Apache::lonnet::perlvar{'lonDocRoot'}\E\/priv\//\Q$Apache::lonnet::perlvar{'lonDocRoot'}\E\/res\//;
1.160 www 2020:
2021:
2022: &Apache::loncommon::content_type($r,'text/html');
2023: $r->send_http_header;
2024:
1.251 schafran 2025: $r->print(&Apache::loncommon::start_page('Metadata Publication'));
1.160 www 2026:
2027: # ---------------------------------------------------------------- Write Source
2028: my $copyfile=$target;
2029:
2030: my @parts=split(/\//,$copyfile);
2031: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
2032:
2033: my $count;
2034: for ($count=5;$count<$#parts;$count++) {
2035: $path.="/$parts[$count]";
2036: if ((-e $path)!=1) {
2037: mkdir($path,0777);
1.255 bisitz 2038: $r->print('<p>'
2039: .&mt('Created directory [_1]'
2040: ,'<span class="LC_filename">'.$parts[$count].'</span>')
2041: .'</p>'
2042: );
1.160 www 2043: }
2044: }
2045:
2046: if (copy($fn,$copyfile)) {
2047: $r->print('<p>'.&mt('Copied source file').'</p>');
2048: } else {
1.226 albertel 2049: return "<span class=\"LC_error\">".
2050: &mt('Failed to copy source').", $!, ".&mt('FAIL')."</span>";
1.160 www 2051: }
2052:
2053: # --------------------------------------------------- Send update notifications
2054:
2055: my @subscribed=&get_subscribed_hosts($target);
2056: foreach my $subhost (@subscribed) {
2057: $r->print('<p>'.&mt('Notifying host').' '.$subhost.':');$r->rflush;
2058: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
2059: $r->print($reply.'</p><br />');$r->rflush;
2060: }
2061: # ------------------------------------------------------------------- Link back
1.281 raeburn 2062: $r->print("<a href='".&Apache::loncfile::display($fn)."'>".&mt('Back to Metadata').'</a>');
1.208 albertel 2063: $r->print(&Apache::loncommon::end_page());
1.160 www 2064: return OK;
2065: }
1.90 matthew 2066: #########################################
2067:
2068: =pod
2069:
1.94 harris41 2070: =item B<handler>
1.90 matthew 2071:
2072: A basic outline of the handler subroutine follows.
2073:
2074: =over 4
2075:
1.94 harris41 2076: =item *
2077:
2078: Get query string for limited number of parameters.
2079:
2080: =item *
2081:
2082: Check filename.
2083:
2084: =item *
2085:
2086: File is there and owned, init lookup tables.
2087:
2088: =item *
1.90 matthew 2089:
1.94 harris41 2090: Start page output.
1.90 matthew 2091:
1.94 harris41 2092: =item *
1.90 matthew 2093:
1.94 harris41 2094: Evaluate individual file, and then output information.
1.90 matthew 2095:
1.94 harris41 2096: =item *
1.90 matthew 2097:
1.94 harris41 2098: Publishing from $thisfn to $thistarget with $thisembstyle.
1.90 matthew 2099:
2100: =back
2101:
2102: =cut
2103:
2104: #########################################
2105: #########################################
1.1 www 2106: sub handler {
1.139 albertel 2107: my $r=shift;
1.2 www 2108:
1.139 albertel 2109: if ($r->header_only) {
2110: &Apache::loncommon::content_type($r,'text/html');
2111: $r->send_http_header;
2112: return OK;
2113: }
1.2 www 2114:
1.43 www 2115: # Get query string for limited number of parameters
2116:
1.80 matthew 2117: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2118: ['filename']);
1.43 www 2119:
1.183 www 2120: # -------------------------------------- Flag and buffer for registered cleanup
1.182 www 2121: $registered_cleanup=0;
1.183 www 2122: @{$modified_urls}=();
1.2 www 2123: # -------------------------------------------------------------- Check filename
2124:
1.209 www 2125: my $fn=&unescape($env{'form.filename'});
1.280 raeburn 2126: ($cuname,$cudom)=&Apache::lonnet::constructaccess($fn);
1.268 www 2127: # ----------------------------------------------------- Do we have permissions?
2128: unless (($cuname) && ($cudom)) {
2129: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
2130: ' trying to publish file '.$env{'form.filename'}.
2131: ' - not authorized',
2132: $r->filename);
2133: return HTTP_NOT_ACCEPTABLE;
2134: }
2135: # ----------------------------------------------------------------- Get docroot
2136: $docroot=$r->dir_config('lonDocRoot');
1.160 www 2137:
2138:
2139: # special publication: default.meta file
2140: if ($fn=~/\/default.meta$/) {
2141: return &defaultmetapublish($r,$fn,$cuname,$cudom);
2142: }
1.159 www 2143: $fn=~s/\.meta$//;
1.268 www 2144:
2145: # sanity test on the filename
2146:
1.139 albertel 2147: unless ($fn) {
2148: $r->log_reason($cuname.' at '.$cudom.
2149: ' trying to publish empty filename', $r->filename);
2150: return HTTP_NOT_FOUND;
2151: }
2152:
1.268 www 2153: unless (-e $docroot.$fn) {
1.139 albertel 2154: $r->log_reason($cuname.' at '.$cudom.
2155: ' trying to publish non-existing file '.
1.192 albertel 2156: $env{'form.filename'}.' ('.$fn.')',
1.139 albertel 2157: $r->filename);
2158: return HTTP_NOT_FOUND;
2159: }
1.2 www 2160:
1.94 harris41 2161: # -------------------------------- File is there and owned, init lookup tables.
1.2 www 2162:
1.205 albertel 2163: %addid=();
2164:
2165: {
2166: my $fh=Apache::File->new($r->dir_config('lonTabDir').'/addid.tab');
2167: while (<$fh>=~/(\w+)\s+(\w+)/) {
2168: $addid{$1}=$2;
1.139 albertel 2169: }
1.205 albertel 2170: }
1.3 www 2171:
1.205 albertel 2172: %nokey=();
1.11 www 2173:
1.205 albertel 2174: {
2175: my $fh=Apache::File->new($r->dir_config('lonIncludes').'/un_keyword.tab');
2176: while (<$fh>) {
2177: my $word=$_;
2178: chomp($word);
2179: $nokey{$word}=1;
1.139 albertel 2180: }
2181: }
1.11 www 2182:
1.94 harris41 2183: # ---------------------------------------------------------- Start page output.
1.2 www 2184:
1.139 albertel 2185: &Apache::loncommon::content_type($r,'text/html');
2186: $r->send_http_header;
1.180 albertel 2187:
1.259 bisitz 2188: # Breadcrumbs
2189: &Apache::lonhtmlcommon::clear_breadcrumbs();
2190: &Apache::lonhtmlcommon::add_breadcrumb({
1.282 raeburn 2191: 'text' => 'Authoring Space',
1.277 raeburn 2192: 'href' => &Apache::loncommon::authorspace($fn),
1.259 bisitz 2193: });
2194: &Apache::lonhtmlcommon::add_breadcrumb({
2195: 'text' => 'Resource Publication',
2196: 'href' => '',
2197: });
2198:
1.208 albertel 2199: my $js='<script type="text/javascript">'.
2200: &Apache::loncommon::browser_and_searcher_javascript().
2201: '</script>';
1.259 bisitz 2202: $r->print(&Apache::loncommon::start_page('Resource Publication',$js)
2203: .&Apache::lonhtmlcommon::breadcrumbs()
2204: .&Apache::loncommon::head_subbox(
1.275 raeburn 2205: &Apache::loncommon::CSTR_pageheader($docroot.$fn))
1.259 bisitz 2206: );
1.101 www 2207:
1.268 www 2208: my $thisdisfn=&HTML::Entities::encode($fn,'<>&"');
2209: my $thistarget=$fn;
2210: $thistarget=~s/^\/priv\//\/res\//;
2211: my $thisdistarget=&HTML::Entities::encode($thistarget,'<>&"');
1.95 www 2212:
1.139 albertel 2213: if ($fn=~/\/$/) {
1.95 www 2214: # -------------------------------------------------------- This is a directory
1.273 www 2215: &publishdirectory($r,$docroot.$fn,$thisdisfn);
1.268 www 2216: $r->print('<hr /><a href="'.$thisdisfn.'">'.&mt('Return to Directory').'</a>');
1.139 albertel 2217: } else {
1.94 harris41 2218: # ---------------------- Evaluate individual file, and then output information.
1.268 www 2219: $fn=~/\.(\w+)$/;
1.139 albertel 2220: my $thistype=$1;
2221: my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
1.200 raeburn 2222: if ($thistype eq 'page') { $thisembstyle = 'rat'; }
1.2 www 2223:
1.254 bisitz 2224: $r->print('<h2>'
2225: .&mt('Publishing [_1]'
2226: ,'<span class="LC_filename">'.$thisdisfn.'</span>')
2227: .'</h2>'
2228: );
1.239 bisitz 2229:
2230: $r->print('<h3>'.&mt('Resource Details').'</h3>');
2231:
2232: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2233:
2234: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Type'))
2235: .&Apache::loncommon::filedescription($thistype)
2236: .&Apache::lonhtmlcommon::row_closure()
2237: );
2238:
2239: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Link to Resource'))
2240: .'<tt>'
2241: );
1.139 albertel 2242: $r->print(<<ENDCAPTION);
1.268 www 2243: <a href='javascript:void(window.open("$thisdisfn","cat","height=300,width=500,scrollbars=1,resizable=1,menubar=0,location=1"))'>
1.129 www 2244: $thisdisfn</a>
2245: ENDCAPTION
1.239 bisitz 2246: $r->print('</tt>'
2247: .&Apache::lonhtmlcommon::row_closure()
2248: );
2249:
2250: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Target'))
2251: .'<tt>'.$thisdistarget.'</tt>'
2252: );
1.192 albertel 2253: if (($cuname ne $env{'user.name'})||($cudom ne $env{'user.domain'})) {
1.240 raeburn 2254: $r->print(&Apache::lonhtmlcommon::row_closure()
2255: .&Apache::lonhtmlcommon::row_title(&mt('Co-Author'))
1.239 bisitz 2256: .'<span class="LC_warning">'
1.258 bisitz 2257: .&Apache::loncommon::plainname($cuname,$cudom) .' ('.$cuname.':'.$cudom.')'
1.239 bisitz 2258: .'</span>'
2259: );
1.139 albertel 2260: }
1.26 www 2261:
1.139 albertel 2262: if (&Apache::loncommon::fileembstyle($thistype) eq 'ssi') {
1.240 raeburn 2263: $r->print(&Apache::lonhtmlcommon::row_closure()
2264: .&Apache::lonhtmlcommon::row_title(&mt('Diffs')));
1.139 albertel 2265: $r->print(<<ENDDIFF);
1.284 bisitz 2266: <a href='javascript:void(window.open("/adm/diff?filename=$thisdisfn&versiontwo=priv","cat","height=300,width=500,scrollbars=1,resizable=1,menubar=0,location=1"))'>
1.129 www 2267: ENDDIFF
1.240 raeburn 2268: $r->print(&mt('Diffs with Current Version').'</a>');
1.139 albertel 2269: }
1.240 raeburn 2270:
2271: $r->print(&Apache::lonhtmlcommon::row_closure(1)
2272: .&Apache::lonhtmlcommon::end_pick_box()
2273: );
1.11 www 2274:
1.268 www 2275: # ---------------------- Publishing from $fn to $thistarget with $thisembstyle.
1.2 www 2276:
1.192 albertel 2277: unless ($env{'form.phase'} eq 'two') {
1.185 www 2278: # ---------------------------------------------------------- Parse for problems
1.189 albertel 2279: my ($warningcount,$errorcount);
2280: if ($thisembstyle eq 'ssi') {
1.268 www 2281: ($warningcount,$errorcount)=&checkonthis($r,$fn);
1.189 albertel 2282: }
2283: unless ($errorcount) {
1.187 www 2284: my ($outstring,$error)=
1.272 www 2285: &publish($docroot.$fn,$docroot.$thistarget,$thisembstyle);
1.246 bisitz 2286: $r->print($outstring);
1.187 www 2287: } else {
1.239 bisitz 2288: $r->print('<h3 class="LC_error">'.
1.189 albertel 2289: &mt('The document contains errors and cannot be published.').
1.187 www 2290: '</h3>');
2291: }
1.139 albertel 2292: } else {
1.272 www 2293: &phasetwo($r,$docroot.$fn,$docroot.$thistarget,$thisembstyle,$thisdistarget);
1.139 albertel 2294: }
2295: }
1.208 albertel 2296: $r->print(&Apache::loncommon::end_page());
1.15 www 2297:
1.139 albertel 2298: return OK;
1.1 www 2299: }
2300:
2301: 1;
2302: __END__
2303:
1.89 matthew 2304: =pod
1.126 bowersj2 2305:
2306: =back
1.66 harris41 2307:
2308: =back
2309:
1.89 matthew 2310: =cut
1.66 harris41 2311:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>