- <h3>Abstract views and document downloads by country (derived from IP address of query)</h3>
- <p><strong>Note:</strong> The country of origin is determined by looking up the source IP address in the <a href="http://www.maxmind.com/app/geoip_country">GeoLite Country</a> database provided by MaxMind LLC. Due to the ever-changing nature of the Internet, this database can never be 100% complete or accurate, so it is possible that a small number of downloads may be reported as being from the wrong country.</p>
- <?php
- $max_width=400;
- if (! isset($GLOBALS["db_values"]["0"]["country_downloads"])) {
- print "<table>\n";
- print '<tr><td align="left" width="200" style="color:#ff0000;"><b>No statistics available.</b></td></tr>';
- print "\n";
- } else {
- // Compute the longest bar
- $max_count = $GLOBALS["db_values"]["0"]["country_downloads"];
- for ($rs=0; $rs<count($GLOBALS["db_values"]); $rs++) {
- if ($GLOBALS["db_values"][$rs]["country_abstracts"] > $max_count) {
- $max_count = $GLOBALS["db_values"][$rs]["country_abstracts"];
- }
- }
- // NJS 2006-06-14: You never know, there may be no downloads or
- // abstracts yet...
- $max_count = max( $max_count, 1 );
- print "<table cellspacing='0' cellpadding='4'>\n";
- print '<tr><td colspan="5"><span style="font-size:small;">Click on a country name or flag to view details of the eprints that have been downloaded from that country.</span></td></tr>';
- print '<tr><th colspan="2" style="background-color:#cccccc;">Country</th>
- <th style="background-color:#66ddee;">Abstracts</th>
- <th style="background-color:#4477dd;color:#ffffff;">Downloads</th>
- <th style="background-color:#cccccc;"> </th></tr>';
- // NJS 2006-01-18: Accumulate total number of downloads and views.
- $total_downloads = 0;
- $total_abstracts = 0;
- for ($rs=0;$rs<count($GLOBALS["db_values"]);$rs++)
- {
- // NJS 2006-01-18: Accumulate total number of downloads and views.
- $total_downloads += $GLOBALS["db_values"][$rs]["country_downloads"];
- $total_abstracts += $GLOBALS["db_values"][$rs]["country_abstracts"];
- 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 '<tr';
- if ($rs % 2) print ' style="background-color:#EDF3FE;"';
- print '><td>';
- // select a flag
- // NJS 2005-12-15 make flags and country names links to detail page
- $ccode = strtolower($GLOBALS["db_values"][$rs]["country_code"]);
- $c_flag = 'flags18x14/' . $ccode . '.png';
- // NJS 2006-06-14: Only generate a link if there are actually
- // some downloads.
- if ( $GLOBALS["db_values"][$rs]["country_downloads"] > 0 )
- print '<a href="' . $_SERVER['PHP_SELF'] .
- '?action=show_detail_country;code=' . $ccode . '">';
- if (file_exists($c_flag)) {
- print '<img src="'. $c_flag . '" width="18" height="14" alt="'. $ccode . '" />';
- } else {
- print '<img src="flags18x14/unknown.png" width="18" height="14" alt="' . $ccode . '" />';
- };
- if ( $GLOBALS["db_values"][$rs]["country_downloads"] > 0 )
- print '</a>';
- print '</td><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]["country_downloads"] > 0 )
- print '<a href="' . $_SERVER['PHP_SELF'] .
- '?action=show_detail_country;code=' . $ccode . '">';
- print $GLOBALS["db_values"][$rs]["country_name"];
- if ( $GLOBALS["db_values"][$rs]["country_downloads"] > 0 )
- print '</a>';
- print '</td><td align="right" style="font-size:small;border-right:1px solid #dddddd;">'.
- $GLOBALS["db_values"][$rs]["country_abstracts"].
- '</td><td align="right" style="font-size:small;border-right:1px solid #dddddd;">' .
- $GLOBALS["db_values"][$rs]["country_downloads"].
- '</td>';
- $cur_count = $GLOBALS["db_values"][$rs]["country_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="views" height="9" width="'.
- $col_width .
- '" /><br />';
- $cur_count = $GLOBALS["db_values"][$rs]["country_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="views" height="9" width="'.
- $col_width .
- '" /></td></tr>';
- }
- // NJS 2006-01-18: Display grand totals.
- print '<tr><th rowspan="2" colspan="2" style="background-color:#cccccc;">Grand Totals:</th>
- <th align="right" style="background-color:#66ddee;">'.
- $total_abstracts.
- '</th><th align="right" style="background-color:#cccccc;"> </th>
- <th align="left" style="background-color:#cccccc;"> abstract views originating from '.
- $total_abstract_countries.
- ' distinct countries</td></tr>';
- print '<tr><th align="right" style="background-color:#cccccc;"> </th>
- <th align="right" style="background-color:#4477dd;color:#ffffff;">'.
- $total_downloads.
- '</th><th align="left" style="background-color:#cccccc;"> document downloads originating from '.
- $total_download_countries.
- ' distinct countries</td></tr>';
- } // of else
- print "</table>\n";
- ?>