<h3>Abstract views and full text downloads by year/month</h3>      

<?php
	// NJS 2006-04-24
	// Add if to check whether there actually are any stats!
	if (! isset($GLOBALS["db_values"]["0"]["abstracts"])) {
		print "<table>\n";
		print '<tr><td align="left" width="200" style="color:#ff0000;"><b>No statistics available.</b></td></tr>';
		print "\n";
	} else {
		$max_count = $GLOBALS["db_values"][0]["abstracts"];
		for ($rs=0;$rs<count($GLOBALS["db_values"]);$rs++)
		{
			if($max_count < $GLOBALS["db_values"][$rs]["abstracts"])
				$max_count = $GLOBALS["db_values"][$rs]["abstracts"];
			// NJS 2006-06-14: Included downloads in the max_count
			// calculation for cases where there are more downloads
			// than abstracts.
			if($max_count < $GLOBALS["db_values"][$rs]["downloads"])
				$max_count = $GLOBALS["db_values"][$rs]["downloads"];
		}
		// NJS 2006-06-14: You never know, there may be no downloads or
		// abstracts yet...
		$max_count = max( $max_count, 1 );
		$max_width = '500'; // Max pixel width of barchart.
		
		print "<table cellspacing='0' cellpadding='4'>\n";
		print '<tr><td colspan="6"><span style="font-size:small;">Click on a month to see full text downloads for that month.<br />
			The numbers in (parentheses) are the number of distinct countries or search engines that downloads originated from.</span></td></tr>';
		print '<tr><th style="background-color:#cccccc;">Period</th>
			<th colspan="2" style="background-color:#66ddee;">Abstracts</th>
			<th colspan="2" style="background-color:#4477dd;color:#ffffff;">Full text</th>
			<th style="background-color:#cccccc;">&nbsp;</th></tr>';
		for ($rs=0;$rs<count($GLOBALS["db_values"]);$rs++)
		{
			$monthnum = (int) strpos('JanFebMarAprMayJunJulAugSepOctNovDec', $GLOBALS["db_values"][$rs]["month"])/3 + 1;
			// NJS 2005-12-15: subtly highlight every alternate row
			print '<tr';
			if ($rs % 2) print ' style="background-color:#EDF3FE;"';
			print '><td style="font-size:small;border-right:1px solid #dddddd;">';
			// NJS 2006-06-14: Only generate a link if there are actually
			// some downloads.
			if ( $GLOBALS["db_values"][$rs]["downloads"] > 0 )
				print '<a href="'.
					$_SERVER['PHP_SELF'].
					'?action=show_detail_date;year='.
					$GLOBALS["db_values"][$rs]["year"].
					';month=' .
					$monthnum .
					'">';
			print $GLOBALS["db_values"][$rs]["year"].
				' '.
				$GLOBALS["db_values"][$rs]["month"];
			if ( $GLOBALS["db_values"][$rs]["downloads"] > 0 )
				print '</a>';
			print '</td><td align="right" style="font-size:small;">'.
				$GLOBALS["db_values"][$rs]["abstracts"].
				'</td><td align="right" style="font-size:small;border-right:1px solid #dddddd;">('.
				$GLOBALS["db_values"][$rs]["acountries"].
				')</td><td align="right" style="font-size:small;">'.
				$GLOBALS["db_values"][$rs]["downloads"].
				'</td><td align="right" style="font-size:small;border-right:1px solid #dddddd;">('.
				$GLOBALS["db_values"][$rs]["dcountries"].
				')</td>';
			$cur_count = $GLOBALS["db_values"][$rs]["abstracts"];
			$col_width = (int) ($cur_count/$max_count * $max_width);
			$col_width = max($col_width, 1);
			$col_width .= "px";
			print '<td align="left"><img src="bars/hh.png" alt="abstracts" height="9" width="'. 
				$col_width . 
				'" /><br />';
			$cur_count = $GLOBALS["db_values"][$rs]["downloads"];
			$col_width = (int) ($cur_count/$max_count * $max_width);
			$col_width = max($col_width, 1);
			$col_width .= "px";
			print '<img src="bars/hp.png" alt="downloads" height="9" width="'. 
				$col_width . 
				'" /></td></tr>';
		}
	} // of else
	print "</table>\n";
?>

	
