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