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

1.1       www         1: # The LearningOnline Network with CAPA
1.14      harris41    2: #
1.1       www         3: # Directory Indexer
                      4: # (Login Screen
1.14      harris41    5: #
1.1       www         6: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
                      7: # 11/23 Gerd Kortemeyer
                      8: # 07/20-08/04 H.K. Ng
                      9: #
1.2       harris41   10: # 05/9-05/19/2001 H. K. Ng
1.4       harris41   11: # 05/21/2001 H. K. Ng
1.6       harris41   12: # 05/23/2001 H. K. Ng
1.7       harris41   13: # 05/31/2001 Scott Harrison
1.9       harris41   14: # 06/01/2001 Scott Harrison
                     15: # 06/02/2001 Scott Harrison
1.10      harris41   16: # 06/15/2001 Scott Harrison
1.12      ng         17: # 06/26/2001 H. K. Ng
1.13      ng         18: # 07/08/2001 H. K. Ng
1.7       harris41   19: 
1.1       www        20: package Apache::lonindexer;
                     21: 
                     22: use strict;
                     23: use Apache::lonnet();
                     24: use Apache::Constants qw(:common);
1.2       harris41   25: use Apache::File;
                     26: use GDBM_File;
                     27: 
1.4       harris41   28: my %hash;
1.2       harris41   29: my %dirs;
                     30: my %language;
1.7       harris41   31: my $hidden;
                     32: my $extrafield;
1.9       harris41   33: my $fnum;
1.2       harris41   34: sub BEGIN {
1.14      harris41   35:     my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                     36: 			     '/language.tab');
1.2       harris41   37:     map {
                     38: 	$_=~/(\w+)\s+([\w\s\-]+)/;
                     39: 	$language{$1}=$2;
                     40:     } <$fh>;
                     41: }
