File:
[LON-CAPA] /
loncom /
publisher /
lonpubdir.pm
Revision
1.164:
download - view:
text,
annotated -
select for diffs
Thu Jun 18 20:19:27 2015 UTC (9 years, 3 months ago) by
musolffc
Branches:
MAIN
CVS tags:
HEAD
File size checking for uploaded files
A new javascript file, file_upload.js, handles client side file size checking.
The function, checkUploadSize(), accepts an html file input element and a maximum
file size (in bytes) as input. If the size of the file to be uploaded exceeds the
size allowed, a message is displayed the the element is cleared. Server side
checking is still used if it passes this test.
Loading file_upload.js adds event handlers to file input elements with
class="flUpload".
<input type="file" class="flUpload" />
It also looks for a hidden element with id="free_space" that contains the maximum
upload size.
<input type="hidden" id="free_space" value="$free_space" />
The free space is usually calculated by subtracting a user's disk usage from their
quota allowance. In some cases it is a fixed value.
I have implemented this for every upload instance I could find. These include:
* Message attachments
* Authoring space
* Portfolio
* Course editor
* Essay response problems
* Helpdesk request forms
* RSS feed uploads
1: # The LearningOnline Network with CAPA
2: # Authoring Space Directory Lister
3: #
4: # $Id: lonpubdir.pm,v 1.164 2015/06/18 20:19:27 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 qw(:DEFAULT :match);
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: if ($thisdisfn eq "$docroot/priv/$udom") {
64: if ((-d "/home/$uname/public_html/") && (!-e "$docroot/priv/$udom/$uname")) {
65: my ($version) = ($r->dir_config('lonVersion') =~ /^\'?(\d+\.\d+)\./);
66: &Apache::loncommon::content_type($r,'text/html');
67: $r->send_http_header;
68:
69: &Apache::lonhtmlcommon::clear_breadcrumbs();
70: my $js = '<script type="text/javascript"
71: src="/res/adm/includes/file_upload.js"></script>';
72: $r->print(&Apache::loncommon::start_page('Authoring Space', $js).
73: '<div class="LC_error">'.
74: '<br /><p>'.
75: &mt('Your Authoring Space is currently in the location used by LON-CAPA version 2.10 and older, but your domain is using a newer LON-CAPA version ([_1]).',$version).'</p>'.
76: '<p>'.
77: &mt('Please ask your Domain Coordinator to move your Authoring Space to the new location.').
78: '</p>'.
79: '</div>'.
80: &Apache::loncommon::end_page());
81: return OK;
82: }
83: }
84: $thisdisfn=~s/^\Q$docroot\E\/priv//;
85:
86: my $resdir=$docroot.'/res'.$thisdisfn; # Resource directory
87: my $targetdir='/res'.$thisdisfn; # Publication target directory.
88: my $linkdir='/priv'.$thisdisfn; # Full URL name of constr space.
89:
90: my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
91:
92: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
93: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,
94: "$londocroot/priv/$udom/$uname"); # expressed in kB
95: my $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,
96: 'author'); # expressed in MB
97:
98: # Put out the start of page.
99: &startpage($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota);
100:
101: if (!-d $fn) {
102: if (-e $fn) {
103: $r->print('<p class="LC_info">'.&mt('Requested item is a file not a directory.').'</p>');
104: } else {
105: $r->print('<p class="LC_info">'.&mt('The requested subdirectory does not exist.').'</p>');
106: }
107: $r->print(&Apache::loncommon::end_page());
108: return OK;
109: }
110: my @files;
111: if (opendir(DIR,$fn)) {
112: @files = grep(!/^\.+$/,readdir(DIR));
113: closedir(DIR);
114: } else {
115: $r->print('<p class="LC_error">'.&mt('Could not open directory.').'</p>');
116: $r->print(&Apache::loncommon::end_page());
117: return OK;
118: }
119:
120: # Put out actions for directory, browse/upload + new file page.
121: &dircontrols($r,$uname,$udom,$thisdisfn, $current_disk_usage, $disk_quota);
122: &resourceactions($r,$uname,$udom,$thisdisfn); # Put out form used for printing/deletion etc.
123:
124: my $numdir = 0;
125: my $numres = 0;
126:
127: if ((@files == 0) && ($thisdisfn =~ m{^/$match_domain/$match_username})) {
128: if ($thisdisfn =~ m{^/$match_domain/$match_username$}) {
129: $r->print('<p class="LC_info">'.&mt('This Authoring Space is currently empty.').'</p>');
130: } else {
131: $r->print('<p class="LC_info">'.&mt('This subdirectory is currently empty.').'</p>');
132: }
133: $r->print(&Apache::loncommon::end_page());
134: return OK;
135: }
136:
137: # Retrieving value for "sortby" and "sortorder" from QUERY_STRING
138: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
139: ['sortby','sortorder']);
140:
141: # Sort by name as default, not reversed
142: if (! exists($env{'form.sortby'})) { $env{'form.sortby'} = 'filename' }
143: if (! exists($env{'form.sortorder'})) { $env{'form.sortorder'} = '' }
144: my $sortby = $env{'form.sortby'};
145: my $sortorder = $env{'form.sortorder'};
146:
147: # Order in which columns are displayed from left to right
148: my @order = ('filetype','actions','filename','title',
149: 'pubstatus','cmtime','size');
150:
151: # Up and down arrows to indicate sort order
152: my @arrows = (' ▲',' ▼','');
153:
154: # Default sort order and column title
155: my %columns = (
156: filetype => {
157: order => 'ascending',
158: text => &mt('Type'),
159: },
160: actions => {
161: # Not sortable
162: text => &mt('Actions'),
163: },
164: filename => {
165: order => 'ascending',
166: text => &mt('Name'),
167: },
168: title => {
169: order => 'ascending',
170: text => &mt('Title'),
171: },
172: pubstatus => {
173: order => 'ascending',
174: text => &mt('Status'),
175: colspan => '2',
176: },
177: cmtime => {
178: order => 'descending',
179: text => &mt('Last Modified'),
180: },
181: size => {
182: order => 'ascending',
183: text => &mt('Size').' (kB)',
184: },
185: );
186:
187: # Print column headers
188: my $output = '';
189: foreach my $key (@order) {
190: my $idx;
191: # Append an up or down arrow to sorted column
192: if ($sortby eq $key) {
193: $idx = ($columns{$key}{order} eq 'ascending') ? 0:1;
194: if ($sortorder eq 'rev') { $idx ++; }
195: $idx = $idx%2;
196: } else { $idx = 2; } # No arrow if column is not sorted
197: $output .= (($columns{$key}{order}) ?
198: '<th'.($columns{$key}{colspan} ? ' colspan="'.$columns{$key}{colspan}.'"' : '')
199: .'><a href="'.$linkdir.'/?sortby='.$key.'&sortorder='
200: .((($sortby eq $key) && ($sortorder ne 'rev')) ? 'rev' : '').'">'
201: .$columns{$key}{text}.$arrows[$idx].'</a></th>' :
202: '<th>'.$columns{$key}{text}.'</th>');
203: }
204:
205: my $result = "<script type=\"text/javascript\">
206: sessionStorage.setItem('CSTRcache','".&prepareJsonData($uname,$udom,$thisdisfn)."');
207: localStorage.setItem('CSTRtrans', '".&prepareJsonTranslations()."');
208: </script>";
209: $r->print($result);
210:
211: $r->print('<div id="currentFolder">'.&Apache::loncommon::start_data_table()
212: .'<tr><th colspan="8" id="searchtitle" style="display:none"></th></tr>'
213: .&Apache::loncommon::start_data_table_header_row() . $output
214: .&Apache::loncommon::end_data_table_header_row()
215: );
216:
217: my $dirptr=16384; # Mask indicating a directory in stat.cmode.
218: my $filehash = {};
219: foreach my $filename (@files) {
220: # Skip .DS_Store, .DAV and hidden files
221: my ($extension) = ($filename=~/\.(\w+)$/);
222: next if (($filename eq '.DS_Store')
223: || ($filename eq '.DAV')
224: || (&Apache::loncommon::fileembstyle($extension) eq 'hdn')
225: || ($filename =~ /^\._/));
226:
227: my ($cmode,$csize,$cmtime)=(stat($fn.'/'.$filename))[2,7,9];
228: my $linkfilename = &HTML::Entities::encode('/priv'.$thisdisfn.'/'.$filename,'<>&"');
229: # Identify type of file according to icon used
230: my ($filetype) = (&Apache::loncommon::icon($filename) =~ m{/(\w+).gif$});
231: my $cstr_dir = $r->dir_config('lonDocRoot').'/priv'.$thisdisfn;
232: my $meta_same = &isMetaSame($cstr_dir, $resdir, $filename);
233:
234: # Store size, title, and status for files but not directories
235: my $size = (!($cmode&$dirptr)) ? $csize/1024. : 0;
236: my ($status, $pubstatus, $title, $fulltitle);
237: if (!($cmode&$dirptr)) {
238: ($status, $pubstatus) = &getStatus($resdir, $targetdir, $cstr_dir,
239: $filename, $linkfilename, $cmtime, $meta_same);
240: ($fulltitle, $title) = &getTitle($resdir, $targetdir, $filename,
241: $linkfilename, $meta_same, \%bombs);
242: } else {
243: ($status, $pubstatus) = ('','');
244: ($fulltitle, $title) = ('','');
245: }
246:
247: # This hash will allow sorting
248: $filehash->{ $filename } = {
249: "cmtime" => $cmtime,
250: "size" => $size,
251: "cmode" => $cmode,
252: "filetype" => $filetype,
253: "title" => $title,
254: "fulltitle" => $fulltitle,
255: "status" => $status,
256: "pubstatus" => $pubstatus,
257: "linkfilename" => $linkfilename,
258: }
259: }
260:
261: my @sorted_files;
262: # Sorting by something other than "Name". Name is the secondary key.
263: if ($sortby =~ m{cmtime|size}) { # Numeric fields
264: # First check if order should be reversed
265: if ($sortorder eq "rev") {
266: @sorted_files = sort {
267: $filehash->{$a}->{$sortby} <=> $filehash->{$b}->{$sortby}
268: or
269: uc($a) cmp uc($b)
270: } (keys(%{$filehash}));
271: } else {
272: @sorted_files = sort {
273: $filehash->{$b}->{$sortby} <=> $filehash->{$a}->{$sortby}
274: or
275: uc($a) cmp uc($b)
276: } (keys(%{$filehash}));
277: }
278: } elsif ($sortby =~ m{filetype|title|status}) { # String fields
279: if ($sortorder eq "rev") {
280: @sorted_files = sort {
281: $filehash->{$b}->{$sortby} cmp $filehash->{$a}->{$sortby}
282: or
283: uc($a) cmp uc($b)
284: } (keys(%{$filehash}));
285: } else {
286: @sorted_files = sort {
287: $filehash->{$a}->{$sortby} cmp $filehash->{$b}->{$sortby}
288: or
289: uc($a) cmp uc($b)
290: } (keys(%{$filehash}));
291: }
292:
293: # Sort by "Name" is the default
294: } else {
295: if ($sortorder eq "rev") {
296: @sorted_files = sort {uc($b) cmp uc($a)} (keys(%{$filehash}));
297: } else {
298: @sorted_files = sort {uc($a) cmp uc($b)} (keys(%{$filehash}));
299: }
300: }
301:
302: # Print the sorted resources
303: foreach my $filename (@sorted_files) {
304: if ($filehash->{$filename}->{"cmode"}&$dirptr) { # Directories
305: &putdirectory($r, $thisdisfn, $linkdir, $filename,
306: $filehash->{$filename}->{"cmtime"},
307: $targetdir, \%bombs, \$numdir);
308: } else { # Files
309: &putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir,
310: $targetdir, $linkdir, $filehash->{$filename}->{"cmtime"},
311: $filehash->{$filename}->{"size"}, \$numres,
312: $filehash->{$filename}->{"linkfilename"},
313: $filehash->{$filename}->{"fulltitle"},
314: $filehash->{$filename}->{"status"},
315: $filehash->{$filename}->{"pubstatus"});
316: }
317: }
318:
319: $r->print(&Apache::loncommon::end_data_table()
320: .'</div><div id="otherplaces" style="display:none">'
321: .&Apache::loncommon::start_data_table()
322: .'<tr><th colspan="7">'.&mt('Results in other directories:').'</th></tr>'
323: .'<tr class="LC_header_row" id="otherplacestable">'
324: .'<th>'.&mt('Type').'</th>'
325: .'<th>'.&mt('Directory').'</th>'
326: .'<th>'.&mt('Name').'</th>'
327: .'<th>'.&mt('Title').'</th>'
328: .'<th colspan="2">'.&mt('Status').'</th>'
329: .'<th>'.&mt('Last Modified').'</th>'
330: .'</tr>'
331: .&Apache::loncommon::end_data_table()
332: .'</div>'
333: .&Apache::loncommon::end_page()
334: );
335: return OK;
336: }
337:
338:
339:
340: # Output the header of the page. This includes:
341: # - The HTML header
342: # - The H1/H3 stuff which includes the directory.
343: #
344: # startpage($r, $uame, $udom, $thisdisfn, $current_disk_usage, $disk_quota);
345: # $r - The apache request object.
346: # $uname - User name.
347: # $udom - Domain name the user is logged in under.
348: # $thisdisfn - Displayable version of the filename.
349: # $current_disk_usage - User's current disk usage (in kB).
350: # $disk_quota - Disk quota for user's authoring space (in MB).
351:
352: sub startpage {
353: my ($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota) = @_;
354: &Apache::loncommon::content_type($r,'text/html');
355: $r->send_http_header;
356:
357: my $formaction='/priv'.$thisdisfn.'/';
358: $formaction=~s|/+|/|g;
359: &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction);
360:
361: &Apache::lonhtmlcommon::clear_breadcrumbs();
362: &Apache::lonhtmlcommon::add_breadcrumb({
363: 'text' => 'Authoring Space',
364: 'href' => &Apache::loncommon::authorspace($formaction),
365: });
366: # breadcrumbs (and tools) will be created
367: # in start_page->bodytag->innerregister
368:
369: $env{'request.noversionuri'}=$formaction;
370: my $js = '<script type="text/javascript"
371: src="/res/adm/includes/file_upload.js"></script>';
372: $r->print(&Apache::loncommon::start_page('Authoring Space', $js));
373:
374: $disk_quota = 1024 * $disk_quota; # convert from MB to kB
375:
376: $r->print(&Apache::loncommon::head_subbox(
377: '<div style="float:right;padding-top:0;margin-top;0">'
378: .&Apache::lonhtmlcommon::display_usage($current_disk_usage,$disk_quota)
379: .'</div>'
380: .&Apache::loncommon::CSTR_pageheader()));
381:
382: my $esc_thisdisfn = &Apache::loncommon::escape_single($thisdisfn);
383: my $doctitle = 'LON-CAPA '.&mt('Authoring Space');
384: my $newname = &mt('New Name');
385: my $pubdirscript=(<<ENDPUBDIRSCRIPT);
386: <script type="text/javascript">
387: top.document.title = '$esc_thisdisfn/ - $doctitle';
388: // Store directory location for menu bar to find
389:
390: parent.lastknownpriv='/priv$esc_thisdisfn/';
391:
392: // Confirmation dialogues
393:
394: function currdiract(theform) {
395: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') {
396: document.publishdir.filename.value = theform.filename.value;
397: document.publishdir.submit();
398: }
399: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editmeta') {
400: top.location=theform.filename.value+'default.meta'
401: }
402: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
403: document.printdir.postdata.value=theform.filename.value
404: document.printdir.submit();
405: }
406: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == "delete") {
407: var delform = document.delresource
408: delform.filename.value = theform.filename.value
409: delform.submit()
410: }
411: }
412:
413: function checkUpload(theform) {
414: if (theform.file == '') {
415: alert("Please use 'Browse..' to choose a file first, before uploading")
416: return
417: }
418: theform.submit()
419: }
420:
421: function SetPubDir(theform,printForm) {
422: if (theform.diraction.options[theform.diraction.selectedIndex].value == "open") {
423: top.location = theform.openname.value
424: return
425: }
426: if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") {
427: theform.submit();
428: }
429: if (theform.diraction.options[theform.diraction.selectedIndex].value == "editmeta") {
430: top.location=theform.filename.value+'default.meta'
431: }
432: if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") {
433: theform.action = '/adm/printout'
434: theform.postdata.value = theform.filename.value
435: theform.submit()
436: }
437: if (theform.diraction.options[theform.diraction.selectedIndex].value == "delete") {
438: var delform = document.delresource
439: delform.filename.value = theform.filename.value
440: delform.submit()
441: }
442: return
443: }
444: function SetResChoice(theform) {
445: var activity = theform.reschoice.options[theform.reschoice.selectedIndex].value
446: if ((activity == 'rename') || (activity == 'copy') || (activity == 'move')) {
447: changename(theform,activity)
448: }
449: if (activity == 'publish') {
450: var pubform = document.pubresource
451: pubform.filename.value = theform.filename.value
452: pubform.submit()
453: }
454: if (activity == 'delete') {
455: var delform = document.delresource
456: delform.filename.value = theform.filename.value
457: delform.submit()
458: }
459: if (activity == 'obsolete') {
460: var pubform = document.pubresource
461: pubform.filename.value = theform.filename.value
462: pubform.makeobsolete.value=1;
463: pubform.submit()
464: }
465: if (activity == 'print') {
466: document.printresource.postdata.value = theform.filename.value
467: document.printresource.submit()
468: }
469: if (activity == 'retrieve') {
470: document.retrieveres.filename.value = theform.filename.value
471: document.retrieveres.submit()
472: }
473: if (activity == 'cleanup') {
474: document.cleanup.filename.value = theform.filename.value
475: document.cleanup.submit()
476: }
477: return
478: }
479: function changename(theform,activity) {
480: var oldname=theform.dispfilename.value;
481: var newname=prompt('$newname',oldname);
482: if (newname == "" || !newname || newname == oldname) {
483: return
484: }
485: document.moveresource.newfilename.value = newname
486: document.moveresource.filename.value = theform.filename.value
487: document.moveresource.action.value = activity
488: document.moveresource.submit();
489: }
490: </script>
491: ENDPUBDIRSCRIPT
492: $r->print($pubdirscript);
493: }
494:
495: sub dircontrols {
496: my ($r,$uname,$udom,$thisdisfn, $current_disk_usage, $disk_quota) = @_;
497: my %lt=&Apache::lonlocal::texthash(
498: cnpd => 'Cannot publish directory',
499: cnrd => 'Cannot retrieve directory',
500: mcdi => 'Must create new subdirectory inside a directory',
501: pubr => 'Publish this Resource',
502: pubd => 'Publish this Directory',
503: dedr => 'Delete Directory',
504: rtrv => 'Retrieve Old Version',
505: list => 'List Directory',
506: uplo => 'Upload file',
507: dele => 'Delete',
508: edit => 'Edit Metadata',
509: sela => 'Select Action',
510: nfil => 'New file',
511: nhtm => 'New HTML file',
512: nprb => 'New problem',
513: npag => 'New assembled page',
514: nseq => 'New assembled sequence',
515: ncrf => 'New custom rights file',
516: nsty => 'New style file',
517: nlib => 'New library file',
518: nbt => 'New bridgetask file',
519: nsub => 'New subdirectory',
520: renm => 'Rename current file to',
521: move => 'Move current file to',
522: copy => 'Copy current file to',
523: type => 'Type Name Here',
524: go => 'Go',
525: prnt => 'Print contents of directory',
526: crea => 'Create a new directory or LON-CAPA document',
527: qs => 'Quick Search',
528: cs => 'Case Sensitive',
529: re => 'Regular Expression',
530: acti => 'Actions for current directory',
531: updc => 'Upload a new document',
532: pick => 'Please select an action to perform using the new filename',
533: );
534: my $mytype = $lt{'type'}; # avoid conflict with " and ' in javascript
535: # Calculate free space in bytes.
536: # $disk_quota is in MB and $current_disk_usage is in kB
537: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
538: $r->printf(<<END,&Apache::loncommon::help_open_topic('Quicksearch'));
539: <div class="LC_columnSection">
540: <div>
541: <form name="curractions" method="post" action="">
542: <fieldset>
543: <legend>$lt{'acti'}</legend>
544: <select name="dirtask" onchange="currdiract(this.form)">
545: <option>$lt{'sela'}</option>
546: <option value="publish">$lt{'pubd'}</option>
547: <option value="editmeta">$lt{'edit'}</option>
548: <option value="printdir">$lt{'prnt'}</option>
549: <option value="delete">$lt{'dedr'}</option>
550: </select>
551: <input type="hidden" name="filename" value="/priv$thisdisfn/" />
552: </fieldset>
553: </form>
554: <form name="publishdir" method="post" action="/adm/publish" target="_parent">
555: <input type="hidden" name="pubrec" value="" />
556: <input type="hidden" name="filename" value="" />
557: </form>
558: <form name="printdir" method="post" action="/adm/printout" target="_parent">
559: <input type="hidden" name="postdata" value="" />
560: </form>
561: </div>
562:
563: <div>
564: <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent">
565: <fieldset>
566: <legend>$lt{'updc'}</legend>
567: <input type="hidden" name="filename" value="/priv$thisdisfn/" />
568: <input type="file" name="upfile" class="flUpload testclass" size="20" />
569: <input type="hidden" id="free_space" value=$free_space />
570: <input type="button" value="$lt{'uplo'}" onclick="checkUpload(this.form)" />
571: </fieldset>
572: </form>
573: </div>
574:
575: <div>
576: <form name="fileaction" method="post" action="/adm/cfile" target="_parent">
577: <fieldset>
578: <legend>$lt{'crea'}</legend>
579: <span class="LC_nobreak">
580: <input type="hidden" name="filename" value="/priv$thisdisfn/" />
581: <script type="text/javascript">
582: function validate_go() {
583: var selected = document.fileaction.action.selectedIndex;
584: if (selected == 0) {
585: alert('$lt{'pick'}');
586: } else {
587: document.fileaction.submit();
588: }
589: }
590: </script>
591: <select name="action">
592: <option value="none">$lt{'sela'}</option>
593: <option value="newfile">$lt{'nfil'}:</option>
594: <option value="newhtmlfile">$lt{'nhtm'}:</option>
595: <option value="newproblemfile">$lt{'nprb'}:</option>
596: <option value="newpagefile">$lt{'npag'}:</option>
597: <option value="newsequencefile">$lt{'nseq'}:</option>
598: <option value="newrightsfile">$lt{'ncrf'}:</option>
599: <option value="newstyfile">$lt{'nsty'}:</option>
600: <option value="newtaskfile">$lt{'nbt'}:</option>
601: <option value="newlibraryfile">$lt{'nlib'}:</option>
602: <option value="newdir">$lt{'nsub'}:</option>
603: </select> <input type="text" name="newfilename" placeholder="$lt{'type'}" value="" onfocus="if (this.value == is.empty()) this.value=''" /> <input type="button" value="Go" onclick="validate_go();" />
604: <br />
605: <span>Quickactions:
606: <input type="hidden" name="mode"/>
607: <a href="javascript:void(0)" onclick="javascript:validate_action('blank')">
608: <img src="/adm/lonIcons/unknown.gif" title="Create blank problem file"></a>
609: <a href="javascript:void(0)" onclick="javascript:validate_action('problemtempl')">
610: <img src="/adm/lonIcons/problem.gif" title="Create new problem from template"></a>
611: <a href="javascript:void(0)" onclick="javascript:validate_action('blankhtml')">
612: <img src="/adm/lonIcons/html.gif" title="Create new blank HTML file"></a>
613: <a href="javascript:void(0)" onclick="javascript:validate_action('folder')">
614: <img src="/adm/lonIcons/navmap.folder.closed.gif" title="Create new subdirectory"></a>
615: </span>
616: <script type="text/javascript">
617: function validate_action(action){
618:
619: if (document.getElementsByName(\'newfilename\')[0].value != \'\'){
620: if (action == "blank") {
621: document.fileaction.action.value=\'newproblemfile\';
622: document.fileaction.mode.value=\'blank\';
623: } else if (action == "problemtempl") {
624: document.fileaction.action.value=\'newproblemfile\';
625: validate_go();
626: } else if (action == "blankhtml") {
627: document.fileaction.action.value=\'newhtmlfile\';
628: validate_go();
629: } else if (action == "folder") {
630: document.fileaction.action.value=\'newdir\';
631: document.fileaction.mode.value=\'folder\';
632: }
633: fileaction.submit();
634: } else {
635: alert(\'Please specify file name.\');
636: // TODO: ask for filename? if so, do some refactoring
637:
638: }
639: }
640: </script>
641: </span>
642: </fieldset>
643: </form>
644: </div>
645: <div>
646: <fieldset style="display:inline">
647: <legend>$lt{'qs'}</legend>
648: <script type="text/javascript" src="/adm/quicksearch/quicksearch.js"></script>
649: <input type="text" id="quickfilter" placeholder="Enter search term" onkeyup="applyFilter()"/>
650: <input type="button" value="Clear" onclick="document.getElementById(\'quickfilter\').value=\'\'; applyFilter()" />
651: %s
652: <br />
653: <label><input type="checkbox" id="casesens" onchange="applyFilter()"/>$lt{'cs'} </label>
654: <label><input type="checkbox" id="regex" onchange="applyFilter()"/>$lt{'re'} </label>
655: </fieldset>
656: </div>
657: </div>
658: END
659: }
660:
661: sub resourceactions {
662: my ($r,$uname,$udom,$thisdisfn) = @_;
663: $r->print(<<END);
664: <form name="moveresource" action="/adm/cfile" target="_parent" method="post">
665: <input type="hidden" name="filename" value="" />
666: <input type="hidden" name="newfilename" value="" />
667: <input type="hidden" name="action" value="" />
668: </form>
669: <form name="delresource" action="/adm/cfile" target="_parent" method="post">
670: <input type="hidden" name="filename" value="" />
671: <input type="hidden" name="action" value="delete" />
672: </form>
673: <form name="pubresource" action="/adm/publish" target="_parent" method="post">
674: <input type="hidden" name="filename" value="" />
675: <input type="hidden" name="makeobsolete" value="0" />
676: </form>
677: <form name="printresource" action="/adm/printout" target="_parent" method="post">
678: <input type="hidden" name="postdata" value="" />
679: </form>
680: <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post">
681: <input type="hidden" name="filename" value="" />
682: </form>
683: <form name="cleanup" action="/adm/cleanup" target="_parent" method="post">
684: <input type="hidden" name="filename" value="" />
685: </form>
686: END
687: }
688:
689: #
690: # Get the title string or "[untitled]" if the file has no title metadata:
691: # Without the latter substitution, it's impossible to examine metadata for
692: # untitled resources. Resources may be legitimately untitled, to prevent
693: # searches from locating them.
694: #
695: # $str = getTitleString($fullname);
696: # $fullname - Fully qualified filename to check.
697: #
698: sub getTitleString {
699: my $fullname = shift;
700: my $title = &Apache::lonnet::metadata($fullname, 'title');
701:
702: unless ($title) {
703: $title = "[".&mt('untitled')."]";
704: }
705: return $title;
706: }
707:
708: sub getCopyRightString {
709: my $fullname = shift;
710: return &Apache::lonnet::metadata($fullname, 'copyright');
711: }
712:
713: sub getSourceRightString {
714: my $fullname = shift;
715: return &Apache::lonnet::metadata($fullname, 'sourceavail');
716: }
717: #
718: # Put out a directory table row:
719: # putdirectory(r, base, here, dirname, modtime, targetdir, bombs, numdir)
720: # r - Apache request object.
721: # reqfile - File in request.
722: # here - Where we are in directory tree.
723: # dirname - Name of directory special file.
724: # modtime - Encoded modification time.
725: # targetdir - Publication target directory.
726: # bombs - Reference to hash of URLs with runtime error messages.
727: # numdir - Reference to scalar used to track number of sub-directories
728: # in directory (used in form name for each "actions" dropdown).
729: #
730: sub putdirectory {
731: my ($r, $reqfile, $here, $dirname, $modtime, $targetdir, $bombs, $numdir) = @_;
732:
733: # construct the display filename: the directory name unless ..:
734:
735: my $actionitem;
736:
737: my $disfilename = $dirname;
738: # Don't display directory itself, and there is no way up from root directory
739: unless ((($dirname eq '..') && ($reqfile=~/^\/[^\/]+\/[^\/]+$/)) || ($dirname eq '.')) {
740: my $kaputt=0;
741: if (ref($bombs) eq 'HASH') {
742: foreach my $key (keys(%{$bombs})) {
743: my $currentdir = &Apache::lonnet::declutter("$targetdir/$disfilename");
744: if (($key) =~ m{^\Q$currentdir\E/}) { $kaputt=1; last; }
745: }
746: }
747: #
748: # Get the metadata from that directory's default.meta to display titles
749: #
750: %Apache::lonpublisher::metadatafields=();
751: %Apache::lonpublisher::metadatakeys=();
752: &Apache::lonpublisher::metaeval(
753: &Apache::lonnet::getfile($r->dir_config('lonDocRoot').$here.'/'.$dirname.'/default.meta')
754: );
755: if ($dirname eq '..') {
756: $actionitem = &mt('Go to ...');
757: $disfilename = '<i>'.&mt('Parent Directory').'</i>';
758: } else {
759: $actionitem =
760: '<form name="dirselect_'.$$numdir.
761: '" action="/adm/publish" target="_parent">'.
762: '<select name="diraction" onchange="SetPubDir(this.form,document)">'.
763: '<option selected="selected">'.&mt('Select action').'</option>'.
764: '<option value="open">'.&mt('Open').'</option>'.
765: '<option value="publish">'.&mt('Publish').'</option>'.
766: '<option value="editmeta">'.&mt('Edit Metadata').'</option>'.
767: '<option value="printdir">'.&mt('Print directory').'</option>'.
768: '<option value="delete">'.&mt('Delete directory').'</option>'.
769: '</select>'.
770: '<input type="hidden" name="filename" value="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" />'.
771: '<input type="hidden" name="openname" value="'.$here.'/'.$dirname.'/" />'.
772: '<input type="hidden" name="postdata" value="" />'.
773: '</form>';
774: $$numdir ++;
775: }
776: $r->print('<tr class="LC_browser_folder">'.
777: '<td><img src="'.
778: $Apache::lonnet::perlvar{'lonIconsURL'}.'/navmap.folder.closed.gif" alt="folder" /></td>'.
779: '<td>'.$actionitem.'</td>'.
780: '<td><span class="LC_filename"><a href="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" target="_parent">'.
781: $disfilename.'</a></span></td>'.
782: '<td colspan="3">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($targetdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'});
783: if ($Apache::lonpublisher::metadatafields{'subject'} ne '') {
784: $r->print(' <i>'.
785: $Apache::lonpublisher::metadatafields{'subject'}.
786: '</i> ');
787: }
788: $r->print($Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
789: '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
790: '<td></td>'.
791: "</tr>\n");
792: }
793: return;
794: }
795:
796: sub getTitle {
797: my ($resdir, $targetdir, $filename, $linkfilename, $meta_same, $bombs) = @_;
798: my $title='';
799: my $titleString = &getTitleString($targetdir.'/'.$filename);
800: if (-e $resdir.'/'.$filename) {
801: $title = '<a href="'.$targetdir.'/'.$filename.
802: '.meta" target="cat">'.$titleString.'</a>';
803: if (!$meta_same) {
804: $title = &mt('Metadata Modified').'<br />'.$title.
805: '<br />'.
806: &Apache::loncommon::modal_link(
807: '/adm/diff?filename='.$linkfilename.'.meta'.'&versiontwo=priv',
808: &mt('Metadata Diffs'),600,500);
809: $title.="\n".'<br />'.
810: &Apache::loncommon::modal_link(
811: '/adm/retrieve?filename='.$linkfilename.'.meta&inhibitmenu=yes&add_modal=yes',
812: &mt('Retrieve Metadata'),600,500);
813: }
814: }
815: # Allow editing metadata of published and unpublished resources
816: $title .= "\n".'<br />' if ($title);
817: $title .= '<a href="'.$linkfilename.'.meta">'.
818: ($$bombs{&Apache::lonnet::declutter($targetdir.'/'.$filename)}?
819: '<img src="/adm/lonMisc/bomb.gif" border="0" alt="'.&mt('bomb').'" />':
820: &mt('Edit Metadata')).
821: '</a>';
822:
823: return ($title, $titleString);
824: }
825:
826:
827: sub isMetaSame {
828: my ($cstr_dir, $resdir, $filename) = @_;
829: my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9];
830: my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
831: return (&Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta',
832: $cstr_dir.'/'.$filename.'.meta') && $meta_rmtime < $meta_cmtime)
833: ? 0 : 1;
834: }
835:
836:
837: sub getStatus {
838: my ($resdir, $targetdir, $cstr_dir, $filename,
839: $linkfilename, $cmtime, $meta_same) = @_;
840: my $pubstatus = 'unpublished';
841: my $status = &mt('Unpublished');
842:
843: if (-e $resdir.'/'.$filename) {
844: my $same = 0;
845: if ((stat($resdir.'/'.$filename))[9] >= $cmtime) {
846: $same = 1;
847: } else {
848: if (&Apache::londiff::are_different_files($resdir.'/'.$filename,
849: $cstr_dir.'/'.$filename)) {
850: $same = 0;
851: } else {
852: $same = 1;
853: }
854: }
855:
856: my $rights_status =
857: &mt(&getCopyRightString($targetdir.'/'.$filename)).', ';
858:
859: my %lt_SourceRight = &Apache::lonlocal::texthash(
860: 'open' => 'Source: open',
861: 'closed' => 'Source: closed',
862: );
863: $rights_status .=
864: $lt_SourceRight{&getSourceRightString($targetdir.'/'.$filename)};
865:
866: if ($same) {
867: if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
868: $pubstatus = 'obsolete';
869: $status=&mt('Obsolete');
870: } else {
871: if (!$meta_same) {
872: $pubstatus = 'metamodified';
873: } else {
874: $pubstatus = 'published';
875: }
876: $status=&mt('Published').
877: '<br />'. $rights_status;
878: }
879: } else {
880: $pubstatus = 'modified';
881: $status=&mt('Modified').
882: '<br />'. $rights_status;
883: if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
884: $status.='<br />'.
885: &Apache::loncommon::modal_link(
886: '/adm/diff?filename='.$linkfilename.'&versiontwo=priv',
887: &mt('Diffs'),600,500);
888: }
889: }
890:
891: $status.="\n".'<br />'.
892: &Apache::loncommon::modal_link(
893: '/adm/retrieve?filename='.$linkfilename.'&inhibitmenu=yes&add_modal=yes',&mt('Retrieve'),600,500);
894: }
895:
896: return ($status, $pubstatus);
897: }
898:
899:
900: #
901: # Put a table row for a file resource.
902: #
903: sub putresource {
904: my ($r, $udom, $uname, $filename, $thisdisfn, $resdir, $targetdir,
905: $linkdir, $cmtime, $size, $numres, $linkfilename, $title,
906: $status, $pubstatus) = @_;
907: &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename);
908:
909: my $editlink='';
910: my $editlink2='';
911: if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
912: $editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=edit">'.&mt('Edit').'</a>)';
913: }
914: if ($filename=~/$LONCAPA::assess_re/) {
915: $editlink=' (<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=editxml">'.&mt('EditXML').'</a>)';
916: $editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=edit">'.&mt('Edit').'</a>)';
917: }
918: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
919: $editlink.=' (<a href="/adm/cleanup?filename='.$linkfilename.'" target="_parent">'.&mt('Clean Up').')</a>';
920: }
921: if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
922: $editlink=' (<a target="_parent" href="/adm/cfile?decompress='.$linkfilename.'">'.&mt('Decompress').'</a>)';
923: }
924: my $publish_button = (-e $resdir.'/'.$filename) ? &mt('Re-publish') : &mt('Publish');
925: my $pub_select = '';
926: &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
927: $r->print(&Apache::loncommon::start_data_table_row().
928: '<td>'.($filename=~/[\#\~]$/?' ':
929: '<img src="'.&Apache::loncommon::icon($filename).'" alt="" />').'</td>'.
930: '<td>'.$pub_select.'</td>'.
931: '<td><span class="LC_filename">'.
932: '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'.
933: $filename.'</a></span>'.$editlink2.$editlink.
934: '</td>'.
935: '<td>'.$title.'</td>'.
936: '<td class="LC_browser_file_'.$pubstatus.'"> </td>'. # Display publication status
937: '<td>'.$status.'</td>'.
938: '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
939: '<td>'.sprintf("%.1f",$size).'</td>'.
940: &Apache::loncommon::end_data_table_row()
941: );
942: return;
943: }
944:
945: sub create_pubselect {
946: my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
947: $$pub_select = '
948: <form name="resselect_'.$$numres.'" action="">
949: <select name="reschoice" onchange="SetResChoice(this.form)">
950: <option>'.&mt('Select action').'</option>'.
951: '<option value="copy">'.&mt('Copy').'</option>';
952: if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
953: $$pub_select .=
954: '<option value="rename">'.&mt('Rename').'</option>'.
955: '<option value="move">'.&mt('Move').'</option>'.
956: '<option value="delete">'.&mt('Delete').'</option>';
957: } else {
958: $$pub_select .= '
959: <option value="obsolete">'.&mt('Mark obsolete').'</option>';
960: }
961: # check for versions
962: my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
963: if ($versions > 0) {
964: $$pub_select .='
965: <option value="retrieve">'.&mt('Retrieve old version').'</option>';
966: }
967: $$pub_select .= '
968: <option value="publish">'.$publish_button.'</option>'.
969: '<option value="cleanup">'.&mt('Clean up').'</option>'.
970: '<option value="print">'.&mt('Print').'</option>'.
971: '</select>
972: <input type="hidden" name="filename" value="/priv'.
973: &HTML::Entities::encode($thisdisfn.'/'.$filename,'<>&"').'" />
974: <input type="hidden" name="dispfilename" value="'.
975: &HTML::Entities::encode($filename).'" /></form>';
976: $$numres ++;
977: }
978:
979: sub check_for_versions {
980: my ($r,$fn,$udom,$uname) = @_;
981: my $versions = 0;
982: my $docroot=$r->dir_config('lonDocRoot');
983: my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
984: my $resdir=$resfn;
985: $resdir=~s/\/[^\/]+$/\//;
986: $fn=~/\/([^\/]+)\.(\w+)$/;
987: my $main=$1;
988: my $suffix=$2;
989: opendir(DIR,$resdir);
990: while (my $filename=readdir(DIR)) {
991: if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
992: $versions ++;
993: }
994: }
995: closedir(DIR);
996: return $versions;
997: }
998:
999: sub prepareJsonTranslations {
1000: my $json =
1001: '{"translations":{'.
1002: '"edit":"'.&mt('Edit').'",'.
1003: '"editxml":"'.&mt('EditXML').'",'.
1004: '"editmeta":"'.&mt('Edit Metadata').'",'.
1005: '"obsolete":"'.&mt('Obsolete').'",'.
1006: '"modified":"'.&mt('Modified').'",'.
1007: '"published":"'.&mt('Published').'",'.
1008: '"unpublished":"'.&mt('Unpublished').'",'.
1009: '"diff":"'.&mt('Diff').'",'.
1010: '"retrieve":"'.&mt('Retrieve').'",'.
1011: '"directory":"'.&mt('Directory').'",'.
1012: '"results":"'.&mt('Show results for keyword:').'"'.
1013: '}}';
1014: }
1015:
1016: # gathers all files in the working directory except the ones that are already on screen
1017: sub prepareJsonData {
1018: my ($uname, $udom, $pathToSkip) = @_;
1019: my $path = "/home/httpd/html/priv/$udom/$uname/";
1020:
1021: # maximum number of entries, to limit workload and required storage space
1022: my $entries = 100;
1023: my $firstfile = 1;
1024: my $firstdir = 1;
1025:
1026: my $json = '{"resources":[';
1027: $json .= &prepareJsonData_rec($path, \$entries, \$firstfile, \$firstdir, $pathToSkip);
1028: $json .= ']}';
1029:
1030: # if the json string is invalid the whole search breaks.
1031: # so we want to make sure that the string is valid in any case.
1032: $json =~ s/,\s*,/,/g;
1033: $json =~ s/\}\s*\{/\},\{/g;
1034: $json =~ s/\}\s*,\s*\]/\}\]/g;
1035: return $json;
1036: }
1037:
1038: # recursive part of json file gathering
1039: sub prepareJsonData_rec {
1040: my ($path, $entries, $firstfile, $firstdir, $pathToSkip) = @_;
1041: my $json;
1042: my $skipThisFolder = $path =~ m/$pathToSkip\/$/?1:0;
1043:
1044: my @dirs;
1045: my @resources;
1046: my @ignored = qw(bak log meta save . ..);
1047:
1048: # Phase 1: Gathering
1049: opendir(DIR,$path);
1050: my @files=sort {uc($a) cmp uc($b)} (readdir(DIR));
1051: foreach my $filename (@files) {
1052: next if ($filename eq '.DS_Store');
1053:
1054: # gather all resources
1055: if ($filename !~ /\./) {
1056: # its a folder
1057: push(@dirs, $filename);
1058: } else {
1059: # only push files we dont want to ignore
1060: next if ($skipThisFolder);
1061:
1062: $filename =~ /\.(\w+?)$/;
1063: unless (grep /$1/, @ignored) {
1064: push(@resources, $filename);
1065: }
1066: }
1067: }
1068: closedir(DIR);
1069: # nothing to do here if both lists are empty
1070: return unless ( @dirs || @resources );
1071:
1072: # Phase 2: Working
1073: $$firstfile = 1;
1074:
1075: foreach (@dirs) {
1076: $json .= '{"name":"'.$_.'",'.
1077: '"path":"'.$path.$_.'",'.
1078: '"title":"",'.
1079: '"status":"",'.
1080: '"cmtime":""},';
1081: }
1082:
1083: foreach (@resources) {
1084: last if ($$entries < 1);
1085: my $title = &getTitleString($path.$_);
1086:
1087: my $privpath = $path.$_;
1088: my $respath = $privpath;
1089: $respath =~ s/httpd\/html\/priv\//httpd\/html\/res\//;
1090:
1091: my $cmtime = (stat($privpath))[9];
1092: my $rmtime = (stat($respath))[9];
1093:
1094: unless ($$firstfile) { $json .= ','; } else { $$firstfile = 0; }
1095:
1096: my $status = 'unpublished';
1097:
1098: # if a resource is published, the published version (/html/res/filepath) gets its own modification time
1099: # this is newer or equal then the version in your authoring space (/html/priv/filepath)
1100: if ($rmtime >= $cmtime) {
1101: # obsolete
1102: if (&Apache::lonnet::metadata($respath, 'obsolete')) {
1103: $status = 'obsolete';
1104: }else{
1105: $status = 'published';
1106: }
1107: } else {
1108: $status = 'modified';
1109: }
1110:
1111: $json .= '{"name":"'.$_.'",'.
1112: '"path":"'.$path.'",'.
1113: '"title":"'.$title.'",'.
1114: '"status":"'.$status.'",'.
1115: '"cmtime":"'.&Apache::lonlocal::locallocaltime($cmtime).'"}';
1116: $$entries--;
1117: }
1118:
1119: foreach(@dirs) {
1120: next if ($$entries < 1);
1121: $json .= ',';
1122: $json .= &prepareJsonData_rec
1123: ($path.$_.'/', $entries, $firstfile, $firstdir, $pathToSkip);
1124: }
1125: return $json;
1126: }
1127: 1;
1128: __END__
1129:
1130:
1131: =head1 NAME
1132:
1133: Apache::lonpubdir - Authoring space directory lister
1134:
1135: =head1 SYNOPSIS
1136:
1137: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
1138:
1139: <LocationMatch "^/+priv.*/$">
1140: PerlAccessHandler Apache::loncacc
1141: SetHandler perl-script
1142: PerlHandler Apache::lonpubdir
1143: ErrorDocument 403 /adm/login
1144: ErrorDocument 404 /adm/notfound.html
1145: ErrorDocument 406 /adm/unauthorized.html
1146: ErrorDocument 500 /adm/errorhandler
1147: </LocationMatch>
1148:
1149: <Location /adm/pubdir>
1150: PerlAccessHandler Apache::lonacc
1151: SetHandler perl-script
1152: PerlHandler Apache::lonpubdir
1153: ErrorDocument 403 /adm/login
1154: ErrorDocument 404 /adm/notfound.html
1155: ErrorDocument 406 /adm/unauthorized.html
1156: ErrorDocument 500 /adm/errorhandler
1157: </Location>
1158:
1159: =head1 INTRODUCTION
1160:
1161: This module publishes a directory of files.
1162:
1163: This is part of the LearningOnline Network with CAPA project
1164: described at http://www.lon-capa.org.
1165:
1166: =head1 HANDLER SUBROUTINE
1167:
1168: This routine is called by Apache and mod_perl.
1169:
1170: =over 4
1171:
1172: =item *
1173:
1174: read in information
1175:
1176: =item *
1177:
1178: start page output
1179:
1180: =item *
1181:
1182: run through list of files and attempt to publish unhidden files
1183:
1184: =back
1185:
1186: =head1 SUBROUTINES:
1187:
1188: =over
1189:
1190: =item startpage($r, $uame, $udom, $thisdisfn)
1191:
1192: Output the header of the page. This includes:
1193: - The HTML header
1194: - The H1/H3 stuff which includes the directory.
1195:
1196: startpage($r, $uame, $udom, $thisdisfn);
1197: $r - The apache request object.
1198: $uname - User name.
1199: $udom - Domain name the user is logged in under.
1200: $thisdisfn - Displayable version of the filename.
1201:
1202: =item getTitleString($fullname)
1203:
1204: Get the title string or "[untitled]" if the file has no title metadata:
1205: Without the latter substitution, it's impossible to examine metadata for
1206: untitled resources. Resources may be legitimately untitled, to prevent
1207: searches from locating them.
1208:
1209: $str = getTitleString($fullname);
1210: $fullname - Fully qualified filename to check.
1211:
1212: =item putdirectory($r, $base, $here, $dirname, $modtime, $targetdir, $bombs,
1213: $numdir)
1214:
1215: Put out a directory table row:
1216:
1217: $r - Apache request object.
1218: $reqfile - File in request.
1219: $here - Where we are in directory tree.
1220: $dirname - Name of directory special file.
1221: $modtime - Encoded modification time.
1222: targetdir - Publication target directory.
1223: bombs - Reference to hash of URLs with runtime error messages.
1224: numdir - Reference to scalar used to track number of sub-directories
1225: in directory (used in form name for each "actions" dropdown).
1226:
1227: =back
1228:
1229: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>