Annotation of loncom/interface/lonindexer.pm, revision 1.17

1.1       www         1: # The LearningOnline Network with CAPA
1.14      harris41    2: #
1.1       www         3: # Directory Indexer
1.14      harris41    4: #
1.17    ! harris41    5: # YEAR=1999
        !             6: # 5/21/99, 5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
1.1       www         7: # 11/23 Gerd Kortemeyer
1.17    ! harris41    8: # YEAR=2000
1.1       www         9: # 07/20-08/04 H.K. Ng
1.17    ! harris41   10: # YEAR=2001
1.2       harris41   11: # 05/9-05/19/2001 H. K. Ng
1.4       harris41   12: # 05/21/2001 H. K. Ng
1.6       harris41   13: # 05/23/2001 H. K. Ng
1.17    ! harris41   14: # 5/31,6/1,6/2,6/15 Scott Harrison
        !            15: # 6/26,7/8 H. K. Ng
        !            16: # 8/6,8/7,8/10 Scott Harrison
1.7       harris41   17: 
1.1       www        18: package Apache::lonindexer;
                     19: 
                     20: use strict;
                     21: use Apache::lonnet();
                     22: use Apache::Constants qw(:common);
1.2       harris41   23: use Apache::File;
                     24: use GDBM_File;
                     25: 
1.17    ! harris41   26: my %hash; # tied to a user-specific gdbm file
        !            27: my %dirs; # keys are directories, values are the open/close status
        !            28: my %language; # has the reference information present in language.tab
        !            29: 
        !            30: # ----- Values which are set by the handler subroutine and are accessible to
        !            31: # -----     other methods.
        !            32: my $extrafield; # default extra table cell
        !            33: my $fnum; # file counter
        !            34: my $dnum; # directory counter
        !            35: 
        !            36: # ---------------------------------------------------------------------- BEGIN
1.2       harris41   37: sub BEGIN {
1.14      harris41   38:     my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                     39: 			     '/language.tab');
1.2       harris41   40:     map {
                     41: 	$_=~/(\w+)\s+([\w\s\-]+)/;
                     42: 	$language{$1}=$2;
                     43:     } <$fh>;
                     44: }