1.1       www        42: 
                     43: sub handler {
                     44:     my $r = shift;
                     45:     $r->content_type('text/html');
                     46:     $r->send_http_header;
                     47:     return OK if $r->header_only;
1.9       harris41   48:     $fnum=0;
1.10      harris41   49:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1       www        50:     my $domain  = $r->dir_config('lonDefDomain');
                     51:     my $role    = $r->dir_config('lonRole');
                     52:     my $loadlim = $r->dir_config('lonLoadLim');
                     53:     my $servadm = $r->dir_config('lonAdmEMail');
                     54:     my $sysadm  = $r->dir_config('lonSysEMail');
                     55:     my $lonhost = $r->dir_config('lonHostID');
                     56:     my $tabdir  = $r->dir_config('lonTabDir');
                     57: 
1.7       harris41   58:     my $fileclr='#ffffe6';
1.15    ! harris41   59:     my $line;
        !            60:     my (@attrchk,@openpath);
        !            61:     my $uri=$r->uri;
        !            62: 
1.7       harris41   63: # -------------------------------------- see if called from an interactive mode
                     64:     map {
                     65:        my ($name, $value) = split(/=/,$_);
                     66:        $value =~ tr/+/ /;
                     67:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                     68:        if ($name eq 'catalogmode') {
                     69:            $ENV{'form.'.$name}=$value;
1.15    ! harris41   70:        }
        !            71:        if ($name eq 'launch') {
        !            72:            $ENV{'form.'.$name}=$value;
        !            73:        }
1.7       harris41   74:     } (split(/&/,$ENV{'QUERY_STRING'}));
                     75: 
                     76:     $hidden=''; my $closebutton='';
                     77:     my $groupimportbutton='';
                     78:     my $colspan=''; 
1.14      harris41   79: 
                     80:     $extrafield='';
1.15    ! harris41   81:     my $diropendb = "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
        !            82: 
        !            83:     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
        !            84: 	if ($ENV{'form.launch'} eq '1') {
        !            85: 	    delete $hash{'mode_catalog'};
        !            86: 	}
        !            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: 
        !            94: 	if ($ENV{'form.catalogmode'} eq 'interactive') {
        !            95: 	    $hash{'mode_catalog'}='interactive';
        !            96: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
        !            97: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
        !            98: 		' border="0"></td>';
        !            99: 	    $colspan=" colspan='2' ";
        !           100: 	    $hidden=<<END;
1.7       harris41  101: <input type='hidden' name='catalogmode' value='interactive'>
                    102: END
1.15    ! harris41  103:             $closebutton=<<END;
1.7       harris41  104: <input type="button" name="close" value='CLOSE' onClick="self.close()">
                    105: END
1.15    ! harris41  106:          }
        !           107: 	elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
        !           108: 	    $hash{'mode_catalog'}='groupimport';
        !           109: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
        !           110: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
        !           111: 		' border="0"></td>';
        !           112: 	    $colspan=" colspan='2' ";
        !           113: 	    $hidden=<<END;
1.7       harris41  114: <input type='hidden' name='catalogmode' value='groupimport'>
                    115: END
1.15    ! harris41  116:             $closebutton=<<END;
1.7       harris41  117: <input type="button" name="close" value='CLOSE' onClick="self.close()">
                    118: END
1.15    ! harris41  119:             $groupimportbutton=<<END;
1.8       harris41  120: <input type="button" name="groupimport" value='GROUP IMPORT' onClick="javascript:select_group()">
1.7       harris41  121: END
1.15    ! harris41  122:         }
1.7       harris41  123: 
1.15    ! harris41  124: 	my $catalogmodefunctions='';
        !           125: 	if ($ENV{'form.catalogmode'} eq 'interactive' or
        !           126: 	    $ENV{'form.catalogmode'} eq 'groupimport') {
        !           127: 	    $catalogmodefunctions=<<END;
1.7       harris41  128: function select_data(title,url) {
                    129:     changeTitle(title);
                    130:     changeURL(url);
1.8       harris41  131:     self.close();
                    132: }
                    133: function save_group() {
                    134:     for (var num=0; num<document.forms.fnum.fnum.value; num++) {
                    135: 	if (eval("document.forms.form"+num+".filelink.checked")) {
                    136: 	    alert(eval("document.forms.form"+num+".title.value")+
                    137: 		       eval("document.forms.form"+num+".filelink.value"));
                    138: 	}
                    139:     }
                    140: }
                    141: function select_group() {
1.9       harris41  142:     var linkflag=false;
1.8       harris41  143:     for (var num=0; num<document.forms.fnum.fnum.value; num++) {
                    144: 	if (eval("document.forms.form"+num+".filelink.checked")) {
1.9       harris41  145: //	    alert(eval("document.forms.form"+num+".title.value")+
                    146: //		       eval("document.forms.form"+num+".filelink.value"));
                    147: 	    insertRowInLastRow();
                    148: 	    placeResourceInLastRow(
                    149: 		   eval("document.forms.form"+num+".title.value"),
                    150: 		   eval("document.forms.form"+num+".filelink.value"),
                    151: 		   linkflag
                    152: 				   );
                    153: 	    linkflag=true;
1.8       harris41  154: 	}
                    155:     }
1.9       harris41  156:     opener.editmode=0;
                    157:     opener.notclear=0;
                    158:     opener.linkmode=0;
                    159:     opener.infoclear();
                    160:     opener.draw();
                    161: }
                    162: function insertRowInLastRow() {
                    163:     opener.insertrow(opener.maxrow);
                    164:     opener.addobj(opener.maxrow,'e&2');
                    165: }
                    166: function placeResourceInLastRow (title,url,linkflag) {
                    167:     opener.newresource(opener.maxrow,2,opener.escape(title),opener.escape(url),'false','normal');
                    168:     opener.save();
                    169:     opener.mostrecent=opener.obj.length-1;
                    170:     if (linkflag) {
                    171: 	opener.joinres(opener.linkmode,opener.mostrecent,0);
                    172:     }
                    173:     opener.linkmode=opener.mostrecent;
1.7       harris41  174: }
                    175: function changeTitle(val) {
                    176:     if (opener.inf.document.forms.resinfo.elements.t) {
                    177:         opener.inf.document.forms.resinfo.elements.t.value=val;
                    178:     }
                    179: }
                    180: function changeURL(val) {
                    181:     if (opener.inf.document.forms.resinfo.elements.u) {
                    182: 	opener.inf.document.forms.resinfo.elements.u.value=val;
                    183:     }
                    184: }
                    185: END
1.15    ! harris41  186:         }
1.7       harris41  187: 
1.1       www       188: # ---------------------------------------------------------------- Print Header
1.15    ! harris41  189: 	$r->print(<<ENDHEADER);
1.1       www       190: <html>
                    191: <head>
