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