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