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