1.1       www        45: 
1.17    ! harris41   46: # ---------------------------------------------------------------- Main Handler
1.1       www        47: sub handler {
                     48:     my $r = shift;
                     49:     $r->content_type('text/html');
                     50:     $r->send_http_header;
                     51:     return OK if $r->header_only;
1.9       harris41   52:     $fnum=0;
1.16      harris41   53:     $dnum=0;
1.17    ! harris41   54: 
        !            55: # --------------------------------------------- machine configuration variables
1.10      harris41   56:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1       www        57:     my $domain  = $r->dir_config('lonDefDomain');
                     58:     my $role    = $r->dir_config('lonRole');
                     59:     my $loadlim = $r->dir_config('lonLoadLim');
                     60:     my $servadm = $r->dir_config('lonAdmEMail');
                     61:     my $sysadm  = $r->dir_config('lonSysEMail');
                     62:     my $lonhost = $r->dir_config('lonHostID');
                     63:     my $tabdir  = $r->dir_config('lonTabDir');
                     64: 
1.7       harris41   65:     my $fileclr='#ffffe6';
1.15      harris41   66:     my $line;
                     67:     my (@attrchk,@openpath);
                     68:     my $uri=$r->uri;
                     69: 
1.7       harris41   70: # -------------------------------------- see if called from an interactive mode
1.17    ! harris41   71:     &get_unprocessed_cgi();
1.7       harris41   72: 
1.17    ! harris41   73:     my $closebutton='';
1.7       harris41   74:     my $groupimportbutton='';
                     75:     my $colspan=''; 
1.14      harris41   76: 
                     77:     $extrafield='';
1.17    ! harris41   78:     my $diropendb = 
        !            79: 	"/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
1.15      harris41   80: 
                     81:     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
                     82: 	if ($ENV{'form.launch'} eq '1') {
1.17    ! harris41   83: 	    &start_fresh_session();
1.15      harris41   84: 	}
1.17    ! harris41   85: 
        !            86: # -------------------- refresh environment with user database values (in %hash)
1.15      harris41   87: 	if ($hash{'mode_catalog'} eq 'interactive') {
                     88: 	    $ENV{'form.catalogmode'}='interactive';
                     89: 	}
                     90: 	if ($hash{'mode_catalog'} eq 'groupimport') {
                     91: 	    $ENV{'form.catalogmode'}='groupimport';
                     92: 	}
                     93: 
1.17    ! harris41   94: # --------------------- define extra fields and buttons in case of special mode
1.15      harris41   95: 	if ($ENV{'form.catalogmode'} eq 'interactive') {
                     96: 	    $hash{'mode_catalog'}='interactive';
                     97: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
                     98: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17    ! harris41   99: 		' border="0" /></td>';
1.15      harris41  100: 	    $colspan=" colspan='2' ";
                    101:             $closebutton=<<END;
1.7       harris41  102: <input type="button" name="close" value='CLOSE' onClick="self.close()">
                    103: END
1.16      harris41  104:         }
1.15      harris41  105: 	elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
                    106: 	    $hash{'mode_catalog'}='groupimport';
                    107: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
                    108: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17    ! harris41  109: 		' border="0" /></td>';
1.15      harris41  110: 	    $colspan=" colspan='2' ";
                    111:             $closebutton=<<END;
1.7       harris41  112: <input type="button" name="close" value='CLOSE' onClick="self.close()">
                    113: END
1.15      harris41  114:             $groupimportbutton=<<END;
1.17    ! harris41  115: <input type="button" name="groupimport" value='GROUP IMPORT'
        !           116: onClick="javascript:select_group()">
1.7       harris41  117: END
1.15      harris41  118:         }
1.7       harris41  119: 
1.17    ! harris41  120: # ------ set catalogmodefunctions to have extra needed javascript functionality
1.15      harris41  121: 	my $catalogmodefunctions='';
                    122: 	if ($ENV{'form.catalogmode'} eq 'interactive' or
                    123: 	    $ENV{'form.catalogmode'} eq 'groupimport') {
                    124: 	    $catalogmodefunctions=<<END;
1.7       harris41  125: function select_data(title,url) {
                    126:     changeTitle(title);
                    127:     changeURL(url);
1.8       harris41  128:     self.close();
                    129: }
                    130: function select_group() {
1.16      harris41  131:     window.location="/adm/groupsort?acts="+document.forms.fileattr.acts.value;
                    132: }
1.7       harris41  133: function changeTitle(val) {
                    134:     if (opener.inf.document.forms.resinfo.elements.t) {
                    135:         opener.inf.document.forms.resinfo.elements.t.value=val;
                    136:     }
                    137: }
                    138: function changeURL(val) {
                    139:     if (opener.inf.document.forms.resinfo.elements.u) {
                    140: 	opener.inf.document.forms.resinfo.elements.u.value=val;
                    141:     }
                    142: }
                    143: END
1.15      harris41  144:         }
1.16      harris41  145: 	if ($ENV{'form.catalogmode'} eq 'groupimport') {
                    146: 	    $catalogmodefunctions.=<<END;
                    147: var acts='';
                    148: function queue(val) {
                    149:     if (eval("document.forms."+val+".filelink.checked")) {
                    150: 	var l=val.length;
                    151: 	var v=val.substring(4,l);
                    152: 	document.forms.fileattr.acts.value+='1a'+v+'b';
                    153:     }
                    154:     else {
                    155: 	var l=val.length;
                    156: 	var v=val.substring(4,l);
                    157: 	document.forms.fileattr.acts.value+='0a'+v+'b';
                    158:     }
                    159: }
                    160: function rep_dirpath(suffix,val) {
                    161:     eval("document.forms.dirpath"+suffix+".acts.value=val");
                    162: }
                    163: END
                    164: 	}
1.17    ! harris41  165: 
1.1       www       166: # ---------------------------------------------------------------- Print Header
1.15      harris41  167: 	$r->print(<<ENDHEADER);
1.1       www       168: <html>
                    169: <head>
1.2       harris41  170: <title>The LearningOnline Network With CAPA Directory Browser</title>
1.3       harris41  171: 
1.14      harris41  172: <script language="javascript">
1.7       harris41  173: $catalogmodefunctions
1.2       harris41  174: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                    175:     var options = "width=" + w + ",height=" + h + ",";
                    176:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                    177:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                    178:     var newWin = window.open(url, wdwName, options);
                    179:     newWin.focus();
                    180: }
1.16      harris41  181: function gothere(val) {
                    182:     window.location=val+'?acts='+document.forms.fileattr.acts.value;
                    183: }
1.14      harris41  184: </script>
1.3       harris41  185: 
1.1       www       186: </head>
                    187: <body bgcolor="#FFFFFF">
                    188: ENDHEADER
1.17    ! harris41  189: 
        !           190: # - Evaluate actions from previous page (both cumulatively and chronologically)
