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: Added archive name to URL and only generate
  49. // a link if there are actually 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 . ';archive=' .
  53. $GLOBALS["config_vars"]["archivename"] . '">';
  54. if (file_exists($c_flag)) {
  55. print '<img src="'. $c_flag . '" width="18" height="14" alt="'. $ccode . '" />';
  56. } else {
  57. print '<img src="flags18x14/unknown.png" width="18" height="14" alt="' . $ccode . '" />';
  58. };
  59. if ( $GLOBALS["db_values"][$rs]["country_downloads"] > 0 )
  60. print '</a>';
  61. print '</td><td style="font-size:small;border-right:1px solid #dddddd;">';
  62. // NJS 2006-06-14: Added archive name to URL and only generate
  63. // a link if there are actually some downloads.
  64. if ( $GLOBALS["db_values"][$rs]["country_downloads"] > 0 )
  65. print '<a href="' . $_SERVER['PHP_SELF'] .
  66. '?action=show_detail_country;code=' . $ccode .
  67. ';archive=' .
  68. $GLOBALS["config_vars"]["archivename"] .
  69. '">';
  70. print $GLOBALS["db_values"][$rs]["country_name"];
  71. if ( $GLOBALS["db_values"][$rs]["country_downloads"] > 0 )
  72. print '</a>';
  73. print '</td><td align="right" style="font-size:small;border-right:1px solid #dddddd;">'.
  74. $GLOBALS["db_values"][$rs]["country_abstracts"].
  75. '</td><td align="right" style="font-size:small;border-right:1px solid #dddddd;">' .
  76. $GLOBALS["db_values"][$rs]["country_downloads"].
  77. '</td>';
  78.  
  79. $cur_count = $GLOBALS["db_values"][$rs]["country_abstracts"];
  80. $col_width = (int) ($cur_count/$max_count * $max_width);
  81. $col_width = max($col_width,1);
  82. $col_width .= "px";
  83. print '<td align="left"><img src="bars/hh.png" alt="views" height="9" width="'.
  84. $col_width .
  85. '" /><br />';
  86.  
  87. $cur_count = $GLOBALS["db_values"][$rs]["country_downloads"];
  88. $col_width = (int) ($cur_count/$max_count * $max_width);
  89. $col_width = max($col_width,1);
  90. $col_width .= "px";
  91. print '<img src="bars/hp.png" alt="views" height="9" width="'.
  92. $col_width .
  93. '" /></td></tr>';
  94. }
  95. // NJS 2006-01-18: Display grand totals.
  96. print '<tr><th rowspan="2" colspan="2" style="background-color:#cccccc;">Grand Totals:</th>
  97. <th align="right" style="background-color:#66ddee;">'.
  98. $total_abstracts.
  99. '</th><th align="right" style="background-color:#cccccc;">&nbsp;</th>
  100. <th align="left" style="background-color:#cccccc;"> abstract views originating from '.
  101. $total_abstract_countries.
  102. ' distinct countries</td></tr>';
  103. print '<tr><th align="right" style="background-color:#cccccc;">&nbsp;</th>
  104. <th align="right" style="background-color:#4477dd;color:#ffffff;">'.
  105. $total_downloads.
  106. '</th><th align="left" style="background-color:#cccccc;"> document downloads originating from '.
  107. $total_download_countries.
  108. ' distinct countries</td></tr>';
  109. } // of else
  110. print "</table>\n";
  111.  
  112. ?>