Annotation of loncom/interface/lonindexer.pm, revision 1.47
1.1 www 1: # The LearningOnline Network with CAPA
1.24 harris41 2: # Directory Indexer
3: #
1.47 ! ng 4: # $Id: lonindexer.pm,v 1.46 2002/07/02 21:08:24 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.47 ! ng 726: my $filelink = $startdir.$filecom[0];
! 727: return OK if (!&Apache::lonnet::allowed('bre',$filelink));
1.1 www 728: my @file_ext = split (/\./,$listname);
1.25 matthew 729: my $curfext = $file_ext[-1];
1.40 matthew 730: if (@Omit) {
731: foreach (@Omit) { return OK if ($curfext eq $_); }
732: }
733: if (@Only) {
734: my $skip = 1;
735: foreach (@Only) { $skip = 0 if ($curfext eq $_); }
736: return OK if ($skip > 0);
737: }
1.25 matthew 738: # Set the icon for the file
1.26 matthew 739: my $iconname = "unknown.gif";
1.28 harris41 740: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.25 matthew 741: # The unless conditional that follows is a bit of overkill
742: $iconname = $curfext.".gif" unless
1.26 matthew 743: (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn');
1.25 matthew 744: #
1.45 ng 745: $r->print("<tr bgcolor=$fileclr><td nowrap valign='bottom'>");
1.7 harris41 746: my $metafile = grep /^$filecom[0]\.meta\&/, @list;
747: my $title;
748: if ($ENV{'form.catalogmode'} eq 'interactive') {
749: $title=$listname;
1.8 harris41 750: $title = &Apache::lonnet::metadata($filelink,'title')
751: if ($metafile == 1);
1.7 harris41 752: $title=$listname unless $title;
1.42 albertel 753: my $titleesc=HTML::Entities::encode($title);
754: $titleesc=~s/\'/\\'/; #' (clean up this spare quote)
1.35 matthew 755: $r->print("<a href=\"javascript:select_data(\'",
1.34 harris41 756: $titleesc,"','",$filelink,"')\">");
1.17 harris41 757: $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
758: "\n");
1.45 ng 759: $r->print("</td><td valign='bottom' nowrap>");
1.8 harris41 760: }
761: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
762: $title=$listname;
763: $title = &Apache::lonnet::metadata($filelink,'title')
764: if ($metafile == 1);
765: $title=$listname unless $title;
1.42 albertel 766: my $titleesc=&HTML::Entities::encode($title);
1.8 harris41 767: $r->print("<form name='form$fnum'>\n");
768: $r->print("<input type='checkbox' name='filelink"."' ".
1.16 harris41 769: "value='$filelink' onClick='".
770: "javascript:queue(\"form$fnum\")' ");
771: if ($hash{'store_'.$filelink}) {
772: $r->print("checked");
773: }
774: $r->print(">\n");
1.8 harris41 775: $r->print("<input type='hidden' name='title"."' ".
1.42 albertel 776: "value='$titleesc'>\n");
1.8 harris41 777: $r->print("</form>\n");
1.45 ng 778: $r->print("</td><td valign='bottom' nowrap>");
1.16 harris41 779: $hash{"pre_${fnum}_link"}=$filelink;
1.42 albertel 780: $hash{"pre_${fnum}_title"}=$titleesc;
1.8 harris41 781: $fnum++;
1.7 harris41 782: }
1.4 harris41 783:
1.12 ng 784: if ($indent > 0 and $indent < 11) {
1.17 harris41 785: $r->print("<img src=",$iconpath,"whitespace",$indent,
786: ".gif border='0' />\n");
1.11 ng 787: } elsif ($indent >0) {
1.4 harris41 788: my $ten = int($indent/10.);
789: my $rem = $indent%10.0;
790: my $count = 0;
791: while ($count < $ten) {
1.17 harris41 792: $r->print("<img src=",$iconpath,
793: "whitespace10.gif border='0' />\n");
1.1 www 794: $count++;
1.4 harris41 795: }
1.17 harris41 796: $r->print("<img src=",$iconpath,"whitespace",$rem,
797: ".gif border='0' />\n") if $rem > 0;
1.1 www 798: }
1.4 harris41 799:
1.25 matthew 800: $r->print("<img src=$iconpath$iconname border='0' />\n");
1.17 harris41 801: $r->print (" <a href=\"javascript:openWindow('".$filelink.
802: "', 'metadatafile', '450', '500', 'no', 'yes')\";".
803: " TARGET=_self>$listname</a> ");
804:
805: $r->print (" (<a href=\"javascript:openWindow('".$filelink.
806: ".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; ".
807: "TARGET=_self>metadata</a>) ") if ($metafile == 1);
1.2 harris41 808:
1.7 harris41 809: $r->print("</td>\n");
1.45 ng 810: if ($hash{'display_attrs_0'} == 1) {
811: my $title = &Apache::lonnet::metadata($filelink,'title')
812: if ($metafile == 1);
813: $r->print('<td valign=bottom> '.($title eq '' ? ' ' : $title).
814: ' </td>'."\n");
815: }
816: $r->print('<td align=right valign=bottom> ',
1.17 harris41 817: $filecom[8]," </td>\n")
1.45 ng 818: if $hash{'display_attrs_1'} == 1;
819: $r->print('<td valign=bottom> '.
1.17 harris41 820: (localtime($filecom[9]))." </td>\n")
1.45 ng 821: if $hash{'display_attrs_2'} == 1;
822: $r->print('<td valign=bottom> '.
1.17 harris41 823: (localtime($filecom[10]))." </td>\n")
1.45 ng 824: if $hash{'display_attrs_3'} == 1;
1.2 harris41 825:
1.45 ng 826: if ($hash{'display_attrs_4'} == 1) {
1.17 harris41 827: my $author = &Apache::lonnet::metadata($filelink,'author')
828: if ($metafile == 1);
1.45 ng 829: $r->print('<td valign=bottom> '.($author eq '' ? ' ' : $author).
1.17 harris41 830: " </td>\n");
1.2 harris41 831: }
1.45 ng 832: if ($hash{'display_attrs_5'} == 1) {
1.17 harris41 833: my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
834: if ($metafile == 1);
1.45 ng 835: # $keywords = ' ' if (!$keywords);
836: $r->print('<td valign=bottom> '.($keywords eq '' ? ' ' : $keywords).
1.17 harris41 837: " </td>\n");
1.2 harris41 838: }
1.45 ng 839: if ($hash{'display_attrs_6'} == 1) {
1.17 harris41 840: my $lang = &Apache::lonnet::metadata($filelink,'language')
841: if ($metafile == 1);
1.28 harris41 842: $lang = &Apache::loncommon::languagedescription($lang);
1.45 ng 843: $r->print('<td valign=bottom> '.($lang eq '' ? ' ' : $lang).
1.17 harris41 844: " </td>\n");
1.2 harris41 845: }
1.1 www 846: $r->print("</tr>\n");
847: }
1.17 harris41 848:
1.2 harris41 849: # -- display directory
1.1 www 850: if ($fnptr == $dirptr) {
851: my @file_ext = split (/\./,$listname);
852: my $curfext = $file_ext[scalar(@file_ext)-1];
1.2 harris41 853: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 854: my $anchor = $curdir;
855: $anchor =~ s/\///g;
1.45 ng 856: $r->print("<tr bgcolor=$fileclr>$extrafield<td valign=bottom>");
1.2 harris41 857: &begin_form ($r,$curdir);
1.4 harris41 858: my $indentm1 = $indent-1;
1.11 ng 859: if ($indentm1 < 11 and $indentm1 > 0) {
1.17 harris41 860: $r->print("<img src=",$iconpath,"whitespace",$indentm1,
861: ".gif border='0' />\n");
1.4 harris41 862: } else {
863: my $ten = int($indentm1/10.);
864: my $rem = $indentm1%10.0;
865: my $count = 0;
866: while ($count < $ten) {
1.17 harris41 867: $r->print ("<img src=",$iconpath
868: ,"whitespace10.gif border='0' />\n");
1.12 ng 869: $count++;
1.4 harris41 870: }
1.17 harris41 871: $r->print ("<img src=",$iconpath,"whitespace",$rem,
872: ".gif border='0' />\n") if $rem > 0;
1.1 www 873: }
1.16 harris41 874: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 875: $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
876: 'folder_pointer_'.$diropen.'.gif"');
877: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
878: "\n");
879: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
880: $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
881: "\n");
1.13 ng 882: $r->print ("$listname$tabtag</tr></form>\n");
1.1 www 883: }
1.2 harris41 884:
1.1 www 885: }
886:
1.14 harris41 887: # ------------------- prints the beginning of a form for directory or file link
1.1 www 888: sub begin_form {
889: my ($r,$uri) = @_;
1.3 harris41 890: my $anchor = $uri;
891: $anchor =~ s/\///g;
1.17 harris41 892: $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
893: '#'.$anchor.
894: '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
895: ',document.forms.fileattr.acts.value)" '.
1.16 harris41 896: 'enctype="application/x-www-form-urlencoded">'."\n");
1.17 harris41 897: $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
898: "\n");
899: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16 harris41 900: $dnum++;
1.17 harris41 901: }
902:
903: # --------- settings whenever the user causes the indexer window to be launched
904: sub start_fresh_session {
905: delete $hash{'mode_catalog'};
1.35 matthew 906: delete $hash{'form_mode'};
907: delete $hash{'form_form'};
908: delete $hash{'form_element'};
1.40 matthew 909: delete $hash{'form_omit'};
910: delete $hash{'form_only'};
1.27 harris41 911: foreach (keys %hash) {
1.17 harris41 912: if ($_ =~ /^pre_/) {
913: delete $hash{$_};
914: }
915: if ($_ =~ /^store/) {
916: delete $hash{$_};
917: }
1.27 harris41 918: }
1.1 www 919: }
920:
1.35 matthew 921: # ------------------------------------------------------------------- setvalues
922: sub setvalues {
923: # setvalues is used in registerurl to synchronize the database
924: # hash and environment hashes
925: my ($H1,$h1key,$H2,$h2key) =@_;
926: #
927: if (exists $H2->{$h2key}) {
928: $H1->{$h1key} = $H2->{$h2key};
929: } elsif (exists $H1->{$h1key}) {
930: $H2->{$h2key} = $H1->{$h1key};
931: }
932: }
933:
1.1 www 934: 1;
1.23 harris41 935:
936: =head1 NAME
937:
938: Apache::lonindexer - mod_perl module for cross server filesystem browsing
939:
940: =head1 SYNOPSIS
941:
942: Invoked by /etc/httpd/conf/srm.conf:
943:
944: <LocationMatch "^/res.*/$">
945: SetHandler perl-script
946: PerlHandler Apache::lonindexer
947: </LocationMatch>
948:
949: =head1 INTRODUCTION
950:
951: This module enables a scheme of browsing across a cross server.
952:
953: This is part of the LearningOnline Network with CAPA project
954: described at http://www.lon-capa.org.
955:
956: =head1 BEGIN SUBROUTINE
957:
958: This routine is only run once after compilation.
959:
960: =over 4
961:
962: =item *
963:
964: Initializes %language hash table.
965:
966: =back
967:
968: =head1 HANDLER SUBROUTINE
969:
970: This routine is called by Apache and mod_perl.
971:
972: =over 4
973:
974: =item *
975:
976: read in machine configuration variables
977:
978: =item *
979:
980: see if called from an interactive mode
981:
982: =item *
983:
984: refresh environment with user database values (in %hash)
985:
986: =item *
987:
988: define extra fields and buttons in case of special mode
989:
990: =item *
991:
992: set catalogmodefunctions to have extra needed javascript functionality
993:
994: =item *
995:
996: print header
997:
998: =item *
999:
1000: evaluate actions from previous page (both cumulatively and chronologically)
1001:
1002: =item *
1003:
1004: output title
1005:
1006: =item *
1007:
1008: get state of file attributes to be showing
1009:
1010: =item *
1011:
1012: output state of file attributes to be showing
1013:
1014: =item *
1015:
1016: output starting row to the indexed file/directory hierarchy
1017:
1018: =item *
1019:
1020: read in what directories have previously been set to "open"
1021:
1022: =item *
1023:
1024: if not at top level, provide an uplink arrow
1025:
1026: =item *
1027:
1028: recursively go through all the directories and output as appropriate
1029:
1030: =item *
1031:
1032: information useful for group import
1033:
1034: =item *
1035:
1036: end the tables
1037:
1038: =item *
1039:
1040: end the output and return
1041:
1042: =back
1043:
1044: =head1 OTHER SUBROUTINES
1045:
1046: =over 4
1047:
1048: =item *
1049:
1050: scanDir - recursive scan of a directory
1051:
1052: =item *
1053:
1054: get_list - get complete matched list based on the uri (returns an array)
1055:
1056: =item *
1057:
1058: match_ext - filters out files based on extensions (returns an array)
1059:
1060: =item *
1061:
1062: display_line - displays one line in appropriate table format
1063:
1064: =item *
1065:
1066: begin_form - prints the beginning of a form for directory or file link
1067:
1068: =item *
1069:
1070: start_fresh_session - settings whenever the user causes the indexer window
1071: to be launched
1072:
1073: =back
1074:
1075: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>