1.2       harris41  192: <title>The LearningOnline Network With CAPA Directory Browser</title>
1.3       harris41  193: 
1.14      harris41  194: <script language="javascript">
1.7       harris41  195: $catalogmodefunctions
1.2       harris41  196: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                    197:     var options = "width=" + w + ",height=" + h + ",";
                    198:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                    199:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                    200:     var newWin = window.open(url, wdwName, options);
                    201:     newWin.focus();
                    202: }
1.14      harris41  203: </script>
1.3       harris41  204: 
1.1       www       205: </head>
                    206: <body bgcolor="#FFFFFF">
                    207: ENDHEADER
                    208: 
1.15    ! harris41  209: 	$r->print('<h2><font color="#888888">The LearningOnline With CAPA Network Directory Browser</font></h2>'."\n");
        !           210:     }
        !           211:     else {
        !           212: 	$r->print('<html><head></head><body>Unable to tie hash to db file</body></html>');
        !           213: 	return OK;
        !           214:     }
        !           215:     untie %hash;
1.11      ng        216:     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
1.6       harris41  217: 
                    218: 	if ($ENV{'form.attrs'} ne "") {
                    219: 	    for (my $i=0; $i<=5; $i++) {
                    220: 		delete $hash{'display_attrs_'.$i};
                    221: 		if ($ENV{'form.attr'.$i} == 1) {
                    222: 		    $attrchk[$i] = "checked";
                    223: 		    $hash{'display_attrs_'.$i} = 1;
                    224: 		}
                    225: 	    }
                    226: 	} else {
                    227: 	    for (my $i=0; $i<=5; $i++) {
                    228: 		$attrchk[$i] = "checked" if $hash{'display_attrs_'.$i} == 1;
                    229: 	    }
                    230: 	}
1.15    ! harris41  231: 	$r->print(<<END);
1.2       harris41  232: <b><font color="#666666">Display file attributes</font></b><br>
1.1       www       233: <form method="post" name="fileattr" action="$uri" enctype="application/x-www-form-urlencoded">
                    234: <table border=0><tr>
1.2       harris41  235: <td><input type=checkbox name=attr0 value="1" $attrchk[0]> Size</td>
                    236: <td><input type=checkbox name=attr1 value="1" $attrchk[1]> Last access</td>
                    237: <td><input type=checkbox name=attr2 value="1" $attrchk[2]> Last modified</td>
1.1       www       238: </tr><tr>
1.2       harris41  239: <td><input type=checkbox name=attr3 value="1" $attrchk[3]> Author</td>
                    240: <td><input type=checkbox name=attr4 value="1" $attrchk[4]> Keywords</td>
                    241: <td><input type=checkbox name=attr5 value="1" $attrchk[5]> Language</td>
1.1       www       242: </tr></table>
1.13      ng        243: <input type=hidden name=dirPointer value="on">
1.6       harris41  244: <input type="submit" name="attrs" value="Review">&nbsp;
                    245: <input type="submit" name="attrs" value="Refresh">
1.7       harris41  246: $hidden
                    247: $closebutton
                    248: $groupimportbutton
1.1       www       249: </form>
                    250: END
                    251: 
