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