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