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