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