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