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