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