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