1: # The LearningOnline Network with CAPA
2: # Construction Space Directory Lister
3: #
4: # $Id: lonpubdir.pm,v 1.73 2004/12/10 18:43:58 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::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>');
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:
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>
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: pubdir(document.publishdir)
228: }
229: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publishsub') {
230: document.publishdir.filename.value = theform.filename.value
231: pubrecdir(document.publishdir)
232: }
233: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editcat') {
234: top.location=theform.filename.value+'default.meta'
235: }
236: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
237: document.printdir.postdata.value=theform.filename.value
238: document.printdir.submit();
239: }
240: }
241:
242: function pubdir(theform) {
243: if (confirm('Publish complete directory?')) {
244: forcepub(theform)
245: theform.submit();
246: }
247: }
248: function pubrecdir(theform) {
249: if (confirm('Publish directory and all subdirectories?')) {
250: forcepub(theform);
251: theform.pubrec.value='1';
252: theform.submit();
253: }
254: }
255:
256: function forcepub(theform) {
257: if (confirm('Force publication of unmodified files? - OK=yes; Cancel=No.')) {
258: theform.forcerepub.value="ON";
259: }
260: }
261:
262: function checkUpload(theform) {
263: if (theform.file == '') {
264: alert("Please use 'Browse..' to choose a file first, before uploading")
265: return
266: }
267: theform.submit()
268: }
269:
270: function SetPubDir(theform,printForm) {
271: if (theform.diraction.options[theform.diraction.selectedIndex].value == "open") {
272: top.location = theform.filename.value
273: return
274: }
275: if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") {
276: pubdir(theform)
277: }
278: if (theform.diraction.options[theform.diraction.selectedIndex].value == "publishsub") {
279: pubrecdir(theform)
280: }
281: if (theform.diraction.options[theform.diraction.selectedIndex].value == "editcat") {
282: top.location=theform.filename.value+'default.meta'
283: }
284: if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") {
285: theform.action = '/adm/printout'
286: theform.postdata.value = theform.filename.value
287: theform.submit()
288: }
289: return
290: }
291: function SetResChoice(theform) {
292: var activity = theform.reschoice.options[theform.reschoice.selectedIndex].value
293: if ((activity == 'rename') || (activity == 'copy') || (activity == 'move')) {
294: changename(theform,activity)
295: }
296: if (activity == 'publish') {
297: var pubform = document.pubresource
298: pubform.filename.value = theform.filename.value
299: pubform.submit()
300: }
301: if (activity == 'delete') {
302: var delform = document.delresource
303: delform.filename.value = theform.filename.value
304: delform.submit()
305: }
306: if (activity == 'obsolete') {
307: var pubform = document.pubresource
308: pubform.filename.value = theform.filename.value
309: alert("You will be taken to the publication page.\\nCheck the 'Obsolete' checkbox at the bottom of the page, and click 'Finalize Publication'.")
310: pubform.submit()
311: }
312: if (activity == 'print') {
313: document.printresource.postdata.value = theform.filename.value
314: document.printresource.submit()
315: }
316: if (activity == 'retrieve') {
317: document.retrieveres.filename.value = theform.filename.value
318: document.retrieveres.submit()
319: }
320: return
321: }
322: function changename(theform,activity) {
323: var newname=prompt('New Name');
324: if (newname == "" || !newname) {
325: return
326: }
327: document.moveresource.newfilename.value = newname
328: document.moveresource.filename.value = theform.filename.value
329: document.moveresource.action.value = activity
330: document.moveresource.submit();
331: }
332: </script>
333: ENDPUBDIRSCRIPT
334: $r->print($pubdirscript);
335:
336: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
337: $r->print('<h3>'.&mt('Co-Author').': '.$uname.' at '.$udom.
338: '</h3>');
339: }
340: }
341:
342: sub dircontrols {
343: my ($r,$uname,$udom,$thisdisfn) = @_;
344: $r->print(<<END);
345: <table cellspacing="4" cellpadding="4" width="100%">
346: <tr>
347: <td bgcolor="#DDDDDD" align="middle"><font face="Arial, Helvetica, sans-serif" size="-1"><b>Actions for current directory</b></font></td>
348: <td bgcolor="#DDDDDD" align="middle"><font face="Arial, Helvetica, sans-serif" size="-1"><b>Upload a new document</b></font></td>
349: <td bgcolor="#DDDDDD" align="middle"><font face="Arial, Helvetica, sans-serif" size="-1"><b>Create a new directory or LON-CAPA document</b></font></td>
350: </tr>
351: <tr>
352: <td bgcolor="#ccddaa" valign="top" align="center">
353: <form name="curractions" method="post" action="">
354: <select name="dirtask" onChange="currdiract(this.form)">
355: <option>Select action</option>
356: <option value="publish">Publish directory</option>
357: <option value="publishsub">Publish with subdirectories</option>
358: <option value="editcat">Edit catalog information</option>
359: <option value="printdir">Print contents of directory</option>
360: </select>
361: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
362: </form>
363: <form name="publishdir" method="post" action="/adm/publish" target="_parent">
364: <input type="hidden" name="pubrec" value="" />
365: <input type="hidden" name="filename" value="" />
366: <input type="hidden" name="forcerepub" value="NO" />
367: </form>
368: <form name="printdir" method="post" action="/adm/printout" target="_parent">
369: <input type="hidden" name="postdata" value="" />
370: </form>
371: </td>
372: <td bgcolor="#ccddaa" valign="top" align="center">
373: <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent">
374: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
375: <input type="file" name="upfile" size="20" />
376: <input type="button" value="Upload file" onclick="checkUpload(this.form)" />
377: </form>
378: </td>
379: <td bgcolor="#ccddaa" align="center">
380: <form name="fileaction" method="post" action="/adm/cfile" target="_parent">
381: <nobr>
382: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
383: <select name="action">
384: <option>Select Action</option>
385: <option value="newfile">New file:</option>
386: <option value="newhtmlfile">New HTML file:</option>
387: <option value="newproblemfile">New problem:</option>
388: <option value="newpagefile">New assembled page:</option>
389: <option value="newsequencefile">New assembled sequence:</option>
390: <option value="newrightsfile">New custom rights file:</option>
391: <option value="newstyfile">New style file:</option>
392: <option value="newdir">New subdirectory:</option>
393: </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()" />
394: </nobr>
395: </form>
396: </td>
397: </tr>
398: </table>
399: END
400: }
401:
402: sub pubbuttons {
403: my ($r,$uname,$thisdisfn) = @_;
404: $r->print('<form method="post" action="/adm/publish" target="_parent">'.
405: '<table><tr><td><input type="hidden" name="filename" value="/~'.
406: $uname.$thisdisfn.'/" />'.
407: '<input type="button" onClick="pubdir(this.form);" value="'.
408: &mt('Publish Directory').'" />'.
409: '<input type="hidden" name="pubrec" value="" />'.
410: '<input type="hidden" name="forcerepub" value="NO" />'.
411: '<input type="button" onClick="pubrecdir(this.form);" value="'.
412: &mt('Publish Directory and Sub Directories').'" /></td><td>'.
413: '<input type="button" onClick="window.location='."'/~".
414: $uname.$thisdisfn."/default.meta'".'" value="'.
415: &mt('Edit Directory Catalog Information').'" /></td></tr></table></form>');
416: }
417:
418: sub resourceactions {
419: my ($r,$uname,$udom,$thisdisfn) = @_;
420: $r->print(<<END);
421: <form name="moveresource" action="/adm/cfile" target="_parent" method="post">
422: <input type="hidden" name="filename" value="" />
423: <input type="hidden" name="newfilename" value="" />
424: <input type="hidden" name="action" value="" />
425: </form>
426: <form name="delresource" action="/adm/cfile" target="_parent" method="post">
427: <input type="hidden" name="filename" value="" />
428: <input type="hidden" name="action" value="delete" />
429: </form>
430: <form name="pubresource" action="/adm/publish" target="_parent" method="post">
431: <input type="hidden" name="pubrec" value="" />
432: <input type="hidden" name="filename" value="" />
433: <input type="hidden" name="forcerepub" value="NO" />
434: </form>
435: <form name="printresource" action="/adm/printout" target="_parent" method="post">
436: <input type="hidden" name="postdata" value="" />
437: </form>
438: <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post">
439: <input type="hidden" name="filename" value="" />
440: </form>
441: END
442: }
443:
444: #
445: # Get the title string or "[untitled]" if the file has no title metadata:
446: # Without the latter substitution, it's impossible to examine metadata for
447: # untitled resources. Resources may be legitimately untitled, to prevent
448: # searches from locating them.
449: #
450: # $str = getTitleString($fullname);
451: # $fullname - Fully qualified filename to check.
452: #
453: sub getTitleString {
454: my $fullname = shift;
455: my $title = &Apache::lonnet::metadata($fullname, 'title');
456:
457: unless ($title) {
458: $title = "[".&mt('untitled')."]";
459: }
460: return $title;
461: }
462:
463: sub getCopyRightString {
464: my $fullname = shift;
465: return &Apache::lonnet::metadata($fullname, 'copyright');
466: }
467:
468: sub getSourceRightString {
469: my $fullname = shift;
470: return &Apache::lonnet::metadata($fullname, 'sourceavail');
471: }
472: #
473: # Put out a directory table row:
474: # putdirectory(r, base, here, dirname, modtime)
475: # r - Apache request object.
476: # reqfile - File in request.
477: # here - Where we are in directory tree.
478: # dirname - Name of directory special file.
479: # modtime - Encoded modification time.
480: #
481: sub putdirectory {
482: my ($r, $reqfile, $here, $dirname, $modtime, $resdir, $bombs, $numdir) = @_;
483: # construct the display filename: the directory name unless ..:
484:
485: my $disfilename = $dirname;
486: if ($dirname eq '..') {
487: $disfilename = '<i>'.&mt('Parent Directory').'</i>';
488: }
489: unless ( (($dirname eq '..') && ($reqfile eq '')) || ($dirname eq '.')) {
490: my $kaputt=0;
491: foreach (keys %{$bombs}) {
492: if ($_=~m:^\Q$resdir\E/\Q$disfilename\E/:) { $kaputt=1; last; }
493: }
494: %Apache::lonpublisher::metadatafields=();
495: %Apache::lonpublisher::metadatakeys=();
496: my $construct=$here;
497: $construct=~s:^/priv/(\w+)$:/home/$1/public_html:;
498: my $dirpath = $here;
499: $dirpath=~s:^/priv/:/~:;
500: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile(
501: $construct.'/'.$dirname.'/default.meta'
502: ));
503: my $actionitem = '';
504: if ($dirname eq '..') {
505: $actionitem = 'Go to ...';
506: } else {
507: $actionitem =
508: '<form name="dirselect_'.$$numdir.
509: '" action="/adm/publish" target="_parent">'.
510: '<select name="diraction" onChange="SetPubDir(this.form,document)">'.
511: '<option selected="selected">'.&mt('Select action').'</option>'.
512: '<option value="open">'.&mt('Open').'</option>'.
513: '<option value="publish">'.&mt('Publish').'</option>'.
514: '<option value="publishsub">'.&mt('Publish with subdirectories').'</option>'.
515: '<option value="editcat">'.&mt('Edit catalog information').'</option>'.
516: '<option value="printdir">'.&mt('Print directory').
517: '</select>'.
518: '<input type="hidden" name="filename" value="'.$dirpath.'/'.$dirname.'/" />'.
519: '<input type="hidden" name="pubrec" value="" />'.
520: '<input type="hidden" name="forcerepub" value="" />'.
521: '<input type="hidden" name="postdata" value="" />'.
522: '</form>';
523: $$numdir ++;
524: }
525: $r->print('<tr bgcolor="#CCCCFF">'.
526: '<td><img src="'.
527: $Apache::lonnet::perlvar{'lonIconsURL'}.'/folder_closed.gif" /></td>'.
528: '<td>'.$actionitem.'</td>'.
529: '<td><font face="arial"><a href="'.$here.'/'.$dirname.'/" target="_parent">'.
530: $disfilename.'</a></font></td>'.
531: '<td colspan="2">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($resdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'}.' <i>'.
532: $Apache::lonpublisher::metadatafields{'subject'}.'</i> '.
533: $Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
534: '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
535: "</tr>\n");
536: }
537: return OK;
538: }
539: #
540: # Put a table row for a file resource.
541: #
542: sub putresource {
543: my ($r, $udom, $uname, $filename, $thisdisfn,
544: $resdir, $targetdir, $linkdir,
545: $cmtime,$bombs,$numres) = @_;
546: my $pubstatus = 'unpublished';
547: my $status=&mt('Unpublished');
548: my $bgcolor='#FFAA99';
549: my $title=' ';
550: my $publish_button=&mt('Publish');
551: # my $action_buttons=
552: # '<br /><a target="_parent" href="/adm/cfile?action=delete&filename=/~'.
553: # $uname.'/'.$thisdisfn.'/'.$filename.'">'.
554: # &mt('Delete').'</a>';
555: if (-e $resdir.'/'.$filename) {
556: my ($rdev,$rino,$rmode,$rnlink,
557: $ruid,$rgid,$rrdev,$rsize,
558: $ratime,$rmtime,$rctime,
559: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
560: $publish_button=&mt('Re-publish');
561: if ($rmtime>=$cmtime) {
562: $pubstatus = 'published';
563: $status=&mt('Published').'<br />'.
564: &mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
565: &mt(&getSourceRightString($targetdir.'/'.$filename));
566: $bgcolor='#CCFF88';
567: if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
568: $pubstatus = 'obsolete';
569: $status=&mt('Obsolete');
570: $bgcolor='#AAAAAA';
571: }
572: # } else {
573: # $action_buttons='';
574: # }
575: $title='<a href="/res/'.$targetdir.'/'.$filename.
576: '.meta" target=cat>'.
577: &getTitleString($targetdir.'/'.$filename).'</a>';
578: } else {
579: $pubstatus = 'modified';
580: $status=&mt('Modified').'<br />'.
581: &mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
582: &mt(&getSourceRightString($targetdir.'/'.$filename));
583: $bgcolor='#FFFF77';
584: # $action_buttons='';
585: $title='<a href="/res/'.$targetdir.'/'.$filename.'.meta" target=cat>'.
586: &getTitleString($targetdir.'/'.$filename).'</a>';
587: if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
588: $status.='<br /><a href="/adm/diff?filename=/~'.$uname.
589: $thisdisfn.'/'.$filename.
590: '&versiontwo=priv" target=cat>'.&mt('Diffs').'</a>';
591: }
592: }
593: $title.='<br /><a href="/~'.$uname.$thisdisfn.'/'.$filename.'.meta">'.
594: ($$bombs{$targetdir.'/'.$filename}?'<img src="/adm/lonMisc/bomb.gif" border="0" />':'Edit Metadata').'</a>';
595: $status.='<br><a href="/adm/retrieve?filename=/~'.$uname.
596: $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Retrieve').'</a>';
597: }
598: my $editlink='';
599: my $editlink2='';
600: if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
601: $editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('Edit').'</a>)';
602: }
603: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
604: $editlink=' (<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('EditXML').'</a>)';
605: $editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceColoredit=1" target="_parent">'.&mt('Edit').'</a>)';
606: }
607: if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
608: $editlink=' (<a target="_parent" href="/adm/cfile?decompress=/~'.
609: $uname.$thisdisfn.'/'.$filename.'">'.&mt('Decompress').'</a>)';
610: }
611: my $pub_select = '';
612: &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
613: $r->print('<tr bgcolor="'.$bgcolor.'">'.
614: '<td>'.($filename=~/[\#\~]$/?' ':
615: '<img src="'.&Apache::loncommon::icon($filename).'" /></td>').
616: '<td>'.$pub_select.'</td>'.
617: '<td><font face="arial">'.
618: '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'.
619: $filename.'</a></font>'.$editlink2.$editlink.
620: '</td>'.
621: '<td>'.$title.'</td>'.
622: '<td>'.$status.'</td>'.
623: '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
624: "</tr>\n");
625: return OK;
626: }
627:
628: sub create_pubselect {
629: my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
630: $$pub_select = '
631: <form name="resselect_'.$$numres.'" action="">
632: <select name="reschoice" onChange="SetResChoice(this.form)">
633: <option>'.&mt('Select action').
634: '<option value="copy"/>'.&mt('Copy');
635: if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
636: $$pub_select .=
637: '<option value="rename"/>'.&mt('Rename').
638: '<option value="move"/>'.&mt('Move').
639: '<option value="delete"/>'.&mt('Delete');
640: } else {
641: $$pub_select .= '
642: <option value="obsolete"/>'.&mt('Mark obsolete');
643: }
644: # check for versions
645: my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
646: if ($versions > 0) {
647: $$pub_select .='
648: <option value="retrieve"/>'.&mt('Retrieve old version');
649: }
650: $$pub_select .= '
651: <option value="publish"/>'.$publish_button.
652: '<option value="print"/>'.&mt('Print').
653: '</select>
654: <input type="hidden" name="filename" value="/~'.
655: $uname.$thisdisfn.'/'.$filename.'"></form>';
656: $$numres ++;
657: }
658:
659: sub check_for_versions {
660: my ($r,$fn,$udom,$uname) = @_;
661: my $versions = 0;
662: my $docroot=$r->dir_config('lonDocRoot');
663: my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
664: my $resdir=$resfn;
665: $resdir=~s/\/[^\/]+$/\//;
666: $fn=~/\/([^\/]+)\.(\w+)$/;
667: my $main=$1;
668: my $suffix=$2;
669: opendir(DIR,$resdir);
670: while (my $filename=readdir(DIR)) {
671: if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
672: $versions ++;
673: }
674: }
675: return $versions;
676: }
677:
678: #
679: # Categorize files in the directory.
680: # For each file in a list of files in a file directory,
681: # the file categorized as one of:
682: # - directory
683: # - sequence
684: # - problem
685: # - Other resource.
686: #
687: # For each file the modification date is determined as well.
688: # Returned is a list of sublists:
689: # (directories, sequences, problems, other)
690: # each of the sublists contains entries of the following form (sorted by
691: # filename):
692: # (filename, typecode, lastmodtime)
693: #
694: # $list = CategorizeFiles($location, $files)
695: # $location - Directory in which the files live (relative to our
696: # execution.
697: # $files - list of files.
698: #
699: sub CategorizeFiles {
700: my $location = shift;
701: my $files = shift;
702: }
703:
704: 1;
705: __END__
706:
707: =head1 NAME
708:
709: Apache::lonpubdir - Construction space directory lister
710:
711: =head1 SYNOPSIS
712:
713: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
714:
715: <LocationMatch "^/\~.*/$">
716: PerlAccessHandler Apache::loncacc
717: SetHandler perl-script
718: PerlHandler Apache::lonpubdir
719: ErrorDocument 403 /adm/login
720: ErrorDocument 404 /adm/notfound.html
721: ErrorDocument 406 /adm/unauthorized.html
722: ErrorDocument 500 /adm/errorhandler
723: </LocationMatch>
724:
725: <Location /adm/pubdir>
726: PerlAccessHandler Apache::lonacc
727: SetHandler perl-script
728: PerlHandler Apache::lonpubdir
729: ErrorDocument 403 /adm/login
730: ErrorDocument 404 /adm/notfound.html
731: ErrorDocument 406 /adm/unauthorized.html
732: ErrorDocument 500 /adm/errorhandler
733: </Location>
734:
735: =head1 INTRODUCTION
736:
737: This module publishes a directory of files.
738:
739: This is part of the LearningOnline Network with CAPA project
740: described at http://www.lon-capa.org.
741:
742: =head1 HANDLER SUBROUTINE
743:
744: This routine is called by Apache and mod_perl.
745:
746: =over 4
747:
748: =item *
749:
750: read in information
751:
752: =item *
753:
754: start page output
755:
756: =item *
757:
758: run through list of files and attempt to publish unhidden files
759:
760: =back
761:
762: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>