1.16      harris41  191:         if ($ENV{'form.catalogmode'} eq 'groupimport') {
                    192: 	    my $acts=$ENV{'form.acts'};
                    193: 	    my @Acts=split(/b/,$acts);
                    194: 	    my %ahash;
                    195: 	    my %achash;
                    196: 	    my $ac=0;
1.17    ! harris41  197: 	    # some initial hashes for working with data
1.16      harris41  198: 	    map {
                    199: 		my ($state,$ref)=split(/a/);
                    200: 		$ahash{$ref}=$state;
                    201: 		$achash{$ref}=$ac;
                    202: 		$ac++;
                    203: 	    } (@Acts);
1.17    ! harris41  204: 	    # sorting through the actions and changing the tied database hash
1.16      harris41  205: 	    map {
                    206: 		my $key=$_;
                    207: 		if ($ahash{$key} eq '1') {
                    208: 		    $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
                    209: 			$hash{'pre_'.$key.'_title'};
                    210: 		    $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
                    211: 			$hash{'storectr'}+0;
                    212: 		    $hash{'storectr'}++;
                    213: 		}
                    214: 		if ($ahash{$key} eq '0') {
                    215: 		    if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
                    216: 			delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
                    217: 		    }
                    218: 		}
                    219: 	    } sort {$achash{$a}<=>$achash{$b}} (keys %ahash);
1.17    ! harris41  220: 	    # deleting the previously cached listing
1.16      harris41  221: 	    map {
                    222: 		if ($_ =~ /^pre_/ && $_ =~/link$/) {
                    223: 		    my $key = $_;
                    224: 		    $key =~ s/^pre_//;
                    225: 		    $key =~ s/_[^_]*$//;
                    226: 		    delete $hash{'pre_'.$key.'_title'};
                    227: 		    delete $hash{'pre_'.$key.'_link'};
                    228: 		}
                    229: 	    } keys %hash;
                    230: 	}
                    231: 	
1.17    ! harris41  232: # output title
        !           233: 	$r->print('<h2><font color="#888888">The LearningOnline With CAPA '.
        !           234: 		  'Network Directory Browser</font></h2>'."\n");
        !           235: # get state of file attributes to be showing
1.6       harris41  236: 	if ($ENV{'form.attrs'} ne "") {
                    237: 	    for (my $i=0; $i<=5; $i++) {
                    238: 		delete $hash{'display_attrs_'.$i};
                    239: 		if ($ENV{'form.attr'.$i} == 1) {
                    240: 		    $attrchk[$i] = "checked";
                    241: 		    $hash{'display_attrs_'.$i} = 1;
                    242: 		}
                    243: 	    }
                    244: 	} else {
                    245: 	    for (my $i=0; $i<=5; $i++) {
                    246: 		$attrchk[$i] = "checked" if $hash{'display_attrs_'.$i} == 1;
                    247: 	    }
                    248: 	}
1.17    ! harris41  249: # output state of file attributes to be showing
1.15      harris41  250: 	$r->print(<<END);
1.17    ! harris41  251: <b><font color="#666666">Display file attributes</font></b><br />
        !           252: <form method="post" name="fileattr" action="$uri"
        !           253:  enctype="application/x-www-form-urlencoded">
1.1       www       254: <table border=0><tr>
1.16      harris41  255: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> Size</td>
1.17    ! harris41  256: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Last
        !           257:  access</td>
        !           258: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last
        !           259:  modified</td>
1.1       www       260: </tr><tr>
1.16      harris41  261: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Author</td>
                    262: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Keywords</td>
                    263: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> Language</td>
1.1       www       264: </tr></table>
1.16      harris41  265: <input type="hidden" name="dirPointer" value="on" />
                    266: <input type="hidden" name="acts" value="" />
                    267: <input type="submit" name="attrs" value="Review" />&nbsp;
                    268: <input type="submit" name="attrs" value="Refresh" />
1.7       harris41  269: $closebutton
                    270: $groupimportbutton
1.1       www       271: </form>
                    272: END
                    273: 
1.17    ! harris41  274:     # output starting row to the indexed file/directory hierarchy
1.15      harris41  275:         my $titleclr="#ddffff";
                    276:         $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
                    277: 	$r->print("<table border=0><tr>\n");
                    278: 	$r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
1.17    ! harris41  279: 	$r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) ".
        !           280: 		  "</b></td>\n") if ($hash{'display_attrs_0'} == 1);
        !           281: 	$r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n") 
        !           282: 	    if ($hash{'display_attrs_1'} == 1);
        !           283: 	$r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n")
        !           284: 	    if ($hash{'display_attrs_2'} == 1);
        !           285: 	$r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n")
        !           286: 	    if ($hash{'display_attrs_3'} == 1);
        !           287: 	$r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n")
        !           288: 	    if ($hash{'display_attrs_4'} == 1);
        !           289: 	$r->print("<td bgcolor=$titleclr><b>Language</b></td>\n")
        !           290: 	    if ($hash{'display_attrs_5'} == 1);
