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