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