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