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