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