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