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