Annotation of loncom/interface/lonindexer.pm, revision 1.80
1.1 www 1: # The LearningOnline Network with CAPA
1.24 harris41 2: # Directory Indexer
3: #
1.80 ! albertel 4: # $Id: lonindexer.pm,v 1.79 2003/10/24 21:09:24 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.15 harris41 435: $r->print(<<END);
1.17 harris41 436: <form method="post" name="fileattr" action="$uri"
437: enctype="application/x-www-form-urlencoded">
1.45 ng 438: <b><font color="#666666">Display file attributes</font></b><br />
1.1 www 439: <table border=0><tr>
1.77 www 440: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> $lt{'ti'}</td>
441: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> $lt{'si'}</td>
442: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> $lt{'la'}</td>
443: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> $lt{'lm'}</td>
444: <td><input type="checkbox" name="attr8" value="1" $attrchk[8] /> $lt{'st'}</td>
445: </tr><tr>
446: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> $lt{'au'}</td>
447: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> $lt{'kw'}</td>
1.78 www 448: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> $lt{'ln'}</td>
1.77 www 449: <td><input type="checkbox" name="attr7" value="1" $attrchk[7] /> $lt{'sr'}</td>
450: <td><input type="checkbox" name="attr9" value="1" $attrchk[9] /> $lt{'av'}</td>
1.63 ng 451: <td> </td>
1.1 www 452: </tr></table>
1.16 harris41 453: <input type="hidden" name="dirPointer" value="on" />
454: <input type="hidden" name="acts" value="" />
1.77 www 455: <input type="submit" name="attrs" value="$lt{'ud'}" />
1.7 harris41 456: $closebutton
457: $groupimportbutton
1.1 www 458: </form>
459: END
460:
1.23 harris41 461: # ----------------- output starting row to the indexed file/directory hierarchy
1.15 harris41 462: my $titleclr="#ddffff";
1.40 matthew 463: # $r->print(&initdebug());
464: # $r->print(&writedebug("Omit:@Omit")) if (@Omit);
465: # $r->print(&writedebug("Only:@Only")) if (@Only);
1.46 ng 466: $r->print("<table width='100\%' border=0><tr><td bgcolor=#777777>\n");
1.45 ng 467: $r->print("<table width='100\%' border=0><tr bgcolor=$titleclr>\n");
1.77 www 468: $r->print("<td $colspan><b>".&mt('Name')."</b></td>\n");
469: $r->print("<td><b>".&mt('Title')."</b></td>\n")
1.45 ng 470: if ($hash{'display_attrs_0'} == 1);
1.77 www 471: $r->print("<td align=right><b>".&mt("Size")." (".&mt("bytes").") ".
1.45 ng 472: "</b></td>\n") if ($hash{'display_attrs_1'} == 1);
1.77 www 473: $r->print("<td><b>".&mt("Last accessed")."</b></td>\n")
1.17 harris41 474: if ($hash{'display_attrs_2'} == 1);
1.77 www 475: $r->print("<td><b>".&mt("Last modified")."</b></td>\n")
1.17 harris41 476: if ($hash{'display_attrs_3'} == 1);
1.77 www 477: $r->print("<td><b>".&mt("Author(s)")."</b></td>\n")
1.17 harris41 478: if ($hash{'display_attrs_4'} == 1);
1.77 www 479: $r->print("<td><b>".&mt("Keywords")."</b></td>\n")
1.17 harris41 480: if ($hash{'display_attrs_5'} == 1);
1.77 www 481: $r->print("<td><b>".&mt("Language")."</b></td>\n")
1.45 ng 482: if ($hash{'display_attrs_6'} == 1);
1.77 www 483: $r->print("<td><b>".&mt("Resource")."</b></td>\n")
1.63 ng 484: if ($hash{'display_attrs_7'} == 1);
1.77 www 485: $r->print("<td><b>".&mt("Usage Statistics")." <br />(".
486: &mt("Courses/Network Hits").")</b></td>\n")
1.70 ng 487: if ($hash{'display_attrs_8'} == 1);
1.45 ng 488: $r->print('</tr>');
1.5 harris41 489:
1.23 harris41 490: # ----------------- read in what directories have previously been set to "open"
1.27 harris41 491: foreach (keys %hash) {
1.4 harris41 492: if ($_ =~ /^diropen_status_/) {
493: my $key = $_;
494: $key =~ s/^diropen_status_//;
495: $dirs{$key} = $hash{$_};
496: }
1.27 harris41 497: }
1.4 harris41 498:
1.2 harris41 499: if ($ENV{'form.openuri'}) { # take care of review and refresh options
500: my $uri=$ENV{'form.openuri'};
1.4 harris41 501: if (exists($hash{'diropen_status_'.$uri})) {
502: my $cursta = $hash{'diropen_status_'.$uri};
1.2 harris41 503: $dirs{$uri} = 'open';
1.4 harris41 504: $hash{'diropen_status_'.$uri} = 'open';
505: if ($cursta eq 'open') {
506: $dirs{$uri} = 'closed';
507: $hash{'diropen_status_'.$uri} = 'closed';
508: }
1.2 harris41 509: } else {
1.4 harris41 510: $hash{'diropen_status_'.$uri} = 'open';
1.2 harris41 511: $dirs{$uri} = 'open';
512: }
513: }
1.12 ng 514:
515: my $bredir = $ENV{'form.dirPointer'};
516: my $toplevel;
1.13 ng 517: my $indent = 0;
1.12 ng 518: $uri = $uri.'/' if $uri !~ /.*\/$/;
1.17 harris41 519:
1.45 ng 520: if ($bredir ne 'on') {
1.12 ng 521: $hash{'top.level'} = $uri;
522: $toplevel = $uri;
1.13 ng 523:
524: } else {
525: $toplevel = $hash{'top.level'};
526: }
1.17 harris41 527:
1.23 harris41 528: # -------------------------------- if not at top level, provide an uplink arrow
1.45 ng 529: if ($toplevel ne '/res/'){
1.13 ng 530: my (@uri_com) = split(/\//,$uri);
531: pop @uri_com;
532: my $upone = join('/',@uri_com);
533: my @list = qw (0);
534: &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
535: $indent = 1;
1.12 ng 536: }
1.17 harris41 537:
1.23 harris41 538: # -------- recursively go through all the directories and output as appropriate
1.16 harris41 539: &scanDir ($r,$toplevel,$indent,\%hash);
1.12 ng 540:
1.23 harris41 541: # ---------------------------- embed hidden information useful for group import
1.8 harris41 542: $r->print("<form name='fnum'>");
543: $r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
1.17 harris41 544:
1.23 harris41 545: # -------------------------------------------------------------- end the tables
1.45 ng 546: $r->print('</table>');
547: $r->print('</td></tr></table>');
1.17 harris41 548:
1.23 harris41 549: # --------------------------------------------------- end the output and return
1.45 ng 550: $r->print('</body></html>'."\n");
1.68 albertel 551: # } else {
552: # $r->print('<html><head></head><body>Unable to tie hash to db '.
553: # 'file</body></html>');
554: # return OK;
1.2 harris41 555: }
1.67 matthew 556: if(! $c->aborted()) {
1.68 albertel 557: my %dbfile;
1.67 matthew 558: if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_NEWDB(),0640)) {
559: while (my($key,$value) = each(%hash)) {
560: $dbfile{$key}=$value;
561: }
562: untie(%dbfile);
563: }
564: }
565:
1.1 www 566: return OK;
567: }
1.2 harris41 568:
1.17 harris41 569: # ----------------------------------------------- recursive scan of a directory
1.2 harris41 570: sub scanDir {
1.16 harris41 571: my ($r,$startdir,$indent,$hashref)=@_;
1.67 matthew 572: my $c = $r->connection();
1.3 harris41 573: my ($compuri,$curdir);
574: my $dirptr=16384;
1.1 www 575: $indent++;
576:
1.2 harris41 577: my %dupdirs = %dirs;
578: my @list=&get_list($r,$startdir);
579: foreach my $line (@list) {
1.67 matthew 580: return if ($c->aborted());
1.53 albertel 581: my ($strip,$dom,undef,$testdir,undef)=split(/\&/,$line,5);
1.4 harris41 582: next if $strip =~ /.*\.meta$/;
1.18 ng 583: my (@fileparts) = split(/\./,$strip);
1.70 ng 584: if ($hash{'display_attrs_9'} != 1) {
1.18 ng 585: if (scalar(@fileparts) >= 3) {
586: my $fext = pop @fileparts;
587: my $ov = pop @fileparts;
588: my $fname = join ('.',@fileparts,$fext);
1.75 albertel 589: next if (grep /\Q$fname\E/,@list and $ov =~ /^\d+$/);
1.18 ng 590: }
591: }
592:
1.45 ng 593: if ($dom eq 'domain') {
1.72 albertel 594: # dom list has full path /res/<domain name>/ already
595: $curdir='';
1.73 albertel 596: $compuri = (split(/\&/,$line))[0];
1.2 harris41 597: } else {
1.17 harris41 598: # user, dir & file have name only, i.e., w/o path
1.45 ng 599: $compuri = join('',$startdir,$strip,'/');
1.3 harris41 600: $curdir = $startdir;
1.2 harris41 601: }
1.45 ng 602: my $diropen = 'closed';
1.5 harris41 603: if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
1.3 harris41 604: while (my ($key,$val)= each %dupdirs) {
1.5 harris41 605: if ($key eq $compuri and $val eq "open") {
1.11 ng 606: $diropen = "opened";
1.53 albertel 607: delete($dupdirs{$key});
608: delete($dirs{$key});
1.5 harris41 609: }
1.3 harris41 610: }
1.1 www 611: }
1.16 harris41 612: &display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
1.45 ng 613: &scanDir ($r,$compuri,$indent) if $diropen eq 'opened';
1.1 www 614: }
615: $indent--;
616: }
617:
1.17 harris41 618: # --------------- get complete matched list based on the uri (returns an array)
1.1 www 619: sub get_list {
620: my ($r,$uri)=@_;
621: my @list;
1.45 ng 622: (my $luri = $uri) =~ s/\//_/g;
1.2 harris41 623:
1.77 www 624: if ($ENV{'form.attrs'} eq &mt('Update Display')) {
1.27 harris41 625: foreach (keys %hash) {
1.4 harris41 626: delete $hash{$_} if ($_ =~ /^dirlist_files_/);
1.27 harris41 627: }
1.2 harris41 628: }
629:
1.4 harris41 630: if ($hash{'dirlist_files'.$luri}) {
631: @list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.1 www 632: } else {
1.4 harris41 633: @list = &Apache::lonnet::dirlist($uri);
634: $hash{'dirlist_files_'.$luri} = join('\n',@list);
1.1 www 635: }
636: return @list=&match_ext($r,@list);
637: }
638:
1.40 matthew 639: sub initdebug {
640: return <<ENDJS;
641: <script>
642: var debugging = true;
643: if (debugging) {
644: var debuggingWindow = window.open('','Debug','width=400,height=300',true);
645: }
646:
647: function output(text) {
648: if (debugging) {
649: debuggingWindow.document.writeln(text);
650: }
651: }
652: output("<html><head><title>Debugging Window</title></head><body><pre>");
653: </script>
654: ENDJS
655: }
656:
657: sub writedebug {
658: my $text = shift;
659: return "<script>output('$text');</script>";
660: }
661:
1.17 harris41 662: # -------------------- filters out files based on extensions (returns an array)
1.1 www 663: sub match_ext {
664: my ($r,@packlist)=@_;
665: my @trimlist;
666: my $nextline;
667: my @fileext;
668: my $dirptr=16384;
669:
1.2 harris41 670: foreach my $line (@packlist) {
671: chomp $line;
672: $line =~ s/^\/home\/httpd\/html//;
673: my @unpackline = split (/\&/,$line);
1.45 ng 674: next if ($unpackline[0] eq '.');
675: next if ($unpackline[0] eq '..');
1.2 harris41 676: my @filecom = split (/\./,$unpackline[0]);
677: my $fext = pop(@filecom);
678: my $fnptr = $unpackline[3]&$dirptr;
679: if ($fnptr == 0 and $unpackline[3] ne "") {
1.28 harris41 680: my $embstyle = &Apache::loncommon::fileembstyle($fext);
1.25 matthew 681: push @trimlist,$line if (defined($embstyle) &&
1.32 harris41 682: ($embstyle ne 'hdn' or $fext eq 'meta'));
1.1 www 683: } else {
1.2 harris41 684: push @trimlist,$line;
1.1 www 685: }
686: }
1.80 ! albertel 687: @trimlist = sort {uc($a) cmp uc($b)} (@trimlist);
1.1 www 688: return @trimlist;
689: }
690:
1.17 harris41 691: # ------------------------------- displays one line in appropriate table format
1.23 harris41 692: sub display_line {
1.16 harris41 693: my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
1.53 albertel 694: my (@pathfn, $fndir);
1.1 www 695: my $dirptr=16384;
696: my $fileclr="#ffffe6";
1.45 ng 697: my $iconpath= $r->dir_config('lonIconsURL') . '/';
1.1 www 698:
699: my @filecom = split (/\&/,$line);
700: my @pathcom = split (/\//,$filecom[0]);
701: my $listname = $pathcom[scalar(@pathcom)-1];
702: my $fnptr = $filecom[3]&$dirptr;
1.77 www 703: my $msg = &mt('View').' '.$filecom[0].' '.&mt('resources');
704: $msg = &mt('Close').' '.$filecom[0].' '.&mt('directory') if $diropen eq 'opened';
1.1 www 705:
1.45 ng 706: my $tabtag='</td>';
1.1 www 707: my $i=0;
708:
1.70 ng 709: while ($i<=8) {
1.45 ng 710: $tabtag=join('',$tabtag,"<td> </td>")
1.17 harris41 711: if $hash{'display_attrs_'.$i} == 1;
1.1 www 712: $i++;
713: }
1.63 ng 714:
715: my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom');
1.17 harris41 716:
717: # display uplink arrow
1.45 ng 718: if ($filecom[1] eq 'viewOneUp') {
1.70 ng 719: $r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
720: $r->print("<td>\n");
1.16 harris41 721: $r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
722: '/" '.
1.17 harris41 723: 'onSubmit="return rep_dirpath(\'UP\','.
724: 'document.forms.fileattr.acts.value)" '.
1.16 harris41 725: 'enctype="application/x-www-form-urlencoded"'.
726: '>'."\n");
1.17 harris41 727: $r->print ('<input type=hidden name=openuri value="'.
728: $startdir.'">'."\n");
1.16 harris41 729: $r->print ('<input type="hidden" name="acts" value="">'."\n");
1.13 ng 730: $r->print ('<input src="'.$iconpath.'arrow_up.gif"');
1.17 harris41 731: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
732: "\n");
1.77 www 733: $r->print(&mt("Up")." $tabtag</tr></form>\n");
1.13 ng 734: return OK;
735: }
1.64 www 736: # Do we have permission to look at this?
737:
738: return OK if (!&Apache::lonnet::allowed('bre',$startdir.$filecom[0]));
1.17 harris41 739:
740: # display domain
1.45 ng 741: if ($filecom[1] eq 'domain') {
1.17 harris41 742: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
743: if ($ENV{'form.dirPointer'} eq "on");
1.70 ng 744: $r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
745: $r->print("<td>");
1.73 albertel 746: &begin_form ($r,$filecom[0]);
747: my $anchor = $filecom[0];
1.3 harris41 748: $anchor =~ s/\///g;
1.13 ng 749: $r->print ('<a name="'.$anchor.'">');
1.16 harris41 750: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 751: $r->print ('<input src="'.$iconpath.'folder_pointer_'.
752: $diropen.'.gif"');
753: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
754: "\n");
755: $r->print ('<a href="javascript:gothere(\''.$filecom[0].
1.73 albertel 756: '\')"><img src="'.$iconpath.'server.gif"');
1.17 harris41 757: $r->print (' border="0" /></a>'."\n");
1.77 www 758: $r->print (&mt("Domain")." - $listname ");
1.60 albertel 759: if ($Apache::lonnet::domaindescription{$listname}) {
760: $r->print("(".$Apache::lonnet::domaindescription{$listname}.
761: ")");
762: }
763: $r->print (" $tabtag</tr></form>\n");
1.1 www 764: return OK;
1.17 harris41 765:
766: # display user directory
1.1 www 767: }
1.45 ng 768: if ($filecom[1] eq 'user') {
1.70 ng 769: $r->print("<tr valign=$valign bgcolor=$fileclr>$extrafield");
770: $r->print("<td nowrap>\n");
1.2 harris41 771: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 772: my $anchor = $curdir;
773: $anchor =~ s/\///g;
1.13 ng 774: &begin_form ($r,$curdir);
1.17 harris41 775: $r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
776: 'whitespace1.gif" border="0" />'."\n");
1.16 harris41 777: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 778: $r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
779: '.gif"');
780: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
781: "\n");
782: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
783: $iconpath.'quill.gif border="0" name="'.$msg.
784: '" height="22" /></a>');
1.60 albertel 785: my $domain=(split(m|/|,$startdir))[2];
786: my $plainname=&Apache::loncommon::plainname($listname,$domain);
787: $r->print ($listname);
788: if (defined($plainname) && $plainname) { $r->print(" ($plainname) "); }
789: $r->print ($tabtag.'</tr></form>'."\n");
1.1 www 790: return OK;
791: }
1.17 harris41 792:
1.1 www 793: # display file
1.45 ng 794: if ($fnptr == 0 and $filecom[3] ne '') {
1.47 ng 795: my $filelink = $startdir.$filecom[0];
1.77 www 796: next if &Apache::lonnet::metadata($filelink,'obsolete');
1.1 www 797: my @file_ext = split (/\./,$listname);
1.25 matthew 798: my $curfext = $file_ext[-1];
1.40 matthew 799: if (@Omit) {
800: foreach (@Omit) { return OK if ($curfext eq $_); }
801: }
802: if (@Only) {
803: my $skip = 1;
804: foreach (@Only) { $skip = 0 if ($curfext eq $_); }
805: return OK if ($skip > 0);
806: }
1.25 matthew 807: # Set the icon for the file
1.26 matthew 808: my $iconname = "unknown.gif";
1.28 harris41 809: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.25 matthew 810: # The unless conditional that follows is a bit of overkill
811: $iconname = $curfext.".gif" unless
1.26 matthew 812: (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn');
1.25 matthew 813: #
1.70 ng 814: $r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap>");
1.62 albertel 815: my $metafile = grep /^\Q$filecom[0]\E\.meta\&/, @list;
1.7 harris41 816: my $title;
817: if ($ENV{'form.catalogmode'} eq 'interactive') {
818: $title=$listname;
1.8 harris41 819: $title = &Apache::lonnet::metadata($filelink,'title')
820: if ($metafile == 1);
1.7 harris41 821: $title=$listname unless $title;
1.42 albertel 822: my $titleesc=HTML::Entities::encode($title);
823: $titleesc=~s/\'/\\'/; #' (clean up this spare quote)
1.35 matthew 824: $r->print("<a href=\"javascript:select_data(\'",
1.34 harris41 825: $titleesc,"','",$filelink,"')\">");
1.17 harris41 826: $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
827: "\n");
1.70 ng 828: $r->print("</td><td nowrap>");
1.8 harris41 829: }
830: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
831: $title=$listname;
832: $title = &Apache::lonnet::metadata($filelink,'title')
833: if ($metafile == 1);
834: $title=$listname unless $title;
1.42 albertel 835: my $titleesc=&HTML::Entities::encode($title);
1.8 harris41 836: $r->print("<form name='form$fnum'>\n");
837: $r->print("<input type='checkbox' name='filelink"."' ".
1.16 harris41 838: "value='$filelink' onClick='".
839: "javascript:queue(\"form$fnum\")' ");
840: if ($hash{'store_'.$filelink}) {
841: $r->print("checked");
842: }
843: $r->print(">\n");
1.8 harris41 844: $r->print("<input type='hidden' name='title"."' ".
1.42 albertel 845: "value='$titleesc'>\n");
1.8 harris41 846: $r->print("</form>\n");
1.70 ng 847: $r->print("</td><td nowrap>");
1.16 harris41 848: $hash{"pre_${fnum}_link"}=$filelink;
1.42 albertel 849: $hash{"pre_${fnum}_title"}=$titleesc;
1.8 harris41 850: $fnum++;
1.7 harris41 851: }
1.4 harris41 852:
1.12 ng 853: if ($indent > 0 and $indent < 11) {
1.17 harris41 854: $r->print("<img src=",$iconpath,"whitespace",$indent,
855: ".gif border='0' />\n");
1.11 ng 856: } elsif ($indent >0) {
1.4 harris41 857: my $ten = int($indent/10.);
858: my $rem = $indent%10.0;
859: my $count = 0;
860: while ($count < $ten) {
1.17 harris41 861: $r->print("<img src=",$iconpath,
862: "whitespace10.gif border='0' />\n");
1.1 www 863: $count++;
1.4 harris41 864: }
1.17 harris41 865: $r->print("<img src=",$iconpath,"whitespace",$rem,
866: ".gif border='0' />\n") if $rem > 0;
1.1 www 867: }
1.4 harris41 868:
1.25 matthew 869: $r->print("<img src=$iconpath$iconname border='0' />\n");
1.17 harris41 870: $r->print (" <a href=\"javascript:openWindow('".$filelink.
1.69 www 871: "', 'previewfile', '450', '500', 'no', 'yes','yes')\";".
1.17 harris41 872: " TARGET=_self>$listname</a> ");
873:
874: $r->print (" (<a href=\"javascript:openWindow('".$filelink.
1.71 ng 875: ".meta', 'metadatafile', '500', '550', 'no', 'yes','no')\"; ".
1.17 harris41 876: "TARGET=_self>metadata</a>) ") if ($metafile == 1);
1.2 harris41 877:
1.7 harris41 878: $r->print("</td>\n");
1.45 ng 879: if ($hash{'display_attrs_0'} == 1) {
1.70 ng 880: my $title = &Apache::lonnet::gettitle($filelink,'title')
1.45 ng 881: if ($metafile == 1);
1.70 ng 882: $r->print('<td> '.($title eq '' ? ' ' : $title).
1.45 ng 883: ' </td>'."\n");
884: }
1.70 ng 885: $r->print('<td align=right> ',
1.17 harris41 886: $filecom[8]," </td>\n")
1.45 ng 887: if $hash{'display_attrs_1'} == 1;
1.70 ng 888: $r->print('<td> '.
1.17 harris41 889: (localtime($filecom[9]))." </td>\n")
1.45 ng 890: if $hash{'display_attrs_2'} == 1;
1.70 ng 891: $r->print('<td> '.
1.17 harris41 892: (localtime($filecom[10]))." </td>\n")
1.45 ng 893: if $hash{'display_attrs_3'} == 1;
1.2 harris41 894:
1.45 ng 895: if ($hash{'display_attrs_4'} == 1) {
1.17 harris41 896: my $author = &Apache::lonnet::metadata($filelink,'author')
897: if ($metafile == 1);
1.70 ng 898: $r->print('<td> '.($author eq '' ? ' ' : $author).
1.17 harris41 899: " </td>\n");
1.2 harris41 900: }
1.45 ng 901: if ($hash{'display_attrs_5'} == 1) {
1.17 harris41 902: my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
903: if ($metafile == 1);
1.45 ng 904: # $keywords = ' ' if (!$keywords);
1.70 ng 905: $r->print('<td> '.($keywords eq '' ? ' ' : $keywords).
1.17 harris41 906: " </td>\n");
1.2 harris41 907: }
1.45 ng 908: if ($hash{'display_attrs_6'} == 1) {
1.17 harris41 909: my $lang = &Apache::lonnet::metadata($filelink,'language')
910: if ($metafile == 1);
1.28 harris41 911: $lang = &Apache::loncommon::languagedescription($lang);
1.70 ng 912: $r->print('<td> '.($lang eq '' ? ' ' : $lang).
1.17 harris41 913: " </td>\n");
1.2 harris41 914: }
1.63 ng 915: if ($hash{'display_attrs_7'} == 1) {
1.56 www 916: my $output='';
1.57 www 917: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
918: if ($embstyle eq 'ssi') {
1.61 www 919: $output=&Apache::lonnet::ssi_body($filelink);
1.56 www 920: $output='<font size="-2">'.$output.'</font>';
1.57 www 921: } elsif ($embstyle eq 'img') {
922: $output='<img src="'.$filelink.'" />';
1.58 www 923: } elsif ($filelink=~/^\/res\/(\w+)\/(\w+)\//) {
924: $output='<img src="http://'.
925: $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}.
926: '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
1.57 www 927: }
1.70 ng 928: $r->print('<td> '.($output eq '' ? ' ':$output).
1.56 www 929: " </td>\n");
930: }
1.70 ng 931: if ($hash{'display_attrs_8'} == 1) {
932: my (%stat) = &Apache::lonmeta::dynamicmeta($filelink) if ($metafile == 1);
1.71 ng 933: my $stat = (exists($stat{'course'}) ? $stat{'course'} : '').
934: ((exists($stat{'course'}) || exists($stat{'count'})) ? '/' : '').
935: (exists($stat{'count'}) ? $stat{'count'} : '');
1.70 ng 936: $r->print('<td align=center> '.($stat eq '' ? ' ' : $stat).
937: ' </td>'."\n");
938: }
939:
1.1 www 940: $r->print("</tr>\n");
941: }
1.17 harris41 942:
1.2 harris41 943: # -- display directory
1.1 www 944: if ($fnptr == $dirptr) {
945: my @file_ext = split (/\./,$listname);
946: my $curfext = $file_ext[scalar(@file_ext)-1];
1.2 harris41 947: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 948: my $anchor = $curdir;
949: $anchor =~ s/\///g;
1.63 ng 950: $r->print("<tr bgcolor=$fileclr>$extrafield<td valign=$valign>");
1.2 harris41 951: &begin_form ($r,$curdir);
1.4 harris41 952: my $indentm1 = $indent-1;
1.11 ng 953: if ($indentm1 < 11 and $indentm1 > 0) {
1.17 harris41 954: $r->print("<img src=",$iconpath,"whitespace",$indentm1,
955: ".gif border='0' />\n");
1.4 harris41 956: } else {
957: my $ten = int($indentm1/10.);
958: my $rem = $indentm1%10.0;
959: my $count = 0;
960: while ($count < $ten) {
1.17 harris41 961: $r->print ("<img src=",$iconpath
962: ,"whitespace10.gif border='0' />\n");
1.12 ng 963: $count++;
1.4 harris41 964: }
1.17 harris41 965: $r->print ("<img src=",$iconpath,"whitespace",$rem,
966: ".gif border='0' />\n") if $rem > 0;
1.1 www 967: }
1.16 harris41 968: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 969: $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
970: 'folder_pointer_'.$diropen.'.gif"');
971: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
972: "\n");
973: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
974: $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
975: "\n");
1.13 ng 976: $r->print ("$listname$tabtag</tr></form>\n");
1.1 www 977: }
1.2 harris41 978:
1.1 www 979: }
980:
1.14 harris41 981: # ------------------- prints the beginning of a form for directory or file link
1.1 www 982: sub begin_form {
983: my ($r,$uri) = @_;
1.3 harris41 984: my $anchor = $uri;
985: $anchor =~ s/\///g;
1.17 harris41 986: $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
987: '#'.$anchor.
988: '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
989: ',document.forms.fileattr.acts.value)" '.
1.16 harris41 990: 'enctype="application/x-www-form-urlencoded">'."\n");
1.17 harris41 991: $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
992: "\n");
993: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16 harris41 994: $dnum++;
1.17 harris41 995: }
996:
997: # --------- settings whenever the user causes the indexer window to be launched
998: sub start_fresh_session {
1.48 matthew 999: delete $hash{'form.catalogmode'};
1000: delete $hash{'form.mode'};
1001: delete $hash{'form.form'};
1002: delete $hash{'form.element'};
1003: delete $hash{'form.omit'};
1004: delete $hash{'form.only'};
1.27 harris41 1005: foreach (keys %hash) {
1.48 matthew 1006: delete $hash{$_} if (/^(pre_|store)/);
1.27 harris41 1007: }
1.1 www 1008: }
1009:
1.35 matthew 1010: # ------------------------------------------------------------------- setvalues
1011: sub setvalues {
1012: # setvalues is used in registerurl to synchronize the database
1013: # hash and environment hashes
1014: my ($H1,$h1key,$H2,$h2key) =@_;
1015: #
1016: if (exists $H2->{$h2key}) {
1017: $H1->{$h1key} = $H2->{$h2key};
1018: } elsif (exists $H1->{$h1key}) {
1019: $H2->{$h2key} = $H1->{$h1key};
1020: }
1021: }
1022:
1.1 www 1023: 1;
1.54 www 1024:
1025: sub cleanup {
1.55 www 1026: if (tied(%hash)){
1027: &Apache::lonnet::logthis('Cleanup indexer: hash');
1028: }
1.54 www 1029: }
1.23 harris41 1030:
1031: =head1 NAME
1032:
1033: Apache::lonindexer - mod_perl module for cross server filesystem browsing
1034:
1035: =head1 SYNOPSIS
1036:
1037: Invoked by /etc/httpd/conf/srm.conf:
1038:
1039: <LocationMatch "^/res.*/$">
1040: SetHandler perl-script
1041: PerlHandler Apache::lonindexer
1042: </LocationMatch>
1043:
1044: =head1 INTRODUCTION
1045:
1046: This module enables a scheme of browsing across a cross server.
1047:
1048: This is part of the LearningOnline Network with CAPA project
1049: described at http://www.lon-capa.org.
1050:
1051: =head1 BEGIN SUBROUTINE
1052:
1053: This routine is only run once after compilation.
1054:
1055: =over 4
1056:
1057: =item *
1058:
1059: Initializes %language hash table.
1060:
1061: =back
1062:
1063: =head1 HANDLER SUBROUTINE
1064:
1065: This routine is called by Apache and mod_perl.
1066:
1067: =over 4
1068:
1069: =item *
1070:
1071: read in machine configuration variables
1072:
1073: =item *
1074:
1075: see if called from an interactive mode
1076:
1077: =item *
1078:
1079: refresh environment with user database values (in %hash)
1080:
1081: =item *
1082:
1083: define extra fields and buttons in case of special mode
1084:
1085: =item *
1086:
1087: set catalogmodefunctions to have extra needed javascript functionality
1088:
1089: =item *
1090:
1091: print header
1092:
1093: =item *
1094:
1095: evaluate actions from previous page (both cumulatively and chronologically)
1096:
1097: =item *
1098:
1099: output title
1100:
1101: =item *
1102:
1103: get state of file attributes to be showing
1104:
1105: =item *
1106:
1107: output state of file attributes to be showing
1108:
1109: =item *
1110:
1111: output starting row to the indexed file/directory hierarchy
1112:
1113: =item *
1114:
1115: read in what directories have previously been set to "open"
1116:
1117: =item *
1118:
1119: if not at top level, provide an uplink arrow
1120:
1121: =item *
1122:
1123: recursively go through all the directories and output as appropriate
1124:
1125: =item *
1126:
1127: information useful for group import
1128:
1129: =item *
1130:
1131: end the tables
1132:
1133: =item *
1134:
1135: end the output and return
1136:
1137: =back
1138:
1139: =head1 OTHER SUBROUTINES
1140:
1141: =over 4
1142:
1143: =item *
1144:
1145: scanDir - recursive scan of a directory
1146:
1147: =item *
1148:
1149: get_list - get complete matched list based on the uri (returns an array)
1150:
1151: =item *
1152:
1153: match_ext - filters out files based on extensions (returns an array)
1154:
1155: =item *
1156:
1157: display_line - displays one line in appropriate table format
1158:
1159: =item *
1160:
1161: begin_form - prints the beginning of a form for directory or file link
1162:
1163: =item *
1164:
1165: start_fresh_session - settings whenever the user causes the indexer window
1166: to be launched
1167:
1168: =back
1169:
1170: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>