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