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