1.15    ! harris41  252:         my $titleclr="#ddffff";
        !           253:         $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
        !           254: 	$r->print("<table border=0><tr>\n");
        !           255: 	$r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
        !           256: 	$r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) </b></td>\n") if ($hash{'display_attrs_0'} == 1);
        !           257: 	$r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n") if ($hash{'display_attrs_1'} == 1);
        !           258: 	$r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n") if ($hash{'display_attrs_2'} == 1);
        !           259: 	$r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n") if ($hash{'display_attrs_3'} == 1);
        !           260: 	$r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n") if ($hash{'display_attrs_4'} == 1);
        !           261: 	$r->print("<td bgcolor=$titleclr><b>Language</b></td>\n") if ($hash{'display_attrs_5'} == 1);
        !           262: 	$r->print("</tr>");
1.5       harris41  263: 
1.4       harris41  264: 	map {
                    265: 	    if ($_ =~ /^diropen_status_/) {
                    266: 		my $key = $_;
                    267: 		$key =~ s/^diropen_status_//;
                    268: 		$dirs{$key} = $hash{$_};
                    269: 	    }
                    270: 	} keys %hash;
                    271: 
1.2       harris41  272: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
                    273: 	    my $uri=$ENV{'form.openuri'};
1.4       harris41  274: 	    if (exists($hash{'diropen_status_'.$uri})) {
                    275: 		my $cursta = $hash{'diropen_status_'.$uri};
1.2       harris41  276: 		$dirs{$uri} = 'open';
1.4       harris41  277: 		$hash{'diropen_status_'.$uri} = 'open';
                    278: 		if ($cursta eq 'open') {
                    279: 		    $dirs{$uri} = 'closed';
                    280: 		    $hash{'diropen_status_'.$uri} = 'closed';
                    281: 		}
1.2       harris41  282: 	    } else {
1.4       harris41  283: 		$hash{'diropen_status_'.$uri} = 'open';
1.2       harris41  284: 		$dirs{$uri} = 'open';
                    285: 	    }
                    286: 	}
1.12      ng        287: 	
                    288: 	my $bredir = $ENV{'form.dirPointer'};
                    289: 	my $toplevel;
1.13      ng        290: 	my $indent = 0;
1.12      ng        291: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
1.13      ng        292: 	if ($bredir ne "on") {
1.12      ng        293: 	    $hash{'top.level'} = $uri;
                    294: 	    $toplevel = $uri;
1.13      ng        295: 
                    296: 	} else {
                    297: 	    $toplevel = $hash{'top.level'};
                    298: 	}
                    299: 	if ($toplevel ne "/res/"){
                    300: 	    my (@uri_com) = split(/\//,$uri);
                    301: 	    pop @uri_com;
                    302: 	    my $upone = join('/',@uri_com);
                    303: 	    my @list = qw (0);
                    304: 	    &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
                    305: 	    $indent = 1;
1.12      ng        306: 	}
1.2       harris41  307: 	&scanDir ($r,$toplevel,$indent);
1.12      ng        308: 	
1.8       harris41  309: 	$r->print("<form name='fnum'>");
                    310: 	$r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
1.2       harris41  311: 	$r->print("</table>");
                    312: 	$r->print("</td></tr></table>");
                    313: 	$r->print("</body></html>\n");
1.4       harris41  314: 	untie(%hash);
1.2       harris41  315:     } else {
                    316: 	$r->print("Unable to tie hash to db file");
                    317:     }
1.1       www       318:     return OK;
                    319: }
