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