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