1.2       harris41  320: 
1.6       harris41  321: 
1.2       harris41  322: # --------------------recursive scan of a directory
                    323: sub scanDir {
                    324:     my ($r,$startdir,$indent)=@_;
1.3       harris41  325:     my ($compuri,$curdir);
                    326:     my $dirptr=16384;
1.1       www       327:     $indent++;
                    328: 
1.2       harris41  329:     my %dupdirs = %dirs;
                    330:     my @list=&get_list($r,$startdir);
                    331:     foreach my $line (@list) {
1.5       harris41  332: 	my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5); 
1.4       harris41  333: 	next if $strip =~ /.*\.meta$/;
1.5       harris41  334: 	if ($dom eq "domain") {
1.3       harris41  335: 	    $compuri = join('',$strip,"/");  # domain list has /res/<domain name>
                    336: 	    $curdir = $compuri;
1.2       harris41  337: 	} else {
1.12      ng        338: 	    $compuri = join('',$startdir,$strip,"/"); # user, dir & file have name only, i.e., w/o path
1.3       harris41  339: 	    $curdir = $startdir;
1.2       harris41  340: 	}
1.11      ng        341: 	my $diropen = "closed";
1.5       harris41  342: 	if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
1.3       harris41  343: 	    while (my ($key,$val)= each %dupdirs) {
1.5       harris41  344: 		if ($key eq $compuri and $val eq "open") {
1.11      ng        345: 		    $diropen = "opened";
1.5       harris41  346: 		    delete $dupdirs{key},$dirs{$key};
                    347: 		}
1.3       harris41  348: 	    }
1.1       www       349: 	}
1.4       harris41  350: 	&display_line($r,$diropen,$line,$indent,$curdir,@list);
1.11      ng        351: 	&scanDir ($r,$compuri,$indent) if $diropen eq "opened";
1.1       www       352:     }
                    353:     $indent--;
                    354: }
                    355: 
1.2       harris41  356: # ----------------- get complete matched list based on the uri ------
1.1       www       357: sub get_list {
                    358:     my ($r,$uri)=@_;
                    359:     my @list;
1.2       harris41  360:     my $luri = $uri;
                    361:     $luri =~ s/\//_/g;
                    362: 
1.6       harris41  363:     if ($ENV{'form.attrs'} eq "Refresh") {
1.4       harris41  364: 	map {
                    365: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
                    366: 	    } keys %hash;
1.2       harris41  367:     }
                    368: 
1.4       harris41  369:     if ($hash{'dirlist_files'.$luri}) {
                    370: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.1       www       371:     } else {
1.4       harris41  372: 	@list = &Apache::lonnet::dirlist($uri);
                    373: 	$hash{'dirlist_files_'.$luri} = join('\n',@list);
1.1       www       374:     }
                    375:     return @list=&match_ext($r,@list);
                    376: }
                    377: 
1.2       harris41  378: #-------------------------- filters out files based on extensions
1.1       www       379: sub match_ext {
                    380:     my ($r,@packlist)=@_;
                    381:     my @trimlist;
                    382:     my $nextline;
                    383:     my @fileext;
                    384:     my $dirptr=16384;
                    385: 
                    386:     my $tabdir  = $r->dir_config('lonTabDir');
1.12      ng        387:     my $fn = $tabdir.'/filetypes.tab';
1.1       www       388:     if (-e $fn) {
                    389: 	my $FH=Apache::File->new($fn);
                    390: 	my @content=<$FH>;
1.2       harris41  391: 	foreach my $line (@content) {
1.1       www       392: 	    (my $ext,my $foo) = split /\s+/,$line;
                    393: 	    push @fileext,$ext;
                    394: 	}
                    395:     }
1.2       harris41  396:     foreach my $line (@packlist) {
                    397: 	chomp $line;
                    398: 	$line =~ s/^\/home\/httpd\/html//;
                    399: 	my @unpackline = split (/\&/,$line);
                    400: 	next if ($unpackline[0] eq ".");
                    401: 	next if ($unpackline[0] eq "..");
                    402: 	my @filecom = split (/\./,$unpackline[0]);
                    403: 	my $fext = pop(@filecom);
                    404: 	my $fnptr = $unpackline[3]&$dirptr;
                    405:  	if ($fnptr == 0 and $unpackline[3] ne "") {
                    406: 	    foreach my $nextline (@fileext) {
                    407: 		push @trimlist,$line if $nextline eq $fext;
1.1       www       408: 	    }
                    409: 	} else {
1.2       harris41  410: 	    push @trimlist,$line;
1.1       www       411: 	}
                    412:     }
1.4       harris41  413:     @trimlist = sort (@trimlist);
1.1       www       414:     return @trimlist;
                    415: }
                    416: 