1.15      harris41  291: 	$r->print("</tr>");
1.5       harris41  292: 
1.17    ! harris41  293: 	# read in what directories have previously been set to "open"
1.4       harris41  294: 	map {
                    295: 	    if ($_ =~ /^diropen_status_/) {
                    296: 		my $key = $_;
                    297: 		$key =~ s/^diropen_status_//;
                    298: 		$dirs{$key} = $hash{$_};
                    299: 	    }
                    300: 	} keys %hash;
                    301: 
1.2       harris41  302: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
                    303: 	    my $uri=$ENV{'form.openuri'};
1.4       harris41  304: 	    if (exists($hash{'diropen_status_'.$uri})) {
                    305: 		my $cursta = $hash{'diropen_status_'.$uri};
1.2       harris41  306: 		$dirs{$uri} = 'open';
1.4       harris41  307: 		$hash{'diropen_status_'.$uri} = 'open';
                    308: 		if ($cursta eq 'open') {
                    309: 		    $dirs{$uri} = 'closed';
                    310: 		    $hash{'diropen_status_'.$uri} = 'closed';
                    311: 		}
1.2       harris41  312: 	    } else {
1.4       harris41  313: 		$hash{'diropen_status_'.$uri} = 'open';
1.2       harris41  314: 		$dirs{$uri} = 'open';
                    315: 	    }
                    316: 	}
1.12      ng        317: 	
                    318: 	my $bredir = $ENV{'form.dirPointer'};
                    319: 	my $toplevel;
1.13      ng        320: 	my $indent = 0;
1.12      ng        321: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
1.17    ! harris41  322: 
1.13      ng        323: 	if ($bredir ne "on") {
1.12      ng        324: 	    $hash{'top.level'} = $uri;
                    325: 	    $toplevel = $uri;
1.13      ng        326: 
                    327: 	} else {
                    328: 	    $toplevel = $hash{'top.level'};
                    329: 	}
1.17    ! harris41  330: 
        !           331: 	# if not at top level, provide an uplink arrow
1.13      ng        332: 	if ($toplevel ne "/res/"){
                    333: 	    my (@uri_com) = split(/\//,$uri);
                    334: 	    pop @uri_com;
                    335: 	    my $upone = join('/',@uri_com);
                    336: 	    my @list = qw (0);
                    337: 	    &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
                    338: 	    $indent = 1;
1.12      ng        339: 	}
1.17    ! harris41  340: 
        !           341: 	# recursively go through all the directories and output as appropriate
1.16      harris41  342: 	&scanDir ($r,$toplevel,$indent,\%hash);
1.12      ng        343: 	
1.17    ! harris41  344: 	# information useful for group import
1.8       harris41  345: 	$r->print("<form name='fnum'>");
                    346: 	$r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
1.17    ! harris41  347: 
        !           348: 	# end the tables
1.2       harris41  349: 	$r->print("</table>");
                    350: 	$r->print("</td></tr></table>");
1.17    ! harris41  351: 
        !           352: 	# end the output and return
1.2       harris41  353: 	$r->print("</body></html>\n");
1.4       harris41  354: 	untie(%hash);
1.2       harris41  355:     } else {
1.17    ! harris41  356: 	$r->print('<html><head></head><body>Unable to tie hash to db '.
        !           357: 		  'file</body></html>');
        !           358: 	return OK;
1.2       harris41  359:     }
1.1       www       360:     return OK;
                    361: }
