Newer
Older
Digital_Repository / Repositories / statistics / includes / inc.html.cumulative_usage_country.es.php
  1. <h3>Abstract views and document downloads by country (derived from IP address of query)</h3>
  2.  
  3. <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>
  4.  
  5. <?php
  6. $max_width=400;
  7. if (! isset($GLOBALS["db_values"]["0"]["country_downloads"])) {
  8. print "<table>\n";
  9. print '<tr><td align="left" width="200" style="color:#ff0000;"><b>No statistics available.</b></td></tr>';
  10. print "\n";
  11. } else {
  12. // Compute the longest bar
  13. $max_count = $GLOBALS["db_values"]["0"]["country_downloads"];
  14. for ($rs=0; $rs<count($GLOBALS["db_values"]); $rs++) {
  15. if ($GLOBALS["db_values"][$rs]["country_abstracts"] > $max_count) {
  16. $max_count = $GLOBALS["db_values"][$rs]["country_abstracts"];
  17. }
  18. }
  19. // NJS 2006-06-14: You never know, there may be no downloads or
  20. // abstracts yet...
  21. $max_count = max( $max_count, 1 );
  22. print "<table cellspacing='0' cellpadding='4'>\n";
  23. 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>';
  24. print '<tr><th colspan="2" style="background-color:#cccccc;">Country</th>
  25. <th style="background-color:#66ddee;">Abstracts</th>
  26. <th style="background-color:#4477dd;color:#ffffff;">Downloads</th>
  27. <th style="background-color:#cccccc;">&nbsp;</th></tr>';
  28.  
  29. // NJS 2006-01-18: Accumulate total number of downloads and views.
  30. $total_downloads = 0;
  31. $total_abstracts = 0;
  32.  
  33. for ($rs=0;$rs<count($GLOBALS["db_values"]);$rs++)
  34. {
  35. // NJS 2006-01-18: Accumulate total number of downloads and views.
  36. $total_downloads += $GLOBALS["db_values"][$rs]["country_downloads"];
  37. $total_abstracts += $GLOBALS["db_values"][$rs]["country_abstracts"];
  38. if ($GLOBALS["db_values"][$rs]["country_name"]=='') { $GLOBALS["db_values"][$rs]["country_name"]='unknown'; }
  39. if ($GLOBALS["db_values"][$rs]["country_name"]=='N/A') { $GLOBALS["db_values"][$rs]["country_name"]='unknown'; }
  40. // NJS 2005-12-15: subtly highlight every alternate row
  41. print '<tr';
  42. if ($rs % 2) print ' style="background-color:#EDF3FE;"';
  43. print '><td>';
  44. // select a flag
  45. // NJS 2005-12-15 make flags and country names links to detail page
  46. $ccode = strtolower($GLOBALS["db_values"][$rs]["country_code"]);
  47. $c_flag = 'flags18x14/' . $ccode . '.png';
  48. // NJS 2006-06-14: Only generate a link if there are actually
  49. // some downloads.
  50. if ( $GLOBALS["db_values"][$rs]["country_downloads"] > 0 )
  51. print '<a href="' . $_SERVER['PHP_SELF'] .
  52. '?action=show_detail_country;code=' . $ccode . '">';
  53. if (file_exists($c_flag)) {
  54. print '<img src="'. $c_flag . '" width="18" height="14" alt="'. $ccode . '" />';
  55. } else {
  56. print '<img src="flags18x14/unknown.png" width="18" height="14" alt="' . $ccode . '" />';
  57. };
  58. if ( $GLOBALS["db_values"][$rs]["country_downloads"] > 0 )
  59. print '</a>';
  60. print '</td><td style="font-size:small;border-right:1px solid #dddddd;">';
  61. // NJS 2006-06-14: Only generate a link if there are actually
  62. // some downloads.
  63. if ( $GLOBALS["db_values"][$rs]["country_downloads"] > 0 )
  64. print '<a href="' . $_SERVER['PHP_SELF'] .
  65. '?action=show_detail_country;code=' . $ccode . '">';
  66. print $GLOBALS["db_values"][$rs]["country_name"];
  67. if ( $GLOBALS["db_values"][$rs]["country_downloads"] > 0 )
  68. print '</a>';
  69. print '</td><td align="right" style="font-size:small;border-right:1px solid #dddddd;">'.
  70. $GLOBALS["db_values"][$rs]["country_abstracts"].
  71. '</td><td align="right" style="font-size:small;border-right:1px solid #dddddd;">' .
  72. $GLOBALS["db_values"][$rs]["country_downloads"].
  73. '</td>';
  74.  
  75. $cur_count = $GLOBALS["db_values"][$rs]["country_abstracts"];
  76. $col_width = (int) ($cur_count/$max_count * $max_width);
  77. $col_width = max($col_width,1);
  78. $col_width .= "px";
  79. print '<td align="left"><img src="bars/hh.png" alt="views" height="9" width="'.
  80. $col_width .
  81. '" /><br />';
  82.  
  83. $cur_count = $GLOBALS["db_values"][$rs]["country_downloads"];
  84. $col_width = (int) ($cur_count/$max_count * $max_width);
  85. $col_width = max($col_width,1);
  86. $col_width .= "px";
  87. print '<img src="bars/hp.png" alt="views" height="9" width="'.
  88. $col_width .
  89. '" /></td></tr>';
  90. }
  91. // NJS 2006-01-18: Display grand totals.
  92. print '<tr><th rowspan="2" colspan="2" style="background-color:#cccccc;">Grand Totals:</th>
  93. <th align="right" style="background-color:#66ddee;">'.
  94. $total_abstracts.
  95. '</th><th align="right" style="background-color:#cccccc;">&nbsp;</th>
  96. <th align="left" style="background-color:#cccccc;"> abstract views originating from '.
  97. $total_abstract_countries.
  98. ' distinct countries</td></tr>';
  99. print '<tr><th align="right" style="background-color:#cccccc;">&nbsp;</th>
  100. <th align="right" style="background-color:#4477dd;color:#ffffff;">'.
  101. $total_downloads.
  102. '</th><th align="left" style="background-color:#cccccc;"> document downloads originating from '.
  103. $total_download_countries.
  104. ' distinct countries</td></tr>';
  105. } // of else
  106. print "</table>\n";
  107.  
  108. ?>