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