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