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