1.2       harris41  362: 
1.6       harris41  363: 
1.17    ! harris41  364: # ----------------------------------------------- recursive scan of a directory
1.2       harris41  365: sub scanDir {
1.16      harris41  366:     my ($r,$startdir,$indent,$hashref)=@_;
1.3       harris41  367:     my ($compuri,$curdir);
                    368:     my $dirptr=16384;
1.1       www       369:     $indent++;
                    370: 
1.2       harris41  371:     my %dupdirs = %dirs;
                    372:     my @list=&get_list($r,$startdir);
                    373:     foreach my $line (@list) {
1.5       harris41  374: 	my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5); 
1.4       harris41  375: 	next if $strip =~ /.*\.meta$/;
1.5       harris41  376: 	if ($dom eq "domain") {
1.17    ! harris41  377: 	    $compuri = join('',$strip,"/");  # dom list has /res/<domain name>
1.3       harris41  378: 	    $curdir = $compuri;
1.2       harris41  379: 	} else {
1.17    ! harris41  380: 	    # user, dir & file have name only, i.e., w/o path
        !           381: 	    $compuri = join('',$startdir,$strip,"/");
1.3       harris41  382: 	    $curdir = $startdir;
1.2       harris41  383: 	}
1.11      ng        384: 	my $diropen = "closed";
1.5       harris41  385: 	if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
1.3       harris41  386: 	    while (my ($key,$val)= each %dupdirs) {
1.5       harris41  387: 		if ($key eq $compuri and $val eq "open") {
1.11      ng        388: 		    $diropen = "opened";
1.5       harris41  389: 		    delete $dupdirs{key},$dirs{$key};
                    390: 		}
1.3       harris41  391: 	    }
1.1       www       392: 	}
1.16      harris41  393: 	&display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
1.11      ng        394: 	&scanDir ($r,$compuri,$indent) if $diropen eq "opened";
1.1       www       395:     }
                    396:     $indent--;
                    397: }
                    398: 
1.17    ! harris41  399: # --------------- get complete matched list based on the uri (returns an array)
1.1       www       400: sub get_list {
                    401:     my ($r,$uri)=@_;
                    402:     my @list;
1.2       harris41  403:     my $luri = $uri;
                    404:     $luri =~ s/\//_/g;
                    405: 
1.6       harris41  406:     if ($ENV{'form.attrs'} eq "Refresh") {
1.4       harris41  407: 	map {
                    408: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
                    409: 	    } keys %hash;
1.2       harris41  410:     }
                    411: 
1.4       harris41  412:     if ($hash{'dirlist_files'.$luri}) {
                    413: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.1       www       414:     } else {
1.4       harris41  415: 	@list = &Apache::lonnet::dirlist($uri);
                    416: 	$hash{'dirlist_files_'.$luri} = join('\n',@list);
1.1       www       417:     }
                    418:     return @list=&match_ext($r,@list);
                    419: }
                    420: 
1.17    ! harris41  421: # -------------------- filters out files based on extensions (returns an array)
1.1       www       422: sub match_ext {
                    423:     my ($r,@packlist)=@_;
                    424:     my @trimlist;
                    425:     my $nextline;
                    426:     my @fileext;
                    427:     my $dirptr=16384;
                    428: 
                    429:     my $tabdir  = $r->dir_config('lonTabDir');
1.12      ng        430:     my $fn = $tabdir.'/filetypes.tab';
1.1       www       431:     if (-e $fn) {
                    432: 	my $FH=Apache::File->new($fn);
                    433: 	my @content=<$FH>;
1.2       harris41  434: 	foreach my $line (@content) {
1.1       www       435: 	    (my $ext,my $foo) = split /\s+/,$line;
                    436: 	    push @fileext,$ext;
                    437: 	}
                    438:     }
1.2       harris41  439:     foreach my $line (@packlist) {
                    440: 	chomp $line;
                    441: 	$line =~ s/^\/home\/httpd\/html//;
                    442: 	my @unpackline = split (/\&/,$line);
                    443: 	next if ($unpackline[0] eq ".");
                    444: 	next if ($unpackline[0] eq "..");
                    445: 	my @filecom = split (/\./,$unpackline[0]);
                    446: 	my $fext = pop(@filecom);
                    447: 	my $fnptr = $unpackline[3]&$dirptr;
                    448:  	if ($fnptr == 0 and $unpackline[3] ne "") {
                    449: 	    foreach my $nextline (@fileext) {
                    450: 		push @trimlist,$line if $nextline eq $fext;
1.1       www       451: 	    }
                    452: 	} else {
1.2       harris41  453: 	    push @trimlist,$line;
1.1       www       454: 	}
                    455:     }
1.4       harris41  456:     @trimlist = sort (@trimlist);
1.1       www       457:     return @trimlist;
                    458: }
                    459: 
