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