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