Annotation of loncom/publisher/lonpubdir.pm, revision 1.89
1.1 www 1: # The LearningOnline Network with CAPA
1.32 www 2: # Construction Space Directory Lister
1.16 albertel 3: #
1.89 ! albertel 4: # $Id: lonpubdir.pm,v 1.88 2005/07/14 21:31:34 raeburn Exp $
1.16 albertel 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/
1.1 www 27: #
1.17 harris41 28: ###
1.1 www 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);
1.6 www 36: use Apache::loncacc;
1.17 harris41 37: use Apache::loncommon();
1.48 www 38: use Apache::lonhtmlcommon();
1.39 www 39: use Apache::lonlocal;
1.50 www 40: use Apache::lonmsg;
1.64 raeburn 41: use Apache::lonmenu;
42: use Apache::lonnet;
1.1 www 43:
44: sub handler {
45:
46: my $r=shift;
47:
48: my $fn;
49:
1.23 foxr 50:
51:
52: $fn = getEffectiveUrl($r);
53:
54: # Validate access to the construction space and get username@domain.
1.6 www 55:
56: my $uname;
57: my $udom;
58:
1.9 www 59: ($uname,$udom)=
1.6 www 60: &Apache::loncacc::constructaccess(
1.9 www 61: $fn,$r->dir_config('lonDefDomain'));
62: unless (($uname) && ($udom)) {
1.6 www 63: $r->log_reason($uname.' at '.$udom.
1.78 albertel 64: ' trying to list directory '.$env{'form.filename'}.
1.6 www 65: ' ('.$fn.') - not authorized',
66: $r->filename);
67: return HTTP_NOT_ACCEPTABLE;
68: }
1.23 foxr 69:
1.32 www 70: # Remove trailing / from directory name.
1.23 foxr 71:
1.3 www 72: $fn=~s/\/$//;
1.1 www 73:
74: unless ($fn) {
1.78 albertel 75: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1.2 www 76: ' trying to list empty directory', $r->filename);
1.1 www 77: return HTTP_NOT_FOUND;
78: }
79:
80: # ----------------------------------------------------------- Start page output
81:
1.23 foxr 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.
1.1 www 86:
1.23 foxr 87: my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn; # Resource directory
88: my $targetdir=$udom.'/'.$uname.$thisdisfn; # Publiction target directory.
1.25 www 89: my $linkdir='/priv/'.$uname.$thisdisfn; # Full URL name of constr space.
1.1 www 90:
1.50 www 91: my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
1.1 www 92:
1.26 www 93: &startpage($r, $uname, $udom, $thisdisfn); # Put out the start of page.
1.78 albertel 94: if ($env{'environment.remote'} eq 'off') {
1.65 albertel 95: &dircontrols($r,$uname,$udom,$thisdisfn); # Put out actions for directory,
1.64 raeburn 96: # browse/upload + new file page.
1.72 raeburn 97: } else {
98: &pubbuttons($r,$uname,$thisdisfn);
1.65 albertel 99: }
1.64 raeburn 100: &resourceactions($r,$uname,$udom,$thisdisfn); #Put out form used for printing/deletion etc.
101:
102: my $numdir = 0;
103: my $numres = 0;
1.6 www 104:
1.50 www 105: # Start off the directory table.
1.64 raeburn 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').
1.85 albertel 114: '</th></tr>'."\n");
1.1 www 115:
1.2 www 116: my $filename;
1.23 foxr 117: my $dirptr=16384; # Mask indicating a directory in stat.cmode.
1.1 www 118:
1.2 www 119: opendir(DIR,$fn);
1.44 albertel 120: my @files=sort {uc($a) cmp uc($b)} (readdir(DIR));
1.11 albertel 121: foreach my $filename (@files) {
1.2 www 122: my ($cdev,$cino,$cmode,$cnlink,
123: $cuid,$cgid,$crdev,$csize,
124: $catime,$cmtime,$cctime,
125: $cblksize,$cblocks)=stat($fn.'/'.$filename);
1.12 www 126:
1.10 albertel 127: my $extension='';
128: if ($filename=~/\.(\w+)$/) { $extension=$1; }
1.15 matthew 129: if ($cmode&$dirptr) {
1.64 raeburn 130: putdirectory($r, $thisdisfn, $linkdir, $filename, $cmtime,$targetdir,\%bombs,\$numdir);
1.17 harris41 131: } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') {
1.64 raeburn 132: putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir,
133: $targetdir, $linkdir, $cmtime,\%bombs,\$numres);
1.14 albertel 134: } else {
1.15 matthew 135: # "hidden" extension and not a directory, so hide it away.
1.2 www 136: }
137: }
138: closedir(DIR);
139:
1.89 ! albertel 140: $r->print('</table>'.&Apache::loncommon::end_page());
1.1 www 141: return OK;
142: }
1.21 foxr 143: #
1.23 foxr 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:
1.78 albertel 151: if ($env{'form.filename'}) { # If a form filename is defined.
152: $fn=$env{'form.filename'};
1.23 foxr 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: #
1.32 www 157: $fn=~s/^http\:\/\/[^\/]+\///;
158: $fn=~s/^\///;
159: $fn=~s/\~(\w+)/\/home\/$1\/public_html/;
1.23 foxr 160:
161: # Remove trailing / strings (?)
162:
163: $fn=~s/\/[^\/]+$//;
1.24 albertel 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: }
1.23 foxr 174: }
1.37 www 175: $fn=~s/\/+/\//g;
1.23 foxr 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.
1.26 www 188:
1.23 foxr 189: sub startpage {
190: my ($r, $uname, $udom, $thisdisfn) = @_;
1.64 raeburn 191: my $currdir = '/priv/'.$uname.$thisdisfn;
1.39 www 192: &Apache::loncommon::content_type($r,'text/html');
1.23 foxr 193: $r->send_http_header;
1.64 raeburn 194:
1.68 raeburn 195: my $formaction='/priv/'.$uname.$thisdisfn.'/';
1.89 ! albertel 196: $formaction=~s|/+|/|g;
! 197: my $pagetitle .= &Apache::loncommon::help_open_menu('','','','',3,'Authoring').
1.68 raeburn 198: '<font face="Arial, Helvetica, sans-serif" size="+1"><b>Construction Space</b>:</font> '.
1.66 raeburn 199: '<form name="dirs" method="post" action="'.$formaction.
1.68 raeburn 200: '" target="_parent"><tt><b>'.
201: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />".
1.64 raeburn 202: &Apache::lonhtmlcommon::select_recent('construct','recent',
203: 'this.form.action=this.form.recent.value;this.form.submit()').
1.66 raeburn 204: '</form>';
205: &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction);
1.78 albertel 206: if ($env{'environment.remote'} eq 'off') {
207: $env{'request.noversionuri'}=$currdir.'/';
1.89 ! albertel 208: $r->print(&Apache::loncommon::start_page('Construction Space',undef,
! 209: {'body_title' =>
! 210: $pagetitle,}));
1.65 albertel 211: } else {
1.89 ! albertel 212: $r->print(&Apache::loncommon::start_page('Construction Space',undef,
! 213: {'only_body' => 1,}));
1.65 albertel 214: $r->print($pagetitle);
215: }
1.29 www 216: my $pubdirscript=(<<ENDPUBDIRSCRIPT);
1.77 albertel 217: <script type="text/javascript">
1.73 raeburn 218: top.document.title = '$thisdisfn/ - LON-CAPA Construction Space';
1.37 www 219: // Store directory location for menu bar to find
220:
1.68 raeburn 221: parent.lastknownpriv='/~$uname$thisdisfn/';
1.37 www 222:
223: // Confirmation dialogues
224:
1.64 raeburn 225: function currdiract(theform) {
226: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') {
1.79 www 227: document.publishdir.filename.value = theform.filename.value;
228: document.publishdir.submit();
1.64 raeburn 229: }
230: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editcat') {
1.66 raeburn 231: top.location=theform.filename.value+'default.meta'
1.64 raeburn 232: }
233: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
234: document.printdir.postdata.value=theform.filename.value
235: document.printdir.submit();
236: }
1.88 raeburn 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: }
1.64 raeburn 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") {
1.75 albertel 254: top.location = theform.openname.value
1.64 raeburn 255: return
256: }
257: if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") {
1.79 www 258: theform.submit();
1.64 raeburn 259: }
260: if (theform.diraction.options[theform.diraction.selectedIndex].value == "editcat") {
1.66 raeburn 261: top.location=theform.filename.value+'default.meta'
1.64 raeburn 262: }
1.68 raeburn 263: if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") {
1.64 raeburn 264: theform.action = '/adm/printout'
265: theform.postdata.value = theform.filename.value
266: theform.submit()
267: }
1.88 raeburn 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: }
1.64 raeburn 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
1.71 raeburn 288: delform.submit()
1.64 raeburn 289: }
290: if (activity == 'obsolete') {
1.68 raeburn 291: var pubform = document.pubresource
292: pubform.filename.value = theform.filename.value
1.80 www 293: pubform.makeobsolete.value=1;
1.68 raeburn 294: pubform.submit()
1.64 raeburn 295: }
296: if (activity == 'print') {
1.68 raeburn 297: document.printresource.postdata.value = theform.filename.value
1.64 raeburn 298: document.printresource.submit()
299: }
300: if (activity == 'retrieve') {
1.68 raeburn 301: document.retrieveres.filename.value = theform.filename.value
302: document.retrieveres.submit()
1.64 raeburn 303: }
1.82 www 304: if (activity == 'cleanup') {
305: document.cleanup.filename.value = theform.filename.value
306: document.cleanup.submit()
307: }
1.64 raeburn 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: }
1.29 www 320: </script>
321: ENDPUBDIRSCRIPT
1.64 raeburn 322: $r->print($pubdirscript);
1.29 www 323:
1.78 albertel 324: if ((($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) &&
325: $env{'environment.remote'} ne 'off') {
1.39 www 326: $r->print('<h3>'.&mt('Co-Author').': '.$uname.' at '.$udom.
1.23 foxr 327: '</h3>');
328: }
1.64 raeburn 329: }
330:
331: sub dircontrols {
332: my ($r,$uname,$udom,$thisdisfn) = @_;
1.84 www 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',
1.88 raeburn 339: dedr => 'Delete Directory',
1.84 www 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: );
1.64 raeburn 365: $r->print(<<END);
366: <table cellspacing="4" cellpadding="4" width="100%">
367: <tr>
1.85 albertel 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>
1.64 raeburn 371: </tr>
372: <tr>
373: <td bgcolor="#ccddaa" valign="top" align="center">
374: <form name="curractions" method="post" action="">
1.85 albertel 375: <select name="dirtask" onchange="currdiract(this.form)">
1.84 www 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>
1.88 raeburn 380: <option value="delete">$lt{'dedr'}</option>
1.64 raeburn 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" />
1.84 www 396: <input type="button" value="$lt{'uplo'}" onclick="checkUpload(this.form)" />
1.64 raeburn 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/" />
1.84 www 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>
1.64 raeburn 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:
1.72 raeburn 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.'/" />'.
1.79 www 428: '<input type="submit" value="'.&mt('Publish Directory').'" /></td><td>'.
1.85 albertel 429: '<input type="button" onclick="window.location='."'/~".
1.72 raeburn 430: $uname.$thisdisfn."/default.meta'".'" value="'.
431: &mt('Edit Directory Catalog Information').'" /></td></tr></table></form>');
432: }
433:
1.64 raeburn 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="" />
1.80 www 448: <input type="hidden" name="makeobsolete" value="0" />
1.64 raeburn 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>
1.82 www 456: <form name="cleanup" action="/adm/cleanup" target="_parent" method="post">
457: <input type="hidden" name="filename" value="" />
458: </form>
1.64 raeburn 459: END
1.23 foxr 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) {
1.40 www 476: $title = "[".&mt('untitled')."]";
1.23 foxr 477: }
478: return $title;
479: }
480:
1.55 www 481: sub getCopyRightString {
482: my $fullname = shift;
483: return &Apache::lonnet::metadata($fullname, 'copyright');
484: }
1.61 www 485:
486: sub getSourceRightString {
487: my $fullname = shift;
488: return &Apache::lonnet::metadata($fullname, 'sourceavail');
489: }
1.23 foxr 490: #
1.21 foxr 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 {
1.64 raeburn 500: my ($r, $reqfile, $here, $dirname, $modtime, $resdir, $bombs, $numdir) = @_;
1.21 foxr 501: # construct the display filename: the directory name unless ..:
502:
503: my $disfilename = $dirname;
504: if ($dirname eq '..') {
1.39 www 505: $disfilename = '<i>'.&mt('Parent Directory').'</i>';
1.21 foxr 506: }
1.64 raeburn 507: unless ( (($dirname eq '..') && ($reqfile eq '')) || ($dirname eq '.')) {
1.50 www 508: my $kaputt=0;
509: foreach (keys %{$bombs}) {
1.56 albertel 510: if ($_=~m:^\Q$resdir\E/\Q$disfilename\E/:) { $kaputt=1; last; }
1.50 www 511: }
1.52 www 512: %Apache::lonpublisher::metadatafields=();
513: %Apache::lonpublisher::metadatakeys=();
514: my $construct=$here;
1.56 albertel 515: $construct=~s:^/priv/(\w+)$:/home/$1/public_html:;
1.67 raeburn 516: my $dirpath = $here;
517: $dirpath=~s:^/priv/:/~:;
1.52 www 518: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile(
519: $construct.'/'.$dirname.'/default.meta'
520: ));
1.64 raeburn 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">'.
1.85 albertel 528: '<select name="diraction" onchange="SetPubDir(this.form,document)">'.
1.64 raeburn 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>'.
1.77 albertel 533: '<option value="printdir">'.&mt('Print directory').'</option>'.
1.88 raeburn 534: '<option value="delete">'.&mt('Delete directory').'</option>'.
1.64 raeburn 535: '</select>'.
1.86 albertel 536: '<input type="hidden" name="filename" value="'.&HTML::Entities::encode($dirpath.'/'.$dirname,'<>&"').'/" />'.
1.75 albertel 537: '<input type="hidden" name="openname" value="'.$here.'/'.$dirname.'/" />'.
1.64 raeburn 538: '<input type="hidden" name="postdata" value="" />'.
539: '</form>';
540: $$numdir ++;
541: }
1.25 www 542: $r->print('<tr bgcolor="#CCCCFF">'.
1.53 www 543: '<td><img src="'.
1.86 albertel 544: $Apache::lonnet::perlvar{'lonIconsURL'}.'/folder_closed.gif" alt="folder" /></td>'.
1.64 raeburn 545: '<td>'.$actionitem.'</td>'.
1.86 albertel 546: '<td><font face="arial"><a href="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" target="_parent">'.
1.54 www 547: $disfilename.'</a></font></td>'.
1.58 www 548: '<td colspan="2">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($resdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'}.' <i>'.
1.53 www 549: $Apache::lonpublisher::metadatafields{'subject'}.'</i> '.
1.52 www 550: $Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
1.42 www 551: '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
1.25 www 552: "</tr>\n");
1.64 raeburn 553: }
1.21 foxr 554: return OK;
555: }
1.22 foxr 556: #
557: # Put a table row for a file resource.
558: #
559: sub putresource {
1.64 raeburn 560: my ($r, $udom, $uname, $filename, $thisdisfn,
1.22 foxr 561: $resdir, $targetdir, $linkdir,
1.64 raeburn 562: $cmtime,$bombs,$numres) = @_;
1.81 www 563: &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename);
1.64 raeburn 564: my $pubstatus = 'unpublished';
1.47 sakharuk 565: my $status=&mt('Unpublished');
1.53 www 566: my $bgcolor='#FFAA99';
1.22 foxr 567: my $title=' ';
1.60 albertel 568: my $publish_button=&mt('Publish');
1.64 raeburn 569: # my $action_buttons=
570: # '<br /><a target="_parent" href="/adm/cfile?action=delete&filename=/~'.
571: # $uname.'/'.$thisdisfn.'/'.$filename.'">'.
572: # &mt('Delete').'</a>';
1.22 foxr 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);
1.64 raeburn 578: $publish_button=&mt('Re-publish');
1.22 foxr 579: if ($rmtime>=$cmtime) {
1.64 raeburn 580: $pubstatus = 'published';
1.55 www 581: $status=&mt('Published').'<br />'.
1.61 www 582: &mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
583: &mt(&getSourceRightString($targetdir.'/'.$filename));
1.60 albertel 584: $bgcolor='#CCFF88';
1.40 www 585: if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
1.64 raeburn 586: $pubstatus = 'obsolete';
1.41 www 587: $status=&mt('Obsolete');
1.40 www 588: $bgcolor='#AAAAAA';
1.64 raeburn 589: }
590: # } else {
591: # $action_buttons='';
592: # }
1.23 foxr 593: $title='<a href="/res/'.$targetdir.'/'.$filename.
1.77 albertel 594: '.meta" target="cat">'.
1.55 www 595: &getTitleString($targetdir.'/'.$filename).'</a>';
1.22 foxr 596: } else {
1.64 raeburn 597: $pubstatus = 'modified';
1.55 www 598: $status=&mt('Modified').'<br />'.
1.61 www 599: &mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
600: &mt(&getSourceRightString($targetdir.'/'.$filename));
1.53 www 601: $bgcolor='#FFFF77';
1.64 raeburn 602: # $action_buttons='';
1.77 albertel 603: $title='<a href="/res/'.$targetdir.'/'.$filename.'.meta" target="cat">'.
1.55 www 604: &getTitleString($targetdir.'/'.$filename).'</a>';
1.22 foxr 605: if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.57 www 606: $status.='<br /><a href="/adm/diff?filename=/~'.$uname.
1.22 foxr 607: $thisdisfn.'/'.$filename.
1.77 albertel 608: '&versiontwo=priv" target="cat">'.&mt('Diffs').'</a>';
1.22 foxr 609: }
1.51 www 610: }
1.77 albertel 611: $title.="\n".'<br /><a href="/~'.$uname.$thisdisfn.'/'.$filename.'.meta">'.
1.86 albertel 612: ($$bombs{$targetdir.'/'.$filename}?'<img src="/adm/lonMisc/bomb.gif" border="0" alt="bomb" />':'Edit Metadata').'</a>';
1.77 albertel 613: $status.="\n".'<br /><a href="/adm/retrieve?filename=/~'.$uname.
1.64 raeburn 614: $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Retrieve').'</a>';
1.22 foxr 615: }
1.33 www 616: my $editlink='';
1.38 taceyjo1 617: my $editlink2='';
1.36 www 618: if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
1.64 raeburn 619: $editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('Edit').'</a>)';
1.34 www 620: }
621: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
1.64 raeburn 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>)';
1.43 taceyjo1 624: }
1.82 www 625: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
1.83 www 626: $editlink.=' (<a href="/adm/cleanup?filename=/~'.$uname.
627: $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Clean Up').')</a>';
1.82 www 628: }
1.43 taceyjo1 629: if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.46 taceyjo1 630: $editlink=' (<a target="_parent" href="/adm/cfile?decompress=/~'.
631: $uname.$thisdisfn.'/'.$filename.'">'.&mt('Decompress').'</a>)';
1.33 www 632: }
1.64 raeburn 633: my $pub_select = '';
634: &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
1.25 www 635: $r->print('<tr bgcolor="'.$bgcolor.'">'.
1.53 www 636: '<td>'.($filename=~/[\#\~]$/?' ':
1.86 albertel 637: '<img src="'.&Apache::loncommon::icon($filename).'" alt="" />').'</td>'.
1.64 raeburn 638: '<td>'.$pub_select.'</td>'.
1.57 www 639: '<td><font face="arial">'.
1.64 raeburn 640: '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'.
1.54 www 641: $filename.'</a></font>'.$editlink2.$editlink.
1.22 foxr 642: '</td>'.
643: '<td>'.$title.'</td>'.
1.41 www 644: '<td>'.$status.'</td>'.
1.42 www 645: '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
1.25 www 646: "</tr>\n");
1.22 foxr 647: return OK;
1.23 foxr 648: }
1.64 raeburn 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="">
1.85 albertel 654: <select name="reschoice" onchange="SetResChoice(this.form)">
1.77 albertel 655: <option>'.&mt('Select action').'</option>'.
656: '<option value="copy">'.&mt('Copy').'</option>';
1.68 raeburn 657: if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
658: $$pub_select .=
1.77 albertel 659: '<option value="rename">'.&mt('Rename').'</option>'.
660: '<option value="move">'.&mt('Move').'</option>'.
661: '<option value="delete">'.&mt('Delete').'</option>';
1.64 raeburn 662: } else {
663: $$pub_select .= '
1.77 albertel 664: <option value="obsolete">'.&mt('Mark obsolete').'</option>';
1.64 raeburn 665: }
666: # check for versions
667: my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
668: if ($versions > 0) {
669: $$pub_select .='
1.77 albertel 670: <option value="retrieve">'.&mt('Retrieve old version').'</option>';
1.64 raeburn 671: }
672: $$pub_select .= '
1.77 albertel 673: <option value="publish">'.$publish_button.'</option>'.
1.82 www 674: '<option value="cleanup">'.&mt('Clean up').'</option>'.
1.77 albertel 675: '<option value="print">'.&mt('Print').'</option>'.
1.68 raeburn 676: '</select>
1.64 raeburn 677: <input type="hidden" name="filename" value="/~'.
1.86 albertel 678: &HTML::Entities::encode($uname.$thisdisfn.'/'.$filename,'<>&"').'" /></form>';
1.64 raeburn 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:
1.23 foxr 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;
1.22 foxr 725: }
726:
1.4 www 727: 1;
728: __END__
1.17 harris41 729:
730: =head1 NAME
731:
1.32 www 732: Apache::lonpubdir - Construction space directory lister
1.17 harris41 733:
734: =head1 SYNOPSIS
735:
736: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
737:
1.18 harris41 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>
1.17 harris41 757:
758: =head1 INTRODUCTION
759:
1.18 harris41 760: This module publishes a directory of files.
1.17 harris41 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>