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