1.17    ! harris41  460: # ------------------------------- displays one line in appropriate table format
1.1       www       461: sub display_line{
1.16      harris41  462:     my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
1.1       www       463:     my (@pathfn, $fndir, $fnptr);
                    464:     my $dirptr=16384;
                    465:     my $fileclr="#ffffe6";
1.10      harris41  466:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1       www       467: 
                    468:     my @filecom = split (/\&/,$line);
                    469:     my @pathcom = split (/\//,$filecom[0]);
                    470:     my $listname = $pathcom[scalar(@pathcom)-1];
                    471:     my $fnptr = $filecom[3]&$dirptr;
1.4       harris41  472:     my $msg = 'View '.$filecom[0].' resources';
1.11      ng        473:     $msg = 'Close '.$filecom[0].' directory' if $diropen eq "opened";
1.1       www       474: 
                    475:     my $tabtag="</td>";
                    476:     my $i=0;
                    477: 
                    478:     while ($i<=5) {
1.17    ! harris41  479: 	$tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,">&nbsp;</td>")
        !           480: 	    if $hash{'display_attrs_'.$i} == 1;
1.1       www       481: 	$i++;
                    482:     }
1.17    ! harris41  483: 
        !           484: # display uplink arrow
1.13      ng        485:     if ($filecom[1] eq "viewOneUp") {
                    486: 	$r->print("<tr>$extrafield");
                    487: 	$r->print("<td bgcolor=$fileclr valign=bottom>\n");
1.16      harris41  488: 	$r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
                    489: 		   '/" '.
1.17    ! harris41  490: 		   'onSubmit="return rep_dirpath(\'UP\','.
        !           491: 		   'document.forms.fileattr.acts.value)" '.
1.16      harris41  492: 		   'enctype="application/x-www-form-urlencoded"'.
                    493:                    '>'."\n");
1.17    ! harris41  494: 	$r->print ('<input type=hidden name=openuri value="'.
        !           495: 		   $startdir.'">'."\n");
1.16      harris41  496: 	$r->print ('<input type="hidden" name="acts" value="">'."\n");
1.13      ng        497: 	$r->print ('<input src="'.$iconpath.'arrow_up.gif"');
1.17    ! harris41  498: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
        !           499: 		   "\n");
1.13      ng        500: 	$r->print("Up $tabtag</tr></form>\n");
                    501: 	return OK;
                    502:     }
1.17    ! harris41  503: 
        !           504: # display domain
1.1       www       505:     if ($filecom[1] eq "domain") {
1.17    ! harris41  506: 	$r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
        !           507: 	    if ($ENV{'form.dirPointer'} eq "on");
1.7       harris41  508: 	$r->print("<tr>$extrafield");
1.1       www       509: 	$r->print("<td bgcolor=$fileclr valign=bottom>");
1.2       harris41  510: 	&begin_form ($r,$filecom[0].'/');
1.3       harris41  511: 	my $anchor = $filecom[0].'/';
                    512: 	$anchor =~ s/\///g;
1.13      ng        513: 	$r->print ('<a name="'.$anchor.'">');
1.16      harris41  514: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17    ! harris41  515: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.
        !           516: 		   $diropen.'.gif"'); 
        !           517: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
        !           518: 		   "\n");
        !           519: 	$r->print ('<a href="javascript:gothere(\''.$filecom[0].
        !           520: 		   '/\')"><img src="'.$iconpath.'server.gif"');
        !           521: 	$r->print (' border="0" /></a>'."\n");
1.1       www       522: 	$r->print("Domain - $listname $tabtag</tr></form>\n");
                    523: 	return OK;
1.17    ! harris41  524: 
        !           525: # display user directory
1.1       www       526:     }
                    527:     if ($filecom[1] eq "user") {
1.7       harris41  528: 	$r->print("<tr>$extrafield");
1.13      ng        529: 	$r->print("<td bgcolor=$fileclr valign=bottom nowrap>\n");
1.2       harris41  530: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  531: 	my $anchor = $curdir;
                    532: 	$anchor =~ s/\///g;
1.13      ng        533: 	&begin_form ($r,$curdir);
1.17    ! harris41  534: 	$r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
        !           535: 		   'whitespace1.gif" border="0" />'."\n");
1.16      harris41  536: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17    ! harris41  537: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
        !           538: 		   '.gif"'); 
        !           539: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
        !           540: 		   "\n");
        !           541: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
        !           542: 		   $iconpath.'quill.gif border="0" name="'.$msg.
        !           543: 		   '" height="22" /></a>');
1.13      ng        544: 	$r->print ($listname.$tabtag.'</tr></form>'."\n");
1.1       www       545: 	return OK;
                    546:     }
