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