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