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