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