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