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