1.2       harris41  417: #------------------- displays one line in appropriate table format
1.1       www       418: sub display_line{
1.4       harris41  419:     my ($r,$diropen,$line,$indent,$startdir,@list)=@_;
1.1       www       420:     my (@pathfn, $fndir, $fnptr);
                    421:     my $dirptr=16384;
                    422:     my $fileclr="#ffffe6";
1.10      harris41  423:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1       www       424: 
                    425:     my @filecom = split (/\&/,$line);
                    426:     my @pathcom = split (/\//,$filecom[0]);
                    427:     my $listname = $pathcom[scalar(@pathcom)-1];
                    428:     my $fnptr = $filecom[3]&$dirptr;
1.4       harris41  429:     my $msg = 'View '.$filecom[0].' resources';
1.11      ng        430:     $msg = 'Close '.$filecom[0].' directory' if $diropen eq "opened";
1.1       www       431: 
                    432:     my $tabtag="</td>";
                    433:     my $i=0;
                    434: 
                    435:     while ($i<=5) {
1.6       harris41  436: 	$tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,">&nbsp;</td>") if $hash{'display_attrs_'.$i} == 1;
1.1       www       437: 	$i++;
                    438:     }
1.13      ng        439:     if ($filecom[1] eq "viewOneUp") {
                    440: 	$r->print("<tr>$extrafield");
                    441: 	$r->print("<td bgcolor=$fileclr valign=bottom>\n");
                    442: 	$r->print ('<form method="post" name="dirpath" action="'.$startdir.
                    443: 		   '" enctype="application/x-www-form-urlencoded">'."\n");
                    444: 	$r->print ($hidden.'<input type=hidden name=openuri value="'.$startdir.'">'."\n");
                    445: 	$r->print ('<input src="'.$iconpath.'arrow_up.gif"');
                    446: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");
                    447: 	$r->print("Up $tabtag</tr></form>\n");
                    448: 	return OK;
                    449:     }
1.1       www       450:     if ($filecom[1] eq "domain") {
1.13      ng        451: 	$r->print ('<input type=hidden name=dirPointer value="on">'."\n") if ($ENV{'form.dirPointer'} eq "on");
1.7       harris41  452: 	$r->print("<tr>$extrafield");
1.1       www       453: 	$r->print("<td bgcolor=$fileclr valign=bottom>");
1.2       harris41  454: 	&begin_form ($r,$filecom[0].'/');
1.3       harris41  455: 	my $anchor = $filecom[0].'/';
                    456: 	$anchor =~ s/\///g;
1.13      ng        457: 	$r->print ('<a name="'.$anchor.'">');
                    458: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.'.gif"'); 
1.11      ng        459: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");
1.13      ng        460: 	$r->print ('<a href="'.$filecom[0].'"><img src="'.$iconpath.'server.gif"');
                    461: 	$r->print (' border="0"></a>'."\n");
1.1       www       462: 	$r->print("Domain - $listname $tabtag</tr></form>\n");
                    463: 	return OK;
                    464:     }
                    465:     if ($filecom[1] eq "user") {
1.7       harris41  466: 	$r->print("<tr>$extrafield");
1.13      ng        467: 	$r->print("<td bgcolor=$fileclr valign=bottom nowrap>\n");
1.2       harris41  468: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  469: 	my $anchor = $curdir;
                    470: 	$anchor =~ s/\///g;
1.13      ng        471: 	&begin_form ($r,$curdir);
1.11      ng        472: 	$r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.'whitespace1.gif" border=0>'."\n");
                    473: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.'.gif"'); 
                    474: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");
