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