1: # The LearningOnline Network with CAPA
2: # Directory Indexer
3: #
4: # $Id: lonindexer.pm,v 1.51 2002/08/20 13:01:53 www 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: # YEAR=1999
29: # 5/21/99, 5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
30: # 11/23 Gerd Kortemeyer
31: # YEAR=2000
32: # 07/20-08/04 H.K. Ng
33: # YEAR=2001
34: # 05/9-05/19/2001 H. K. Ng
35: # 05/21/2001 H. K. Ng
36: # 05/23/2001 H. K. Ng
37: # 5/31,6/1,6/2,6/15 Scott Harrison
38: # 6/26,7/8 H. K. Ng
39: # 8/6,8/7,8/10 Scott Harrison
40: # 8/14 H. K. Ng
41: # 8/28,10/15,11/28,11/29 Scott Harrison
42: # 11/30 Matthew Hall
43: # 12/11,12/13 Scott Harrison
44: # YEAR=2002
45: # 1/17 Scott Harrison
46: # 6/29/2002 H. K. Ng
47: #
48: ###
49:
50: ###############################################################################
51: ## ##
52: ## ORGANIZATION OF THIS PERL MODULE ##
53: ## ##
54: ## 1. Description of functions ##
55: ## 2. Modules used by this module ##
56: ## 3. Choices for different output views (detailed, summary, xml, etc) ##
57: ## 4. BEGIN block (to be run once after compilation) ##
58: ## 5. Handling routine called via Apache and mod_perl ##
59: ## 6. Other subroutines ##
60: ## ##
61: ###############################################################################
62:
63: package Apache::lonindexer;
64:
65: # ------------------------------------------------- modules used by this module
66: use strict;
67: use Apache::lonnet();
68: use Apache::loncommon();
69: use Apache::Constants qw(:common);
70: use Apache::File;
71: use GDBM_File;
72:
73: # ---------------------------------------- variables used throughout the module
74: my %hash; # tied to a user-specific gdbm file
75: my %dirs; # keys are directories, values are the open/close status
76: my %language; # has the reference information present in language.tab
77:
78: # ----- Values which are set by the handler subroutine and are accessible to
79: # ----- other methods.
80: my $extrafield; # default extra table cell
81: my $fnum; # file counter
82: my $dnum; # directory counter
83:
84: # ----- Used to include or exclude files with certain extensions.
85: my @Only = ();
86: my @Omit = ();
87:
88:
89: # ----------------------------- Handling routine called via Apache and mod_perl
90: sub handler {
91: my $r = shift;
92: $r->content_type('text/html');
93: &Apache::loncommon::no_cache($r);
94: $r->send_http_header;
95: return OK if $r->header_only;
96: $fnum=0;
97: $dnum=0;
98: untie %hash;
99:
100: # Deal with stupid global variables (is there a way around making
101: # these global to this package? It is just so wrong....)
102: undef (@Only);
103: undef (@Omit);
104:
105: # ------------------------------------- read in machine configuration variables
106: my $iconpath= $r->dir_config('lonIconsURL') . "/";
107: my $domain = $r->dir_config('lonDefDomain');
108: my $role = $r->dir_config('lonRole');
109: my $loadlim = $r->dir_config('lonLoadLim');
110: my $servadm = $r->dir_config('lonAdmEMail');
111: my $sysadm = $r->dir_config('lonSysEMail');
112: my $lonhost = $r->dir_config('lonHostID');
113: my $tabdir = $r->dir_config('lonTabDir');
114:
115: my $fileclr='#ffffe6';
116: my $line;
117: my (@attrchk,@openpath);
118: my $uri=$r->uri;
119:
120: # -------------------------------------- see if called from an interactive mode
121: # Get the parameters from the query string
122: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
123: ['catalogmode','launch','acts','mode','form','element',
124: 'only','omit']);
125: #-------------------------------------------------------------------
126: my $closebutton='';
127: my $groupimportbutton='';
128: my $colspan='';
129:
130: $extrafield='';
131: my $diropendb =
132: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
133:
134: if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
135: if ($ENV{'form.launch'} eq '1') {
136: &start_fresh_session();
137: }
138: # -------------------- refresh environment with user database values (in %hash)
139: &setvalues(\%hash,'form.catalogmode',\%ENV,'form.catalogmode' );
140:
141: # --------------------- define extra fields and buttons in case of special mode
142: if ($ENV{'form.catalogmode'} eq 'interactive') {
143: $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
144: '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
145: ' border="0" /></td>';
146: $colspan=" colspan='2' ";
147: $closebutton=<<END;
148: <input type="button" name="close" value='CLOSE' onClick="self.close()">
149: END
150: }
151: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
152: $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
153: '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
154: ' border="0" /></td>';
155: $colspan=" colspan='2' ";
156: $closebutton=<<END;
157: <input type="button" name="close" value='CLOSE' onClick="self.close()">
158: END
159: $groupimportbutton=<<END;
160: <input type="button" name="groupimport" value='GROUP IMPORT'
161: onClick="javascript:select_group()">
162: END
163: }
164: # Additions made by Matthew to make the browser a little easier to deal
165: # with in the future.
166: #
167: # $mode (at this time) indicates if we are in edit mode.
168: # $form is the name of the form that the URL is placed when the
169: # selection is made.
170: # $element is the name of the element in $formname which receives
171: # the URL.
172: # &Apache::lonxml::debug('Checking mode, form, element');
173: &setvalues(\%hash,'form.mode' ,\%ENV,'form.mode' );
174: &setvalues(\%hash,'form.form' ,\%ENV,'form.form' );
175: &setvalues(\%hash,'form.element',\%ENV,'form.element');
176: &setvalues(\%hash,'form.only' ,\%ENV,'form.only' );
177: &setvalues(\%hash,'form.omit' ,\%ENV,'form.omit' );
178:
179: # Deal with 'omit' and 'only'
180: if (exists $ENV{'form.omit'}) {
181: @Omit = split(',',$ENV{'form.omit'});
182: }
183: if (exists $ENV{'form.only'}) {
184: @Only = split(',',$ENV{'form.only'});
185: }
186:
187: my $mode = $ENV{'form.mode'};
188: my ($form,$element);
189: if ($mode eq 'edit' || $mode eq 'parmset') {
190: $form = $ENV{'form.form'};
191: $element = $ENV{'form.element'};
192: }
193: &Apache::lonxml::debug("mode=$mode form=$form element=$element");
194: # ------ set catalogmodefunctions to have extra needed javascript functionality
195: my $catalogmodefunctions='';
196: if ($ENV{'form.catalogmode'} eq 'interactive' or
197: $ENV{'form.catalogmode'} eq 'groupimport') {
198: # The if statement below sets us up to use the old version
199: # by default (ie. if $mode is undefined). This is the easy
200: # way out. Hopefully in the future I'll find a way to get
201: # the calls dealt with in a more comprehensive manner.
202:
203: #
204: # There is now also mode "simple", which is for the simple version of the rat
205: #
206: #
207: if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
208: my $location = "/adm/groupsort?catalogmode=groupimport&";
209: $location .= "mode=".$mode."&";
210: $location .= "acts=";
211: $catalogmodefunctions=<<"END";
212: function select_data(title,url) {
213: changeTitle(title);
214: changeURL(url);
215: self.close();
216: }
217: function select_group() {
218: window.location="$location"+document.forms.fileattr.acts.value;
219: }
220: function changeTitle(val) {
221: if (opener.inf) {
222: if (opener.inf.document.forms.resinfo.elements.t) {
223: opener.inf.document.forms.resinfo.elements.t.value=val;
224: }
225: }
226: }
227: function changeURL(val) {
228: if (opener.inf) {
229: if (opener.inf.document.forms.resinfo.elements.u) {
230: opener.inf.document.forms.resinfo.elements.u.value=val;
231: }
232: }
233: }
234: END
235: } elsif ($mode eq 'edit') { # we are in 'edit' mode
236: my $location = "/adm/groupsort?catalogmode=interactive&";
237: $location .= "form=$form&element=$element&mode=edit&acts=";
238: $catalogmodefunctions=<<END;
239: // mode = $mode
240: function select_data(title,url) {
241: changeURL(url);
242: self.close();
243: }
244:
245: function select_group() {
246: window.location="$location"+document.forms.fileattr.acts.value;
247: }
248:
249: function changeURL(val) {
250: if (window.opener.document) {
251: window.opener.document.forms["$form"].elements["$element"].value=val;
252: } else {
253: alert("The file you selected is: "+val);
254: }
255: }
256:
257: END
258: } elsif ($mode eq 'parmset') {
259: my $location = "/adm/groupsort?catalogmode=interactive&";
260: $location .= "form=$form&element=$element&mode=parmset&acts=";
261: $catalogmodefunctions=<<END;
262: // mode = $mode
263: function select_data(title,url) {
264: changeURL(url);
265: self.close();
266: }
267:
268: function select_group() {
269: window.location="$location"+document.forms.fileattr.acts.value;
270: }
271:
272: function changeURL(val) {
273: if (window.opener.document) {
274: var elementname = "$element"+"_value";
275: var checkboxname = "$element"+"_setparmval";
276: window.opener.document.forms["$form"].elements[elementname].value=val;
277: window.opener.document.forms["$form"].elements[checkboxname].checked=true;
278: } else {
279: alert("The file you selected is: "+val);
280: }
281: }
282:
283: END
284: }
285: }
286: $catalogmodefunctions.=<<END;
287: var acts='';
288: function rep_dirpath(suffix,val) {
289: eval("document.forms.dirpath"+suffix+".acts.value=val");
290: }
291: END
292: if ($ENV{'form.catalogmode'} eq 'groupimport') {
293: $catalogmodefunctions.=<<END;
294: function queue(val) {
295: if (eval("document.forms."+val+".filelink.checked")) {
296: var l=val.length;
297: var v=val.substring(4,l);
298: document.forms.fileattr.acts.value+='1a'+v+'b';
299: }
300: else {
301: var l=val.length;
302: var v=val.substring(4,l);
303: document.forms.fileattr.acts.value+='0a'+v+'b';
304: }
305: }
306: END
307: }
308:
309: # ---------------------------------------------------------------- Print Header
310: $r->print(<<ENDHEADER);
311: <html>
312: <head>
313: <title>The LearningOnline Network With CAPA Directory Browser</title>
314:
315: <script type="text/javascript">
316: $catalogmodefunctions
317: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
318: var options = "width=" + w + ",height=" + h + ",";
319: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
320: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
321: var newWin = window.open(url, wdwName, options);
322: newWin.focus();
323: }
324: function gothere(val) {
325: window.location=val+'?acts='+document.forms.fileattr.acts.value;
326: }
327: </script>
328:
329: </head>
330: <body bgcolor="#FFFFFF">
331: ENDHEADER
332:
333: # - Evaluate actions from previous page (both cumulatively and chronologically)
334: if ($ENV{'form.catalogmode'} eq 'groupimport') {
335: my $acts=$ENV{'form.acts'};
336: my @Acts=split(/b/,$acts);
337: my %ahash;
338: my %achash;
339: my $ac=0;
340: # some initial hashes for working with data
341: foreach (@Acts) {
342: my ($state,$ref)=split(/a/);
343: $ahash{$ref}=$state;
344: $achash{$ref}=$ac;
345: $ac++;
346: }
347: # sorting through the actions and changing the tied database hash
348: foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
349: my $key=$_;
350: if ($ahash{$key} eq '1') {
351: $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
352: $hash{'pre_'.$key.'_title'};
353: $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
354: $hash{'storectr'}+0;
355: $hash{'storectr'}++;
356: }
357: if ($ahash{$key} eq '0') {
358: if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
359: delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
360: }
361: }
362: }
363: # deleting the previously cached listing
364: foreach (keys %hash) {
365: if ($_ =~ /^pre_/ && $_ =~/link$/) {
366: my $key = $_;
367: $key =~ s/^pre_//;
368: $key =~ s/_[^_]*$//;
369: delete $hash{'pre_'.$key.'_title'};
370: delete $hash{'pre_'.$key.'_link'};
371: }
372: }
373: }
374:
375: # ---------------------------------------------------------------- output title
376: $r->print(
377: '<h2><font color="#339933">The Learning<i>Online</i> Network with CAPA '.
378: 'Network Directory Browser</font></h2>'."\n");
379: # ---------------------------------- get state of file attributes to be showing
380: if ($ENV{'form.attrs'} ne '') {
381: for (my $i=0; $i<=7; $i++) {
382: delete $hash{'display_attrs_'.$i};
383: if ($ENV{'form.attr'.$i} == 1) {
384: $attrchk[$i] = 'checked';
385: $hash{'display_attrs_'.$i} = 1;
386: }
387: }
388: } else {
389: for (my $i=0; $i<=7; $i++) {
390: $attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;
391: }
392: }
393: # ------------------------------- output state of file attributes to be showing
394: $r->print(<<END);
395: <form method="post" name="fileattr" action="$uri"
396: enctype="application/x-www-form-urlencoded">
397: <b><font color="#666666">Display file attributes</font></b><br />
398: <table border=0><tr>
399: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> Title</td>
400: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Size</td>
401: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last access</td>
402: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Last modified</td>
403: </tr><tr>
404: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Author</td>
405: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> Keywords</td>
406: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> Language</td>
407: <td><input type="checkbox" name="attr7" value="1" $attrchk[7] /> All versions</td>
408: </tr></table>
409: <input type="hidden" name="dirPointer" value="on" />
410: <input type="hidden" name="acts" value="" />
411: <input type="submit" name="attrs" value="Review" />
412: <input type="submit" name="attrs" value="Refresh" />
413: $closebutton
414: $groupimportbutton
415: </form>
416: END
417:
418: # ----------------- output starting row to the indexed file/directory hierarchy
419: my $titleclr="#ddffff";
420: # $r->print(&initdebug());
421: # $r->print(&writedebug("Omit:@Omit")) if (@Omit);
422: # $r->print(&writedebug("Only:@Only")) if (@Only);
423: $r->print("<table width='100\%' border=0><tr><td bgcolor=#777777>\n");
424: $r->print("<table width='100\%' border=0><tr bgcolor=$titleclr>\n");
425: $r->print("<td $colspan><b>Name</b></td>\n");
426: $r->print("<td><b>Title</b></td>\n")
427: if ($hash{'display_attrs_0'} == 1);
428: $r->print("<td align=right><b>Size (bytes) ".
429: "</b></td>\n") if ($hash{'display_attrs_1'} == 1);
430: $r->print("<td><b>Last accessed</b></td>\n")
431: if ($hash{'display_attrs_2'} == 1);
432: $r->print("<td><b>Last modified</b></td>\n")
433: if ($hash{'display_attrs_3'} == 1);
434: $r->print("<td><b>Author(s)</b></td>\n")
435: if ($hash{'display_attrs_4'} == 1);
436: $r->print("<td><b>Keywords</b></td>\n")
437: if ($hash{'display_attrs_5'} == 1);
438: $r->print("<td><b>Language</b></td>\n")
439: if ($hash{'display_attrs_6'} == 1);
440: $r->print('</tr>');
441:
442: # ----------------- read in what directories have previously been set to "open"
443: foreach (keys %hash) {
444: if ($_ =~ /^diropen_status_/) {
445: my $key = $_;
446: $key =~ s/^diropen_status_//;
447: $dirs{$key} = $hash{$_};
448: }
449: }
450:
451: if ($ENV{'form.openuri'}) { # take care of review and refresh options
452: my $uri=$ENV{'form.openuri'};
453: if (exists($hash{'diropen_status_'.$uri})) {
454: my $cursta = $hash{'diropen_status_'.$uri};
455: $dirs{$uri} = 'open';
456: $hash{'diropen_status_'.$uri} = 'open';
457: if ($cursta eq 'open') {
458: $dirs{$uri} = 'closed';
459: $hash{'diropen_status_'.$uri} = 'closed';
460: }
461: } else {
462: $hash{'diropen_status_'.$uri} = 'open';
463: $dirs{$uri} = 'open';
464: }
465: }
466:
467: my $bredir = $ENV{'form.dirPointer'};
468: my $toplevel;
469: my $indent = 0;
470: $uri = $uri.'/' if $uri !~ /.*\/$/;
471:
472: if ($bredir ne 'on') {
473: $hash{'top.level'} = $uri;
474: $toplevel = $uri;
475:
476: } else {
477: $toplevel = $hash{'top.level'};
478: }
479:
480: # -------------------------------- if not at top level, provide an uplink arrow
481: if ($toplevel ne '/res/'){
482: my (@uri_com) = split(/\//,$uri);
483: pop @uri_com;
484: my $upone = join('/',@uri_com);
485: my @list = qw (0);
486: &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
487: $indent = 1;
488: }
489:
490: # -------- recursively go through all the directories and output as appropriate
491: &scanDir ($r,$toplevel,$indent,\%hash);
492:
493: # ---------------------------- embed hidden information useful for group import
494: $r->print("<form name='fnum'>");
495: $r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
496:
497: # -------------------------------------------------------------- end the tables
498: $r->print('</table>');
499: $r->print('</td></tr></table>');
500:
501: # --------------------------------------------------- end the output and return
502: $r->print('</body></html>'."\n");
503: untie(%hash);
504: } else {
505: $r->print('<html><head></head><body>Unable to tie hash to db '.
506: 'file</body></html>');
507: return OK;
508: }
509: return OK;
510: }
511:
512: # ----------------------------------------------- recursive scan of a directory
513: sub scanDir {
514: my ($r,$startdir,$indent,$hashref)=@_;
515: my ($compuri,$curdir);
516: my $dirptr=16384;
517: $indent++;
518:
519: my %dupdirs = %dirs;
520: my @list=&get_list($r,$startdir);
521: foreach my $line (@list) {
522: my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5);
523: next if $strip =~ /.*\.meta$/;
524: my (@fileparts) = split(/\./,$strip);
525: if ($hash{'display_attrs_7'} != 1) {
526: if (scalar(@fileparts) >= 3) {
527: my $fext = pop @fileparts;
528: my $ov = pop @fileparts;
529: my $fname = join ('.',@fileparts,$fext);
530: next if (grep /$fname/,@list and $ov =~ /\d+/);
531: }
532: }
533:
534: if ($dom eq 'domain') {
535: $compuri = join('',$strip,'/'); # dom list has /res/<domain name>
536: $curdir = $compuri;
537: } else {
538: # user, dir & file have name only, i.e., w/o path
539: $compuri = join('',$startdir,$strip,'/');
540: $curdir = $startdir;
541: }
542: my $diropen = 'closed';
543: if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
544: while (my ($key,$val)= each %dupdirs) {
545: if ($key eq $compuri and $val eq "open") {
546: $diropen = "opened";
547: delete $dupdirs{key},$dirs{$key};
548: }
549: }
550: }
551: &display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
552: &scanDir ($r,$compuri,$indent) if $diropen eq 'opened';
553: }
554: $indent--;
555: }
556:
557: # --------------- get complete matched list based on the uri (returns an array)
558: sub get_list {
559: my ($r,$uri)=@_;
560: my @list;
561: (my $luri = $uri) =~ s/\//_/g;
562:
563: if ($ENV{'form.attrs'} eq 'Refresh') {
564: foreach (keys %hash) {
565: delete $hash{$_} if ($_ =~ /^dirlist_files_/);
566: }
567: }
568:
569: if ($hash{'dirlist_files'.$luri}) {
570: @list = split(/\n/,$hash{'dirlist_files_'.$luri});
571: } else {
572: @list = &Apache::lonnet::dirlist($uri);
573: $hash{'dirlist_files_'.$luri} = join('\n',@list);
574: }
575: return @list=&match_ext($r,@list);
576: }
577:
578: sub initdebug {
579: return <<ENDJS;
580: <script>
581: var debugging = true;
582: if (debugging) {
583: var debuggingWindow = window.open('','Debug','width=400,height=300',true);
584: }
585:
586: function output(text) {
587: if (debugging) {
588: debuggingWindow.document.writeln(text);
589: }
590: }
591: output("<html><head><title>Debugging Window</title></head><body><pre>");
592: </script>
593: ENDJS
594: }
595:
596: sub writedebug {
597: my $text = shift;
598: return "<script>output('$text');</script>";
599: }
600:
601: # -------------------- filters out files based on extensions (returns an array)
602: sub match_ext {
603: my ($r,@packlist)=@_;
604: my @trimlist;
605: my $nextline;
606: my @fileext;
607: my $dirptr=16384;
608:
609: foreach my $line (@packlist) {
610: chomp $line;
611: $line =~ s/^\/home\/httpd\/html//;
612: my @unpackline = split (/\&/,$line);
613: next if ($unpackline[0] eq '.');
614: next if ($unpackline[0] eq '..');
615: my @filecom = split (/\./,$unpackline[0]);
616: my $fext = pop(@filecom);
617: my $fnptr = $unpackline[3]&$dirptr;
618: if ($fnptr == 0 and $unpackline[3] ne "") {
619: my $embstyle = &Apache::loncommon::fileembstyle($fext);
620: push @trimlist,$line if (defined($embstyle) &&
621: ($embstyle ne 'hdn' or $fext eq 'meta'));
622: } else {
623: push @trimlist,$line;
624: }
625: }
626: @trimlist = sort (@trimlist);
627: return @trimlist;
628: }
629:
630: # ------------------------------- displays one line in appropriate table format
631: sub display_line {
632: my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
633: my (@pathfn, $fndir, $fnptr);
634: my $dirptr=16384;
635: my $fileclr="#ffffe6";
636: my $iconpath= $r->dir_config('lonIconsURL') . '/';
637:
638: my @filecom = split (/\&/,$line);
639: my @pathcom = split (/\//,$filecom[0]);
640: my $listname = $pathcom[scalar(@pathcom)-1];
641: my $fnptr = $filecom[3]&$dirptr;
642: my $msg = 'View '.$filecom[0].' resources';
643: $msg = 'Close '.$filecom[0].' directory' if $diropen eq 'opened';
644:
645: my $tabtag='</td>';
646: my $i=0;
647:
648: while ($i<=6) {
649: $tabtag=join('',$tabtag,"<td> </td>")
650: if $hash{'display_attrs_'.$i} == 1;
651: $i++;
652: }
653:
654: # display uplink arrow
655: if ($filecom[1] eq 'viewOneUp') {
656: $r->print("<tr bgcolor=$fileclr>$extrafield");
657: $r->print("<td valign=bottom>\n");
658: $r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
659: '/" '.
660: 'onSubmit="return rep_dirpath(\'UP\','.
661: 'document.forms.fileattr.acts.value)" '.
662: 'enctype="application/x-www-form-urlencoded"'.
663: '>'."\n");
664: $r->print ('<input type=hidden name=openuri value="'.
665: $startdir.'">'."\n");
666: $r->print ('<input type="hidden" name="acts" value="">'."\n");
667: $r->print ('<input src="'.$iconpath.'arrow_up.gif"');
668: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
669: "\n");
670: $r->print("Up $tabtag</tr></form>\n");
671: return OK;
672: }
673:
674: # display domain
675: if ($filecom[1] eq 'domain') {
676: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
677: if ($ENV{'form.dirPointer'} eq "on");
678: $r->print("<tr bgcolor=$fileclr>$extrafield");
679: $r->print("<td valign=bottom>");
680: &begin_form ($r,$filecom[0].'/');
681: my $anchor = $filecom[0].'/';
682: $anchor =~ s/\///g;
683: $r->print ('<a name="'.$anchor.'">');
684: $r->print ('<input type="hidden" name="acts" value="">');
685: $r->print ('<input src="'.$iconpath.'folder_pointer_'.
686: $diropen.'.gif"');
687: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
688: "\n");
689: $r->print ('<a href="javascript:gothere(\''.$filecom[0].
690: '/\')"><img src="'.$iconpath.'server.gif"');
691: $r->print (' border="0" /></a>'."\n");
692: $r->print("Domain - $listname (".
693: $Apache::lonnet::domaindescription{$listname}.") $tabtag</tr></form>\n");
694: return OK;
695:
696: # display user directory
697: }
698: if ($filecom[1] eq 'user') {
699: $r->print("<tr bgcolor=$fileclr>$extrafield");
700: $r->print("<td valign=bottom nowrap>\n");
701: my $curdir = $startdir.$filecom[0].'/';
702: my $anchor = $curdir;
703: $anchor =~ s/\///g;
704: &begin_form ($r,$curdir);
705: $r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
706: 'whitespace1.gif" border="0" />'."\n");
707: $r->print ('<input type="hidden" name="acts" value="">');
708: $r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
709: '.gif"');
710: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
711: "\n");
712: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
713: $iconpath.'quill.gif border="0" name="'.$msg.
714: '" height="22" /></a>');
715: $r->print ($listname.$tabtag.'</tr></form>'."\n");
716: return OK;
717: }
718:
719: # display file
720: if ($fnptr == 0 and $filecom[3] ne '') {
721: my $filelink = $startdir.$filecom[0];
722: return OK if (!&Apache::lonnet::allowed('bre',$filelink));
723: my @file_ext = split (/\./,$listname);
724: my $curfext = $file_ext[-1];
725: if (@Omit) {
726: foreach (@Omit) { return OK if ($curfext eq $_); }
727: }
728: if (@Only) {
729: my $skip = 1;
730: foreach (@Only) { $skip = 0 if ($curfext eq $_); }
731: return OK if ($skip > 0);
732: }
733: # Set the icon for the file
734: my $iconname = "unknown.gif";
735: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
736: # The unless conditional that follows is a bit of overkill
737: $iconname = $curfext.".gif" unless
738: (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn');
739: #
740: $r->print("<tr bgcolor=$fileclr><td nowrap valign='bottom'>");
741: my $metafile = grep /^$filecom[0]\.meta\&/, @list;
742: my $title;
743: if ($ENV{'form.catalogmode'} eq 'interactive') {
744: $title=$listname;
745: $title = &Apache::lonnet::metadata($filelink,'title')
746: if ($metafile == 1);
747: $title=$listname unless $title;
748: my $titleesc=HTML::Entities::encode($title);
749: $titleesc=~s/\'/\\'/; #' (clean up this spare quote)
750: $r->print("<a href=\"javascript:select_data(\'",
751: $titleesc,"','",$filelink,"')\">");
752: $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
753: "\n");
754: $r->print("</td><td valign='bottom' nowrap>");
755: }
756: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
757: $title=$listname;
758: $title = &Apache::lonnet::metadata($filelink,'title')
759: if ($metafile == 1);
760: $title=$listname unless $title;
761: my $titleesc=&HTML::Entities::encode($title);
762: $r->print("<form name='form$fnum'>\n");
763: $r->print("<input type='checkbox' name='filelink"."' ".
764: "value='$filelink' onClick='".
765: "javascript:queue(\"form$fnum\")' ");
766: if ($hash{'store_'.$filelink}) {
767: $r->print("checked");
768: }
769: $r->print(">\n");
770: $r->print("<input type='hidden' name='title"."' ".
771: "value='$titleesc'>\n");
772: $r->print("</form>\n");
773: $r->print("</td><td valign='bottom' nowrap>");
774: $hash{"pre_${fnum}_link"}=$filelink;
775: $hash{"pre_${fnum}_title"}=$titleesc;
776: $fnum++;
777: }
778:
779: if ($indent > 0 and $indent < 11) {
780: $r->print("<img src=",$iconpath,"whitespace",$indent,
781: ".gif border='0' />\n");
782: } elsif ($indent >0) {
783: my $ten = int($indent/10.);
784: my $rem = $indent%10.0;
785: my $count = 0;
786: while ($count < $ten) {
787: $r->print("<img src=",$iconpath,
788: "whitespace10.gif border='0' />\n");
789: $count++;
790: }
791: $r->print("<img src=",$iconpath,"whitespace",$rem,
792: ".gif border='0' />\n") if $rem > 0;
793: }
794:
795: $r->print("<img src=$iconpath$iconname border='0' />\n");
796: $r->print (" <a href=\"javascript:openWindow('".$filelink.
797: "', 'metadatafile', '450', '500', 'no', 'yes')\";".
798: " TARGET=_self>$listname</a> ");
799:
800: $r->print (" (<a href=\"javascript:openWindow('".$filelink.
801: ".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; ".
802: "TARGET=_self>metadata</a>) ") if ($metafile == 1);
803:
804: $r->print("</td>\n");
805: if ($hash{'display_attrs_0'} == 1) {
806: my $title = &Apache::lonnet::metadata($filelink,'title')
807: if ($metafile == 1);
808: $r->print('<td valign=bottom> '.($title eq '' ? ' ' : $title).
809: ' </td>'."\n");
810: }
811: $r->print('<td align=right valign=bottom> ',
812: $filecom[8]," </td>\n")
813: if $hash{'display_attrs_1'} == 1;
814: $r->print('<td valign=bottom> '.
815: (localtime($filecom[9]))." </td>\n")
816: if $hash{'display_attrs_2'} == 1;
817: $r->print('<td valign=bottom> '.
818: (localtime($filecom[10]))." </td>\n")
819: if $hash{'display_attrs_3'} == 1;
820:
821: if ($hash{'display_attrs_4'} == 1) {
822: my $author = &Apache::lonnet::metadata($filelink,'author')
823: if ($metafile == 1);
824: $r->print('<td valign=bottom> '.($author eq '' ? ' ' : $author).
825: " </td>\n");
826: }
827: if ($hash{'display_attrs_5'} == 1) {
828: my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
829: if ($metafile == 1);
830: # $keywords = ' ' if (!$keywords);
831: $r->print('<td valign=bottom> '.($keywords eq '' ? ' ' : $keywords).
832: " </td>\n");
833: }
834: if ($hash{'display_attrs_6'} == 1) {
835: my $lang = &Apache::lonnet::metadata($filelink,'language')
836: if ($metafile == 1);
837: $lang = &Apache::loncommon::languagedescription($lang);
838: $r->print('<td valign=bottom> '.($lang eq '' ? ' ' : $lang).
839: " </td>\n");
840: }
841: $r->print("</tr>\n");
842: }
843:
844: # -- display directory
845: if ($fnptr == $dirptr) {
846: my @file_ext = split (/\./,$listname);
847: my $curfext = $file_ext[scalar(@file_ext)-1];
848: my $curdir = $startdir.$filecom[0].'/';
849: my $anchor = $curdir;
850: $anchor =~ s/\///g;
851: $r->print("<tr bgcolor=$fileclr>$extrafield<td valign=bottom>");
852: &begin_form ($r,$curdir);
853: my $indentm1 = $indent-1;
854: if ($indentm1 < 11 and $indentm1 > 0) {
855: $r->print("<img src=",$iconpath,"whitespace",$indentm1,
856: ".gif border='0' />\n");
857: } else {
858: my $ten = int($indentm1/10.);
859: my $rem = $indentm1%10.0;
860: my $count = 0;
861: while ($count < $ten) {
862: $r->print ("<img src=",$iconpath
863: ,"whitespace10.gif border='0' />\n");
864: $count++;
865: }
866: $r->print ("<img src=",$iconpath,"whitespace",$rem,
867: ".gif border='0' />\n") if $rem > 0;
868: }
869: $r->print ('<input type="hidden" name="acts" value="">');
870: $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
871: 'folder_pointer_'.$diropen.'.gif"');
872: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
873: "\n");
874: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
875: $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
876: "\n");
877: $r->print ("$listname$tabtag</tr></form>\n");
878: }
879:
880: }
881:
882: # ------------------- prints the beginning of a form for directory or file link
883: sub begin_form {
884: my ($r,$uri) = @_;
885: my $anchor = $uri;
886: $anchor =~ s/\///g;
887: $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
888: '#'.$anchor.
889: '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
890: ',document.forms.fileattr.acts.value)" '.
891: 'enctype="application/x-www-form-urlencoded">'."\n");
892: $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
893: "\n");
894: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
895: $dnum++;
896: }
897:
898: # --------- settings whenever the user causes the indexer window to be launched
899: sub start_fresh_session {
900: delete $hash{'form.catalogmode'};
901: delete $hash{'form.mode'};
902: delete $hash{'form.form'};
903: delete $hash{'form.element'};
904: delete $hash{'form.omit'};
905: delete $hash{'form.only'};
906: foreach (keys %hash) {
907: delete $hash{$_} if (/^(pre_|store)/);
908: }
909: }
910:
911: # ------------------------------------------------------------------- setvalues
912: sub setvalues {
913: # setvalues is used in registerurl to synchronize the database
914: # hash and environment hashes
915: my ($H1,$h1key,$H2,$h2key) =@_;
916: #
917: if (exists $H2->{$h2key}) {
918: $H1->{$h1key} = $H2->{$h2key};
919: } elsif (exists $H1->{$h1key}) {
920: $H2->{$h2key} = $H1->{$h1key};
921: }
922: }
923:
924: 1;
925:
926: =head1 NAME
927:
928: Apache::lonindexer - mod_perl module for cross server filesystem browsing
929:
930: =head1 SYNOPSIS
931:
932: Invoked by /etc/httpd/conf/srm.conf:
933:
934: <LocationMatch "^/res.*/$">
935: SetHandler perl-script
936: PerlHandler Apache::lonindexer
937: </LocationMatch>
938:
939: =head1 INTRODUCTION
940:
941: This module enables a scheme of browsing across a cross server.
942:
943: This is part of the LearningOnline Network with CAPA project
944: described at http://www.lon-capa.org.
945:
946: =head1 BEGIN SUBROUTINE
947:
948: This routine is only run once after compilation.
949:
950: =over 4
951:
952: =item *
953:
954: Initializes %language hash table.
955:
956: =back
957:
958: =head1 HANDLER SUBROUTINE
959:
960: This routine is called by Apache and mod_perl.
961:
962: =over 4
963:
964: =item *
965:
966: read in machine configuration variables
967:
968: =item *
969:
970: see if called from an interactive mode
971:
972: =item *
973:
974: refresh environment with user database values (in %hash)
975:
976: =item *
977:
978: define extra fields and buttons in case of special mode
979:
980: =item *
981:
982: set catalogmodefunctions to have extra needed javascript functionality
983:
984: =item *
985:
986: print header
987:
988: =item *
989:
990: evaluate actions from previous page (both cumulatively and chronologically)
991:
992: =item *
993:
994: output title
995:
996: =item *
997:
998: get state of file attributes to be showing
999:
1000: =item *
1001:
1002: output state of file attributes to be showing
1003:
1004: =item *
1005:
1006: output starting row to the indexed file/directory hierarchy
1007:
1008: =item *
1009:
1010: read in what directories have previously been set to "open"
1011:
1012: =item *
1013:
1014: if not at top level, provide an uplink arrow
1015:
1016: =item *
1017:
1018: recursively go through all the directories and output as appropriate
1019:
1020: =item *
1021:
1022: information useful for group import
1023:
1024: =item *
1025:
1026: end the tables
1027:
1028: =item *
1029:
1030: end the output and return
1031:
1032: =back
1033:
1034: =head1 OTHER SUBROUTINES
1035:
1036: =over 4
1037:
1038: =item *
1039:
1040: scanDir - recursive scan of a directory
1041:
1042: =item *
1043:
1044: get_list - get complete matched list based on the uri (returns an array)
1045:
1046: =item *
1047:
1048: match_ext - filters out files based on extensions (returns an array)
1049:
1050: =item *
1051:
1052: display_line - displays one line in appropriate table format
1053:
1054: =item *
1055:
1056: begin_form - prints the beginning of a form for directory or file link
1057:
1058: =item *
1059:
1060: start_fresh_session - settings whenever the user causes the indexer window
1061: to be launched
1062:
1063: =back
1064:
1065: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>