1.17    ! harris41  547: 
1.1       www       548: # display file
                    549:     if ($fnptr == 0 and $filecom[3] ne "") {
                    550: 	my @file_ext = split (/\./,$listname);
                    551: 	my $curfext = $file_ext[scalar(@file_ext)-1];
1.2       harris41  552: 	my $filelink = $startdir.$filecom[0];
1.8       harris41  553: 	$r->print("<tr><td nowrap valign='bottom' bgcolor=$fileclr>");
1.7       harris41  554: 	my $metafile = grep /^$filecom[0]\.meta\&/, @list;
                    555: 	my $title;
                    556:         if ($ENV{'form.catalogmode'} eq 'interactive') {
                    557: 	    $title=$listname;
1.8       harris41  558: 	    $title = &Apache::lonnet::metadata($filelink,'title')
                    559: 		if ($metafile == 1);
1.7       harris41  560: 	    $title=$listname unless $title;
                    561: 	    $r->print("<a href='javascript:select_data(\"",
                    562: 	              $title,'","',$filelink,"\")'>");
1.17    ! harris41  563: 	    $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
        !           564: 		      "\n");
1.8       harris41  565: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
                    566: 	}
                    567:         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
                    568: 	    $title=$listname;
                    569: 	    $title = &Apache::lonnet::metadata($filelink,'title')
                    570: 		if ($metafile == 1);
                    571: 	    $title=$listname unless $title;
                    572: 	    $r->print("<form name='form$fnum'>\n");
                    573: 	    $r->print("<input type='checkbox' name='filelink"."' ".
1.16      harris41  574: 		      "value='$filelink' onClick='".
                    575: 		      "javascript:queue(\"form$fnum\")' ");
                    576: 	    if ($hash{'store_'.$filelink}) {
                    577: 		$r->print("checked");
                    578: 	    }
                    579: 	    $r->print(">\n");
1.8       harris41  580: 	    $r->print("<input type='hidden' name='title"."' ".
                    581: 		      "value='$title'>\n");
                    582: 	    $r->print("</form>\n");
                    583: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
1.16      harris41  584: 	    $hash{"pre_${fnum}_link"}=$filelink;
                    585: 	    $hash{"pre_${fnum}_title"}=$title;
1.8       harris41  586:   	    $fnum++;
1.7       harris41  587: 	}
1.4       harris41  588: 
1.12      ng        589: 	if ($indent > 0 and $indent < 11) {
1.17    ! harris41  590: 	    $r->print("<img src=",$iconpath,"whitespace",$indent,
        !           591: 		      ".gif border='0' />\n");
1.11      ng        592: 	} elsif ($indent >0) {
1.4       harris41  593: 	    my $ten = int($indent/10.);
                    594: 	    my $rem = $indent%10.0;
                    595: 	    my $count = 0;
                    596: 	    while ($count < $ten) {
1.17    ! harris41  597: 		$r->print("<img src=",$iconpath,
        !           598: 			  "whitespace10.gif border='0' />\n");
1.1       www       599: 	    $count++;
1.4       harris41  600: 	    }
1.17    ! harris41  601: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,
        !           602: 		      ".gif border='0' />\n") if $rem > 0;
1.1       www       603: 	}
1.4       harris41  604: 
1.17    ! harris41  605: 	$r->print("<img src=$iconpath$curfext.gif border='0' />\n");
        !           606: 	$r->print (" <a href=\"javascript:openWindow('".$filelink.
        !           607: 		   "', 'metadatafile', '450', '500', 'no', 'yes')\";".
        !           608: 		   " TARGET=_self>$listname</a> ");
        !           609: 
        !           610: 	$r->print (" (<a href=\"javascript:openWindow('".$filelink.
        !           611: 		   ".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; ".
        !           612: 		   "TARGET=_self>metadata</a>) ") if ($metafile == 1);
1.2       harris41  613: 
1.7       harris41  614: 	$r->print("</td>\n");
1.17    ! harris41  615: 	$r->print("<td bgcolor=$fileclr align=right valign=bottom> ",
        !           616: 		  $filecom[8]," </td>\n") 
1.11      ng        617: 	    if $hash{'display_attrs_0'} == 1;
1.17    ! harris41  618: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".
        !           619: 		  (localtime($filecom[9]))." </td>\n") 
1.11      ng        620: 	    if $hash{'display_attrs_1'} == 1;
1.17    ! harris41  621: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".
        !           622: 		  (localtime($filecom[10]))." </td>\n") 
1.11      ng        623: 	    if $hash{'display_attrs_2'} == 1;
1.2       harris41  624: 
1.6       harris41  625: 	if ($hash{'display_attrs_3'} == 1) {
1.17    ! harris41  626: 	    my $author = &Apache::lonnet::metadata($filelink,'author')
        !           627: 		if ($metafile == 1);
1.2       harris41  628: 	    $author = '&nbsp;' if (!$author);
1.17    ! harris41  629: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$author.
        !           630: 		      " </td>\n");
1.2       harris41  631: 	}
1.6       harris41  632: 	if ($hash{'display_attrs_4'} == 1) {
1.17    ! harris41  633: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
        !           634: 		if ($metafile == 1);
1.2       harris41  635: 	    $keywords = '&nbsp;' if (!$keywords);
1.17    ! harris41  636: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords.
        !           637: 		      " </td>\n");
