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