[LON-CAPA-cvs] cvs: loncom /interface lonindexer.pm

ng lon-capa-cvs@mail.lon-capa.org
Mon, 21 Jul 2003 18:35:26 -0000


ng		Mon Jul 21 14:35:26 2003 EDT

  Modified files:              
    /loncom/interface	lonindexer.pm 
  Log:
  fix bug 1357 - show usage stat on number of courses/network hits
  
  
  
Index: loncom/interface/lonindexer.pm
diff -u loncom/interface/lonindexer.pm:1.69 loncom/interface/lonindexer.pm:1.70
--- loncom/interface/lonindexer.pm:1.69	Thu Jul 17 17:11:09 2003
+++ loncom/interface/lonindexer.pm	Mon Jul 21 14:35:25 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Directory Indexer
 #
-# $Id: lonindexer.pm,v 1.69 2003/07/17 21:11:09 www Exp $
+# $Id: lonindexer.pm,v 1.70 2003/07/21 18:35:25 ng Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -62,6 +62,7 @@
 use Apache::lonnet();
 use Apache::loncommon();
 use Apache::Constants qw(:common);
+use Apache::lonmeta;
 use Apache::File;
 use GDBM_File;
 
@@ -377,7 +378,7 @@
 	
 # ---------------------------------- get state of file attributes to be showing
 	if ($ENV{'form.attrs'} ne '') {
-	    for (my $i=0; $i<=8; $i++) {
+	    for (my $i=0; $i<=9; $i++) {
 		delete $hash{'display_attrs_'.$i};
 		if ($ENV{'form.attr'.$i} == 1) {
 		    $attrchk[$i] = 'checked';
@@ -385,7 +386,7 @@
 		}
 	    }
 	} else {
-	    for (my $i=0; $i<=8; $i++) {
+	    for (my $i=0; $i<=9; $i++) {
 		$attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;
 	    }
 	}
@@ -399,11 +400,12 @@
 <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Size</td>
 <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last access</td>
 <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Last modified</td>
-<td><input type="checkbox" name="attr8" value="1" $attrchk[8] /> All versions</td></tr><tr>
+<td><input type="checkbox" name="attr8" value="1" $attrchk[8] /> Statistics</td></tr><tr>
 <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Author</td>
 <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> Keywords</td>
 <td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> Language</td>
 <td><input type="checkbox" name="attr7" value="1" $attrchk[7] /> Show Resource</td>
+<td><input type="checkbox" name="attr9" value="1" $attrchk[9] /> All versions</td>
 <td>&nbsp;</td>
 </tr></table>
 <input type="hidden" name="dirPointer" value="on" />
@@ -439,6 +441,8 @@
 	    if ($hash{'display_attrs_6'} == 1);
 	$r->print("<td><b>Resource</b></td>\n")
 	    if ($hash{'display_attrs_7'} == 1);
+	$r->print("<td><b>Usage Statistics <br />(Courses/Network Hits)</b></td>\n")
+	    if ($hash{'display_attrs_8'} == 1);
 	$r->print('</tr>');
 
 # ----------------- read in what directories have previously been set to "open"
@@ -535,7 +539,7 @@
 	my ($strip,$dom,undef,$testdir,undef)=split(/\&/,$line,5); 
 	next if $strip =~ /.*\.meta$/;
 	my (@fileparts) = split(/\./,$strip);
-	if ($hash{'display_attrs_8'} != 1) {
+	if ($hash{'display_attrs_9'} != 1) {
 	    if (scalar(@fileparts) >= 3) {
 		my $fext = pop @fileparts;
 		my $ov = pop @fileparts;
@@ -659,7 +663,7 @@
     my $tabtag='</td>';
     my $i=0;
 
-    while ($i<=7) {
+    while ($i<=8) {
 	$tabtag=join('',$tabtag,"<td>&nbsp;</td>")
 	    if $hash{'display_attrs_'.$i} == 1;
 	$i++;
@@ -669,8 +673,8 @@
 
 # display uplink arrow
     if ($filecom[1] eq 'viewOneUp') {
-	$r->print("<tr bgcolor=$fileclr>$extrafield");
-	$r->print("<td valign=$valign>\n");
+	$r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
+	$r->print("<td>\n");
 	$r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
 		   '/" '.
 		   'onSubmit="return rep_dirpath(\'UP\','.
@@ -694,8 +698,8 @@
     if ($filecom[1] eq 'domain') {
 	$r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
 	    if ($ENV{'form.dirPointer'} eq "on");
-	$r->print("<tr bgcolor=$fileclr>$extrafield");
-	$r->print("<td valign=$valign>");
+	$r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
+	$r->print("<td>");
 	&begin_form ($r,$filecom[0].'/');
 	my $anchor = $filecom[0].'/';
 	$anchor =~ s/\///g;
@@ -719,8 +723,8 @@
 # display user directory
     }
     if ($filecom[1] eq 'user') {
-	$r->print("<tr bgcolor=$fileclr>$extrafield");
-	$r->print("<td valign=$valign nowrap>\n");
+	$r->print("<tr valign=$valign bgcolor=$fileclr>$extrafield");
+	$r->print("<td nowrap>\n");
 	my $curdir = $startdir.$filecom[0].'/';
 	my $anchor = $curdir;
 	$anchor =~ s/\///g;
@@ -763,7 +767,7 @@
 	$iconname = $curfext.".gif" unless
 	    (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn');
 	#
-	$r->print("<tr bgcolor=$fileclr><td nowrap valign='$valign'>");
+	$r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap>");
 	my $metafile = grep /^\Q$filecom[0]\E\.meta\&/, @list;
 	my $title;
         if ($ENV{'form.catalogmode'} eq 'interactive') {
@@ -777,7 +781,7 @@
                       $titleesc,"','",$filelink,"')\">");
 	    $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
 		      "\n");
-	    $r->print("</td><td valign='$valign' nowrap>");
+	    $r->print("</td><td nowrap>");
 	}
         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
 	    $title=$listname;
@@ -796,7 +800,7 @@
 	    $r->print("<input type='hidden' name='title"."' ".
 		      "value='$titleesc'>\n");
 	    $r->print("</form>\n");
-	    $r->print("</td><td valign='$valign' nowrap>");
+	    $r->print("</td><td nowrap>");
 	    $hash{"pre_${fnum}_link"}=$filelink;
 	    $hash{"pre_${fnum}_title"}=$titleesc;
   	    $fnum++;
@@ -829,39 +833,39 @@
 
 	$r->print("</td>\n");
 	if ($hash{'display_attrs_0'} == 1) {
-	    my $title = &Apache::lonnet::metadata($filelink,'title')
+	    my $title = &Apache::lonnet::gettitle($filelink,'title')
 		if ($metafile == 1);
-	    $r->print('<td valign=$valign> '.($title eq '' ? '&nbsp;' : $title).
+	    $r->print('<td> '.($title eq '' ? '&nbsp;' : $title).
 		      ' </td>'."\n");
 	}
-	$r->print('<td align=right valign=$valign> ',
+	$r->print('<td align=right> ',
 		  $filecom[8]," </td>\n") 
 	    if $hash{'display_attrs_1'} == 1;
-	$r->print('<td valign=$valign> '.
+	$r->print('<td> '.
 		  (localtime($filecom[9]))." </td>\n") 
 	    if $hash{'display_attrs_2'} == 1;
-	$r->print('<td valign=$valign> '.
+	$r->print('<td> '.
 		  (localtime($filecom[10]))." </td>\n") 
 	    if $hash{'display_attrs_3'} == 1;
 
 	if ($hash{'display_attrs_4'} == 1) {
 	    my $author = &Apache::lonnet::metadata($filelink,'author')
 		if ($metafile == 1);
-	    $r->print('<td valign=$valign> '.($author eq '' ? '&nbsp;' : $author).
+	    $r->print('<td> '.($author eq '' ? '&nbsp;' : $author).
 		      " </td>\n");
 	}
 	if ($hash{'display_attrs_5'} == 1) {
 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
 		if ($metafile == 1);
 	    # $keywords = '&nbsp;' if (!$keywords);
-	    $r->print('<td valign=$valign> '.($keywords eq '' ? '&nbsp;' : $keywords).
+	    $r->print('<td> '.($keywords eq '' ? '&nbsp;' : $keywords).
 		      " </td>\n");
 	}
 	if ($hash{'display_attrs_6'} == 1) {
 	    my $lang = &Apache::lonnet::metadata($filelink,'language')
 		if ($metafile == 1);
 	    $lang = &Apache::loncommon::languagedescription($lang);
-	    $r->print('<td valign=$valign> '.($lang eq '' ? '&nbsp;' : $lang).
+	    $r->print('<td> '.($lang eq '' ? '&nbsp;' : $lang).
 		      " </td>\n");
 	}
         if ($hash{'display_attrs_7'} == 1) {
@@ -877,9 +881,18 @@
 		 $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}.
                  '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
            }
-	   $r->print('<td valign=$valign> '.($output eq '' ? '&nbsp;':$output).
+	   $r->print('<td> '.($output eq '' ? '&nbsp;':$output).
 		      " </td>\n");
         }
+	if ($hash{'display_attrs_8'} == 1) {
+	    my (%stat) = &Apache::lonmeta::dynamicmeta($filelink) if ($metafile == 1);
+	    my $stat = ($stat{'course'} eq '' ? '' : $stat{'course'}).
+		(($stat{'course'} ne '' || $stat{'count'} ne '') ? '/' : '').
+		($stat{'count'} eq '' ? '' : $stat{'count'});
+	    $r->print('<td align=center> '.($stat eq '' ? '&nbsp;' : $stat).
+		      ' </td>'."\n");
+	}
+
 	$r->print("</tr>\n");
     }