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