1: # The LearningOnline Network with CAPA
2: # Authoring Space Directory Lister
3: #
4: # $Id: lonpubdir.pm,v 1.153 2014/05/20 19:53:59 raeburn Exp $
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: #
28: ###
29:
30: package Apache::lonpubdir;
31:
32: use strict;
33: use Apache::File;
34: use File::Copy;
35: use Apache::Constants qw(:common :http :methods);
36: use Apache::loncommon();
37: use Apache::lonhtmlcommon();
38: use Apache::londiff();
39: use Apache::lonlocal;
40: use Apache::lonmsg;
41: use Apache::lonmenu;
42: use Apache::lonnet;
43: use LONCAPA;
44:
45: sub handler {
46:
47: my $r=shift;
48:
49: # Validate access to the construction space and get username:domain.
50:
51: my ($uname,$udom)=&Apache::lonnet::constructaccess($r->uri);
52: unless (($uname) && ($udom)) {
53: return HTTP_NOT_ACCEPTABLE;
54: }
55:
56: # ----------------------------------------------------------- Start page output
57:
58: my $fn=$r->filename;
59: $fn=~s/\/$//;
60: my $thisdisfn=$fn;
61:
62: my $docroot=$r->dir_config('lonDocRoot'); # Apache londocument root.
63: $thisdisfn=~s/^\Q$docroot\E\/priv//;
64:
65: my $resdir=$docroot.'/res'.$thisdisfn; # Resource directory
66: my $targetdir='/res'.$thisdisfn; # Publication target directory.
67: my $linkdir='/priv'.$thisdisfn; # Full URL name of constr space.
68:
69: my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
70:
71: &startpage($r, $uname, $udom, $thisdisfn); # Put out the start of page.
72: &dircontrols($r,$uname,$udom,$thisdisfn); # Put out actions for directory,
73: # browse/upload + new file page.
74: &resourceactions($r,$uname,$udom,$thisdisfn); # Put out form used for printing/deletion etc.
75:
76: my $numdir = 0;
77: my $numres = 0;
78:
79: # Retrieving value for "sortby" and "sortorder" from QUERY_STRING
80: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
81: ['sortby','sortorder']);
82:
83: # Sort by name as default, not reversed
84: if (! exists($env{'form.sortby'})) { $env{'form.sortby'} = 'filename' }
85: if (! exists($env{'form.sortorder'})) { $env{'form.sortorder'} = '' }
86:
87: my $sortby = $env{'form.sortby'};
88: my $sortorder = $env{'form.sortorder'};
89:
90: # Start off the directory table.
91: $r->print(&Apache::loncommon::start_data_table()
92: .&Apache::loncommon::start_data_table_header_row()
93: .'<th><a href="'.$linkdir.'/?sortby=filetype&sortorder='
94: .((($sortby eq "filetype") && ($sortorder ne 'rev')) ? 'rev' : '')
95: .'">'.&mt('Type')
96: .'<span class="LC_fontsize_small"> ▼</span></a></th>'
97: .'<th>'.&mt('Actions').'</th>'
98: .'<th><a href="'.$linkdir.'/?sortby=filename&sortorder='
99: .((($sortby eq "filename") && ($sortorder ne 'rev')) ? 'rev' : '')
100: .'">'.&mt('Name')
101: .'<span class="LC_fontsize_small"> ▼</span></a></th>'
102: .'<th><a href="'.$linkdir.'/?sortby=title&sortorder='
103: .((($sortby eq "title") && ($sortorder ne 'rev')) ? 'rev' : '')
104: .'">'.&mt('Title')
105: .'<span class="LC_fontsize_small"> ▼</span></a></th>'
106: .'<th colspan="2"><a href="'.$linkdir.'/?sortby=pubstatus&sortorder='
107: .((($sortby eq "pubstatus") && ($sortorder ne 'rev')) ? 'rev' : '')
108: .'">'.&mt('Status')
109: .'<span class="LC_fontsize_small"> ▼</span></a></th>'
110: .'<th><a href="'.$linkdir.'/?sortby=cmtime&sortorder='
111: .((($sortby eq "cmtime") && ($sortorder ne 'rev')) ? 'rev' : '')
112: .'">'.&mt('Last Modified')
113: .'<span class="LC_fontsize_small"> ▼</span></a></th>'
114: .'<th><a href="'.$linkdir.'/?sortby=size&sortorder='
115: .((($sortby eq "size") && ($sortorder ne 'rev')) ? 'rev' : '')
116: .'">'.&mt('Size').' (kB)'
117: .'<span class="LC_fontsize_small"> ▼</span></a></th>'
118: .&Apache::loncommon::end_data_table_header_row()
119: );
120:
121: my $dirptr=16384; # Mask indicating a directory in stat.cmode.
122:
123: opendir(DIR,$fn);
124: my $filehash = {};
125: my @files= readdir(DIR);
126: foreach my $filename (@files) {
127: # Skip .DS_Store and hidden files
128: my ($extension) = ($filename=~/\.(\w+)$/);
129: next if (($filename eq '.DS_Store')
130: || &Apache::loncommon::fileembstyle($extension) eq 'hdn');
131:
132: my ($cmode,$csize,$cmtime)=(stat($fn.'/'.$filename))[2,7,9];
133: my $linkfilename = &HTML::Entities::encode('/priv'.$thisdisfn.'/'.$filename,'<>&"');
134: # Identify type of file according to icon used
135: my ($filetype) = (&Apache::loncommon::icon($filename) =~ m{/(\w+).gif$});
136: my $cstr_dir = $r->dir_config('lonDocRoot').'/priv'.$thisdisfn;
137: my $meta_same = &isMetaSame($cstr_dir, $resdir, $filename);
138:
139: # Store size, title, and status for files but not directories
140: my $size = (!($cmode&$dirptr)) ? $csize/1024. : 0;
141: my ($status, $pubstatus, $title, $fulltitle);
142: if (!($cmode&$dirptr)) {
143: ($status, $pubstatus) = &getStatus($resdir, $targetdir, $cstr_dir,
144: $filename, $linkfilename, $cmtime, $meta_same);
145: ($fulltitle, $title) = &getTitle($resdir, $targetdir, $filename,
146: $linkfilename, $meta_same, \%bombs);
147: } else {
148: ($status, $pubstatus) = ('','');
149: ($fulltitle, $title) = ('','');
150: }
151:
152: # This hash will allow sorting
153: $filehash->{ $filename } = {
154: "cmtime" => $cmtime,
155: "size" => $size,
156: "cmode" => $cmode,
157: "filetype" => $filetype,
158: "title" => $title,
159: "fulltitle" => $fulltitle,
160: "status" => $status,
161: "pubstatus" => $pubstatus,
162: "linkfilename" => $linkfilename,
163: }
164: }
165:
166: my @sorted_files;
167: # Sorting by something other than "Name". Name is the secondary key.
168: if ($sortby =~ m{cmtime|size}) { # Numeric fields
169: # First check if order should be reversed
170: if ($sortorder eq "rev") {
171: @sorted_files = sort {
172: $filehash->{$a}->{$sortby} <=> $filehash->{$b}->{$sortby}
173: or
174: uc($a) cmp uc($b)
175: } (keys(%{$filehash}));
176: } else {
177: @sorted_files = sort {
178: $filehash->{$b}->{$sortby} <=> $filehash->{$a}->{$sortby}
179: or
180: uc($a) cmp uc($b)
181: } (keys(%{$filehash}));
182: }
183: } elsif ($sortby =~ m{filetype|title|status}) { # String fields
184: if ($sortorder eq "rev") {
185: @sorted_files = sort {
186: $filehash->{$b}->{$sortby} cmp $filehash->{$a}->{$sortby}
187: or
188: uc($a) cmp uc($b)
189: } (keys(%{$filehash}));
190: } else {
191: @sorted_files = sort {
192: $filehash->{$a}->{$sortby} cmp $filehash->{$b}->{$sortby}
193: or
194: uc($a) cmp uc($b)
195: } (keys(%{$filehash}));
196: }
197:
198: # Sort by "Name" is the default
199: } else {
200: if ($sortorder eq "rev") {
201: @sorted_files = sort {uc($b) cmp uc($a)} (keys(%{$filehash}));
202: } else {
203: @sorted_files = sort {uc($a) cmp uc($b)} (keys(%{$filehash}));
204: }
205: }
206:
207: # Print the sorted resources
208: foreach my $filename (@sorted_files) {
209: if ($filehash->{$filename}->{"cmode"}&$dirptr) { # Directories
210: &putdirectory($r, $thisdisfn, $linkdir, $filename,
211: $filehash->{$filename}->{"cmtime"},
212: $targetdir, \%bombs, \$numdir);
213: } else { # Files
214: &putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir,
215: $targetdir, $linkdir, $filehash->{$filename}->{"cmtime"},
216: $filehash->{$filename}->{"size"}, \$numres,
217: $filehash->{$filename}->{"linkfilename"},
218: $filehash->{$filename}->{"fulltitle"},
219: $filehash->{$filename}->{"status"},
220: $filehash->{$filename}->{"pubstatus"});
221: }
222: }
223:
224: closedir(DIR);
225:
226: $r->print( &Apache::loncommon::end_data_table()
227: .&Apache::loncommon::end_page() );
228:
229: return OK;
230: }
231:
232:
233:
234: # Output the header of the page. This includes:
235: # - The HTML header
236: # - The H1/H3 stuff which includes the directory.
237: #
238: # startpage($r, $uame, $udom, $thisdisfn);
239: # $r - The apache request object.
240: # $uname - User name.
241: # $udom - Domain name the user is logged in under.
242: # $thisdisfn - Displayable version of the filename.
243:
244: sub startpage {
245: my ($r, $uname, $udom, $thisdisfn) = @_;
246: &Apache::loncommon::content_type($r,'text/html');
247: $r->send_http_header;
248:
249: my $formaction='/priv'.$thisdisfn.'/';
250: $formaction=~s|/+|/|g;
251: &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction);
252:
253: &Apache::lonhtmlcommon::clear_breadcrumbs();
254: &Apache::lonhtmlcommon::add_breadcrumb({
255: 'text' => 'Authoring Space',
256: 'href' => &Apache::loncommon::authorspace($formaction),
257: });
258: # breadcrumbs (and tools) will be created
259: # in start_page->bodytag->innerregister
260:
261: $env{'request.noversionuri'}=$formaction;
262: $r->print(&Apache::loncommon::start_page('Authoring Space'));
263:
264: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
265: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
266: my $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); #expressed in MB
267: $disk_quota = 1000 * $disk_quota; # convert from MB to kB
268:
269: $r->print(&Apache::loncommon::head_subbox(
270: '<div style="float:right;padding-top:0;margin-top;0">'
271: .&Apache::lonhtmlcommon::display_usage($current_disk_usage,$disk_quota)
272: .'</div>'
273: .&Apache::loncommon::CSTR_pageheader()));
274:
275: my $esc_thisdisfn = &Apache::loncommon::escape_single($thisdisfn);
276: my $doctitle = 'LON-CAPA '.&mt('Authoring Space');
277: my $newname = &mt('New Name');
278: my $pubdirscript=(<<ENDPUBDIRSCRIPT);
279: <script type="text/javascript">
280: top.document.title = '$esc_thisdisfn/ - $doctitle';
281: // Store directory location for menu bar to find
282:
283: parent.lastknownpriv='/priv$esc_thisdisfn/';
284:
285: // Confirmation dialogues
286:
287: function currdiract(theform) {
288: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') {
289: document.publishdir.filename.value = theform.filename.value;
290: document.publishdir.submit();
291: }
292: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editmeta') {
293: top.location=theform.filename.value+'default.meta'
294: }
295: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
296: document.printdir.postdata.value=theform.filename.value
297: document.printdir.submit();
298: }
299: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == "delete") {
300: var delform = document.delresource
301: delform.filename.value = theform.filename.value
302: delform.submit()
303: }
304: }
305:
306: function checkUpload(theform) {
307: if (theform.file == '') {
308: alert("Please use 'Browse..' to choose a file first, before uploading")
309: return
310: }
311: theform.submit()
312: }
313:
314: function SetPubDir(theform,printForm) {
315: if (theform.diraction.options[theform.diraction.selectedIndex].value == "open") {
316: top.location = theform.openname.value
317: return
318: }
319: if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") {
320: theform.submit();
321: }
322: if (theform.diraction.options[theform.diraction.selectedIndex].value == "editmeta") {
323: top.location=theform.filename.value+'default.meta'
324: }
325: if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") {
326: theform.action = '/adm/printout'
327: theform.postdata.value = theform.filename.value
328: theform.submit()
329: }
330: if (theform.diraction.options[theform.diraction.selectedIndex].value == "delete") {
331: var delform = document.delresource
332: delform.filename.value = theform.filename.value
333: delform.submit()
334: }
335: return
336: }
337: function SetResChoice(theform) {
338: var activity = theform.reschoice.options[theform.reschoice.selectedIndex].value
339: if ((activity == 'rename') || (activity == 'copy') || (activity == 'move')) {
340: changename(theform,activity)
341: }
342: if (activity == 'publish') {
343: var pubform = document.pubresource
344: pubform.filename.value = theform.filename.value
345: pubform.submit()
346: }
347: if (activity == 'delete') {
348: var delform = document.delresource
349: delform.filename.value = theform.filename.value
350: delform.submit()
351: }
352: if (activity == 'obsolete') {
353: var pubform = document.pubresource
354: pubform.filename.value = theform.filename.value
355: pubform.makeobsolete.value=1;
356: pubform.submit()
357: }
358: if (activity == 'print') {
359: document.printresource.postdata.value = theform.filename.value
360: document.printresource.submit()
361: }
362: if (activity == 'retrieve') {
363: document.retrieveres.filename.value = theform.filename.value
364: document.retrieveres.submit()
365: }
366: if (activity == 'cleanup') {
367: document.cleanup.filename.value = theform.filename.value
368: document.cleanup.submit()
369: }
370: return
371: }
372: function changename(theform,activity) {
373: var oldname=theform.dispfilename.value;
374: var newname=prompt('$newname',oldname);
375: if (newname == "" || !newname || newname == oldname) {
376: return
377: }
378: document.moveresource.newfilename.value = newname
379: document.moveresource.filename.value = theform.filename.value
380: document.moveresource.action.value = activity
381: document.moveresource.submit();
382: }
383: </script>
384: ENDPUBDIRSCRIPT
385: $r->print($pubdirscript);
386: }
387:
388: sub dircontrols {
389: my ($r,$uname,$udom,$thisdisfn) = @_;
390: my %lt=&Apache::lonlocal::texthash(
391: cnpd => 'Cannot publish directory',
392: cnrd => 'Cannot retrieve directory',
393: mcdi => 'Must create new subdirectory inside a directory',
394: pubr => 'Publish this Resource',
395: pubd => 'Publish this Directory',
396: dedr => 'Delete Directory',
397: rtrv => 'Retrieve Old Version',
398: list => 'List Directory',
399: uplo => 'Upload file',
400: dele => 'Delete',
401: edit => 'Edit Metadata',
402: sela => 'Select Action',
403: nfil => 'New file',
404: nhtm => 'New HTML file',
405: nprb => 'New problem',
406: npag => 'New assembled page',
407: nseq => 'New assembled sequence',
408: ncrf => 'New custom rights file',
409: nsty => 'New style file',
410: nlib => 'New library file',
411: nbt => 'New bridgetask file',
412: nsub => 'New subdirectory',
413: renm => 'Rename current file to',
414: move => 'Move current file to',
415: copy => 'Copy current file to',
416: type => 'Type Name Here',
417: go => 'Go',
418: prnt => 'Print contents of directory',
419: crea => 'Create a new directory or LON-CAPA document',
420: acti => 'Actions for current directory',
421: updc => 'Upload a new document',
422: pick => 'Please select an action to perform using the new filename',
423: );
424: my $mytype = $lt{'type'}; # avoid conflict with " and ' in javascript
425: $r->print(<<END);
426: <div class="LC_columnSection">
427: <div>
428: <form name="curractions" method="post" action="">
429: <fieldset>
430: <legend>$lt{'acti'}</legend>
431: <select name="dirtask" onchange="currdiract(this.form)">
432: <option>$lt{'sela'}</option>
433: <option value="publish">$lt{'pubd'}</option>
434: <option value="editmeta">$lt{'edit'}</option>
435: <option value="printdir">$lt{'prnt'}</option>
436: <option value="delete">$lt{'dedr'}</option>
437: </select>
438: <input type="hidden" name="filename" value="/priv$thisdisfn/" />
439: </fieldset>
440: </form>
441: <form name="publishdir" method="post" action="/adm/publish" target="_parent">
442: <input type="hidden" name="pubrec" value="" />
443: <input type="hidden" name="filename" value="" />
444: </form>
445: <form name="printdir" method="post" action="/adm/printout" target="_parent">
446: <input type="hidden" name="postdata" value="" />
447: </form>
448: </div>
449:
450: <div>
451: <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent">
452: <fieldset>
453: <legend>$lt{'updc'}</legend>
454: <input type="hidden" name="filename" value="/priv$thisdisfn/" />
455: <input type="file" name="upfile" size="20" />
456: <input type="button" value="$lt{'uplo'}" onclick="checkUpload(this.form)" />
457: </fieldset>
458: </form>
459: </div>
460:
461: <div>
462: <form name="fileaction" method="post" action="/adm/cfile" target="_parent">
463: <fieldset>
464: <legend>$lt{'crea'}</legend>
465: <span class="LC_nobreak">
466: <input type="hidden" name="filename" value="/priv$thisdisfn/" />
467: <script type="text/javascript">
468: function validate_go() {
469: var selected = document.fileaction.action.selectedIndex;
470: if (selected == 0) {
471: alert('$lt{'pick'}');
472: } else {
473: document.fileaction.submit();
474: }
475: }
476: </script>
477: <select name="action">
478: <option value="none">$lt{'sela'}</option>
479: <option value="newfile">$lt{'nfil'}:</option>
480: <option value="newhtmlfile">$lt{'nhtm'}:</option>
481: <option value="newproblemfile">$lt{'nprb'}:</option>
482: <option value="newpagefile">$lt{'npag'}:</option>
483: <option value="newsequencefile">$lt{'nseq'}:</option>
484: <option value="newrightsfile">$lt{'ncrf'}:</option>
485: <option value="newstyfile">$lt{'nsty'}:</option>
486: <option value="newtaskfile">$lt{'nbt'}:</option>
487: <option value="newlibraryfile">$lt{'nlib'}:</option>
488: <option value="newdir">$lt{'nsub'}:</option>
489: </select> <input type="text" name="newfilename" value="$lt{'type'}" onfocus="if (this.value == '$mytype') this.value=''" /> <input type="button" value="Go" onclick="validate_go();" />
490: </span>
491: </fieldset>
492: </form>
493: </div>
494: </div>
495: END
496: }
497:
498: sub resourceactions {
499: my ($r,$uname,$udom,$thisdisfn) = @_;
500: $r->print(<<END);
501: <form name="moveresource" action="/adm/cfile" target="_parent" method="post">
502: <input type="hidden" name="filename" value="" />
503: <input type="hidden" name="newfilename" value="" />
504: <input type="hidden" name="action" value="" />
505: </form>
506: <form name="delresource" action="/adm/cfile" target="_parent" method="post">
507: <input type="hidden" name="filename" value="" />
508: <input type="hidden" name="action" value="delete" />
509: </form>
510: <form name="pubresource" action="/adm/publish" target="_parent" method="post">
511: <input type="hidden" name="filename" value="" />
512: <input type="hidden" name="makeobsolete" value="0" />
513: </form>
514: <form name="printresource" action="/adm/printout" target="_parent" method="post">
515: <input type="hidden" name="postdata" value="" />
516: </form>
517: <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post">
518: <input type="hidden" name="filename" value="" />
519: </form>
520: <form name="cleanup" action="/adm/cleanup" target="_parent" method="post">
521: <input type="hidden" name="filename" value="" />
522: </form>
523: END
524: }
525:
526: #
527: # Get the title string or "[untitled]" if the file has no title metadata:
528: # Without the latter substitution, it's impossible to examine metadata for
529: # untitled resources. Resources may be legitimately untitled, to prevent
530: # searches from locating them.
531: #
532: # $str = getTitleString($fullname);
533: # $fullname - Fully qualified filename to check.
534: #
535: sub getTitleString {
536: my $fullname = shift;
537: my $title = &Apache::lonnet::metadata($fullname, 'title');
538:
539: unless ($title) {
540: $title = "[".&mt('untitled')."]";
541: }
542: return $title;
543: }
544:
545: sub getCopyRightString {
546: my $fullname = shift;
547: return &Apache::lonnet::metadata($fullname, 'copyright');
548: }
549:
550: sub getSourceRightString {
551: my $fullname = shift;
552: return &Apache::lonnet::metadata($fullname, 'sourceavail');
553: }
554: #
555: # Put out a directory table row:
556: # putdirectory(r, base, here, dirname, modtime, targetdir, bombs, numdir)
557: # r - Apache request object.
558: # reqfile - File in request.
559: # here - Where we are in directory tree.
560: # dirname - Name of directory special file.
561: # modtime - Encoded modification time.
562: # targetdir - Publication target directory.
563: # bombs - Reference to hash of URLs with runtime error messages.
564: # numdir - Reference to scalar used to track number of sub-directories
565: # in directory (used in form name for each "actions" dropdown).
566: #
567: sub putdirectory {
568: my ($r, $reqfile, $here, $dirname, $modtime, $targetdir, $bombs, $numdir) = @_;
569:
570: # construct the display filename: the directory name unless ..:
571:
572: my $actionitem;
573:
574: my $disfilename = $dirname;
575: # Don't display directory itself, and there is no way up from root directory
576: unless ((($dirname eq '..') && ($reqfile=~/^\/[^\/]+\/[^\/]+$/)) || ($dirname eq '.')) {
577: my $kaputt=0;
578: if (ref($bombs) eq 'HASH') {
579: foreach my $key (keys(%{$bombs})) {
580: my $currentdir = &Apache::lonnet::declutter("$targetdir/$disfilename");
581: if (($key) =~ m{^\Q$currentdir\E/}) { $kaputt=1; last; }
582: }
583: }
584: #
585: # Get the metadata from that directory's default.meta to display titles
586: #
587: %Apache::lonpublisher::metadatafields=();
588: %Apache::lonpublisher::metadatakeys=();
589: &Apache::lonpublisher::metaeval(
590: &Apache::lonnet::getfile($r->dir_config('lonDocRoot').$here.'/'.$dirname.'/default.meta')
591: );
592: if ($dirname eq '..') {
593: $actionitem = &mt('Go to ...');
594: $disfilename = '<i>'.&mt('Parent Directory').'</i>';
595: } else {
596: $actionitem =
597: '<form name="dirselect_'.$$numdir.
598: '" action="/adm/publish" target="_parent">'.
599: '<select name="diraction" onchange="SetPubDir(this.form,document)">'.
600: '<option selected="selected">'.&mt('Select action').'</option>'.
601: '<option value="open">'.&mt('Open').'</option>'.
602: '<option value="publish">'.&mt('Publish').'</option>'.
603: '<option value="editmeta">'.&mt('Edit Metadata').'</option>'.
604: '<option value="printdir">'.&mt('Print directory').'</option>'.
605: '<option value="delete">'.&mt('Delete directory').'</option>'.
606: '</select>'.
607: '<input type="hidden" name="filename" value="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" />'.
608: '<input type="hidden" name="openname" value="'.$here.'/'.$dirname.'/" />'.
609: '<input type="hidden" name="postdata" value="" />'.
610: '</form>';
611: $$numdir ++;
612: }
613: $r->print('<tr class="LC_browser_folder">'.
614: '<td><img src="'.
615: $Apache::lonnet::perlvar{'lonIconsURL'}.'/navmap.folder.closed.gif" alt="folder" /></td>'.
616: '<td>'.$actionitem.'</td>'.
617: '<td><span class="LC_filename"><a href="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" target="_parent">'.
618: $disfilename.'</a></span></td>'.
619: '<td colspan="3">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($targetdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'});
620: if ($Apache::lonpublisher::metadatafields{'subject'} ne '') {
621: $r->print(' <i>'.
622: $Apache::lonpublisher::metadatafields{'subject'}.
623: '</i> ');
624: }
625: $r->print($Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
626: '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
627: '<td></td>'.
628: "</tr>\n");
629: }
630: return OK;
631: }
632:
633: sub getTitle {
634: my ($resdir, $targetdir, $filename, $linkfilename, $meta_same, $bombs) = @_;
635: my $title='';
636: my $titleString = &getTitleString($targetdir.'/'.$filename);
637: if (-e $resdir.'/'.$filename) {
638: $title = '<a href="'.$targetdir.'/'.$filename.
639: '.meta" target="cat">'.$titleString.'</a>';
640: if (!$meta_same) {
641: $title = &mt('Metadata Modified').'<br />'.$title.
642: '<br />'.
643: &Apache::loncommon::modal_link(
644: '/adm/diff?filename='.$linkfilename.'.meta'.'&versiontwo=priv',
645: &mt('Metadata Diffs'),600,500);
646: $title.="\n".'<br />'.
647: &Apache::loncommon::modal_link(
648: '/adm/retrieve?filename='.$linkfilename.'.meta&inhibitmenu=yes&add_modal=yes',
649: &mt('Retrieve Metadata'),600,500);
650: }
651: }
652: # Allow editing metadata of published and unpublished resources
653: $title .= "\n".'<br />' if ($title);
654: $title .= '<a href="'.$linkfilename.'.meta">'.
655: ($$bombs{&Apache::lonnet::declutter($targetdir.'/'.$filename)}?
656: '<img src="/adm/lonMisc/bomb.gif" border="0" alt="'.&mt('bomb').'" />':
657: &mt('Edit Metadata')).
658: '</a>';
659:
660: return ($title, $titleString);
661: }
662:
663:
664: sub isMetaSame {
665: my ($cstr_dir, $resdir, $filename) = @_;
666: my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9];
667: my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
668: return (&Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta',
669: $cstr_dir.'/'.$filename.'.meta') && $meta_rmtime < $meta_cmtime)
670: ? 0 : 1;
671: }
672:
673:
674: sub getStatus {
675: my ($resdir, $targetdir, $cstr_dir, $filename,
676: $linkfilename, $cmtime, $meta_same) = @_;
677: my $pubstatus = 'unpublished';
678: my $status = &mt('Unpublished');
679:
680: if (-e $resdir.'/'.$filename) {
681: my $same = 0;
682: if ((stat($resdir.'/'.$filename))[9] >= $cmtime) {
683: $same = 1;
684: } else {
685: if (&Apache::londiff::are_different_files($resdir.'/'.$filename,
686: $cstr_dir.'/'.$filename)) {
687: $same = 0;
688: } else {
689: $same = 1;
690: }
691: }
692:
693: my $rights_status =
694: &mt(&getCopyRightString($targetdir.'/'.$filename)).', ';
695:
696: my %lt_SourceRight = &Apache::lonlocal::texthash(
697: 'open' => 'Source: open',
698: 'closed' => 'Source: closed',
699: );
700: $rights_status .=
701: $lt_SourceRight{&getSourceRightString($targetdir.'/'.$filename)};
702:
703: if ($same) {
704: if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
705: $pubstatus = 'obsolete';
706: $status=&mt('Obsolete');
707: } else {
708: if (!$meta_same) {
709: $pubstatus = 'metamodified';
710: } else {
711: $pubstatus = 'published';
712: }
713: $status=&mt('Published').
714: '<br />'. $rights_status;
715: }
716: } else {
717: $pubstatus = 'modified';
718: $status=&mt('Modified').
719: '<br />'. $rights_status;
720: if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
721: $status.='<br />'.
722: &Apache::loncommon::modal_link(
723: '/adm/diff?filename='.$linkfilename.'&versiontwo=priv',
724: &mt('Diffs'),600,500);
725: }
726: }
727:
728: $status.="\n".'<br />'.
729: &Apache::loncommon::modal_link(
730: '/adm/retrieve?filename='.$linkfilename.'&inhibitmenu=yes&add_modal=yes',&mt('Retrieve'),600,500);
731: }
732:
733: return ($status, $pubstatus);
734: }
735:
736:
737: #
738: # Put a table row for a file resource.
739: #
740: sub putresource {
741: my ($r, $udom, $uname, $filename, $thisdisfn, $resdir, $targetdir,
742: $linkdir, $cmtime, $size, $numres, $linkfilename, $title,
743: $status, $pubstatus) = @_;
744: &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename);
745:
746: my $editlink='';
747: my $editlink2='';
748: if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
749: $editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=edit">'.&mt('Edit').'</a>)';
750: }
751: if ($filename=~/$LONCAPA::assess_re/) {
752: $editlink=' (<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=editxml">'.&mt('EditXML').'</a>)';
753: $editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=edit">'.&mt('Edit').'</a>)';
754: }
755: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
756: $editlink.=' (<a href="/adm/cleanup?filename='.$linkfilename.'" target="_parent">'.&mt('Clean Up').')</a>';
757: }
758: if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
759: $editlink=' (<a target="_parent" href="/adm/cfile?decompress='.$linkfilename.'">'.&mt('Decompress').'</a>)';
760: }
761: my $publish_button = (-e $resdir.'/'.$filename) ? &mt('Re-publish') : &mt('Publish');
762: my $pub_select = '';
763: &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
764: $r->print(&Apache::loncommon::start_data_table_row().
765: '<td>'.($filename=~/[\#\~]$/?' ':
766: '<img src="'.&Apache::loncommon::icon($filename).'" alt="" />').'</td>'.
767: '<td>'.$pub_select.'</td>'.
768: '<td><span class="LC_filename">'.
769: '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'.
770: $filename.'</a></span>'.$editlink2.$editlink.
771: '</td>'.
772: '<td>'.$title.'</td>'.
773: '<td class="LC_browser_file_'.$pubstatus.'"> </td>'. # Display publication status
774: '<td>'.$status.'</td>'.
775: '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
776: '<td>'.sprintf("%.1f",$size).'</td>'.
777: &Apache::loncommon::end_data_table_row()
778: );
779: return OK;
780: }
781:
782: sub create_pubselect {
783: my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
784: $$pub_select = '
785: <form name="resselect_'.$$numres.'" action="">
786: <select name="reschoice" onchange="SetResChoice(this.form)">
787: <option>'.&mt('Select action').'</option>'.
788: '<option value="copy">'.&mt('Copy').'</option>';
789: if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
790: $$pub_select .=
791: '<option value="rename">'.&mt('Rename').'</option>'.
792: '<option value="move">'.&mt('Move').'</option>'.
793: '<option value="delete">'.&mt('Delete').'</option>';
794: } else {
795: $$pub_select .= '
796: <option value="obsolete">'.&mt('Mark obsolete').'</option>';
797: }
798: # check for versions
799: my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
800: if ($versions > 0) {
801: $$pub_select .='
802: <option value="retrieve">'.&mt('Retrieve old version').'</option>';
803: }
804: $$pub_select .= '
805: <option value="publish">'.$publish_button.'</option>'.
806: '<option value="cleanup">'.&mt('Clean up').'</option>'.
807: '<option value="print">'.&mt('Print').'</option>'.
808: '</select>
809: <input type="hidden" name="filename" value="/priv'.
810: &HTML::Entities::encode($thisdisfn.'/'.$filename,'<>&"').'" />
811: <input type="hidden" name="dispfilename" value="'.
812: &HTML::Entities::encode($filename).'" /></form>';
813: $$numres ++;
814: }
815:
816: sub check_for_versions {
817: my ($r,$fn,$udom,$uname) = @_;
818: my $versions = 0;
819: my $docroot=$r->dir_config('lonDocRoot');
820: my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
821: my $resdir=$resfn;
822: $resdir=~s/\/[^\/]+$/\//;
823: $fn=~/\/([^\/]+)\.(\w+)$/;
824: my $main=$1;
825: my $suffix=$2;
826: opendir(DIR,$resdir);
827: while (my $filename=readdir(DIR)) {
828: if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
829: $versions ++;
830: }
831: }
832: return $versions;
833: }
834:
835: 1;
836: __END__
837:
838:
839: =head1 NAME
840:
841: Apache::lonpubdir - Authoring space directory lister
842:
843: =head1 SYNOPSIS
844:
845: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
846:
847: <LocationMatch "^/+priv.*/$">
848: PerlAccessHandler Apache::loncacc
849: SetHandler perl-script
850: PerlHandler Apache::lonpubdir
851: ErrorDocument 403 /adm/login
852: ErrorDocument 404 /adm/notfound.html
853: ErrorDocument 406 /adm/unauthorized.html
854: ErrorDocument 500 /adm/errorhandler
855: </LocationMatch>
856:
857: <Location /adm/pubdir>
858: PerlAccessHandler Apache::lonacc
859: SetHandler perl-script
860: PerlHandler Apache::lonpubdir
861: ErrorDocument 403 /adm/login
862: ErrorDocument 404 /adm/notfound.html
863: ErrorDocument 406 /adm/unauthorized.html
864: ErrorDocument 500 /adm/errorhandler
865: </Location>
866:
867: =head1 INTRODUCTION
868:
869: This module publishes a directory of files.
870:
871: This is part of the LearningOnline Network with CAPA project
872: described at http://www.lon-capa.org.
873:
874: =head1 HANDLER SUBROUTINE
875:
876: This routine is called by Apache and mod_perl.
877:
878: =over 4
879:
880: =item *
881:
882: read in information
883:
884: =item *
885:
886: start page output
887:
888: =item *
889:
890: run through list of files and attempt to publish unhidden files
891:
892: =back
893:
894: =head1 SUBROUTINES:
895:
896: =over
897:
898: =item startpage($r, $uame, $udom, $thisdisfn)
899:
900: Output the header of the page. This includes:
901: - The HTML header
902: - The H1/H3 stuff which includes the directory.
903:
904: startpage($r, $uame, $udom, $thisdisfn);
905: $r - The apache request object.
906: $uname - User name.
907: $udom - Domain name the user is logged in under.
908: $thisdisfn - Displayable version of the filename.
909:
910: =item getTitleString($fullname)
911:
912: Get the title string or "[untitled]" if the file has no title metadata:
913: Without the latter substitution, it's impossible to examine metadata for
914: untitled resources. Resources may be legitimately untitled, to prevent
915: searches from locating them.
916:
917: $str = getTitleString($fullname);
918: $fullname - Fully qualified filename to check.
919:
920: =item putdirectory($r, $base, $here, $dirname, $modtime, $targetdir, $bombs,
921: $numdir)
922:
923: Put out a directory table row:
924:
925: $r - Apache request object.
926: $reqfile - File in request.
927: $here - Where we are in directory tree.
928: $dirname - Name of directory special file.
929: $modtime - Encoded modification time.
930: targetdir - Publication target directory.
931: bombs - Reference to hash of URLs with runtime error messages.
932: numdir - Reference to scalar used to track number of sub-directories
933: in directory (used in form name for each "actions" dropdown).
934:
935: =back
936:
937: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>