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