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