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

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

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