1.13      ng        475: 	$r->print ('<a href="'.$curdir.'"><img src='.$iconpath.'quill.gif border=0 name="'.$msg.'" height="22"></a>');
                    476: 	$r->print ($listname.$tabtag.'</tr></form>'."\n");
1.1       www       477: 	return OK;
                    478:     }
                    479: # display file
                    480:     if ($fnptr == 0 and $filecom[3] ne "") {
                    481: 	my @file_ext = split (/\./,$listname);
                    482: 	my $curfext = $file_ext[scalar(@file_ext)-1];
1.2       harris41  483: 	my $filelink = $startdir.$filecom[0];
1.8       harris41  484: 	$r->print("<tr><td nowrap valign='bottom' bgcolor=$fileclr>");
1.7       harris41  485: 	my $metafile = grep /^$filecom[0]\.meta\&/, @list;
                    486: 	my $title;
                    487:         if ($ENV{'form.catalogmode'} eq 'interactive') {
                    488: 	    $title=$listname;
1.8       harris41  489: 	    $title = &Apache::lonnet::metadata($filelink,'title')
                    490: 		if ($metafile == 1);
1.7       harris41  491: 	    $title=$listname unless $title;
                    492: 	    $r->print("<a href='javascript:select_data(\"",
                    493: 	              $title,'","',$filelink,"\")'>");
                    494: 	    $r->print("<img src='",$iconpath,"select.gif' border=0></a>\n");
1.8       harris41  495: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
                    496: 	}
                    497:         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
                    498: 	    $title=$listname;
                    499: 	    $title = &Apache::lonnet::metadata($filelink,'title')
                    500: 		if ($metafile == 1);
                    501: 	    $title=$listname unless $title;
                    502: 	    $r->print("<form name='form$fnum'>\n");
                    503: 	    $r->print("<input type='checkbox' name='filelink"."' ".
                    504: 		      "value='$filelink'>\n");
                    505: 	    $r->print("<input type='hidden' name='title"."' ".
                    506: 		      "value='$title'>\n");
                    507: 	    $r->print("</form>\n");
                    508: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
                    509:   	    $fnum++;
1.7       harris41  510: 	}
1.4       harris41  511: 
1.12      ng        512: 	if ($indent > 0 and $indent < 11) {
1.4       harris41  513: 	    $r->print("<img src=",$iconpath,"whitespace",$indent,".gif border=0>\n");
1.11      ng        514: 	} elsif ($indent >0) {
1.4       harris41  515: 	    my $ten = int($indent/10.);
                    516: 	    my $rem = $indent%10.0;
                    517: 	    my $count = 0;
                    518: 	    while ($count < $ten) {
                    519: 		$r->print("<img src=",$iconpath,"whitespace10.gif border=0>\n");
1.1       www       520: 	    $count++;
1.4       harris41  521: 	    }
                    522: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,".gif border=0>\n") if $rem > 0;
1.1       www       523: 	}
1.4       harris41  524: 
1.1       www       525: 	$r->print("<img src=$iconpath$curfext.gif border=0>\n");
1.12      ng        526: 	$r->print (" <a href=\"javascript:openWindow('".$filelink."', 'metadatafile', '450', '500', 'no', 'yes')\"; TARGET=_self>$listname</a> ");
1.2       harris41  527: 
1.4       harris41  528: 	$r->print (" (<a href=\"javascript:openWindow('".$filelink.".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; TARGET=_self>metadata</a>) ") if ($metafile == 1);
1.2       harris41  529: 
1.7       harris41  530: 	$r->print("</td>\n");
1.11      ng        531: 	$r->print("<td bgcolor=$fileclr align=right valign=bottom> ",$filecom[8]," </td>\n") 
                    532: 	    if $hash{'display_attrs_0'} == 1;
                    533: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[9]))." </td>\n") 
                    534: 	    if $hash{'display_attrs_1'} == 1;
                    535: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[10]))." </td>\n") 
                    536: 	    if $hash{'display_attrs_2'} == 1;
