Annotation of loncom/publisher/lonpubdir.pm, revision 1.95
1.1 www 1: # The LearningOnline Network with CAPA
1.32 www 2: # Construction Space Directory Lister
1.16 albertel 3: #
1.95 ! albertel 4: # $Id: lonpubdir.pm,v 1.94 2006/06/26 22:47:27 albertel 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.91 www 39: use Apache::londiff();
1.39 www 40: use Apache::lonlocal;
1.50 www 41: use Apache::lonmsg;
1.64 raeburn 42: use Apache::lonmenu;
43: use Apache::lonnet;
1.1 www 44:
45: sub handler {
46:
47: my $r=shift;
48:
49: my $fn;
50:
1.23 foxr 51:
52:
53: $fn = getEffectiveUrl($r);
54:
55: # Validate access to the construction space and get username@domain.
1.6 www 56:
57: my $uname;
58: my $udom;
59:
1.9 www 60: ($uname,$udom)=
1.6 www 61: &Apache::loncacc::constructaccess(
1.9 www 62: $fn,$r->dir_config('lonDefDomain'));
63: unless (($uname) && ($udom)) {
1.6 www 64: $r->log_reason($uname.' at '.$udom.
1.78 albertel 65: ' trying to list directory '.$env{'form.filename'}.
1.6 www 66: ' ('.$fn.') - not authorized',
67: $r->filename);
68: return HTTP_NOT_ACCEPTABLE;
69: }
1.23 foxr 70:
1.32 www 71: # Remove trailing / from directory name.
1.23 foxr 72:
1.3 www 73: $fn=~s/\/$//;
1.1 www 74:
75: unless ($fn) {
1.78 albertel 76: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1.2 www 77: ' trying to list empty directory', $r->filename);
1.1 www 78: return HTTP_NOT_FOUND;
79: }
80:
81: # ----------------------------------------------------------- Start page output
82:
1.23 foxr 83: my $thisdisfn=$fn;
84: $thisdisfn=~s/^\/home\/$uname\/public_html//; # subdirectory part of
85: # construction space.
86: my $docroot=$r->dir_config('lonDocRoot'); # Apache londocument root.
1.1 www 87:
1.23 foxr 88: my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn; # Resource directory
89: my $targetdir=$udom.'/'.$uname.$thisdisfn; # Publiction target directory.
1.25 www 90: my $linkdir='/priv/'.$uname.$thisdisfn; # Full URL name of constr space.
1.1 www 91:
1.50 www 92: my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
1.1 www 93:
1.26 www 94: &startpage($r, $uname, $udom, $thisdisfn); # Put out the start of page.
1.78 albertel 95: if ($env{'environment.remote'} eq 'off') {
1.65 albertel 96: &dircontrols($r,$uname,$udom,$thisdisfn); # Put out actions for directory,
1.64 raeburn 97: # browse/upload + new file page.
1.72 raeburn 98: } else {
99: &pubbuttons($r,$uname,$thisdisfn);
1.65 albertel 100: }
1.64 raeburn 101: &resourceactions($r,$uname,$udom,$thisdisfn); #Put out form used for printing/deletion etc.
102:
103: my $numdir = 0;
104: my $numres = 0;
1.6 www 105:
1.50 www 106: # Start off the directory table.
1.64 raeburn 107: $r->print('<h3>Directory Contents:</h3>');
1.92 albertel 108: $r->print('<table id="LC_browser"><tr>'.
109: '<th>'.&mt('Type').'</th>'.
110: '<th>'.&mt('Actions').'</th>'.
111: '<th>'.&mt('Name').'</th>'.
112: '<th>'.&mt('Title').'</th>'.
113: '<th>'.&mt('Status').'</th>'.
114: '<th>'.&mt('Last Modified').
1.85 albertel 115: '</th></tr>'."\n");
1.1 www 116:
1.2 www 117: my $filename;
1.23 foxr 118: my $dirptr=16384; # Mask indicating a directory in stat.cmode.
1.1 www 119:
1.2 www 120: opendir(DIR,$fn);
1.44 albertel 121: my @files=sort {uc($a) cmp uc($b)} (readdir(DIR));
1.11 albertel 122: foreach my $filename (@files) {
1.2 www 123: my ($cdev,$cino,$cmode,$cnlink,
124: $cuid,$cgid,$crdev,$csize,
125: $catime,$cmtime,$cctime,
126: $cblksize,$cblocks)=stat($fn.'/'.$filename);
1.12 www 127:
1.10 albertel 128: my $extension='';
129: if ($filename=~/\.(\w+)$/) { $extension=$1; }
1.15 matthew 130: if ($cmode&$dirptr) {
1.64 raeburn 131: putdirectory($r, $thisdisfn, $linkdir, $filename, $cmtime,$targetdir,\%bombs,\$numdir);
1.17 harris41 132: } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') {
1.64 raeburn 133: putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir,
134: $targetdir, $linkdir, $cmtime,\%bombs,\$numres);
1.14 albertel 135: } else {
1.15 matthew 136: # "hidden" extension and not a directory, so hide it away.
1.2 www 137: }
138: }
139: closedir(DIR);
140:
1.89 albertel 141: $r->print('</table>'.&Apache::loncommon::end_page());
1.1 www 142: return OK;
143: }
1.21 foxr 144: #
1.23 foxr 145: # Gets the effective URL of the request and returns it:
146: # $effn = getEffectiveUrl($r);
147: # $r - The Apache Request object.
148: sub getEffectiveUrl {
149: my $r = shift;
150: my $fn;
151:
1.78 albertel 152: if ($env{'form.filename'}) { # If a form filename is defined.
153: $fn=$env{'form.filename'};
1.23 foxr 154: #
155: # Replace the ~username of the URL with /home/username/public_html
156: # so that we don't have to worry about ~ expansion internally.
157: #
1.32 www 158: $fn=~s/^http\:\/\/[^\/]+\///;
159: $fn=~s/^\///;
160: $fn=~s/\~(\w+)/\/home\/$1\/public_html/;
1.23 foxr 161:
162: # Remove trailing / strings (?)
163:
164: $fn=~s/\/[^\/]+$//;
1.24 albertel 165: } else {
166: # If no form is defined, use request filename.
167: $fn = $r->filename();
168: my $lonDocRoot=$r->dir_config('lonDocRoot');
169: if ( $fn =~ /$lonDocRoot/ ) {
170: #internal authentication, needs fixup.
171: $fn = $r->uri(); # non users do not get the full path request
172: # through SCRIPT_FILENAME
173: $fn=~s|^/~(\w+)|/home/$1/public_html|;
174: }
1.23 foxr 175: }
1.37 www 176: $fn=~s/\/+/\//g;
1.23 foxr 177: return $fn;
178: }
179: #
180: # Output the header of the page. This includes:
181: # - The HTML header
182: # - The H1/H3 stuff which includes the directory.
183: #
184: # startpage($r, $uame, $udom, $thisdisfn);
185: # $r - The apache request object.
186: # $uname - User name.
187: # $udom - Domain name the user is logged in under.
188: # $thisdisfn - Displayable version of the filename.
1.26 www 189:
1.23 foxr 190: sub startpage {
191: my ($r, $uname, $udom, $thisdisfn) = @_;
1.64 raeburn 192: my $currdir = '/priv/'.$uname.$thisdisfn;
1.39 www 193: &Apache::loncommon::content_type($r,'text/html');
1.23 foxr 194: $r->send_http_header;
1.64 raeburn 195:
1.68 raeburn 196: my $formaction='/priv/'.$uname.$thisdisfn.'/';
1.89 albertel 197: $formaction=~s|/+|/|g;
1.94 albertel 198: my $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.78 albertel 207: if ($env{'environment.remote'} eq 'off') {
208: $env{'request.noversionuri'}=$currdir.'/';
1.89 albertel 209: $r->print(&Apache::loncommon::start_page('Construction Space',undef,
210: {'body_title' =>
211: $pagetitle,}));
1.65 albertel 212: } else {
1.90 albertel 213: $r->print(&Apache::loncommon::start_page('Construction Space',undef));
1.65 albertel 214: $r->print($pagetitle);
215: }
1.90 albertel 216:
1.29 www 217: my $pubdirscript=(<<ENDPUBDIRSCRIPT);
1.77 albertel 218: <script type="text/javascript">
1.73 raeburn 219: top.document.title = '$thisdisfn/ - LON-CAPA Construction Space';
1.37 www 220: // Store directory location for menu bar to find
221:
1.68 raeburn 222: parent.lastknownpriv='/~$uname$thisdisfn/';
1.37 www 223:
224: // Confirmation dialogues
225:
1.64 raeburn 226: function currdiract(theform) {
227: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') {
1.79 www 228: document.publishdir.filename.value = theform.filename.value;
229: document.publishdir.submit();
1.64 raeburn 230: }
231: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editcat') {
1.66 raeburn 232: top.location=theform.filename.value+'default.meta'
1.64 raeburn 233: }
234: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
235: document.printdir.postdata.value=theform.filename.value
236: document.printdir.submit();
237: }
1.88 raeburn 238: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == "delete") {
239: var delform = document.delresource
240: delform.filename.value = theform.filename.value
241: delform.submit()
242: }
1.64 raeburn 243: }
244:
245: function checkUpload(theform) {
246: if (theform.file == '') {
247: alert("Please use 'Browse..' to choose a file first, before uploading")
248: return
249: }
250: theform.submit()
251: }
252:
253: function SetPubDir(theform,printForm) {
254: if (theform.diraction.options[theform.diraction.selectedIndex].value == "open") {
1.75 albertel 255: top.location = theform.openname.value
1.64 raeburn 256: return
257: }
258: if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") {
1.79 www 259: theform.submit();
1.64 raeburn 260: }
261: if (theform.diraction.options[theform.diraction.selectedIndex].value == "editcat") {
1.66 raeburn 262: top.location=theform.filename.value+'default.meta'
1.64 raeburn 263: }
1.68 raeburn 264: if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") {
1.64 raeburn 265: theform.action = '/adm/printout'
266: theform.postdata.value = theform.filename.value
267: theform.submit()
268: }
1.88 raeburn 269: if (theform.diraction.options[theform.diraction.selectedIndex].value == "delete") {
270: var delform = document.delresource
271: delform.filename.value = theform.filename.value
272: delform.submit()
273: }
1.64 raeburn 274: return
275: }
276: function SetResChoice(theform) {
277: var activity = theform.reschoice.options[theform.reschoice.selectedIndex].value
278: if ((activity == 'rename') || (activity == 'copy') || (activity == 'move')) {
279: changename(theform,activity)
280: }
281: if (activity == 'publish') {
282: var pubform = document.pubresource
283: pubform.filename.value = theform.filename.value
284: pubform.submit()
285: }
286: if (activity == 'delete') {
287: var delform = document.delresource
288: delform.filename.value = theform.filename.value
1.71 raeburn 289: delform.submit()
1.64 raeburn 290: }
291: if (activity == 'obsolete') {
1.68 raeburn 292: var pubform = document.pubresource
293: pubform.filename.value = theform.filename.value
1.80 www 294: pubform.makeobsolete.value=1;
1.68 raeburn 295: pubform.submit()
1.64 raeburn 296: }
297: if (activity == 'print') {
1.68 raeburn 298: document.printresource.postdata.value = theform.filename.value
1.64 raeburn 299: document.printresource.submit()
300: }
301: if (activity == 'retrieve') {
1.68 raeburn 302: document.retrieveres.filename.value = theform.filename.value
303: document.retrieveres.submit()
1.64 raeburn 304: }
1.82 www 305: if (activity == 'cleanup') {
306: document.cleanup.filename.value = theform.filename.value
307: document.cleanup.submit()
308: }
1.64 raeburn 309: return
310: }
311: function changename(theform,activity) {
312: var newname=prompt('New Name');
313: if (newname == "" || !newname) {
314: return
315: }
316: document.moveresource.newfilename.value = newname
317: document.moveresource.filename.value = theform.filename.value
318: document.moveresource.action.value = activity
319: document.moveresource.submit();
320: }
1.29 www 321: </script>
322: ENDPUBDIRSCRIPT
1.64 raeburn 323: $r->print($pubdirscript);
1.29 www 324:
1.78 albertel 325: if ((($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) &&
326: $env{'environment.remote'} ne 'off') {
1.39 www 327: $r->print('<h3>'.&mt('Co-Author').': '.$uname.' at '.$udom.
1.23 foxr 328: '</h3>');
329: }
1.64 raeburn 330: }
331:
332: sub dircontrols {
333: my ($r,$uname,$udom,$thisdisfn) = @_;
1.84 www 334: my %lt=&Apache::lonlocal::texthash(
335: cnpd => 'Cannot publish directory',
336: cnrd => 'Cannot retrieve directory',
337: mcdi => 'Must create new subdirectory inside a directory',
338: pubr => 'Publish this Resource',
339: pubd => 'Publish this Directory',
1.88 raeburn 340: dedr => 'Delete Directory',
1.84 www 341: rtrv => 'Retrieve Old Version',
342: list => 'List Directory',
343: uplo => 'Upload file',
344: dele => 'Delete',
345: edit => 'Edit Catalog Information',
346: sela => 'Select Action',
347: nfil => 'New file',
348: nhtm => 'New HTML file',
349: nprb => 'New problem',
350: npag => 'New assembled page',
351: nseq => 'New assembled sequence',
352: ncrf => 'New custom rights file',
353: nsty => 'New style file',
354: nlib => 'New library file',
355: nsub => 'New subdirectory',
356: renm => 'Rename current file to',
357: move => 'Move current file to',
358: copy => 'Copy current file to',
359: type => 'Type Name Here',
360: go => 'Go',
361: prnt => 'Print contents of directory',
362: crea => 'Create a new directory or LON-CAPA document',
363: acti => 'Actions for current directory',
364: updc => 'Upload a new document'
365: );
1.64 raeburn 366: $r->print(<<END);
1.93 albertel 367: <table id="LC_cstr_controls">
1.64 raeburn 368: <tr>
1.93 albertel 369: <th>$lt{'acti'}</th>
370: <th>$lt{'updc'}</th>
371: <th>$lt{'crea'}</th>
1.64 raeburn 372: </tr>
373: <tr>
1.93 albertel 374: <td>
1.64 raeburn 375: <form name="curractions" method="post" action="">
1.85 albertel 376: <select name="dirtask" onchange="currdiract(this.form)">
1.84 www 377: <option>$lt{'sela'}</option>
378: <option value="publish">$lt{'pubd'}</option>
379: <option value="editcat">$lt{'edit'}</option>
380: <option value="printdir">$lt{'prnt'}</option>
1.88 raeburn 381: <option value="delete">$lt{'dedr'}</option>
1.64 raeburn 382: </select>
383: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
384: </form>
385: <form name="publishdir" method="post" action="/adm/publish" target="_parent">
386: <input type="hidden" name="pubrec" value="" />
387: <input type="hidden" name="filename" value="" />
388: </form>
389: <form name="printdir" method="post" action="/adm/printout" target="_parent">
390: <input type="hidden" name="postdata" value="" />
391: </form>
392: </td>
1.93 albertel 393: <td>
1.64 raeburn 394: <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent">
395: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
396: <input type="file" name="upfile" size="20" />
1.84 www 397: <input type="button" value="$lt{'uplo'}" onclick="checkUpload(this.form)" />
1.64 raeburn 398: </form>
399: </td>
1.93 albertel 400: <td>
1.64 raeburn 401: <form name="fileaction" method="post" action="/adm/cfile" target="_parent">
1.92 albertel 402: <span style="white-space: nowrap">
1.64 raeburn 403: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
1.84 www 404: <select name="action">
405: <option value="Select Action">$lt{'sela'}</option>
406: <option value="newfile">$lt{'nfil'}:</option>
407: <option value="newhtmlfile">$lt{'nhtm'}:</option>
408: <option value="newproblemfile">$lt{'nprb'}:</option>
409: <option value="newpagefile">$lt{'npag'}:</option>
410: <option value="newsequencefile">$lt{'nseq'}:</option>
411: <option value="newrightsfile">$lt{'ncrf'}:</option>
412: <option value="newstyfile">$lt{'nsty'}:</option>
413: <option value="newlibraryfile">$lt{'nlib'}:</option>
414: <option value="newdir">$lt{'nsub'}:</option>
1.64 raeburn 415: </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()" />
1.92 albertel 416: </span>
1.64 raeburn 417: </form>
418: </td>
419: </tr>
420: </table>
421: END
422: }
423:
1.72 raeburn 424: sub pubbuttons {
425: my ($r,$uname,$thisdisfn) = @_;
426: $r->print('<form method="post" action="/adm/publish" target="_parent">'.
427: '<table><tr><td><input type="hidden" name="filename" value="/~'.
428: $uname.$thisdisfn.'/" />'.
1.79 www 429: '<input type="submit" value="'.&mt('Publish Directory').'" /></td><td>'.
1.85 albertel 430: '<input type="button" onclick="window.location='."'/~".
1.72 raeburn 431: $uname.$thisdisfn."/default.meta'".'" value="'.
432: &mt('Edit Directory Catalog Information').'" /></td></tr></table></form>');
433: }
434:
1.64 raeburn 435: sub resourceactions {
436: my ($r,$uname,$udom,$thisdisfn) = @_;
437: $r->print(<<END);
438: <form name="moveresource" action="/adm/cfile" target="_parent" method="post">
439: <input type="hidden" name="filename" value="" />
440: <input type="hidden" name="newfilename" value="" />
441: <input type="hidden" name="action" value="" />
442: </form>
443: <form name="delresource" action="/adm/cfile" target="_parent" method="post">
444: <input type="hidden" name="filename" value="" />
445: <input type="hidden" name="action" value="delete" />
446: </form>
447: <form name="pubresource" action="/adm/publish" target="_parent" method="post">
448: <input type="hidden" name="filename" value="" />
1.80 www 449: <input type="hidden" name="makeobsolete" value="0" />
1.64 raeburn 450: </form>
451: <form name="printresource" action="/adm/printout" target="_parent" method="post">
452: <input type="hidden" name="postdata" value="" />
453: </form>
454: <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post">
455: <input type="hidden" name="filename" value="" />
456: </form>
1.82 www 457: <form name="cleanup" action="/adm/cleanup" target="_parent" method="post">
458: <input type="hidden" name="filename" value="" />
459: </form>
1.64 raeburn 460: END
1.23 foxr 461: }
462:
463: #
464: # Get the title string or "[untitled]" if the file has no title metadata:
465: # Without the latter substitution, it's impossible to examine metadata for
466: # untitled resources. Resources may be legitimately untitled, to prevent
467: # searches from locating them.
468: #
469: # $str = getTitleString($fullname);
470: # $fullname - Fully qualified filename to check.
471: #
472: sub getTitleString {
473: my $fullname = shift;
474: my $title = &Apache::lonnet::metadata($fullname, 'title');
475:
476: unless ($title) {
1.40 www 477: $title = "[".&mt('untitled')."]";
1.23 foxr 478: }
479: return $title;
480: }
481:
1.55 www 482: sub getCopyRightString {
483: my $fullname = shift;
484: return &Apache::lonnet::metadata($fullname, 'copyright');
485: }
1.61 www 486:
487: sub getSourceRightString {
488: my $fullname = shift;
489: return &Apache::lonnet::metadata($fullname, 'sourceavail');
490: }
1.23 foxr 491: #
1.21 foxr 492: # Put out a directory table row:
493: # putdirectory(r, base, here, dirname, modtime)
494: # r - Apache request object.
495: # reqfile - File in request.
496: # here - Where we are in directory tree.
497: # dirname - Name of directory special file.
498: # modtime - Encoded modification time.
499: #
500: sub putdirectory {
1.64 raeburn 501: my ($r, $reqfile, $here, $dirname, $modtime, $resdir, $bombs, $numdir) = @_;
1.21 foxr 502: # construct the display filename: the directory name unless ..:
503:
504: my $disfilename = $dirname;
505: if ($dirname eq '..') {
1.39 www 506: $disfilename = '<i>'.&mt('Parent Directory').'</i>';
1.21 foxr 507: }
1.64 raeburn 508: unless ( (($dirname eq '..') && ($reqfile eq '')) || ($dirname eq '.')) {
1.50 www 509: my $kaputt=0;
510: foreach (keys %{$bombs}) {
1.56 albertel 511: if ($_=~m:^\Q$resdir\E/\Q$disfilename\E/:) { $kaputt=1; last; }
1.50 www 512: }
1.52 www 513: %Apache::lonpublisher::metadatafields=();
514: %Apache::lonpublisher::metadatakeys=();
515: my $construct=$here;
1.56 albertel 516: $construct=~s:^/priv/(\w+)$:/home/$1/public_html:;
1.67 raeburn 517: my $dirpath = $here;
518: $dirpath=~s:^/priv/:/~:;
1.52 www 519: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile(
520: $construct.'/'.$dirname.'/default.meta'
521: ));
1.64 raeburn 522: my $actionitem = '';
523: if ($dirname eq '..') {
524: $actionitem = 'Go to ...';
525: } else {
526: $actionitem =
527: '<form name="dirselect_'.$$numdir.
528: '" action="/adm/publish" target="_parent">'.
1.85 albertel 529: '<select name="diraction" onchange="SetPubDir(this.form,document)">'.
1.64 raeburn 530: '<option selected="selected">'.&mt('Select action').'</option>'.
531: '<option value="open">'.&mt('Open').'</option>'.
532: '<option value="publish">'.&mt('Publish').'</option>'.
533: '<option value="editcat">'.&mt('Edit catalog information').'</option>'.
1.77 albertel 534: '<option value="printdir">'.&mt('Print directory').'</option>'.
1.88 raeburn 535: '<option value="delete">'.&mt('Delete directory').'</option>'.
1.64 raeburn 536: '</select>'.
1.86 albertel 537: '<input type="hidden" name="filename" value="'.&HTML::Entities::encode($dirpath.'/'.$dirname,'<>&"').'/" />'.
1.75 albertel 538: '<input type="hidden" name="openname" value="'.$here.'/'.$dirname.'/" />'.
1.64 raeburn 539: '<input type="hidden" name="postdata" value="" />'.
540: '</form>';
541: $$numdir ++;
542: }
1.92 albertel 543: $r->print('<tr class="LC_browser_folder">'.
1.53 www 544: '<td><img src="'.
1.86 albertel 545: $Apache::lonnet::perlvar{'lonIconsURL'}.'/folder_closed.gif" alt="folder" /></td>'.
1.64 raeburn 546: '<td>'.$actionitem.'</td>'.
1.92 albertel 547: '<td><span class="LC_filename"><a href="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" target="_parent">'.
548: $disfilename.'</a></span></td>'.
549: '<td colspan="2">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($resdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'});
550: if ($Apache::lonpublisher::metadatafields{'subject'} ne '') {
551: $r->print(' <i>'.
552: $Apache::lonpublisher::metadatafields{'subject'}.
553: '</i> ');
554: }
555: $r->print($Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
1.42 www 556: '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
1.25 www 557: "</tr>\n");
1.64 raeburn 558: }
1.21 foxr 559: return OK;
560: }
1.22 foxr 561: #
562: # Put a table row for a file resource.
563: #
564: sub putresource {
1.64 raeburn 565: my ($r, $udom, $uname, $filename, $thisdisfn,
1.22 foxr 566: $resdir, $targetdir, $linkdir,
1.64 raeburn 567: $cmtime,$bombs,$numres) = @_;
1.81 www 568: &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename);
1.64 raeburn 569: my $pubstatus = 'unpublished';
1.47 sakharuk 570: my $status=&mt('Unpublished');
1.92 albertel 571: my $css_class='LC_browser_file';
1.22 foxr 572: my $title=' ';
1.60 albertel 573: my $publish_button=&mt('Publish');
1.95 ! albertel 574: my $cstr_dir = '/home/'.$uname.'/public_html/'.$thisdisfn.'/';
1.64 raeburn 575: # my $action_buttons=
576: # '<br /><a target="_parent" href="/adm/cfile?action=delete&filename=/~'.
577: # $uname.'/'.$thisdisfn.'/'.$filename.'">'.
578: # &mt('Delete').'</a>';
1.22 foxr 579: if (-e $resdir.'/'.$filename) {
1.91 www 580: my $same=0;
1.22 foxr 581: my ($rdev,$rino,$rmode,$rnlink,
582: $ruid,$rgid,$rrdev,$rsize,
583: $ratime,$rmtime,$rctime,
584: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
1.91 www 585: if ($rmtime>=$cmtime) {
586: $same=1;
587: } else {
588: if (&Apache::londiff::are_different_files($resdir.'/'.$filename,
1.95 ! albertel 589: $cstr_dir.'/'.$filename)) {
1.91 www 590: $same=0;
591: } else {
592: $same=1;
593: }
594: }
1.95 ! albertel 595: my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9];
! 596: my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
! 597: my $meta_same = 1;
! 598: if ($meta_rmtime < $meta_cmtime
! 599: && &Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta',
! 600: $cstr_dir.'/'.$filename.'.meta')) {
! 601: $meta_same = 0;
! 602: }
1.64 raeburn 603: $publish_button=&mt('Re-publish');
1.95 ! albertel 604: my $rights_status =
! 605: &mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
! 606: &mt(&getSourceRightString($targetdir.'/'.$filename));
! 607: $title = '<a href="/res/'.$targetdir.'/'.$filename.
! 608: '.meta" target="cat">'.
! 609: &getTitleString($targetdir.'/'.$filename).'</a>';
! 610: &Apache::lonnet::logthis("same $same meta $meta_same");
1.91 www 611: if ($same) {
1.40 www 612: if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
1.64 raeburn 613: $pubstatus = 'obsolete';
1.41 www 614: $status=&mt('Obsolete');
1.95 ! albertel 615: } else {
! 616: if (!$meta_same) {
! 617: $pubstatus = 'metamodified';
! 618: } else {
! 619: $pubstatus = 'published';
! 620: }
! 621: $status=&mt('Published').
! 622: '<br />'. $rights_status;
! 623: }
1.64 raeburn 624: # } else {
625: # $action_buttons='';
626: # }
1.22 foxr 627: } else {
1.64 raeburn 628: $pubstatus = 'modified';
1.95 ! albertel 629: $status=&mt('Modified').
! 630: '<br />'. $rights_status;
1.64 raeburn 631: # $action_buttons='';
1.22 foxr 632: if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.57 www 633: $status.='<br /><a href="/adm/diff?filename=/~'.$uname.
1.22 foxr 634: $thisdisfn.'/'.$filename.
1.77 albertel 635: '&versiontwo=priv" target="cat">'.&mt('Diffs').'</a>';
1.22 foxr 636: }
1.95 ! albertel 637: }
! 638:
1.77 albertel 639: $title.="\n".'<br /><a href="/~'.$uname.$thisdisfn.'/'.$filename.'.meta">'.
1.86 albertel 640: ($$bombs{$targetdir.'/'.$filename}?'<img src="/adm/lonMisc/bomb.gif" border="0" alt="bomb" />':'Edit Metadata').'</a>';
1.95 ! albertel 641:
! 642: if (!$meta_same) {
! 643: $title = &mt('Metadata Modified').'<br />'.$title.
! 644: '<br /><a href="/adm/diff?filename=/~'.$uname.
! 645: $thisdisfn.'/'.$filename.'.meta'.
! 646: '&versiontwo=priv" target="cat">'.&mt('Metadata Diffs').'</a>';
! 647: $title.="\n".'<br /><a href="/adm/retrieve?filename=/~'.$uname.
! 648: $thisdisfn.'/'.$filename.'.meta" target="_parent">'.&mt('Retrieve Metadata').'</a>';
! 649: }
1.77 albertel 650: $status.="\n".'<br /><a href="/adm/retrieve?filename=/~'.$uname.
1.64 raeburn 651: $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Retrieve').'</a>';
1.22 foxr 652: }
1.33 www 653: my $editlink='';
1.38 taceyjo1 654: my $editlink2='';
1.36 www 655: if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
1.64 raeburn 656: $editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('Edit').'</a>)';
1.34 www 657: }
658: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
1.64 raeburn 659: $editlink=' (<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('EditXML').'</a>)';
660: $editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceColoredit=1" target="_parent">'.&mt('Edit').'</a>)';
1.43 taceyjo1 661: }
1.82 www 662: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
1.83 www 663: $editlink.=' (<a href="/adm/cleanup?filename=/~'.$uname.
664: $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Clean Up').')</a>';
1.82 www 665: }
1.43 taceyjo1 666: if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.46 taceyjo1 667: $editlink=' (<a target="_parent" href="/adm/cfile?decompress=/~'.
668: $uname.$thisdisfn.'/'.$filename.'">'.&mt('Decompress').'</a>)';
1.33 www 669: }
1.64 raeburn 670: my $pub_select = '';
671: &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
1.92 albertel 672: $r->print('<tr class="LC_browser_file_'.$pubstatus.'">'.
1.53 www 673: '<td>'.($filename=~/[\#\~]$/?' ':
1.86 albertel 674: '<img src="'.&Apache::loncommon::icon($filename).'" alt="" />').'</td>'.
1.64 raeburn 675: '<td>'.$pub_select.'</td>'.
1.92 albertel 676: '<td><span class="LC_filename"> '.
1.64 raeburn 677: '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'.
1.92 albertel 678: $filename.'</a></span>'.$editlink2.$editlink.
1.22 foxr 679: '</td>'.
680: '<td>'.$title.'</td>'.
1.41 www 681: '<td>'.$status.'</td>'.
1.42 www 682: '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
1.25 www 683: "</tr>\n");
1.22 foxr 684: return OK;
1.23 foxr 685: }
1.64 raeburn 686:
687: sub create_pubselect {
688: my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
689: $$pub_select = '
690: <form name="resselect_'.$$numres.'" action="">
1.85 albertel 691: <select name="reschoice" onchange="SetResChoice(this.form)">
1.77 albertel 692: <option>'.&mt('Select action').'</option>'.
693: '<option value="copy">'.&mt('Copy').'</option>';
1.68 raeburn 694: if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
695: $$pub_select .=
1.77 albertel 696: '<option value="rename">'.&mt('Rename').'</option>'.
697: '<option value="move">'.&mt('Move').'</option>'.
698: '<option value="delete">'.&mt('Delete').'</option>';
1.64 raeburn 699: } else {
700: $$pub_select .= '
1.77 albertel 701: <option value="obsolete">'.&mt('Mark obsolete').'</option>';
1.64 raeburn 702: }
703: # check for versions
704: my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
705: if ($versions > 0) {
706: $$pub_select .='
1.77 albertel 707: <option value="retrieve">'.&mt('Retrieve old version').'</option>';
1.64 raeburn 708: }
709: $$pub_select .= '
1.77 albertel 710: <option value="publish">'.$publish_button.'</option>'.
1.82 www 711: '<option value="cleanup">'.&mt('Clean up').'</option>'.
1.77 albertel 712: '<option value="print">'.&mt('Print').'</option>'.
1.68 raeburn 713: '</select>
1.64 raeburn 714: <input type="hidden" name="filename" value="/~'.
1.86 albertel 715: &HTML::Entities::encode($uname.$thisdisfn.'/'.$filename,'<>&"').'" /></form>';
1.64 raeburn 716: $$numres ++;
717: }
718:
719: sub check_for_versions {
720: my ($r,$fn,$udom,$uname) = @_;
721: my $versions = 0;
722: my $docroot=$r->dir_config('lonDocRoot');
723: my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
724: my $resdir=$resfn;
725: $resdir=~s/\/[^\/]+$/\//;
726: $fn=~/\/([^\/]+)\.(\w+)$/;
727: my $main=$1;
728: my $suffix=$2;
729: opendir(DIR,$resdir);
730: while (my $filename=readdir(DIR)) {
731: if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
732: $versions ++;
733: }
734: }
735: return $versions;
736: }
737:
1.23 foxr 738: #
739: # Categorize files in the directory.
740: # For each file in a list of files in a file directory,
741: # the file categorized as one of:
742: # - directory
743: # - sequence
744: # - problem
745: # - Other resource.
746: #
747: # For each file the modification date is determined as well.
748: # Returned is a list of sublists:
749: # (directories, sequences, problems, other)
750: # each of the sublists contains entries of the following form (sorted by
751: # filename):
752: # (filename, typecode, lastmodtime)
753: #
754: # $list = CategorizeFiles($location, $files)
755: # $location - Directory in which the files live (relative to our
756: # execution.
757: # $files - list of files.
758: #
759: sub CategorizeFiles {
760: my $location = shift;
761: my $files = shift;
1.22 foxr 762: }
763:
1.4 www 764: 1;
765: __END__
1.17 harris41 766:
767: =head1 NAME
768:
1.32 www 769: Apache::lonpubdir - Construction space directory lister
1.17 harris41 770:
771: =head1 SYNOPSIS
772:
773: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
774:
1.18 harris41 775: <LocationMatch "^/\~.*/$">
776: PerlAccessHandler Apache::loncacc
777: SetHandler perl-script
778: PerlHandler Apache::lonpubdir
779: ErrorDocument 403 /adm/login
780: ErrorDocument 404 /adm/notfound.html
781: ErrorDocument 406 /adm/unauthorized.html
782: ErrorDocument 500 /adm/errorhandler
783: </LocationMatch>
784:
785: <Location /adm/pubdir>
786: PerlAccessHandler Apache::lonacc
787: SetHandler perl-script
788: PerlHandler Apache::lonpubdir
789: ErrorDocument 403 /adm/login
790: ErrorDocument 404 /adm/notfound.html
791: ErrorDocument 406 /adm/unauthorized.html
792: ErrorDocument 500 /adm/errorhandler
793: </Location>
1.17 harris41 794:
795: =head1 INTRODUCTION
796:
1.18 harris41 797: This module publishes a directory of files.
1.17 harris41 798:
799: This is part of the LearningOnline Network with CAPA project
800: described at http://www.lon-capa.org.
801:
802: =head1 HANDLER SUBROUTINE
803:
804: This routine is called by Apache and mod_perl.
805:
806: =over 4
807:
808: =item *
809:
810: read in information
811:
812: =item *
813:
814: start page output
815:
816: =item *
817:
818: run through list of files and attempt to publish unhidden files
819:
820: =back
821:
822: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>