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