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