diff --git a/Repositories/statistics/includes/inc.fns.cumulative_usage_country.es.php b/Repositories/statistics/includes/inc.fns.cumulative_usage_country.es.php index 6039129..f4f61ac 100755 --- a/Repositories/statistics/includes/inc.fns.cumulative_usage_country.es.php +++ b/Repositories/statistics/includes/inc.fns.cumulative_usage_country.es.php @@ -7,11 +7,177 @@ $country_downloads = $sql->getCumulativeUsageCountryType($GLOBALS["config_vars"]["archivename"],"download"); $country_abstracts = $sql->getCumulativeUsageCountryType($GLOBALS["config_vars"]["archivename"],"abstract"); - // NJS 2006-01-18: Calculate total number of countries. - $total_download_countries = count($country_downloads); - $total_abstract_countries = count($country_abstracts); - $GLOBALS["db_values"] = merge_countries($country_abstracts,$country_downloads); // $debug->setDebug($GLOBALS["db_values"],__LINE__,__FILE__,'','',''); + + /* NJS 2007-01-31 + Calculate the length of the largest bar for the country + downloads histogram. + + This was refactored from inc.html.cumulative_usage_country.php. + + Arguments: $mode either 'country' (count only real countries) + or 'bot' (count only bots/crawlers) + + Returns: integer + */ + function getMaxCount ( $mode ) + { + $max = 0; + + for ( $rs = 0; $rs < count( $GLOBALS["db_values"] ); $rs++ ) + { + /* If we're in country mode, skip all bot entries (country + code starts with 'X@'). If we're in bot mode, skip + all country entries (country code *doesn't* start with + 'X@'). + */ + $cc = substr( $GLOBALS["db_values"][$rs]["country_code"], 0, 2 ); + if ( ( $mode == 'country' ) && ( $cc == 'X@' ) ) continue; + if ( ( $mode == 'bot' ) && ( $cc != 'X@' ) ) continue; + + // Check abstracts... + $abs = $GLOBALS["db_values"][$rs]["country_abstracts"]; + if ( $abs > $max ) + { + $max = $abs; + } + + // ...then downloads. + $dl = $GLOBALS["db_values"][$rs]["country_downloads"]; + if ( $dl > $max ) + { + $max = $dl; + } + } + return $max; + } + + + /* NJS 2007-01-31 + Output a "country" downloads histogram. This function only + generates rows () of the table; the enclosing element + must be output by the caller. + + This was refactored from inc.html.cumulative_usage_country.php. + + Arguments: $mode either 'country' (display only real countries) + or 'bot' (display only bots/crawlers) + $max_count length (number of hits) of longest bar + $max_width maximum width in pixels of a bar + + Returns: void + */ + function generateCountryTable ( $mode, $max_count, $max_width ) + { + // NJS 2006-01-18: Accumulate total number of downloads and views. + $total_downloads = 0; + $total_abstracts = 0; + $abstract_countries = array(); + $download_countries = array(); + + for ( $rs = 0; $rs < count( $GLOBALS["db_values"] ); $rs++ ) + { + /* If we're in country mode, skip all bot entries (country + code starts with 'X@'). If we're in bot mode, skip + all country entries (country code *doesn't* start with + 'X@'). + */ + $ccode = $GLOBALS["db_values"][$rs]["country_code"]; + $cc = substr( $ccode, 0, 2 ); + if ( ( $mode == 'country' ) && ( $cc == 'X@' ) ) continue; + if ( ( $mode == 'bot' ) && ( $cc != 'X@' ) ) continue; + + // NJS 2006-01-18: Accumulate total number of downloads and views. + // NJS 2007-01-31: Record countries in a bitmap so we can easily count them later. + $abs = $GLOBALS["db_values"][$rs]["country_abstracts"]; + $dl = $GLOBALS["db_values"][$rs]["country_downloads"]; + $total_abstracts += $abs; + $total_downloads += $dl; + if ( $abs > 0 ) + { + $abstract_countries[$ccode] = 1; + } + if ( $dl > 0 ) + { + $download_countries[$ccode] = 1; + } + + if ($GLOBALS["db_values"][$rs]["country_name"]=='') { $GLOBALS["db_values"][$rs]["country_name"]='unknown'; } + if ($GLOBALS["db_values"][$rs]["country_name"]=='N/A') { $GLOBALS["db_values"][$rs]["country_name"]='unknown'; } + // NJS 2005-12-15: subtly highlight every alternate row + print ''; + + $cur_count = $abs; + $col_width = (int) ($cur_count/$max_count * $max_width); + if ( $abs > 0 ) $col_width = max($col_width,1); + $col_width .= "px"; + print ''; + } + + // NJS 2006-01-18: Display grand totals. + print ' + + '; + print ' + '; + } + ?>
'; + + // select a flag + // NJS 2005-12-15 make flags and country names links to detail page + $ccode = strtolower($ccode); + $c_flag = 'flags18x14/' . $ccode . '.png'; + // NJS 2006-06-14: Only generate a link if there are actually + // some downloads. + if ( $dl > 0 ) + print ''; + if (file_exists($c_flag)) { + print ''. $ccode . ''; + } else { + print '' . $ccode . ''; + }; + if ( $dl > 0 ) + print ''; + + print ''; + // NJS 2006-06-14: Only generate a link if there are actually + // some downloads. + if ( $dl > 0 ) + print ''; + print $GLOBALS["db_values"][$rs]["country_name"]; + if ( $dl > 0 ) + print ''; + print ''. + ( ( $abs > 0 ) ? $abs : '' ). + '' . + ( ( $dl > 0 ) ? $dl : '' ). + 'views
'; + + $cur_count = $dl; + $col_width = (int) ($cur_count/$max_count * $max_width); + if ($dl > 0) $col_width = max($col_width,1); + $col_width .= "px"; + print 'views
Grand Totals:'. + $total_abstracts. + '  abstract views'; + if ( $mode == 'country' ) + print ' originating from '. + count($abstract_countries). + ' distinct countries
 '. + $total_downloads. + ' document downloads'; + if ($mode == 'country' ) + print ' originating from '. + count($download_countries). + ' distinct countries