Newer
Older
Digital_Repository / Repositories / statistics / includes / inc.fns.show_detail_eprint.es.php
  1. <?php
  2. /*
  3. Usage by dates, countries, totals.
  4. */
  5. /* New */
  6. function getCountryEprintType($year,$month,$rnge,$type,$id)
  7. {
  8. $year = (int) $year;
  9. $month = (int) $month;
  10. $records = array();
  11.  
  12. // Generate type enquiry
  13. if ($type == 'download') {
  14. $limit2 = ' AND view_type = "download" ';
  15. } elseif ($type == 'abstract') {
  16. $limit2 = ' AND view_type = "abstract" ';
  17. } else {
  18. $limit2 = '';
  19. }
  20.  
  21. // generate date enquiry
  22. $date_range = '';
  23. if($year>=2002 and $year<2100) {
  24. if($month>0 and $month<=12) {
  25. $date_range = " AND year(request_date) = $year AND month(request_date) = $month";
  26. } else {
  27. $date_range = " AND year(request_date) = $year";
  28. }
  29. }
  30. if($rnge=='4w') {
  31. $date_range = " AND request_date >= date_sub(curdate(),INTERVAL 1 MONTH)";
  32. }
  33. $query =
  34. 'select count(*) as count,country_name,country_code from view WHERE archiveid = ' .
  35. $id .
  36. $limit2 .
  37. $date_range .
  38. ' GROUP BY country_name ORDER BY count DESC';
  39. $result = mysql_query($query);
  40. if (!$result) {
  41. sqlconn::_setError(mysql_errno(),mysql_error());
  42. return mysql_error();
  43. } else {
  44. while ($row = mysql_fetch_assoc($result)) {
  45. $records[] = $row;
  46. }
  47. return $records;
  48. }
  49. }
  50.  
  51. // If no id default to front page.
  52. if(!isset($_REQUEST["id"])) { return "pub_default"; }
  53.  
  54. // Get detail given year/month
  55. $show_date = 'all years';
  56. if(isset($_REQUEST["year"]) and $_REQUEST["year"]>2002) {
  57. if(isset($_REQUEST["month"]) and $_REQUEST["month"]>=1 and $_REQUEST["month"]<=12) {
  58. $dt = strtotime($_REQUEST["month"]."/1/".$_REQUEST["year"]);
  59. $show_date = date("F Y",$dt);
  60. } else {
  61. $show_date = $_REQUEST["year"];
  62. $_REQUEST["month"] = 0;
  63. }
  64. } else {
  65. $_REQUEST["year"] = 0;
  66. $_REQUEST["month"] = 0;
  67. }
  68. if(isset($_REQUEST["range"])) {
  69. // Work out current date
  70. if($_REQUEST["range"]=='4w') {
  71. $show_date = 'past 4 weeks';
  72. }
  73. } else {
  74. $_REQUEST["range"] = '';
  75. }
  76. // by country
  77. $country_abstracts = getCountryEprintType($_REQUEST["year"], $_REQUEST["month"], $_REQUEST["range"], 'abstract', $_REQUEST["id"]);
  78. $country_downloads = getCountryEprintType($_REQUEST["year"], $_REQUEST["month"], $_REQUEST["range"], 'download', $_REQUEST["id"]);
  79. $GLOBALS["db_values"] = merge_countries($country_abstracts, $country_downloads);
  80. // title
  81. $title = $sql->getTitle($_REQUEST["id"]);
  82. // by type
  83. $type_count = $sql->getAbstractDownload($_REQUEST["year"], $_REQUEST["month"], $_REQUEST["range"], 'download', $_REQUEST["id"]);
  84. // by date
  85. $month_downloads = $sql->getCumulativeUsageType($_REQUEST["id"],'download');
  86. $month_abstracts = $sql->getCumulativeUsageType($_REQUEST["id"],'abstract');
  87. $month_tally = merge_dates($month_abstracts,$month_downloads);
  88. ?>