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