File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.21: download - view: text, annotated - select for diffs
Tue Oct 16 17:04:31 2001 UTC (22 years, 8 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
fixing authorship info

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

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