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