1.2       harris41  537: 
1.6       harris41  538: 	if ($hash{'display_attrs_3'} == 1) {
1.4       harris41  539: 	    my $author = &Apache::lonnet::metadata($filelink,'author') if ($metafile == 1);
1.2       harris41  540: 	    $author = '&nbsp;' if (!$author);
                    541: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$author." </td>\n");
                    542: 	}
1.6       harris41  543: 	if ($hash{'display_attrs_4'} == 1) {
1.4       harris41  544: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords') if ($metafile == 1);
1.2       harris41  545: 	    $keywords = '&nbsp;' if (!$keywords);
                    546: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords." </td>\n");
                    547: 	}
1.6       harris41  548: 	if ($hash{'display_attrs_5'} == 1) {
1.4       harris41  549: 	    my $lang = &Apache::lonnet::metadata($filelink,'language') if ($metafile == 1);
1.2       harris41  550: 	    $lang = $language{$lang};
                    551: 	    $lang = '&nbsp;' if (!$lang);
                    552: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang." </td>\n");
                    553: 	}
1.1       www       554: 	$r->print("</tr>\n");
                    555:     }
1.2       harris41  556: # -- display directory
1.1       www       557:     if ($fnptr == $dirptr) {
                    558: 	my @file_ext = split (/\./,$listname);
                    559: 	my $curfext = $file_ext[scalar(@file_ext)-1];
1.2       harris41  560: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  561: 	my $anchor = $curdir;
                    562: 	$anchor =~ s/\///g;
1.7       harris41  563: 	$r->print("<tr>$extrafield<td bgcolor=$fileclr valign=bottom>");
1.2       harris41  564: 	&begin_form ($r,$curdir);
1.4       harris41  565: 	my $indentm1 = $indent-1;
1.11      ng        566: 	if ($indentm1 < 11 and $indentm1 > 0) {
1.4       harris41  567: 	    $r->print("<img src=",$iconpath,"whitespace",$indentm1,".gif border=0>\n");
                    568: 	} else {
                    569: 	    my $ten = int($indentm1/10.);
                    570: 	    my $rem = $indentm1%10.0;
                    571: 	    my $count = 0;
                    572: 	    while ($count < $ten) {
1.13      ng        573: 		$r->print ("<img src=",$iconpath,"whitespace10.gif border=0>\n");
1.12      ng        574: 		$count++;
1.4       harris41  575: 	    }
1.13      ng        576: 	    $r->print ("<img src=",$iconpath,"whitespace",$rem,".gif border=0>\n") if $rem > 0;
1.1       www       577: 	}
1.11      ng        578: 	$r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.'folder_pointer_'.$diropen.'.gif"');
                    579: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");
1.13      ng        580: 	$r->print ('<a href="'.$curdir.'"><img src="'.$iconpath.'folder_'.$diropen.'.gif" border=0></a>'."\n");
                    581: 	$r->print ("$listname$tabtag</tr></form>\n");
1.1       www       582:     }
1.2       harris41  583: 
1.1       www       584: }
                    585: 
1.14      harris41  586: # ------------------- prints the beginning of a form for directory or file link
1.1       www       587: sub begin_form {
                    588:     my ($r,$uri) = @_;
1.3       harris41  589:     my $anchor = $uri;
                    590:     $anchor =~ s/\///g;
1.13      ng        591:     $r->print ('<form method="post" name="dirpath" action="'.$uri.'#'.$anchor.
                    592: 	       '" enctype="application/x-www-form-urlencoded">'."\n");
1.12      ng        593:     $r->print ($hidden.'<input type=hidden name=openuri value="'.$uri.'">'."\n");
                    594:     $r->print ('<input type=hidden name=dirPointer value="on">'."\n");
1.1       www       595: }
                    596: 
                    597: 1;
                    598: __END__

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