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