1.2       harris41  638: 	}
1.6       harris41  639: 	if ($hash{'display_attrs_5'} == 1) {
1.17    ! harris41  640: 	    my $lang = &Apache::lonnet::metadata($filelink,'language')
        !           641: 		if ($metafile == 1);
1.2       harris41  642: 	    $lang = $language{$lang};
                    643: 	    $lang = '&nbsp;' if (!$lang);
1.17    ! harris41  644: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang.
        !           645: 		      " </td>\n");
1.2       harris41  646: 	}
1.1       www       647: 	$r->print("</tr>\n");
                    648:     }
1.17    ! harris41  649: 
1.2       harris41  650: # -- display directory
1.1       www       651:     if ($fnptr == $dirptr) {
                    652: 	my @file_ext = split (/\./,$listname);
                    653: 	my $curfext = $file_ext[scalar(@file_ext)-1];
1.2       harris41  654: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  655: 	my $anchor = $curdir;
                    656: 	$anchor =~ s/\///g;
1.7       harris41  657: 	$r->print("<tr>$extrafield<td bgcolor=$fileclr valign=bottom>");
1.2       harris41  658: 	&begin_form ($r,$curdir);
1.4       harris41  659: 	my $indentm1 = $indent-1;
1.11      ng        660: 	if ($indentm1 < 11 and $indentm1 > 0) {
1.17    ! harris41  661: 	    $r->print("<img src=",$iconpath,"whitespace",$indentm1,
        !           662: 		      ".gif border='0' />\n");
1.4       harris41  663: 	} else {
                    664: 	    my $ten = int($indentm1/10.);
                    665: 	    my $rem = $indentm1%10.0;
                    666: 	    my $count = 0;
                    667: 	    while ($count < $ten) {
1.17    ! harris41  668: 		$r->print ("<img src=",$iconpath
        !           669: 			   ,"whitespace10.gif border='0' />\n");
1.12      ng        670: 		$count++;
1.4       harris41  671: 	    }
1.17    ! harris41  672: 	    $r->print ("<img src=",$iconpath,"whitespace",$rem,
        !           673: 		       ".gif border='0' />\n") if $rem > 0;
1.1       www       674: 	}
1.16      harris41  675: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17    ! harris41  676: 	$r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
        !           677: 		   'folder_pointer_'.$diropen.'.gif"');
        !           678: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
        !           679: 		   "\n");
        !           680: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
        !           681: 		   $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
        !           682: 		   "\n");
1.13      ng        683: 	$r->print ("$listname$tabtag</tr></form>\n");
1.1       www       684:     }
1.2       harris41  685: 
1.1       www       686: }
                    687: 
1.14      harris41  688: # ------------------- prints the beginning of a form for directory or file link
1.1       www       689: sub begin_form {
                    690:     my ($r,$uri) = @_;
1.3       harris41  691:     my $anchor = $uri;
                    692:     $anchor =~ s/\///g;
1.17    ! harris41  693:     $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
        !           694: 	       '#'.$anchor.
        !           695: 	       '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
        !           696: 	       ',document.forms.fileattr.acts.value)" '.
1.16      harris41  697: 	       'enctype="application/x-www-form-urlencoded">'."\n");
1.17    ! harris41  698:     $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
        !           699: 	       "\n");
        !           700:     $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16      harris41  701:     $dnum++;
1.17    ! harris41  702: }
        !           703: 
        !           704: # ----------- grab unprocessed CGI variables that may have been appended to URL
        !           705: sub get_unprocessed_cgi {
        !           706:     map {
        !           707:        my ($name, $value) = split(/=/,$_);
        !           708:        $value =~ tr/+/ /;
        !           709:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
        !           710:        if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') {
        !           711:            $ENV{'form.'.$name}=$value;
        !           712:        }
        !           713:     } (split(/&/,$ENV{'QUERY_STRING'}));
        !           714: }
        !           715: 
        !           716: # --------- settings whenever the user causes the indexer window to be launched
        !           717: sub start_fresh_session {
        !           718:     delete $hash{'mode_catalog'};
        !           719:     map {
        !           720: 	if ($_ =~ /^pre_/) {
        !           721: 	    delete $hash{$_};
        !           722: 	}
        !           723: 	if ($_ =~ /^store/) {
        !           724: 	    delete $hash{$_};
        !           725: 	}
        !           726:     } keys %hash;    
1.1       www       727: }
                    728: 
                    729: 1;
                    730: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>