File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.16: download - view: text, annotated - select for diffs
Wed Aug 8 03:00:11 2001 UTC (22 years, 11 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
functional now for group import

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

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