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