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